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 <nobody@lumidify.org>
Date:   Sat, 28 May 2022 12:12:52 +0200

Slightly improve key handling

Diffstat:
Mconfigparser.c | 7+++++++
Mkeys.c | 14++++++++++----
Mleditrc.5 | 29+++++++++++++++++++++++++++--
3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/configparser.c b/configparser.c @@ -890,24 +890,31 @@ parse_modmask(char *modmask_str, size_t len, unsigned int *mask_ret) { if (str_array_equal("shift", modmask_str + cur, LEDIT_MIN(5, len - cur))) { cur += 5; *mask_ret |= ShiftMask; + /* } else if (str_array_equal("lock", modmask_str + cur, LEDIT_MIN(4, len - cur))) { cur += 4; *mask_ret |= LockMask; + */ } else if (str_array_equal("control", modmask_str + cur, LEDIT_MIN(7, len - cur))) { cur += 7; *mask_ret |= ControlMask; } else if (str_array_equal("mod1", modmask_str + cur, LEDIT_MIN(4, len - cur))) { cur += 4; *mask_ret |= Mod1Mask; + /* } else if (str_array_equal("mod2", modmask_str + cur, LEDIT_MIN(4, len - cur))) { cur += 4; *mask_ret |= Mod2Mask; + */ } else if (str_array_equal("mod3", modmask_str + cur, LEDIT_MIN(4, len - cur))) { cur += 4; *mask_ret |= Mod3Mask; } else if (str_array_equal("mod4", modmask_str + cur, LEDIT_MIN(4, len - cur))) { cur += 4; *mask_ret |= Mod4Mask; + } else if (str_array_equal("mod5", modmask_str + cur, LEDIT_MIN(4, len - cur))) { + cur += 4; + *mask_ret |= Mod5Mask; } else if (str_array_equal("any", modmask_str + cur, LEDIT_MIN(3, len - cur))) { cur += 3; *mask_ret = UINT_MAX; diff --git a/keys.c b/keys.c @@ -14,11 +14,10 @@ #include "keys.h" /* FIXME: Does this break anything? */ -/*static unsigned int importantmod = ShiftMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask;*/ -/* FIXME: ShiftMask is currently masked away anyways, so it isn't really important */ +/* FIXME: ShiftMask is currently masked away when the key contains text - is this correct? */ /* 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 usually) */ +static unsigned int importantmod = ShiftMask | ControlMask | Mod1Mask | Mod3Mask | Mod4Mask | Mod5Mask; int match_key(unsigned int mask, unsigned int state) @@ -46,6 +45,13 @@ preprocess_key( * and the modifier mask can be checked separately. Please tell me if you * know the proper way to do this. */ + /* + * Note on the above: I guess XKB tries to be smart and map the keys back to + * the first language when control is pressed and multiple languages are + * configured. This is completely useless for ledit, though, because most + * keys don't use control in normal mode, and it just messes with all the + * 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 @@ -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 corresponding +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 nicer. .Pp .Sy modes specifies the allowed modes and can be a combination of