From 2eec04a3062b93e9ebb38236b88e27105b06a96d Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Sun, 19 Nov 2023 15:02:39 -0500 Subject: [PATCH] Added initial WIP xsndioicon utility which watches 'sndioctl -m' output and shows a sndio status icon using wmlaunchbutton. Issue #1 --- README.md | 2 + bin/xsndioicon | 77 ++++++++++++++++++++++++++++++++ pixmap/sound_full.xpm | 101 ++++++++++++++++++++++++++++++++++++++++++ pixmap/sound_low.xpm | 84 +++++++++++++++++++++++++++++++++++ pixmap/sound_mute.xpm | 83 ++++++++++++++++++++++++++++++++++ pixmap/sound_none.xpm | 78 ++++++++++++++++++++++++++++++++ 6 files changed, 425 insertions(+) create mode 100755 bin/xsndioicon create mode 100644 pixmap/sound_full.xpm create mode 100644 pixmap/sound_low.xpm create mode 100644 pixmap/sound_mute.xpm create mode 100644 pixmap/sound_none.xpm diff --git a/README.md b/README.md index 576f776..ef7ab44 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/bin/xsndioicon b/bin/xsndioicon new file mode 100755 index 0000000..45987a6 --- /dev/null +++ b/bin/xsndioicon @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# xsndioicon - X11 icon to open xsndiomenu +# +# CHANGE LOG: +# +# v0.1 - 2023-11-18 - Morgan Aldridge +# 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 diff --git a/pixmap/sound_full.xpm b/pixmap/sound_full.xpm new file mode 100644 index 0000000..5e2a082 --- /dev/null +++ b/pixmap/sound_full.xpm @@ -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@&!!!!!tu!", +"!!!!&>4&!!!!eyq!", +"!!!!!##&!!!!!!!!", +"!!!!!!!&!!!!!!!!", +"!!!!!!!!!!!!!!!!", +"!!!!!!!!!!!!!!!!" +}; diff --git a/pixmap/sound_low.xpm b/pixmap/sound_low.xpm new file mode 100644 index 0000000..8794cb3 --- /dev/null +++ b/pixmap/sound_low.xpm @@ -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@&SSSSSSSS", +"SSSS&>4&SSSSSSSS", +"SSSSS##&SSSSSSSS", +"SSSSSSS&SSSSSSSS", +"SSSSSSSSSSSSSSSS", +"SSSSSSSSSSSSSSSS" +}; diff --git a/pixmap/sound_mute.xpm b/pixmap/sound_mute.xpm new file mode 100644 index 0000000..46e1a4f --- /dev/null +++ b/pixmap/sound_mute.xpm @@ -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% 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 #838381", +"w c #838383", +"e c #858583", +"r c #858584", +"t c gray52", +"y c #878785", +"u c gray53", +"i c #8A8A88", +"p c #8B8B88", +"a c #8D8D8B", +"s c #90908F", +"d c #91918F", +"f c gray57", +"g c #929291", +"h c #9A9A99", +"j c #9B9B99", +"k c #9D9D9B", +"l c gray62", +"z c #A2A2A1", +"x c #A3A3A1", +"c c #A6A6A5", +"v c #A9A9A9", +"b c #AFAFAD", +"n c gray73", +"m c #BCBCBC", +"M c #C3C3C2", +"N c None", +/* pixels */ +"NNNNNNNNNNNNNNNN", +"NNNNNNNNNNNNNNNN", +"NNNNNNNeNNNNNNNN", +"NNNNNiyqNNNNNNNN", +"NNNNikb0NNNNNNNN", +"afssxvx6NNNNNNNN", +"iMmnlqf1NNNNNNNN", +"ycyy03y>NNNNNNNN", +"qh=+X.;;NNNNNNNN", +"8h7>>X@&NNNNNNNN", +"NNNN&>4&NNNNNNNN", +"NNNNN##&NNNNNNNN", +"NNNNNNN&NNNNNNNN", +"NNNNNNNNNNNNNNNN", +"NNNNNNNNNNNNNNNN" +};