Search code examples
xmonad

Can't set brigtness and media control keys on Xmonad


I managed to set up my XMonad config from the ground up by myself - but I am having difficulties setting the brightness and media control keys - and I have no experience in programming or Haskell for that matter, and thus I don't know how to read the error messages (my fault, sorry). When reverting to the state before the changes relating to my problems, I have no compilation erorrs.

So I tried copiying from other people's dotfiles but I always got compilation errors. Here I am copying Derrek Taylor's XMonad config, specifically the part relating to the problem. So I copied :

 -- Multimedia Keys
    , ("<XF86AudioPlay>", spawn (myTerminal ++ "mocp --play"))
    , ("<XF86AudioPrev>", spawn (myTerminal ++ "mocp --previous"))
    , ("<XF86AudioNext>", spawn (myTerminal ++ "mocp --next"))
    , ("<XF86AudioMute>",   spawn "amixer set Master toggle")
    , ("<XF86AudioLowerVolume>", spawn "amixer set Master 5%- unmute")
    , ("<XF86AudioRaiseVolume>", spawn "amixer set Master 5%+ unmute")
    , ("<XF86HomePage>", spawn "firefox")
    , ("<XF86Search>", safeSpawn "firefox" ["https://www.duckduckgo.com/"])
    , ("<XF86Mail>", runOrRaise "thunderbird" (resource =? "thunderbird"))
    , ("<XF86Calculator>", runOrRaise "qalculate-gtk" (resource =? "qalculate-gtk"))
    , ("<XF86Eject>", spawn "toggleeject")
    , ("<Print>", spawn "scrotd 0")
    ]

From his dotfiles which are at this link.

I am getting the following error upon compilation (Apologies for not pasting the text itself as no keyboard combination I tried worked ) :

The error message

As far as imports go, I have the following :

import XMonad
 11 import Data.Monoid
 12 import System.Exit
 13 import XMonad.Util.SpawnOnce
 14 import XMonad.Util.Run
 15 import XMonad.Hooks.ManageDocks
 16 import qualified XMonad.StackSet as W
 17 import qualified Data.Map        as M
 18 import XMonad.Hooks.DynamicLog
 19 import XMonad.Hooks.ManageHelpers
 20 import XMonad.Hooks.UrgencyHook
 21 import XMonad.Util.WorkspaceCompare
 22 import XMonad.Util.EZConfig
 23 import Graphics.X11.ExtraTypes
 24 import XMonad.Hooks.EwmhDesktops
 

Can you please help me ? The bightness and Media Control keys , and later the battery widget on XMobar (will put on another post if I don't figure it out myself) are the last things I need to do before my laptop is 100% percent ready. I really enjoyed the journey so far and I laerned a lot, so would be happy if you not only help me solve the issue but explain it to a noob like me.

Thanks in advance !


Solution

  • OK so it seems I accidentally fixed my own problem, but in the most unusual way :

    1. I went over to this site because I was searching on how to control the brightness. Literally just went to Duck Duck Go and put "how to conrtol brightness XMonad" or whatever. Installed Lux, the program to do it. For some reason after trying XBrightness it didn't register my screen or some other error message was found which is irrelevant for this discussion so I just stuck with Lux.

    2. However while the general syntax seemed good, I've now noticed that DT's config which I gave the link to above had a different name for the XF keys. Well I just discovered while writing this was that the reason I had problems was the EZ keymap configuration - DT was using it and seems I wasn't. This realization however was much after doing step 3.

    3.I took at Luke Smith's DWM fork which I used for a while before switching to XMonad. Turns out the keymap names are different and I tried them instead. Then noticed that the X in XF86AudioLowerVolume for instance was capitalized while in something like , ((0, xF86XK_MonBrightnessUp), spawn "lux -a 10%") from step 1 it wasn't. Since at this point Lux worked I just played the game of making sure the syntax was the same for both cases. Eventually I also figured out that Luke's dwm fork held the exact names for the keys including the lowercase so I just stuck with copiying the syntax and changing the appropriate keybindings. A few XMonad compile error messages later it got everything working !

    Now my Controls look as follows :

     , ((0, xF86XK_MonBrightnessUp), spawn "lux -a 10%")
     , ((0, xF86XK_MonBrightnessDown), spawn "lux -s 10%")
     , ((0, xF86XK_AudioMute), spawn "amixer set Master toggle")
     , ((0, xF86XK_AudioLowerVolume), spawn "amixer set Master 5%- unmute")
     , ((0, xF86XK_AudioRaiseVolume), spawn "amixer set Master 5%+ unmute")
    

    Instead of making me hate window managers, I am now intrigued. Guess I should learn some basic programming :)

    Hope this was usefull to anyone else having issues with XMonad.

    Cheers !