Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add volume indicators to xmobar. #23

Merged
merged 1 commit into from May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
120 changes: 120 additions & 0 deletions bin/getMasterVolume
@@ -0,0 +1,120 @@
#!/bin/sh


# To generate bars in python:
# import numpy
# import math
# for i in numpy.arange(0, 10.1, 0.1):
# print str(i) + ") bar='" + ''.join(['/' for s in range(0, int(round(i)))]) + ''.join(['-' for s in range(0, int(10 - round(i)))]) +"' ;;"
#
# (Requires minor hand-editing to remove '.0' for whole numbers.
#
#
bars=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2/10 }}' | head -n 1)

case $bars in
0) bar='----------' ;;
0.1) bar='----------' ;;
0.2) bar='----------' ;;
0.3) bar='----------' ;;
0.4) bar='----------' ;;
0.5) bar='/---------' ;;
0.6) bar='/---------' ;;
0.7) bar='/---------' ;;
0.8) bar='/---------' ;;
0.9) bar='/---------' ;;
1) bar='/---------' ;;
1.1) bar='/---------' ;;
1.2) bar='/---------' ;;
1.3) bar='/---------' ;;
1.4) bar='/---------' ;;
1.5) bar='//--------' ;;
1.6) bar='//--------' ;;
1.7) bar='//--------' ;;
1.8) bar='//--------' ;;
1.9) bar='//--------' ;;
2) bar='//--------' ;;
2.1) bar='//--------' ;;
2.2) bar='//--------' ;;
2.3) bar='//--------' ;;
2.4) bar='//--------' ;;
2.5) bar='///-------' ;;
2.6) bar='///-------' ;;
2.7) bar='///-------' ;;
2.8) bar='///-------' ;;
2.9) bar='///-------' ;;
3) bar='///-------' ;;
3.1) bar='///-------' ;;
3.2) bar='///-------' ;;
3.3) bar='///-------' ;;
3.4) bar='///-------' ;;
3.5) bar='////------' ;;
3.6) bar='////------' ;;
3.7) bar='////------' ;;
3.8) bar='////------' ;;
3.9) bar='////------' ;;
4) bar='////------' ;;
4.1) bar='////------' ;;
4.2) bar='////------' ;;
4.3) bar='////------' ;;
4.4) bar='////------' ;;
4.5) bar='/////-----' ;;
4.6) bar='/////-----' ;;
4.7) bar='/////-----' ;;
4.8) bar='/////-----' ;;
4.9) bar='/////-----' ;;
5) bar='/////-----' ;;
5.1) bar='/////-----' ;;
5.2) bar='/////-----' ;;
5.3) bar='/////-----' ;;
5.4) bar='/////-----' ;;
5.5) bar='//////----' ;;
5.6) bar='//////----' ;;
5.7) bar='//////----' ;;
5.8) bar='//////----' ;;
5.9) bar='//////----' ;;
6) bar='//////----' ;;
6.1) bar='//////----' ;;
6.2) bar='//////----' ;;
6.3) bar='//////----' ;;
6.4) bar='//////----' ;;
6.5) bar='///////---' ;;
6.6) bar='///////---' ;;
6.7) bar='///////---' ;;
6.8) bar='///////---' ;;
6.9) bar='///////---' ;;
7) bar='///////---' ;;
7.1) bar='///////---' ;;
7.2) bar='///////---' ;;
7.3) bar='///////---' ;;
7.4) bar='///////---' ;;
7.5) bar='////////--' ;;
7.6) bar='////////--' ;;
7.7) bar='////////--' ;;
7.8) bar='////////--' ;;
7.9) bar='////////--' ;;
8) bar='////////--' ;;
8.1) bar='////////--' ;;
8.2) bar='////////--' ;;
8.3) bar='////////--' ;;
8.4) bar='////////--' ;;
8.5) bar='/////////-' ;;
8.6) bar='/////////-' ;;
8.7) bar='/////////-' ;;
8.8) bar='/////////-' ;;
8.9) bar='/////////-' ;;
9) bar='/////////-' ;;
9.1) bar='/////////-' ;;
9.2) bar='/////////-' ;;
9.3) bar='/////////-' ;;
9.4) bar='/////////-' ;;
9.5) bar='//////////' ;;
9.6) bar='//////////' ;;
9.7) bar='//////////' ;;
9.8) bar='//////////' ;;
9.9) bar='//////////' ;;
10) bar='//////////' ;;
*) bar='----------' ;;
esac

echo "$bar ($bars)"
3 changes: 2 additions & 1 deletion xmobar.hs
Expand Up @@ -16,9 +16,10 @@ Config {
Run Swap ["-t","Swap: <usedratio>%","-H","1024","-L","512","-h","#FFB6B0","-l","#CEFFAC","-n","#FFFFCC"] 10,
Run Network "em1" ["-t","Net: <rx>, <tx>","-H","200","-L","10","-h","#FFB6B0","-l","#CEFFAC","-n","#FFFFCC"] 10,
Run Date "%a %b %_d %l:%M" "date" 10,
Run Com "getMasterVolume" [] "volumelevel" 10,
Run StdinReader
],
sepChar = "%",
alignSep = "}{",
template = "%StdinReader% }{ %multicpu% %memory% %swap% %em1% <fc=#FFFFCC>%date%</fc> %KPAO%"
template = "%StdinReader% }{ %multicpu% %memory% %swap% %em1% | <fc=#FFFFCC>%date%</fc> | Volume: <fc=#b2b2ff>%volumelevel%</fc>"
}
10 changes: 5 additions & 5 deletions xmonad.hs
Expand Up @@ -168,23 +168,23 @@ myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $

-- Decrease volume.
, ((0, xF86XK_AudioLowerVolume),
spawn "amixer -q set Master 10%-")
spawn "amixer -q set Master 5%-")

-- Increase volume.
, ((0, xF86XK_AudioRaiseVolume),
spawn "amixer -q set Master 10%+")
spawn "amixer -q set Master 5%+")

-- Mute volume.
, ((modMask .|. controlMask, xK_m),
spawn "amixer -q set Master toggle")

-- Decrease volume.
, ((modMask .|. controlMask, xK_j),
spawn "amixer -q set Master 10%-")
spawn "amixer -q set Master 5%-")

-- Increase volume.
, ((modMask .|. controlMask, xK_k),
spawn "amixer -q set Master 10%+")
spawn "amixer -q set Master 5%+")

-- Audio previous.
, ((0, 0x1008FF16),
Expand Down