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

32 lines
849 B
Haskell
Raw Normal View History

module Xmobar.Plugins.Screensaver where
2020-03-15 15:10:25 -04:00
import Graphics.X11.Xlib.Display
import Graphics.X11.XScreenSaver
import Xmobar
data Screensaver = Screensaver (String, String, String) Int
deriving (Read, Show)
2020-03-15 15:10:25 -04:00
instance Exec Screensaver where
alias (Screensaver _ _) = "screensaver"
run (Screensaver opts _) = run' opts
rate (Screensaver _ r) = r
-- TODO make this respond to events rather than polling
run' :: (String, String, String) -> IO String
run' (text, colorOn, colorOff) = do
dpy <- openDisplay ""
xssi <- xScreenSaverQueryInfo dpy
closeDisplay dpy
return $ case xssi of
Just x -> wrapColor text
$ case xssi_state x of
ScreenSaverDisabled -> colorOff
_ -> colorOn
2020-03-15 15:10:25 -04:00
Nothing -> "N/A"
where
-- TODO not DRY
wrapColor s c = "<fc=" ++ c ++ ">" ++ s ++ "</fc>"