From 513ed120b4088bab7fe6d77e841d72e082dd6812 Mon Sep 17 00:00:00 2001 From: slotThe Date: Sun, 5 Jan 2020 17:11:55 +0100 Subject: Add template to Volume --- src/Xmobar/Plugins/Monitors/Volume.hs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Xmobar/Plugins/Monitors/Volume.hs b/src/Xmobar/Plugins/Monitors/Volume.hs index de07aa6..a52261f 100644 --- a/src/Xmobar/Plugins/Monitors/Volume.hs +++ b/src/Xmobar/Plugins/Monitors/Volume.hs @@ -23,16 +23,26 @@ module Xmobar.Plugins.Monitors.Volume import Control.Applicative ( (<$>), liftA3 ) import Control.Monad ( liftM2, liftM3, mplus ) +import Data.Maybe (fromMaybe) import Data.Traversable (sequenceA) import Xmobar.Plugins.Monitors.Common import Sound.ALSA.Mixer import qualified Sound.ALSA.Exception as AE import System.Console.GetOpt -volumeConfig :: IO MConfig -volumeConfig = mkMConfig "Vol: % " - ["volume", "volumebar", "volumevbar", "dB","status", "volumeipat"] +volumeConfig :: IO MConfig +volumeConfig = + mkMConfig + "Vol: % " + [ "volume" + , "volumebar" + , "volumevbar" + , "dB" + , "status" + , "volumeipat" + , "volumestatus" + ] data VolumeOpts = VolumeOpts { onString :: String @@ -135,7 +145,7 @@ switchHelper opts cHelp strHelp vs = return $ ++ maybe "" (const "") (cHelp opts) formatSwitch :: VolumeOpts -> Bool -> VolumeStatus -> Monitor String -formatSwitch opts True vs = switchHelper opts onColor onString vs +formatSwitch opts True vs = switchHelper opts onColor onString vs formatSwitch opts False _ = switchHelper opts offColor offString VolOff -- | Convert the current volume status into user defined strings @@ -183,7 +193,13 @@ runVolumeWith opts mixerName controlName = do (liftA3 percent val lo hi) -- current volume in % s <- getFormatSwitch opts sw volStat ipat <- liftMonitor $ liftM3 (formatVolDStr $ volumeIconPattern opts) lo hi val - parseTemplate [p, b, v, d, s, ipat] + + -- Volume and status in one. + let vs = if isVolOff sw + then offString opts -- User defined off string + else s ++ p -- Status string, current volume in % + + parseTemplate [p, b, v, d, s, ipat, vs] where @@ -239,4 +255,8 @@ runVolumeWith opts mixerName controlName = do getFormatSwitch _ _ Nothing = unavailable getFormatSwitch opts' (Just sw) (Just vs) = formatSwitch opts' sw vs + -- | Determine whether the volume is off based on the value of 'sw' from + -- 'runVolumeWith'. + isVolOff = not . fromMaybe False + unavailable = getConfigValue naString -- cgit v1.2.3