tSlightly improve key handling - ledit - Text editor (WIP) | |
git clone git://lumidify.org/ledit.git (fast, but not encrypted) | |
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow) | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 3d224fbf6ef3157c0b8a93a32da2e87b27aa943f | |
parent 865902c9561f792f454c3825f5dddbb88365802d | |
Author: lumidify <[email protected]> | |
Date: Sat, 28 May 2022 12:12:52 +0200 | |
Slightly improve key handling | |
Diffstat: | |
M configparser.c | 7 +++++++ | |
M keys.c | 14 ++++++++++---- | |
M leditrc.5 | 29 +++++++++++++++++++++++++++-- | |
3 files changed, 44 insertions(+), 6 deletions(-) | |
--- | |
diff --git a/configparser.c b/configparser.c | |
t@@ -890,24 +890,31 @@ parse_modmask(char *modmask_str, size_t len, unsigned in… | |
if (str_array_equal("shift", modmask_str + cur, LEDIT_MIN(5, l… | |
cur += 5; | |
*mask_ret |= ShiftMask; | |
+ /* | |
} else if (str_array_equal("lock", modmask_str + cur, LEDIT_MI… | |
cur += 4; | |
*mask_ret |= LockMask; | |
+ */ | |
} else if (str_array_equal("control", modmask_str + cur, LEDIT… | |
cur += 7; | |
*mask_ret |= ControlMask; | |
} else if (str_array_equal("mod1", modmask_str + cur, LEDIT_MI… | |
cur += 4; | |
*mask_ret |= Mod1Mask; | |
+ /* | |
} else if (str_array_equal("mod2", modmask_str + cur, LEDIT_MI… | |
cur += 4; | |
*mask_ret |= Mod2Mask; | |
+ */ | |
} else if (str_array_equal("mod3", modmask_str + cur, LEDIT_MI… | |
cur += 4; | |
*mask_ret |= Mod3Mask; | |
} else if (str_array_equal("mod4", modmask_str + cur, LEDIT_MI… | |
cur += 4; | |
*mask_ret |= Mod4Mask; | |
+ } else if (str_array_equal("mod5", modmask_str + cur, LEDIT_MI… | |
+ cur += 4; | |
+ *mask_ret |= Mod5Mask; | |
} else if (str_array_equal("any", modmask_str + cur, LEDIT_MIN… | |
cur += 3; | |
*mask_ret = UINT_MAX; | |
diff --git a/keys.c b/keys.c | |
t@@ -14,11 +14,10 @@ | |
#include "keys.h" | |
/* FIXME: Does this break anything? */ | |
-/*static unsigned int importantmod = ShiftMask | ControlMask | Mod1Mask | Mod2… | |
-/* FIXME: ShiftMask is currently masked away anyways, so it isn't really impor… | |
+/* FIXME: ShiftMask is currently masked away when the key contains text - is t… | |
/* FIXME: The Mod*Masks can be remapped, so it isn't really clear what is what… | |
-/* most are disabled now to avoid issues with e.g. numlock */ | |
-static unsigned int importantmod = ShiftMask | ControlMask | Mod1Mask; | |
+/* LockMask and Mod2Mask in particular are disabled (caps lock and numlock usu… | |
+static unsigned int importantmod = ShiftMask | ControlMask | Mod1Mask | Mod3Ma… | |
int | |
match_key(unsigned int mask, unsigned int state) | |
t@@ -46,6 +45,13 @@ preprocess_key( | |
* and the modifier mask can be checked separately. Please tell me if … | |
* know the proper way to do this. | |
*/ | |
+ /* | |
+ * Note on the above: I guess XKB tries to be smart and map the keys b… | |
+ * the first language when control is pressed and multiple languages a… | |
+ * configured. This is completely useless for ledit, though, because m… | |
+ * keys don't use control in normal mode, and it just messes with all … | |
+ * keys that do use control because ledit does its own mapping. | |
+ */ | |
event->xkey.state &= ~ControlMask; | |
/* FIXME: X_HAVE_UTF8_STRING See XmbLookupString(3) */ | |
*buf_len_ret = Xutf8LookupString( | |
diff --git a/leditrc.5 b/leditrc.5 | |
t@@ -187,15 +187,40 @@ must be specified. | |
specifies modifier keys. | |
The current options are | |
.Ar shift , | |
-.Ar lock , | |
.Ar control , | |
.Ar mod1 , | |
-.Ar mod2 , | |
.Ar mod3 , | |
.Ar mod4 , | |
.Ar mod5 , | |
and | |
.Ar any . | |
+.Ar mod1 | |
+is usually Alt, | |
+.Ar mod4 | |
+is usually the super key. | |
+Note that | |
+.Ar mod2 | |
+and | |
+.Ar lock | |
+are missing because these are usually numlock and caps lock, respectively, | |
+which would mess up the key bindings because they would all need to optionally | |
+include these. | |
+This key handling is currently a bit of a mess because it isn't really clear | |
+which modifier keys should be ignored and which shouldn't. | |
+As an additional bit of weirdness, | |
+.Ar control | |
+is currently masked out before obtaining the text or symbolic name correspondi… | |
+to a key because it can cause issues in certain cases (XKB tries to be | |
+.Dq smart | |
+and map some keys back to the default language, but that completely messes | |
+up all the key handling that | |
+.Xr ledit 1 | |
+does). | |
+Oh, one more thing - for keys that are specified with text instead of a keysym, | |
+.Ar shift | |
+is masked out of the current modifier state before checking if it matches the | |
+configured state because it is usually included implicitly in the text. | |
+Please let me know if you have any ideas how to make the key handling a bit ni… | |
.Pp | |
.Sy modes | |
specifies the allowed modes and can be a combination of |