Xmonad: clickable workspaces with azerty layout

Xmonad is a keyboard oriented desktop manager. But sometimes, you still want to do some mouse actions.

Dzen2 provides clickable areas that allows to bind a command to a mouse click on a specific area of a Dzen bar. If you use Dzen2 as your status bar, it is then only a question of mapping the right keystroke to the workspace name and it should work.

The standard configuration to do this is already well documented:

myWorkspaces            = clickable $ ["1","2","3","4","5","6","7","8","9"]
  where clickable l     = [ "^ca(1,xdotool key alt+" ++ show (n) ++ ")" ++ ws ++ "^ca()" |
                            (i,ws) <- zip [1..] l,
                            let n = i ]

However I am using an azerty keyboard layout. I am then using a slightly different keyboard layout to switch workspaces. Typing “alt+1”, “alt+2” and so on to switch workspace will then not have any effect for my configuration.

An additional caveat is xdotool which does not honor default keymap unless you explicitly set it beforehand with setxkbmap.

All this taken into account, here is the resulting config snippet that works:

myWorkspaces    = clickable $ ["web","2","3","4","5","6","irc","8","9"]
    where clickable l = [ "^ca(1,setxkbmap fr;xdotool key super+ampersand)web^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+eacute)2^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+quotedbl)3^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+apostrophe)4^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+parenleft)5^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+minus)6^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+egrave)irc^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+underscore)8^ca()",
                          "^ca(1,setxkbmap fr;xdotool key super+ccedilla)9^ca()"

Note that some of my workspaces are named with plain text instead of number. I am also using the super key instead of alt as my Xmonad mod key.

If you are more Haskell fluent than I am, do not hesitate to suggest some factorization.