From bd1fcd1ef0d014703303c156ab75b8921ef26d43 Mon Sep 17 00:00:00 2001 From: David Roundy Date: Tue, 24 Jul 2007 16:20:45 +0200 Subject: make delete work when window is in multiple workspaces. darcs-hash:20070724142045-72aca-2c5ac9fe613333f8333329fc63d420883891f782.gz --- StackSet.hs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'StackSet.hs') diff --git a/StackSet.hs b/StackSet.hs index 29b2a48..6097893 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -305,17 +305,13 @@ differentiate (x:xs) = Just $ Stack x [] xs -- | -- /O(n)/. 'filter p s' returns the elements of 's' such that 'p' evaluates to --- True. Order is preserved, and focus moves to the next node to the right (if --- necessary). --- --- Note, this isn't the same as the 'remove' semantics, as focus --- won't move 'left' on the end of list. +-- True. Order is preserved, and focus moves as described for 'delete'. -- filter :: (a -> Bool) -> Stack a -> StackOrNot a filter p (Stack f ls rs) = case L.filter p (f:rs) of f':rs' -> Just $ Stack f' (L.filter p ls) rs' -- maybe move focus down - [] -> case L.filter p (reverse ls) of -- filter back up - f':rs' -> Just $ Stack f' [] rs' -- else up + [] -> case L.filter p ls of -- filter back up + f':rs' -> Just $ Stack f' [] (reverse rs') -- else up [] -> Nothing -- | @@ -437,21 +433,12 @@ insertUp a s = if member a s then s else insert -- * deleting the master window resets it to the newly focused window -- * otherwise, delete doesn't affect the master. -- -delete :: (Integral i, Ord a, Eq s) => a -> StackSet i a s sd -> StackSet i a s sd -delete w s | Just w == peek s = remove s -- common case. - | otherwise = maybe s (removeWindow.tag.workspace.current $ s) (findIndex w s) - where - -- find and remove window script - removeWindow o n = foldr ($) s [view o,remove,view n] - - -- actual removal logic, and focus/master logic: - remove = modify Nothing $ \c -> - if focus c == w - then case c of - Stack _ ls (r:rs) -> Just $ Stack r ls rs -- try down first - Stack _ (l:ls) [] -> Just $ Stack l ls [] -- else up - Stack _ [] [] -> Nothing - else Just $ c { up = w `L.delete` up c, down = w `L.delete` down c } +delete :: (Ord a, Eq s) => a -> StackSet i a s sd -> StackSet i a s sd +delete w s = s { current = removeFromScreen (current s) + , visible = map removeFromScreen (visible s) + , hidden = map removeFromWorkspace (hidden s) } + where removeFromWorkspace ws = ws { stack = stack ws >>= filter (/=w) } + removeFromScreen scr = scr { workspace = removeFromWorkspace (workspace scr) } ------------------------------------------------------------------------ -- cgit v1.2.3