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 --- config | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 config (limited to 'config') diff --git a/config b/config new file mode 100644 index 0000000..3dcab8b --- /dev/null +++ b/config @@ -0,0 +1,15 @@ +# 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" +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 -- cgit v1.3.1 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. --- commands.cpp | 1 + config | 13 ++----------- config.cpp | 42 ------------------------------------------ config.h | 13 ++----------- keybinds.cpp | 27 +++++++++++---------------- keybinds.h | 10 ++++------ main.cpp | 49 ++++++++++++++++++++++++++++++++----------------- util.h | 7 +++++++ 8 files changed, 59 insertions(+), 103 deletions(-) (limited to 'config') 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& split, const CommandA void CommandsModule::runCommand(string command) { + cout << command << endl; vector split = splitCommand(command); Command* cmd = lookupCommand(split[0]); if(cmd == nullptr) diff --git a/config b/config index 3dcab8b..5eb0c4a 100644 --- a/config +++ b/config @@ -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 diff --git a/config.cpp b/config.cpp index 74a4a1d..cff7a45 100644 --- a/config.cpp +++ b/config.cpp @@ -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); diff --git a/config.h b/config.h index e6d6227..b02dc9e 100644 --- a/config.h +++ b/config.h @@ -26,9 +26,6 @@ public: std::vector loadFromFile(std::string path); std::vector reloadFile(); - // Startup - std::string* startupBash; - int startupBashc; // Main int gaps; @@ -38,6 +35,8 @@ public: // Workspaces std::vector 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 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; -} diff --git a/keybinds.h b/keybinds.h index c0cc955..43f6ef3 100644 --- a/keybinds.h +++ b/keybinds.h @@ -8,24 +8,22 @@ #include #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 binds; - bool exitNow; CommandsModule& commandsModule; - Display* dpy; - Window root; + Globals& globals; }; 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); diff --git a/util.h b/util.h index 666fb40..bc3cc6a 100644 --- a/util.h +++ b/util.h @@ -2,8 +2,15 @@ #include #include +#include #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 split (const std::string &s, char delim); + + +struct Globals { + Display* dpy; + Window root; +}; -- cgit v1.3.1 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. --- commands.cpp | 20 ++------------------ commands.h | 2 -- config | 4 ++++ config.cpp | 7 +++++++ config.h | 3 +++ keybinds.cpp | 22 +++++++++++++++++----- keybinds.h | 5 ++++- main.cpp | 11 ++++------- 8 files changed, 41 insertions(+), 33 deletions(-) (limited to 'config') diff --git a/commands.cpp b/commands.cpp index 09bdf62..c41536d 100644 --- a/commands.cpp +++ b/commands.cpp @@ -12,30 +12,15 @@ using std::cout, std::endl, std::string, std::vector, std::tolower; -const void CommandsModule::printHello(const CommandArg* argv) -{ - cout << "Hello" << endl; -} - -const void CommandsModule::echo(const CommandArg* argv) -{ - cout << "Echo: '" << argv[0].str << '\'' << endl; -} - CommandsModule::CommandsModule() { - addCommand("printHello", &CommandsModule::printHello, 0, {}, this); - CommandArgType* args0 = new CommandArgType[1]; - args0[0] = STR_REST; - addCommand("echo", &CommandsModule::echo, 1, args0, this); } CommandsModule::~CommandsModule() { for(Command c : commandList) { - // This is probably needed but its not working - //if(c.argc > 0) - //delete[] c.argTypes; + if(c.argc > 0) + delete[] c.argTypes; } } @@ -150,7 +135,6 @@ CommandArg* CommandsModule::getCommandArgs(vector& split, const CommandA void CommandsModule::runCommand(string command) { - cout << command << endl; vector split = splitCommand(command); Command* cmd = lookupCommand(split[0]); if(cmd == nullptr) diff --git a/commands.h b/commands.h index 92801bd..d7f2351 100644 --- a/commands.h +++ b/commands.h @@ -51,8 +51,6 @@ private: std::vector commandList; std::vector splitCommand(std::string command); CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); - const void printHello(const CommandArg* argv); - const void echo(const CommandArg* argv); public: CommandsModule(); ~CommandsModule(); diff --git a/config b/config index 5eb0c4a..de761d3 100644 --- a/config +++ b/config @@ -1,4 +1,8 @@ # This is a comment + +# Mainly used for testing +swapmods + bind mod+e exit bind mod+Return spawn kitty gaps 10 diff --git a/config.cpp b/config.cpp index cff7a45..6ade520 100644 --- a/config.cpp +++ b/config.cpp @@ -45,6 +45,11 @@ const void Config::addWorkspaceCmd(const CommandArg* argv) numWS++; } +const void Config::swapSuperAltCmd(const CommandArg* argv) +{ + swapSuperAlt ^= true; +} + Config::Config(CommandsModule& commandsModule) : commandsModule(commandsModule) { @@ -53,6 +58,7 @@ Config::Config(CommandsModule& commandsModule) commandsModule.addCommand("outergaps", &Config::outerGapsCmd, 1, {NUM}, this); commandsModule.addCommand("logfile", &Config::logFileCmd, 1, {STR_REST}, this); commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, {STR, NUM_ARR_REST}, this); + commandsModule.addCommand("swapmods", &Config::swapSuperAltCmd, 0, {}, this); } std::vector Config::reloadFile() @@ -72,6 +78,7 @@ std::vector Config::loadFromFile(std::string path) outerGaps = 3; logFile = "/tmp/yatlog.txt"; numWS = 0; + swapSuperAlt = false; //Probably need something for workspaces and binds too... diff --git a/config.h b/config.h index b02dc9e..452db9c 100644 --- a/config.h +++ b/config.h @@ -37,12 +37,15 @@ public: int numWS; bool loaded = false; + // Binds + bool swapSuperAlt; // Config Commands COMMAND(gapsCmd); COMMAND(outerGapsCmd); COMMAND(logFileCmd); COMMAND(addWorkspaceCmd); + COMMAND(swapSuperAltCmd); private: CommandsModule& commandsModule; diff --git a/keybinds.cpp b/keybinds.cpp index 30b3fd0..85e9e4e 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -10,9 +10,10 @@ using std::string, std::cout, std::endl; -KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Globals& globals) +KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals) :commandsModule(commandsModule), - globals(globals) + globals(globals), + cfg(cfg) { CommandArgType* bindArgs = new CommandArgType[2]; bindArgs[0] = STR; @@ -23,10 +24,15 @@ KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Globals& globals) const void KeybindsModule::handleKeypress(XKeyEvent e) { if(e.same_screen!=1) return; + //cout << "Key Pressed" << endl; + //cout << "\tState: " << e.state << endl; + //cout << "\tCode: " << XKeysymToString(XKeycodeToKeysym(globals.dpy, e.keycode, 0)) << endl; //updateMousePos(); + + const unsigned int masks = ShiftMask | ControlMask | Mod1Mask | Mod4Mask; for(Keybind bind : binds) { - if(bind.modifiers == e.state && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0)) + if(bind.modifiers == (e.state & masks) && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0)) { commandsModule.runCommand(bind.command); } @@ -48,11 +54,11 @@ const void KeybindsModule::bind(const CommandArg* argv) { if(key == "mod") { - bind.modifiers |= Mod1Mask; + bind.modifiers |= Mod4Mask >> 3 * cfg.swapSuperAlt; } else if(key == "alt") { - bind.modifiers |= Mod4Mask; + bind.modifiers |= Mod1Mask << 3 * cfg.swapSuperAlt; } else if(key == "shift") { @@ -74,7 +80,13 @@ const void KeybindsModule::bind(const CommandArg* argv) } } bind.command = argv[1].str; + cout << bind.modifiers << endl; 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::clearKeybinds() +{ + XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root); +} diff --git a/keybinds.h b/keybinds.h index 43f6ef3..07d9aea 100644 --- a/keybinds.h +++ b/keybinds.h @@ -8,6 +8,7 @@ #include #include "commands.h" +#include "config.h" #include "util.h" struct Keybind { @@ -18,12 +19,14 @@ struct Keybind { class KeybindsModule { public: - KeybindsModule(CommandsModule& commandsModule, Globals& globals); + KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals); ~KeybindsModule() = default; const void bind(const CommandArg* argv); const void handleKeypress(XKeyEvent e); + const void clearKeybinds(); private: std::vector binds; CommandsModule& commandsModule; + Config& cfg; Globals& globals; }; 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.3.1 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 --- commands.cpp | 52 +++++++++++++++++++++++++++++++--------------------- config | 31 +++++++++++++++++++++++++++++++ config.cpp | 7 ++++++- keybinds.cpp | 6 +++--- keybinds.h | 3 ++- main.cpp | 11 +++++++---- 6 files changed, 80 insertions(+), 30 deletions(-) (limited to 'config') diff --git a/commands.cpp b/commands.cpp index c41536d..141de26 100644 --- a/commands.cpp +++ b/commands.cpp @@ -86,10 +86,9 @@ vector CommandsModule::splitCommand(string command) return v; } -template -std::basic_string lowercase(const std::basic_string& s) +string lowercase(string s) { - std::basic_string s2 = s; + string s2 = s; std::transform(s2.begin(), s2.end(), s2.begin(), [](unsigned char c){ return std::tolower(c); }); return s2; } @@ -103,30 +102,41 @@ CommandArg* CommandsModule::getCommandArgs(vector& split, const CommandA { case STR: args[i-1].str = (char*)split[i].c_str(); break; case NUM: args[i-1].num = std::stoi(split[i]); break; - case MOVDIR: args[i-1].dir = LEFT; break; + case MOVDIR: + { + if(lowercase(split[i]) == "up") + args[i-1].dir = UP; + else if(lowercase(split[i]) == "down") + args[i-1].dir = DOWN; + else if(lowercase(split[i]) == "left") + args[i-1].dir = LEFT; + else if(lowercase(split[i]) == "right") + args[i-1].dir = RIGHT; + break; + } case STR_REST: - { - string rest = ""; - for(int j = i; j < split.size(); j++) { - rest += split[j]; - if(j != split.size() - 1) - rest += " "; + string rest = ""; + for(int j = i; j < split.size(); j++) + { + rest += split[j]; + if(j != split.size() - 1) + rest += " "; + } + args[i-1].str = new char[rest.size()]; + strcpy(args[i-1].str, rest.c_str()); + return args; } - args[i-1].str = new char[rest.size()]; - strcpy(args[i-1].str, rest.c_str()); - return args; - } case NUM_ARR_REST: - { - int* rest = new int[split.size() - i]; - for(int j = 0; j < split.size() - i; j++) { - rest[j] = std::stoi(split[j + i]); + int* rest = new int[split.size() - i]; + for(int j = 0; j < split.size() - i; j++) + { + rest[j] = std::stoi(split[j + i]); + } + args[i-1].numArr = {rest, (int) split.size() - i}; + return args; } - args[i-1].numArr = {rest, (int) split.size() - i}; - return args; - } default: cout << "UH OH SOMETHING IS VERY WRONG" << endl; } } diff --git a/config b/config index de761d3..b046b67 100644 --- a/config +++ b/config @@ -7,4 +7,35 @@ bind mod+e exit bind mod+Return spawn kitty gaps 10 outergaps 10 + +# Tiling +bind mod+t toggle + +# Focus +bind mod+h focChange left +bind mod+j focChange down +bind mod+k focChange up +bind mod+l focChange right + +# Workspaces addworkspace "1: A" 1 +addworkspace "2: B" 1 +addworkspace "3: C" 1 +addworkspace "4: D" 1 +addworkspace "5: E" 1 +addworkspace "6: F" 2 1 +addworkspace "7: G" 2 1 +addworkspace "8: H" 2 1 +addworkspace "9: I" 2 1 +addworkspace "10: J" 2 1 + +bind mod+1 changeWS 1 +bind mod+2 changeWS 2 +bind mod+3 changeWS 3 +bind mod+4 changeWS 4 +bind mod+5 changeWS 5 +bind mod+6 changeWS 6 +bind mod+7 changeWS 7 +bind mod+8 changeWS 8 +bind mod+9 changeWS 9 +bind mod+0 changeWS 10 diff --git a/config.cpp b/config.cpp index 6ade520..b17f0e2 100644 --- a/config.cpp +++ b/config.cpp @@ -40,7 +40,10 @@ const void Config::logFileCmd(const CommandArg* argv) const void Config::addWorkspaceCmd(const CommandArg* argv) { int* prefs = new int[argv[1].numArr.size]; - memcpy(prefs, argv[1].numArr.arr, argv[1].numArr.size * sizeof(int)); + for(int i = 0; i < argv[1].numArr.size; i++) + { + prefs[i] = argv[1].numArr.arr[i] - 1; + } workspaces.push_back({argv[0].str, prefs, argv[1].numArr.size}); numWS++; } @@ -87,6 +90,8 @@ std::vector Config::loadFromFile(std::string path) std::ifstream config(path); while(getline(config, cmd)) { + if(cmd.size() == 0) + continue; if(cmd.at(0) == '#') continue; try diff --git a/keybinds.cpp b/keybinds.cpp index 85e9e4e..6e4abfd 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -10,7 +10,7 @@ using std::string, std::cout, std::endl; -KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals) +KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals, void (*updateMousePos)()) :commandsModule(commandsModule), globals(globals), cfg(cfg) @@ -19,6 +19,7 @@ KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Glob bindArgs[0] = STR; bindArgs[1] = STR_REST; commandsModule.addCommand("bind", &KeybindsModule::bind, 2, bindArgs, this); + this->updateMousePos = updateMousePos; } const void KeybindsModule::handleKeypress(XKeyEvent e) @@ -27,7 +28,7 @@ const void KeybindsModule::handleKeypress(XKeyEvent e) //cout << "Key Pressed" << endl; //cout << "\tState: " << e.state << endl; //cout << "\tCode: " << XKeysymToString(XKeycodeToKeysym(globals.dpy, e.keycode, 0)) << endl; - //updateMousePos(); + updateMousePos(); const unsigned int masks = ShiftMask | ControlMask | Mod1Mask | Mod4Mask; for(Keybind bind : binds) @@ -80,7 +81,6 @@ const void KeybindsModule::bind(const CommandArg* argv) } } bind.command = argv[1].str; - cout << bind.modifiers << endl; KeyCode c = XKeysymToKeycode(globals.dpy, bind.key); XGrabKey(globals.dpy, c, bind.modifiers, globals.root, False, GrabModeAsync, GrabModeAsync); binds.push_back(bind); diff --git a/keybinds.h b/keybinds.h index 07d9aea..686eaf8 100644 --- a/keybinds.h +++ b/keybinds.h @@ -19,7 +19,7 @@ struct Keybind { class KeybindsModule { public: - KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals); + KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals, void (*updateMousePos)()); ~KeybindsModule() = default; const void bind(const CommandArg* argv); const void handleKeypress(XKeyEvent e); @@ -29,4 +29,5 @@ private: CommandsModule& commandsModule; Config& cfg; Globals& globals; + void (*updateMousePos)(); }; 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.3.1 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` --- config | 5 ++++- config.cpp | 12 ++++++++++-- keybinds.cpp | 3 ++- main.cpp | 55 +++++++++++++++++++++++++++++++++++-------------------- makefile | 4 ++-- util.h | 4 ++-- 6 files changed, 55 insertions(+), 28 deletions(-) (limited to 'config') diff --git a/config b/config index b046b67..8ccdc1e 100644 --- a/config +++ b/config @@ -4,10 +4,13 @@ swapmods bind mod+e exit -bind mod+Return spawn kitty +bind mod+Return spawn alacritty +bind mod+k spawn kitty gaps 10 outergaps 10 +bind mod+r reload + # Tiling bind mod+t toggle diff --git a/config.cpp b/config.cpp index b17f0e2..5200a4b 100644 --- a/config.cpp +++ b/config.cpp @@ -74,20 +74,28 @@ std::vector Config::reloadFile() std::vector Config::loadFromFile(std::string path) { std::vector errs; - + file = path; + + std::ifstream config(path); + if(!config.good()) + { + config = std::ifstream("/etc/YATwm/config"); + errs.push_back({CFG_ERR_FATAL, "Using default config: /etc/YATwm/config"}); + } + //Set defaults gaps = 3; outerGaps = 3; logFile = "/tmp/yatlog.txt"; numWS = 0; swapSuperAlt = false; + workspaces = std::vector(); //Probably need something for workspaces and binds too... string cmd; int line = 0; - std::ifstream config(path); while(getline(config, cmd)) { if(cmd.size() == 0) diff --git a/keybinds.cpp b/keybinds.cpp index 6e4abfd..3a431f0 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -33,7 +33,7 @@ const void KeybindsModule::handleKeypress(XKeyEvent e) const unsigned int masks = ShiftMask | ControlMask | Mod1Mask | Mod4Mask; for(Keybind bind : binds) { - if(bind.modifiers == (e.state & masks) && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0)) + if(bind.modifiers == (e.state & masks) && bind.key == XLookupKeysym(&e, 0)) { commandsModule.runCommand(bind.command); } @@ -89,4 +89,5 @@ const void KeybindsModule::bind(const CommandArg* argv) const void KeybindsModule::clearKeybinds() { XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root); + binds = std::vector(); } 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)); diff --git a/makefile b/makefile index 01e6b5d..df4304a 100644 --- a/makefile +++ b/makefile @@ -18,9 +18,9 @@ $(OBJS_DIR)/%.o : $(SOURCE_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ i: $(EXEC) - sudo install -D $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC) + sudo install -D -m 755 $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC) sudo install -D -m 644 yat.desktop $(INSTALL_DIR)usr/share/xsessions/yat.desktop - sudo install -D -m 644 config.toml $(INSTALL_DIR)etc/YATwm/config.toml + sudo install -D -m 644 config $(INSTALL_DIR)etc/YATwm/config install: i r: sudo rm $(INSTALL_DIR)usr/bin/$(EXEC) diff --git a/util.h b/util.h index bc3cc6a..bdc45d8 100644 --- a/util.h +++ b/util.h @@ -11,6 +11,6 @@ std::vector split (const std::string &s, char delim); struct Globals { - Display* dpy; - Window root; + Display*& dpy; + Window& root; }; -- cgit v1.3.1 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. --- config | 13 +- config.cpp | 4 +- keybinds.cpp | 5 +- main.cpp | 7 + readme.html | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.org | 100 +++++++++---- 6 files changed, 563 insertions(+), 36 deletions(-) create mode 100644 readme.html (limited to 'config') diff --git a/config b/config index 8ccdc1e..f97bb04 100644 --- a/config +++ b/config @@ -1,15 +1,18 @@ # This is a comment # Mainly used for testing -swapmods +# swapmods -bind mod+e exit +bind mod+shift+e exit bind mod+Return spawn alacritty -bind mod+k spawn kitty +bind mod+c spawn firefox +bind mod+x spawn loginctl lock-session +bind mod+shift+x bashSpawn loginctl lock-session && systemctl suspend gaps 10 outergaps 10 -bind mod+r reload +bind mod+shift+r reload +bind mod+q kill # Tiling bind mod+t toggle @@ -42,3 +45,5 @@ bind mod+7 changeWS 7 bind mod+8 changeWS 8 bind mod+9 changeWS 9 bind mod+0 changeWS 10 + +spawnOnce xss-lock --transfer-sleep-lock -- i3lock -et --nofork \ No newline at end of file diff --git a/config.cpp b/config.cpp index 5200a4b..27ecb6a 100644 --- a/config.cpp +++ b/config.cpp @@ -85,8 +85,8 @@ std::vector Config::loadFromFile(std::string path) } //Set defaults - gaps = 3; - outerGaps = 3; + gaps = 10; + outerGaps = 10; logFile = "/tmp/yatlog.txt"; numWS = 0; swapSuperAlt = false; diff --git a/keybinds.cpp b/keybinds.cpp index 3a431f0..64d3fc8 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -15,10 +15,7 @@ KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Glob globals(globals), cfg(cfg) { - CommandArgType* bindArgs = new CommandArgType[2]; - bindArgs[0] = STR; - bindArgs[1] = STR_REST; - commandsModule.addCommand("bind", &KeybindsModule::bind, 2, bindArgs, this); + commandsModule.addCommand("bind", &KeybindsModule::bind, 2, {STR, STR_REST}, this); this->updateMousePos = updateMousePos; } 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}); diff --git a/readme.html b/readme.html new file mode 100644 index 0000000..38a81bc --- /dev/null +++ b/readme.html @@ -0,0 +1,470 @@ + + + + + + + +YATwm + + + + +
+

