From 253b9528143d12b04987dfb9cee0a847b281b007 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Fri, 18 Feb 2022 22:03:23 +0000 Subject: [PATCH] X.L.SubLayouts: Document assumptions/pre-conditions of toGroupStack This started as an investigation/fix of xmonad freezing when a bug in X.A.DynamicWorkspaces caused duplicate Windows in a single Workspace Stack, but I soon(-ish) realized that trying to make SubLayouts robust enough to handle duplicities in a Stack is futile. Any code that creates duplicities in a Stack is buggy, and must be fixed; the rest can assume there aren't any. Instead, let's just document that this is a pre-condition, and that (and how) stuff will misbehave. Related: https://github.com/xmonad/xmonad-contrib/issues/565 --- XMonad/Layout/SubLayouts.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/XMonad/Layout/SubLayouts.hs b/XMonad/Layout/SubLayouts.hs index bf2e6484..1a590f97 100644 --- a/XMonad/Layout/SubLayouts.hs +++ b/XMonad/Layout/SubLayouts.hs @@ -422,7 +422,7 @@ updateGroup :: Ord a => Maybe (W.Stack a) -> Groups a -> Groups a updateGroup Nothing _ = mempty updateGroup (Just st) gs = fromGroupStack (toGroupStack gs st) --- | rearrange the windowset to put the groups of tabs next to eachother, so +-- | rearrange the windowset to put the groups of tabs next to each other, so -- that the stack of tabs stays put. updateWs :: Groups Window -> X () updateWs = windowsMaybe . updateWs' @@ -447,6 +447,11 @@ fromGroupStack = M.fromList . map (W.focus &&& id) . W.integrate -- | Arrange a stack of windows into a stack of stacks, according to (possibly -- outdated) Groups. +-- +-- Assumes that the groups are disjoint and there are no duplicates in the +-- stack; will result in additional duplicates otherwise. This is a reasonable +-- assumption—the rest of xmonad will mishave too—but it isn't checked +-- anywhere and there had been bugs breaking this assumption in the past. toGroupStack :: (Ord a) => Groups a -> W.Stack a -> GroupStack a toGroupStack gs st@(W.Stack f ls rs) = W.Stack (fromJust (lu f)) (mapMaybe lu ls) (mapMaybe lu rs)