Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmonad - switching workspaces with mouse buttons 6 and 7

Tags:

haskell

xmonad

I would like to be able to move to the previous and next workspaces using the buttons 6 and 7 (the rocker buttons either side of the wheel) on my mouse. I'm guessing it has something to do with additionalMouseBindings, and if that followed the same pattern as additionalKeys I'd be golden. Alas, it is not, and I don't fully understand how to define a new binding. The naive:

`additionalMouseBindings`
[ -- get the middle button to switch views
  ((0, button6), spawn "xdotool key super+Down")
, ((0, button7), spawn "xdotool key super+Up")
]

isn't working, for reasons that will be obvious to somebody who knows Haskell and xmonad.

TIA for any suggestions.

like image 835
Tony Martin Avatar asked Nov 20 '14 09:11

Tony Martin


1 Answers

By "doesn't work" I suppose you mean it doesn't compile.

After @chi comment, I checked the buttons : button6 and 7 are not defined, so that is a first problem. But according to this post the extra buttons work if you just give their number.

It looks like you are using the additionalMouseBindings function from the XMonad.Util.EZConfig module. Its type is :

additionalMouseBindings :: XConfig a -> [((ButtonMask, Button), Window -> X ())] -> XConfig a

You are surrounding it in backticks which turns it into an operator. You aren't showing the first operand here, of type XConfig a, so you could have a first error here. You should have something of the form :

 yourPreviousConfig `additionalMouseBindings` listOfBindings 

That expression is equal to your new XConfig.

You can see that the list of bindings for the mouse buttons is not the same type as for the keys. The elements of the list are of type ((ButtonMask, Button), Window -> X ()) : buttons are associated to a function that takes a Window and returns X() (whereas keys are associated to expressions of type X()). XMonad will call the function you specify here with the clicked window as argument. You don't care about the window in your case. spawn "xdotool key super+Down" is of type X (), you can turn that into a function that takes a Window (or anything) by making a lambda function :

((0, 6), \w -> spawn "xdotool key super+Down")

Or you can use const to get a constant function that always return spawn "xdotool key super+Down" :

((0, 6), const $ spawn "xdotool key super+Down")

Finally, it seems really overkill to call xdotool to switch workspaces. Perhaps you are already using some of the functions of the module here in your key bindings ? You can use them in your mouse bindings too. nextWS and prevWS are of type X(), so you need make constant functions with them, like above.

like image 80
Leiaz Avatar answered Sep 30 '22 18:09

Leiaz