mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
Removed unnecessary IO
This applies for withSB and withEasySB, as well as statusBarProp and statusBarPropTo, making composability better. statusBarPipe is more awkward to use now, but that's fine
This commit is contained in:
parent
654fa5045c
commit
168cb6a6c3
@ -198,7 +198,7 @@ statusBar :: LayoutClass l Window
|
|||||||
-> IO (XConfig (ModifiedLayout AvoidStruts l))
|
-> IO (XConfig (ModifiedLayout AvoidStruts l))
|
||||||
statusBar cmd pp k conf= do
|
statusBar cmd pp k conf= do
|
||||||
sb <- statusBarPipe cmd (pure pp)
|
sb <- statusBarPipe cmd (pure pp)
|
||||||
withEasySB sb k conf
|
return $ withEasySB sb k conf
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- Helper function which provides ToggleStruts keybinding
|
-- Helper function which provides ToggleStruts keybinding
|
||||||
@ -260,7 +260,6 @@ dynamicLogXinerama = withWindowSet $ io . putStrLn . pprWindowSetXinerama
|
|||||||
-- the menu bar.
|
-- the menu bar.
|
||||||
xmobarProp :: LayoutClass l Window
|
xmobarProp :: LayoutClass l Window
|
||||||
=> XConfig l -- ^ The base config
|
=> XConfig l -- ^ The base config
|
||||||
-> IO (XConfig (ModifiedLayout AvoidStruts l))
|
-> XConfig (ModifiedLayout AvoidStruts l)
|
||||||
xmobarProp conf = do
|
xmobarProp =
|
||||||
xmobarPropConfig <- statusBarProp "xmobar" (pure xmobarPP)
|
withEasySB (statusBarProp "xmobar" (pure xmobarPP)) toggleStrutsKey
|
||||||
withEasySB xmobarPropConfig toggleStrutsKey conf
|
|
||||||
|
@ -82,9 +82,8 @@ import XMonad.Hooks.StatusBar.PP
|
|||||||
-- status bar that supports property logging, is to use 'statusBarProp'
|
-- status bar that supports property logging, is to use 'statusBarProp'
|
||||||
-- with 'withEasySB'; these take care of the necessary plumbing:
|
-- with 'withEasySB'; these take care of the necessary plumbing:
|
||||||
--
|
--
|
||||||
-- > main = do
|
-- > mySB = statusBarProp "xmobar" (pure xmobarPP)
|
||||||
-- > mySB <- statusBarProp "xmobar" (pure xmobarPP)
|
-- > main = xmonad $ withEasySB mySB defToggleStrutsKey def
|
||||||
-- > xmonad =<< withEasySB mySB defToggleStrutsKey def
|
|
||||||
--
|
--
|
||||||
-- You can read more about X11 properties
|
-- You can read more about X11 properties
|
||||||
-- [here](https://en.wikipedia.org/wiki/X_Window_System_core_protocol#Properties)
|
-- [here](https://en.wikipedia.org/wiki/X_Window_System_core_protocol#Properties)
|
||||||
@ -100,9 +99,8 @@ import XMonad.Hooks.StatusBar.PP
|
|||||||
-- to configure "XMonad.Hooks.ManageDocks" yourself. Here's what that might
|
-- to configure "XMonad.Hooks.ManageDocks" yourself. Here's what that might
|
||||||
-- look like:
|
-- look like:
|
||||||
--
|
--
|
||||||
-- > main = do
|
-- > mySB = statusBarProp "xmobar" (pure myPP)
|
||||||
-- > mySB <- statusBarProp "xmobar" (pure myPP)
|
-- > main = xmonad . withSB mySB . ewmh . docks $ def {...}
|
||||||
-- > xmonad =<< (withSB mySB . ewmh . docks $ def {...})
|
|
||||||
--
|
--
|
||||||
-- You then have to tell your status bar to read from the @_XMONAD_LOG@ property
|
-- You then have to tell your status bar to read from the @_XMONAD_LOG@ property
|
||||||
-- of the root window. In the case of xmobar, this is achieved by simply using
|
-- of the root window. In the case of xmobar, this is achieved by simply using
|
||||||
@ -132,6 +130,13 @@ import XMonad.Hooks.StatusBar.PP
|
|||||||
-- bar read from that pipe.
|
-- bar read from that pipe.
|
||||||
-- Please be aware that this kind of setup is very bug-prone and hence is
|
-- Please be aware that this kind of setup is very bug-prone and hence is
|
||||||
-- discouraged: if anything goes wrong with the bar, xmonad will freeze!
|
-- discouraged: if anything goes wrong with the bar, xmonad will freeze!
|
||||||
|
--
|
||||||
|
-- Also note that 'statusBarPipe' returns 'IO StatusBarConfig', so
|
||||||
|
-- you need to evaluate it before passing it to 'withSB' or 'withEasySB':
|
||||||
|
--
|
||||||
|
-- > main = do
|
||||||
|
-- > mySB <- statusBarPipe "xmobar" (pure myPP)
|
||||||
|
-- > xmonad $ withSB mySB myConf
|
||||||
|
|
||||||
|
|
||||||
-- $plumbing
|
-- $plumbing
|
||||||
@ -250,9 +255,8 @@ instance Default StatusBarConfig where
|
|||||||
withSB :: LayoutClass l Window
|
withSB :: LayoutClass l Window
|
||||||
=> StatusBarConfig -- ^ The status bar config
|
=> StatusBarConfig -- ^ The status bar config
|
||||||
-> XConfig l -- ^ The base config
|
-> XConfig l -- ^ The base config
|
||||||
-> IO (XConfig l)
|
-> XConfig l
|
||||||
withSB (StatusBarConfig lh sh ch) conf =
|
withSB (StatusBarConfig lh sh ch) conf = conf
|
||||||
return $ conf
|
|
||||||
{ logHook = logHook conf *> lh
|
{ logHook = logHook conf *> lh
|
||||||
, startupHook = startupHook conf *> ch *> sh
|
, startupHook = startupHook conf *> ch *> sh
|
||||||
}
|
}
|
||||||
@ -268,12 +272,11 @@ withEasySB :: LayoutClass l Window
|
|||||||
-> (XConfig Layout -> (KeyMask, KeySym))
|
-> (XConfig Layout -> (KeyMask, KeySym))
|
||||||
-- ^ The key binding
|
-- ^ The key binding
|
||||||
-> XConfig l -- ^ The base config
|
-> XConfig l -- ^ The base config
|
||||||
-> IO (XConfig (ModifiedLayout AvoidStruts l))
|
-> XConfig (ModifiedLayout AvoidStruts l)
|
||||||
withEasySB sb k conf = do
|
withEasySB sb k conf = docks . withSB sb $ conf
|
||||||
conf' <- withSB sb conf
|
{ layoutHook = avoidStruts (layoutHook conf)
|
||||||
return $ docks $ conf' { layoutHook = avoidStruts (layoutHook conf')
|
, keys = (<>) <$> keys' <*> keys conf
|
||||||
, keys = (<>) <$> keys' <*> keys conf'
|
}
|
||||||
}
|
|
||||||
where keys' = (`M.singleton` sendMessage ToggleStruts) . k
|
where keys' = (`M.singleton` sendMessage ToggleStruts) . k
|
||||||
|
|
||||||
-- | Default @mod-b@ key binding for 'withEasySB'
|
-- | Default @mod-b@ key binding for 'withEasySB'
|
||||||
@ -283,16 +286,16 @@ defToggleStrutsKey XConfig{modMask = modm} = (modm, xK_b)
|
|||||||
-- | Creates a 'StatusBarConfig' that uses property logging to @_XMONAD_LOG@, which
|
-- | Creates a 'StatusBarConfig' that uses property logging to @_XMONAD_LOG@, which
|
||||||
-- is set in 'xmonadDefProp'
|
-- is set in 'xmonadDefProp'
|
||||||
statusBarProp :: String -- ^ The command line to launch the status bar
|
statusBarProp :: String -- ^ The command line to launch the status bar
|
||||||
-> X PP -- ^ The pretty printing options
|
-> X PP -- ^ The pretty printing options
|
||||||
-> IO StatusBarConfig
|
-> StatusBarConfig
|
||||||
statusBarProp = statusBarPropTo xmonadDefProp
|
statusBarProp = statusBarPropTo xmonadDefProp
|
||||||
|
|
||||||
-- | Like 'statusBarProp', but lets you define the property
|
-- | Like 'statusBarProp', but lets you define the property
|
||||||
statusBarPropTo :: String -- ^ Property to write the string to
|
statusBarPropTo :: String -- ^ Property to write the string to
|
||||||
-> String -- ^ The command line to launch the status bar
|
-> String -- ^ The command line to launch the status bar
|
||||||
-> X PP -- ^ The pretty printing options
|
-> X PP -- ^ The pretty printing options
|
||||||
-> IO StatusBarConfig
|
-> StatusBarConfig
|
||||||
statusBarPropTo prop cmd pp = pure def
|
statusBarPropTo prop cmd pp = def
|
||||||
{ sbLogHook = xmonadPropLog' prop =<< dynamicLogString =<< pp
|
{ sbLogHook = xmonadPropLog' prop =<< dynamicLogString =<< pp
|
||||||
, sbStartupHook = spawnStatusBarAndRemember cmd
|
, sbStartupHook = spawnStatusBarAndRemember cmd
|
||||||
, sbCleanupHook = cleanupStatusBars
|
, sbCleanupHook = cleanupStatusBars
|
||||||
@ -300,8 +303,8 @@ statusBarPropTo prop cmd pp = pure def
|
|||||||
|
|
||||||
-- | Like 'statusBarProp', but uses pipe-based logging instead.
|
-- | Like 'statusBarProp', but uses pipe-based logging instead.
|
||||||
statusBarPipe :: String -- ^ The command line to launch the status bar
|
statusBarPipe :: String -- ^ The command line to launch the status bar
|
||||||
-> X PP -- ^ The pretty printing options
|
-> X PP -- ^ The pretty printing options
|
||||||
-> IO StatusBarConfig
|
-> IO StatusBarConfig
|
||||||
statusBarPipe cmd xpp = do
|
statusBarPipe cmd xpp = do
|
||||||
h <- spawnPipe cmd
|
h <- spawnPipe cmd
|
||||||
return $ def { sbLogHook = xpp >>= \pp -> dynamicLogWithPP pp { ppOutput = hPutStrLn h } }
|
return $ def { sbLogHook = xpp >>= \pp -> dynamicLogWithPP pp { ppOutput = hPutStrLn h } }
|
||||||
@ -314,11 +317,12 @@ statusBarPipe cmd xpp = do
|
|||||||
-- Here's an example of what such declarative configuration of multiple status
|
-- Here's an example of what such declarative configuration of multiple status
|
||||||
-- bars may look like:
|
-- bars may look like:
|
||||||
--
|
--
|
||||||
-- > main = do
|
-- > -- Make sure to setup the xmobar config accordingly
|
||||||
-- > xmobarTop <- statusBarPipe "xmobar -x 0 ~/.config/xmobar/xmobarrc_top" (pure ppTop)
|
-- > xmobarTop = statusBarPropTo "_XMONAD_LOG_1" "xmobar -x 0 ~/.config/xmobar/xmobarrc_top" (pure ppTop)
|
||||||
-- > xmobarBottom <- statusBarPipe "xmobar -x 0 ~/.config/xmobar/xmobarrc_bottom" (pure ppBottom)
|
-- > xmobarBottom = statusBarPropTo "_XMONAD_LOG_2" "xmobar -x 0 ~/.config/xmobar/xmobarrc_bottom" (pure ppBottom)
|
||||||
-- > xmobar1 <- statusBarPipe "xmobar -x 1 ~/.config/xmobar/xmobarrc1" (pure pp1)
|
-- > xmobar1 = statusBarPropTo "_XMONAD_LOG_3" "xmobar -x 1 ~/.config/xmobar/xmobarrc1" (pure pp1)
|
||||||
-- > xmonad =<< withSB (xmobarTop <> xmobarBottom <> xmobar1) myConfig
|
-- >
|
||||||
|
-- > main = xmonad $ withSB (xmobarTop <> xmobarBottom <> xmobar1) myConfig
|
||||||
--
|
--
|
||||||
-- The above example also works if the different status bars support different
|
-- The above example also works if the different status bars support different
|
||||||
-- logging methods: you could mix property logging and logging via pipes.
|
-- logging methods: you could mix property logging and logging via pipes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user