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

27 lines
675 B
Haskell
Raw Normal View History

{-# LANGUAGE LambdaCase #-}
module Xmobar.Plugins.Screensaver where
2020-03-15 15:10:25 -04:00
import Control.Concurrent
import Control.Monad
import DBus.Screensaver
2020-03-15 15:10:25 -04:00
import Xmobar
data Screensaver = Screensaver (String, String, String)
deriving (Read, Show)
2020-03-15 15:10:25 -04:00
instance Exec Screensaver where
alias (Screensaver _) = "screensaver"
start (Screensaver (text, colorOn, colorOff)) cb = do
_ <- matchSignal $ cb . fmtState
cb . fmtState =<< callQuery
forever (threadDelay 5000000)
where
fmtState = \case
Just s -> wrapColor text $ if s then colorOn else colorOff
Nothing -> "N/A"
wrapColor s c = "<fc=" ++ c ++ ">" ++ s ++ "</fc>"