From d30806e1dce27418fcd6505addedd92b06ed114c Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Tue, 2 Feb 2021 21:37:42 +0000 Subject: [PATCH] X.H.EwmhDesktops: Split workspaceListTransform into two (fix wmctrl -s) Turns out that renaming workspaces in the transform is a bad idea in the `ewmhDesktopsEventHook'` as W.view is then unable to find the workspace. This was somewhat usable before we introduced the unified `ewmh'` config combinator as one would only rename in the transform passed to `ewmhDesktopsLogHookCustom`, but with the unified config, we actually need to separate renames from sorting/reordering, otherwise switching workspaces by pagers or wmctrl doesn't work. Related: https://github.com/xmonad/xmonad-contrib/pull/105 Related: https://github.com/xmonad/xmonad-contrib/pull/122 Related: f271d59c345e ("X.A.WorkspaceNames: Provide workspaceListTransform for EwmhDesktops") --- CHANGES.md | 4 ++-- XMonad/Actions/WorkspaceNames.hs | 12 ++++++------ XMonad/Hooks/EwmhDesktops.hs | 28 ++++++++++++++++------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b12e6eff40..eff196d19e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -329,8 +329,8 @@ * `XMonad.Actions.WorkspaceNames` - - Added `workspaceNamesListTransform` which makes workspace names visible - to external pagers. + - Added `workspaceNamesRenameWS` which makes workspace names visible + to external pagers and tools like `wmctrl` or `arbtt`. * `XMonad.Util.PureX` diff --git a/XMonad/Actions/WorkspaceNames.hs b/XMonad/Actions/WorkspaceNames.hs index 14356f2665..2482902ca8 100644 --- a/XMonad/Actions/WorkspaceNames.hs +++ b/XMonad/Actions/WorkspaceNames.hs @@ -40,7 +40,7 @@ module XMonad.Actions.WorkspaceNames ( workspaceNamePrompt, -- * EwmhDesktops integration - workspaceNamesListTransform + workspaceNamesRenameWS, ) where import XMonad @@ -190,12 +190,12 @@ workspaceNamePrompt conf job = do contains completions input = return $ filter (Data.List.isInfixOf input) completions --- | 'XMonad.Hooks.EwmhDesktops.workspaceListTransform' that exposes workspace +-- | 'XMonad.Hooks.EwmhDesktops.workspaceRename' that exposes workspace -- names to pagers and other EWMH-aware clients. -- -- Usage: --- > ewmh' def{ workspaceListTransform = workspaceNamesListTransform } -workspaceNamesListTransform :: X ([WindowSpace] -> [WindowSpace]) -workspaceNamesListTransform = do +-- > ewmh' def{ workspaceRename = workspaceNamesRenameWS } +workspaceNamesRenameWS :: X (WindowSpace -> WindowSpace) +workspaceNamesRenameWS = do names <- getWorkspaceNames - return $ map $ \ws -> ws{ W.tag = names $ W.tag ws } + return $ \ws -> ws{ W.tag = names $ W.tag ws } diff --git a/XMonad/Hooks/EwmhDesktops.hs b/XMonad/Hooks/EwmhDesktops.hs index 16d2ca027b..24301a898b 100644 --- a/XMonad/Hooks/EwmhDesktops.hs +++ b/XMonad/Hooks/EwmhDesktops.hs @@ -75,14 +75,16 @@ import XMonad.Util.WindowProperties (getProp32) -- | TODO data EwmhConfig = EwmhConfig - { workspaceListTransform :: X ([WindowSpace] -> [WindowSpace]) + { workspaceListSort :: X ([WindowSpace] -> [WindowSpace]) + , workspaceRename :: X (WindowSpace -> WindowSpace) , activateHook :: ManageHook , fullscreen :: Bool } instance Default EwmhConfig where def = EwmhConfig - { workspaceListTransform = pure id + { workspaceListSort = pure id + , workspaceRename = pure id , activateHook = doFocus , fullscreen = False } @@ -169,16 +171,18 @@ ewmhDesktopsLogHook = ewmhDesktopsLogHook' def -- user-specified function to transform the workspace list (post-sorting) {-# DEPRECATED ewmhDesktopsLogHookCustom "Use ewmhDesktopsLogHook' instead" #-} ewmhDesktopsLogHookCustom :: ([WindowSpace] -> [WindowSpace]) -> X () -ewmhDesktopsLogHookCustom f = ewmhDesktopsLogHook' def{ workspaceListTransform = pure f } +ewmhDesktopsLogHookCustom f = ewmhDesktopsLogHook' def{ workspaceListSort = pure f } -- | -- Notifies pagers and window lists, such as those in the gnome-panel -- of the current state of workspaces and windows. ewmhDesktopsLogHook' :: EwmhConfig -> X () -ewmhDesktopsLogHook' EwmhConfig{workspaceListTransform} = withWindowSet $ \s -> do +ewmhDesktopsLogHook' EwmhConfig{workspaceListSort, workspaceRename} = withWindowSet $ \s -> do sort' <- getSortByIndex - workspaceListTransform' <- workspaceListTransform - let ws = workspaceListTransform' $ sort' $ W.workspaces s + workspaceListSort' <- workspaceListSort + workspaceRename' <- workspaceRename + let wsTransform = map workspaceRename' . workspaceListSort' + let ws = wsTransform $ sort' $ W.workspaces s -- Set number of workspaces and names thereof let desktopNames = map W.tag ws @@ -190,8 +194,8 @@ ewmhDesktopsLogHook' EwmhConfig{workspaceListTransform} = withWindowSet $ \s -> let clientList = nub . concatMap (maybe [] (\(W.Stack x l r) -> reverse l ++ r ++ [x]) . W.stack) $ ws whenChanged (ClientList clientList) $ setClientList clientList - -- Remap the current workspace to handle any renames that f might be doing. - let maybeCurrent' = W.tag <$> listToMaybe (workspaceListTransform' [W.workspace $ W.current s]) + -- Remap the current workspace to handle any renames that wsTransform might be doing. + let maybeCurrent' = W.tag <$> listToMaybe (wsTransform [W.workspace $ W.current s]) current = join (flip elemIndex (map W.tag ws) <$> maybeCurrent') whenChanged (CurrentDesktop $ fromMaybe 0 current) $ mapM_ setCurrentDesktop current @@ -216,7 +220,7 @@ ewmhDesktopsEventHook = ewmhDesktopsEventHook' def -- user-specified function to transform the workspace list (post-sorting) {-# DEPRECATED ewmhDesktopsEventHookCustom "Use ewmhDesktopsEventHook' instead" #-} ewmhDesktopsEventHookCustom :: ([WindowSpace] -> [WindowSpace]) -> Event -> X All -ewmhDesktopsEventHookCustom f = ewmhDesktopsEventHook' def{ workspaceListTransform = pure f } +ewmhDesktopsEventHookCustom f = ewmhDesktopsEventHook' def{ workspaceListSort = pure f } -- | -- Intercepts messages from pagers and similar applications and reacts on them. @@ -234,12 +238,12 @@ ewmhDesktopsEventHookCustom f = ewmhDesktopsEventHook' def{ workspaceListTransfo -- handled by other modules like "XMonad.Hooks.ManageHelpers", -- "XMonad.Actions.Minimize", etc.) ewmhDesktopsEventHook' :: EwmhConfig -> Event -> X All -ewmhDesktopsEventHook' EwmhConfig{ workspaceListTransform, activateHook, fullscreen } +ewmhDesktopsEventHook' EwmhConfig{ workspaceListSort, activateHook, fullscreen } e@ClientMessageEvent{ev_window = w, ev_message_type = mt, ev_data = d} = withWindowSet $ \s -> do sort' <- getSortByIndex - workspaceListTransform' <- workspaceListTransform - let ws = workspaceListTransform' $ sort' $ W.workspaces s + workspaceListSort' <- workspaceListSort + let ws = workspaceListSort' $ sort' $ W.workspaces s a_cd <- getAtom "_NET_CURRENT_DESKTOP" a_d <- getAtom "_NET_WM_DESKTOP"