Skip to content

Commit

Permalink
Update StatusBar library to use the X monad instead of IO.
Browse files Browse the repository at this point in the history
This change allows dynamic status bars to pull information out of the
X monad, which can be really useful for status bars. For instance, you
can now query the screen width in order to set the width of status
bars appropriately.

Existing configurations may need to be updated in order to lift an
`IO StatusBarConfig` to an `X StatusBarConfig`. This can be done using
either the `io` function provided by `XMonad.Core`, or `liftIO` from
`base` in `Control.Monad.IO.Class`

- https://hackage.haskell.org/package/xmonad-0.18.0/docs/XMonad-Core.html#v:io
- https://hackage.haskell.org/package/base-4.19.1.0/docs/Control-Monad-IO-Class.html#v:liftIO
  • Loading branch information
Chobbes committed Mar 9, 2024
1 parent de5ef6c commit e735339
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

### Breaking Changes

* `XMonad.Hooks.StatusBars`

- Move status bar functions from the `IO` to the `X` monad to
allow them to look up information from `X`, like the screen
width. Existing configurations may need to use `io` from
`XMonad.Core` or `liftIO` from `Control.Monad.IO.Class` in
order to lift any existing `IO StatusBarConfig` values into
`X StatusBarConfig` values.

### New Modules

* `XMonad.Actions.Profiles`.
Expand Down
8 changes: 4 additions & 4 deletions XMonad/Hooks/StatusBar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ instance ExtensionClass ActiveSBs where
-- 'avoidStruts', check 'dynamicEasySBs'.
--
-- Heavily inspired by "XMonad.Hooks.DynamicBars"
dynamicSBs :: (ScreenId -> IO StatusBarConfig) -> XConfig l -> XConfig l
dynamicSBs :: (ScreenId -> X StatusBarConfig) -> XConfig l -> XConfig l
dynamicSBs f conf = addAfterRescreenHook (updateSBs f) $ conf
{ startupHook = startupHook conf >> killAllStatusBars >> updateSBs f
, logHook = logHook conf >> logSBs
Expand All @@ -462,7 +462,7 @@ dynamicSBs f conf = addAfterRescreenHook (updateSBs f) $ conf
-- resulting config and adds 'avoidStruts' to the
-- layout.
dynamicEasySBs :: LayoutClass l Window
=> (ScreenId -> IO StatusBarConfig)
=> (ScreenId -> X StatusBarConfig)
-> XConfig l
-> XConfig (ModifiedLayout AvoidStruts l)
dynamicEasySBs f conf =
Expand All @@ -471,7 +471,7 @@ dynamicEasySBs f conf =
-- | Given the function to create status bars, update
-- the status bars by killing those that shouldn't be
-- visible anymore and creates any missing status bars
updateSBs :: (ScreenId -> IO StatusBarConfig) -> X ()
updateSBs :: (ScreenId -> X StatusBarConfig) -> X ()
updateSBs f = do
actualScreens <- withWindowSet $ return . map W.screen . W.screens
(toKeep, toKill) <-
Expand All @@ -480,7 +480,7 @@ updateSBs f = do
cleanSBs (map snd toKill)
-- Create new status bars if needed
let missing = actualScreens \\ map fst toKeep
added <- io $ traverse (\s -> (s,) <$> f s) missing
added <- traverse (\s -> (s,) <$> f s) missing
traverse_ (sbStartupHook . snd) added
XS.put (ASB (toKeep ++ added))

Expand Down

0 comments on commit e735339

Please sign in to comment.