Skip to content

Commit

Permalink
X.H.EwmhDesktops: Clean up "handle"
Browse files Browse the repository at this point in the history
Whitespace and refactoring before other changes.
  • Loading branch information
liskin committed Nov 5, 2020
1 parent 9fc9151 commit d7bb99e
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions XMonad/Hooks/EwmhDesktops.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE MultiWayIf #-}

-----------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -203,6 +204,8 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
-- * _NET_WM_DESKTOP (move windows to other desktops)
--
-- * _NET_ACTIVE_WINDOW (activate another window, changing workspace if needed)
--
-- * _NET_CLOSE_WINDOW (close window)
ewmhDesktopsEventHook :: Event -> X All
ewmhDesktopsEventHook = ewmhDesktopsEventHookCustom id

Expand Down Expand Up @@ -247,41 +250,36 @@ activateLogHook mh = XS.get >>= maybe (return ()) go . netActivated
windows (appEndo f)

handle :: ([WindowSpace] -> [WindowSpace]) -> Event -> X ()
handle f (ClientMessageEvent {
ev_window = w,
ev_message_type = mt,
ev_data = d
}) = withWindowSet $ \s -> do
sort' <- getSortByIndex
let ws = f $ sort' $ W.workspaces s

a_cd <- getAtom "_NET_CURRENT_DESKTOP"
a_d <- getAtom "_NET_WM_DESKTOP"
a_aw <- getAtom "_NET_ACTIVE_WINDOW"
a_cw <- getAtom "_NET_CLOSE_WINDOW"
a_ignore <- mapM getAtom ["XMONAD_TIMER"]
if mt == a_cd then do
let n = head d
if 0 <= n && fi n < length ws then
windows $ W.view (W.tag (ws !! fi n))
else trace $ "Bad _NET_CURRENT_DESKTOP with data[0]="++show n
else if mt == a_d then do
let n = head d
if 0 <= n && fi n < length ws then
windows $ W.shiftWin (W.tag (ws !! fi n)) w
else trace $ "Bad _NET_DESKTOP with data[0]="++show n
else if mt == a_aw then do
lh <- asks (logHook . config)
XS.put (NetActivated (Just w))
lh
else if mt == a_cw then
killWindow w
else if mt `elem` a_ignore then
return ()
else
-- The Message is unknown to us, but that is ok, not all are meant
-- to be handled by the window manager
return ()
handle f (ClientMessageEvent {ev_window = w, ev_message_type = mt, ev_data = d}) =
withWindowSet $ \s -> do
sort' <- getSortByIndex
let ws = f $ sort' $ W.workspaces s

a_cd <- getAtom "_NET_CURRENT_DESKTOP"
a_d <- getAtom "_NET_WM_DESKTOP"
a_aw <- getAtom "_NET_ACTIVE_WINDOW"
a_cw <- getAtom "_NET_CLOSE_WINDOW"

if | mt == a_cd ->
case d of
(n:_) | 0 <= n && fi n < length ws -> windows $ W.view (W.tag (ws !! fi n))
| otherwise -> trace $ "Bad _NET_CURRENT_DESKTOP with data[0]="++show n
_ -> trace $ "Bad _NET_CURRENT_DESKTOP with data="++show d
| mt == a_d ->
case d of
(n:_) | 0 <= n && fi n < length ws -> windows $ W.shiftWin (W.tag (ws !! fi n)) w
| otherwise -> trace $ "Bad _NET_DESKTOP with data[0]="++show n
_ -> trace $ "Bad _NET_DESKTOP with data="++show d
| mt == a_aw -> do
lh <- asks (logHook . config)
XS.put (NetActivated (Just w))
lh
| mt == a_cw ->
killWindow w
| otherwise ->
-- The Message is unknown to us, but that is ok, not all are meant
-- to be handled by the window manager
return ()
handle _ _ = return ()

-- | Add EWMH fullscreen functionality to the given config.
Expand Down

0 comments on commit d7bb99e

Please sign in to comment.