summaryrefslogtreecommitdiffstats
path: root/StackSet.hs
diff options
context:
space:
mode:
authorDavid Roundy <droundy@darcs.net>2007-07-24 16:20:45 +0200
committerDavid Roundy <droundy@darcs.net>2007-07-24 16:20:45 +0200
commit36b8561f5e83e68b1c2babc9f56c7d91fa5386e4 (patch)
tree1f4fab93d3dca6a5d3c27a96813601f3fca172d6 /StackSet.hs
parent53b55cb7b1f9836daa5ab4c7e31fa784fdfa4c4b (diff)
downloadmetatile-36b8561f5e83e68b1c2babc9f56c7d91fa5386e4.tar
metatile-36b8561f5e83e68b1c2babc9f56c7d91fa5386e4.zip
make delete work when window is in multiple workspaces.
darcs-hash:20070724142045-72aca-2c5ac9fe613333f8333329fc63d420883891f782
Diffstat (limited to 'StackSet.hs')
-rw-r--r--StackSet.hs31
1 files changed, 9 insertions, 22 deletions
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) }
------------------------------------------------------------------------