From fa82db1130258d83014ab6769a5297552c53242b Mon Sep 17 00:00:00 2001 From: Evgeny Kurnevsky Date: Tue, 29 Jun 2021 21:59:09 +0300 Subject: [PATCH] Change EWMH windows ordering to be closer to the spec. --- CHANGES.md | 4 ++++ XMonad/Hooks/EwmhDesktops.hs | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2212c012..9dacf86c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -47,6 +47,10 @@ activation behavior and then add resulting `ManageHook` using `activateLogHook` to your `logHook`. Also, module `X.H.Focus` provides additional combinators. + + - Ordering of windows that are set to `_NET_CLIENT_LIST` and `_NET_CLIENT_LIST_STACKING` + was changed to be closer to the spec. From now these two lists will have + differently sorted windows. * All modules still exporting a `defaultFoo` constructor diff --git a/XMonad/Hooks/EwmhDesktops.hs b/XMonad/Hooks/EwmhDesktops.hs index 69123303..c6cfd5a2 100644 --- a/XMonad/Hooks/EwmhDesktops.hs +++ b/XMonad/Hooks/EwmhDesktops.hs @@ -123,6 +123,14 @@ newtype ClientList = ClientList [Window] instance ExtensionClass ClientList where initialValue = ClientList [none] +-- | +-- Cached stacking client list (e.g. @_NET_CLIENT_LIST_STACKING@). +newtype ClientListStacking = ClientListStacking [Window] + deriving Eq + +instance ExtensionClass ClientListStacking where + initialValue = ClientListStacking [none] + -- | -- Cached current desktop (e.g. @_NET_CURRENT_DESKTOP@). newtype CurrentDesktop = CurrentDesktop Int @@ -171,10 +179,17 @@ ewmhDesktopsLogHookCustom t = withWindowSet $ \s -> do setNumberOfDesktops (length desktopNames) setDesktopNames desktopNames - -- Set client list; all windows, with focused windows last - let clientList = nub . concatMap (maybe [] (\(W.Stack x l r) -> reverse l ++ r ++ [x]) . W.stack) $ ws + -- Set client list which should be sorted by window age. We just + -- guess that StackSet contains windows list in this order which + -- isn't true but at least gives consistency with windows cycling + let clientList = nub . concatMap (W.integrate' . W.stack) $ ws whenChanged (ClientList clientList) $ setClientList clientList + -- Set stacking client list which should have bottom-to-top + -- stacking order, i.e. focused window should be last + let clientListStacking = nub . concatMap (maybe [] (\(W.Stack x l r) -> reverse l ++ r ++ [x]) . W.stack) $ ws + whenChanged (ClientListStacking clientListStacking) $ setClientListStacking clientListStacking + -- Remap the current workspace to handle any renames that f might be doing. let maybeCurrent' = W.tag <$> listToMaybe (t [W.workspace $ W.current s]) current = flip elemIndex (map W.tag ws) =<< maybeCurrent' @@ -354,12 +369,15 @@ setDesktopNames names = withDisplay $ \dpy -> do setClientList :: [Window] -> X () setClientList wins = withDisplay $ \dpy -> do - -- (What order do we really need? Something about age and stacking) r <- asks theRoot a <- getAtom "_NET_CLIENT_LIST" io $ changeProperty32 dpy r a wINDOW propModeReplace (fmap fromIntegral wins) - a' <- getAtom "_NET_CLIENT_LIST_STACKING" - io $ changeProperty32 dpy r a' wINDOW propModeReplace (fmap fromIntegral wins) + +setClientListStacking :: [Window] -> X () +setClientListStacking wins = withDisplay $ \dpy -> do + r <- asks theRoot + a <- getAtom "_NET_CLIENT_LIST_STACKING" + io $ changeProperty32 dpy r a wINDOW propModeReplace (fmap fromIntegral wins) setWindowDesktop :: (Integral a) => Window -> a -> X () setWindowDesktop win i = withDisplay $ \dpy -> do