diff options
-rw-r--r-- | Main.hs | 6 | ||||
-rw-r--r-- | StackSet.hs | 19 |
2 files changed, 21 insertions, 4 deletions
@@ -51,9 +51,9 @@ main = do args <- getArgs let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new (SomeLayout $ LayoutSelection safeLayouts) - workspaces $ zipWith SD xinesc gaps + , [(x, "")] <- reads s = W.ensureTags defaultLayout workspaces x + | otherwise = new defaultLayout workspaces $ zipWith SD xinesc gaps + defaultLayout = SomeLayout $ LayoutSelection safeLayouts gaps = take (length xinesc) $ defaultGaps ++ repeat (0,0,0,0) safeLayouts = if null defaultLayouts then [SomeLayout Full] else defaultLayouts diff --git a/StackSet.hs b/StackSet.hs index b1b156a..c0f9dee 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -24,7 +24,7 @@ module StackSet ( -- $stackOperations peek, index, integrate, integrate', differentiate, focusUp, focusDown, focusMaster, - focusWindow, tagMember, member, findIndex, + focusWindow, tagMember, renameTag, ensureTags, member, findIndex, -- * Modifying the stackset -- $modifyStackset insertUp, delete, delete', filter, @@ -39,6 +39,7 @@ module StackSet ( import Prelude hiding (filter) import Data.Maybe (listToMaybe,fromJust) import qualified Data.List as L (deleteBy,find,splitAt,filter) +import Data.List ( (\\) ) import qualified Data.Map as M (Map,insert,delete,empty) -- $intro @@ -400,6 +401,22 @@ workspaces s = workspace (current s) : map workspace (visible s) ++ hidden s tagMember :: Eq i => i -> StackSet i l a s sd -> Bool tagMember t = elem t . map tag . workspaces +-- | Rename a given tag if present in the StackSet. +renameTag :: Eq i => i -> i -> StackSet i l a s sd -> StackSet i l a s sd +renameTag o n s = s { current = rs $ current s + , visible = map rs $ visible s + , hidden = map rw $ hidden s } + where rs scr = scr { workspace = rw $ workspace scr } + rw w = if tag w == o then w { tag = n } else w + +-- | Ensure that a given set of tags is present. +ensureTags :: Eq i => l -> [i] -> StackSet i l a s sd -> StackSet i l a s sd +ensureTags l allt st = et allt (map tag (workspaces st) \\ allt) st + where et [] _ s = s + et (i:is) rn s | i `tagMember` s = et is rn s + et (i:is) [] s = et is [] (s { hidden = Workspace i l Nothing : hidden s }) + et (i:is) (r:rs) s = et is rs $ renameTag r i s + -- | -- Finding if a window is in the stackset is a little tedious. We could -- keep a cache :: Map a i, but with more bookkeeping. |