From ba0bf3d271175ce396fb8fadad23e6d62cb8b942 Mon Sep 17 00:00:00 2001 From: David Roundy Date: Tue, 7 Aug 2007 22:16:16 +0200 Subject: move event loop out of mouseDrag. darcs-hash:20070807201616-72aca-80f5d15118592f79aca8a2e928c4ad4f29fdf8b1 --- Main.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index efa7ab1..fc12bce 100644 --- a/Main.hs +++ b/Main.hs @@ -65,7 +65,8 @@ main = do { windowset = winset , layouts = M.fromList [(w, safeLayouts) | w <- [0 .. W workspaces - 1]] , mapped = S.empty - , waitingUnmap = M.empty } + , waitingUnmap = M.empty + , dragging = Nothing } xSetErrorHandler -- in C, I'm too lazy to write the binding: dons @@ -183,6 +184,22 @@ handle e@(MappingNotifyEvent {ev_window = w}) = do io $ refreshKeyboardMapping e when (ev_request e == mappingKeyboard) $ withDisplay $ io . flip grabKeys w +-- handle button release, which may finish dragging. +handle e@(ButtonEvent {ev_event_type = t}) + | t == buttonRelease = do + drag <- gets dragging + case drag of + Just (_,f) -> modify (\s -> s { dragging = Nothing }) >> f + -- we're done dragging and have released the mouse + Nothing -> broadcastMessage e + +-- handle motionNotify event, which may mean we are dragging. +handle e@(MotionEvent {ev_event_type = t, ev_x = x, ev_y = y}) = do + drag <- gets dragging + case drag of + Just (d,_) -> d (fromIntegral x) (fromIntegral y) -- we're dragging + Nothing -> broadcastMessage e + -- click on an unfocused window, makes it focused on this workspace handle e@(ButtonEvent {ev_window = w,ev_event_type = t,ev_button = b }) | t == buttonPress = do -- cgit v1.2.3