summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-08-24 12:58:40 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-08-24 12:58:40 +1200
commit6b5c246a431dcaff119833724137f0716fa2a002 (patch)
tree99ced8d93809cf675b55ea683f28f847e84d9722
parent87b7f6c47d8eab8bfe7f126652a88939aac58a6a (diff)
parentd22b5d2363ed8a90960446a209482180f6d27fc0 (diff)
downloadYATwm-6b5c246a431dcaff119833724137f0716fa2a002.tar.gz
YATwm-6b5c246a431dcaff119833724137f0716fa2a002.zip
Merge branch 'keybind-refactor'
-rw-r--r--commands.cpp75
-rw-r--r--commands.h5
-rw-r--r--keybinds.cpp236
-rw-r--r--keybinds.h32
-rw-r--r--main.cpp2
-rw-r--r--readme.html89
-rw-r--r--readme.org12
-rw-r--r--util.cpp15
-rw-r--r--util.h5
9 files changed, 387 insertions, 84 deletions
diff --git a/commands.cpp b/commands.cpp
index de7d81e..54fe891 100644
--- a/commands.cpp
+++ b/commands.cpp
@@ -1,5 +1,6 @@
#include "commands.h"
#include "error.h"
+#include "util.h"
#include <cctype>
#include <iostream>
@@ -11,10 +12,16 @@
#include <regex>
#include <cstring>
-using std::cout, std::endl, std::string, std::vector, std::tolower;
+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()
{
@@ -129,13 +136,6 @@ vector<string> CommandsModule::splitCommand(string command)
return v;
}
-string lowercase(string s)
-{
- string s2 = s;
- std::transform(s2.begin(), s2.end(), s2.begin(), [](unsigned char c){ return std::tolower(c); });
- return s2;
-}
-
CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandArgType* argTypes, const int argc)
{
CommandArg* args = new CommandArg[argc];
@@ -215,11 +215,36 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA
void CommandsModule::runCommand(string command)
{
vector<string> split = splitCommand(command);
+ vector<string>::const_iterator start = split.begin();
+ int count = 0;
+ for(string s : split)
+ {
+ if(s == ";")
+ {
+ vector<string>::const_iterator end = start + count;
+ vector<string> partialCmd(start, end);
+ runCommand(partialCmd);
+ count = 0;
+ start = end + 1;
+ }
+ else
+ {
+ count++;
+ }
+ }
+ if(start != split.end())
+ {
+ vector<string> partialCmd(start, (vector<string>::const_iterator)split.end());
+ runCommand(partialCmd);
+ }
+}
+void CommandsModule::runCommand(vector<string> 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, command + " is the wrong args");
+ throw Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments");
CommandArg* args;
try
{
@@ -254,14 +279,42 @@ void CommandsModule::runCommand(string command)
delete[] args;
}
-Err CommandsModule::checkCommand(string command)
+vector<Err> CommandsModule::checkCommand(string command)
{
+ vector<Err> errs;
vector<string> split = splitCommand(command);
+ vector<string>::const_iterator start = split.begin();
+ int count = 0;
+ for(string s : split)
+ {
+ if(s == ";")
+ {
+ vector<string>::const_iterator end = start + count;
+ vector<string> partialCmd(start, end);
+ errs.push_back(checkCommand(partialCmd));
+ count = 0;
+ start = end + 1;
+ }
+ else
+ {
+ count++;
+ }
+ }
+ if(start != split.end())
+ {
+ vector<string> partialCmd(start, (vector<string>::const_iterator)split.end());
+ errs.push_back(checkCommand(partialCmd));
+ }
+ return errs;
+}
+
+Err CommandsModule::checkCommand(vector<string> 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, command + " is the wrong args");
+ return Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments");
CommandArg* args;
try
{
diff --git a/commands.h b/commands.h
index d7f2351..af4a4a0 100644
--- a/commands.h
+++ b/commands.h
@@ -51,6 +51,7 @@ 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 echo(const CommandArg* argv);
public:
CommandsModule();
~CommandsModule();
@@ -63,7 +64,9 @@ public:
void addCommand(Command c);
Command* lookupCommand(std::string name);
void runCommand(std::string command);
- Err checkCommand(std::string command);
+ void runCommand(std::vector<std::string> split);
+ std::vector<Err> checkCommand(std::string command);
+ Err checkCommand(std::vector<std::string> split);
};
// YES I KNOW THIS IS BAD
diff --git a/keybinds.cpp b/keybinds.cpp
index 64d3fc8..c41452f 100644
--- a/keybinds.cpp
+++ b/keybinds.cpp
@@ -1,14 +1,29 @@
#include <X11/X.h>
#include <X11/Xlib.h>
+#include <cctype>
#include <iostream>
#include <sstream>
+#include <utility>
#include <vector>
+#include <regex>
+#include "commands.h"
#include "error.h"
#include "keybinds.h"
#include "util.h"
-using std::string, std::cout, std::endl;
+using std::string;
+
+bool Keybind::operator<(const Keybind &o) const {
+ if(key != o.key)
+ {
+ return key < o.key;
+ }
+ else return modifiers < o.modifiers;
+}
+bool Keybind::operator==(const Keybind &o) const {
+ return (key == o.key && modifiers == o.modifiers);
+}
KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals, void (*updateMousePos)())
:commandsModule(commandsModule),
@@ -16,36 +31,99 @@ KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Glob
cfg(cfg)
{
commandsModule.addCommand("bind", &KeybindsModule::bind, 2, {STR, STR_REST}, this);
+ commandsModule.addCommand("quitkey", &KeybindsModule::quitKey, 1, {STR}, this);
+ commandsModule.addCommand("bindmode", &KeybindsModule::bindMode, 1, {STR}, this);
+
+ bindModes = {
+ {"normal", &KeybindsModule::normalBindMode},
+ {"emacs", &KeybindsModule::emacsBindMode}
+ };
+ bindFunc = &KeybindsModule::normalBindMode;
+
this->updateMousePos = updateMousePos;
+ keyMaps.insert({0, std::map<Keybind, KeyFunction>()});
+}
+
+void KeybindsModule::changeMap(int newMapID)
+{
+ if(currentMapID == newMapID)
+ return;
+ if(currentMapID != 0)
+ XUngrabKeyboard(globals.dpy, CurrentTime);
+ XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root);
+ currentMapID = newMapID;
+ if(newMapID == 0)
+ {
+ for(std::pair<Keybind, KeyFunction> pair : getKeymap(currentMapID))
+ {
+ Keybind bind = pair.first;
+ XGrabKey(globals.dpy, bind.key, bind.modifiers, globals.root, false, GrabModeAsync, GrabModeAsync);
+ }
+ }
+ else
+ {
+ XGrabKeyboard(globals.dpy, globals.root, false, GrabModeAsync, GrabModeAsync, CurrentTime);
+ }
}
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;
+ // 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)
+ Keybind k = {(KeyCode)e.keycode, e.state & masks};
+ if(k == exitBind)
+ {
+ changeMap(0);
+ }
+ else if(getKeymap(currentMapID).count(k) > 0)
{
- if(bind.modifiers == (e.state & masks) && bind.key == XLookupKeysym(&e, 0))
+ KeyFunction& c = getKeymap(currentMapID).find(k)->second;
+ if(getKeymap(c.mapID).size() == 0)
{
- commandsModule.runCommand(bind.command);
+ commandsModule.runCommand(c.command);
+ changeMap(0);
}
+ else
+ {
+ XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root);
+ changeMap(c.mapID);
+ }
+ }
+ else if(std::find(std::begin(ignoredKeys), std::end(ignoredKeys), e.keycode) == std::end(ignoredKeys))
+ {
+ changeMap(0);
}
}
-const void KeybindsModule::bind(const CommandArg* argv)
+bool isUpper(const std::string& s) {
+ return std::all_of(s.begin(), s.end(), [](unsigned char c){ return std::isupper(c); });
+}
+
+const void KeybindsModule::bindMode(const CommandArg* argv)
{
- Err e = commandsModule.checkCommand(argv[1].str);
- if(e.code != NOERR)
+ if(bindModes.count(argv[0].str) < 1)
+ {
+ throw Err(CFG_ERR_KEYBIND, "Bind mode: " + string(argv[0].str) + " does not exist");
+ }
+ else
{
- e.message = "Binding fail - " + e.message;
- throw e;
+ bindFunc = bindModes.find(argv[0].str)->second;
}
- std::vector<string> keys = split(argv[0].str, '+');
+}
+
+Keybind KeybindsModule::getKeybind(std::string bindString)
+{
+ return (this->*bindFunc)(bindString);
+}
+
+const Keybind KeybindsModule::normalBindMode(string bindString)
+{
+ std::vector<string> keys = split(bindString, '+');
Keybind bind;
bind.modifiers = 0;
for(string key : keys)
@@ -68,23 +146,137 @@ const void KeybindsModule::bind(const CommandArg* argv)
}
else
{
+ if(isUpper(key))
+ {
+ bind.modifiers |= ShiftMask;
+ }
KeySym s = XStringToKeysym(key.c_str());
- bind.key = s;
- if(bind.key == NoSymbol)
+ if(s == NoSymbol)
{
- throw Err(CFG_ERR_KEYBIND, "Keybind '" + string(argv[0].str) + "' is invalid!");
- continue;
+ throw Err(CFG_ERR_KEYBIND, "Keybind '" + bindString + "' is invalid!");
}
+ bind.key = XKeysymToKeycode(globals.dpy, s);
}
}
- 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);
+ if(!bind.key)
+ throw Err(CFG_ERR_KEYBIND, "Keybind '" + bindString + "' is invalid!");
+ return bind;
+}
+
+const Keybind KeybindsModule::emacsBindMode(string bindString)
+{
+ Keybind bind;
+ bind.modifiers = 0;
+
+ const std::regex keyRegex("^(?:([CMs])-)?(?:([CMs])-)?(?:([CMs])-)?([^\\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[i];
+ if(modifierMatch.matched)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ KeySym keySym = XStringToKeysym(keyMatch[4].str().c_str());
+
+ if(isUpper(keyMatch[4].str().c_str()) && keySym != NoSymbol)
+ {
+ bind.modifiers |= ShiftMask;
+ }
+ if(keySym == NoSymbol)
+ {
+ if(keyMatch[4].str() == "RET")
+ keySym = XK_Return;
+ else if(keyMatch[4].str() == "ESC")
+ keySym = XK_Escape;
+ else if(keyMatch[4].str() == "SPC")
+ keySym = XK_space;
+ else if(keyMatch[4].str() == "-")
+ keySym = XK_minus;
+ else if(keyMatch[4].str() == "+")
+ keySym = XK_plus;
+ else
+ throw Err(CFG_ERR_KEYBIND, "Keybind '" + bindString + "' is invalid");
+ }
+ bind.key = XKeysymToKeycode(globals.dpy, keySym);
+
+ return bind;
+}
+
+const void KeybindsModule::bind(const CommandArg* argv)
+{
+ std::vector<Err> errs = commandsModule.checkCommand(argv[1].str);
+ for(Err e : errs)
+ {
+ if(e.code != NOERR)
+ {
+ e.message = "Binding fail - " + e.message;
+ throw e;
+ }
+ }
+ std::vector<string> keys = split(argv[0].str, ' ');
+ int currentBindingMap = 0;
+ for(int i = 0; i < keys.size() - 1; i++)
+ {
+ Keybind bind = getKeybind(keys[i]);
+ if(getKeymap(currentBindingMap).count(bind) > 0)
+ {
+ currentBindingMap = getKeymap(currentBindingMap).find(bind)->second.mapID;
+ }
+ else
+ {
+ KeyFunction newMap = {"", nextKeymapID};
+ keyMaps.insert({nextKeymapID, std::map<Keybind, KeyFunction>()});
+ nextKeymapID++;
+ getKeymap(currentBindingMap).insert({bind, newMap});
+ currentBindingMap = getKeymap(currentBindingMap).find(bind)->second.mapID;
+ }
+ }
+ Keybind bind = getKeybind(keys[keys.size() - 1]);
+ if(getKeymap(currentBindingMap).count(bind) <= 0)
+ {
+ KeyFunction function = {argv[1].str, nextKeymapID};
+ keyMaps.insert({nextKeymapID, std::map<Keybind, KeyFunction>()});
+ nextKeymapID++;
+ getKeymap(currentBindingMap).insert({bind, function});
+ if(currentBindingMap == currentMapID)
+ {
+ KeyCode c = XKeysymToKeycode(globals.dpy, bind.key);
+ XGrabKey(globals.dpy, c, bind.modifiers, globals.root, false, GrabModeAsync, GrabModeAsync);
+ }
+ }
+ else
+ {
+ throw Err(CFG_ERR_KEYBIND, "Bind is a keymap already!");
+ }
+ // cout << "Added bind" << endl;
+ // cout << "\t" << argv[0].str << endl;
+}
+
+const void KeybindsModule::quitKey(const CommandArg* argv)
+{
+ exitBind = getKeybind(argv[0].str);
}
const void KeybindsModule::clearKeybinds()
{
XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root);
- binds = std::vector<Keybind>();
+ keyMaps = std::map<int, std::map<Keybind, KeyFunction>>();
+ keyMaps.insert({0, std::map<Keybind, KeyFunction>()});
}
diff --git a/keybinds.h b/keybinds.h
index 686eaf8..a742240 100644
--- a/keybinds.h
+++ b/keybinds.h
@@ -2,6 +2,7 @@
#include <X11/X.h>
#include <X11/Xlib.h>
+
#include <map>
#include <string>
#include <X11/keysym.h>
@@ -12,20 +13,45 @@
#include "util.h"
struct Keybind {
- KeySym key;
+ KeyCode key;
unsigned int modifiers;
+ bool operator<(const Keybind &o) const;
+ bool operator==(const Keybind &o) const;
+};
+
+struct KeyFunction
+{
std::string command;
+ int mapID;
};
-class KeybindsModule {
+#define getKeymap(X) \
+ keyMaps.find(X)->second
+
+
+class KeybindsModule
+{
public:
KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals, void (*updateMousePos)());
~KeybindsModule() = default;
const void bind(const CommandArg* argv);
+ const void quitKey(const CommandArg* argv);
+ const void bindMode(const CommandArg* argv);
const void handleKeypress(XKeyEvent e);
const void clearKeybinds();
private:
- std::vector<Keybind> binds;
+ Keybind getKeybind(std::string bindString);
+ void changeMap(int newMapID);
+ std::map<int, std::map<Keybind, KeyFunction>> keyMaps;
+ const Keybind emacsBindMode(std::string bindString);
+ const Keybind normalBindMode(std::string bindString);
+ std::map<std::string, const Keybind(KeybindsModule::*)(std::string bindString)> bindModes;
+ const Keybind(KeybindsModule::* bindFunc)(std::string bindString);
+ // Modifier keys to ignore when canceling a keymap
+ KeyCode ignoredKeys[8] = {50, 37, 133, 64, 62, 105, 134, 108};
+ int currentMapID = 0;
+ int nextKeymapID = 1;
+ Keybind exitBind = {42, 0x40};
CommandsModule& commandsModule;
Config& cfg;
Globals& globals;
diff --git a/main.cpp b/main.cpp
index f6cc6e8..cc3d2bb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1117,7 +1117,7 @@ int main(int argc, char** argv)
clientMessage(e.xclient);
break;
default:
- //cout << "Unhandled event, code: " << evNames[e.type] << "!\n";
+ // cout << "Unhandled event: " << getEventName(e.type) << endl;
break;
}
}
diff --git a/readme.html b/readme.html
index 1040470..7879e4d 100644
--- a/readme.html
+++ b/readme.html
@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
-<!-- 2023-06-21 Wed 20:26 -->
+<!-- 2023-06-28 Wed 21:24 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>YATwm</title>
@@ -200,36 +200,36 @@
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
-<li><a href="#orge9be048">1. This config is best read in Emacs!</a></li>
-<li><a href="#org90a4bc0">2. Disclaimer: This is still very much in beta</a></li>
-<li><a href="#org5eaba64">3. Usage instructions</a>
+<li><a href="#orgbfb53c0">1. This config is best read in Emacs!</a></li>
+<li><a href="#org10dcbf8">2. Disclaimer: This is still very much in beta</a></li>
+<li><a href="#org522cd53">3. Usage instructions</a>
<ul>
-<li><a href="#org41321d1">3.1. Installation</a>
+<li><a href="#org5f71891">3.1. Installation</a>
<ul>
-<li><a href="#org318ad8e">3.1.1. Pre reqs</a></li>
-<li><a href="#orgf06bf1e">3.1.2. Installing and removing</a></li>
+<li><a href="#org3dc64ae">3.1.1. Pre reqs</a></li>
+<li><a href="#org309a902">3.1.2. Installing and removing</a></li>
</ul>
</li>
-<li><a href="#org3c09ef5">3.2. Config</a>
+<li><a href="#orgb007d3a">3.2. Config</a>
<ul>
-<li><a href="#org43f17c0">3.2.1. Syntax</a></li>
-<li><a href="#org384a204">3.2.2. General</a></li>
-<li><a href="#orga3a5f0e">3.2.3. Workspaces</a></li>
-<li><a href="#orgee481dd">3.2.4. Keybinds</a></li>
+<li><a href="#org6dcf252">3.2.1. Syntax</a></li>
+<li><a href="#org9f46c02">3.2.2. General</a></li>
+<li><a href="#org7f3b7f1">3.2.3. Workspaces</a></li>
+<li><a href="#org123f75e">3.2.4. Keybinds</a></li>
</ul>
</li>
</ul>
</li>
-<li><a href="#orgd9a91f5">4. Credits</a></li>
+<li><a href="#org5ea945f">4. Credits</a></li>
</ul>
</div>
</div>
-<div id="outline-container-orge9be048" class="outline-2">
-<h2 id="orge9be048"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2>
+<div id="outline-container-orgbfb53c0" class="outline-2">
+<h2 id="orgbfb53c0"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2>
</div>
-<div id="outline-container-org90a4bc0" class="outline-2">
-<h2 id="org90a4bc0"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2>
+<div id="outline-container-org10dcbf8" class="outline-2">
+<h2 id="org10dcbf8"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2>
<div class="outline-text-2" id="text-2">
<p>
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).<br />
@@ -237,16 +237,16 @@ This only just works, multiple monitors aren't supported and floating windows ca
</div>
</div>
-<div id="outline-container-org5eaba64" class="outline-2">
-<h2 id="org5eaba64"><span class="section-number-2">3.</span> Usage instructions</h2>
+<div id="outline-container-org522cd53" class="outline-2">
+<h2 id="org522cd53"><span class="section-number-2">3.</span> Usage instructions</h2>
<div class="outline-text-2" id="text-3">
</div>
-<div id="outline-container-org41321d1" class="outline-3">
-<h3 id="org41321d1"><span class="section-number-3">3.1.</span> Installation</h3>
+<div id="outline-container-org5f71891" class="outline-3">
+<h3 id="org5f71891"><span class="section-number-3">3.1.</span> Installation</h3>
<div class="outline-text-3" id="text-3-1">
</div>
-<div id="outline-container-org318ad8e" class="outline-4">
-<h4 id="org318ad8e"><span class="section-number-4">3.1.1.</span> Pre reqs</h4>
+<div id="outline-container-org3dc64ae" class="outline-4">
+<h4 id="org3dc64ae"><span class="section-number-4">3.1.1.</span> Pre reqs</h4>
<div class="outline-text-4" id="text-3-1-1">
<ul class="org-ul">
<li><code>Xlib</code> and <code>g++</code> and <code>libnotify</code> to build the program<br /></li>
@@ -258,8 +258,8 @@ This only just works, multiple monitors aren't supported and floating windows ca
</ul>
</div>
</div>
-<div id="outline-container-orgf06bf1e" class="outline-4">
-<h4 id="orgf06bf1e"><span class="section-number-4">3.1.2.</span> Installing and removing</h4>
+<div id="outline-container-org309a902" class="outline-4">
+<h4 id="org309a902"><span class="section-number-4">3.1.2.</span> Installing and removing</h4>
<div class="outline-text-4" id="text-3-1-2">
<ul class="org-ul">
<li><code>make i</code> or <code>make install</code> to install<br /></li>
@@ -269,23 +269,23 @@ This only just works, multiple monitors aren't supported and floating windows ca
</div>
</div>
</div>
-<div id="outline-container-org3c09ef5" class="outline-3">
-<h3 id="org3c09ef5"><span class="section-number-3">3.2.</span> Config</h3>
+<div id="outline-container-orgb007d3a" class="outline-3">
+<h3 id="orgb007d3a"><span class="section-number-3">3.2.</span> Config</h3>
<div class="outline-text-3" id="text-3-2">
<p>
You can configure YATwm with the config file in <code>$HOME/.config/YATwm/config</code> or <code>$XDG_CONFIG_HOME/YATwm/config</code> 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 <code>/etc/YATwm/config</code>.<br />
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 <code>/etc/YATwm/config</code>.<br />
</p>
</div>
-<div id="outline-container-org43f17c0" class="outline-4">
-<h4 id="org43f17c0"><span class="section-number-4">3.2.1.</span> Syntax</h4>
+<div id="outline-container-org6dcf252" class="outline-4">
+<h4 id="org6dcf252"><span class="section-number-4">3.2.1.</span> Syntax</h4>
<div class="outline-text-4" id="text-3-2-1">
<p>
-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 <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. 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. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with <code>\</code> (e.g. <code>\'</code>), to insert <code>\</code> then use <code>\\</code>.<br />
+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 <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. 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. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with <code>\</code> (e.g. <code>\'</code>), to insert <code>\</code> then use <code>\\</code>. If you want to have multiple commands on the same line, e.g. binding a key to multiple commands, then use <code>;</code> as an argument on its own to separate them (tip: if you are using this for keybinds then enclose <b>all</b> the keybind commands in quotes, e.g. <code>bind mod+l "spawn i3lock ; spawn systemctl suspend"</code>).<br />
</p>
</div>
<ol class="org-ol">
-<li><a id="orgd79f7a9"></a>Command arg types<br />
+<li><a id="orge3364c9"></a>Command arg types<br />
<div class="outline-text-5" id="text-3-2-1-1">
<ul class="org-ul">
<li>String: this is just some text, this can be wrapped in quotes if you want a space in it.<br /></li>
@@ -302,7 +302,7 @@ The config file is a list of commands. Each command should be on a new line. For
</ul>
</div>
</li>
-<li><a id="org948d88f"></a>List of commands<br />
+<li><a id="orgbdd70f3"></a>List of commands<br />
<div class="outline-text-5" id="text-3-2-1-2">
<ul class="org-ul">
<li>exit: shuts down YATwm<br /></li>
@@ -359,17 +359,21 @@ The config file is a list of commands. Each command should be on a new line. For
</ul></li>
<li>bind: Binds a key to a command<br />
<ul class="org-ul">
-<li>String: The key bind, modifiers and keys are separated with +, e.g. <code>mod+x</code><br /></li>
+<li>String: The key bind, modifiers and keys are separated with +, e.g. <code>mod+x</code>. This can also be a key chord, where you have multiple binds, where when pressed in succession will execute the command (make sure to enclose this arg in quotes, and then separate the binds with spaces)<br /></li>
<li>String rest: The command to run<br /></li>
</ul></li>
+<li>quitkey: Sets the key to exit a key chord (note: pressing an unbound key also does this)<br />
+<ul class="org-ul">
+<li>String: The key bind, modifiers and keys are separated with +, e.g. <code>mod+g</code>.<br /></li>
+</ul></li>
<li>wsDump: This is a command for testing, you probably don't want to use it<br /></li>
</ul>
</div>
</li>
</ol>
</div>
-<div id="outline-container-org384a204" class="outline-4">
-<h4 id="org384a204"><span class="section-number-4">3.2.2.</span> General</h4>
+<div id="outline-container-org9f46c02" class="outline-4">
+<h4 id="org9f46c02"><span class="section-number-4">3.2.2.</span> General</h4>
<div class="outline-text-4" id="text-3-2-2">
<p>
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).<br />
@@ -379,8 +383,8 @@ YATwm also keeps a log file, the location of this file can be changed with the c
</div>
</div>
-<div id="outline-container-orga3a5f0e" class="outline-4">
-<h4 id="orga3a5f0e"><span class="section-number-4">3.2.3.</span> Workspaces</h4>
+<div id="outline-container-org7f3b7f1" class="outline-4">
+<h4 id="org7f3b7f1"><span class="section-number-4">3.2.3.</span> Workspaces</h4>
<div class="outline-text-4" id="text-3-2-3">
<p>
You can add workspace with the command <code>addworkspace</code> in the config file.<br />
@@ -406,8 +410,8 @@ Defaults workspace are listed below (these are the args for the addworkspace com
</ol>
</div>
</div>
-<div id="outline-container-orgee481dd" class="outline-4">
-<h4 id="orgee481dd"><span class="section-number-4">3.2.4.</span> Keybinds</h4>
+<div id="outline-container-org123f75e" class="outline-4">
+<h4 id="org123f75e"><span class="section-number-4">3.2.4.</span> Keybinds</h4>
<div class="outline-text-4" id="text-3-2-4">
<p>
Current keybinds (these can all be edited):<br />
@@ -427,6 +431,7 @@ Current keybinds (these can all be edited):<br />
<li><code>mod + f</code> : toggle fullscreen<br /></li>
<li><code>mod + (num)</code> : switch to workspace (num) - currently only for 1-10 but you can add more<br /></li>
<li><code>mod + shift + (num)</code> : move window to workspace (num) - currently only for 1-10 but you can add more<br /></li>
+<li><code>mod + g</code> : exit key chord<br /></li>
</ul>
<p>
(mod is super, and the direction keys are h, j, k, l - left, down, up, right respectively like vim)<br />
@@ -451,8 +456,8 @@ Commands are executed going down the list and multiple commands with the same ke
</div>
</div>
-<div id="outline-container-orgd9a91f5" class="outline-2">
-<h2 id="orgd9a91f5"><span class="section-number-2">4.</span> Credits</h2>
+<div id="outline-container-org5ea945f" class="outline-2">
+<h2 id="org5ea945f"><span class="section-number-2">4.</span> Credits</h2>
<div class="outline-text-2" id="text-4">
<p>
Catwm (<a href="https://github.com/pyknite/catwm">https://github.com/pyknite/catwm</a>)<br />
@@ -465,7 +470,7 @@ basic<sub>wm</sub> (<a href="https://github.com/jichu4n/basic_wm">https://github
</div>
</div>
<div id="postamble" class="status">
-<p class="date">Created: 2023-06-21 Wed 20:26</p>
+<p class="date">Created: 2023-06-28 Wed 21:24</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
diff --git a/readme.org b/readme.org
index 9a41662..f6257da 100644
--- a/readme.org
+++ b/readme.org
@@ -20,7 +20,7 @@ This only just works, multiple monitors aren't supported and floating windows ca
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~. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with ~\~ (e.g. ~\'~), to insert ~\~ then use ~\\~.
+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~. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with ~\~ (e.g. ~\'~), to insert ~\~ then use ~\\~. If you want to have multiple commands on the same line, e.g. binding a key to multiple commands, then use ~;~ as an argument on its own to separate them (tip: if you are using this for keybinds then enclose *all* the keybind commands in quotes, e.g. ~bind mod+l "spawn i3lock ; spawn systemctl suspend"~).
**** 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.
@@ -63,8 +63,12 @@ The config file is a list of commands. Each command should be on a new line. For
- 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: The key bind, structured according to the bind mode. This can also be a key chord, where you have multiple binds, where when pressed in succession will execute the command (make sure to enclose this arg in quotes, and then separate the binds with spaces)
- String rest: The command to run
+- quitkey: Sets the key to exit a key chord (note: pressing an unbound key also does this)
+ - String: The key bind, structured according to the bind mode.
+- bindmode: Sets the bind mode (Description of these further down)
+ - String: The bind mode to use
- 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).
@@ -104,6 +108,7 @@ Current keybinds (these can all be edited):
- ~mod + f~ : toggle fullscreen
- ~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 + g~ : exit key chord
(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~.
@@ -114,7 +119,8 @@ 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
-
+**** Bind modes
+The current two bind modes are ~normal~ and ~emacs~. The normal bind mode has the same syntax as i3, so key and modifiers separated with a '+', and use the xlib KeySym name for them. The emacs bind mode has the same syntax as emacs, so separate modifiers and keys with a '-', and the key comes last. It uses xlib keysyms, but for multi letter keys such as ~RET~, ~SPC~, ~ESC~, ~+~, ~-~ it has special logic to interpret how they would be written in emacs (note: if there are any other exceptions please let me know).
* Credits
Catwm (https://github.com/pyknite/catwm)
diff --git a/util.cpp b/util.cpp
index dff3428..58116d0 100644
--- a/util.cpp
+++ b/util.cpp
@@ -1,6 +1,7 @@
#include "util.h"
#include <sstream>
+#include <algorithm>
using std::string;
@@ -15,3 +16,17 @@ std::vector<string> split (const string &s, char delim) {
return result;
}
+
+const string evNames[] = {"", "", "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"};
+
+string getEventName(int e)
+{
+ return evNames[e];
+}
+
+string lowercase(string s)
+{
+ string s2 = s;
+ std::transform(s2.begin(), s2.end(), s2.begin(), [](unsigned char c){ return std::tolower(c); });
+ return s2;
+}
diff --git a/util.h b/util.h
index bdc45d8..66ecf76 100644
--- a/util.h
+++ b/util.h
@@ -4,11 +4,14 @@
#include <string>
#include <X11/Xlib.h>
-#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::string getEventName(int e);
std::vector<std::string> split (const std::string &s, char delim);
+std::string lowercase(std::string s);
+
struct Globals {
Display*& dpy;