i3: How to use media keys that show up on separate input device?

1

I've installed the i3 window manager alongside GNOME desktop on Ubuntu-GNOME 16.04. I'm having trouble getting my media keys working with a Logitech G610 keyboard.

I have the following in my ~/.config/i3/config file:

bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle

and have confirmed that those commands work in the terminal. The issue I'm seeing is that the XF86AudioRaiseVolume etc keypress events are not registering.

If I use xev -event keyboard to try see the keycodes, when I press the multimedia keys all I get is the following:

MappingNotify event, serial 30, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeymapNotify event, serial 31, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

and no keycode is reported like for other keys. However, using sudo showkey -k, I get the following which are the expected values:

keycode 113 press
keycode 113 release
keycode 115 press
keycode 115 release
keycode 114 press
keycode 114 release

Running xinput, I see the following

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Logitech MX Master                        id=12   [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS DualPoint TouchPad          id=15   [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS DualPoint Stick             id=16   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Logitech Gaming Keyboard G610             id=10   [slave  keyboard (3)]
    ↳ Logitech Gaming Keyboard G610             id=11   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=13   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=14   [slave  keyboard (3)]
    ↳ DELL Wireless hotkeys                     id=17   [slave  keyboard (3)]

where the Logitech keyboard shows up as two devices. Running xinput list-props 10 and xinput list-props 11 I see that the first listing maps to /dev/input/event8, while the second maps to /dev/input/event9.

If I run xinput test 10 I see that the first listing for my keyboard responds to all the normal keyboard keys but not the media keys, while xinput test 11 responds only to the media keys:

key press   121 
key release 121 
key press   123 
key release 123 
key press   122 
key release 122

(These are off by 8 from the showkey output, but apparently that's expected. Also, these values match the mapping output by xmodmap -pke, i.e. keycode 121 = XF86AudioMute NoSymbol XF86AudioMute). Running sudo evtest /dev/input/event8 and sudo evtest /dev/input/event9 produce similar results.

So, my understanding of the process between keypress and handling is pretty fuzzy, but it seems that maybe the fact that the normal keys and media keys are on different input devices is preventing the media keypress events from getting through to the X session (as evidenced by not showing up for xev?) and therefore not getting through to i3? This works fine for the GNOME desktop, so is there something I need to configure to get them working for i3? I'm at a loss for how to proceed from here, any help would be greatly appreciated.

EDIT

I originally had quotes around the commands in my ~/.config/i3/config file, but that doesn't work. I've edited above to make it correct, but that wasn't the root of the problem.

dpkoch

Posted 2018-09-17T18:39:47.603

Reputation: 21

Answers

1

Based on the info provided in the previous answer, I ran ps and noticed that gnome-session was running even though I'd not logged into GNOME desktop since boot and had only logged into i3. My suspicion was that the gnome session was stealing the events, but unmapping those keyboard shortcuts in the gnome settings didn't seem to change anything.

My solution was to boot directly into a tty session following the instructions here, so that gnome-session doesn't start. I created the file ~/.xinitrc containing the single line exec i3, then after bootup I log in to the tty terminal and run startx to launch i3. With this method gnome is not running, and my media keys now work.

dpkoch

Posted 2018-09-17T18:39:47.603

Reputation: 21

Update: Starting i3 with just exec i3 in my ~/.xinitrc file was causing some issues with dbus that caused things like my terminal taking 6 seconds to open. For anyone who might be following this method, changing the contents of ~/.xinitrc to exec dbus-launch --exit-with-session i3 seems to have fixed that – dpkoch – 2018-10-05T17:19:09.670

0

Partial answer:

That the keyboard showing up as two devices is not a problem. Both devices are assigned to the Virtual Core Keyboard, so both devices should produce proper key core events.

The MappingNotify event may be an indication that some application is reacting to the media keys. In particular, if you get FocusOut and FocusIn events you didn't show us, then some other application is acting on those for sure.

Now this may be the i3 window manager with your configured keys, or it may be something else. So first thing to test is to remove or comment out your i3 bindings, test again, and see if you still get the Mapping/Focus events.

If yes, the next step is to figure out which application is stealing it. Use ps, xlsclients etc. to narrow it down. One way is to kill/disable applications until they got no longer stolen.

dirkt

Posted 2018-09-17T18:39:47.603

Reputation: 11 627

Good information, thank you. I wasn't able to find much out with xlsclients, since it seemed to just list the active applications in my current i3 session. However, using ps I did notice that gnome-shell was still running, I've provided an answer explaining how I dealt with that

– dpkoch – 2018-09-25T22:49:06.590