YATwm

+ +
+

1. This config is best read in Emacs!

+
+ +
+

2. Disclaimer: This is still very much in beta

+
+

+This only just works, multiple monitors aren't supported and floating windows cannot move and there is no resizing. Many features are just hacked together and are likely to break. However, it is just about usable so if you really want to try then go for it! (feel free to make an issue if you have any questions).
+

+
+
+ +
+

3. Usage instructions

+
+
+
+

3.1. Installation

+
+
+
+

3.1.1. Pre reqs

+
+
    +
  • Xlib and g++ and libnotify to build the program
  • +
  • Xephyr for the test script
  • +
  • rofi, alacritty, and i3lock for the default config
    +
      +
    • The current default config is currently just the configuration that I want to use (this will likely change)
    • +
  • +
+
+
+
+

3.1.2. Installing and removing

+
+
    +
  • make i or make install to install
  • +
  • make r or make remove to remove
  • +
  • ./test to test
  • +
+
+
+
+
+

3.2. Config

+
+

+You can configure YATwm with the config file in $HOME/.config/YATwm/config or $XDG_CONFIG_HOME/YATwm/config if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to /etc/YATwm/config.
+It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in /etc/YATwm/config.
+

+
+
+

3.2.1. Syntax

+
+

+The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the gaps command like this gaps 10 (make sure this is all there is on that line). This says to call the command gaps with the arguments of 10. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. addWorkspace "1: A" 1, here the arguments are 1: A and 1.
+

