From dd905d2603329e09f77242a2e7e55875042b160a Mon Sep 17 00:00:00 2001 From: Wilson Sales Date: Thu, 8 Nov 2018 18:46:56 -0200 Subject: [PATCH] X.A.DynamicWorkspaceOrder: add transformation-aware withNthWorkspace The user may modify the list of workspace tags that results form applying the dynamic order. This way one may filter workspaces they don't want in the order (e.g. "NSP") or apply any transformation he wishes to the list of tags. --- CHANGES.md | 5 +++++ XMonad/Actions/DynamicWorkspaceOrder.hs | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index da4751b7ee..2eb777f163 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -49,6 +49,11 @@ * `XMonad.Actions.MessageHandling` Refresh-performing functions updated to better reflect the new `sendMessage`. + * `XMonad.Actions.DynamicProjects` + Add a version of `withNthWorkspace` that takes a `[WorkspaceId] -> + [WorkspaceId]` transformation to apply over the list of workspace tags + resulting from the dynamic order. + ## 0.14 ### Breaking Changes diff --git a/XMonad/Actions/DynamicWorkspaceOrder.hs b/XMonad/Actions/DynamicWorkspaceOrder.hs index ccb8fef6b3..f1755cca04 100644 --- a/XMonad/Actions/DynamicWorkspaceOrder.hs +++ b/XMonad/Actions/DynamicWorkspaceOrder.hs @@ -30,6 +30,7 @@ module XMonad.Actions.DynamicWorkspaceOrder , moveToGreedy , shiftTo + , withNthWorkspace' , withNthWorkspace ) where @@ -183,13 +184,19 @@ moveToGreedy dir t = doTo dir t getSortByOrder (windows . W.greedyView) shiftTo :: Direction1D -> WSType -> X () shiftTo dir t = doTo dir t getSortByOrder (windows . W.shift) --- | Do something with the nth workspace in the dynamic order. The --- callback is given the workspace's tag as well as the 'WindowSet' --- of the workspace itself. -withNthWorkspace :: (String -> WindowSet -> WindowSet) -> Int -> X () -withNthWorkspace job wnum = do +-- | Do something with the nth workspace in the dynamic order after +-- transforming it. The callback is given the workspace's tag as well +-- as the 'WindowSet' of the workspace itself. +withNthWorkspace' :: ([WorkspaceId] -> [WorkspaceId]) -> (String -> WindowSet -> WindowSet) -> Int -> X () +withNthWorkspace' tr job wnum = do sort <- getSortByOrder - ws <- gets (map W.tag . sort . W.workspaces . windowset) + ws <- gets (tr . map W.tag . sort . W.workspaces . windowset) case drop wnum ws of (w:_) -> windows $ job w [] -> return () + +-- | Do something with the nth workspace in the dynamic order. The +-- callback is given the workspace's tag as well as the 'WindowSet' +-- of the workspace itself. +withNthWorkspace :: (String -> WindowSet -> WindowSet) -> Int -> X () +withNthWorkspace = withNthWorkspace' id