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

input/keyboard: fix bindsym --to-code failing on duplicates #8323

Closed
wants to merge 0 commits into from

Conversation

sahinf
Copy link
Contributor

@sahinf sahinf commented Sep 1, 2024

If a keysymbol maps to more than one keycode, we should choose the first keycode instead of refusing the binding. It is more likely that duplicates are coming from nonstandard keys such as the 'Internet' keys.

After these changes, I can bindsym --to-code Print as expected.

libxkbcommon API maps both keycodes 107 and 218 to the Keysym 0xff61 = 65377.
The only way to map between keysym to keycode or vice versa seems to be to loop
through all keycodes exposed by xkb_keymap_key_for_each and it starts looping from the lowest keycode.

Some more investigation here

To test, bind a nonstandard key to some visual changes eg:

# bindsym --to-code Print exec notify-send --expire-time=1000 "$(brightnessctl -m set 5%+)"
# bindsym --to-code Print+a exec notify-send --expire-time=1000 "$(brightnessctl -m set 5%-)"

Fixes #8267, #8298, maybe #8275

@emersion
Copy link
Member

emersion commented Sep 2, 2024

Well, the issue is that there is no way to tell whether the first one is the "good" one, or whether it's a different one. Maybe you want the first one but someone else will get confused because it expects the second one.

@sahinf
Copy link
Contributor Author

sahinf commented Sep 2, 2024

no way to tell whether the first one is the "good" one

As far as my limited perspective regarding Internet keys, then yes there is a way to tell: Most people don't have internet keys. This fixes current Sway user issues without really taking away any feature or introducing new branch logic. It used to reject both keycodes, but now it would choose the first.

Unless this is a libxkbcommon bug, I would argue that my compositor should absolutely make assumptions like choosing a real print key rather than being unable to map print key altogether, just because there was a duplicate entry or whatever with a key that literally doesn't exist.

@sahinf
Copy link
Contributor Author

sahinf commented Sep 5, 2024

@emersion Any other ideas to get bindsym --to-code to work as expected?

@kennylevinsen
Copy link
Member

As far as my limited perspective regarding Internet keys, then yes there is a way to tell: Most people don't have internet keys.

Sway does not know what "internet keys" are, and the key people want is not guaranteed to be the first in the keymap, so this doesn't really seem like a solution - just a hack that works in this case.

Maybe we should just change the semantic to bind to all the matched keycodes. That might be more in line with what a user expects. If they want a specific one, they should be explicit with bindcode.

@sahinf
Copy link
Contributor Author

sahinf commented Sep 6, 2024

I assumed that we were rejecting duplicates for a reason but I can't find any reasoning in commit a09c144

I agree that would be more intuitive.

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

Successfully merging this pull request may close these issues.

Bindsym --to-code not working with non-modifier keys.
3 participants