diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2022-08-28 18:22:59 +1200 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2022-08-28 18:22:59 +1200 |
| commit | 01a34fabc8cd6b5a7cb5ab1dd0e58f27094ec4d5 (patch) | |
| tree | 2fa857402e8e4e95d4e71aa8831f6d61433c4a4b | |
| parent | 1566509dc6c3a7b6b579c0088f627786b73ee6a6 (diff) | |
| download | YATwm-01a34fabc8cd6b5a7cb5ab1dd0e58f27094ec4d5.tar.gz YATwm-01a34fabc8cd6b5a7cb5ab1dd0e58f27094ec4d5.zip | |
Very basic window and focus moving
| -rw-r--r-- | #config.h# | 57 | ||||
| -rw-r--r-- | config.h | 48 | ||||
| -rw-r--r-- | main.cpp | 128 | ||||
| -rw-r--r-- | makefile | 2 | ||||
| -rw-r--r-- | structs.h | 2 |
5 files changed, 201 insertions, 36 deletions
@@ -11,12 +11,23 @@ std::string startup[] = {"picom -fD 3", "feh --bg-scale /usr/share/backgrounds/v int gaps = 10; int outerGaps = 30; +int numWS = 5; + //Keys //The types and perhaps functions likely to be moved to seperate header file later +enum MoveDir +{ + Up, + Right, + Down, + Left +}; + typedef union { - const int num; const char** str; + const int num; + const MoveDir dir; } KeyArg; struct Key @@ -33,30 +44,34 @@ 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); +void focChange(const KeyArg arg); + +const char* alacritty[] = ; +const char* rofi[] = {"rofi", "-i", "-show", "drun", NULL}; -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}}, +#define WSKEY(K, X) \ + {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, {NULL}, - {XK_2, mod, changeWS, {NULL}}, - {XK_3, mod, changeWS, {.num = 2}}, - {XK_4, mod, changeWS, {.num = 3}}, - {XK_5, mod, changeWS, {.num = 4}}, - //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", NULL}}}, + {XK_d, MOD, spawn, {.str = rofi}}, + {XK_t, MOD, toggle, {NULL}}, + {XK_q, MOD, kill, {NULL}}, + {XK_h, MOD, focChange, {.dir = Left}}, + {XK_j, MOD, focChange, {.dir = Down}}, + {XK_k, MOD, focChange, {.dir = Up}}, + {XK_l, MOD, focChange, {.dir = Right}}, + WSKEY(XK_1, 1) + WSKEY(XK_2, 2) + WSKEY(XK_3, 3) + WSKEY(XK_4, 4) + WSKEY(XK_5, 5) }; @@ -15,10 +15,19 @@ int numWS = 5; //Keys //The types and perhaps functions likely to be moved to seperate header file later +enum MoveDir +{ + Up, + Right, + Down, + Left +}; + typedef union { const char** str; const int num; + const MoveDir dir; } KeyArg; struct Key @@ -30,12 +39,16 @@ struct Key }; //Keybind commands -void exit(const KeyArg arg); -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); +#define KEYCOM(X) \ + void X (const KeyArg arg) +KEYCOM(exit); +KEYCOM(spawn); +KEYCOM(toggle); +KEYCOM(kill); +KEYCOM(changeWS); +KEYCOM(wToWS); +KEYCOM(focChange); +KEYCOM(wMove); const char* alacritty[] = {"alacritty", NULL}; const char* rofi[] = {"rofi", "-i", "-show", "drun", NULL}; @@ -45,19 +58,30 @@ const char* rofi[] = {"rofi", "-i", "-show", "drun", NULL}; #define WSKEY(K, X) \ {K, MOD, changeWS, {.num = X}}, \ - {K, MOD|SHIFT, wToWS, {.num = X}}, - + {K, MOD|SHIFT, wToWS, {.num = X}} static struct Key keyBinds[] = { //Key //Modifiers //Func //Args + //General {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) + //Focus + {XK_h, MOD, focChange, {.dir = Left}}, + {XK_j, MOD, focChange, {.dir = Down}}, + {XK_k, MOD, focChange, {.dir = Up}}, + {XK_l, MOD, focChange, {.dir = Right}}, + //Window moving + {XK_h, MOD|SHIFT, wMove, {.dir = Left}}, + {XK_j, MOD|SHIFT, wMove, {.dir = Down}}, + {XK_k, MOD|SHIFT, wMove, {.dir = Up}}, + {XK_l, MOD|SHIFT, wMove, {.dir = Right}}, + //Workspaces + WSKEY(XK_1, 1), + WSKEY(XK_2, 2), + WSKEY(XK_3, 3), + WSKEY(XK_4, 4), WSKEY(XK_5, 5) }; @@ -147,6 +147,131 @@ void wToWS(const KeyArg arg) tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2); XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); } +int FFCF(int sID) +{ + if(frames.find(sID)->second.isClient) + return sID; + return FFCF(frames.find(sID)->second.subFrameIDs[0]); +} +int dirFind(int fID, MoveDir dir) +{ + vector<int>& pSF = frames.find(frames.find(fID)->second.pID)->second.subFrameIDs; + TileDir pDir = frames.find(frames.find(fID)->second.pID)->second.dir; + + int i = 0; + for(int f : pSF) + { + if(f == fID) + { + break; + } + i++; + } + + if(pDir == vertical) + { + switch(dir) + { + case Up: i--; break; + case Down: i++; break; + case Left: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case Right: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + } + } + else if(pDir == horizontal) + { + switch(dir) + { + case Left: i--; break; + case Right: i++; break; + case Up: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case Down: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + } + } + if(i < 0) + i = pSF.size() - 1; + if(i == pSF.size()) + i = 0; + + return pSF[i]; +} +void focChange(const KeyArg arg) +{ + Window focusedWindow; + int revertToReturn; + XGetInputFocus(dpy, &focusedWindow, &revertToReturn); + if(focusedWindow == root) + return; + + int fID = frameIDS.find(focusedWindow)->second; + int nID = dirFind(fID, arg.dir); + int fNID = FFCF(nID); + Window w = clients.find(frames.find(fNID)->second.cID)->second.w; + XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime); +} +void wMove(const KeyArg arg) +{ + Window focusedWindow; + int revertToReturn; + XGetInputFocus(dpy, &focusedWindow, &revertToReturn); + if(focusedWindow == root) + return; + + int fID = frameIDS.find(focusedWindow)->second; + int nID = dirFind(fID, arg.dir); + int fNID = FFCF(nID); + int pID = frames.find(fNID)->second.pID; + int oPID = frames.find(fID)->second.pID; + + vector<int>& pSF = frames.find(pID)->second.subFrameIDs; + vector<int>& oPSF = frames.find(oPID)->second.subFrameIDs; + + for(int i = 0; i < frames.find(oPID)->second.subFrameIDs.size(); i++) + { + if(oPSF[i] != fID) + continue; + + if(pID!=oPID) + { + oPSF.erase(oPSF.begin() + i); + + frames.find(fID)->second.pID = pID; + pSF.push_back(fID); + cout << "Moving to: " << pID << "\n"; + } + else + { + if(frames.find(pID)->second.dir == vertical) + { + if(arg.dir == Left || arg.dir == Right) + return; + } + else + { + if(arg.dir == Up || arg.dir == Down) + return; + } + + int offset; + if(arg.dir == Up || arg.dir == Left) + offset = -1; + else + offset = 1; + + int swapPos = i + offset; + + if(swapPos == pSF.size()) + swapPos = 0; + else if(swapPos == -1) + swapPos = pSF.size() - 1; + + std::swap(pSF[i], pSF[swapPos]); + } + tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2); + XSetInputFocus(dpy, focusedWindow, RevertToPointerRoot, CurrentTime); + return; + } +} void keyPress(XKeyEvent e) { @@ -201,7 +326,7 @@ void mapRequest(XMapRequestEvent e) frameIDS.insert(pair<Window, int>(e.window, f.ID)); //Check how to add - if(nextDir == frames.find(pID)->second.dir) + if(nextDir == frames.find(pID)->second.dir || frameIDS.count(focusedWindow)==0) { //Add to focused parent frames.find(pID)->second.subFrameIDs.push_back(f.ID); @@ -389,6 +514,7 @@ int main(int argc, char** argv) } } + XSetInputFocus(dpy, root, RevertToNone, CurrentTime); cout << "Begin mainloop\n"; while(keepGoing) @@ -1,6 +1,6 @@ .PHONY: clean CXX := g++ -CXXFLAGS := -g `pkg-config --cflags x11` +CXXFLAGS := -g `pkg-config --cflags x11` LINKFLAGS := `pkg-config --libs x11` OBJS_DIR := . OUT_DIR := . @@ -2,7 +2,7 @@ #include <vector> -int noID = -1; +#define noID -1 struct Client { |
