From ef998ee445e8a59a1cc5c9d15d721aabea187fd7 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 2 Feb 2023 21:17:12 +1300 Subject: feat: fullscreen keybind --- main.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index d4502dd..6f1cd9b 100644 --- a/main.cpp +++ b/main.cpp @@ -75,6 +75,7 @@ int mX, mY; #define getClient(c) clients.find(c)->second #define getFrame(f) frames.find(f)->second +#define getFrameID(w) frameIDS.find(w)->second Window bar; @@ -95,9 +96,14 @@ void clientMessage(XClientMessageEvent e); static int OnXError(Display* display, XErrorEvent* e); +// Tiling +// Call this one to tile everything (it does all the fancy stuff trust me just call this one) void tileRoots(); +// Call this one to until everything (it handles multiple monitors) void untileRoots(); -void tile(int frameID, int x, int y, int w, int h); +// This is to be called by tileRoots, it takes in the x, y, w, and h of where it's allowed to tile windows to, and returns the ID of a fullscreen client if one is found, or noID (-1) if none are found +int tile(int frameID, int x, int y, int w, int h); +// This is to be called by tileRoots, it takes in a frameID and recursively unmaps all its children void untile(int frameID); // Usefull functions @@ -573,6 +579,17 @@ const void nextMonitor(const CommandArg* argv) XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[focusedScreen].x + screens[focusedScreen].w/2, screens[focusedScreen].y + screens[focusedScreen].h/2); focusRoot(focusedWorkspaces[focusedScreen]); } +void fullscreen(const KeyArg arg) +{ + Window focusedWindow; + int focusedRevert; + XGetInputFocus(dpy, &focusedWindow, &focusedRevert); + + int fID = getFrameID(focusedWindow); + int cID = getFrame(fID).cID; + getClient(cID).fullscreen ^= true; + tileRoots(); +} void configureRequest(XConfigureRequestEvent e) { @@ -670,7 +687,7 @@ void mapRequest(XMapRequestEvent e) XSelectInput(dpy, e.window, EnterWindowMask); //Make client - Client c = {currClientID, e.window, false}; + Client c = {currClientID, e.window, false, false}; currClientID++; //Add to clients map @@ -861,7 +878,17 @@ void tileRoots() { for(int i = 0; i < nscreens; i++) { - tile(focusedWorkspaces[i], screens[i].x + cfg.outerGaps, screens[i].y + cfg.outerGaps, screens[i].w - cfg.outerGaps*2, screens[i].h - cfg.outerGaps*2 - bH); + int fullscreenClientID = tile(focusedWorkspaces[i], screens[i].x + cfg.outerGaps, screens[i].y + cfg.outerGaps, screens[i].w - cfg.outerGaps*2, screens[i].h - cfg.outerGaps*2 - bH); + if(fullscreenClientID!=noID) + { + untile(focusedWorkspaces[i]); + Client c = getClient(fullscreenClientID); + XMapWindow(dpy, c.w); + XMoveWindow(dpy, c.w, + screens[i].x, screens[i].y); + XResizeWindow(dpy, c.w, + screens[i].w, screens[i].h); + } } } void untileRoots() @@ -871,7 +898,7 @@ void untileRoots() untile(focusedWorkspaces[i]); } } -void tile(int frameID, int x, int y, int w, int h) +int tile(int frameID, int x, int y, int w, int h) { for(int fID : frames.find(frameID)->second.floatingFrameIDs) { @@ -896,20 +923,25 @@ void tile(int frameID, int x, int y, int w, int h) } if(!f.isClient) { - tile(fID, wX, wY, wW, wH); + int fullscreenClientID = tile(fID, wX, wY, wW, wH); + if(fullscreenClientID == noID) + return fullscreenClientID; continue; } + Client c = clients.find(f.cID)->second; + if(c.fullscreen) + return c.ID; wX += cfg.gaps; wY += cfg.gaps; wW -= cfg.gaps * 2; wH -= cfg.gaps * 2; - Client c = clients.find(f.cID)->second; XMapWindow(dpy, c.w); XMoveWindow(dpy, c.w, wX, wY); XResizeWindow(dpy, c.w, wW, wH); } + return noID; } void untile(int frameID) -- cgit v1.2.3 From ab3d823a8190ae6ec4a1444aa3b5a01aaa018586 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 3 Feb 2023 17:45:07 +1300 Subject: feat: Windows that request to be fullscreen should become fullscreen - more testing neededs --- main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 6f1cd9b..01f01c7 100644 --- a/main.cpp +++ b/main.cpp @@ -589,6 +589,7 @@ void fullscreen(const KeyArg arg) int cID = getFrame(fID).cID; getClient(cID).fullscreen ^= true; tileRoots(); + setFullscreen(focusedWindow, getClient(cID).fullscreen); } void configureRequest(XConfigureRequestEvent e) @@ -862,6 +863,26 @@ void clientMessage(XClientMessageEvent e) setCurrentDesktop(currWS); */ } + else if(e.message_type == XInternAtom(dpy, "_NET_WM_STATE", false)) + { + if((Atom)e.data.l[0] == 0) + log("\tremove"); + if((Atom)e.data.l[0] == 1) + log("\ttoggle"); + if((Atom)e.data.l[0] == 2) + log("\tadd"); + char* prop1 = XGetAtomName(dpy, (Atom)e.data.l[1]); + log("\tprop1"); + if((Atom)e.data.l[1] == XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false)) + { + int fID = getFrameID(e.window); + int cID = getFrame(fID).cID; + getClient(cID).fullscreen = (Atom) e.data.l[0] == 1; + setFullscreen(e.window, (Atom) e.data.l[0] == 1); + tileRoots(); + } + XFree(prop1); + } XFree(name); } -- cgit v1.2.3 From 21b1840e0982929c1fa8acc5fadd203dccc94585 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 25 Feb 2023 17:07:29 +1300 Subject: fixup: Make fullscreen request either toggle or add I'm not sure if add prop is ever going to be used though. I've tested with both OBS and qutebrowser and both send 2 toggle requests to go fullscreen, and 2 remove requests to get out of fullscreen --- main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 01f01c7..af9210b 100644 --- a/main.cpp +++ b/main.cpp @@ -872,13 +872,12 @@ void clientMessage(XClientMessageEvent e) if((Atom)e.data.l[0] == 2) log("\tadd"); char* prop1 = XGetAtomName(dpy, (Atom)e.data.l[1]); - log("\tprop1"); if((Atom)e.data.l[1] == XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false)) { int fID = getFrameID(e.window); int cID = getFrame(fID).cID; - getClient(cID).fullscreen = (Atom) e.data.l[0] == 1; - setFullscreen(e.window, (Atom) e.data.l[0] == 1); + getClient(cID).fullscreen = (Atom) e.data.l[0] > 0; + setFullscreen(e.window, (Atom) e.data.l[0] > 0); tileRoots(); } XFree(prop1); -- cgit v1.2.3 From c4813b0ad3f8e0cc4f55b0f0fda8359eb9729417 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 21 Jun 2023 20:26:52 +1200 Subject: feat: Fixed fullscreen stuff after rebasing in the config refactor Also added stuff to the readme for it --- main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index af9210b..72ba368 100644 --- a/main.cpp +++ b/main.cpp @@ -579,7 +579,7 @@ const void nextMonitor(const CommandArg* argv) XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[focusedScreen].x + screens[focusedScreen].w/2, screens[focusedScreen].y + screens[focusedScreen].h/2); focusRoot(focusedWorkspaces[focusedScreen]); } -void fullscreen(const KeyArg arg) +const void fullscreen(const CommandArg* arg) { Window focusedWindow; int focusedRevert; @@ -1018,6 +1018,7 @@ int main(int argc, char** argv) commandsModule.addCommand("reload", reload, 0, {}); commandsModule.addCommand("wsDump", wsDump, 0, {}); commandsModule.addCommand("nextMonitor", nextMonitor, 0, {}); + commandsModule.addCommand("fullscreen", fullscreen, 0, {}); //Config std::vector cfgErr; -- cgit v1.2.3