xmonad-config/lib/Xmobar/Plugins/Screensaver.hs

40 lines
1.1 KiB
Haskell
Raw Normal View History

{-# LANGUAGE LambdaCase #-}
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Screensaver plugin
--
-- Use the custom DBus interface exported by the XMonad process so I can react
-- to signals spawned by commands
module Xmobar.Plugins.Screensaver
( Screensaver(..)
, ssAlias
) where
2020-03-15 15:10:25 -04:00
2020-03-25 18:55:52 -04:00
import Control.Concurrent
import Control.Monad
2021-11-21 17:54:00 -05:00
import DBus.Client
2020-03-25 18:55:52 -04:00
import Xmobar
2020-04-01 20:17:47 -04:00
import XMonad.Hooks.DynamicLog (xmobarColor)
import XMonad.Internal.DBus.Screensaver
2020-03-15 15:10:25 -04:00
2021-11-21 17:54:00 -05:00
newtype Screensaver = Screensaver (String, String, String) deriving (Read, Show)
2020-03-15 15:10:25 -04:00
ssAlias :: String
ssAlias = "screensaver"
2020-03-15 15:10:25 -04:00
instance Exec Screensaver where
alias (Screensaver _) = ssAlias
start (Screensaver (text, colorOn, colorOff)) cb = do
_ <- matchSignal $ cb . fmtState
2021-11-21 17:54:00 -05:00
cb . fmtState =<< callQuery =<< connectSession
forever (threadDelay 5000000)
where
fmtState = \case
2021-06-19 00:54:01 -04:00
Just s -> xmobarColor (if s then colorOn else colorOff) "" text
Nothing -> "N/A"