mirror of
https://github.com/xmonad/xmonad.git
synced 2025-07-31 20:21:52 -07:00
abstract out setfocus code a bit
This commit is contained in:
61
Main.hs
61
Main.hs
@@ -157,33 +157,24 @@ handle e@(MappingNotifyEvent {window = w}) = do
|
|||||||
handle (KeyEvent {event_type = t, state = m, keycode = code})
|
handle (KeyEvent {event_type = t, state = m, keycode = code})
|
||||||
| t == keyPress = withDisplay $ \dpy -> do
|
| t == keyPress = withDisplay $ \dpy -> do
|
||||||
s <- io $ keycodeToKeysym dpy code 0
|
s <- io $ keycodeToKeysym dpy code 0
|
||||||
maybe (return ()) id (M.lookup (m,s) keys)
|
whenJust (M.lookup (m,s) keys) id
|
||||||
|
|
||||||
handle e@(CrossingEvent {event_type = t})
|
handle e@(CrossingEvent {window = w, event_type = t})
|
||||||
| t == enterNotify && mode e == notifyNormal && detail e /= notifyInferior
|
| t == enterNotify && mode e == notifyNormal && detail e /= notifyInferior
|
||||||
= withDisplay $ \d -> do
|
= do ws <- gets workspace
|
||||||
let w = window e
|
if W.member w ws
|
||||||
ws <- gets workspace
|
then setFocus w
|
||||||
if W.member w ws
|
else do b <- isRoot w
|
||||||
then io $ setInputFocus d w revertToPointerRoot 0 -- it is ours, manage it
|
when b setTopFocus
|
||||||
else do rootw <- gets theRoot
|
|
||||||
when (w == rootw) $ do
|
|
||||||
let new_w = maybe rootw id (W.peek ws) -- focus to the top of the stack
|
|
||||||
io $ setInputFocus d new_w revertToPointerRoot 0
|
|
||||||
io $ sync d False
|
|
||||||
|
|
||||||
handle e@(CrossingEvent {event_type = t})
|
handle e@(CrossingEvent {event_type = t})
|
||||||
| t == leaveNotify
|
| t == leaveNotify
|
||||||
= withDisplay $ \d -> do
|
= do rootw <- gets theRoot
|
||||||
let dflt = defaultScreen d
|
when (window e == rootw && not (same_screen e)) $ setFocus rootw
|
||||||
rootw <- io $ rootWindow d dflt
|
|
||||||
when (window e == rootw && not (same_screen e)) $
|
|
||||||
io $ setInputFocus d rootw revertToPointerRoot 0
|
|
||||||
|
|
||||||
handle e@(ConfigureRequestEvent {}) = do
|
handle e@(ConfigureRequestEvent {window = w}) = do
|
||||||
dpy <- gets display
|
dpy <- gets display
|
||||||
ws <- gets workspace
|
ws <- gets workspace
|
||||||
let w = window e
|
|
||||||
|
|
||||||
when (W.member w ws) $ -- already managed, reconfigure (see client:configure()
|
when (W.member w ws) $ -- already managed, reconfigure (see client:configure()
|
||||||
trace ("Reconfigure already managed window: " ++ show w)
|
trace ("Reconfigure already managed window: " ++ show w)
|
||||||
@@ -246,7 +237,7 @@ manage w = do
|
|||||||
withDisplay $ \d -> io $ do
|
withDisplay $ \d -> io $ do
|
||||||
selectInput d w $ structureNotifyMask .|. enterWindowMask .|. propertyChangeMask
|
selectInput d w $ structureNotifyMask .|. enterWindowMask .|. propertyChangeMask
|
||||||
mapWindow d w
|
mapWindow d w
|
||||||
setInputFocus d w revertToPointerRoot 0 -- CurrentTime
|
setFocus w
|
||||||
windows $ W.push w
|
windows $ W.push w
|
||||||
|
|
||||||
-- | unmanage. A window no longer exists, remove it from the window
|
-- | unmanage. A window no longer exists, remove it from the window
|
||||||
@@ -254,18 +245,28 @@ manage w = do
|
|||||||
unmanage :: Window -> X ()
|
unmanage :: Window -> X ()
|
||||||
unmanage w = do
|
unmanage w = do
|
||||||
ws <- gets workspace
|
ws <- gets workspace
|
||||||
when (W.member w ws) $ withDisplay $ \d -> withServerX d $ do
|
when (W.member w ws) $ do
|
||||||
-- xseterrorhandler(dummy)
|
|
||||||
modify $ \s -> s { workspace = W.delete w (workspace s) }
|
modify $ \s -> s { workspace = W.delete w (workspace s) }
|
||||||
new_ws <- gets workspace
|
withDisplay $ \d ->
|
||||||
case W.peek new_ws of
|
withServerX d $ do
|
||||||
Just new -> io $ setInputFocus d new revertToPointerRoot 0
|
setTopFocus
|
||||||
Nothing -> do
|
io (sync d False)
|
||||||
rootw <- gets theRoot
|
|
||||||
io $ setInputFocus d rootw revertToPointerRoot 0
|
|
||||||
|
|
||||||
io (sync d False)
|
-- | Explicitly set the keyboard focus to the given window
|
||||||
-- xseterrorhandler(error)
|
setFocus :: Window -> X ()
|
||||||
|
setFocus w = withDisplay $ \d -> io $ setInputFocus d w revertToPointerRoot 0
|
||||||
|
|
||||||
|
-- | Set the focus to the window on top of the stack, or root
|
||||||
|
setTopFocus :: X ()
|
||||||
|
setTopFocus = do
|
||||||
|
ws <- gets workspace
|
||||||
|
case W.peek ws of
|
||||||
|
Just new -> setFocus new
|
||||||
|
Nothing -> gets theRoot >>= setFocus
|
||||||
|
|
||||||
|
-- | True if the given window is the root window
|
||||||
|
isRoot :: Window -> X Bool
|
||||||
|
isRoot w = liftM (w==) (gets theRoot)
|
||||||
|
|
||||||
-- | Grab the X server (lock it) from the X monad
|
-- | Grab the X server (lock it) from the X monad
|
||||||
withServerX :: Display -> X () -> X ()
|
withServerX :: Display -> X () -> X ()
|
||||||
|
Reference in New Issue
Block a user