You are not logged in.

#1 2020-12-19 17:16:33

mdsp
Member
Registered: 2020-12-19
Posts: 9

Need help to map volume keys on xmonad

Hello! I used to I3, however I wanted something more different and something that would push me with new knowledge, so I moved to xmonad even if my Haskell's skills weren't so awesome...

I tried to build my config by hand, seeing other people config for example.

However I'm struggling to map the volume keys to spawn certain commands...

The relevant part of my xmonad.hs is:

import Graphics.X11.ExtraTypes.XF86 (xF86XK_AudioLowerVolume, xF86XK_AudioRaiseVolume, xF86XK_AudioMute)

[...]

, ((0, xF86XK_AudioLowerVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
, ((0, xF86XK_AudioRaiseVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
, ((0, xF86XK_AudioMute), spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")

Which raises these errors:

xmonad.hs:189:12: error:
    • Couldn't match expected type ‘[Char]’
                  with actual type ‘(a0, KeySym)’
    • In the expression: (0, xF86XK_AudioLowerVolume)
      In the expression:
        ((0, xF86XK_AudioLowerVolume),
         spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
      In the expression:
        [("M-C-r", spawn "xmonad --recompile"),
         ("M-S-r", spawn "xmonad --restart"), ("M-S-q", io exitSuccess),
         ("M-q", kill1), ....]
    |
189 |         , ((0, xF86XK_AudioLowerVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

xmonad.hs:190:12: error:
    • Couldn't match expected type ‘[Char]’
                  with actual type ‘(a1, KeySym)’
    • In the expression: (0, xF86XK_AudioRaiseVolume)
      In the expression:
        ((0, xF86XK_AudioRaiseVolume),
         spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
      In the expression:
        [("M-C-r", spawn "xmonad --recompile"),
         ("M-S-r", spawn "xmonad --restart"), ("M-S-q", io exitSuccess),
         ("M-q", kill1), ....]
    |
190 |         , ((0, xF86XK_AudioRaiseVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

xmonad.hs:191:12: error:
    • Couldn't match expected type ‘[Char]’
                  with actual type ‘(a2, KeySym)’
    • In the expression: (0, xF86XK_AudioMute)
      In the expression:
        ((0, xF86XK_AudioMute),
         spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")
      In the expression:
        [("M-C-r", spawn "xmonad --recompile"),
         ("M-S-r", spawn "xmonad --restart"), ("M-S-q", io exitSuccess),
         ("M-q", kill1), ....]
    |
191 |         , ((0, xF86XK_AudioMute), spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")
    |            ^^^^^^^^^^^^^^^^^^^^^

Please check the file for errors.

Ok, it's saying that was expectiing a string, and received a KeySym... So how I was supposed to use these keys?

Offline

#2 2020-12-19 18:32:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,510
Website

Re: Need help to map volume keys on xmonad

Yes, it does expect a string but received a LIST.  You are using the mouse-bind format for key bindings.

, (xF86XK_AudioLowerVolume, spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
, (xF86XK_AudioRaiseVolume, spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
, (xF86XK_AudioMute, spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")

I'm assuming these important keysym variables are actually string variables - but I don't use xmonad.  The error is clear though as is the difference between these three attempted bindings and all other key bindings.

EDIT: from looking up a few other examples, it seems your format may be required, but it needs to be in a different section.  Please post your full config file so we can see the context.

EDIT 2: Ah, I see it's the Util.EZConfig you are apparently using that has a different key binding syntax than the "standard".  You cannot mix and match (at least not within the same list).  I believe EZConfig has two sections "additionalKeys" and "additionalKeysP" which have different syntax.  Your original lines should be in the former, but appear to be in the latter.

If you are using EZConfig with Emacs style bindings, the following should work:

, ("<XF86AudioLowerVolume>", spawn "pactl set-sing-volume @DEFAULT_SINK@ -10%")

But this really depends on exactly which tools you are using.  Be sure to follow the documentation for the config tools you use.

Last edited by Trilby (2020-12-19 18:45:33)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2020-12-31 18:59:59

mdsp
Member
Registered: 2020-12-19
Posts: 9

Re: Need help to map volume keys on xmonad

Trilby wrote:

Yes, it does expect a string but received a LIST.  You are using the mouse-bind format for key bindings.

, (xF86XK_AudioLowerVolume, spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
, (xF86XK_AudioRaiseVolume, spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
, (xF86XK_AudioMute, spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")

I'm assuming these important keysym variables are actually string variables - but I don't use xmonad.  The error is clear though as is the difference between these three attempted bindings and all other key bindings.

EDIT: from looking up a few other examples, it seems your format may be required, but it needs to be in a different section.  Please post your full config file so we can see the context.

EDIT 2: Ah, I see it's the Util.EZConfig you are apparently using that has a different key binding syntax than the "standard".  You cannot mix and match (at least not within the same list).  I believe EZConfig has two sections "additionalKeys" and "additionalKeysP" which have different syntax.  Your original lines should be in the former, but appear to be in the latter.

If you are using EZConfig with Emacs style bindings, the following should work:

, ("<XF86AudioLowerVolume>", spawn "pactl set-sing-volume @DEFAULT_SINK@ -10%")

But this really depends on exactly which tools you are using.  Be sure to follow the documentation for the config tools you use.

Yeah! I'm using Emacs style, but this do not work as expected... I also changed to safeSpawn, but no difference:

        , ("<XF86AudioLowerVolume>", safeSpawn "pactl" ["set-sink-volume @DEFAULT_SINK@ -10%"])
        , ("<XF86AudioRaiseVolume>", safeSpawn "pactl" ["set-sink-volume @DEFAULT_SINK@ +10%"])
        , ("<XF86AudioMute>", safeSpawn "pactl" ["set-sink-mute @DEFAULT_SINK@ toggle"])

On my notebook keyboard, the raise and lower volume keys is accesible via the Fn key. Does this interfer?

Offline

#4 2020-12-31 20:07:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,510
Website

Re: Need help to map volume keys on xmonad

Again:

Trilby wrote:

Please post your full config file so we can see the context.

And with the new format do you get any error message, or is it just not adjusting the volume?

mdsp wrote:

the raise and lower volume keys is accesible via the Fn key. Does this interfer?

That depends what you mean - assuming you are using the proper format for that section of your config, then a kepress that emits the XF86* keysyms will adjust your volume.  If you need to use a Fn key combination to emit that keysym, then it will, of course, only work when you use the Fn key combination.  Check the output of xev if you need to in order to see what keysym that key press actually emits.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB