keyd icon indicating copy to clipboard operation
keyd copied to clipboard

Bindings in nested layers involving shift wrongly holding down shift

Open heyzec opened this issue 2 years ago • 3 comments

Hi there, many thanks for creating this program. It has been very helpful to me and I am currently using it on a daily basis.

I was exploring nested layers and found this strange behaviour. When using the config directly from examples/nav-layer.conf:

# In essence we want:
...
#  - capslock+shift+h = C-left
#  - capslock+shift+l = C-right
#  - capslock+shift+j = C-down
#  - capslock+shift+k = C-up

[main]
capslock = overload(capslock, esc)

[shift]
capslock = layer(capslock_shift)

[capslock:C]
shift = layer(capslock_shift)
h = left
...

[capslock_shift]
h = C-left
...

However,

  • Hold down capslock, then hold down shift, then press h: Ctrl-left (expected)
  • Hold down shift, then hold down capslock, then press h: Ctrl-shift-left (unexpected)

I am using on Hyprland + NixOS. I have also tried out the config on a clean install of Ubuntu 22.04 with the same issue appearing.

Edit: Not sure if related to https://github.com/rvaiya/keyd/issues/490

heyzec avatar Oct 19 '23 13:10 heyzec

Oh, good catch! I think that example was created before composite layers existed. The way to achieve it now would be simply:

[ids]
*

[main]
capslock = overload(capslock, esc)

[capslock:C]
h = left
j = down
k = up
l = right

[capslock+shift]
h = C-left
j = C-down
k = C-up
l = C-right

Nested layers are inherently order-dependent and a bit harder to reason about, but I think the behaviour you're observing is reasonable. After all, if you press shift first, the modifier remains active (since you're only adding to it with layer(capslock_shift) rather than using swap(capslock_shift)). But if you press capslock first, a subsequent activation of shift gets rerouted directly to capslock_shift, without ever activating the "real" shift.

So the example is wrong --- it should be removed/changed.

nsbgn avatar Oct 19 '23 14:10 nsbgn

Ahh, thanks for the quick reply! I was testing what you had and it works perfectly! If you don't mind, I think I can help with the trivial task of opening a PR with your example.

heyzec avatar Oct 19 '23 14:10 heyzec

Sure! rvaiya is the one who ultimately decides on PRs but this seems rather cut and dry :)

nsbgn avatar Oct 19 '23 15:10 nsbgn