summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-06-03 21:30:05 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-06-03 21:30:05 +1200
commite9cc5756dbb0a2d079a7b5e3438d79945f819df5 (patch)
tree3881cb6bed150ef11252ef04a5e11c05d5af05f8
parent01bc6a33eb235cd10851e2c31b99e6840603ca7d (diff)
downloadYATwm-e9cc5756dbb0a2d079a7b5e3438d79945f819df5.tar.gz
YATwm-e9cc5756dbb0a2d079a7b5e3438d79945f819df5.zip
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.
-rw-r--r--commands.cpp20
-rw-r--r--commands.h2
-rw-r--r--config4
-rw-r--r--config.cpp7
-rw-r--r--config.h3
-rw-r--r--keybinds.cpp22
-rw-r--r--keybinds.h5
-rw-r--r--main.cpp11
8 files changed, 41 insertions, 33 deletions
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<string>& split, const CommandA
void CommandsModule::runCommand(string command)
{
- cout << command << endl;
vector<string> split = splitCommand(command);
Command* cmd = lookupCommand(split[0]);
if(cmd == nullptr)
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<Command> commandList;
std::vector<std::string> splitCommand(std::string command);
CommandArg* getCommandArgs(std::vector<std::string>& 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<Err> Config::reloadFile()
@@ -72,6 +78,7 @@ std::vector<Err> 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 <vector>
#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<Keybind> 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<Err> 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<int> v;