diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2024-10-01 14:58:13 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2024-10-01 14:58:13 +1300 |
| commit | 8b48a9cfc4b0795a62a515e2519e7194d1d57347 (patch) | |
| tree | fc0d0d6df5bb0c10853cb3ba77bc48cc48a2d23d /src/main.cpp | |
| parent | 915532bf8fbda9ba2a36e04fcd6acc67c6c68fa5 (diff) | |
| parent | e162dff48c251e262f475de9261f0ecfa0f39dc4 (diff) | |
| download | YATwm-8b48a9cfc4b0795a62a515e2519e7194d1d57347.tar.gz YATwm-8b48a9cfc4b0795a62a515e2519e7194d1d57347.zip | |
Merge branch 'main' into IPC
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 171 |
1 files changed, 91 insertions, 80 deletions
diff --git a/src/main.cpp b/src/main.cpp index 1f3edc2..77f4dbc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,6 +97,8 @@ void detectScreens(); void focusRoot(int root); void handleConfigErrs(vector<Err> cfgErrs); void updateTime(); +void cWS(int newWS); +void focusWindow(Window w); void configureRequest(XConfigureRequestEvent e); void mapRequest(XMapRequestEvent e); @@ -173,13 +175,13 @@ void focusRoot(int root) if(getFrame(root).subFrameIDs.size() == 0) { //log("\tRoot has no children"); - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focusWindow(root); return; } int client = getFrame(getClientChild(root)).cID; Window w = getClient(client).w; //log("\tFocusing window: " << w); - XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime); + focusWindow(w); } void handleConfigErrs(vector<Err> cfgErrs) { @@ -221,6 +223,59 @@ void updateTime() now = std::localtime(&timeNow); strftime(nowString, sizeof(nowString), "[%H:%M:%S] ", now); } +void cWS(int newWS) +{ + int prevWS = currWS; + + currWS = newWS; + if(prevWS == currWS) + return; + untileRoots(); + + //log("Changing WS with keybind"); + + for(int i = 0; i < cfg.workspaces[newWS - 1].screenPreferencesc; i++) + { + if(nscreens > cfg.workspaces[newWS - 1].screenPreferences[i]) + { + int screen = cfg.workspaces[newWS - 1].screenPreferences[i]; + //log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")"); + prevWS = focusedWorkspaces[screen]; + //log("Changed prevWS"); + focusedWorkspaces[screen] = newWS; + //log("Changed focusedWorkspaces"); + if(focusedScreen != screen) + { + focusedScreen = screen; + XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[screen].x + screens[screen].w/2, screens[screen].y + screens[screen].h/2); + } + //log("Changed focusedScreen"); + break; + } + } + + //log("Finished changes"); + + //log(prevWS); + // LOOK: what is this for????? + if(prevWS < 1 || prevWS > cfg.workspaces.size()) + { + //untile(prevWS); + } + //log("Untiled"); + //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); + tileRoots(); + //log("Roots tiled"); + focusWindow(getFrame(currWS).rootData->focus); + + //EWMH + setCurrentDesktop(currWS); +} +void focusWindow(Window w) +{ + XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime); + getFrame(currWS).rootData->focus = w; +} //Keybind commands const void exit(const CommandArg* argv) @@ -287,57 +342,6 @@ const void kill(const CommandArg* argv) XKillClient(dpy, w); } } -// Took this out as it is used commonly -void cWS(int newWS) -{ - int prevWS = currWS; - - currWS = newWS; - if(prevWS == currWS) - return; - untileRoots(); - - //log("Changing WS with keybind"); - - for(int i = 0; i < cfg.workspaces[newWS - 1].screenPreferencesc; i++) - { - if(nscreens > cfg.workspaces[newWS - 1].screenPreferences[i]) - { - int screen = cfg.workspaces[newWS - 1].screenPreferences[i]; - //log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")"); - prevWS = focusedWorkspaces[screen]; - //log("Changed prevWS"); - focusedWorkspaces[screen] = newWS; - //log("Changed focusedWorkspaces"); - if(focusedScreen != screen) - { - focusedScreen = screen; - XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[screen].x + screens[screen].w/2, screens[screen].y + screens[screen].h/2); - } - //log("Changed focusedScreen"); - break; - } - } - - //log("Finished changes"); - - //log(prevWS); - // LOOK: what is this for????? - if(prevWS < 1 || prevWS > cfg.workspaces.size()) - { - //untile(prevWS); - } - //log("Untiled"); - //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); - tileRoots(); - //log("Roots tiled"); - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - - cout << focusedWorkspaces[0] << endl; - - //EWMH - setCurrentDesktop(currWS); -} const void changeWS(const CommandArg* argv) { cWS(argv[0].num); @@ -362,7 +366,7 @@ const void wToWS(const CommandArg* argv) //Frame disolve pSF.erase(pSF.begin() + i); int pID = frames.find(fID)->second.pID; - if(pSF.size() < 2 && !frames.find(pID)->second.isRoot) + if(pSF.size() < 2 && !frames.find(pID)->second.rootData) { //Erase parent frame int lastChildID = frames.find(frames.find(pID)->second.subFrameIDs[0])->second.ID; @@ -393,7 +397,7 @@ const void wToWS(const CommandArg* argv) //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); untileRoots(); tileRoots(); - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focusWindow(root); } int dirFind(int fID, MoveDir dir) { @@ -449,7 +453,7 @@ const void focChange(const CommandArg* argv) int nID = dirFind(fID, argv[0].dir); int fNID = FFCF(nID); Window w = clients.find(frames.find(fNID)->second.cID)->second.w; - XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime); + focusWindow(w); } const void wMove(const CommandArg* argv) { @@ -479,7 +483,7 @@ const void wMove(const CommandArg* argv) { //Frame dissolve oPSF.erase(oPSF.begin() + i); - if(oPSF.size() < 2 && !frames.find(oPID)->second.isRoot) + if(oPSF.size() < 2 && !frames.find(oPID)->second.rootData) { //Erase parent frame int lastChildID = frames.find(frames.find(oPID)->second.subFrameIDs[0])->second.ID; @@ -531,10 +535,10 @@ const void wMove(const CommandArg* argv) untileRoots(); tileRoots(); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); - XSetInputFocus(dpy, focusedWindow, RevertToPointerRoot, CurrentTime); + focusWindow(focusedWindow); return; } - XSetInputFocus(dpy, focusedWindow, RevertToPointerRoot, CurrentTime); + focusWindow(focusedWindow); } const void bashSpawn(const CommandArg* argv) { @@ -578,7 +582,7 @@ const void wsDump(const CommandArg* argv) if(getFrame(i).isClient) { int id = i; - while(!getFrame(id).isRoot) + while(!getFrame(id).rootData) { id=getFrame(id).pID; } @@ -620,7 +624,7 @@ void configureRequest(XConfigureRequestEvent e) changes.stack_mode = e.detail; XConfigureWindow(dpy, e.window, (unsigned int) e.value_mask, &changes); log("Configure request: " << e.window); - //XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); + //focusWindow(e.window); //tileRoots(); } @@ -717,8 +721,7 @@ void mapRequest(XMapRequestEvent e) //Make frame //pID = (frameIDS.count(focusedWindow)>0)? frames.find(frameIDS.find(focusedWindow)->second)->second.pID : currWS; vector<int> v; - vector<int> floating; - Frame f = {currFrameID, pID, true, c.ID, noDir, v, false, floating}; + Frame f = {currFrameID, pID, true, c.ID, noDir, v, NULL}; currFrameID++; @@ -730,7 +733,7 @@ void mapRequest(XMapRequestEvent e) { cout << "Floating" << endl; clients.find(c.ID)->second.floating = true; - frames.find(pID)->second.floatingFrameIDs.push_back(f.ID); + frames.find(pID)->second.rootData->floatingFrameIDs.push_back(f.ID); frames.insert(pair<int, Frame>(f.ID, f)); setWindowDesktop(e.window, currWS); updateClientList(clients); @@ -764,7 +767,7 @@ void mapRequest(XMapRequestEvent e) vector<int> v; v.push_back(frames.find(frameIDS.find(focusedWindow)->second)->second.ID); v.push_back(f.ID); - Frame pF = {currFrameID, pID, false, noID, nextDir, v, false, floating}; + Frame pF = {currFrameID, pID, false, noID, nextDir, v, NULL}; //Update the IDS f.pID = currFrameID; @@ -776,7 +779,7 @@ void mapRequest(XMapRequestEvent e) //Insert the new frame into the frames map frames.insert(pair<int, Frame>(pF.ID, pF)); } - + //Add to frames map frames.insert(pair<int, Frame>(f.ID, f)); @@ -784,7 +787,7 @@ void mapRequest(XMapRequestEvent e) updateClientList(clients); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); - XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); + focusWindow(e.window); tileRoots(); } @@ -799,7 +802,7 @@ void destroyNotify(XDestroyWindowEvent e) vector<int>& pS = frames.find(pID)->second.subFrameIDs; if(clients.find(frames.find(fID)->second.cID)->second.floating) { - pS = frames.find(pID)->second.floatingFrameIDs; + pS = frames.find(pID)->second.rootData->floatingFrameIDs; } for(int i = 0; i < pS.size(); i++) { @@ -810,7 +813,7 @@ void destroyNotify(XDestroyWindowEvent e) frames.erase(fID); frameIDS.erase(e.window); - if(pS.size() < 2 && !frames.find(pID)->second.isRoot) + if(pS.size() < 2 && !frames.find(pID)->second.rootData) { //Erase parent frame int lastChildID = frames.find(frames.find(pID)->second.subFrameIDs[0])->second.ID; @@ -830,7 +833,7 @@ void destroyNotify(XDestroyWindowEvent e) break; } } - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focusWindow(root); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); tileRoots(); @@ -857,7 +860,7 @@ void enterNotify(XEnterWindowEvent e) } } focusedScreen = monitor; - XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); + focusWindow(e.window); } void clientMessage(XClientMessageEvent e) { @@ -877,7 +880,7 @@ void clientMessage(XClientMessageEvent e) untile(prevWS); tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focusWindow(root); //EWMH setCurrentDesktop(currWS); @@ -940,10 +943,13 @@ void untileRoots() } int tile(int frameID, int x, int y, int w, int h) { - for(int fID : frames.find(frameID)->second.floatingFrameIDs) + if(getFrame(frameID).rootData) { - Window w = clients.find(frames.find(fID)->second.cID)->second.w; - XMapWindow(dpy, w); + for(int fID : frames.find(frameID)->second.rootData->floatingFrameIDs) + { + Window w = clients.find(frames.find(fID)->second.cID)->second.w; + XMapWindow(dpy, w); + } } TileDir dir = frames.find(frameID)->second.dir; int i = 0; @@ -986,10 +992,13 @@ int tile(int frameID, int x, int y, int w, int h) void untile(int frameID) { - for(int fID : frames.find(frameID)->second.floatingFrameIDs) + if(getFrame(frameID).rootData) { - Window w = clients.find(frames.find(fID)->second.cID)->second.w; - XUnmapWindow(dpy, w); + for(int fID : frames.find(frameID)->second.rootData->floatingFrameIDs) + { + Window w = clients.find(frames.find(fID)->second.cID)->second.w; + XUnmapWindow(dpy, w); + } } vector<int>& subFrameIDs = frames.find(frameID)->second.subFrameIDs; TileDir dir = frames.find(frameID)->second.dir; @@ -1088,12 +1097,14 @@ int main(int argc, char** argv) for(int i = 1; i < cfg.numWS + 1; i++) { vector<int> v; - Frame rootFrame = {i, noID, false, noID, horizontal, v, true}; + RootData* rootData = new RootData; + rootData->focus = root; + Frame rootFrame = {i, noID, false, noID, horizontal, v, rootData}; frames.insert(pair<int, Frame>(i, rootFrame)); currFrameID++; } - XSetInputFocus(dpy, root, RevertToNone, CurrentTime); + focusWindow(root); XWarpPointer(dpy, root, root, 0, 0, 0, 0, 960, 540); fd_set fdset; |
