aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDon Stewart <dons@cse.unsw.edu.au>2007-06-10 06:55:51 +0200
committerDon Stewart <dons@cse.unsw.edu.au>2007-06-10 06:55:51 +0200
commit4434c4a765ce9d33c215d24d240d236205afc003 (patch)
tree17ede5d91f1003bc840e746512b85da3b1f8e6b7
parent8a5181aa5635cc68c322dd56085e7257f4ea2c6b (diff)
downloadxmonad-4434c4a765ce9d33c215d24d240d236205afc003.tar.gz
xmonad-4434c4a765ce9d33c215d24d240d236205afc003.tar.xz
xmonad-4434c4a765ce9d33c215d24d240d236205afc003.zip
polish serialisation code (-7 lines)
darcs-hash:20070610045551-9c5c1-a1604a4e90d160728b3c5cd12acb3b4febc3625a.gz
-rw-r--r--XMonad.hs66
1 files changed, 36 insertions, 30 deletions
diff --git a/XMonad.hs b/XMonad.hs
index 058da37..ca8d0f1 100644
--- a/XMonad.hs
+++ b/XMonad.hs
@@ -187,37 +187,43 @@ trace msg = io $! do hPutStrLn stderr msg; hFlush stderr
-- ---------------------------------------------------------------------
-- Serialise a StackSet in a simple format
--
--- 4|1:16777220:16777220,2:18874372:18874372,3::,4::,5::,6::,7::,8::,9::
+-- 432|1:16777220:16777220,2:18874372:18874372,3::,4::,5::,6::,7::,8::,9::
+--
+-- format, roughly,:
+--
+-- fmt := current visible '|' workspaces
+--
+-- current := int
+-- visible := int* | epsilon
+--
+-- workspaces := workspace ',' workspaces0
+-- workspaces0 := workspace ',' workspaces0 | epsilon
+--
+-- workspace := tag ':' focus* ':' clients
+-- clients := epsilon | client ';' clients
+--
+-- tag := int
+-- focus := client
+--
+-- client = int+
+-- int := 0 .. 9
--
-
-infixl 6 <:>, <|>
-(<:>), (<|>) :: Doc -> Doc -> Doc
-p <:> q = p <> char ':' <> q
-p <|> q = p <> char '|' <> q
serial :: WindowSet -> String
serial = render . ppr
-
-newtype Windows = Windows [Window]
-
-class Pretty a where ppr :: a -> Doc
-
-instance Pretty Window where ppr = text . show
-
-instance Pretty a => Pretty [a] where
- ppr = hcat . intersperse (char ',') . map ppr
-
-instance Pretty Windows where
- ppr (Windows s) = hcat . intersperse (char ';') . map ppr $ s
-
-instance Pretty WindowSet where
- ppr s = int (1 + fromIntegral (tag . workspace . current $ s)) <|>
- ppr (sortBy (\a b -> tag a `compare` tag b)
- (map workspace (current s : visible s) ++ hidden s))
-
-instance Pretty (Workspace WorkspaceId Window) where
- ppr (Workspace i s) =
- int (1 + fromIntegral i)
- <:> (case s of Empty -> empty ; _ -> ppr (focus s))
- <:> ppr (Windows (integrate s))
-
+ where
+ ppr s = pprtag (current s) <> hcat (map pprtag (visible s))
+ <|> (hcat . intersperse (char ',') . map pprWorkspace $
+ (sortBy (\a b -> tag a `compare` tag b)
+ (map workspace (current s : visible s) ++ hidden s)))
+ where infixl 6 <|>
+ p <|> q = p <> char '|' <> q
+
+ pprtag = int . (+1) . fromIntegral . tag . workspace
+
+ pprWorkspace (Workspace i s) = int (1 + fromIntegral i)
+ <:> (if s == Empty then empty else text (show (focus s)))
+ <:> pprWindows (integrate s)
+ where p <:> q = p <> char ':' <> q
+
+ pprWindows = hcat . intersperse (char ';') . map (text.show)