From aa1500fea32db04c9e4fe72786ebd7e3479b6a8a Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 15:14:05 +1300 Subject: feat: Commands restructure + home manager module now makes config Commands module is now a separate libraray that the flake includes. The home manager module will now auto generate the config and has options for different things such as keybinds, gaps, workspaces, etc. --- src/IPC.h | 2 +- src/commands.cpp | 335 ------------------------------------------------------- src/commands.h | 89 --------------- src/config.cpp | 5 +- src/config.h | 2 +- src/keybinds.cpp | 5 +- src/keybinds.h | 2 +- src/main.cpp | 3 +- 8 files changed, 11 insertions(+), 432 deletions(-) delete mode 100644 src/commands.cpp delete mode 100644 src/commands.h (limited to 'src') diff --git a/src/IPC.h b/src/IPC.h index e0bbcee..0705c2b 100644 --- a/src/IPC.h +++ b/src/IPC.h @@ -3,7 +3,7 @@ #include #include -#include "commands.h" +#include #include "config.h" #include "util.h" diff --git a/src/commands.cpp b/src/commands.cpp deleted file mode 100644 index 5688da4..0000000 --- a/src/commands.cpp +++ /dev/null @@ -1,335 +0,0 @@ -#include "commands.h" -#include "error.h" -#include "util.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using std::cout, std::endl, std::string, std::vector; - -const void CommandsModule::echo(const CommandArg* argv) -{ - cout << argv[0].str << endl; -} - -CommandsModule::CommandsModule() -{ - addCommand("echo", &CommandsModule::echo, 1, {STR_REST}, this); -} -CommandsModule::~CommandsModule() -{ - for(Command c : commandList) - { - if(c.argc > 0) - delete[] c.argTypes; - } -} - -void CommandsModule::addCommand(Command c) -{ - if(lookupCommand(c.name) != nullptr) - { - cout << "Duplicate command: " << c.name << endl; - } - commandList.push_back(c); -} -void CommandsModule::addCommand(std::string name, const void (*func)(const CommandArg *), const int argc, CommandArgType *argTypes) -{ - Command c = {name, nullptr, func, argc, argTypes, nullptr}; - addCommand(c); -} -void CommandsModule::addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes) -{ - CommandArgType* argTypesArr = new CommandArgType[argc]; - for(int i = 0; i < argc; i++) - { - argTypesArr[i] = argTypes[i]; - } - addCommand(name, func, argc, argTypesArr); -} - -struct NameMatches -{ - NameMatches(string s): s_{s} {} - bool operator()(Command c) { return (c.name == s_); } - string s_; -}; - -Command* CommandsModule::lookupCommand(string name) -{ - auto elem = std::find_if(commandList.begin(), commandList.end(), NameMatches(name)); - if (elem != commandList.end()) - { - int i = elem - commandList.begin(); - return &(commandList[i]); - } - else - { - return nullptr; - } -} - -vector CommandsModule::splitCommand(string command) -{ - vector v; - string arg = ""; - bool inQuotes = false; - bool escapeNext = true; - char quoteType; - for(int i = 0; i < command.size(); i++) - { - if(escapeNext) - { - arg += command[i]; - escapeNext = false; - } - else if(command[i] == '\\') - { - escapeNext = true; - } - else if(inQuotes) - { - if(command[i] == quoteType) - { - if(arg != "") - { - v.push_back(arg); - arg = ""; - } - inQuotes = false; - } - else - { - arg += command[i]; - } - } - else - { - if(command[i] == ' ') - { - if(arg != "") - { - v.push_back(arg); - arg = ""; - } - } - else if(command[i] == '"' || command[i] == '\'') - { - inQuotes = true; - quoteType = command[i]; - } - else - { - arg += command[i]; - } - } - } - if(arg != "") - v.push_back(arg); - return v; -} - -CommandArg* CommandsModule::getCommandArgs(vector& split, const CommandArgType* argTypes, const int argc) -{ - CommandArg* args = new CommandArg[argc]; - for(int i = 1; i < argc + 1; i++) - { - switch(argTypes[i-1]) - { - case STR: args[i-1].str = (char*)split[i].c_str(); break; - case NUM: - { - try - { - args[i-1].num = std::stoi(split[i]); - break; - } - catch(std::invalid_argument e) - { - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); - } - } - 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; - else - { - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!"); - } - break; - } - case STR_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()]; - strncpy(args[i-1].str, rest.c_str(), rest.size()); - return args; - } - case NUM_ARR_REST: - { - int* rest = new int[split.size() - i]; - for(int j = 0; j < split.size() - i; j++) - { - try - { - rest[j] = std::stoi(split[j + i]); - } - catch(std::invalid_argument e) - { - delete[] rest; - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); - } - } - args[i-1].numArr = {rest, (int) split.size() - i}; - return args; - } - default: cout << "UH OH SOMETHING IS VERY WRONG" << endl; - } - } - return args; -} - -void CommandsModule::runCommand(string command) -{ - vector split = splitCommand(command); - vector::const_iterator start = split.begin(); - int count = 0; - for(string s : split) - { - if(s == ";") - { - vector::const_iterator end = start + count; - vector partialCmd(start, end); - runCommand(partialCmd); - count = 0; - start = end + 1; - } - else - { - count++; - } - } - if(start != split.end()) - { - vector partialCmd(start, (vector::const_iterator)split.end()); - runCommand(partialCmd); - } -} -void CommandsModule::runCommand(vector split) -{ - Command* cmd = lookupCommand(split[0]); - if(cmd == nullptr) - throw Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); - if(cmd->argc > split.size() - 1) - throw Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); - CommandArg* args; - try - { - args = getCommandArgs(split, cmd->argTypes, cmd->argc); - } - catch(Err e) - { - throw e; - } - try - { - if(cmd->module == nullptr) - cmd->staticFunc(args); - else - cmd->func(*cmd->module, args); - } - catch (Err e) - { - for(int i = 0; i < cmd->argc; i++) - { - if(cmd->argTypes[i] == STR_REST) - delete[] args[i].str; - } - delete[] args; - throw e; - } - for(int i = 0; i < cmd->argc; i++) - { - if(cmd->argTypes[i] == STR_REST) - delete[] args[i].str; - } - delete[] args; -} - -vector CommandsModule::checkCommand(string command) -{ - vector errs; - vector split = splitCommand(command); - vector::const_iterator start = split.begin(); - int count = 0; - for(string s : split) - { - if(s == ";") - { - vector::const_iterator end = start + count; - vector partialCmd(start, end); - errs.push_back(checkCommand(partialCmd)); - count = 0; - start = end + 1; - } - else - { - count++; - } - } - if(start != split.end()) - { - vector partialCmd(start, (vector::const_iterator)split.end()); - errs.push_back(checkCommand(partialCmd)); - } - return errs; -} - -Err CommandsModule::checkCommand(vector split) -{ - Command* cmd = lookupCommand(split[0]); - if(cmd == nullptr) - return Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); - if(cmd->argc > split.size()) - return Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); - CommandArg* args; - try - { - args = getCommandArgs(split, cmd->argTypes, cmd->argc); - } - catch(Err e) - { - return e; - } - for(int i = 0; i < cmd->argc; i++) - { - if(cmd->argTypes[i] == STR_REST || cmd->argTypes[i] == NUM_ARR_REST) - delete[] args[i].str; - } - delete[] args; - return Err(NOERR, ""); -} diff --git a/src/commands.h b/src/commands.h deleted file mode 100644 index af4a4a0..0000000 --- a/src/commands.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "error.h" - -#include -#include -#include -#include - -enum MoveDir - { - UP, - RIGHT, - DOWN, - LEFT - }; -enum CommandArgType - { - STR, - NUM, - MOVDIR, - STR_REST, - NUM_ARR_REST - }; - -struct NumArr -{ - int* arr; - int size; -}; -typedef union -{ - char* str; - int num; - NumArr numArr; - MoveDir dir; -} CommandArg; - -struct Command -{ - const std::string name; - const std::function func; - const std::function staticFunc; - const int argc; - CommandArgType* argTypes; - std::any* module; -}; -class CommandsModule -{ -private: - std::vector commandList; - std::vector splitCommand(std::string command); - CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); - const void echo(const CommandArg* argv); -public: - CommandsModule(); - ~CommandsModule(); - template - void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module); - void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes); - template - void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module); - void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes); - void addCommand(Command c); - Command* lookupCommand(std::string name); - void runCommand(std::string command); - void runCommand(std::vector split); - std::vector checkCommand(std::string command); - Err checkCommand(std::vector split); -}; - -// YES I KNOW THIS IS BAD -// but it needs to be done this way -template -void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module) -{ - Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module}; - addCommand(c); -} -template -void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module) -{ - CommandArgType* argTypesArr = new CommandArgType[argc]; - for(int i = 0; i < argc; i++) - { - argTypesArr[i] = argTypes[i]; - } - addCommand(name, func, argc, argTypesArr, module); -} diff --git a/src/config.cpp b/src/config.cpp index 925e6ea..df195aa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,6 +1,7 @@ #include "config.h" -#include "commands.h" -#include "error.h" +#include +//TODO: FIX THIS +#include #include diff --git a/src/config.h b/src/config.h index 452db9c..b04753f 100644 --- a/src/config.h +++ b/src/config.h @@ -1,8 +1,8 @@ #pragma once -#include "commands.h" #include #include +#include #include #include diff --git a/src/keybinds.cpp b/src/keybinds.cpp index 235f8c1..127a534 100644 --- a/src/keybinds.cpp +++ b/src/keybinds.cpp @@ -7,8 +7,9 @@ #include #include -#include "commands.h" -#include "error.h" +#include +//TODO: FIX THIS +#include #include "keybinds.h" #include "util.h" diff --git a/src/keybinds.h b/src/keybinds.h index a742240..5fd4fba 100644 --- a/src/keybinds.h +++ b/src/keybinds.h @@ -8,7 +8,7 @@ #include #include -#include "commands.h" +#include #include "config.h" #include "util.h" diff --git a/src/main.cpp b/src/main.cpp index da1ae9b..3e01b4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,7 +36,8 @@ #include "config.h" #include "util.h" #include "ewmh.h" -#include "error.h" +//TODO: FIX THIS +#include using std::cout; using std::string; -- cgit v1.3.1 From e9c351d109439ca27c472f0d8d5f8a530ce24033 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 20:28:39 +1300 Subject: revert: Added the commands library back to the source --- YATwm.nix | 1 - flake.lock | 6 +- flake.nix | 5 - makefile | 3 +- src/IPC.h | 2 +- src/commands.cpp | 372 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/commands.h | 91 ++++++++++++++ src/config.cpp | 5 +- src/config.h | 2 +- src/keybinds.cpp | 5 +- src/keybinds.h | 2 +- 11 files changed, 475 insertions(+), 19 deletions(-) create mode 100644 src/commands.cpp create mode 100644 src/commands.h (limited to 'src') diff --git a/YATwm.nix b/YATwm.nix index 515fad5..be7cd2d 100644 --- a/YATwm.nix +++ b/YATwm.nix @@ -33,6 +33,5 @@ runHook postInstall xorg.libXrandr libnotify pkg-config - inputs.libCommands.packages.x86_64-linux.default ]; } diff --git a/flake.lock b/flake.lock index d22a24f..af0e49b 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1734323986, - "narHash": "sha256-m/lh6hYMIWDYHCAsn81CDAiXoT3gmxXI9J987W5tZrE=", + "lastModified": 1735141468, + "narHash": "sha256-VIAjBr1qGcEbmhLwQJD6TABppPMggzOvqFsqkDoMsAY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "394571358ce82dff7411395829aa6a3aad45b907", + "rev": "4005c3ff7505313cbc21081776ad0ce5dfd7a3ce", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index da92073..8d97f64 100644 --- a/flake.nix +++ b/flake.nix @@ -2,10 +2,6 @@ description = "YATwm"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; - libCommands = { - url = "github:BossCode45/commands"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = { self, nixpkgs, ... }@inputs: let pkgs = nixpkgs.legacyPackages.x86_64-linux; @@ -20,7 +16,6 @@ pkgs.libnotify pkgs.pkg-config pkgs.clang-tools - inputs.libCommands.packages.x86_64-linux.default ]; }; packages.x86_64-linux.YATwm = (pkgs.callPackage ./YATwm.nix {inherit inputs;}); diff --git a/makefile b/makefile index 3a12ea4..991a02a 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ .PHONY: clean CXX := g++ CXXFLAGS := -std=c++17 `pkg-config --cflags --libs libnotify`# -g -fsanitize=address -fno-omit-frame-pointer -LINKFLAGS := -lX11 -lXrandr -lcommands +LINKFLAGS := -lX11 -lXrandr OBJS_DIR := ./build OUT_DIR := ./out SOURCE_DIR := ./src @@ -32,6 +32,7 @@ remove: r #Files to be compiled $(OBJS_DIR)/main.o: $(SOURCE_FILES) $(SOURCE_HEADERS) $(OBJS_DIR)/ewmh.o: $(SOURCE_DIR)/ewmh.cpp $(SOURCE_DIR)/ewmh.h +$(OBJS_DIR)/command.o: $(SOURCE_DIR)/commands.cpp $(SOURCE_DIR)/commands.h $(SOURCE_DIR)/util.h $(SOURCE_DIR)/error.h $(OBJS_DIR)/util.o: $(SOURCE_DIR)/util.cpp $(SOURCE_DIR)/util.h $(OBJS_DIR)/config.o: $(SOURCE_DIR)/config.cpp $(SOURCE_DIR)/config.h $(OBJS_DIR)/keybinds.o: $(SOURCE_DIR)/keybinds.cpp $(SOURCE_DIR)/keybinds.h diff --git a/src/IPC.h b/src/IPC.h index 0705c2b..e0bbcee 100644 --- a/src/IPC.h +++ b/src/IPC.h @@ -3,7 +3,7 @@ #include #include -#include +#include "commands.h" #include "config.h" #include "util.h" diff --git a/src/commands.cpp b/src/commands.cpp new file mode 100644 index 0000000..caa82eb --- /dev/null +++ b/src/commands.cpp @@ -0,0 +1,372 @@ +#include "commands.h" +#include "error.h" +#include "util.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::cout, std::endl, std::string, std::vector; + +const void CommandsModule::echo(const CommandArg* argv) +{ + cout << argv[0].str << endl; +} + +const void CommandsModule::loadFile(const CommandArg* argv) +{ + std::vector errs; + + string path = cwd + "/" + std::string(argv[0].str); + + std::ifstream file(path); + if(!file.good()) + throw Err(CMD_ERR_NON_FATAL, "File '" + std::string(argv[0].str) + "' doesn't exist"); + + string prevCWD = cwd; + cwd = std::filesystem::path(path).parent_path(); + + cout << "Loading file '" << argv[0].str << "'" << endl; + + int line = 0; + for(string cmd; std::getline(file, cmd);) + { + line++; + if(cmd.size() == 0) + continue; + if(cmd.at(0) == '#') + continue; + try + { + this->runCommand(cmd); + } + catch (Err e) + { + throw Err(e.code, "Error in file '" + std::string(argv[0].str) + "' (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message); + } + } + + cwd = prevCWD; +} + +CommandsModule::CommandsModule() +{ + addCommand("echo", &CommandsModule::echo, 1, {STR_REST}, this); + addCommand("loadFile", &CommandsModule::loadFile, 1, {STR_REST}, this); + cwd = std::filesystem::current_path(); +} +CommandsModule::~CommandsModule() +{ + for(Command c : commandList) + { + if(c.argc > 0) + delete[] c.argTypes; + } +} + +void CommandsModule::addCommand(Command c) +{ + if(lookupCommand(c.name) != nullptr) + { + cout << "Duplicate command: " << c.name << endl; + } + commandList.push_back(c); +} +void CommandsModule::addCommand(std::string name, const void (*func)(const CommandArg *), const int argc, CommandArgType *argTypes) +{ + Command c = {name, nullptr, func, argc, argTypes, nullptr}; + addCommand(c); +} +void CommandsModule::addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes) +{ + CommandArgType* argTypesArr = new CommandArgType[argc]; + for(int i = 0; i < argc; i++) + { + argTypesArr[i] = argTypes[i]; + } + addCommand(name, func, argc, argTypesArr); +} + +struct NameMatches +{ + NameMatches(string s): s_{s} {} + bool operator()(Command c) { return (c.name == s_); } + string s_; +}; + +Command* CommandsModule::lookupCommand(string name) +{ + auto elem = std::find_if(commandList.begin(), commandList.end(), NameMatches(name)); + if (elem != commandList.end()) + { + int i = elem - commandList.begin(); + return &(commandList[i]); + } + else + { + return nullptr; + } +} + +vector CommandsModule::splitCommand(string command) +{ + vector v; + string arg = ""; + bool inQuotes = false; + bool escapeNext = true; + char quoteType; + for(int i = 0; i < command.size(); i++) + { + if(escapeNext) + { + arg += command[i]; + escapeNext = false; + } + else if(command[i] == '\\') + { + escapeNext = true; + } + else if(inQuotes) + { + if(command[i] == quoteType) + { + if(arg != "") + { + v.push_back(arg); + arg = ""; + } + inQuotes = false; + } + else + { + arg += command[i]; + } + } + else + { + if(command[i] == ' ') + { + if(arg != "") + { + v.push_back(arg); + arg = ""; + } + } + else if(command[i] == '"' || command[i] == '\'') + { + inQuotes = true; + quoteType = command[i]; + } + else + { + arg += command[i]; + } + } + } + if(arg != "") + v.push_back(arg); + return v; +} + +CommandArg* CommandsModule::getCommandArgs(vector& split, const CommandArgType* argTypes, const int argc) +{ + CommandArg* args = new CommandArg[argc]; + for(int i = 1; i < argc + 1; i++) + { + switch(argTypes[i-1]) + { + case STR: args[i-1].str = (char*)split[i].c_str(); break; + case NUM: + { + try + { + args[i-1].num = std::stoi(split[i]); + break; + } + catch(std::invalid_argument e) + { + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); + } + } + 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; + else + { + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!"); + } + break; + } + case STR_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()]; + strncpy(args[i-1].str, rest.c_str(), rest.size()); + return args; + } + case NUM_ARR_REST: + { + int* rest = new int[split.size() - i]; + for(int j = 0; j < split.size() - i; j++) + { + try + { + rest[j] = std::stoi(split[j + i]); + } + catch(std::invalid_argument e) + { + delete[] rest; + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); + } + } + args[i-1].numArr = {rest, (int) split.size() - i}; + return args; + } + default: cout << "UH OH SOMETHING IS VERY WRONG" << endl; + } + } + return args; +} + +void CommandsModule::runCommand(string command) +{ + vector split = splitCommand(command); + vector::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector::const_iterator end = start + count; + vector partialCmd(start, end); + runCommand(partialCmd); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector partialCmd(start, (vector::const_iterator)split.end()); + runCommand(partialCmd); + } +} +void CommandsModule::runCommand(vector split) +{ + Command* cmd = lookupCommand(split[0]); + if(cmd == nullptr) + throw Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); + if(cmd->argc > split.size() - 1) + throw Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); + CommandArg* args; + try + { + args = getCommandArgs(split, cmd->argTypes, cmd->argc); + } + catch(Err e) + { + throw e; + } + try + { + if(cmd->module == nullptr) + cmd->staticFunc(args); + else + cmd->func(*cmd->module, args); + } + catch (Err e) + { + for(int i = 0; i < cmd->argc; i++) + { + if(cmd->argTypes[i] == STR_REST) + delete[] args[i].str; + } + delete[] args; + throw e; + } + for(int i = 0; i < cmd->argc; i++) + { + if(cmd->argTypes[i] == STR_REST) + delete[] args[i].str; + } + delete[] args; +} + +vector CommandsModule::checkCommand(string command) +{ + vector errs; + vector split = splitCommand(command); + vector::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector::const_iterator end = start + count; + vector partialCmd(start, end); + errs.push_back(checkCommand(partialCmd)); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector partialCmd(start, (vector::const_iterator)split.end()); + errs.push_back(checkCommand(partialCmd)); + } + return errs; +} + +Err CommandsModule::checkCommand(vector split) +{ + Command* cmd = lookupCommand(split[0]); + if(cmd == nullptr) + return Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); + if(cmd->argc > split.size()) + return Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); + CommandArg* args; + try + { + args = getCommandArgs(split, cmd->argTypes, cmd->argc); + } + catch(Err e) + { + return e; + } + for(int i = 0; i < cmd->argc; i++) + { + if(cmd->argTypes[i] == STR_REST || cmd->argTypes[i] == NUM_ARR_REST) + delete[] args[i].str; + } + delete[] args; + return Err(NOERR, ""); +} diff --git a/src/commands.h b/src/commands.h new file mode 100644 index 0000000..4825f1c --- /dev/null +++ b/src/commands.h @@ -0,0 +1,91 @@ +#pragma once + +#include "error.h" + +#include +#include +#include +#include + +enum MoveDir + { + UP, + RIGHT, + DOWN, + LEFT + }; +enum CommandArgType + { + STR, + NUM, + MOVDIR, + STR_REST, + NUM_ARR_REST + }; + +struct NumArr +{ + int* arr; + int size; +}; +typedef union +{ + char* str; + int num; + NumArr numArr; + MoveDir dir; +} CommandArg; + +struct Command +{ + const std::string name; + const std::function func; + const std::function staticFunc; + const int argc; + CommandArgType* argTypes; + std::any* module; +}; +class CommandsModule +{ +private: + std::vector commandList; + std::vector splitCommand(std::string command); + CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); + const void echo(const CommandArg* argv); + const void loadFile(const CommandArg* argv); + std::string cwd; +public: + CommandsModule(); + ~CommandsModule(); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module); + void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module); + void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes); + void addCommand(Command c); + Command* lookupCommand(std::string name); + void runCommand(std::string command); + void runCommand(std::vector split); + std::vector checkCommand(std::string command); + Err checkCommand(std::vector split); +}; + +// YES I KNOW THIS IS BAD +// but it needs to be done this way +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module) +{ + Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module}; + addCommand(c); +} +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module) +{ + CommandArgType* argTypesArr = new CommandArgType[argc]; + for(int i = 0; i < argc; i++) + { + argTypesArr[i] = argTypes[i]; + } + addCommand(name, func, argc, argTypesArr, module); +} diff --git a/src/config.cpp b/src/config.cpp index df195aa..925e6ea 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,7 +1,6 @@ #include "config.h" -#include -//TODO: FIX THIS -#include +#include "commands.h" +#include "error.h" #include diff --git a/src/config.h b/src/config.h index b04753f..55e4fd3 100644 --- a/src/config.h +++ b/src/config.h @@ -2,7 +2,7 @@ #include #include -#include +#include "commands.h" #include #include diff --git a/src/keybinds.cpp b/src/keybinds.cpp index 127a534..235f8c1 100644 --- a/src/keybinds.cpp +++ b/src/keybinds.cpp @@ -7,9 +7,8 @@ #include #include -#include -//TODO: FIX THIS -#include +#include "commands.h" +#include "error.h" #include "keybinds.h" #include "util.h" diff --git a/src/keybinds.h b/src/keybinds.h index 5fd4fba..a742240 100644 --- a/src/keybinds.h +++ b/src/keybinds.h @@ -8,7 +8,7 @@ #include #include -#include +#include "commands.h" #include "config.h" #include "util.h" -- cgit v1.3.1 From 63005f5fc81e9b641f07eadb5f07bc7c532d40c7 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 20:50:44 +1300 Subject: feat: Added new command line option --config (-c) The new options allows you to specify the location of the config file in the arguments to the program. --- config | 5 ++++- src/main.cpp | 32 +++++++++++++++++++------------- test | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/config b/config index b154600..07e4bc6 100644 --- a/config +++ b/config @@ -1,10 +1,13 @@ # This is a comment # Mainly used for testing -# swapmods +swapmods + +quitkey mod+g bind mod+shift+e exit bind mod+Return spawn alacritty +bind "mod+r 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 diff --git a/src/main.cpp b/src/main.cpp index 3e01b4d..291151f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -36,8 +35,7 @@ #include "config.h" #include "util.h" #include "ewmh.h" -//TODO: FIX THIS -#include +#include "error.h" using std::cout; using std::string; @@ -1030,13 +1028,15 @@ int main(int argc, char** argv) { int versionFlag = 0; bool immediateExit = false; + string configLocation = ""; while(1) { static option long_options[] = {{"version", no_argument, &versionFlag, 1}, + {"config", required_argument, NULL, 'c'}, {0, 0, 0, 0}}; int optionIndex; - char c = getopt_long(argc, argv, "v", long_options, &optionIndex); + char c = getopt_long(argc, argv, "c:v", long_options, &optionIndex); if(c == -1) break; @@ -1048,8 +1048,12 @@ int main(int argc, char** argv) break; //Option had arg break; + case 'c': + configLocation = string(optarg); + break; case 'v': versionFlag = 1; + break; case '?': //Error?? break; @@ -1124,16 +1128,19 @@ int main(int argc, char** argv) std::vector cfgErr; cout << "Registered commands" << endl; - - char* confDir = getenv("XDG_CONFIG_HOME"); - if(confDir != NULL) - { - cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); - } + + if(configLocation != "") + cfgErr = cfg.loadFromFile(configLocation); else { - string home = getenv("HOME"); - cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + 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"); + } } cout << "Done config" << endl; @@ -1234,7 +1241,6 @@ int main(int argc, char** argv) } if(ready == -1) { - cout << "E" << endl; log("ERROR"); } } diff --git a/test b/test index fba98d4..f821b7f 100644 --- a/test +++ b/test @@ -7,6 +7,6 @@ Xephyr -screen 1600x900+2080+90 :1 & sleep 0.1 -DISPLAY=:1 ./YATwm +DISPLAY=:1 ./YATwm -c config pkill Xephyr -- cgit v1.3.1 From 74c58cdf74c4921071da93c4cbfaf22f672242a5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 6 Mar 2025 21:26:04 +1300 Subject: feat: Added the "S" modifier to the emacs bind mode You can now use S as a modifier for shift when binding with emacs mode if you're unable to capatilise the key to be bound. --- YATwm.nix | 4 +- compile_commands.json | 132 +++++++++++++++++++++++++------------------------- config | 108 ++++++++++++++++++++++------------------- nix/hm-module.nix | 7 +++ src/config.cpp | 2 +- src/keybinds.cpp | 55 ++++++++++++--------- src/main.cpp | 1 + 7 files changed, 165 insertions(+), 144 deletions(-) (limited to 'src') diff --git a/YATwm.nix b/YATwm.nix index be7cd2d..088f6eb 100644 --- a/YATwm.nix +++ b/YATwm.nix @@ -15,8 +15,8 @@ stdenv.mkDerivation { src = fetchgit { url = "https://git.tehbox.org/cgit/boss/YATwm.git/"; - rev = "v0.0.1"; - hash = "sha256-A4Yra/903rOeEbXfFia/A2HRPrFyE1b05mzHWlDImCY="; + rev = "0bc070e"; + hash = "sha256-yQoyXGJE8JrSon/P5uhyN1rRwBH/kz0LCGIly3yNDhg="; }; installPhase = '' diff --git a/compile_commands.json b/compile_commands.json index 3a2baf6..5d777ae 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,49 +1,49 @@ [ { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", - "build/main.o", - "src/main.cpp" + "build/keybinds.o", + "src/keybinds.cpp" ], "directory": "/home/boss/Documents/Coding/WM/YATwm", - "file": "/home/boss/Documents/Coding/WM/YATwm/src/main.cpp", - "output": "/home/boss/Documents/Coding/WM/YATwm/build/main.o" + "file": "/home/boss/Documents/Coding/WM/YATwm/src/keybinds.cpp", + "output": "/home/boss/Documents/Coding/WM/YATwm/build/keybinds.o" }, { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", - "build/config.o", - "src/config.cpp" + "build/main.o", + "src/main.cpp" ], "directory": "/home/boss/Documents/Coding/WM/YATwm", - "file": "/home/boss/Documents/Coding/WM/YATwm/src/config.cpp", - "output": "/home/boss/Documents/Coding/WM/YATwm/build/config.o" + "file": "/home/boss/Documents/Coding/WM/YATwm/src/main.cpp", + "output": "/home/boss/Documents/Coding/WM/YATwm/build/main.o" }, { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", "build/ewmh.o", @@ -55,31 +55,13 @@ }, { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", - "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", - "-c", - "-o", - "build/util.o", - "src/util.cpp" - ], - "directory": "/home/boss/Documents/Coding/WM/YATwm", - "file": "/home/boss/Documents/Coding/WM/YATwm/src/util.cpp", - "output": "/home/boss/Documents/Coding/WM/YATwm/build/util.o" - }, - { - "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", "build/IPC.o", @@ -91,13 +73,13 @@ }, { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", "build/commands.o", @@ -109,20 +91,38 @@ }, { "arguments": [ - "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++", + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", "-std=c++17", - "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include", - "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include", - "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0", - "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", "-c", "-o", - "build/keybinds.o", - "src/keybinds.cpp" + "build/util.o", + "src/util.cpp" ], "directory": "/home/boss/Documents/Coding/WM/YATwm", - "file": "/home/boss/Documents/Coding/WM/YATwm/src/keybinds.cpp", - "output": "/home/boss/Documents/Coding/WM/YATwm/build/keybinds.o" + "file": "/home/boss/Documents/Coding/WM/YATwm/src/util.cpp", + "output": "/home/boss/Documents/Coding/WM/YATwm/build/util.o" + }, + { + "arguments": [ + "/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/g++", + "-std=c++17", + "-I/nix/store/xq34vhc04n55v53xj9hbn0h0vj2ywcv6-libnotify-0.8.3-dev/include", + "-I/nix/store/089kvf479gh1jnapqi296pjn2yvmyplj-gdk-pixbuf-2.42.12-dev/include/gdk-pixbuf-2.0", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include", + "-I/nix/store/5dd834gbg319lfmfwgv54mswcq9k4k57-glib-2.82.1-dev/include/glib-2.0", + "-I/nix/store/8mmkgqj0r37s2rlxjvpj8dya7k9gcg77-glib-2.82.1/lib/glib-2.0/include", + "-c", + "-o", + "build/config.o", + "src/config.cpp" + ], + "directory": "/home/boss/Documents/Coding/WM/YATwm", + "file": "/home/boss/Documents/Coding/WM/YATwm/src/config.cpp", + "output": "/home/boss/Documents/Coding/WM/YATwm/build/config.o" } ] diff --git a/config b/config index 07e4bc6..5771451 100644 --- a/config +++ b/config @@ -1,54 +1,60 @@ -# This is a comment +# Home manager generated config: -# Mainly used for testing +# Keybinds: +bindmode emacs +quitkey s-g swapmods +bind "s-0" changeWS 10 +bind "s-1" changeWS 1 +bind "s-2" changeWS 2 +bind "s-3" changeWS 3 +bind "s-4" changeWS 4 +bind "s-5" changeWS 5 +bind "s-6" changeWS 6 +bind "s-7" changeWS 7 +bind "s-8" changeWS 8 +bind "s-9" changeWS 9 +bind "s-E" exit +bind "s-R" reload +bind "s-RET" spawn alacritty +bind "s-S-0" wToWS 10 +bind "s-S-1" wToWS 1 +bind "s-S-2" wToWS 2 +bind "s-S-3" wToWS 3 +bind "s-S-4" wToWS 4 +bind "s-S-5" wToWS 5 +bind "s-S-6" wToWS 6 +bind "s-S-7" wToWS 7 +bind "s-S-8" wToWS 8 +bind "s-S-9" wToWS 9 +bind "s-S-p s" wToWS 11 +bind "s-X" bashSpawn loginctl lock-session && systemctl suspend +bind "s-d" bashSpawn rofi -i -show drun +bind "s-f" fullscreen +bind "s-h" focChange left +bind "s-j" focChange down +bind "s-k" focChange up +bind "s-l" focChange right +bind "s-p s" changeWS 11 +bind "s-r k" spawn kitty +bind "s-t" toggle +bind "s-x" spawn loginctl lock-session + +# 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 +addWorkspace "S" 1 + + +# Gaps: +gaps 3 +outergaps 3 -quitkey mod+g - -bind mod+shift+e exit -bind mod+Return spawn alacritty -bind "mod+r 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 -bind mod+d bashSpawn "rofi -i -show drun" -gaps 10 -outergaps 10 - -bind mod+shift+r reload -bind mod+q kill - -# Tiling -bind mod+t toggle -bind mod+f fullscreen - -# 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 - -spawnOnce xss-lock --transfer-sleep-lock -- i3lock -et --nofork \ No newline at end of file diff --git a/nix/hm-module.nix b/nix/hm-module.nix index c9f914b..0db7fd4 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -116,6 +116,13 @@ List of commands to be executed at startup. Name for workspace. ''; }; +# key = mkOption { +# type = stypes.str; +# example = "1"; +# description = '' +# Key that will be used for switching to this monitor. mod+ will switch, and mod+shift+ will move the currently focused window. +# ''; +# }; monitorPriorities = mkOption { type = types.listOf types.int; default = [1]; diff --git a/src/config.cpp b/src/config.cpp index 925e6ea..df8a43d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -57,7 +57,7 @@ Config::Config(CommandsModule& commandsModule) commandsModule.addCommand("gaps", &Config::gapsCmd, 1, {NUM}, this); 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("addWorkspace", &Config::addWorkspaceCmd, 2, {STR, NUM_ARR_REST}, this); commandsModule.addCommand("swapmods", &Config::swapSuperAltCmd, 0, {}, this); } diff --git a/src/keybinds.cpp b/src/keybinds.cpp index 235f8c1..1f60a75 100644 --- a/src/keybinds.cpp +++ b/src/keybinds.cpp @@ -168,48 +168,55 @@ const Keybind KeybindsModule::emacsBindMode(string bindString) Keybind bind; bind.modifiers = 0; - const std::regex keyRegex("^(?:([CMs])-)?(?:([CMs])-)?(?:([CMs])-)?([^\\s]|(SPC|ESC|RET|))$"); + //cout << "Adding keybind: '" << bindString << "'" << endl; + + const std::regex keyRegex("^((?:[CMSs]-)*)([^\\s]|(?:SPC|ESC|RET))$"); std::smatch keyMatch; if(std::regex_match(bindString, keyMatch, keyRegex)) { - for (int i = 1; i < 3; i++) + std::ssub_match modifierMatch = keyMatch[1]; + for(std::string modifier : split(modifierMatch, '-')) { - std::ssub_match modifierMatch = keyMatch[i]; - if(modifierMatch.matched) + if(modifier == "s") + { + //cout << "\tModifier: s" << endl; + bind.modifiers |= cfg.swapSuperAlt?Mod1Mask:Mod4Mask; + } + else if(modifier == "M") + { + //cout << "\tModifier: M" << endl; + bind.modifiers |= cfg.swapSuperAlt?Mod4Mask:Mod1Mask; + } + else if(modifier == "C") + { + //cout << "\tModifier: C" << endl; + bind.modifiers |= ControlMask; + } + else if(modifier == "S") { - std::string modifier = modifierMatch.str(); - if(modifier == "s") - { - bind.modifiers |= Mod4Mask >> 3 * cfg.swapSuperAlt; - } - else if(modifier == "M") - { - bind.modifiers |= Mod1Mask << 3 * cfg.swapSuperAlt; - } - else if(modifier == "C") - { - bind.modifiers |= ControlMask; - } + //cout << "\tModifier: S" << endl; + bind.modifiers |= ShiftMask; } } } - KeySym keySym = XStringToKeysym(keyMatch[4].str().c_str()); + KeySym keySym = XStringToKeysym(keyMatch[2].str().c_str()); + //cout << "\tKey: " << keyMatch[2].str() << endl; - if(isUpper(keyMatch[4].str().c_str()) && keySym != NoSymbol) + if(isUpper(keyMatch[2].str().c_str()) && keySym != NoSymbol) { bind.modifiers |= ShiftMask; } if(keySym == NoSymbol) { - if(keyMatch[4].str() == "RET") + if(keyMatch[2].str() == "RET") keySym = XK_Return; - else if(keyMatch[4].str() == "ESC") + else if(keyMatch[2].str() == "ESC") keySym = XK_Escape; - else if(keyMatch[4].str() == "SPC") + else if(keyMatch[2].str() == "SPC") keySym = XK_space; - else if(keyMatch[4].str() == "-") + else if(keyMatch[2].str() == "-") keySym = XK_minus; - else if(keyMatch[4].str() == "+") + else if(keyMatch[2].str() == "+") keySym = XK_plus; else throw Err(CFG_ERR_KEYBIND, "Keybind '" + bindString + "' is invalid"); diff --git a/src/main.cpp b/src/main.cpp index 291151f..45e4eba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include -- cgit v1.3.1