Skip to content

Commit

Permalink
X.H.StatusBar: Add signalAllStatusBars
Browse files Browse the repository at this point in the history
With `xrandr --setmonitor`, xmobar sometimes fails to reposition itself,
and needs a second nudge. Provide a way to give it that nudge.
  • Loading branch information
liskin committed Oct 28, 2024
1 parent b22205a commit 5a0d6e4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions XMonad/Hooks/StatusBar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module XMonad.Hooks.StatusBar (
killStatusBar,
killAllStatusBars,
startAllStatusBars,
signalAllStatusBars,
) where

import Control.Concurrent (threadDelay, rtsSupportsBoundThreads)
Expand All @@ -67,7 +68,7 @@ import qualified Codec.Binary.UTF8.String as UTF8 (encode)
import qualified Data.Map as M
import System.IO (hClose)
import System.Posix.Process (getGroupProcessStatus)
import System.Posix.Signals (sigTERM, sigKILL, signalProcessGroup)
import System.Posix.Signals (Signal, sigTERM, sigKILL, signalProcessGroup)
import System.Posix.Types (ProcessID)

import Foreign.C (CChar)
Expand Down Expand Up @@ -572,7 +573,7 @@ spawnStatusBar cmd = do
XS.modify (StatusBarPIDs . M.insert cmd newPid . getPIDs)

-- | Kill all status bars started with 'spawnStatusBar'. Note the
-- caveats in 'cleanupStatusBar'
-- caveats in 'killStatusBar'.
killAllStatusBars :: X ()
killAllStatusBars =
XS.gets (M.elems . getPIDs) >>= io . mapC_ killPid >> XS.put (StatusBarPIDs mempty)
Expand All @@ -585,3 +586,12 @@ killAllStatusBars =
-- `killAllStatusBars`.
startAllStatusBars :: X ()
startAllStatusBars = XS.get >>= traverse_ (sbStartupHook . snd) . getASBs

-- | Send a signal to all status bars started with 'spawnStatusBar'. Note the
-- caveats in 'killStatusBar'.
signalAllStatusBars :: Signal -> X ()
signalAllStatusBars sig =
XS.gets (M.elems . getPIDs) >>= io . traverse_ (signalPid sig)

signalPid :: Signal -> ProcessID -> IO ()
signalPid sig pid = void $ try @SomeException (signalProcessGroup sig pid)

0 comments on commit 5a0d6e4

Please sign in to comment.