xmonad-config/lib/Xmobar/Screensaver.hs

32 lines
823 B
Haskell
Raw Normal View History

2020-03-15 15:10:25 -04:00
module Xmobar.Screensaver where
import Graphics.X11.Xlib.Display
import Graphics.X11.XScreenSaver
import Xmobar
data Screensaver = Screensaver (String, String, String) Int
deriving (Read, Show)
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
Nothing -> "N/A"
where
-- TODO not DRY
wrapColor s c = "<fc=" ++ c ++ ">" ++ s ++ "</fc>"