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

Interaction between modifier, layer, and parent layer triggers parent incorrectly #47

Closed
canadaduane opened this issue Nov 15, 2021 · 5 comments

Comments

@canadaduane
Copy link
Contributor

canadaduane commented Nov 15, 2021

When I create a layer triggered on leftalt, with a parent layout as modifier 'M', with key mappings that trigger leftalt-* combinations, I get a strange effect where the original parent layer ('M' in this case) is triggered in addition to the A-1 or A-2 keys:

leftalt = layer(macmeta)

[macmeta:M]
1 = A-1
2 = A-2

When I run keyd -m I see that there are indeed multiple keydown and keyup events--the meta key goes down/up, then alt goes down and 1 goes down, then alt goes up. (Note that only Alt-1 is being pressed physically):

keyd virtual keyboard: meta down
keyd virtual keyboard: meta up
keyd virtual keyboard: alt down
keyd virtual keyboard: 1 down
^[1keyd virtual keyboard: alt up
keyd virtual keyboard: 1 up

I'm going to reboot and see if anything changes, but I wanted to leave this here in case the data has value in replication for anyone else.

@canadaduane
Copy link
Contributor Author

Ok, I think I have another possible clue: When I rebooted, and ran keyd -m, I got a different keyboard:

$ sudo keyd -m
[sudo] password for duane: 
AT Translated Set 2 keyboard: enter up
AT Translated Set 2 keyboard: a down
aAT Translated Set 2 keyboard: a up
AT Translated Set 2 keyboard: b down
bAT Translated Set 2 keyboard: b up
AT Translated Set 2 keyboard: alt down
AT Translated Set 2 keyboard: 1 down
^[1AT Translated Set 2 keyboard: 1 up
AT Translated Set 2 keyboard: alt up
AT Translated Set 2 keyboard: control down
AT Translated Set 2 keyboard: c down

And the unwanted "meta" key down/up is not present there.

I tested a 2nd time, and now suddenly it's grabbing a different keyboard:

$ sudo keyd -m
keyd virtual keyboard: enter up
keyd virtual keyboard: meta down
keyd virtual keyboard: meta up
keyd virtual keyboard: alt down
keyd virtual keyboard: 1 down
^[1keyd virtual keyboard: alt up
keyd virtual keyboard: 1 up
keyd virtual keyboard: esc down
keyd virtual keyboard: esc up
Generic USB Keyboard: control down

... and this one has the unwanted meta down/up again. Strange...

@rvaiya
Copy link
Owner

rvaiya commented Nov 15, 2021

When I create a layer triggered on leftalt, with a parent layout as modifier 'M', with key mappings that trigger leftalt-* combinations, I get a strange effect where the original parent layer ('M' in this case) is triggered in addition to the A-1 or A-2 keys:

The output you have posted is consistent with what you should expect. Namely leftalt + 1 should have the same effect as A-1 but holding leftalt should behave as the meta key. In order to achieve this keyd sends meta down until you press 1 at which point it sends meta up alt down 1 down which is what you are seeing in the logs. The end result is that the display server sees A-1 which is what you have defined in the config file. You can ignore the noise in keyd -m unless you are getting unexpected behaviour.

I tested a 2nd time, and now suddenly it's grabbing a different keyboard:

keyd creates a virtual device. In the first log it looks like keyd is not running since you are seeing the raw device events, in the second it is running and modifying your keystrokes as above. It should start automatically if you have the systemd unit enabled.

@rvaiya
Copy link
Owner

rvaiya commented Nov 15, 2021

To clarify, [mylayer:M] creates a modifier layer called mylayer, M in this instance is not just another layer from which mylayer inherits, it instructs keyd to treat mylayer as a proper modifier for all non explicitly defined keys. This allows you to do things like create custom shift and control layers which stack properly and allows you to use keys which are bound to mylayer to behave as the modifiers when no other key is pressed (e.g when using them in combination with a mouse).

It is not just syntactic sugar for the following

leftmeta = mylayer

[meta]
a = M-a
b = M-b
...

[mylayer:meta]
1 = A-1
2 = A-2

which would not have the subtle but important properties mentioned above. For instance the above config would not handle leftcontrol+leftmeta+a properly (it would not produce C-M-a as expected). It also would not allow the user to meta click anything since pressing leftmeta alone would not send any keystrokes. Modifier layers account for both of these uses and behave as expected.

As far as I am aware this functionality is unique to keyd. It should be documented in the man page but it is possible that the section requires clarification.

@canadaduane
Copy link
Contributor Author

Hmmm, I see.

Unfortunately, the effect of "M-down" followed by "M-up" on my system is to trigger a system shortcut bar and overlay. I'll have to start over with this new information and see if I can tackle making my Linux machine behave in a more Mac OS-like way differently.

Thanks for your help!

@rvaiya
Copy link
Owner

rvaiya commented Nov 15, 2021

If you don't care about stacking behaviour and don't want your layer to do anything on key down you can explicitly define each key as above (a = M-a). It might be easier to just reassign your launcher key.

Alternatively, if you still want your launcher to be activated by tapping your meta key, you could do something like this:

leftmeta = overload(M, f13)
rightmeta = overload(M, f13)

leftalt = layer(mymeta)

[mymeta:M]

1 = A-1

and then reassign your launcher key to F13.

This hybrid approach has the additional advantage of preserving stacking semantics and allowing you to use meta by itself in programs which require it (by tapping alt) while also allowing you to tap the physical meta key to run your launcher.

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