rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.74k stars 162 forks source link

Lorien ignores bindings from keyd-application-mapper #181

Closed i-c-u-p closed 2 years ago

i-c-u-p commented 2 years ago

Application bindings set for Lorien in ~/.config/app.conf don't work when keyd-application-mapper is running, even though the window is detected. Lorien was installed from the AUR package lorien-bin. When a Lorien window is in focus, it shows up in keyd-application-mapper's logs as Active window: lorien|lorien-v0-4-0.

Here's my configs:

~/.config/keyd/app.conf:

[alacritty]
extend.i = S-pagedown
extend.o = S-pageup

[alacritty|htop]
extend.i = pagedown
extend.o = pageup

[lorien]
extend+shift.b = C-y
/etc/keyd/default.conf: ``` [ids] * # Colemak-DH (Curl+Angle mods) [main] esc = overload(switch, capslock) capslock = overload(extend, esc) rightmeta = compose rightcontrol = rightcontrol rightshift = rightshift e = f r = p t = b y = j u = l i = u o = y p = ; s = r d = s f = t h = m j = n k = e l = i ; = o z = x x = c c = d b = z n = k m = h [qwerty] esc = overload(switch, capslock) capslock = overload(extend, esc) rightmeta = compose rightcontrol = rightcontrol rightshift = rightshift e = e r = r t = t y = y u = u i = i o = o p = p s = s d = d f = f h = h j = j k = k l = l ; = ; z = z x = x c = c b = b n = n m = m [noCapsLayer] capslock = esc [extend:C] j = left k = down l = up ; = right 1 = f1 2 = f2 3 = f3 4 = f4 5 = f5 6 = f6 7 = f7 8 = f8 9 = f9 0 = f10 - = f11 = = f12 m = home / = end i = pagedown o = pageup f = backspace r = delete s = layer(alt) d = layer(shift) space = layer(control) g = enter [extend+control] s = layer(alt) d = layer(shift) [extend+shift] space = layer(control) s = layer(alt) [extend+alt] d = layer(shift) space = layer(control) [extend+control+shift] s = layer(alt) [extend+control+alt] d = layer(shift) [extend+shift+alt] space = layer(control) [extend+control+shift+alt] [switch] q = toggle(qwerty) w = toggle(noCapsLayer) ```
rvaiya commented 2 years ago

Can you post the output of KEYD_DEBUG=1 keyd-application-mapper using the latest commit?

i-c-u-p commented 2 years ago

Can you post the output of KEYD_DEBUG=1 keyd-application-mapper using the latest commit?

$ keyd -v
keyd v2.3.1-rc (8f0727c)
$ KEYD_DEBUG=1 keyd-application-mapper
X detected
Active window: alacritty|keyd-debug-1-keyd-application-mapper
    Matched alacritty|*
DEBUG: src/keyd.c:454: Debug mode activated
Active window: lorien|lorien-v0-4-0
    Matched lorien|*
DEBUG: src/keyd.c:454: Debug mode activated
Active window: mousepad|untitled-6-mousepad
DEBUG: src/keyd.c:454: Debug mode activated
Active window: mousepad|config-keyd-app-conf-mousepad
DEBUG: src/keyd.c:454: Debug mode activated
Active window: alacritty|keyd-debug-1-keyd-application-mapper
    Matched alacritty|*
DEBUG: src/keyd.c:454: Debug mode activated
Active window: lorien|lorien-v0-4-0
    Matched lorien|*
DEBUG: src/keyd.c:454: Debug mode activated
Active window: mousepad|config-keyd-app-conf-mousepad
DEBUG: src/keyd.c:454: Debug mode activated
Active window: lorien|lorien-v0-4-0
    Matched lorien|*
DEBUG: src/keyd.c:454: Debug mode activated
Active window: alacritty|keyd-debug-1-keyd-application-mapper
    Matched alacritty|*
DEBUG: src/keyd.c:454: Debug mode activated
rvaiya commented 2 years ago

It looks like the rule is being matched correctly. What is the output of keyd -m after pressing capslock+shift+b while lorien is focused?

i-c-u-p commented 2 years ago

It looks like the rule is being matched correctly. What is the output of keyd -m after pressing capslock+shift+b while lorien is focused?

output of capslock+s+b:

$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <redacted keyboard id> (<redacted keyboard name>  Keyboard)
device added: <redacted mouse id> (<redacted mouse name>)
keyd virtual device 0fac:0ade   enter up
<redacted mouse name>   <redacted mouse id> leftmouse down
<redacted mouse name>   <redacted mouse id> leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   leftcontrol up

output of capslock+leftshift+b:

