-
Notifications
You must be signed in to change notification settings - Fork 88
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
keycodes_from_xmodmap
returns one-to-one mapping instead of one-to-many
#316
Comments
This has been mentioned previously I think? Strictly speaking it would be a breaking change to alter the return type of the function parsing keycodes and I'm not 100% confident that doing so in a way that didn't require changes in user code would be guaranteed to not alter existing use of the library. Having an alternative parse function that set up the keymap is probably the safe thing to add instead? |
I think this is the closest issue: #228 Implementing a separate parsing function seems a nice thing to do in order to ensure backwards compatibility. I can try implementing it, would it be okay? |
If you're up for it then go for it! If you can get something working and tested then I'll take a look and have a think about how to write the docs to explain the need / difference between the two implementations. |
Re: two implementations. What do you thing about the following solution: add deprecation warning to the old option, and use the new option in the examples? As far as I can see, there is no benefits in the old option apart from backwards compatibility, and it also has footguns like the one I encountered. |
Sounds good 👍 My only concern is that the odd behaviour of the current implementation is required for someone's current set up. Unlikely but I want to be careful nonetheless |
I tried to implement it and quickly realized a problem with the idea of using one-to-many mapping. As I said earlier, I use two layouts: English (US) and Russian. The problem is, they have common symbols assigned to different keys. For example,
So, under the old system, if I use However, under the new system, the situation would also be bad! Because Right now, I am a bit unsure how to implement a correct solution. For me (and my bi-layout-al peers) the expected flow is to assign bindings in terms of QWERTY and expect them to be the same (physically) even when layout is switched. But how to correctly extract "the primary" layout from xmodmap, I am not sure. Even worse, Arch Linux Wiki states that:
Right now I am trying to educate myself on these systems and proper ways to use them. |
Ah...this is the sort of thing I was worried about 😅 There is always the escape hatch of best-effort parsing the keybindings with xmodmap and then explicitly inserting additional keys into the map to account for the ones that aren't handled correctly. But that's obviously not ideal if it can be avoided. |
Background
I want to define a key mapping to control Spotify via DBus. For that, I want to link
XF86AudioPlay
key (Fn+F9 on my keyboard) with aspawn("dbus-send ...")
. However, it didn't work: the key press did nothing.The issue
Digging into the code, I discovered the following.
parse_keybindings_with_xmodmap
works by getting a mapping from String to u8 fromkeycodes_from_xmodmap
and using that to convert key names likeXF86AudioPlay
to key codes like172
.keycodes_from_xmodmap
executesxmodmap -pke
. This command dumps keycode mappings in lines of the following format:collect
ed into aHashMap
.xmodmap -pke | grep -i xf86audioplay
outputs the following:keycodes_from_xmodmap
would first turn it into the following pairs:collect
, just into a mappingxev
utility, I confirmed that pressing "Play" button of my keyboard emits keycode 172. Thus, it doesn't get captured by Penrose.Possible fix
Possible fix would modify the logic of
keycodes_from_xmodmap
so that it returnsResult<HashMap<String, Vec<u8>>>
instead ofResult<HashMap<String, u8>>
and then adaptingparse_bindings_with_xmodmap
/parse_binding
functions. I am not sure how popular is this problem, though, and whether changing the signature ofkeycodes_from_xmodmap
worth it. In any case, I am open to implementing it.System details
I run Penrose on Arch Linux with
startx
.setxkbmap -print -verbose 10
returns this:It is a fairly standard configuration with English / Russian layout switch on CapsLock.
My keyboard is Logitech G Pro:
Picture of the keyboard
The text was updated successfully, but these errors were encountered: