[xmonad] Learning how to do proper keybindings (and a little bit about xmobar)

Thomas Løcke thomas.granvej6 at gmail.com
Mon Feb 6 09:02:34 CET 2012


Hey all,

The other day I got my new Thinkpad T420 laptop, and I decided that it was
time to put some pressure on my 40 year old brain. I've used KDE on
Slackware for what feels like an eternity, so I feel comfortable and at
home with KDE. This is both good and bad. Good because I know my way around
KDE, bad because over the years I've sorta become a bit of a mouse-junkie
(Ack!).

So naturally I had to find something completely different: Enter xmonad.

I've been fascinated with Haskell for a while now, but never really managed
to get started with it. I'm guessing xmonad would be as good a place to
start as any.

Its been a rocky start for me, I must admit. The whole functional paradigm
is both mesmerizing and scary. My first real stumble block has been how to
do proper keybindings in xmonad.sh, specifically to be able to adjust the
volume using the T420 volume buttons.

This is what I've currently got:

----------
import XMonad
import XMonad.Actions.CycleWS
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.EZConfig
import XMonad.Util.Run(spawnPipe)
import System.IO

myLogHook dest = dynamicLogWithPP defaultPP { ppOutput = hPutStrLn dest
                                            ,ppVisible = wrap "(" ")"
    }

myKeys = [ ("M-b", sendMessage ToggleStruts )
         , ("M-<Right>", nextWS)
         , ("M-<Left>", prevWS)
         , ("M-p", spawn "gmrun")
         , ("M-r", spawn "xmonad --restart")
         , ("M-g", spawn "google-chrome")
         , ("M-f", spawn "firefox")
         , ("M-s", spawn "sudo /usr/sbin/pm-suspend")
         , ("C-M-h", spawn "sudo /usr/sbin/pm-hibernate")
         , ("C-M-r", spawn "sudo /sbin/shutdown -r now")
         , ("C-M-s", spawn "sudo /sbin/shutdown -h now")
         ]

-- This is where it all goes haywire! I found these online, but with no
direction on how
-- to add them to myKeys.
-- volKeys = \c -> mkKeymap c $
--       [ ("<XF86AudioRaiseVolume>", spawn "amixer -c 0 set Master 1+
unmute")
--       , ("<XF86AudioLowerVolume>", spawn "amixer -c 0 set Master 1-")
--       ]

main = do
    xmproc <- spawnPipe "/usr/bin/xmobar /home/thomas/.xmobarrc"
    xmonad $ defaultConfig
        { manageHook = manageDocks <+> manageHook defaultConfig
        , layoutHook = avoidStruts  $  layoutHook defaultConfig
, terminal = "urxvt"
, focusFollowsMouse = False
        , logHook = myLogHook xmproc
        , modMask = mod4Mask     -- Rebind Mod to the Windows key
        }
`additionalKeysP` myKeys
----------

The commented block below myKeys is where everything falls apart for me. I
cannot for the life of me figure out how to add those two keys to myKeys.
Any and all advice is more than welcome!

Oh, and one final question: I've chosen xmobar as my status bar and so far
I'm loving the slimness completely, but I've noticed that most people seem
to be using dzen - is dzen considered the "better" choice? I just want
something simple that tells me what workspace I'm on, has a small tray for
wicd and some basic cpu/mem/battery info. xmobar does all these things
(with a minor glitch in the battery department, but that's for another
post), but I'd rather not bet on something that isn't being broadly used by
the xmonad community. So, is it OK for me to stick with xmobar?

:o)
Thomas Løcke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/xmonad/attachments/20120206/4154b45f/attachment.htm>


More information about the xmonad mailing list