diff options
author | Don Stewart <dons@cse.unsw.edu.au> | 2007-03-07 08:42:48 +0100 |
---|---|---|
committer | Don Stewart <dons@cse.unsw.edu.au> | 2007-03-07 08:42:48 +0100 |
commit | 91e917f6665da4562d8e01e816359d207f9d1771 (patch) | |
tree | 75d6c397750fdddb61a2e755a57930397f716afa | |
parent | c8e006cd49179b1a680028d1c3bd472ab5e73046 (diff) | |
download | xmonad-91e917f6665da4562d8e01e816359d207f9d1771.tar.gz xmonad-91e917f6665da4562d8e01e816359d207f9d1771.tar.xz xmonad-91e917f6665da4562d8e01e816359d207f9d1771.zip |
fmt. and use a Map for keycode lookup
darcs-hash:20070307074248-9c5c1-e7bd70d5c7822120cdfded97be4da59ca18d5218.gz
-rw-r--r-- | Main.hs | 65 | ||||
-rw-r--r-- | W.hs | 4 |
2 files changed, 30 insertions, 39 deletions
@@ -16,6 +16,8 @@ import Data.Bits hiding (rotate) import Data.List +import qualified Data.Map as M + import System.IO import System.Process (runCommand) import System.Exit @@ -30,16 +32,16 @@ import W -- -- The keys list -- -keys :: [(KeyMask, KeySym, W ())] -keys = - [ (mod1Mask .|. shiftMask, xK_Return, spawn "xterm") - , (mod1Mask, xK_p, spawn "exe=`dmenu_path | dmenu` && exec $exe") - , (controlMask, xK_space, spawn "gmrun") - , (mod1Mask, xK_Tab, focus 1) - , (mod1Mask, xK_j, focus 1) - , (mod1Mask, xK_k, focus (-1)) - , (mod1Mask .|. shiftMask, xK_c, kill) - , (mod1Mask .|. shiftMask, xK_q, io $ exitWith ExitSuccess) +keys :: M.Map (KeyMask, KeySym) (W ()) +keys = M.fromList + [ ((mod1Mask .|. shiftMask, xK_Return), spawn "xterm") + , ((mod1Mask, xK_p ), spawn "exe=`dmenu_path | dmenu` && exec $exe") + , ((controlMask, xK_space ), spawn "gmrun") + , ((mod1Mask, xK_Tab ), focus 1) + , ((mod1Mask, xK_j ), focus 1) + , ((mod1Mask, xK_k ), focus (-1)) + , (mod1Mask .|. shiftMask, xK_c ), kill) + , ((mod1Mask .|. shiftMask, xK_q ), io $ exitWith ExitSuccess) ] -- @@ -69,41 +71,28 @@ main = do e <- io $ allocaXEvent $ \ev -> nextEvent dpy ev >> getEvent ev handle e --- --- | grabkeys. Register key commands --- -registerKeys :: Display -> Window -> W () -registerKeys dpy root = - forM_ keys $ \(mod, sym, _) -> do - kc <- io (keysymToKeycode dpy sym) - io $ grabKey dpy kc mod root True grabModeAsync grabModeAsync + -- register keys + registerKeys dpy root = forM_ (M.keys keys) $ \(mod,sym) -> io $ do + kc <- keysymToKeycode dpy sym + grabKey dpy kc mod root True grabModeAsync grabModeAsync -- -- The event handler -- handle :: Event -> W () -handle (MapRequestEvent {window = w}) = manage w - -handle (DestroyWindowEvent {window = w}) = do - ws <- gets windows - when (elem w ws) (unmanage w) - -handle (UnmapEvent {window = w}) = do - ws <- gets windows - when (elem w ws) (unmanage w) +handle (MapRequestEvent {window = w}) = manage w +handle (DestroyWindowEvent {window = w}) = unmanage w +handle (UnmapEvent {window = w}) = unmanage w handle (KeyEvent {event_type = t, state = mod, keycode = code}) | t == keyPress = do dpy <- gets display sym <- io $ keycodeToKeysym dpy code 0 - case filter (\(mod', sym', _) -> mod == mod' && sym == sym') keys of - [] -> return () - ((_, _, act):_) -> act + M.lookup (mod,sym) keys handle e@(ConfigureRequestEvent {}) = do dpy <- gets display - io $ configureWindow dpy (window e) (value_mask e) $ - WindowChanges + io $ configureWindow dpy (window e) (value_mask e) $ WindowChanges { wcX = x e , wcY = y e , wcWidth = width e @@ -151,11 +140,13 @@ manage w = do -- | unmanage, a window no longer exists, remove it from the stack unmanage :: Window -> W () unmanage w = do - dpy <- gets display - io $ do grabServer dpy - sync dpy False - ungrabServer dpy - withWindows $ filter (/= w) + ws <- gets windows + when (w `elem` ws) $ do + dpy <- gets display + io $ do grabServer dpy + sync dpy False + ungrabServer dpy + withWindows $ filter (/= w) -- | focus. focus to window at offset 'n' in list. -- The currently focused window is always the head of the list @@ -16,9 +16,9 @@ module W where -import System.IO -import Graphics.X11.Xlib import Control.Monad.State +import System.IO +import Graphics.X11.Xlib (Display,Window) -- | WState, the window manager state. -- Just the display, width, height and a window list |