summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Janssen <spencerjanssen@gmail.com>2008-10-07 22:39:53 +0200
committerSpencer Janssen <spencerjanssen@gmail.com>2008-10-07 22:39:53 +0200
commitf2015e3a8da76ad819ce3968f057ab10974ec656 (patch)
treebba19c0b2ae7f53926386d6ec68cb679bd05b417
parent27c8f42e9fc273d70a3e3be6c08e8a601787de7e (diff)
downloadmetatile-f2015e3a8da76ad819ce3968f057ab10974ec656.tar
metatile-f2015e3a8da76ad819ce3968f057ab10974ec656.zip
Track mouse position via events received
darcs-hash:20081007203953-25a6b-820e60a7db931a5e5e27ab8736643aea932ca3ec
-rw-r--r--XMonad/Core.hs3
-rw-r--r--XMonad/Main.hsc16
2 files changed, 16 insertions, 3 deletions
diff --git a/XMonad/Core.hs b/XMonad/Core.hs
index 1bc289a..a6ee797 100644
--- a/XMonad/Core.hs
+++ b/XMonad/Core.hs
@@ -70,6 +70,9 @@ data XConf = XConf
, buttonActions :: !(M.Map (KeyMask, Button) (Window -> X ()))
-- ^ a mapping of button presses to actions
, mouseFocused :: !Bool -- ^ was refocus caused by mouse action?
+ , mousePosition :: !(Maybe (Position, Position))
+ -- ^ position of the mouse according to
+ -- the event currently being processed
}
-- todo, better name
diff --git a/XMonad/Main.hsc b/XMonad/Main.hsc
index 430e60c..945c5ea 100644
--- a/XMonad/Main.hsc
+++ b/XMonad/Main.hsc
@@ -99,7 +99,8 @@ xmonad initxmc = do
, focusedBorder = fbc
, keyActions = keys xmc xmc
, buttonActions = mouseBindings xmc xmc
- , mouseFocused = False }
+ , mouseFocused = False
+ , mousePosition = Nothing }
st = XState
{ windowset = initialWinset
, mapped = S.empty
@@ -136,10 +137,19 @@ xmonad initxmc = do
userCode $ startupHook initxmc
-- main loop, for all you HOF/recursion fans out there.
- forever_ $ handle =<< io (nextEvent dpy e >> getEvent e)
+ forever_ $ prehandle =<< io (nextEvent dpy e >> getEvent e)
return ()
- where forever_ a = a >> forever_ a
+ where
+ forever_ a = a >> forever_ a
+
+ -- if the event gives us the position of the pointer, set mousePosition
+ prehandle e = let mouse = do guard (ev_event_type e `elem` evs)
+ return (fromIntegral (ev_x_root e)
+ ,fromIntegral (ev_y_root e))
+ in local (\c -> c { mousePosition = mouse }) (handle e)
+ evs = [ keyPress, keyRelease, enterNotify, leaveNotify
+ , buttonPress, buttonRelease]
-- ---------------------------------------------------------------------