$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <redacted keyboard id> (<redacted keyboard name>  Keyboard)
device added: <redacted mouse id> (<redacted mouse name>)
keyd virtual device 0fac:0ade   enter up
<redacted mouse name>   <redacted mouse id> leftmouse down
<redacted mouse name>   <redacted mouse id> leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   leftcontrol up

While pressing the capslock+leftshift+b bind repeatedly during testing, the C-y binding actually did occasionally activate in Lorien, but it happens randomly and I can't reliably reproduce it other than mashing capslock+leftshift+b until it does.

rvaiya commented 2 years ago

It looks like keyd is emitting the correct keycodes. My suspicion is that lorien doesn't like the additional leftshift events. Try a simpler binding like - = C-y and see if it works consistently.

i-c-u-p commented 2 years ago

It looks like keyd is emitting the correct keycodes. My suspicion is that lorien doesn't like the additional leftshift events. Try a simpler binding like - = C-y and see if it works consistently.

Changing the binding and hitting - results in the same problem. Here's the output log (along with C-y which does work):

app.conf (Lorien section):

[lorien]
- = C-y

output of pressing - on keyboard:

$ keyd -v
keyd v2.3.1-rc (9325bf3)
$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <keyboard id> (<keyboard name>  Keyboard)
device added: <mouse id> (<mouse name>)
keyd virtual device 0fac:0ade   enter up
<mouse name>    <mouse id>  leftmouse down
<mouse name>    <mouse id>  leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftcontrol up

output of pressing C-y on keyboard:

$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <keyboard id> (<keyboard name>  Keyboard)
device added: <mouse id> (<mouse name>)
keyd virtual device 0fac:0ade   enter up
<mouse name>    <mouse id>  leftmouse down
<mouse name>    <mouse id>  leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftcontrol up
rvaiya commented 2 years ago

Can you try this using the test branch? (e.g git fetch origin; git checkout origin/test; make && sudo make install)

i-c-u-p commented 2 years ago

Can you try this using the test branch? (e.g git fetch origin; git checkout origin/test; make && sudo make install)

Still doesn't work. Output log:

$ keyd -v
keyd v2.3.1-rc (84b58e8)
$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <keyboard id> (<keyboard name>  Keyboard)
device added: <mouse id> (<mouse name>)
keyd virtual device 0fac:0ade   enter up
<mouse name>    <mouse id>  leftmouse down
<mouse name>    <mouse id>  leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftcontrol up
rvaiya commented 2 years ago

Can you try the tip of test again? I believe this should do the trick.

i-c-u-p commented 2 years ago

Can you try the tip of test again? I believe this should do the trick.

That fixed it. Output log:

Pressing -:

$ keyd -v
keyd v2.3.1-rc (6c4c6ac)
$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <keyboard id> (<keyboard name>  Keyboard)
device added: <mouse id> (<mouse name>)
keyd virtual device 0fac:0ade   enter up
<mouse name>    <mouse id>  leftmouse down
<mouse name>    <mouse id>  leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftcontrol up

Pressing capslock+d+b (after changing [lorien] section of app.conf back to extend+shift.b = C-y):

$ sudo keyd -m
device added: 0fac:0ade (keyd virtual device)
device added: <keyboard id> (<keyboard name>  Keyboard)
device added: <mouse id> (<mouse name>)
keyd virtual device 0fac:0ade   enter up
<mouse name>    <mouse id>  leftmouse down
<mouse name>    <mouse id>  leftmouse up
keyd virtual device 0fac:0ade   leftcontrol down
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   y down
keyd virtual device 0fac:0ade   y up
keyd virtual device 0fac:0ade   leftshift down
keyd virtual device 0fac:0ade   leftshift up
keyd virtual device 0fac:0ade   leftcontrol up
rvaiya commented 2 years ago

Thanks. As I suspected, it appears to be a bug in Lorien's (or possibly Godot's) input logic, which requires a pause after the initial key down. I will have to think about how best to allow users to account for this in a generic way.

rvaiya commented 2 years ago

I believe this should work out of the box in the latest commit.

i-c-u-p commented 2 years ago

EDIT: Ignore this comment, the issue was with Lorien itself and not keyd


The Lorien bindings work in the latest commit, but they still have a problem that I unfortunately forgot to mention earlier, which is that they don't repeat when held.

https://user-images.githubusercontent.com/96894903/163755558-1e5f5572-d885-42fc-a165-3180e86a47d3.mp4

