X.H.StatusBar: Use addAfterRescreenHook instead of listening for RRScreenChangeNotifyEvent

The new X.H.Rescreen provides a simpler composable API for hooking into
rescreen. Unfortunately it also breaks other code that listens for
RRScreenChangeNotifyEvent, so this conversion isn't really optional.

Not that there's any dispute this is nicer, is there? :-)
This commit is contained in:
Tomas Janousek 2021-06-03 00:38:04 +01:00
parent eab9a3a58e
commit 30995c41ff

View File

@ -74,11 +74,10 @@ import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Layout.LayoutModifier import XMonad.Layout.LayoutModifier
import XMonad.Hooks.ManageDocks import XMonad.Hooks.ManageDocks
import XMonad.Hooks.Rescreen
import XMonad.Hooks.StatusBar.PP import XMonad.Hooks.StatusBar.PP
import qualified XMonad.StackSet as W import qualified XMonad.StackSet as W
import Graphics.X11.Xrandr (xrrSelectInput)
-- $usage -- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
-- --
@ -342,7 +341,7 @@ statusBarPipe cmd xpp = do
-- > -- >
-- > main = xmonad $ withSB (xmobarTop <> xmobarBottom <> xmobar1) myConfig -- > main = xmonad $ withSB (xmobarTop <> xmobarBottom <> xmobar1) myConfig
-- --
-- And here is an example of the related xmobar configuration for the multiple -- And here is an example of the related xmobar configuration for the multiple
-- status bars mentioned above: -- status bars mentioned above:
-- --
-- > xmobarrc_top -- > xmobarrc_top
@ -422,13 +421,9 @@ instance ExtensionClass ActiveSBs where
-- --
-- Heavily inspired by "XMonad.Hooks.DynamicBars" -- Heavily inspired by "XMonad.Hooks.DynamicBars"
dynamicSBs :: (ScreenId -> IO StatusBarConfig) -> XConfig l -> XConfig l dynamicSBs :: (ScreenId -> IO StatusBarConfig) -> XConfig l -> XConfig l
dynamicSBs f conf = conf dynamicSBs f conf = addAfterRescreenHook (updateSBs f) $ conf
{ startupHook = startupHook conf { startupHook = startupHook conf >> killAllStatusBars >> updateSBs f
>> setupEventHandler , logHook = logHook conf >> logSBs
>> killAllStatusBars
>> updateSBs f
, logHook = logHook conf >> logSBs
, handleEventHook = eventHookSBs f <> handleEventHook conf
} }
-- | Like 'dynamicSBs', but applies 'docks' to the -- | Like 'dynamicSBs', but applies 'docks' to the
@ -457,23 +452,10 @@ updateSBs f = do
traverse_ (sbStartupHook . snd) added traverse_ (sbStartupHook . snd) added
XS.put (ASB (toKeep ++ added)) XS.put (ASB (toKeep ++ added))
-- | Handles 'RRScreenChangeNotifyEvent' by updating the
-- status bars.
eventHookSBs :: (ScreenId -> IO StatusBarConfig) -> Event -> X All
eventHookSBs f RRScreenChangeNotifyEvent{} = updateSBs f >> return (All True)
eventHookSBs _ _ = return (All True)
-- | Run 'sbLogHook' for the saved 'StatusBarConfig's -- | Run 'sbLogHook' for the saved 'StatusBarConfig's
logSBs :: X () logSBs :: X ()
logSBs = XS.get >>= traverse_ (sbLogHook . snd) . getASBs logSBs = XS.get >>= traverse_ (sbLogHook . snd) . getASBs
-- | Subscribe to the 'RRScreenChangeNotifyEvent'
setupEventHandler :: X ()
setupEventHandler = do
dpy <- asks display
root <- asks theRoot
io $ xrrSelectInput dpy root rrScreenChangeNotifyMask
-- | Kill the given 'StatusBarConfig's from the given -- | Kill the given 'StatusBarConfig's from the given
-- list -- list
cleanSBs :: [StatusBarConfig] -> X () cleanSBs :: [StatusBarConfig] -> X ()