Add mouse bindings so that mod+scroll-up goes to previous, mod+scroll-down goes to...
authorMatt Mullins <mokomull@gmail.com>
Tue, 27 Nov 2012 05:57:10 +0000 (21:57 -0800)
committerMatt Mullins <mokomull@gmail.com>
Tue, 27 Nov 2012 05:57:10 +0000 (21:57 -0800)
xmonad.hs

index cdd9cbe..ee6c832 100644 (file)
--- a/xmonad.hs
+++ b/xmonad.hs
@@ -5,6 +5,7 @@ import XMonad.Layout.Reflect
 import XMonad.Layout.NoBorders
 import XMonad.Prompt
 import XMonad.Prompt.Shell
+import XMonad.StackSet as SS
 import XMonad.Actions.NoBorders
 import Data.Bits ((.|.))
 import qualified Data.Map as M
@@ -16,6 +17,8 @@ defaults = defaultConfig {
            --, terminal = "rxvt-unicode +sb -bg black -fg white -fn 6x13"
            , terminal = "gnome-terminal"
            , keys = \x -> (M.fromList $ mykeys x) `M.union` dvorakify (keys defaultConfig x)
+           , mouseBindings = \x -> (M.fromList $ mymouseBindings x) `M.union`
+                                   (mouseBindings defaultConfig x)
            , layoutHook = smartBorders $ tiled ||| Mirror tiled ||| reflectHoriz tiled ||| Full
            , manageHook = myManageHook <+> manageHook defaultConfig
 } where
@@ -25,6 +28,10 @@ defaults = defaultConfig {
                    , ( (modMask x .|. mod1Mask , xK_2), spawn "xrandr --output TMDS-1 --off" )
                    , ( (modMask x .|. shiftMask, xK_semicolon), withFocused toggleBorder )
                    ]
+        mymouseBindings x = [
+                              ( (modMask x, button4), \win -> windows $ prevWorkspace x)
+                            , ( (modMask x, button5), \win -> windows $ nextWorkspace x)
+                            ]
         tiled = Tall nmaster delta ratio
         nmaster = 1
         ratio = 0.5
@@ -34,6 +41,36 @@ defaults = defaultConfig {
                         className =? "Xpdf" --> doFloat
                        ]
 
+-- swap to the next workspace in the set in the given XConfig
+nextWorkspace :: XConfig a -> WindowSet -> WindowSet
+nextWorkspace = changeWorkspace nextInList
+
+-- swap to the previous workspace in the set in the given XConfig
+prevWorkspace :: XConfig a -> WindowSet -> WindowSet
+prevWorkspace = changeWorkspace prevInList
+
+-- switches to the workspace given by a function taking the list of all workspace names,
+-- the current workspace name and returning a desired workspace name
+changeWorkspace :: ([String] -> String -> String) -> XConfig a -> WindowSet -> WindowSet
+changeWorkspace dir x currentState = let current_i = indexOf $ current currentState
+                                         next_i = dir (XMonad.workspaces x) current_i
+                                     in  greedyView next_i currentState
+
+indexOf :: SS.Screen i l a sid sd -> i
+indexOf screen = SS.tag $ SS.workspace $ screen
+
+-- finds the next element in the list after z, returning z if it is the end of the list
+nextInList :: Eq x => [x] -> x -> x
+nextInList (x:y:xs) z | z == x = y
+nextInList (x:xs)   z          = nextInList xs z
+nextInList []       z          = z
+
+-- finds the previous element in the list before z, returning z if it is the head of the list
+prevInList :: Eq x => [x] -> x -> x
+prevInList (x:y:xs) z | z == y = x
+prevInList (x:xs)   z          = prevInList xs z
+prevInList []       z          = z
+
 dk :: KeySym -> KeySym
 dk k         | k == xK_minus = xK_bracketleft
         | k == xK_underscore = xK_braceleft