2020-03-20 20:10:15 -04:00
|
|
|
{-# 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
|
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
module Xmobar.Plugins.Screensaver (Screensaver(..)) where
|
2020-03-15 15:10:25 -04:00
|
|
|
|
2020-03-25 18:55:52 -04:00
|
|
|
import Control.Concurrent
|
|
|
|
import Control.Monad
|
2020-03-20 20:10:15 -04:00
|
|
|
|
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
|
|
|
|
2020-03-25 18:55:52 -04:00
|
|
|
newtype Screensaver = Screensaver (String, String, String)
|
2020-03-20 15:41:13 -04:00
|
|
|
deriving (Read, Show)
|
2020-03-15 15:10:25 -04:00
|
|
|
|
|
|
|
instance Exec Screensaver where
|
2020-03-20 20:10:15 -04:00
|
|
|
alias (Screensaver _) = "screensaver"
|
|
|
|
start (Screensaver (text, colorOn, colorOff)) cb = do
|
|
|
|
_ <- matchSignal $ cb . fmtState
|
|
|
|
cb . fmtState =<< callQuery
|
2020-03-21 14:46:49 -04:00
|
|
|
forever (threadDelay 5000000)
|
2020-03-20 20:10:15 -04:00
|
|
|
where
|
|
|
|
fmtState = \case
|
2021-06-19 00:54:01 -04:00
|
|
|
Just s -> xmobarColor (if s then colorOn else colorOff) "" text
|
2020-03-20 20:10:15 -04:00
|
|
|
Nothing -> "N/A"
|
2020-03-20 15:41:13 -04:00
|
|
|
|