summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-01-15 00:44:36 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-01-15 00:44:36 +0100
commit9d9ae4166bd0d6b85f1eb19d6f1699a6453517db (patch)
tree1bd7a63b0faf33c63aea6d21c1653a5409c65f6e
parentdc09eaa311110b90e1768b52da73eee250e2aadb (diff)
downloadxmobar-9d9ae4166bd0d6b85f1eb19d6f1699a6453517db.tar.gz
xmobar-9d9ae4166bd0d6b85f1eb19d6f1699a6453517db.tar.bz2
Volume monitor: new field 'volumebar', and a bit of refactoring
-rw-r--r--README2
-rw-r--r--src/Plugins/Monitors/Volume.hs32
2 files changed, 18 insertions, 16 deletions
diff --git a/README b/README
index 4d94987..2e5eb47 100644
--- a/README
+++ b/README
@@ -579,7 +579,7 @@ Monitors have default aliases.
- `--highd` _number_ High threshold for dB. Defaults to -5.0.
- `--lowd` _number_ Low threshold for dB. Defaults to -30.0.
- Variables that can be used with the `-t`/`--template` argument:
- `volume`, `dB`, `status`
+ `volume`, `volumebar`, `dB`, `status`
- Default template: `Vol: <volume>% <status>`
- Requires the package [alsa-mixer] installed in your system. In addition,
to activate this plugin you must pass `--flags="with_alsa"` during
diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs
index c0f97a6..0c5f92c 100644
--- a/src/Plugins/Monitors/Volume.hs
+++ b/src/Plugins/Monitors/Volume.hs
@@ -21,7 +21,8 @@ import Sound.ALSA.Mixer
import System.Console.GetOpt
volumeConfig :: IO MConfig
-volumeConfig = mkMConfig "Vol: <volume>% <status>" ["volume","dB","status"]
+volumeConfig = mkMConfig "Vol: <volume>% <status>"
+ ["volume", "volumebar", "dB","status"]
data VolumeOpts = VolumeOpts
@@ -66,9 +67,13 @@ percent v' lo' hi' = (v - lo) / (hi - lo)
hi = fromIntegral hi'
formatVol :: Integer -> Integer -> Integer -> Monitor String
-formatVol v lo hi =
+formatVol lo hi v =
showPercentWithColors $ percent v lo hi
+formatVolBar :: Integer -> Integer -> Integer -> Monitor String
+formatVolBar lo hi v =
+ showPercentBar (100 * x) x where x = percent v lo hi
+
switchHelper :: VolumeOpts
-> (VolumeOpts -> Maybe String)
-> (VolumeOpts -> String)
@@ -85,12 +90,13 @@ formatSwitch opts False = switchHelper opts offColor offString
colorHelper :: Maybe String -> String
colorHelper = maybe "" (\c -> "<fc=" ++ c ++ ">")
-formatDb :: VolumeOpts -> Float -> Monitor String
-formatDb opts db = do
+formatDb :: VolumeOpts -> Integer -> Monitor String
+formatDb opts dbi = do
h <- getConfigValue highColor
m <- getConfigValue normalColor
l <- getConfigValue lowColor
- let digits = showDigits 0 db
+ let db = fromIntegral dbi / 100.0
+ digits = showDigits 0 db
startColor | db >= highDbThresh opts = colorHelper h
| db < lowDbThresh opts = colorHelper l
| otherwise = colorHelper m
@@ -106,17 +112,13 @@ runVolume mixerName controlName argv = do
(common $ volume control)
switchControl = fromJust $ maybe (playback $ switch control) Just
(common $ switch control)
+ maybeNA = maybe (return "N/A")
(lo, hi) <- io $ getRange volumeControl
val <- io $ getChannel FrontLeft $ value volumeControl
db <- io $ getChannel FrontLeft $ dB volumeControl
sw <- io $ getChannel FrontLeft switchControl
- p <- case val of
- Just x -> formatVol x lo hi
- Nothing -> formatVol hi lo hi
- d <- case db of
- Just x -> formatDb opts $ fromIntegral x / 100.0
- Nothing -> formatDb opts 0.0
- s <- case sw of
- Just x -> formatSwitch opts x
- Nothing -> formatSwitch opts True
- parseTemplate [ p, d, s ]
+ p <- maybeNA (formatVol lo hi) val
+ b <- maybeNA (formatVolBar lo hi) val
+ d <- maybeNA (formatDb opts) db
+ s <- maybeNA (formatSwitch opts) sw
+ parseTemplate [p, b, d, s]