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

keycodes_from_xmodmap returns one-to-one mapping instead of one-to-many #316

Open
nkruglikov opened this issue Oct 19, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@nkruglikov
Copy link

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 a spawn("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 from keycodes_from_xmodmap and using that to convert key names like XF86AudioPlay to key codes like 172.
  • keycodes_from_xmodmap executes xmodmap -pke. This command dumps keycode mappings in lines of the following format:
    ...
    keycode  52 = z Z Cyrillic_ya Cyrillic_YA
    ...
    
    The above line would be turned into the following pairs:
    ...
    (z, 52)
    (Z, 52)
    (Cyrillic_ya, 52)
    (Cyrillic_YA, 52)
    ...
    
    Then this pairs are collected into a HashMap.
  • On my system, xmodmap -pke | grep -i xf86audioplay outputs the following:
    keycode 172 = XF86AudioPlay XF86AudioPause XF86AudioPlay XF86AudioPause
    keycode 208 = XF86AudioPlay NoSymbol XF86AudioPlay
    keycode 215 = XF86AudioPlay NoSymbol XF86AudioPlay
    
    This means that keycodes_from_xmodmap would first turn it into the following pairs:
    (XF86AudioPlay, 172)
    ...
    (XF86AudioPlay, 208)
    ...
    (XF86AudioPlay, 215)
    ...
    
    and then, during collect, just into a mapping
    XF86AudioPlay => 215
    
  • With xev 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 returns Result<HashMap<String, Vec<u8>>> instead of Result<HashMap<String, u8>> and then adapting parse_bindings_with_xmodmap / parse_binding functions. I am not sure how popular is this problem, though, and whether changing the signature of keycodes_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:

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     us,ru
options:    grp:caps_toggle
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+us+ru:2+inet(evdev)+group(caps_toggle)
geometry:   pc(pc105)
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us+ru:2+inet(evdev)+group(caps_toggle)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

It is a fairly standard configuration with English / Russian layout switch on CapsLock.

My keyboard is Logitech G Pro:

Picture of the keyboard

image

@nkruglikov nkruglikov added the bug Something isn't working label Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant