summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDon Stewart <dons@cse.unsw.edu.au>2007-03-12 02:40:29 +0100
committerDon Stewart <dons@cse.unsw.edu.au>2007-03-12 02:40:29 +0100
commitbbe54d90ad92ec76f05ca9ad5bc02d8959e47973 (patch)
tree493e37117326a29eb6d846a69eeec1bbad0fd551
parent30b2c029e2f363fbe476e078faf0afea784935ba (diff)
downloadmetatile-bbe54d90ad92ec76f05ca9ad5bc02d8959e47973.tar
metatile-bbe54d90ad92ec76f05ca9ad5bc02d8959e47973.zip
fiddling, comments
darcs-hash:20070312014029-9c5c1-413bd2cb8b19937ae6baeb2124bfd933a7f15111
-rw-r--r--Main.hs41
1 files changed, 27 insertions, 14 deletions
diff --git a/Main.hs b/Main.hs
index 8091714..c76c005 100644
--- a/Main.hs
+++ b/Main.hs
@@ -142,23 +142,31 @@ grabKeys dpy rootw = do
--
handle :: Event -> X ()
+-- run window manager command
+handle (KeyEvent {event_type = t, state = m, keycode = code})
+ | t == keyPress
+ = withDisplay $ \dpy -> do
+ s <- io $ keycodeToKeysym dpy code 0
+ whenJust (M.lookup (m,s) keys) id
+
+-- manage a new window
handle (MapRequestEvent {window = w}) = withDisplay $ \dpy -> do
- wa <- io $ getWindowAttributes dpy w
+ wa <- io $ getWindowAttributes dpy w -- ignore override windows
when (not (waOverrideRedirect wa)) $ manage w
-handle (DestroyWindowEvent {window = w}) = unmanage w
-handle (UnmapEvent {window = w}) = unmanage w
+-- window destroyed, unmanage it
+handle (DestroyWindowEvent {window = w}) = do b <- isClient w; when b $ unmanage w
+
+-- window gone, unmanage it
+handle (UnmapEvent {window = w}) = do b <- isClient w; when b $ unmanage w
+-- set keyboard mapping
handle e@(MappingNotifyEvent {window = w}) = do
let m = (request e, first_keycode e, count e)
io $ refreshKeyboardMapping m
when (request e == mappingKeyboard) $ withDisplay $ io . flip grabKeys w
-handle (KeyEvent {event_type = t, state = m, keycode = code})
- | t == keyPress = withDisplay $ \dpy -> do
- s <- io $ keycodeToKeysym dpy code 0
- whenJust (M.lookup (m,s) keys) id
-
+-- entered a normal window
handle e@(CrossingEvent {window = w, event_type = t})
| t == enterNotify && mode e == notifyNormal && detail e /= notifyInferior
= do ws <- gets workspace
@@ -167,11 +175,13 @@ handle e@(CrossingEvent {window = w, event_type = t})
else do b <- isRoot w
when b setTopFocus
+-- left a window, check if we need to focus root
handle e@(CrossingEvent {event_type = t})
| t == leaveNotify
= do rootw <- gets theRoot
when (window e == rootw && not (same_screen e)) $ setFocus rootw
+-- configure a window
handle e@(ConfigureRequestEvent {window = w}) = do
dpy <- gets display
ws <- gets workspace
@@ -244,12 +254,11 @@ manage w = do
-- list, on whatever workspace it is.
unmanage :: Window -> X ()
unmanage w = do
- ws <- gets workspace
- when (W.member w ws) $ do
- modify $ \s -> s { workspace = W.delete w (workspace s) }
- withServerX $ do
- setTopFocus
- withDisplay $ \d -> io (sync d False) -- TODO, everything operates on the current display, so wrap it up.
+ modify $ \s -> s { workspace = W.delete w (workspace s) }
+ withServerX $ do
+ setTopFocus
+ withDisplay $ \d -> io (sync d False)
+ -- TODO, everything operates on the current display, so wrap it up.
-- | Grab the X server (lock it) from the X monad
withServerX :: X () -> X ()
@@ -312,3 +321,7 @@ view o = do
windows $ W.view n
where n = o-1
+
+-- | True if window is under management by us
+isClient :: Window -> X Bool
+isClient w = liftM (W.member w) (gets workspace)