{ ^_^ } sinustrom Scribo, ergo sum!

Sound Blaster USB sound card volume control under Wayland

2023-05-19
Author: Zoltan Puskas
Tags:
License: CC-BY-NC-SA

A few years ago I finally had the time to actually configure my Sound Blaster X-Fi Surround 5.1 sound card with LIRC so that both the volume control knob and the remote controller function under Linux. Recently 0x0000ff has reached out notifying me that the guide does not completely work for people using the Wayland display server in place of X.Org, as sending keyboard signals works a bit differently there. Fortunately they were also kind enough to provide the list of changes needed as well as the relevant configuration files. With their permission this post will serve as an addendum to the previous guide, but only documenting the differences needed to make it compatible with Wayland.

Setup

They’ve made the Sound Blaster X-Fi Surround 5.1 sound card work with the setup below:

  • KDE Neon (Ubuntu LTS based Linux distribution)
  • systemd: 249.11-0ubuntu3.7
  • KDE Plasma: 5.27.2
  • KDE Frameworks: 5.103.0
  • Wayland: 1.21.0
  • ydotool: latest version from master GitHub branch

I’ve tested it on my Gentoo laptop with the following setup:

  • Linux kernel: 6.3.1
  • systemd: 253.4
  • udev: 217-r5
  • KDE Plasma: 5.27.4
  • KDE Frameworks: 5.105.0
  • ydotool: 1.0.4
  • xorg-server: 21.1.8

Installing packages

Instead of xdotool we will be using different program, ydotool, which works with Wayland, X.Org, and more. You can simply install it by:

# emerge ydotool

On some distributions (e.g. Debian based systems) the ydotool package is rather old and has issues, so it might be worth installing it manually from source.

Configuration

UDEV

If the /dev/uinput has incorrect permissions, a new udev rule is needed to make sure it has RW permissions for all users. For that let’s create /etc/udev/rules.d/10-uinput.rules with the following content:

KERNEL=="uinput", MODE="0666"

Then make the rule is live:

# udevadm control --reload-rules

Finally let’s trigger it manually, as it will not trigger automatically until the next boot, since the kernel has already loaded the uinput module:

# udevadm trigger --name-match=uinput

After that the device should have correct permissions:

$ ll /dev/uinput
crw-rw-rw- 1 root root 10, 223 May 19 21:35 /dev/uinput

Starting the service

First enable the ydotoold service for your user and then start it:

$ systemctl --user enable ydotool
$ systemctl --user start ydotool

An OpenRC unit is also available if not using systemd.

User action configuration

In the ~/.config/lircrc file instead of xdotool use ydotool, e.g.:

begin
   remote = RM-850
   prog = irexec
   config = /usr/bin/ydotool key 114:1 114:0
   button = KEY_VOLUMEDOWN
   repeat = 1
end

begin
   remote = RM-850
   prog = irexec
   config = /usr/bin/ydotool key 115:1 115:0
   button = KEY_VOLUMEUP
   repeat = 1
end

begin
   remote = RM-850
   prog = irexec
   config = /usr/bin/ydotool key 113:1 113:0
   button = KEY_MUTE
end

Note that ydotool has a different syntax, as it’s using actual key codes!

At this point everything should be working.

ydotool does not connect

If for whatever reason ydotool fails to connect to ydotoold them the YDOTOOL_SOCKET environment variable has to be set explicitly to point to the socket’s location. Normally this should not be needed unless if you are launching ydotoold in a non-standard way, e.g. via KDE Plasma’s autostart, and you have set a custom socket location.

Use ~/.profile or KDE session environment variables in this case to make the environment variable available for the entire session:

export YDOTOOL_SOCKET="<your/custom/socket/path>"

Content