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.cpp | 423 +++++++++++++++++-------------------------------------------- 1 file changed, 114 insertions(+), 309 deletions(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 74ba0b0..101af24 100644 --- a/config.cpp +++ b/config.cpp @@ -1,349 +1,157 @@ #include "config.h" +#include "commands.h" -#include "error.h" -#include "toml++/toml.hpp" -#include "util.h" - -#include #include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include //Just for testing #include -#include -using std::map, std::string, std::to_string; +using std::string; // For testing -using std::cout, std::endl, std::cerr; - -map funcNameMap = { - {"exit", exit}, - {"spawn", spawn}, - {"toggle", toggle}, - {"kill", kill}, - {"changeWS", changeWS}, - {"wToWS", wToWS}, - {"focChange", focChange}, - {"wMove", wMove}, - {"bashSpawn", bashSpawn}, - {"reload", reload}, - {"wsDump", wsDump}, - {"nextMonitor", nextMonitor}, -}; - +using std::cout, std::endl; -Config::Config() +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); + } } -string to_string(string s) +const void Config::spawn(const CommandArg* argv) { - return s; + 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; } -string to_string(bool b) +const void Config::reload(const CommandArg* argv) { - if(b) - return "true"; - else - return "false"; + cout << "Reloading config" << endl; + reloadFile(); } -template -T Config::getValue(string path, Err* err) +const void Config::gapsCmd(const CommandArg* argv) { - std::optional tblVal = tbl.at_path(path).value(); - if(tblVal) - return *tblVal; - else - { - err->code = ERR_CFG_NON_FATAL; - T val = *defaults.at_path(path).value(); - err->errorMessage += "\n\tValue for " + path + " is invalid, using default (" + to_string(val) + ")"; - return val; - } + gaps = argv[0].num; } -void Config::loadWorkspaceArrays(toml::table tbl, toml::table defaults, Err* err) +const void Config::outerGapsCmd(const CommandArg* argv) { - if(!tbl["Workspaces"]["workspaceNames"].as_array()) - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\n\tworkspaceNames invalid array, using defaults"; - return loadWorkspaceArrays(defaults, defaults, err); - } - workspaceNamesc = tbl["Workspaces"]["workspaceNames"].as_array()->size(); - workspaceNames = new string[workspaceNamesc]; - for(int i = 0; i < workspaceNamesc; i++) - { - auto element = tbl["Workspaces"]["workspaceNames"][i].value(); - if(element) - workspaceNames[i] = *element; - else - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\nelement " + to_string(i) + " in workspaceNames invalid, using defaults"; - delete[] workspaceNames; - return loadWorkspaceArrays(defaults, defaults, err); - } - } - if(!tbl["Workspaces"]["screenPreferences"].as_array()) - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\nscreenPreferences invalid array, using default"; - delete[] workspaceNames; - return loadWorkspaceArrays(defaults, defaults, err); - } - screenPreferencesc = tbl["Workspaces"]["screenPreferences"].as_array()->size(); - if(screenPreferencesc != workspaceNamesc) - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\nworkspaceNames and screenPreferences aren't the same length, using defaults"; - delete[] workspaceNames; - return loadWorkspaceArrays(defaults, defaults, err); - } - screenPreferences = new int*[screenPreferencesc]; - for(int i = 0; i < screenPreferencesc; i++) - { - if(!tbl["Workspaces"]["screenPreferences"][i].as_array()) - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\telement " + to_string(i) + " in screenPreferences in invalid, using defaults"; - delete[] workspaceNames; - for(int k = 0; k < i; k++) - { - delete[] screenPreferences[k]; - } - delete[] screenPreferences; - return loadWorkspaceArrays(defaults, defaults, err); - } - int* wsScreens = new int[maxMonitors]; - for(int j = 0; j < maxMonitors; j++) - { - if(tbl["Workspaces"]["screenPreferences"][i].as_array()->size() <= j) - { - wsScreens[j] = 0; - continue; - } - auto element = tbl["Workspaces"]["screenPreferences"][i][j].value(); - if(element) - wsScreens[j] = *element; - else - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\telement " + to_string(i) + " " + to_string(j) + " in screenPreferences in invalid, using defaults"; - delete[] workspaceNames; - for(int k = 0; k <= i; k++) - { - delete[] screenPreferences[k]; - } - delete[] screenPreferences; - return loadWorkspaceArrays(defaults, defaults, err); - } - } - screenPreferences[i] = wsScreens; - } + outerGaps = argv[0].num; } -void Config::loadStartupBash(toml::table tbl, toml::table defaults, Err* err) +const void Config::logFileCmd(const CommandArg* argv) { - if(!tbl["Startup"]["startupBash"].as_array()) - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\n\tstartupBash array invalid, using default"; - return loadStartupBash(defaults, defaults, err); - } - startupBashc = tbl["Startup"]["startupBash"].as_array()->size(); - std::vector startupBash; - for(int i = 0; i < startupBashc; i++) - { - auto element = tbl["Startup"]["startupBash"][i].value(); - if(element) - startupBash.push_back(*element); - else - { - err->code = ERR_CFG_NON_FATAL; - err->errorMessage += "\n\tstartupBash element " + to_string(i) + " invalid, skipping"; - } - } - startupBashc = startupBash.size(); - this->startupBash = new string[startupBashc]; - for(int i = 0; i < startupBash.size(); i++) - { - this->startupBash[i] = startupBash[i]; - } + logFile = argv[0].str; } -Err Config::reload() +const void Config::addWorkspaceCmd(const CommandArg* argv) { - if(!loaded) - return {ERR_CFG_FATAL, "Path not set yet, call loadFromFile before reload"}; - return loadFromFile(path); + int* prefs = new int[argv[1].numArr.size]; + memcpy(prefs, argv[1].numArr.arr, argv[1].numArr.size * sizeof(int)); + workspaces.push_back({argv[0].str, prefs, argv[1].numArr.size}); } -Err Config::loadFromFile(string path) +Config::Config(CommandsModule& commandsModule) + : commandsModule(commandsModule) { - if(loaded) - { - free(); - } - loaded = true; - this->path = path; - Err err; - err.code = NOERR; - err.errorMessage = ""; - defaults = toml::parse_file("/etc/YATwm/config.toml"); - try - { - tbl = toml::parse_file(path); - } - catch (const toml::parse_error& parseErr) - { - err.code = ERR_CFG_FATAL; - string description = (string) parseErr.description(); - string startCol = std::to_string(parseErr.source().begin.column); - string startLine = std::to_string(parseErr.source().begin.line); - string endCol = std::to_string(parseErr.source().end.column); - string endLine = std::to_string(parseErr.source().end.line); - string pos = "Line " + startLine; - string what = parseErr.what(); - err.errorMessage += "\n\t" + description + "\t(" + pos + ")" + "\n\tUsing /etc/YATwm/config.toml instead"; - tbl = defaults; - } + //Register commands for keybinds + CommandArgType* spawnArgs = new CommandArgType[1]; + spawnArgs[0] = STR_REST; + commandsModule.addCommand("spawn", &Config::spawn, 1, spawnArgs, this); + commandsModule.addCommand("spawn_once", &Config::spawn_once, 1, spawnArgs, this); + commandsModule.addCommand("reload", &Config::reload, 0, {}, this); + + //Register commands for config + CommandArgType* gapsArgs = new CommandArgType[1]; + gapsArgs[0] = NUM; + commandsModule.addCommand("gaps", &Config::gapsCmd, 1, gapsArgs, this); + commandsModule.addCommand("outergaps", &Config::outerGapsCmd, 1, gapsArgs, this); + CommandArgType* logFileArgs = new CommandArgType[1]; + logFileArgs[0] = STR_REST; + commandsModule.addCommand("logfile", &Config::logFileCmd, 1, logFileArgs, this); + CommandArgType* addWorkspaceArgs = new CommandArgType[2]; + addWorkspaceArgs[0] = STR; + addWorkspaceArgs[1] = NUM_ARR_REST; + commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, addWorkspaceArgs, this); +} - //Startup - loadStartupBash(tbl, defaults, &err); +void Config::reloadFile() +{ + if(!loaded) + return; + loadFromFile(file); +} - //Main - gaps = getValue("Main.gaps", &err); - outerGaps = getValue("Main.outerGaps", &err); - logFile = getValue("Main.logFile", &err); +void Config::loadFromFile(string path) +{ + file = path; + //Set defaults + gaps = 3; + outerGaps = 3; + logFile = "/tmp/yatlog.txt"; - //Workspaces - numWS = getValue("Workspaces.numWS", &err); - maxMonitors = getValue("Workspaces.maxMonitors", &err); - loadWorkspaceArrays(tbl, defaults, &err); - - //Keybinds - bool swapSuperAlt = getValue("Keybinds.swapSuperAlt", &err); + //Probably need something for workspaces and binds too... - toml::node_view bindsArr = tbl["Keybinds"]["key"]; - if(!bindsArr.is_array()) + string cmd; + int line = 0; + std::ifstream config(path); + while(getline(config, cmd)) { - err.code = ERR_CFG_NON_FATAL; - err.errorMessage += "\n\tBinds array not valid, using default"; - bindsArr = defaults["Keybinds"]["key"]; - } - std::vector keyBinds; - bindsc = bindsArr.as_array()->size(); - for(int i = 0; i < bindsc; i++) - { - KeyBind bind; - bind.modifiers = 0; - const std::optional potentialBindString = bindsArr[i]["bind"].value(); - string bindString; - if(potentialBindString) - bindString = *potentialBindString; - else - { - err.code = ERR_CFG_NON_FATAL; - err.errorMessage += "\n\tSkipping element " + to_string(i) + " of binds as the bind string is invalid"; + if(cmd.at(0) == '#') continue; - } - std::vector keys = split(bindString, '+'); - for(string key : keys) - { - if(key == "mod") - { - if(!swapSuperAlt) - bind.modifiers |= Mod4Mask; - else - bind.modifiers |= Mod1Mask; - } - else if(key == "alt") - { - if(swapSuperAlt) - bind.modifiers |= Mod4Mask; - else - bind.modifiers |= Mod1Mask; - } - else if(key == "shift") - { - bind.modifiers |= ShiftMask; - } - else if(key == "control") - { - bind.modifiers |= ControlMask; - } - else - { - bind.keysym = XStringToKeysym(key.c_str()); - if(bind.keysym == NoSymbol) - { - err.code = ERR_CFG_NON_FATAL; - err.errorMessage += "\n\tSkipping element " + to_string(i) + " of binds as the bind string is invalid"; - continue; - } - } - } - std::optional potentialFuncString = bindsArr[i]["func"].value(); - string funcString; - if(potentialFuncString) - funcString = *potentialFuncString; - else + try { - err.code = ERR_CFG_NON_FATAL; - err.errorMessage += "\n\tSkipping element " + to_string(i) + " of binds as the func string is invalid"; - continue; + commandsModule.runCommand(cmd); } - if(funcNameMap.count(funcString) == 0) + catch (Err e) { - err.code = ERR_CFG_NON_FATAL; - err.errorMessage += "\n\tSkipping element " + to_string(i) + " of binds as the func string is invalid"; - continue; + cout << "Error in config (line " << line << "): " << e.code << endl; + cout << "\tMessage: " << e.message << endl; } - void(* func) (const KeyArg arg) = funcNameMap.find(funcString)->second; - bind.func = func; - - auto args = bindsArr[i]["args"]; - if(args.is()) - { - int num = *args.value(); - bind.args = {.num = num}; - } - else if(args.is()) - { - string str = (string)*args.value(); - if(str == "Up") - bind.args = {.dir = Up}; - else if (str == "Down") - bind.args = {.dir = Down}; - else if (str == "Left") - bind.args = {.dir = Left}; - else if (str == "Right") - bind.args = {.dir = Right}; - else - { - bind.args = {.str = strdup(str.c_str())}; - } - } - else - { - bind.args = {NULL}; - } - keyBinds.push_back(bind); + line++; } - bindsc = keyBinds.size(); - binds = new KeyBind[bindsc]; - for(int i = 0; i < bindsc; i++) - { - binds[i] = keyBinds[i]; - } - if(err.code != NOERR) - err.errorMessage = err.errorMessage.substr(1); - return err; + loaded = true; } Config::~Config() @@ -352,13 +160,10 @@ Config::~Config() } void Config::free() { - delete[] startupBash; - delete[] workspaceNames; - for(int i = 0; i < screenPreferencesc; i++) + if(!loaded) + return; + for(Workspace w : workspaces) { - delete[] screenPreferences[i]; + delete [] w.screenPreferences; } - delete[] screenPreferences; - delete[] binds; - loaded = false; } -- cgit v1.2.3 From 27137ec9d29c36df8117869773203b243849896c Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 26 May 2023 21:46:19 +1200 Subject: feat: Made keybinds work (I hope) Note: the config file reloading keybinds isn't quite working, though, need to ungrab the keys --- config.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 101af24..6d8215c 100644 --- a/config.cpp +++ b/config.cpp @@ -1,5 +1,6 @@ #include "config.h" #include "commands.h" +#include "error.h" #include @@ -66,6 +67,7 @@ const void Config::focChange(const CommandArg* argv) } 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(); } @@ -116,14 +118,14 @@ Config::Config(CommandsModule& commandsModule) commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, addWorkspaceArgs, this); } -void Config::reloadFile() +Err Config::reloadFile() { if(!loaded) - return; - loadFromFile(file); + return {CFG_ERR_NON_FATAL, "Not loaded config yet"}; + return loadFromFile(file); } -void Config::loadFromFile(string path) +Err Config::loadFromFile(string path) { file = path; //Set defaults @@ -152,6 +154,7 @@ void Config::loadFromFile(string path) line++; } loaded = true; + return {NOERR, ""}; } Config::~Config() -- cgit v1.2.3 From ea827624d203c73af896669e161972fc8be022ed Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 27 May 2023 16:33:46 +1200 Subject: feat: Made it compile woo Note: doesn't work yet though, as commands haven't all been registered yet --- config.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 6d8215c..422ec19 100644 --- a/config.cpp +++ b/config.cpp @@ -92,6 +92,7 @@ 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)); workspaces.push_back({argv[0].str, prefs, argv[1].numArr.size}); + numWS++; } Config::Config(CommandsModule& commandsModule) @@ -118,20 +119,23 @@ Config::Config(CommandsModule& commandsModule) commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, addWorkspaceArgs, this); } -Err Config::reloadFile() +std::vector Config::reloadFile() { if(!loaded) - return {CFG_ERR_NON_FATAL, "Not loaded config yet"}; + return {{CFG_ERR_NON_FATAL, "Not loaded config yet"}}; return loadFromFile(file); } -Err Config::loadFromFile(string path) +std::vector Config::loadFromFile(std::string path) { + std::vector ers; + file = path; //Set defaults gaps = 3; outerGaps = 3; logFile = "/tmp/yatlog.txt"; + numWS = 0; //Probably need something for workspaces and binds too... @@ -148,13 +152,12 @@ Err Config::loadFromFile(string path) } catch (Err e) { - cout << "Error in config (line " << line << "): " << e.code << endl; - cout << "\tMessage: " << e.message << endl; + ers.push_back({e.code, "Error in config (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message}); + } line++; } loaded = true; - return {NOERR, ""}; } Config::~Config() -- cgit v1.2.3 From 6b3dff404248bcf03e0bf0463a8c53d8918f7eec Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 31 May 2023 20:55:49 +1200 Subject: Added support for commands without a module Also made it easier to add commands by making the ~addCommand~ function accept a vector for ~argTypes~ and then convert it. --- config.cpp | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 422ec19..74a4a1d 100644 --- a/config.cpp +++ b/config.cpp @@ -41,18 +41,6 @@ const void Config::spawn_once(const CommandArg* argv) } } -const void Config::spawn(const CommandArg* argv) -{ - 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; @@ -99,24 +87,14 @@ Config::Config(CommandsModule& commandsModule) : commandsModule(commandsModule) { //Register commands for keybinds - CommandArgType* spawnArgs = new CommandArgType[1]; - spawnArgs[0] = STR_REST; - commandsModule.addCommand("spawn", &Config::spawn, 1, spawnArgs, this); - commandsModule.addCommand("spawn_once", &Config::spawn_once, 1, spawnArgs, this); + commandsModule.addCommand("spawn_once", &Config::spawn_once, 1, {STR_REST}, this); commandsModule.addCommand("reload", &Config::reload, 0, {}, this); //Register commands for config - CommandArgType* gapsArgs = new CommandArgType[1]; - gapsArgs[0] = NUM; - commandsModule.addCommand("gaps", &Config::gapsCmd, 1, gapsArgs, this); - commandsModule.addCommand("outergaps", &Config::outerGapsCmd, 1, gapsArgs, this); - CommandArgType* logFileArgs = new CommandArgType[1]; - logFileArgs[0] = STR_REST; - commandsModule.addCommand("logfile", &Config::logFileCmd, 1, logFileArgs, this); - CommandArgType* addWorkspaceArgs = new CommandArgType[2]; - addWorkspaceArgs[0] = STR; - addWorkspaceArgs[1] = NUM_ARR_REST; - commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, addWorkspaceArgs, this); + 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); } std::vector Config::reloadFile() @@ -128,7 +106,7 @@ std::vector Config::reloadFile() std::vector Config::loadFromFile(std::string path) { - std::vector ers; + std::vector errs; file = path; //Set defaults @@ -152,12 +130,13 @@ std::vector Config::loadFromFile(std::string path) } catch (Err e) { - ers.push_back({e.code, "Error in config (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message}); + errs.push_back({e.code, "Error in config (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message}); } line++; } loaded = true; + return errs; } Config::~Config() -- cgit v1.2.3 From 01bc6a33eb235cd10851e2c31b99e6840603ca7d Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 1 Jun 2023 12:53:13 +1200 Subject: IT WORKS!!!!!! The new config commands system works, finally able to run this as a test and it works!!!!!. Still more to be done but at least it works. --- config.cpp | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'config.cpp') 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); -- cgit v1.2.3 From e9cc5756dbb0a2d079a7b5e3438d79945f819df5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 3 Jun 2023 21:30:05 +1200 Subject: feat: Keybind updates Re added the ability to swap super and mod as a config parameter (the ~swapmods~) command). Finally fixed keybinds sometimes not working because of numlock, bitwise & with the modifiers I actually care about. --- config.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'config.cpp') 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... -- cgit v1.2.3 From 0b539b0b0278f2d7c2b7629e6d28d8463cba2688 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Mon, 5 Jun 2023 20:35:32 +1200 Subject: Added a very basic config, and fixed some stuff NOTE: for some reason toggling doesn't work anymore --- config.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'config.cpp') 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 -- cgit v1.2.3 From 5f54adae7bc4edaf2c18383efe13ded233255509 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 16 Jun 2023 00:05:28 +1200 Subject: feat: Uses a backup config file and respects XDG Uses config files in the order of `$XDG_CONFIG_HOME/YATwm/config`, `$HOME/.config/YATwm/config`, then `/etc/YATwm/config` --- config.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'config.cpp') 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) -- cgit v1.2.3 From 557faa2603d33d6f6a8b7baa9c9f7891bfcb8d30 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sun, 18 Jun 2023 21:31:41 +1200 Subject: feat: Updated readme Updated the readme and added a default config file. --- config.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'config.cpp') 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; -- cgit v1.2.3