DEV Community

Asif Zubayer Palak
Asif Zubayer Palak

Posted on

How to set media key-binds for dwm in Arch Linux

After installing Arch Linux with suckless dwm window manager, some of the keys in your keyboard may stop working.

This requires the need to manually set up keybinds for your set up.

Required Installations

In order to get started, there are some packages that you need to install to set the keybinds.
The packages are xbindkeys and xbindkeys_config

The commands to install these two packages for Arch are:

if you don't have yay installed, run this first
sudo pacman -Sy yay

or you can also build them from AUR, but I suggest using yay

yay -S xbindkeys xbindkeys_config-gtk2
xbindkeys -d > ~/.xbindkeysrc
Enter fullscreen mode Exit fullscreen mode

This will create a file called .xbindkeysrc in your home directory which contains all your keybinds, but we will be using the GUI version instead.

If you want to not use the GUI version or if it is not working for you, check out the xbindkeys manual here

Setting Keybinds

  1. Open the application called xbindkeys_config either from dmenu or from the terminal
  2. You will be prompted with a window such as: Image description
  3. On the bottom bar, there are several options, select New which will open a panel to the left.
  4. There are several text boxes for each attribute. Name would contain the name of the keybind, Key will contain the keycode of the hardware keys and Action contains the command that will execute upon pressing the button.

Configs for Keybinds

Config for Volume Up:

  • First write Volume Up in the name and then select Get Key that will pop up a blank window.
  • Select the key combination for your keybind
  • Next, put this command into the Action box
pactl set-sink-volume @DEFAULT_SINK@ +1%
Enter fullscreen mode Exit fullscreen mode

You can change 1% to whatever value you want to increment the volume by.

  • Lastly hit Save

Config for Volume Down:

  • Same as Volume up except the Action command will be
pactl set-sink-volume @DEFAULT_SINK@ -1%
Enter fullscreen mode Exit fullscreen mode

Config for Mute:

  • To mute/unmute the Audio Output/Speaker/Headphone
pactl set-sink-mute @DEFAULT_SINK@ toggle
Enter fullscreen mode Exit fullscreen mode
  • To mute/unmute the Audio Input/Microphone
pactl set-source-mute @DEFAULT_SOURCE@ toggle
Enter fullscreen mode Exit fullscreen mode

Config for Media Playback:

To set keybinds for pause/play or next/previous, you need to install playerctl

Run the command yay -Sy playerctl in the terminal and you are good to go.

The Action Commands for Pause/Play:

playerctl play-pause
Enter fullscreen mode Exit fullscreen mode

The Action Commands for Previous Track:

playerctl previous
Enter fullscreen mode Exit fullscreen mode

The Action Commands for Next Track:

playerctl next
Enter fullscreen mode Exit fullscreen mode

Once Done, Hit Save and Exit and lastly, in order for your keybinds to remain permanent after each boot, you must configure your .xinitrc in the directory ~.xinitrc

Use a text editor of your choice and add the following line:

xbindkeys &
Enter fullscreen mode Exit fullscreen mode

before exec dwm

Top comments (0)