diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2023-06-01 12:53:13 +1200 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2023-06-01 12:53:13 +1200 |
| commit | 01bc6a33eb235cd10851e2c31b99e6840603ca7d (patch) | |
| tree | 2af16074f305328b66e3c2bc731b8245b718a7b6 | |
| parent | 6b3dff404248bcf03e0bf0463a8c53d8918f7eec (diff) | |
| download | YATwm-01bc6a33eb235cd10851e2c31b99e6840603ca7d.tar.gz YATwm-01bc6a33eb235cd10851e2c31b99e6840603ca7d.zip | |
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.
| -rw-r--r-- | commands.cpp | 1 | ||||
| -rw-r--r-- | config | 13 | ||||
| -rw-r--r-- | config.cpp | 42 | ||||
| -rw-r--r-- | config.h | 13 | ||||
| -rw-r--r-- | keybinds.cpp | 27 | ||||
| -rw-r--r-- | keybinds.h | 10 | ||||
| -rw-r--r-- | main.cpp | 49 | ||||
| -rw-r--r-- | util.h | 7 |
8 files changed, 59 insertions, 103 deletions
diff --git a/commands.cpp b/commands.cpp index 549775e..09bdf62 100644 --- a/commands.cpp +++ b/commands.cpp @@ -150,6 +150,7 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA void CommandsModule::runCommand(string command) { + cout << command << endl; vector<string> split = splitCommand(command); Command* cmd = lookupCommand(split[0]); if(cmd == nullptr) @@ -1,15 +1,6 @@ # This is a comment -bind e exit -bind q exit -bind o echo test -bind x spawn notify-send stuff -bind a spawn xterm -bind r reload -spawn "notify-send test" -spawn_once "notify-send once" +bind mod+e exit +bind mod+Return spawn kitty gaps 10 outergaps 10 addworkspace "1: A" 1 -addworkspace "2: B" 1 -addworkspace "5: A" 2 1 -addworkspace "6: B" 2 1
\ No newline at end of file @@ -22,44 +22,6 @@ using std::string; // For testing using std::cout, std::endl; -const void Config::exit(const CommandArg* argv) -{ - cout << "exit called" << endl; -} -const void Config::spawn_once(const CommandArg* argv) -{ - if(loaded) - return; - if(fork() == 0) - { - int null = open("/dev/null", O_WRONLY); - dup2(null, 0); - dup2(null, 1); - dup2(null, 2); - system(argv[0].str); - exit(0); - } -} - -const void Config::changeWS(const CommandArg* argv) -{ - cout << "changeWS called" << endl; -} -const void Config::wToWS(const CommandArg* argv) -{ - cout << "wToWS called" << endl; -} -const void Config::focChange(const CommandArg* argv) -{ - cout << "focChange called" << endl; -} -const void Config::reload(const CommandArg* argv) -{ - // Note: this is kinda broken cos it doesn't ungrab keys, i'll do that later. - cout << "Reloading config" << endl; - reloadFile(); -} - const void Config::gapsCmd(const CommandArg* argv) { gaps = argv[0].num; @@ -86,10 +48,6 @@ const void Config::addWorkspaceCmd(const CommandArg* argv) Config::Config(CommandsModule& commandsModule) : commandsModule(commandsModule) { - //Register commands for keybinds - commandsModule.addCommand("spawn_once", &Config::spawn_once, 1, {STR_REST}, this); - commandsModule.addCommand("reload", &Config::reload, 0, {}, this); - //Register commands for config commandsModule.addCommand("gaps", &Config::gapsCmd, 1, {NUM}, this); commandsModule.addCommand("outergaps", &Config::outerGapsCmd, 1, {NUM}, this); @@ -26,9 +26,6 @@ public: std::vector<Err> loadFromFile(std::string path); std::vector<Err> reloadFile(); - // Startup - std::string* startupBash; - int startupBashc; // Main int gaps; @@ -38,6 +35,8 @@ public: // Workspaces std::vector<Workspace> workspaces; int numWS; + bool loaded = false; + // Config Commands COMMAND(gapsCmd); @@ -45,15 +44,7 @@ public: COMMAND(logFileCmd); COMMAND(addWorkspaceCmd); - // Keybind Commands - COMMAND(exit); - COMMAND(spawn_once); - COMMAND(changeWS); - COMMAND(wToWS); - COMMAND(focChange); - COMMAND(reload); private: CommandsModule& commandsModule; - bool loaded = false; std::string file; }; diff --git a/keybinds.cpp b/keybinds.cpp index ee6892a..30b3fd0 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -10,17 +10,14 @@ using std::string, std::cout, std::endl; -KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Display* dpy, Window root) - :commandsModule(commandsModule) +KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Globals& globals) + :commandsModule(commandsModule), + globals(globals) { - this->dpy = dpy; - this->root = root; CommandArgType* bindArgs = new CommandArgType[2]; bindArgs[0] = STR; bindArgs[1] = STR_REST; commandsModule.addCommand("bind", &KeybindsModule::bind, 2, bindArgs, this); - commandsModule.addCommand("exit", &KeybindsModule::exit, 0, {}, this); - exitNow = false; } const void KeybindsModule::handleKeypress(XKeyEvent e) @@ -29,7 +26,7 @@ const void KeybindsModule::handleKeypress(XKeyEvent e) //updateMousePos(); for(Keybind bind : binds) { - if(bind.modifiers == e.state && bind.key == e.keycode) + if(bind.modifiers == e.state && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0)) { commandsModule.runCommand(bind.command); } @@ -46,6 +43,7 @@ const void KeybindsModule::bind(const CommandArg* argv) } std::vector<string> keys = split(argv[0].str, '+'); Keybind bind; + bind.modifiers = 0; for(string key : keys) { if(key == "mod") @@ -54,7 +52,7 @@ const void KeybindsModule::bind(const CommandArg* argv) } else if(key == "alt") { - bind.modifiers |= Mod1Mask; + bind.modifiers |= Mod4Mask; } else if(key == "shift") { @@ -66,7 +64,8 @@ const void KeybindsModule::bind(const CommandArg* argv) } else { - bind.key = XKeysymToKeycode(dpy, XStringToKeysym(key.c_str())); + KeySym s = XStringToKeysym(key.c_str()); + bind.key = s; if(bind.key == NoSymbol) { throw Err(CFG_ERR_KEYBIND, "Keybind '" + string(argv[0].str) + "' is invalid!"); @@ -74,12 +73,8 @@ const void KeybindsModule::bind(const CommandArg* argv) } } } - XGrabKey(dpy, bind.key, bind.modifiers, root, false, GrabModeAsync, GrabModeAsync); + bind.command = argv[1].str; + KeyCode c = XKeysymToKeycode(globals.dpy, bind.key); + XGrabKey(globals.dpy, c, bind.modifiers, globals.root, False, GrabModeAsync, GrabModeAsync); binds.push_back(bind); } - -const void KeybindsModule::exit(const CommandArg* argv) -{ - exitNow = true; - cout << "Exiting..." << endl; -} @@ -8,24 +8,22 @@ #include <vector> #include "commands.h" +#include "util.h" struct Keybind { - KeyCode key; + KeySym key; unsigned int modifiers; std::string command; }; class KeybindsModule { public: - KeybindsModule(CommandsModule& commandsModule, Display* dpy, Window root); + KeybindsModule(CommandsModule& commandsModule, Globals& globals); ~KeybindsModule() = default; const void bind(const CommandArg* argv); - const void exit(const CommandArg* argv); const void handleKeypress(XKeyEvent e); private: std::vector<Keybind> binds; - bool exitNow; CommandsModule& commandsModule; - Display* dpy; - Window root; + Globals& globals; }; @@ -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<Err> 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<int> v; @@ -973,14 +996,6 @@ int main(int argc, char** argv) frames.insert(pair<int, Frame>(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); @@ -2,8 +2,15 @@ #include <vector> #include <string> +#include <X11/Xlib.h> #define evNames {0, 0, "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify", "GenericEvent", "LASTEvent"}; std::vector<std::string> split (const std::string &s, char delim); + + +struct Globals { + Display* dpy; + Window root; +}; |
