X.U.ClickableWorkspaces: Add integrations with X.L.IndependentScreens and X.A.WorkspaceNames

Having these work together isn't entirely trivial so let's provide the
integrations.

Related: https://github.com/xmonad/xmonad-contrib/pull/390
This commit is contained in:
Tomas Janousek 2021-02-03 00:41:15 +00:00
parent 5990456cc9
commit c6b4e69f39

View File

@ -18,12 +18,20 @@ module XMonad.Util.ClickableWorkspaces (
-- * Usage -- * Usage
-- $usage -- $usage
clickablePP, clickablePP,
clickableWrap clickableRenamedPP,
clickableWrap,
-- * Integrations
clickableWorkspaceNamesPP,
clickableMarshallPP,
clickableMarshallWorkspaceNamesPP
) where ) where
import XMonad import XMonad
import XMonad.Util.WorkspaceCompare (getWsIndex) import XMonad.Actions.WorkspaceNames
import XMonad.Hooks.DynamicLog (xmobarAction, xmobarRaw, PP(..)) import XMonad.Hooks.DynamicLog (xmobarAction, xmobarRaw, PP(..))
import XMonad.Layout.IndependentScreens
import XMonad.Util.WorkspaceCompare (getWsIndex)
-- $usage -- $usage
-- However you have set up your PP, apply @clickablePP@ to it, and bind the result -- However you have set up your PP, apply @clickablePP@ to it, and bind the result
@ -41,17 +49,24 @@ clickableWrap :: Int -> String -> String
clickableWrap i ws = xmobarAction ("xdotool set_desktop " ++ show i) "1" $ xmobarRaw ws clickableWrap i ws = xmobarAction ("xdotool set_desktop " ++ show i) "1" $ xmobarRaw ws
-- | Use index of workspace in users config to target workspace with @xdotool@ switch. -- | Use index of workspace in users config to target workspace with @xdotool@ switch.
getClickable :: X (WorkspaceId -> String) getClickable :: (WorkspaceId -> String) -> X (WorkspaceId -> String)
getClickable = do getClickable ren = do
wsIndex <- getWsIndex wsIndex <- getWsIndex
return $ \ws -> case wsIndex ws of return $ \ws -> case wsIndex ws of
Just idx -> clickableWrap idx ws Just idx -> clickableWrap idx (ren ws)
Nothing -> ws Nothing -> ws
-- | Apply clickable wrapping to all workspace fields in given PP. -- | Apply clickable wrapping to all workspace fields in given PP.
clickablePP :: PP -> X PP clickablePP :: PP -> X PP
clickablePP pp = do clickablePP = clickableRenamedPP id
clickable <- getClickable
-- | Alternative to 'clickablePP' that allows changing the visible workspace
-- name. Useful for integration with modules that change workspace names, such
-- as "XMonad.Layout.IndependentScreens" and "XMonad.Actions.WorkspaceNames".
-- See "XMonad.Util.ClickableWorkspaces.Integrations".
clickableRenamedPP :: (WorkspaceId -> String) -> PP -> X PP
clickableRenamedPP ren pp = do
clickable <- getClickable ren
return $ return $
pp { ppCurrent = ppCurrent pp . clickable pp { ppCurrent = ppCurrent pp . clickable
, ppVisible = ppVisible pp . clickable , ppVisible = ppVisible pp . clickable
@ -59,3 +74,21 @@ clickablePP pp = do
, ppHiddenNoWindows = ppHiddenNoWindows pp . clickable , ppHiddenNoWindows = ppHiddenNoWindows pp . clickable
, ppUrgent = ppUrgent pp . clickable , ppUrgent = ppUrgent pp . clickable
} }
-- | Integration with "XMonad.Actions.WorkspaceNames".
clickableWorkspaceNamesPP :: PP -> X PP
clickableWorkspaceNamesPP pp = do
rename <- getWorkspaceNames
clickableRenamedPP rename pp
-- | Integration with "XMonad.Layout.IndependentScreens".
clickableMarshallPP :: ScreenId -> PP -> X PP
clickableMarshallPP s pp =
clickableRenamedPP unmarshallW pp{ ppSort = marshallSort s <$> ppSort pp }
-- | Integration with both "XMonad.Actions.WorkspaceNames" and
-- "XMonad.Layout.IndependentScreens".
clickableMarshallWorkspaceNamesPP :: ScreenId -> PP -> X PP
clickableMarshallWorkspaceNamesPP s pp = do
rename <- getWorkspaceNames
clickableRenamedPP (unmarshallW . rename) pp{ ppSort = marshallSort s <$> ppSort pp }