summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar
diff options
context:
space:
mode:
authorslotThe <soliditsallgood@tuta.io>2020-01-05 17:11:55 +0100
committerslotThe <soliditsallgood@tuta.io>2020-01-05 17:11:55 +0100
commit513ed120b4088bab7fe6d77e841d72e082dd6812 (patch)
treee96ce9f84c149b981069386f313c97f968f82d06 /src/Xmobar
parent1f44a35904d7d866a73efab6a5c6bd8a0653282c (diff)
downloadxmobar-513ed120b4088bab7fe6d77e841d72e082dd6812.tar.gz
xmobar-513ed120b4088bab7fe6d77e841d72e082dd6812.tar.bz2
Add <volumestatus> template to Volume
Diffstat (limited to 'src/Xmobar')
-rw-r--r--src/Xmobar/Plugins/Monitors/Volume.hs30
1 files changed, 25 insertions, 5 deletions
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>% <status>"
- ["volume", "volumebar", "volumevbar", "dB","status", "volumeipat"]
+volumeConfig :: IO MConfig
+volumeConfig =
+ mkMConfig
+ "Vol: <volume>% <status>"
+ [ "volume"
+ , "volumebar"
+ , "volumevbar"
+ , "dB"
+ , "status"
+ , "volumeipat"
+ , "volumestatus"
+ ]
data VolumeOpts = VolumeOpts
{ onString :: String
@@ -135,7 +145,7 @@ switchHelper opts cHelp strHelp vs = return $
++ maybe "" (const "</fc>") (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