Skip to content

Commit

Permalink
Added initial WIP xsndioicon utility which watches 'sndioctl -m' outp…
Browse files Browse the repository at this point in the history
…ut and shows a sndio status icon using wmlaunchbutton. Issue #1
  • Loading branch information
morgant committed Nov 19, 2023
1 parent 0f30255 commit 2eec04a
Show file tree
Hide file tree
Showing 6 changed files with 425 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ A simple menu utility to view & control [sndio](https://sndio.org/) devices & st

## LICENSE

Mark James' [FamFamFam Silk Icons](https://github.com/markjames/famfamfam-silk-icons) licensed under the [Creative Commons Attribution 2.5 License](http://creativecommons.org/licenses/by/2.5/).

Released under the [MIT license](LICENSE).
77 changes: 77 additions & 0 deletions bin/xsndioicon
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

#
# xsndioicon - X11 icon to open xsndiomenu
#
# CHANGE LOG:
#
# v0.1 - 2023-11-18 - Morgan Aldridge <[email protected]>
# Initial version.
#
# LICENSE:
#
# Copyright (c) 2023 Morgan Aldridge
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

_pid=""

trap '[ -n "$_pid" ] && kill $_pid' EXIT

_to_percent() {
printf "%.f" "$(echo "$1 * 100" | bc)"
}

_percent_to_icon() {
if [ "$1" -le 0 ] ; then
printf "none"
elif [ "$1" -le 50 ] ; then
printf "low"
else
printf "full"
fi
}

_show_icon() {
[ -n "$_pid" ] && kill "$_pid"
wmlaunchbutton "pixmap/sound_${1}.xpm" xsndiomenu &
_pid="$!"
}

sndioctl -m | while IFS="=" read -r _control _value; do
_value="$(IFS=" " echo "$_value" | cut -f 1)"
printf "_value=%s\n" "$_value"
case "$_control" in
output*.level)
printf "handling output.level=%s\n" "$_value"
_level="$(_to_percent "$_value")"
_show_icon "$(_percent_to_icon "$_level")"
;;
output*.mute)
printf "handling output.mute=%s\n" "$_value"
if [ "$_value" -eq 1 ] ; then
_show_icon "mute"
else
_level="$(sndioctl -n output.level)"
_level="$(_to_percent "$_level")"
_show_icon "$(_percent_to_icon "$_level")"
fi
;;
esac
done
101 changes: 101 additions & 0 deletions pixmap/sound_full.xpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* XPM */
static const char *sound_full[] = {
/* columns rows colors chars-per-pixel */
"16 16 79 1 ",
" c #3F3F3F",
". c #494949",
"X c #515150",
"o c #535353",
"O c #5F5F5D",
"+ c #5F5F5F",
"@ c #61615F",
"# c #646360",
"$ c #646460",
"% c #656560",
"& c #656561",
"* c #676763",
"= c #656565",
"- c #696966",
"; c #696967",
": c #6C6C69",
"> c #6D6D69",
", c #6F6F6B",
"< c #6F6F6E",
"1 c #72716E",
"2 c #73736F",
"3 c #727272",
"4 c #747471",
"5 c #777772",
"6 c #787775",
"7 c #787877",
"8 c #7B7B78",
"9 c gray49",
"0 c #7F7F7C",
"q c #E1172C",
"w c #E12034",
"e c #E12438",
"r c #E1293B",
"t c #E62E3D",
"y c #ED323D",
"u c #ED353F",
"i c #E13042",
"p c #E13243",
"a c #ED3B45",
"s c #E13A4A",
"d c #E13B4B",
"f c #E1404F",
"g c #E14A57",
"h c #ED4D55",
"j c #E9505A",
"k c #ED535A",
"l c #E15763",
"z c #E65A63",
"x c #E95961",
"c c #ED5B61",
"v c #EC656B",
"b c #EC696D",
"n c #838381",
"m c #838383",
"M c #858583",
"N c #858584",
"B c gray52",
"V c #878785",
"C c gray53",
"Z c #8A8A88",
"A c #8B8B88",
"S c #8D8D8B",
"D c #90908F",
"F c #91918F",
"G c gray57",
"H c #929291",
"J c #9A9A99",
"K c #9B9B99",
"L c #9D9D9B",
"P c gray62",
"I c #A2A2A1",
"U c #A3A3A1",
"Y c #A6A6A5",
"T c #A9A9A9",
"R c #AFAFAD",
"E c gray73",
"W c #BCBCBC",
"Q c #C3C3C2",
"! c None",
/* pixels */
"!!!!!!!!!!!!!!!!",
"!!!!!!!!!!!!!!!!",
"!!!!!!!M!!!!!!!!",
"!!!!!ZVn!!!!!!!!",
"!!!!ZLR0!!!!!bl!",
"SGDDUTU6!!!!!zc!",
"ZQWEPnG1!!!v!!ks",
"VYVV03V>!j!xg!si",
"nJ=+X.;;!j!jf!ir",
"8J7<X +&!!!h!!aw",
"41>>>X@&!!!!!tu!",
"!!!!&>4&!!!!eyq!",
"!!!!!##&!!!!!!!!",
"!!!!!!!&!!!!!!!!",
"!!!!!!!!!!!!!!!!",
"!!!!!!!!!!!!!!!!"
};
84 changes: 84 additions & 0 deletions pixmap/sound_low.xpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* XPM */
static const char *sound_low[] = {
/* columns rows colors chars-per-pixel */
"16 16 62 1 ",
" c #3F3F3F",
". c #494949",
"X c #515150",
"o c #535353",
"O c #5F5F5D",
"+ c #5F5F5F",
"@ c #61615F",
"# c #646360",
"$ c #646460",
"% c #656560",
"& c #656561",
"* c #676763",
"= c #656565",
"- c #696966",
"; c #696967",
": c #6C6C69",
"> c #6D6D69",
", c #6F6F6B",
"< c #6F6F6E",
"1 c #72716E",
"2 c #73736F",
"3 c #727272",
"4 c #747471",
"5 c #777772",
"6 c #787775",
"7 c #787877",
"8 c #7B7B78",
"9 c gray49",
"0 c #7F7F7C",
"q c #E1404F",
"w c #E14A57",
"e c #ED4D55",
"r c #E9505A",
"t c #E95961",
"y c #EC656B",
"u c #838381",
"i c #838383",
"p c #858583",
"a c #858584",
"s c gray52",
"d c #878785",
"f c gray53",
"g c #8A8A88",
"h c #8B8B88",
"j c #8D8D8B",
"k c #90908F",
"l c #91918F",
"z c gray57",
"x c #929291",
"c c #9A9A99",
"v c #9B9B99",
"b c #9D9D9B",
"n c gray62",
"m c #A2A2A1",
"M c #A3A3A1",
"N c #A6A6A5",
"B c #A9A9A9",
"V c #AFAFAD",
"C c gray73",
"Z c #BCBCBC",
"A c #C3C3C2",
"S c None",
/* pixels */
"SSSSSSSSSSSSSSSS",
"SSSSSSSSSSSSSSSS",
"SSSSSSSpSSSSSSSS",
"SSSSSgduSSSSSSSS",
"SSSSgbV0SSSSSSSS",
"jzkkMBM6SSSSSSSS",
"gAZCnuz1SSSySSSS",
"dNdd03d>SrStwSSS",
"uc=+X.;;SrSrqSSS",
"8c7<X +&SSSeSSSS",
"41>>>X@&SSSSSSSS",
"SSSS&>4&SSSSSSSS",
"SSSSS##&SSSSSSSS",
"SSSSSSS&SSSSSSSS",
"SSSSSSSSSSSSSSSS",
"SSSSSSSSSSSSSSSS"
};
83 changes: 83 additions & 0 deletions pixmap/sound_mute.xpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* XPM */
static const char *sound_mute[] = {
/* columns rows colors chars-per-pixel */
"16 16 61 1 ",
" c #474040",
". c #515150",
"X c #5F5F5D",
"o c #61615F",
"O c #646360",
"+ c #646460",
"@ c #656560",
"# c #656561",
"$ c #676763",
"% c #656565",
"& c #696966",
"* c #6F6866",
"= c #6D6D69",
"- c #726B68",
"; c #736C68",
": c #747471",
"> c #777772",
", c #7B7B78",
"< c #A65757",
"1 c #B0615F",
"2 c #B26363",
"3 c #B66765",
"4 c #B56666",
"5 c #B86969",
"6 c #CC4D4D",
"7 c #CD4F4E",
"8 c #D35454",
"9 c #D45555",
"0 c #D65454",
"q c #D85959",
"w c #E14E4E",
"e c #E74F4F",
"r c #EB4F4F",
"t c #EE4E4E",
"y c #E45150",
"u c #E45151",
"i c #E65454",
"p c #C87878",
"a c #838381",
"s c #858583",
"d c gray52",
"f c #878785",
"g c gray53",
"h c #8A8A88",
"j c #8B8B88",
"k c #8D8D8B",
"l c #90908F",
"z c #91918F",
"x c #929291",
"c c #9A9A99",
"v c #9B9B99",
"b c #9D9D9B",
"n c gray62",
"m c #A3A3A1",
"M c #A6A6A5",
"N c #A9A9A9",
"B c #AFAFAD",
"V c gray73",
"C c #BCBCBC",
"Z c #C3C3C2",
"A c None",
/* pixels */
"AAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAA",
"AAAAAAAAAAAsAAAA",
"AAAAAAAAAjdaAAAA",
"AAAAAAAAjbB4tAAA",
"AAAAkxllmNpytAAA",
"AAAAjZCVn5i0AAAA",
"AAAAdMdd4yq;AAAA",
"AAAAac%<w7*&AAAA",
"AAAA,c2y7 X$AAAA",
"AAAA:1y8-.o$AAAA",
"AAAA0reA$=:$AAAA",
"AAAAttAAAOO$AAAA",
"AAAAAAAAAAA$AAAA",
"AAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAA"
};
Loading

0 comments on commit 2eec04a

Please sign in to comment.