In this demonstration video in Mousepad, you can see that when capslock+b is held, it outputs C-z with the delay and rate set in x (I actually set it in xfce4-keyboard-settings, but it's reflected in xset q (output below)) and when holding and releasing d ontop of capslock+b it switches between C-z and C-s-z with no delay, which appears up as the text appearing and disappearing in a sweeping motion in the video. But in Lorien when capslock+b or capslock+d+b are held, C-z and C-s-z don't repeat and so b has to be released and pressed repeatedly to input it multiple times. This happens in keyd versions a5e6a83 and 6c4c6ac. My configs have changed so I'll also include those again.

"xset q" output: ``` Keyboard Control: auto repeat: on key click percent: 0 LED mask: 00000002 XKB indicators: 00: Caps Lock: off 01: Num Lock: on 02: Scroll Lock: off 03: Compose: off 04: Kana: off 05: Sleep: off 06: Suspend: off 07: Mute: off 08: Misc: off 09: Mail: off 10: Charging: off 11: Shift Lock: off 12: Group 2: off 13: Mouse Keys: off auto repeat delay: 250 repeat rate: 50 auto repeating keys: 00ffffffdffffbbf fadfffefffedffff 9fffffffffffffff fff7ffffffffffff bell percent: 50 bell pitch: 400 bell duration: 100 Pointer Control: acceleration: 2/1 threshold: 4 Screen Saver: prefer blanking: no allow exposures: no timeout: 1200 cycle: 900 Colors: default colormap: 0x20 BlackPixel: 0x0 WhitePixel: 0xffffff Font Path: /usr/share/fonts/misc,/usr/share/fonts/TTF,/usr/share/fonts/OTF,/usr/share/fonts/100dpi,/usr/share/fonts/75dpi,built-ins DPMS (Energy Star): Standby: 1800 Suspend: 0 Off: 3600 DPMS is Enabled Monitor is On ```
~/.config/keyd/app.conf: ``` [alacritty] CapsLayer.i = S-pagedown CapsLayer.o = S-pageup [alacritty|htop] CapsLayer.i = pagedown CapsLayer.o = pageup [alacritty|man-*] CapsLayer.i = pagedown CapsLayer.o = pageup [lorien] CapsLayer+shift.b = C-y [gimp-2-10] CapsLayer+shift.b = C-y ```
/etc/keyd/default.conf: ``` [ids] * # Colemak-DH (Curl+Angle mods) [main] esc = overload(LayoutLayer, capslock) capslock = overload(CapsLayer, esc) rightmeta = compose rightcontrol = rightcontrol rightshift = rightshift e = f r = p t = b y = j u = l i = u o = y p = ; s = r d = s f = t h = m j = n k = e l = i ; = o z = x x = c c = d b = z n = k m = h [QWERTY] e = e r = r t = t y = y u = u i = i o = o p = p s = s d = d f = f h = h j = j k = k l = l ; = ; z = z x = x c = c b = b n = n m = m [NoCapsLayer] capslock = esc [NumPrac] a = tab s = S-enter d = C-backspace f = backspace [CapsLayer:C] j = left k = down l = up ; = right 1 = f1 2 = f2 3 = f3 4 = f4 5 = f5 6 = f6 7 = f7 8 = f8 9 = f9 0 = f10 - = f11 = = f12 m = home / = end i = pagedown o = pageup f = backspace r = delete space = layer(control) s = layer(alt) d = layer(shift) g = enter [CapsLayer+control] s = layer(alt) d = layer(shift) [CapsLayer+shift] space = layer(control) s = layer(alt) [CapsLayer+alt] d = layer(shift) space = layer(control) [CapsLayer+control+shift] s = layer(alt) [CapsLayer+control+alt] d = layer(shift) [CapsLayer+shift+alt] space = layer(control) [CapsLayer+control+shift+alt] [LayoutLayer] q = toggle(QWERTY) w = toggle(NoCapsLayer) e = toggle(NumPrac) ```
rvaiya commented 2 years ago

Does this work without keyd? I would assume Lorien just doesn't implement key repeat.

i-c-u-p commented 2 years ago

Does this work without keyd? I would assume Lorien just doesn't implement key repeat.

Yes; I guess it's just an issue with Lorien then. I probably should have checked that before making a long-winded comment about it... I'll close the issue now since this is fixed.

rvaiya commented 2 years ago

I've enhanced macros to allow for timeouts to be specified between individual keys. This should allow you to make use of keyd's built in macro repeat functionality to achieve what you want.

Try mapping to something like macro(leftcontrol+b+1ms). You may have to increase the timeout from 1ms, depending on how long of a gap lorien expects.

i-c-u-p commented 2 years ago

I've enhanced macros to allow for timeouts to be specified between individual keys. This should allow you to make use of keyd's built in macro repeat functionality to achieve what you want.

Try mapping to something like macro(leftcontrol+b+1ms). You may have to increase the timeout from 1ms, depending on how long of a gap lorien expects.

A delay around 12ms seems to be the fastest for Lorien macros. As it's set lower than that, Lorien starts missing progressively more inputs, which makes it slower. Although alternating between repeating C-z and C-y can't be done instantly (such as the "sweeping" effect I showed in the vid a few comments back) by holding and releasing d while capslock+b is held and instead requires releasing and holding some keys:

While holding capslock+b: release b hold d hold b *C-y starts being output*

While holding capslock+d+b: release b release d hold b *C-z starts being output*

But the ability to alternate between spamming undos and redos without delay isn't very practically useful, so this isn't much of a problem.

As a side issue, I added macro_timeout = 250 and macro_repeat_timeout = 20 to my default.conf to try matching what appears in xset q, and I think the repeat timeout isn't actually reached. According to xset q my auto repeat delay is 250 and repeat rate is 50. I held down the a key for 4 seconds (approximately; I eyeballed it using my clock in xfce) twice and on average there were 185 a's. Then I did the same holding capslock+a after adding CapsLayer.a = macro(a) to a new [mousepad] section in app.conf, and it averaged to 133.5 a's. This means the delay is only ~72.16% as fast as expected. I did the same test holding capslock+s with CapsLayer.s = macro2(250, 20, a) under [mousepad] and that only produced 123 a's, ~66.49% of the expected amount.

As for the repeat delay set in macro_timeout and macro2(), I couldn't tell any difference by eye so a more rigorous method would be needed to check those.

~/.config/keyd/app.conf: ``` [alacritty] CapsLayer.i = S-pagedown CapsLayer.o = S-pageup [alacritty|htop] CapsLayer.i = pagedown CapsLayer.o = pageup [alacritty|man-*] CapsLayer.i = pagedown CapsLayer.o = pageup [lorien] CapsLayer.b = macro(leftcontrol+z+12ms) CapsLayer+shift.b = macro(leftcontrol+y+12ms) [gimp-2-10] CapsLayer+shift.b = C-y ```
/etc/keyd/default.conf: ``` [ids] * [global] macro_timeout = 250 macro_repeat_timeout = 20 # Colemak-DH (Curl+Angle mods) [main] esc = overload(LayoutLayer, capslock) capslock = overload(CapsLayer, esc) rightmeta = compose rightcontrol = rightcontrol rightshift = rightshift e = f r = p t = b y = j u = l i = u o = y p = ; s = r d = s f = t h = m j = n k = e l = i ; = o z = x x = c c = d b = z n = k m = h [QWERTY] e = e r = r t = t y = y u = u i = i o = o p = p s = s d = d f = f h = h j = j k = k l = l ; = ; z = z x = x c = c b = b n = n m = m [NoCapsLayer] capslock = esc [NumPrac] a = tab s = S-enter d = C-backspace f = backspace [CapsLayer:C] j = left k = down l = up ; = right 1 = f1 2 = f2 3 = f3 4 = f4 5 = f5 6 = f6 7 = f7 8 = f8 9 = f9 0 = f10 - = f11 = = f12 m = home / = end i = pagedown o = pageup f = backspace r = delete space = layer(control) d = layer(shift) s = layer(alt) g = enter [CapsLayer+control] s = layer(alt) d = layer(shift) [CapsLayer+shift] space = layer(control) s = layer(alt) [CapsLayer+alt] d = layer(shift) space = layer(control) [CapsLayer+control+shift] s = layer(alt) [CapsLayer+control+alt] d = layer(shift) [CapsLayer+shift+alt] space = layer(control) [CapsLayer+control+shift+alt] [LayoutLayer] q = toggle(QWERTY) w = toggle(NoCapsLayer) e = toggle(NumPrac) ```
rvaiya commented 2 years ago

Although alternating between repeating C-z and C-y can't be done instantly (such as the "sweeping" effect I showed in the vid a few comments back) by holding and releasing d while capslock+b is held and instead requires releasing and holding some keys...

From what I can see from your config, what you have described is expected behaviour, though it i possible I have not understood something. If you think there is a bug in the macro logic, I would appreciate it if you could create a dedicated issue and provide the minimal steps to reproduce it.

As a side issue, I added macro_timeout = 250 and macro_repeat_timeout = 20 to my default.conf to try matching what appears in xset q, and I think the repeat timeout isn't actually reached. A

Please read the manpage carefully. The keyd options mean different things and are measured in different units.

Edit: Apologies, it appears I read your comment in haste. It seems you have correctly converted the xset value into miliseconds. There is indeed a resolution issue, I will investigate further.

Edit 2: The timeout issue has been fixed.

I am treating this issue as closed for now since the original problem has been resolved.

i-c-u-p commented 2 years ago

Edit 2: The timeout issue has been fixed.

Tested and it's indeed fixed for macro() and macro2() after updating to 49f863c.