module Monky.Examples.Alsa
( getVOLHandle
, AlsaH
)
where
import Monky.Alsa hiding (getVOLHandle)
import qualified Monky.Alsa as A (getVOLHandle)
import Monky.Modules
import Monky.Examples.Utility
import Formatting
import Data.Text (Text)
getVolumeStr :: VOLHandle -> IO Text
getVolumeStr h = do
updateVOLH h
m <- getMute h
v <- getVolumePercent h
if m
then return "Mute"
else return $ sformat ((left 3 ' ' %. int) % "%") v
getVOLOutput :: VOLHandle -> IO [MonkyOut]
getVOLOutput h = do
out <- getVolumeStr h
return [MonkyPlain out]
instance PollModule AlsaH where
getOutput (AH h) = getVOLOutput h
instance EvtModule AlsaH where
startEvtLoop (AH h) r = do
[fd] <- getPollFDs h
r =<< getOutput (AH h)
loopFd h fd r getVOLOutput
newtype AlsaH = AH VOLHandle
getVOLHandle :: String
-> IO AlsaH
getVOLHandle = fmap AH . A.getVOLHandle