-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.IndependentScreens
-- Copyright   :  (c) 2009 Daniel Wagner
-- License     :  BSD3
--
-- Maintainer  :  <daniel@wagner-home.com>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Utility functions for simulating independent sets of workspaces on
-- each screen (like dwm's workspace model), using internal tags to
-- distinguish workspaces associated with each screen.
-----------------------------------------------------------------------------

module XMonad.Layout.IndependentScreens (
    -- * Usage
    -- $usage
    VirtualWorkspace, PhysicalWorkspace,
    workspaces',
    withScreens, onCurrentScreen,
    marshallPP,
    whenCurrentOn,
    countScreens,
    -- * Converting between virtual and physical workspaces
    -- $converting
    marshall, unmarshall, unmarshallS, unmarshallW,
    marshallWindowSpace, unmarshallWindowSpace, marshallSort
) where

-- for the screen stuff
import Control.Applicative((<*), liftA2)
import Control.Arrow hiding ((|||))
import Control.Monad
import Data.List (nub, genericLength)
import Graphics.X11.Xinerama
import XMonad
import XMonad.StackSet hiding (filter, workspaces)
import XMonad.Hooks.DynamicLog

-- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
--
-- > import XMonad.Layout.IndependentScreens
--
-- You can define your workspaces by calling @withScreens@:
--
-- > myConfig = def { workspaces = withScreens 2 ["web", "email", "irc"] }
--
-- This will create \"physical\" workspaces with distinct internal names for
-- each (screen, virtual workspace) pair.
--
-- Then edit any keybindings that use the list of workspaces or refer
-- to specific workspace names.  In the default configuration, only
-- the keybindings for changing workspace do this:
--
-- > keyBindings conf = let m = modMask conf in fromList $
-- >     {- lots of other keybindings -}
-- >     [((m .|. modm, k), windows $ f i)
-- >         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
-- >         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
--
-- This should change to
--
-- > keyBindings conf = let m = modMask conf in fromList $
-- >     {- lots of other keybindings -}
-- >     [((m .|. modm, k), windows $ onCurrentScreen f i)
-- >         | (i, k) <- zip (workspaces' conf) [xK_1 .. xK_9]
-- >         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
--
-- In particular, the analogue of @XMonad.workspaces@ is
-- @workspaces'@, and you can use @onCurrentScreen@ to convert functions
-- of virtual workspaces to functions of physical workspaces, which work
-- by marshalling the virtual workspace name and the currently focused
-- screen into a physical workspace name.
--
-- A complete example abusing many of the functions below is available in the
-- "XMonad.Config.Dmwit" module.

type VirtualWorkspace  = WorkspaceId
type PhysicalWorkspace = WorkspaceId

-- $converting
-- You shouldn't need to use the functions below very much. They are used
-- internally. However, in some cases, they may be useful, and so are exported
-- just in case. In general, the \"marshall\" functions convert the convenient
-- form (like \"web\") you would like to use in your configuration file to the
-- inconvenient form (like \"2_web\") that xmonad uses internally. Similarly,
-- the \"unmarshall\" functions convert in the other direction.

marshall :: ScreenId -> VirtualWorkspace -> PhysicalWorkspace
marshall :: ScreenId -> VirtualWorkspace -> VirtualWorkspace
marshall (S Int
sc) VirtualWorkspace
vws = Int -> VirtualWorkspace
forall a. Show a => a -> VirtualWorkspace
show Int
sc VirtualWorkspace -> VirtualWorkspace -> VirtualWorkspace
forall a. [a] -> [a] -> [a]
++ Char
'_'Char -> VirtualWorkspace -> VirtualWorkspace
forall a. a -> [a] -> [a]
:VirtualWorkspace
vws

unmarshall  :: PhysicalWorkspace -> (ScreenId, VirtualWorkspace)
unmarshallS :: PhysicalWorkspace -> ScreenId
unmarshallW :: PhysicalWorkspace -> VirtualWorkspace

unmarshall :: VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall  = ((Int -> ScreenId
S (Int -> ScreenId)
-> (VirtualWorkspace -> Int) -> VirtualWorkspace -> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> Int
forall a. Read a => VirtualWorkspace -> a
read) (VirtualWorkspace -> ScreenId)
-> (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace, VirtualWorkspace)
-> (ScreenId, VirtualWorkspace)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Int -> VirtualWorkspace -> VirtualWorkspace
forall a. Int -> [a] -> [a]
drop Int
1) ((VirtualWorkspace, VirtualWorkspace)
 -> (ScreenId, VirtualWorkspace))
-> (VirtualWorkspace -> (VirtualWorkspace, VirtualWorkspace))
-> VirtualWorkspace
-> (ScreenId, VirtualWorkspace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool)
-> VirtualWorkspace -> (VirtualWorkspace, VirtualWorkspace)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'_')
unmarshallS :: VirtualWorkspace -> ScreenId
unmarshallS = (ScreenId, VirtualWorkspace) -> ScreenId
forall a b. (a, b) -> a
fst ((ScreenId, VirtualWorkspace) -> ScreenId)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall
unmarshallW :: VirtualWorkspace -> VirtualWorkspace
unmarshallW = (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall

workspaces' :: XConfig l -> [VirtualWorkspace]
workspaces' :: XConfig l -> [VirtualWorkspace]
workspaces' = [VirtualWorkspace] -> [VirtualWorkspace]
forall a. Eq a => [a] -> [a]
nub ([VirtualWorkspace] -> [VirtualWorkspace])
-> (XConfig l -> [VirtualWorkspace])
-> XConfig l
-> [VirtualWorkspace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VirtualWorkspace -> VirtualWorkspace)
-> [VirtualWorkspace] -> [VirtualWorkspace]
forall a b. (a -> b) -> [a] -> [b]
map ((ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall) ([VirtualWorkspace] -> [VirtualWorkspace])
-> (XConfig l -> [VirtualWorkspace])
-> XConfig l
-> [VirtualWorkspace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConfig l -> [VirtualWorkspace]
forall (l :: * -> *). XConfig l -> [VirtualWorkspace]
workspaces

withScreens :: ScreenId            -- ^ The number of screens to make workspaces for
            -> [VirtualWorkspace]  -- ^ The desired virtual workspace names
            -> [PhysicalWorkspace] -- ^ A list of all internal physical workspace names
withScreens :: ScreenId -> [VirtualWorkspace] -> [VirtualWorkspace]
withScreens ScreenId
n [VirtualWorkspace]
vws = [ScreenId -> VirtualWorkspace -> VirtualWorkspace
marshall ScreenId
sc VirtualWorkspace
pws | VirtualWorkspace
pws <- [VirtualWorkspace]
vws, ScreenId
sc <- [ScreenId
0..ScreenId
nScreenId -> ScreenId -> ScreenId
forall a. Num a => a -> a -> a
-ScreenId
1]]

onCurrentScreen :: (VirtualWorkspace -> WindowSet -> a) -> (PhysicalWorkspace -> WindowSet -> a)
onCurrentScreen :: (VirtualWorkspace -> WindowSet -> a)
-> VirtualWorkspace -> WindowSet -> a
onCurrentScreen VirtualWorkspace -> WindowSet -> a
f VirtualWorkspace
vws = Screen
  VirtualWorkspace (Layout Window) Window ScreenId ScreenDetail
-> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
screen (Screen
   VirtualWorkspace (Layout Window) Window ScreenId ScreenDetail
 -> ScreenId)
-> (WindowSet
    -> Screen
         VirtualWorkspace (Layout Window) Window ScreenId ScreenDetail)
-> WindowSet
-> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet
-> Screen
     VirtualWorkspace (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
current (WindowSet -> ScreenId)
-> (ScreenId -> WindowSet -> a) -> WindowSet -> a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= VirtualWorkspace -> WindowSet -> a
f (VirtualWorkspace -> WindowSet -> a)
-> (ScreenId -> VirtualWorkspace) -> ScreenId -> WindowSet -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId -> VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace -> ScreenId -> VirtualWorkspace
forall a b c. (a -> b -> c) -> b -> a -> c
flip ScreenId -> VirtualWorkspace -> VirtualWorkspace
marshall VirtualWorkspace
vws

-- | In case you don't know statically how many screens there will be, you can call this in main before starting xmonad.  For example, part of my config reads
--
-- > main = do
-- >   nScreens <- countScreens
-- >   xmonad $ def {
-- >     ...
-- >     workspaces = withScreens nScreens (workspaces def),
-- >     ...
-- >     }
--
countScreens :: (MonadIO m, Integral i) => m i
countScreens :: m i
countScreens = ([Rectangle] -> i) -> m [Rectangle] -> m i
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Rectangle] -> i
forall i a. Num i => [a] -> i
genericLength (m [Rectangle] -> m i)
-> (IO [Rectangle] -> m [Rectangle]) -> IO [Rectangle] -> m i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO [Rectangle] -> m [Rectangle]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Rectangle] -> m i) -> IO [Rectangle] -> m i
forall a b. (a -> b) -> a -> b
$ VirtualWorkspace -> IO Display
openDisplay VirtualWorkspace
"" IO Display -> (Display -> IO [Rectangle]) -> IO [Rectangle]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (IO [Rectangle] -> IO () -> IO [Rectangle])
-> (Display -> IO [Rectangle])
-> (Display -> IO ())
-> Display
-> IO [Rectangle]
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 IO [Rectangle] -> IO () -> IO [Rectangle]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
(<*) Display -> IO [Rectangle]
getScreenInfo Display -> IO ()
closeDisplay

-- | This turns a naive pretty-printer into one that is aware of the
-- independent screens. That is, you can write your pretty printer to behave
-- the way you want on virtual workspaces; this function will convert that
-- pretty-printer into one that first filters out physical workspaces on other
-- screens, then converts all the physical workspaces on this screen to their
-- virtual names.
--
-- For example, if you have handles @hLeft@ and @hRight@ for bars on the left and right screens, respectively, and @pp@ is a pretty-printer function that takes a handle, you could write
--
-- > logHook = let log screen handle = dynamicLogWithPP . marshallPP screen . pp $ handle
-- >           in log 0 hLeft >> log 1 hRight
marshallPP :: ScreenId -> PP -> PP
marshallPP :: ScreenId -> PP -> PP
marshallPP ScreenId
s PP
pp = PP
pp {
    ppCurrent :: VirtualWorkspace -> VirtualWorkspace
ppCurrent           = PP -> VirtualWorkspace -> VirtualWorkspace
ppCurrent         PP
pp (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall,
    ppVisible :: VirtualWorkspace -> VirtualWorkspace
ppVisible           = PP -> VirtualWorkspace -> VirtualWorkspace
ppVisible         PP
pp (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall,
    ppHidden :: VirtualWorkspace -> VirtualWorkspace
ppHidden            = PP -> VirtualWorkspace -> VirtualWorkspace
ppHidden          PP
pp (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall,
    ppHiddenNoWindows :: VirtualWorkspace -> VirtualWorkspace
ppHiddenNoWindows   = PP -> VirtualWorkspace -> VirtualWorkspace
ppHiddenNoWindows PP
pp (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall,
    ppUrgent :: VirtualWorkspace -> VirtualWorkspace
ppUrgent            = PP -> VirtualWorkspace -> VirtualWorkspace
ppUrgent          PP
pp (VirtualWorkspace -> VirtualWorkspace)
-> (VirtualWorkspace -> VirtualWorkspace)
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, VirtualWorkspace) -> VirtualWorkspace
forall a b. (a, b) -> b
snd ((ScreenId, VirtualWorkspace) -> VirtualWorkspace)
-> (VirtualWorkspace -> (ScreenId, VirtualWorkspace))
-> VirtualWorkspace
-> VirtualWorkspace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VirtualWorkspace -> (ScreenId, VirtualWorkspace)
unmarshall,
    ppSort :: X ([WindowSpace] -> [WindowSpace])
ppSort              = (([WindowSpace] -> [WindowSpace])
 -> [WindowSpace] -> [WindowSpace])
-> X ([WindowSpace] -> [WindowSpace])
-> X ([WindowSpace] -> [WindowSpace])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ScreenId
-> ([WindowSpace] -> [WindowSpace])
-> [WindowSpace]
-> [WindowSpace]
marshallSort ScreenId
s) (PP -> X ([WindowSpace] -> [WindowSpace])
ppSort PP
pp)
    }

-- | Take a pretty-printer and turn it into one that only runs when the current
-- workspace is one associated with the given screen. The way this works is a
-- bit hacky, so beware: the 'ppOutput' field of the input will not be invoked
-- if either of the following conditions is met:
--
-- 1. The 'ppSort' of the input returns an empty list (when not given one).
--
-- 2. The 'ppOrder' of the input returns the exact string @\"\\0\"@.
--
-- For example, you can use this to create a pipe which tracks the title of the
-- window currently focused on a given screen (even if the screen is not
-- current) by doing something like this:
--
-- > ppFocus s = whenCurrentOn s def
-- >     { ppOrder  = \(_:_:title:_) -> [title]
-- >     , ppOutput = appendFile ("focus" ++ show s) . (++ "\n")
-- >     }
--
-- Sequence a few of these pretty-printers to get a log hook that keeps each
-- screen's title up-to-date.
whenCurrentOn :: ScreenId -> PP -> PP
whenCurrentOn :: ScreenId -> PP -> PP
whenCurrentOn ScreenId
s PP
pp = PP
pp
    { ppSort :: X ([WindowSpace] -> [WindowSpace])
ppSort = do
        [WindowSpace] -> [WindowSpace]
sort <- PP -> X ([WindowSpace] -> [WindowSpace])
ppSort PP
pp
        ([WindowSpace] -> [WindowSpace])
-> X ([WindowSpace] -> [WindowSpace])
forall (m :: * -> *) a. Monad m => a -> m a
return (([WindowSpace] -> [WindowSpace])
 -> X ([WindowSpace] -> [WindowSpace]))
-> ([WindowSpace] -> [WindowSpace])
-> X ([WindowSpace] -> [WindowSpace])
forall a b. (a -> b) -> a -> b
$ \[WindowSpace]
xs -> case [WindowSpace]
xs of
            WindowSpace
x:[WindowSpace]
_ | VirtualWorkspace -> ScreenId
unmarshallS (WindowSpace -> VirtualWorkspace
forall i l a. Workspace i l a -> i
tag WindowSpace
x) ScreenId -> ScreenId -> Bool
forall a. Eq a => a -> a -> Bool
== ScreenId
s -> [WindowSpace] -> [WindowSpace]
sort [WindowSpace]
xs
            [WindowSpace]
_ -> []
    , ppOrder :: [VirtualWorkspace] -> [VirtualWorkspace]
ppOrder = \i :: [VirtualWorkspace]
i@(VirtualWorkspace
wss:[VirtualWorkspace]
_) -> case VirtualWorkspace
wss of
        VirtualWorkspace
"" -> [VirtualWorkspace
"\0"] -- we got passed no workspaces; this is the signal from ppSort that this is a boring case
        VirtualWorkspace
_  -> PP -> [VirtualWorkspace] -> [VirtualWorkspace]
ppOrder PP
pp [VirtualWorkspace]
i
    , ppOutput :: VirtualWorkspace -> IO ()
ppOutput = \VirtualWorkspace
out -> case VirtualWorkspace
out of
        VirtualWorkspace
"\0" -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return () -- we got passed the signal from ppOrder that this is a boring case
        VirtualWorkspace
_ -> PP -> VirtualWorkspace -> IO ()
ppOutput PP
pp VirtualWorkspace
out
    }

-- | If @vSort@ is a function that sorts 'WindowSpace's with virtual names, then @marshallSort s vSort@ is a function which sorts 'WindowSpace's with physical names in an analogous way -- but keeps only the spaces on screen @s@.
marshallSort :: ScreenId -> ([WindowSpace] -> [WindowSpace]) -> ([WindowSpace] -> [WindowSpace])
marshallSort :: ScreenId
-> ([WindowSpace] -> [WindowSpace])
-> [WindowSpace]
-> [WindowSpace]
marshallSort ScreenId
s [WindowSpace] -> [WindowSpace]
vSort = [WindowSpace] -> [WindowSpace]
pScreens ([WindowSpace] -> [WindowSpace])
-> ([WindowSpace] -> [WindowSpace])
-> [WindowSpace]
-> [WindowSpace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [WindowSpace] -> [WindowSpace]
vSort ([WindowSpace] -> [WindowSpace])
-> ([WindowSpace] -> [WindowSpace])
-> [WindowSpace]
-> [WindowSpace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [WindowSpace] -> [WindowSpace]
vScreens where
    onScreen :: Workspace VirtualWorkspace l a -> Bool
onScreen Workspace VirtualWorkspace l a
ws = VirtualWorkspace -> ScreenId
unmarshallS (Workspace VirtualWorkspace l a -> VirtualWorkspace
forall i l a. Workspace i l a -> i
tag Workspace VirtualWorkspace l a
ws) ScreenId -> ScreenId -> Bool
forall a. Eq a => a -> a -> Bool
== ScreenId
s
    vScreens :: [WindowSpace] -> [WindowSpace]
vScreens    = (WindowSpace -> WindowSpace) -> [WindowSpace] -> [WindowSpace]
forall a b. (a -> b) -> [a] -> [b]
map WindowSpace -> WindowSpace
unmarshallWindowSpace ([WindowSpace] -> [WindowSpace])
-> ([WindowSpace] -> [WindowSpace])
-> [WindowSpace]
-> [WindowSpace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WindowSpace -> Bool) -> [WindowSpace] -> [WindowSpace]
forall a. (a -> Bool) -> [a] -> [a]
filter WindowSpace -> Bool
forall l a. Workspace VirtualWorkspace l a -> Bool
onScreen
    pScreens :: [WindowSpace] -> [WindowSpace]
pScreens    = (WindowSpace -> WindowSpace) -> [WindowSpace] -> [WindowSpace]
forall a b. (a -> b) -> [a] -> [b]
map (ScreenId -> WindowSpace -> WindowSpace
marshallWindowSpace ScreenId
s)

-- | Convert the tag of the 'WindowSpace' from a 'VirtualWorkspace' to a 'PhysicalWorkspace'.
marshallWindowSpace   :: ScreenId -> WindowSpace -> WindowSpace
-- | Convert the tag of the 'WindowSpace' from a 'PhysicalWorkspace' to a 'VirtualWorkspace'.
unmarshallWindowSpace :: WindowSpace -> WindowSpace

marshallWindowSpace :: ScreenId -> WindowSpace -> WindowSpace
marshallWindowSpace ScreenId
s WindowSpace
ws = WindowSpace
ws { tag :: VirtualWorkspace
tag = ScreenId -> VirtualWorkspace -> VirtualWorkspace
marshall ScreenId
s  (WindowSpace -> VirtualWorkspace
forall i l a. Workspace i l a -> i
tag WindowSpace
ws) }
unmarshallWindowSpace :: WindowSpace -> WindowSpace
unmarshallWindowSpace WindowSpace
ws = WindowSpace
ws { tag :: VirtualWorkspace
tag = VirtualWorkspace -> VirtualWorkspace
unmarshallW (WindowSpace -> VirtualWorkspace
forall i l a. Workspace i l a -> i
tag WindowSpace
ws) }