+
+
    +
  1. Command arg types
    +
    +
      +
    • String: this is just some text, this can be wrapped in quotes if you want a space in it.
    • +
    • String rest: This will only ever be the final argument. This just takes the rest of the line as a string, so you can use spaces without needing quotes.
    • +
    • Number: This is a number, with the digits 0-9.
    • +
    • Number array rest: This will only ever be the final argument. This takes the rest of the line as a list of number, separated with spaces, e.g. 2 1 3.
    • +
    • Direction: This is one of the cardinal directions listed below.
      +
        +
      • left
      • +
      • right
      • +
      • up
      • +
      • down
      • +
    • +
    +
    +
  2. +
  3. List of commands
    +
    +
      +
    • exit: shuts down YATwm
    • +
    • spawn: Spawns an application using execvp
      +
        +
      • String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes)
      • +
    • +
    • spawnOnce: Same as spawn but only runs on the first load of the config file
      +
        +
      • String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes)
      • +
    • +
    • toggle: Changes the tiling direction for the next window
    • +
    • kill: Kills the focused window
    • +
    • changeWS: changes to a different workspace
      +
        +
      • Number: Which workspace to change to, starts at 1 for first workspace.
      • +
    • +
    • wToWS: moves a window to a workspace
      +
        +
      • Number: Which workspace to move the window to, starts at 1 for first workspace.
      • +
    • +
    • focChange: Changes the focus in a direction
      +
        +
      • Direction: Which direction to focus in
      • +
    • +
    • bashSpawn: Spawns something uses system (your shell)
      +
        +
      • String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes)
      • +
    • +
    • bashSpawnOnce: Same as bashSpawn but only runs on the first load of the config file
      +
        +
      • String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes)
      • +
    • +
    • reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them.
    • +
    • nextMonitor: Focuses the next monitor, wraps around.
    • +
    • gaps: Sets the size of the inner gaps, margins around each window (this ends up looking doubled as each window has it)
      +
        +
      • Number: The size in pixels
      • +
    • +
    • outergaps: Sets the size of the outer gaps, distance for windows and the edge of the output (add this to the inner gaps to get distance between window and edge of output)
      +
        +
      • Number: The size in pixels
      • +
    • +
    • logfile: The file to write the log to
      +
        +
      • String: The name of the file
      • +
    • +
    • swapmods: Swaps super and alt for keybinds
    • +
    • addworkspace: Adds a workspace (note: This doesn't work very well with refreshes, I'd suggest not messing with it, but you can probably change the names of workspace without anything breaking)
      +
        +
      • String: The name of the workspace
      • +
      • Number array rest: The monitor preferences. This is which monitor it should appear on, first (primary) monitor is one. E.g. 2 1 to appear on the second monitor first, but if that isn't plugged in then use the first.
      • +
    • +
    • bind: Binds a key to a command
      +
        +
      • String: The key bind, modifiers and keys are separated with +, e.g. mod+x
      • +
      • String rest: The command to run
      • +
    • +
    • wsDump: This is a command for testing, you probably don't want to use it
    • +
    +
    +
  4. +
