From 4a07bd68dd3e3ccdf613ebc1b7114dd277e29c47 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 25 Aug 2022 16:33:36 +1200 Subject: Moving windows betweeen workspaces --- config.h | 33 ++++++++++++++++----------------- main.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/config.h b/config.h index 0b66419..5400faf 100644 --- a/config.h +++ b/config.h @@ -35,30 +35,29 @@ void spawn(const KeyArg arg); void toggle(const KeyArg arg); void kill(const KeyArg arg); void changeWS(const KeyArg arg); +void wToWS(const KeyArg arg); const char* alacritty[] = {"alacritty", NULL}; const char* rofi[] = {"rofi", "-i", "-show", "drun", NULL}; +#define MOD Mod1Mask +#define SHIFT ShiftMask + #define WSKEY(K, X) \ - {K, mod, changeWS, {.num = X - 1}}, + {K, MOD, changeWS, {.num = X}}, \ + {K, MOD|SHIFT, wToWS, {.num = X}}, -unsigned int mod = Mod1Mask; static struct Key keyBinds[] = { //Key //Modifiers //Func //Args - {XK_e, mod, exit, {NULL}}, - {XK_Return, mod, spawn, {.str = alacritty}}, - {XK_d, mod, spawn, {.str = rofi}}, - {XK_t, mod, toggle, {NULL}}, - {XK_q, mod, kill, {NULL}}, - {XK_1, mod, changeWS, {.num = 1}}, - {XK_2, mod, changeWS, {.num = 2}}, - {XK_3, mod, changeWS, {.num = 3}}, - {XK_4, mod, changeWS, {.num = 4}}, - {XK_5, mod, changeWS, {.num = 5}}, - //WSKEY(XK_1, 1) - //WSKEY(XK_2, 2) - //WSKEY(XK_3, 3) - //WSKEY(XK_4, 4) - //WSKEY(XK_5, 5) + {XK_e, MOD, exit, {NULL}}, + {XK_Return, MOD, spawn, {.str = alacritty}}, + {XK_d, MOD, spawn, {.str = rofi}}, + {XK_t, MOD, toggle, {NULL}}, + {XK_q, MOD, kill, {NULL}}, + WSKEY(XK_1, 1) + WSKEY(XK_2, 2) + WSKEY(XK_3, 3) + WSKEY(XK_4, 4) + WSKEY(XK_5, 5) }; diff --git a/main.cpp b/main.cpp index 2066993..1724b82 100644 --- a/main.cpp +++ b/main.cpp @@ -104,6 +104,30 @@ void changeWS(const KeyArg arg) tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2); XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); } +void wToWS(const KeyArg arg) +{ + Window focusedWindow; + int revertToReturn; + XGetInputFocus(dpy, &focusedWindow, &revertToReturn); + if(focusedWindow == root) + return; + + int fID = frameIDS.find(focusedWindow)->second; + vector& pSF = frames.find(frames.find(fID)->second.pID)->second.subFrameIDs; + for(int i = 0; i < pSF.size(); i++) + { + if(pSF[i] == fID) + { + pSF.erase(pSF.begin() + i); + break; + } + } + frames.find(fID)->second.pID = arg.num; + frames.find(arg.num)->second.subFrameIDs.push_back(fID); + XUnmapWindow(dpy, focusedWindow); + tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2); + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); +} void keyPress(XKeyEvent e) { @@ -236,6 +260,7 @@ void destroyNotify(XDestroyWindowEvent e) break; } } + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2); } -- cgit v1.2.3