How do you make volume keys and mute key work in Xmonad
Use 'xev' and tap the multimedia keys to discover their names. One might be 'XF86XK_AudioMute'. Then look at the contents of '/usr/include/X11/XF86keysym.h' and look for the name. On my system, 'XF86XK_AudioMute' is '0x1008FF12'.
Drop that where you would put a key in your config file. It might look like this:
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
-CUT-
} `additionalKeys`
[ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock"),
((0 , 0x1008FF11), spawn "amixer -q sset Master 2%-"),
((0 , 0x1008FF13), spawn "amixer -q sset Master 2%+"),
((0 , 0x1008FF12), spawn "amixer set Master toggle")
]
'amixer' will set your volume. The '0' replacing mod4Mask allows you to tap the multimedia key without holding your mod key.
See this Graphics.X11.ExtraTypes.XF86 for keys you want and add to your config file:
import Graphics.X11.ExtraTypes.XF86
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
[ ...
, ((0, xF86XK_AudioLowerVolume ), spawn "amixer set Master 2-")
, ((0, xF86XK_AudioRaiseVolume ), spawn "amixer set Master 2+")
, ((0, xF86XK_AudioMute ), spawn "amixer set Master toggle")
...]
If you're using pulseaudio, pactl
also should work.
, ((0 , xF86XK_AudioRaiseVolume), spawn "pactl set-sink-volume 0 +1.5%")
, ((0 , xF86XK_AudioLowerVolume), spawn "pactl set-sink-volume 0 -- -1.5%")
, ((0 , xF86XK_AudioMute), spawn "pactl set-sink-mute 0 toggle")
]
0
is sink id. pactl list short sinks
will show sink list.
pactl stat|grep 'Default Sink' | cut -f2 -d':'
will show current default sink. You can use sink name instead numeric id.
Doulble dash --
tells 'this is not option(like -h), just value' to pactl
.