mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-01 12:41:53 -07:00
Track mouse position via events received
This commit is contained in:
@@ -70,6 +70,9 @@ data XConf = XConf
|
|||||||
, buttonActions :: !(M.Map (KeyMask, Button) (Window -> X ()))
|
, buttonActions :: !(M.Map (KeyMask, Button) (Window -> X ()))
|
||||||
-- ^ a mapping of button presses to actions
|
-- ^ a mapping of button presses to actions
|
||||||
, mouseFocused :: !Bool -- ^ was refocus caused by mouse action?
|
, 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
|
-- todo, better name
|
||||||
|
@@ -99,7 +99,8 @@ xmonad initxmc = do
|
|||||||
, focusedBorder = fbc
|
, focusedBorder = fbc
|
||||||
, keyActions = keys xmc xmc
|
, keyActions = keys xmc xmc
|
||||||
, buttonActions = mouseBindings xmc xmc
|
, buttonActions = mouseBindings xmc xmc
|
||||||
, mouseFocused = False }
|
, mouseFocused = False
|
||||||
|
, mousePosition = Nothing }
|
||||||
st = XState
|
st = XState
|
||||||
{ windowset = initialWinset
|
{ windowset = initialWinset
|
||||||
, mapped = S.empty
|
, mapped = S.empty
|
||||||
@@ -136,10 +137,19 @@ xmonad initxmc = do
|
|||||||
userCode $ startupHook initxmc
|
userCode $ startupHook initxmc
|
||||||
|
|
||||||
-- main loop, for all you HOF/recursion fans out there.
|
-- 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 ()
|
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]
|
||||||
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user