summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-06-05 20:35:32 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-06-05 20:35:32 +1200
commit0b539b0b0278f2d7c2b7629e6d28d8463cba2688 (patch)
tree3a0b47f09dc58f2c14ba06443f2a5fe88d166e2f
parente9cc5756dbb0a2d079a7b5e3438d79945f819df5 (diff)
downloadYATwm-0b539b0b0278f2d7c2b7629e6d28d8463cba2688.tar.gz
YATwm-0b539b0b0278f2d7c2b7629e6d28d8463cba2688.zip
Added a very basic config, and fixed some stuff
NOTE: for some reason toggling doesn't work anymore
-rw-r--r--commands.cpp52
-rw-r--r--config31
-rw-r--r--config.cpp7
-rw-r--r--keybinds.cpp6
-rw-r--r--keybinds.h3
-rw-r--r--main.cpp11
6 files changed, 80 insertions, 30 deletions
diff --git a/commands.cpp b/commands.cpp
index c41536d..141de26 100644
--- a/commands.cpp
+++ b/commands.cpp
@@ -86,10 +86,9 @@ vector<string> CommandsModule::splitCommand(string command)
return v;
}
-template <typename T>
-std::basic_string<T> lowercase(const std::basic_string<T>& s)
+string lowercase(string s)
{
- std::basic_string<T> 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<string>& 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<Err> 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<Err> 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);
}