From da3b5b2131d2b4ff5cb127e92090fca568376835 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 24 May 2023 10:28:49 +1200 Subject: in-progress: Config refactor started, changed all existing keybind command args and added in the new files, still many errors --- main.cpp | 80 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index d367ead..1433e70 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,6 @@ #include #include -#include #include @@ -26,10 +25,12 @@ #include #include +#include "commands.h" #include "structs.h" #include "config.h" #include "util.h" #include "ewmh.h" +#include "error.h" using std::cout; using std::string; @@ -42,7 +43,8 @@ std::ofstream yatlog; #define log(x) yatlog << x << std::endl -Config cfg; +CommandsModule commandsModule; +Config cfg(commandsModule); Display* dpy; Window root; @@ -194,11 +196,11 @@ void handleConfigErrs(Err cfgErr) } //Keybind commands -void exit(const KeyArg arg) +const void exit(const CommandArg* argv) { keepGoing = false; } -void spawn(const KeyArg arg) +const void spawn(const CommandArg* argv) { if(fork() == 0) { @@ -206,7 +208,7 @@ void spawn(const KeyArg arg) dup2(null, 0); dup2(null, 1); dup2(null, 2); - const std::string argsStr = arg.str; + const std::string argsStr = argv[0].str; vector args = split(argsStr, ' '); char** execvpArgs = new char*[args.size()]; for(int i = 0; i < args.size(); i++) @@ -217,11 +219,11 @@ void spawn(const KeyArg arg) exit(0); } } -void toggle(const KeyArg arg) +const void toggle(const CommandArg* argv) { nextDir = nextDir = (nextDir==horizontal)? vertical : horizontal; } -void kill(const KeyArg arg) +const void kill(const CommandArg* argv) { Window w; int revertToReturn; @@ -252,11 +254,11 @@ void kill(const KeyArg arg) XKillClient(dpy, w); } } -void changeWS(const KeyArg arg) +const void changeWS(const CommandArg* argv) { int prevWS = currWS; - currWS = arg.num; + currWS = argv[0].num; if(prevWS == currWS) return; untileRoots(); @@ -265,17 +267,17 @@ void changeWS(const KeyArg arg) for(int i = 0; i < cfg.maxMonitors; i++) { - if(nscreens > cfg.screenPreferences[arg.num - 1][i]) + if(nscreens > cfg.screenPreferences[argv[0].num - 1][i]) { - int screen = cfg.screenPreferences[arg.num - 1][i]; + int screen = cfg.screenPreferences[argv[0].num - 1][i]; //log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")"); - prevWS = focusedWorkspaces[cfg.screenPreferences[arg.num - 1][i]]; + prevWS = focusedWorkspaces[cfg.screenPreferences[argv[0].num - 1][i]]; //log("Changed prevWS"); - focusedWorkspaces[cfg.screenPreferences[arg.num - 1][i]] = arg.num; + focusedWorkspaces[cfg.screenPreferences[argv[0].num - 1][i]] = argv[0].num; //log("Changed focusedWorkspaces"); - if(focusedScreen != cfg.screenPreferences[arg.num - 1][i]) + if(focusedScreen != cfg.screenPreferences[argv[0].num - 1][i]) { - focusedScreen = cfg.screenPreferences[arg.num - 1][i]; + focusedScreen = cfg.screenPreferences[argv[0].num - 1][i]; 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"); @@ -299,7 +301,7 @@ void changeWS(const KeyArg arg) //EWMH setCurrentDesktop(currWS); } -void wToWS(const KeyArg arg) +const void wToWS(const CommandArg* argv) { Window focusedWindow; int revertToReturn; @@ -340,11 +342,11 @@ void wToWS(const KeyArg arg) break; } } - frames.find(fID)->second.pID = arg.num; - frames.find(arg.num)->second.subFrameIDs.push_back(fID); + frames.find(fID)->second.pID = argv[0].num; + frames.find(argv[0].num)->second.subFrameIDs.push_back(fID); //EWMH - setWindowDesktop(focusedWindow, arg.num); + setWindowDesktop(focusedWindow, argv[0].num); XUnmapWindow(dpy, focusedWindow); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); @@ -371,20 +373,20 @@ int dirFind(int fID, MoveDir dir) { switch(dir) { - case Up: i--; break; - case Down: i++; break; - case Left: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; - case Right: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case UP: i--; break; + case DOWN: i++; break; + case LEFT: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case RIGHT: return (frames.find(fID)->second.pID > cfg.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 > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; - case Down: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case LEFT: i--; break; + case RIGHT: i++; break; + case UP: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; + case DOWN: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID; } } if(i < 0) @@ -394,7 +396,7 @@ int dirFind(int fID, MoveDir dir) return pSF[i]; } -void focChange(const KeyArg arg) +const void focChange(const CommandArg* argv) { Window focusedWindow; int revertToReturn; @@ -403,12 +405,12 @@ void focChange(const KeyArg arg) return; int fID = frameIDS.find(focusedWindow)->second; - int nID = dirFind(fID, arg.dir); + 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); } -void wMove(const KeyArg arg) +const void wMove(const CommandArg* argv) { Window focusedWindow; int revertToReturn; @@ -419,7 +421,7 @@ void wMove(const KeyArg arg) int fID = frameIDS.find(focusedWindow)->second; if(clients.find(frames.find(fID)->second.cID)->second.floating) return; - int nID = dirFind(fID, arg.dir); + int nID = dirFind(fID, argv[0].dir); int fNID = FFCF(nID); int pID = frames.find(fNID)->second.pID; int oPID = frames.find(fID)->second.pID; @@ -461,17 +463,17 @@ void wMove(const KeyArg arg) { if(frames.find(pID)->second.dir == vertical) { - if(arg.dir == Left || arg.dir == Right) + if(argv[0].dir == LEFT || argv[0].dir == RIGHT) return; } else { - if(arg.dir == Up || arg.dir == Down) + if(argv[0].dir == UP || argv[0].dir == DOWN) return; } int offset; - if(arg.dir == Up || arg.dir == Left) + if(argv[0].dir == UP || argv[0].dir == LEFT) offset = -1; else offset = 1; @@ -493,7 +495,7 @@ void wMove(const KeyArg arg) } XSetInputFocus(dpy, focusedWindow, RevertToPointerRoot, CurrentTime); } -void bashSpawn(const KeyArg arg) +const void bashSpawn(const CommandArg* argv) { if(fork() == 0) { @@ -501,12 +503,12 @@ void bashSpawn(const KeyArg arg) dup2(null, 0); dup2(null, 1); dup2(null, 2); - system(arg.str); + system(argv[0].str); exit(0); } } -void reload(const KeyArg arg) +const void reload(const CommandArg* argv) { detectScreens(); @@ -518,7 +520,7 @@ void reload(const KeyArg arg) //Re tile tileRoots(); } -void wsDump(const KeyArg arg) +const void wsDump(const CommandArg* argv) { log("Workspace dump:"); for(int i = 1; i < currFrameID; i++) @@ -534,7 +536,7 @@ void wsDump(const KeyArg arg) } } } -void nextMonitor(const KeyArg arg) +const void nextMonitor(const CommandArg* argv) { focusedScreen++; if(focusedScreen >= nscreens) -- cgit v1.2.3 From 27137ec9d29c36df8117869773203b243849896c Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 26 May 2023 21:46:19 +1200 Subject: feat: Made keybinds work (I hope) Note: the config file reloading keybinds isn't quite working, though, need to ungrab the keys --- main.cpp | 64 +++++++++++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 39 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 1433e70..e4a4bcc 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,7 @@ #include #include "commands.h" +#include "keybinds.h" #include "structs.h" #include "config.h" #include "util.h" @@ -43,11 +44,13 @@ std::ofstream yatlog; #define log(x) yatlog << x << std::endl +Display* dpy; +Window root; + CommandsModule commandsModule; Config cfg(commandsModule); +KeybindsModule keybindsModule(commandsModule, dpy, root); -Display* dpy; -Window root; int sW, sH; int bH; TileDir nextDir = horizontal; @@ -81,7 +84,6 @@ void updateMousePos(); void focusRoot(int root); void handleConfigErrs(Err cfgErr); -void keyPress(XKeyEvent e); void configureRequest(XConfigureRequestEvent e); void mapRequest(XMapRequestEvent e); void destroyNotify(XDestroyWindowEvent e); @@ -164,11 +166,11 @@ void handleConfigErrs(Err cfgErr) { if(cfgErr.code!=NOERR) { - if(cfgErr.code == ERR_CFG_FATAL) + if(cfgErr.code == CFG_ERR_FATAL) { - log("YATwm fatal error (Code " << cfgErr.code << ")\n" << cfgErr.errorMessage); + log("YATwm fatal error (Code " << cfgErr.code << ")\n" << cfgErr.message); std::string title = "YATwm fatal config error (Code " + std::to_string(cfgErr.code) + ")"; - std::string body = cfgErr.errorMessage; + std::string body = cfgErr.message; NotifyNotification* n = notify_notification_new(title.c_str(), body.c_str(), 0); @@ -180,7 +182,7 @@ void handleConfigErrs(Err cfgErr) } else { - log("YATwm non fatal error (Code " << cfgErr.code << ")\n" << cfgErr.errorMessage); + log("YATwm non fatal error (Code " << cfgErr.code << ")\n" << cfgErr.message); std::string title = "YATwm non fatal config error (Code " + std::to_string(cfgErr.code) + ")"; std::string body = "Check logs for more information"; NotifyNotification* n = notify_notification_new(title.c_str(), @@ -254,11 +256,12 @@ const void kill(const CommandArg* argv) XKillClient(dpy, w); } } -const void changeWS(const CommandArg* argv) +// Took this out as it is used commonly +void cWS(int newWS) { int prevWS = currWS; - currWS = argv[0].num; + currWS = newWS; if(prevWS == currWS) return; untileRoots(); @@ -267,17 +270,17 @@ const void changeWS(const CommandArg* argv) for(int i = 0; i < cfg.maxMonitors; i++) { - if(nscreens > cfg.screenPreferences[argv[0].num - 1][i]) + if(nscreens > cfg.screenPreferences[newWS - 1][i]) { - int screen = cfg.screenPreferences[argv[0].num - 1][i]; + int screen = cfg.screenPreferences[newWS - 1][i]; //log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")"); - prevWS = focusedWorkspaces[cfg.screenPreferences[argv[0].num - 1][i]]; + prevWS = focusedWorkspaces[cfg.screenPreferences[newWS - 1][i]]; //log("Changed prevWS"); - focusedWorkspaces[cfg.screenPreferences[argv[0].num - 1][i]] = argv[0].num; + focusedWorkspaces[cfg.screenPreferences[newWS - 1][i]] = newWS; //log("Changed focusedWorkspaces"); - if(focusedScreen != cfg.screenPreferences[argv[0].num - 1][i]) + if(focusedScreen != cfg.screenPreferences[newWS - 1][i]) { - focusedScreen = cfg.screenPreferences[argv[0].num - 1][i]; + focusedScreen = cfg.screenPreferences[newWS - 1][i]; 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"); @@ -301,6 +304,10 @@ const void changeWS(const CommandArg* argv) //EWMH setCurrentDesktop(currWS); } +const void changeWS(const CommandArg* argv) +{ + cWS(argv[0].num); +} const void wToWS(const CommandArg* argv) { Window focusedWindow; @@ -513,7 +520,7 @@ const void reload(const CommandArg* argv) detectScreens(); //Load config again - Err cfgErr = cfg.reload(); + Err cfgErr = cfg.reloadFile(); //Error check handleConfigErrs(cfgErr); @@ -546,22 +553,6 @@ const void nextMonitor(const CommandArg* argv) focusRoot(focusedWorkspaces[focusedScreen]); } -void keyPress(XKeyEvent e) -{ - if(e.same_screen!=1) return; - updateMousePos(); - //cout << "Keypress recieved\n"; - KeySym keysym = XLookupKeysym(&e, 0); - //cout << "\t" << XKeysymToString(keysym) << " super: " << ((e.state & Mod4Mask) == Mod4Mask) << " alt: " << ((e.state & Mod1Mask) == Mod1Mask) << " shift: " << ((e.state & ShiftMask) == ShiftMask) << std::endl; - for(int i = 0; i < cfg.bindsc; i++) - { - if(cfg.binds[i].keysym == keysym && (e.state & cfg.binds[i].modifiers) == cfg.binds[i].modifiers) - { - cfg.binds[i].func(cfg.binds[i].args); - } - } -} - void configureRequest(XConfigureRequestEvent e) { XWindowChanges changes; @@ -811,7 +802,7 @@ void clientMessage(XClientMessageEvent e) log("Client message: " << name); if(e.message_type == XInternAtom(dpy, "_NET_CURRENT_DESKTOP", false)) { - changeWS({.num = (int)((long)e.data.l[0] + 1)}); + cWS(e.data.l[0] + 1); /* //Change desktop int nextWS = (long)e.data.l[0] + 1; @@ -966,11 +957,6 @@ int main(int argc, char** argv) XSetErrorHandler(OnXError); XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask); - for(int i = 0; i < cfg.bindsc; i++) - { - XGrabKey(dpy, XKeysymToKeycode(dpy, cfg.binds[i].keysym), cfg.binds[i].modifiers, root, false, GrabModeAsync, GrabModeAsync); - //log("Grabbing " << XKeysymToString(cfg.binds[i].keysym)); - } XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); //EWMH initEWMH(&dpy, &root, cfg.numWS,cfg. workspaceNames); @@ -1004,7 +990,7 @@ int main(int argc, char** argv) switch(e.type) { case KeyPress: - keyPress(e.xkey); + keybindsModule.keyPress(e.xkey); break; case ConfigureRequest: configureRequest(e.xconfigurerequest); -- cgit v1.2.3 From ea827624d203c73af896669e161972fc8be022ed Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 27 May 2023 16:33:46 +1200 Subject: feat: Made it compile woo Note: doesn't work yet though, as commands haven't all been registered yet --- main.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index e4a4bcc..3f541a1 100644 --- a/main.cpp +++ b/main.cpp @@ -82,7 +82,7 @@ int FFCF(int sID); void detectScreens(); void updateMousePos(); void focusRoot(int root); -void handleConfigErrs(Err cfgErr); +void handleConfigErrs(vector cfgErrs); void configureRequest(XConfigureRequestEvent e); void mapRequest(XMapRequestEvent e); @@ -123,9 +123,9 @@ void detectScreens() log("\t\tw: " << screens[i].w << ", h: " << screens[i].h); XFree(name); } - for(int i = 0; i < cfg.numWS; i++) + for(int i = 0; i < cfg.workspaces.size(); i++) { - if(cfg.screenPreferences[i][0] < nscreens && focusedWorkspaces[cfg.screenPreferences[i][0]] == 0) + if(cfg.workspaces[i].screenPreferences[0] < nscreens && focusedWorkspaces[cfg.workspaces[i].screenPreferences[0]] == 0) { //focusedWorkspaces[screenPreferences[i][0]] = i+1; } @@ -162,9 +162,9 @@ void focusRoot(int root) //log("\tFocusing window: " << w); XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime); } -void handleConfigErrs(Err cfgErr) +void handleConfigErrs(vector cfgErrs) { - if(cfgErr.code!=NOERR) + for(Err cfgErr : cfgErrs) { if(cfgErr.code == CFG_ERR_FATAL) { @@ -268,19 +268,19 @@ void cWS(int newWS) //log("Changing WS with keybind"); - for(int i = 0; i < cfg.maxMonitors; i++) + for(int i = 0; i < nscreens; i++) { - if(nscreens > cfg.screenPreferences[newWS - 1][i]) + if(nscreens > cfg.workspaces[newWS - 1].screenPreferences[i]) { - int screen = cfg.screenPreferences[newWS - 1][i]; + int screen = cfg.workspaces[newWS - 1].screenPreferences[i]; //log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")"); - prevWS = focusedWorkspaces[cfg.screenPreferences[newWS - 1][i]]; + prevWS = focusedWorkspaces[screen]; //log("Changed prevWS"); - focusedWorkspaces[cfg.screenPreferences[newWS - 1][i]] = newWS; + focusedWorkspaces[screen] = newWS; //log("Changed focusedWorkspaces"); - if(focusedScreen != cfg.screenPreferences[newWS - 1][i]) + if(focusedScreen != screen) { - focusedScreen = cfg.screenPreferences[newWS - 1][i]; + 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"); @@ -291,7 +291,8 @@ void cWS(int newWS) //log("Finished changes"); //log(prevWS); - if(prevWS < 1 || prevWS > cfg.numWS) + // LOOK: what is this for????? + if(prevWS < 1 || prevWS > cfg.workspaces.size()) { //untile(prevWS); } @@ -520,7 +521,7 @@ const void reload(const CommandArg* argv) detectScreens(); //Load config again - Err cfgErr = cfg.reloadFile(); + vector cfgErr = cfg.reloadFile(); //Error check handleConfigErrs(cfgErr); @@ -929,8 +930,9 @@ int main(int argc, char** argv) std::string home = getenv("HOME"); std::string pathAfterHome = "/.config/YATwm/config.toml"; std::string file = home + pathAfterHome; - Err cfgErr = cfg.loadFromFile(file); - + // Err cfgErr = cfg.loadFromFile(file); + std::vector cfgErr = cfg.loadFromFile("config"); + //Log yatlog.open(cfg.logFile, std::ios_base::app); @@ -959,7 +961,7 @@ int main(int argc, char** argv) XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); //EWMH - initEWMH(&dpy, &root, cfg.numWS,cfg. workspaceNames); + initEWMH(&dpy, &root, cfg.workspaces.size(), cfg.workspaces); setCurrentDesktop(1); for(int i = 1; i < cfg.numWS + 1; i++) @@ -990,7 +992,7 @@ int main(int argc, char** argv) switch(e.type) { case KeyPress: - keybindsModule.keyPress(e.xkey); + keybindsModule.handleKeypress(e.xkey); break; case ConfigureRequest: configureRequest(e.xconfigurerequest); -- cgit v1.2.3 From 6b3dff404248bcf03e0bf0463a8c53d8918f7eec Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 31 May 2023 20:55:49 +1200 Subject: Added support for commands without a module Also made it easier to add commands by making the ~addCommand~ function accept a vector for ~argTypes~ and then convert it. --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 3f541a1..bf523fd 100644 --- a/main.cpp +++ b/main.cpp @@ -925,6 +925,8 @@ int main(int argc, char** argv) dpy = XOpenDisplay(nullptr); root = Window(DefaultRootWindow(dpy)); + // Adding commands + commandsModule.addCommand("spawn", spawn, 1, {STR_REST}); //Config std::string home = getenv("HOME"); -- cgit v1.2.3 From 01bc6a33eb235cd10851e2c31b99e6840603ca7d Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 1 Jun 2023 12:53:13 +1200 Subject: IT WORKS!!!!!! The new config commands system works, finally able to run this as a test and it works!!!!!. Still more to be done but at least it works. --- main.cpp | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index bf523fd..034554c 100644 --- a/main.cpp +++ b/main.cpp @@ -44,12 +44,14 @@ std::ofstream yatlog; #define log(x) yatlog << x << std::endl -Display* dpy; -Window root; +Globals globals; + +Display*& dpy = globals.dpy; +Window& root = globals.root; CommandsModule commandsModule; Config cfg(commandsModule); -KeybindsModule keybindsModule(commandsModule, dpy, root); +KeybindsModule keybindsModule(commandsModule, globals); int sW, sH; int bH; @@ -514,7 +516,12 @@ const void bashSpawn(const CommandArg* argv) system(argv[0].str); exit(0); } - +} +const void bashSpawnOnce(const CommandArg* argv) +{ + if(cfg.loaded) + return; + else bashSpawn(argv); } const void reload(const CommandArg* argv) { @@ -915,18 +922,29 @@ int main(int argc, char** argv) { const char* version = "YATwm for X\n" - "version 0.0.0"; + "version 0.1.0"; cout << version << endl; return 0; } } //Important init stuff mX = mY = 0; - dpy = XOpenDisplay(nullptr); - root = Window(DefaultRootWindow(dpy)); + globals.dpy = XOpenDisplay(nullptr); + globals.root = Window(DefaultRootWindow(dpy)); // Adding commands + commandsModule.addCommand("exit", exit, 0, {}); commandsModule.addCommand("spawn", spawn, 1, {STR_REST}); + commandsModule.addCommand("toggle", toggle, 0, {}); + commandsModule.addCommand("kill", kill, 0, {}); + commandsModule.addCommand("changeWS", changeWS, 1, {NUM}); + commandsModule.addCommand("wToWS", wToWS, 1, {NUM}); + commandsModule.addCommand("focChange", focChange, 1, {MOVDIR}); + commandsModule.addCommand("bashSpawn", bashSpawn, 1, {STR_REST}); + commandsModule.addCommand("bashSpawnOnce", bashSpawnOnce, 1, {STR_REST}); + commandsModule.addCommand("reload", reload, 0, {}); + commandsModule.addCommand("wsDump", wsDump, 0, {}); + commandsModule.addCommand("nextMonitor", nextMonitor, 0, {}); //Config std::string home = getenv("HOME"); @@ -934,7 +952,7 @@ int main(int argc, char** argv) std::string file = home + pathAfterHome; // Err cfgErr = cfg.loadFromFile(file); std::vector cfgErr = cfg.loadFromFile("config"); - + //Log yatlog.open(cfg.logFile, std::ios_base::app); @@ -946,26 +964,31 @@ int main(int argc, char** argv) //Notifications notify_init("YATwm"); + cout << 0 << endl; //Error check config handleConfigErrs(cfgErr); - + cout << 1 << endl; screens = new ScreenInfo[1]; focusedWorkspaces = new int[1]; detectScreens(); + cout << 2 << endl; int screenNum = DefaultScreen(dpy); sW = DisplayWidth(dpy, screenNum); sH = DisplayHeight(dpy, screenNum); + cout << 3 << endl; XSetErrorHandler(OnXError); XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask); + cout << 4 << endl; XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); //EWMH initEWMH(&dpy, &root, cfg.workspaces.size(), cfg.workspaces); setCurrentDesktop(1); + cout << 5 << endl; for(int i = 1; i < cfg.numWS + 1; i++) { vector v; @@ -973,14 +996,6 @@ int main(int argc, char** argv) frames.insert(pair(i, rootFrame)); currFrameID++; } - for(int i = 0; i < cfg.startupBashc; i++) - { - if(fork() == 0) - { - system((cfg.startupBash[i] + " > /dev/null 2> /dev/null").c_str()); - exit(0); - } - } XSetInputFocus(dpy, root, RevertToNone, CurrentTime); XWarpPointer(dpy, root, root, 0, 0, 0, 0, 960, 540); -- cgit v1.2.3 From e9cc5756dbb0a2d079a7b5e3438d79945f819df5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 3 Jun 2023 21:30:05 +1200 Subject: feat: Keybind updates Re added the ability to swap super and mod as a config parameter (the ~swapmods~) command). Finally fixed keybinds sometimes not working because of numlock, bitwise & with the modifiers I actually care about. --- main.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 034554c..e74634d 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,7 @@ Window& root = globals.root; CommandsModule commandsModule; Config cfg(commandsModule); -KeybindsModule keybindsModule(commandsModule, globals); +KeybindsModule keybindsModule(commandsModule, cfg, globals); int sW, sH; int bH; @@ -527,6 +527,9 @@ const void reload(const CommandArg* argv) { detectScreens(); + //Clear keybinds + keybindsModule.clearKeybinds(); + //Load config again vector cfgErr = cfg.reloadFile(); //Error check @@ -964,31 +967,25 @@ int main(int argc, char** argv) //Notifications notify_init("YATwm"); - cout << 0 << endl; //Error check config handleConfigErrs(cfgErr); - cout << 1 << endl; screens = new ScreenInfo[1]; focusedWorkspaces = new int[1]; detectScreens(); - cout << 2 << endl; int screenNum = DefaultScreen(dpy); sW = DisplayWidth(dpy, screenNum); sH = DisplayHeight(dpy, screenNum); - cout << 3 << endl; XSetErrorHandler(OnXError); XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask); - cout << 4 << endl; XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); //EWMH initEWMH(&dpy, &root, cfg.workspaces.size(), cfg.workspaces); setCurrentDesktop(1); - cout << 5 << endl; for(int i = 1; i < cfg.numWS + 1; i++) { vector v; -- cgit v1.2.3 From 0b539b0b0278f2d7c2b7629e6d28d8463cba2688 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Mon, 5 Jun 2023 20:35:32 +1200 Subject: Added a very basic config, and fixed some stuff NOTE: for some reason toggling doesn't work anymore --- main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index e74634d..2e1f0ad 100644 --- a/main.cpp +++ b/main.cpp @@ -47,11 +47,13 @@ std::ofstream yatlog; Globals globals; Display*& dpy = globals.dpy; -Window& root = globals.root; +Window &root = globals.root; + +void updateMousePos(); CommandsModule commandsModule; Config cfg(commandsModule); -KeybindsModule keybindsModule(commandsModule, cfg, globals); +KeybindsModule keybindsModule(commandsModule, cfg, globals, &updateMousePos); int sW, sH; int bH; @@ -82,7 +84,6 @@ int currWS = 1; // Usefull functions int FFCF(int sID); void detectScreens(); -void updateMousePos(); void focusRoot(int root); void handleConfigErrs(vector cfgErrs); @@ -270,7 +271,7 @@ void cWS(int newWS) //log("Changing WS with keybind"); - for(int i = 0; i < nscreens; i++) + for(int i = 0; i < cfg.workspaces[newWS - 1].screenPreferencesc; i++) { if(nscreens > cfg.workspaces[newWS - 1].screenPreferences[i]) { @@ -304,6 +305,8 @@ void cWS(int newWS) //log("Roots tiled"); XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + cout << focusedWorkspaces[0] << endl; + //EWMH setCurrentDesktop(currWS); } -- cgit v1.2.3 From 5f54adae7bc4edaf2c18383efe13ded233255509 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 16 Jun 2023 00:05:28 +1200 Subject: feat: Uses a backup config file and respects XDG Uses config files in the order of `$XDG_CONFIG_HOME/YATwm/config`, `$HOME/.config/YATwm/config`, then `/etc/YATwm/config` --- main.cpp | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 2e1f0ad..14e43b7 100644 --- a/main.cpp +++ b/main.cpp @@ -44,10 +44,10 @@ std::ofstream yatlog; #define log(x) yatlog << x << std::endl -Globals globals; +Display* dpy; +Window root; -Display*& dpy = globals.dpy; -Window &root = globals.root; +Globals globals = {dpy, root}; void updateMousePos(); @@ -532,13 +532,14 @@ const void reload(const CommandArg* argv) //Clear keybinds keybindsModule.clearKeybinds(); - + //Load config again vector cfgErr = cfg.reloadFile(); //Error check handleConfigErrs(cfgErr); //Re tile + untileRoots(); tileRoots(); } const void wsDump(const CommandArg* argv) @@ -577,7 +578,10 @@ void configureRequest(XConfigureRequestEvent e) changes.border_width = e.border_width; changes.sibling = e.above; changes.stack_mode = e.detail; - XConfigureWindow(dpy, e.window, e.value_mask, &changes); + XConfigureWindow(dpy, e.window, (unsigned int) e.value_mask, &changes); + log("Configure request: " << e.window); + //XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); + //tileRoots(); } void mapRequest(XMapRequestEvent e) @@ -656,7 +660,7 @@ void mapRequest(XMapRequestEvent e) - XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); + XSelectInput(dpy, e.window, EnterWindowMask); //Make client @@ -680,7 +684,7 @@ void mapRequest(XMapRequestEvent e) status = getProp(e.window, "_NET_WM_STATE", &type, &data); if(status == Success && type!=None && (((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_MODAL", false) || ((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_ABOVE", false))) { - log("\tWindow floating"); + cout << "Floating" << endl; clients.find(c.ID)->second.floating = true; frames.find(pID)->second.floatingFrameIDs.push_back(f.ID); frames.insert(pair(f.ID, f)); @@ -736,6 +740,7 @@ void mapRequest(XMapRequestEvent e) updateClientList(clients); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); + XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime); tileRoots(); } @@ -790,10 +795,10 @@ void destroyNotify(XDestroyWindowEvent e) void enterNotify(XEnterWindowEvent e) { //log(e.xcrossing.x); - /* Cancel if crossing into root - if(e.xcrossing.window == root) - break; - */ + //Cancel if crossing into root + if(e.window == root) + return; + XWindowAttributes attr; XGetWindowAttributes(dpy, e.window, &attr); int monitor = 0; @@ -839,7 +844,10 @@ void clientMessage(XClientMessageEvent e) static int OnXError(Display* display, XErrorEvent* e) { - log("XError " << e->type); + char* error = new char[50]; + XGetErrorText(dpy, e->type, error, 50); + log("XError " << error); + delete[] error; return 0; } @@ -935,8 +943,8 @@ int main(int argc, char** argv) } //Important init stuff mX = mY = 0; - globals.dpy = XOpenDisplay(nullptr); - globals.root = Window(DefaultRootWindow(dpy)); + dpy = XOpenDisplay(nullptr); + root = Window(DefaultRootWindow(dpy)); // Adding commands commandsModule.addCommand("exit", exit, 0, {}); @@ -953,11 +961,18 @@ int main(int argc, char** argv) commandsModule.addCommand("nextMonitor", nextMonitor, 0, {}); //Config - std::string home = getenv("HOME"); - std::string pathAfterHome = "/.config/YATwm/config.toml"; - std::string file = home + pathAfterHome; - // Err cfgErr = cfg.loadFromFile(file); - std::vector cfgErr = cfg.loadFromFile("config"); + std::vector cfgErr; + + char* confDir = getenv("XDG_CONFIG_HOME"); + if(confDir != NULL) + { + cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); + } + else + { + string home = getenv("HOME"); + cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + } //Log yatlog.open(cfg.logFile, std::ios_base::app); @@ -981,7 +996,7 @@ int main(int argc, char** argv) sW = DisplayWidth(dpy, screenNum); sH = DisplayHeight(dpy, screenNum); - XSetErrorHandler(OnXError); + //XSetErrorHandler(OnXError); XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask); XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); -- cgit v1.2.3 From 557faa2603d33d6f6a8b7baa9c9f7891bfcb8d30 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sun, 18 Jun 2023 21:31:41 +1200 Subject: feat: Updated readme Updated the readme and added a default config file. --- main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 14e43b7..d4502dd 100644 --- a/main.cpp +++ b/main.cpp @@ -224,6 +224,12 @@ const void spawn(const CommandArg* argv) exit(0); } } +const void spawnOnce(const CommandArg* argv) +{ + if(cfg.loaded) + return; + else spawn(argv); +} const void toggle(const CommandArg* argv) { nextDir = nextDir = (nextDir==horizontal)? vertical : horizontal; @@ -949,6 +955,7 @@ int main(int argc, char** argv) // Adding commands commandsModule.addCommand("exit", exit, 0, {}); commandsModule.addCommand("spawn", spawn, 1, {STR_REST}); + commandsModule.addCommand("spawnOnce", spawnOnce, 1, {STR_REST}); commandsModule.addCommand("toggle", toggle, 0, {}); commandsModule.addCommand("kill", kill, 0, {}); commandsModule.addCommand("changeWS", changeWS, 1, {NUM}); -- cgit v1.2.3