[Xmonad] heads up: xmonad zipper patch pushed

Donald Bruce Stewart dons at cse.unsw.edu.au
Sun May 20 03:22:58 EDT 2007


I've pushed the reimplementation of xmonad as a zipper. This affects the
StackSet module entirely (completely rewritten), and much of
Operations.hs.  Additional, a bit of the StackSet api has changed names
(documented in the file), new QC properties have been added., and the
code has shrunk by 55 lines:

                           Code    Comments
Before:

    Operations.hs           194    139
    Main.hs                 110     88
    StackSet.hs             101    132
    XMonad.hs                57     89
    Config.hs                53    136
    TOTAL:                  515    584

After:
    Operations.hs           152    149
    Main.hs                  97     71
    StackSet.hs              87    272
    XMonad.hs                71    102
    Config.hs                53    136
    TOTAL:                  460    730

A few words of warning:

    * This likely breaks some of the contrib modules, due to api
      changes. Fixing that will happen over the next few days.

    * Also, the changes that affect Xinerama are untested, so Jason, if you can
      check that out. In particular, I believe focusWindow needs to
      check for visible workspaces, not just the current workspace.

    * Finally, Neil, if you want to rerun the Catch verifier on StackSet, that
      would be neat. I think I've followed up on the changes you suggested
      earlier in the week.

Here's a sample of the changes to the logic core in StackSet, to make us feel
happy. Old, table-based implementation of 'swap/promote':

    -promote w = maybe w id $ do
    -    a <- peek w -- fail if null
    -    (f, xs@(x:_)) <- M.lookup (current w) (stacks w)
    -    let w' = w { stacks = M.insert (current w) (f, swap a x xs) (stacks w) }
    -    return $ insert a (current w) w' -- and maintain focus (?)
    -  where
    -       swap a b xs = maybe xs id $ do
    -         ai <- L.elemIndex a xs
    -         bi <- L.elemIndex b xs
    -         return . insertAt bi a . insertAt ai b $ xs
    -        where insertAt n x ys = as ++ x : drop 1 bs
    -                 where (as,bs) = splitAt n ys

New implementation:

    +swap = modify Empty $ \c -> case c of
    +    Node _ [] _  -> c    -- already master.
    +    Node t ls rs -> Node t [] (ys ++ x : rs) where (x:ys) = reverse ls

Cute eh? Similar effects for insert/rotate and friends.

Window managers should be zippers.

-- Don


More information about the Xmonad mailing list