+
+
+

3.2.2. General

+
+

+You can change either the inner gaps (padding around each window - so double it for space between windows), or the outer gaps (padding around the display - add to inner gaps to get space between window and screen edges).
+They can be changed with the commands gaps and outerGaps in the config file (default 10 for both).
+YATwm also keeps a log file, the location of this file can be changed with the command logFile (default /tmp/yatlog.txt).
+

+
+
+ +
+

3.2.3. Workspaces

+
+

+You can add workspace with the command addworkspace in the config file.
+

+
+addworkspace "1: A" 1
+addworkspace "2: B" 1
+
+

+Defaults workspace are listed below (these are the args for the addworkspace command):
+

+
    +
  1. "1: A" 1
  2. +
  3. "2: B" 1
  4. +
  5. "3: C" 1
  6. +
  7. "4: D" 1
  8. +
  9. "5: E" 1
  10. +
  11. "6: F" 2 1
  12. +
  13. "7: G" 2 1
  14. +
  15. "8: H" 2 1
  16. +
  17. "9: I" 2 1
  18. +
  19. "10: J" 2 1
  20. +
+
+
+
+

3.2.4. Keybinds

+
+

+Current keybinds (these can all be edited):
+

+
    +
  • mod + e : exit
  • +
  • mod + t : change next tile direction
  • +
  • mod + q : quit focused window
  • +
  • mod + shift + r : reload WM (rechecks monitors)
  • +
  • mod + direction : change focus in direction (vim keybinds)
  • +
  • mod + shift + direction : move window in direction (vim keybinds)
  • +
  • mod + enter : alacritty
  • +
  • mod + d : rofi
  • +
  • mod + c : firefox
  • +
  • mod + x : lock
  • +
  • mod + shift + x : lock and sleep
  • +
  • mod + (num) : switch to workspace (num) - currently only for 1-10 but you can add more
  • +
  • mod + shift + (num) : move window to workspace (num) - currently only for 1-10 but you can add more
  • +
