Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModeSwitch modifier key not working properly #1964

Open
nbonfils opened this issue Nov 29, 2024 · 2 comments
Open

ModeSwitch modifier key not working properly #1964

nbonfils opened this issue Nov 29, 2024 · 2 comments

Comments

@nbonfils
Copy link

I remaped my CapsLock key to ModeSwitch to leverage Xmodmap so that I can have access to some nice stuff like arrow keys while holding CapsLock etc...

For the sake of completeness, my .Xmodmap looks like something like this:

clear lock
keycode 66 = Mode_switch 

! Redifine keys to make use of Mode_switch layer
keycode 31 = i I Up
keycode 44 = j J Left
keycode 45 = k K Down
keycode 46 = l L Right

Most application like the web browser, emacs, xterm, xev etc... pickup that when I do caps+j it means Left.

I tried logging keys from my init.lua:

local on_key_pressed__orig = keymap.on_key_pressed

function keymap.on_key_pressed(k, ...)
   core.log(k)
   return on_key_pressed__orig(k, ...)
end

And basically what I see when I press ModeSwitch (aka CapsLock) is nothing, I pressed ModeSwitch 4 times at the end here:

1732857573

So I dove deeper and saw another issue that mentionned the checkkeys program from SDL: #64 (comment)

And so I tried it and this is what happens when I press some keys, then I try the combination caps+j (which is Left):

$ ./checkkeys 
INFO: Initial state: modifiers: (none)
INFO: Key pressed :  scancode 4 = A, keycode 0x00000061 = A  modifiers: (none)
INFO: INPUT Text (\x61): "a"
INFO: Key released:  scancode 4 = A, keycode 0x00000061 = A  modifiers: (none)
INFO: Key pressed :  scancode 4 = A, keycode 0x00000061 = A  modifiers: (none)
INFO: INPUT Text (\x61): "a"
INFO: Key released:  scancode 4 = A, keycode 0x00000061 = A  modifiers: (none)
INFO: Key pressed :  scancode 224 = Left Ctrl, keycode 0x400000E0 = Left Ctrl  modifiers: LCTRL
INFO: Key released:  scancode 224 = Left Ctrl, keycode 0x400000E0 = Left Ctrl  modifiers: (none)
INFO: Key pressed :  scancode 224 = Left Ctrl, keycode 0x400000E0 = Left Ctrl  modifiers: LCTRL
INFO: Key released:  scancode 224 = Left Ctrl, keycode 0x400000E0 = Left Ctrl  modifiers: (none)
INFO: Key pressed :  scancode 225 = Left Shift, keycode 0x400000E1 = Left Shift  modifiers: LSHIFT
INFO: Key pressed :  scancode 6 = C, keycode 0x00000063 = C  modifiers: LSHIFT
INFO: INPUT Text (\x43): "C"
INFO: Key released:  scancode 6 = C, keycode 0x00000063 = C  modifiers: LSHIFT
INFO: Key released:  scancode 225 = Left Shift, keycode 0x400000E1 = Left Shift  modifiers: (none)
INFO: Key pressed :  scancode 40 = Return, keycode 0x0000000D = Return  modifiers: (none)
INFO: Key released:  scancode 40 = Return, keycode 0x0000000D = Return  modifiers: (none)
INFO: Key pressed :  scancode 257 = ModeSwitch, keycode 0x40000000 =   modifiers: (none)
INFO: Key pressed :  scancode 13 = J, keycode 0x0000006A = J  modifiers: (none)
INFO: Key released:  scancode 13 = J, keycode 0x0000006A = J  modifiers: (none)
INFO: Key released:  scancode 257 = ModeSwitch, keycode 0x40000000 =   modifiers: (none)

From this I understand 2 things:

  1. SDL knows about the ModeSwitch key
  2. SDL doesn't consider the ModeSwitch key as a proper modifier

My next guess is that something could be done about this here:
https://github.com/lite-xl/lite-xl/blob/master/src/api/system.c#L121-L147

But that's where I am starting to struggle as I am not yet very familiar with Lite-xl or SDL2.
I don't mind trying to fix this, but I will need a bit of hand holding here.

@Guldoman
Copy link
Member

As I don't really use X I can't directly help with this, but feel free to hop on our Discord server (an invite is at the top of our README and on our website) if you need anything.

@nbonfils
Copy link
Author

nbonfils commented Dec 2, 2024

After digging and thinking a bit, it seems that even if we hacked our way around to take into account the ModeSwitch key as a special modifier. It would still not take into account the Xmodmap remaps...
So the only way would then be to reproduce the the ModeSwitch+key bindings in lite-xl keymap. That really sounds like a last resort and pretty inefficient hack.

So I just opened an issue upstream: libsdl-org/SDL#11562

I think I'll still try to implement this hack as a temporary solution, because I don't think this will be fixed and released anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants