summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2007-10-05 05:41:02 +0200
committerSpencer Janssen <sjanssen@cse.unl.edu>2007-10-05 05:41:02 +0200
commitf708ef2d9dcaeccdd6916373cf12eb73a72195d3 (patch)
treebff32a0badad0962d7cb3956d9e7c83243070681
parentfef4121478dee22f87f010dff820b3f5aa195c44 (diff)
downloadmetatile-f708ef2d9dcaeccdd6916373cf12eb73a72195d3.tar
metatile-f708ef2d9dcaeccdd6916373cf12eb73a72195d3.zip
Move grabButtons/Keys into X
darcs-hash:20071005034102-a5988-fb2b9080382d62b3486ba53d019b5baf7e7f4b01
-rw-r--r--Main.hs35
1 files changed, 18 insertions, 17 deletions
diff --git a/Main.hs b/Main.hs
index a149d34..9eff7f2 100644
--- a/Main.hs
+++ b/Main.hs
@@ -81,14 +81,15 @@ main = do
sync dpy False
selectInput dpy rootw $ substructureRedirectMask .|. substructureNotifyMask
.|. enterWindowMask .|. leaveWindowMask .|. structureNotifyMask
- grabKeys dpy rootw
- grabButtons dpy rootw
-
- sync dpy False
allocaXEvent $ \e ->
runX cf st $ do
+ grabKeys
+ grabButtons
+
+ io $ sync dpy False
+
-- bootstrap the windowset, Operations.windows will identify all
-- the windows in winset as new and set initial properties for
-- those windows
@@ -126,23 +127,25 @@ scan dpy rootw = do
&& (wa_map_state wa == waIsViewable || ic)
-- | Grab the keys back
-grabKeys :: Display -> Window -> IO ()
-grabKeys dpy rootw = do
- ungrabKey dpy anyKey anyModifier rootw
+grabKeys :: X ()
+grabKeys = do
+ XConf { display = dpy, theRoot = rootw } <- ask
+ let grab kc m = io $ grabKey dpy kc m rootw True grabModeAsync grabModeAsync
+ io $ ungrabKey dpy anyKey anyModifier rootw
forM_ (M.keys keys) $ \(mask,sym) -> do
- kc <- keysymToKeycode dpy sym
+ kc <- io $ keysymToKeycode dpy sym
-- "If the specified KeySym is not defined for any KeyCode,
-- XKeysymToKeycode() returns zero."
when (kc /= '\0') $ mapM_ (grab kc . (mask .|.)) extraModifiers
- where grab kc m = grabKey dpy kc m rootw True grabModeAsync grabModeAsync
-grabButtons :: Display -> Window -> IO ()
-grabButtons dpy rootw = do
- ungrabButton dpy anyButton anyModifier rootw
+grabButtons :: X ()
+grabButtons = do
+ XConf { display = dpy, theRoot = rootw } <- ask
+ let grab button mask = io $ grabButton dpy button mask rootw False buttonPressMask
+ grabModeAsync grabModeSync none none
+ io $ ungrabButton dpy anyButton anyModifier rootw
mapM_ (\(m,b) -> mapM_ (grab b . (m .|.)) extraModifiers) (M.keys mouseBindings)
- where grab button mask = grabButton dpy button mask rootw False buttonPressMask
- grabModeAsync grabModeSync none none
-- ---------------------------------------------------------------------
-- | Event handler. Map X events onto calls into Operations.hs, which
@@ -185,9 +188,7 @@ handle (UnmapEvent {ev_window = w, ev_send_event = synthetic}) = whenX (isClient
-- set keyboard mapping
handle e@(MappingNotifyEvent {}) = do
io $ refreshKeyboardMapping e
- when (ev_request e == mappingKeyboard) $ withDisplay $ \dpy -> do
- rootw <- asks theRoot
- io $ grabKeys dpy rootw
+ when (ev_request e == mappingKeyboard) grabKeys
-- handle button release, which may finish dragging.
handle e@(ButtonEvent {ev_event_type = t})