moved to pamixer

Ricard Illa 2021-08-04 20:36:05 +02:00
parent b9e38a1ce1
commit e7d15f9718
No known key found for this signature in database
GPG Key ID: F69A672B72E54902
1 changed files with 20 additions and 7 deletions

View File

@ -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