+

+(mod is super, and the direction keys are h, j, k, l - left, down, up, right respectively like vim)
+

+ +

+You can use the command swapmods to make mod act as alt and alt act as mod.
+

+ +

+To add new keybinds use the bind command:
+

+
+bind mod+q kill
+bind mod+shift+x bashSpawn loginctl lock-session && systemctl suspend
+
+

+Commands are executed going down the list and multiple commands with the same keybind and modifiers will all be executed
+

+
+
+
+
+ +
+

4. Credits

+ +
+
+
+

Created: 2023-06-18 Sun 21:31

+

Validate

+
+ + diff --git a/readme.org b/readme.org index 46a4753..4ccee0d 100644 --- a/readme.org +++ b/readme.org @@ -1,6 +1,6 @@ #+TITLE: YATwm #+OPTIONS: \n:t -* This config is best read in emacs! +* This config is best read in Emacs! * Disclaimer: This is still very much in beta This only just works, multiple monitors aren't supported and floating windows cannot move and there is no resizing. Many features are just hacked together and are likely to break. However, it is just about usable so if you really want to try then go for it! (feel free to make an issue if you have any questions). @@ -10,58 +10,106 @@ This only just works, multiple monitors aren't supported and floating windows ca *** Pre reqs - ~Xlib~ and ~g++~ and ~libnotify~ to build the program - ~Xephyr~ for the test script -- ~rofi~, ~alacritty~, ~picom~, ~feh~, ~polybar~, ~qutebrowser~ and ~i3lock~ for the default config +- ~rofi~, ~alacritty~, and ~i3lock~ for the default config - The current default config is currently just the configuration that I want to use (this will likely change) *** Installing and removing - ~make i~ or ~make install~ to install - ~make r~ or ~make remove~ to remove - ~./test~ to test ** Config -You can configure YATwm with the config file in ~$HOME/.config/YATwm/config.toml~. I have provided an example config file in this directory that has all the variables set to their defaults. -It should alert you with a notification if you have an error, and put the error your log file. It will just use default values if you didn't provide them or provided invalid values (apart from keybinds and startupBash entries, which will just be skipped if invalid (but defaults will be used if the whole array is missing). -*** Startup -Add a bash command to the ~startupBash~ string array in your config and it will execute on startup. +You can configure YATwm with the config file in ~$HOME/.config/YATwm/config~ or ~$XDG_CONFIG_HOME/YATwm/config~ if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to ~/etc/YATwm/config~. +It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in ~/etc/YATwm/config~. +*** Syntax +The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the ~gaps~ command like this ~gaps 10~ (make sure this is all there is on that line). This says to call the command ~gaps~ with the arguments of ~10~. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. ~addWorkspace "1: A" 1~, here the arguments are ~1: A~ and ~1~. +**** Command arg types +- String: this is just some text, this can be wrapped in quotes if you want a space in it. +- String rest: This will only ever be the final argument. This just takes the rest of the line as a string, so you can use spaces without needing quotes. +- Number: This is a number, with the digits 0-9. +- Number array rest: This will only ever be the final argument. This takes the rest of the line as a list of number, separated with spaces, e.g. ~2 1 3~. +- Direction: This is one of the cardinal directions listed below. + - left + - right + - up + - down +**** List of commands +- exit: shuts down YATwm +- spawn: Spawns an application using ~execvp~ + - String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes) +- spawnOnce: Same as spawn but only runs on the first load of the config file + - String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes) +- toggle: Changes the tiling direction for the next window +- kill: Kills the focused window +- changeWS: changes to a different workspace + - Number: Which workspace to change to, starts at 1 for first workspace. +- wToWS: moves a window to a workspace + - Number: Which workspace to move the window to, starts at 1 for first workspace. +- focChange: Changes the focus in a direction + - Direction: Which direction to focus in +- bashSpawn: Spawns something uses ~system~ (your shell) + - String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes) +- bashSpawnOnce: Same as bashSpawn but only runs on the first load of the config file + - String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes) +- reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them. +- nextMonitor: Focuses the next monitor, wraps around. +- gaps: Sets the size of the inner gaps, margins around each window (this ends up looking doubled as each window has it) + - Number: The size in pixels +- outergaps: Sets the size of the outer gaps, distance for windows and the edge of the output (add this to the inner gaps to get distance between window and edge of output) + - Number: The size in pixels +- logfile: The file to write the log to + - String: The name of the file +- swapmods: Swaps super and alt for keybinds +- addworkspace: Adds a workspace (note: This doesn't work very well with refreshes, I'd suggest not messing with it, but you can probably change the names of workspace without anything breaking) + - String: The name of the workspace + - Number array rest: The monitor preferences. This is which monitor it should appear on, first (primary) monitor is one. E.g. ~2 1~ to appear on the second monitor first, but if that isn't plugged in then use the first. +- bind: Binds a key to a command + - String: The key bind, modifiers and keys are separated with +, e.g. ~mod+x~ + - String rest: The command to run +- wsDump: This is a command for testing, you probably don't want to use it *** General You can change either the inner gaps (padding around each window - so double it for space between windows), or the outer gaps (padding around the display - add to inner gaps to get space between window and screen edges). -They can be changed with the integers ~gaps~ and ~outerGaps~ in the config file. -YATwm also keeps a log file, the location of this file can be changed with the string ~logFile~. +They can be changed with the commands ~gaps~ and ~outerGaps~ in the config file (default ~10~ for both). +YATwm also keeps a log file, the location of this file can be changed with the command ~logFile~ (default ~/tmp/yatlog.txt~). *** Workspaces -You can change the number of workspaces by editing ~numWS~ in the config file (this will likely change), and the names by editing ~workspaceNames~. You can think of workspaces as virtual desktops. You can change the preference of workspaces by editing the ~screenPreferences~ array. It orders the screens with 0 being the first monitor and they go up from there. The number coming first for each workspace will be the highest priority and other ones will be used if that monitor is not detected. All preference arrays should end in 0. You can use maxMonitors to set how many is the max amount of monitors you would have plugged in (this will likely change). +You can add workspace with the command ~addworkspace~ in the config file. +#+begin_src +addworkspace "1: A" 1 +addworkspace "2: B" 1 +#+end_src +Defaults workspace are listed below (these are the args for the addworkspace command): +1. "1: A" 1 +2. "2: B" 1 +3. "3: C" 1 +4. "4: D" 1 +5. "5: E" 1 +6. "6: F" 2 1 +7. "7: G" 2 1 +8. "8: H" 2 1 +9. "9: I" 2 1 +10. "10: J" 2 1 *** Keybinds Current keybinds (these can all be edited): - ~mod + e~ : exit - ~mod + t~ : change next tile direction - ~mod + q~ : quit focused window - ~mod + shift + r~ : reload WM (rechecks monitors) -- ~mod + direction~ : change focus in direction -- ~mod + shift + direction~ : move window in direction +- ~mod + direction~ : change focus in direction (vim keybinds) +- ~mod + shift + direction~ : move window in direction (vim keybinds) - ~mod + enter~ : alacritty - ~mod + d~ : rofi - ~mod + c~ : firefox - ~mod + x~ : lock - ~mod + shift + x~ : lock and sleep -- ~mod + p~ : log testing stuff - ~mod + (num)~ : switch to workspace (num) - currently only for 1-10 but you can add more - ~mod + shift + (num)~ : move window to workspace (num) - currently only for 1-10 but you can add more (mod is super, and the direction keys are h, j, k, l - left, down, up, right respectively like vim) -You can use the variable ~swapSuperAlt~ to make ~mod~ act as ~alt~ and ~alt~ act as ~mod~. +You can use the command ~swapmods~ to make ~mod~ act as ~alt~ and ~alt~ act as ~mod~. -To add new keybinds create a new entry in the Keybinds.key array: -#+begin_src -[[Keybinds.key]] -bind = "bind" -func = "func" -args = args -#+end_src -Args can be either a string or a number, directions are strings. -e.g. +To add new keybinds use the bind command: #+begin_src -[[Keybinds.key]] -bind = "mod+shift+j" -func = "wMove" -args = "Down" +bind mod+q kill +bind mod+shift+x bashSpawn loginctl lock-session && systemctl suspend #+end_src Commands are executed going down the list and multiple commands with the same keybind and modifiers will all be executed -- cgit v1.3.1