X.L.Monitor: changes in message passing

- transform mbName (Maybe String) to name (String)
- slghtly change semantics of messages, document it
This commit is contained in:
Roman Cheplyaka 2008-12-26 22:08:51 +00:00
parent d44ca42551
commit ed240c6972

View File

@ -59,7 +59,7 @@ import Control.Monad
-- > -- Cairo-clock creates 2 windows with the same classname, thus also using title -- > -- Cairo-clock creates 2 windows with the same classname, thus also using title
-- > prop = ClassName "Cairo-clock" `And` Title "MacSlow's Cairo-Clock" -- > prop = ClassName "Cairo-clock" `And` Title "MacSlow's Cairo-Clock"
-- > -- rectangle 150x150 in lower right corner, assuming 1280x800 resolution -- > -- rectangle 150x150 in lower right corner, assuming 1280x800 resolution
-- > , rect = (Rectangle (1280-150) (800-150) 150 150) -- > , rect = Rectangle (1280-150) (800-150) 150 150
-- > -- avoid flickering -- > -- avoid flickering
-- > , persistent = True -- > , persistent = True
-- > -- make the window transparent -- > -- make the window transparent
@ -67,7 +67,7 @@ import Control.Monad
-- > -- hide on start -- > -- hide on start
-- > , visible = False -- > , visible = False
-- > -- assign it a name to be able to toggle it independently of others -- > -- assign it a name to be able to toggle it independently of others
-- > , mbName = Just "clock" -- > , name = "clock"
-- > } -- > }
-- --
-- Add ManageHook to de-manage monitor windows and apply opacity settings. -- Add ManageHook to de-manage monitor windows and apply opacity settings.
@ -92,7 +92,7 @@ data Monitor a = Monitor
{ prop :: Property -- ^ property which uniquely identifies monitor window { prop :: Property -- ^ property which uniquely identifies monitor window
, rect :: Rectangle -- ^ specifies where to put monitor , rect :: Rectangle -- ^ specifies where to put monitor
, visible :: Bool -- ^ is it visible by default? , visible :: Bool -- ^ is it visible by default?
, mbName :: (Maybe String) -- ^ name of monitor (useful when we have many of them) , name :: String -- ^ name of monitor (useful when we have many of them)
, persistent :: Bool -- ^ is it shown on all layouts? , persistent :: Bool -- ^ is it shown on all layouts?
, opacity :: Integer -- ^ opacity level , opacity :: Integer -- ^ opacity level
} deriving (Read, Show) } deriving (Read, Show)
@ -104,11 +104,13 @@ monitor = Monitor
{ prop = Const False { prop = Const False
, rect = Rectangle 0 0 0 0 , rect = Rectangle 0 0 0 0
, visible = True , visible = True
, mbName = Nothing , name = ""
, persistent = False , persistent = False
, opacity = 0xFFFFFFFF , opacity = 0xFFFFFFFF
} }
-- | Messages without names affect all monitors. Messages with names affect only
-- monitors whose names match.
data MonitorMessage = ToggleMonitor | ShowMonitor | HideMonitor data MonitorMessage = ToggleMonitor | ShowMonitor | HideMonitor
| ToggleMonitorNamed String | ToggleMonitorNamed String
| ShowMonitorNamed String | ShowMonitorNamed String
@ -134,13 +136,13 @@ instance LayoutModifier Monitor Window where
handleMess mon mess handleMess mon mess
| Just ToggleMonitor <- fromMessage mess = return $ Just $ mon { visible = not $ visible mon } | Just ToggleMonitor <- fromMessage mess = return $ Just $ mon { visible = not $ visible mon }
| Just (ToggleMonitorNamed n) <- fromMessage mess = return $ | Just (ToggleMonitorNamed n) <- fromMessage mess = return $
if mbName mon `elem` [Just n, Nothing] then Just $ mon { visible = not $ visible mon } else Nothing if name mon == n then Just $ mon { visible = not $ visible mon } else Nothing
| Just ShowMonitor <- fromMessage mess = return $ Just $ mon { visible = True } | Just ShowMonitor <- fromMessage mess = return $ Just $ mon { visible = True }
| Just (ShowMonitorNamed n) <- fromMessage mess = return $ | Just (ShowMonitorNamed n) <- fromMessage mess = return $
if mbName mon `elem` [Just n, Nothing] then Just $ mon { visible = True } else Nothing if name mon == n then Just $ mon { visible = True } else Nothing
| Just HideMonitor <- fromMessage mess = return $ Just $ mon { visible = False } | Just HideMonitor <- fromMessage mess = return $ Just $ mon { visible = False }
| Just (HideMonitorNamed n) <- fromMessage mess = return $ | Just (HideMonitorNamed n) <- fromMessage mess = return $
if mbName mon `elem` [Just n, Nothing] then Just $ mon { visible = False } else Nothing if name mon == n then Just $ mon { visible = False } else Nothing
| Just Hide <- fromMessage mess = do unless (persistent mon) $ withMonitor (prop mon) () hide; return Nothing | Just Hide <- fromMessage mess = do unless (persistent mon) $ withMonitor (prop mon) () hide; return Nothing
| otherwise = return Nothing | otherwise = return Nothing