diff --git a/src/Monitors/Volume.hs b/src/Monitors/Volume.hs index dde8a77..e992d3b 100644 --- a/src/Monitors/Volume.hs +++ b/src/Monitors/Volume.hs @@ -5,6 +5,7 @@ import Data.Maybe import System.Process import Text.Printf import Text.Regex +import Text.Read import qualified Data.Map as M import Monitors.Common @@ -72,15 +73,27 @@ parseMixerInfo = fmap fmtMixer . matchRegex regex vol = read volume in MixerData { mute = mute, vol = vol } -parseAmixerStdout :: String -> [MixerData] -parseAmixerStdout = nub . mapMaybe parseMixerInfo . lines +fmtData :: MixerData -> String +fmtData = (separator ++ ) . getStatus -fmtData :: [MixerData] -> String -fmtData = (separator ++ ) . intercalate separator . map getStatus +getMute :: IO Bool +getMute = parseMute <$> readProcess "/nix/store/ambq4n07zlax0lwz0v1yph85cph1sssk-pamixer-1.4/bin/pamixer" ["--get-mute"] "" + where + parseMute "true" = True + parseMute "false" = False + parseMute _ = False -runAmixer :: String -> IO String -runAmixer mixer = readProcess "amixer" ["get", "-c", "0", mixer] "" +getVol :: IO Int +getVol = parseVol <$> readProcess "pamixer" ["--get-volume"] "" + where + parseVol x = case readMaybe x of (Just vol) -> vol + Nothing -> 0 +getInfo :: IO MixerData +getInfo = do + mute <- getMute + vol <- getVol + return $ MixerData { mute = mute, vol = vol } queryVolume :: IO String -queryVolume = fmtData . parseAmixerStdout <$> runAmixer mixer +queryVolume = fmtData <$> getInfo