diff --git a/bin/sway_brightness b/bin/sway_brightness index 8b68f28..eaeed36 100755 --- a/bin/sway_brightness +++ b/bin/sway_brightness @@ -1,7 +1,11 @@ #!/bin/bash source $HOME/.config/sway/bin/sway_helpers DEVICE=sysfs/backlight/intel_backlight -APP=light +NOTIFY_APP="dunstify -a brightness -h string:x-dunst-stack-tag:brightness" +ICON=$HOME/.local/share/icons/Tela-circle-dark/16/panel/xfpm-brightness-lcd.svg +APP="/usr/bin/light -s $DEVICE" +PRG1="●" +PRG2="◌" ## main _log BRIGHTNESS INFO args: $* @@ -9,13 +13,20 @@ _check_app $APP case $1 in d*) - light -s $DEVICE -U 10 + $APP -U 10 + BR=$($APP) + $NOTIFY_APP -i $ICON "$BR" "$(getProgressString 10 "$PRG1" "$PRG2" $BR)" ;; i*) - light -s $DEVICE -A 10 + $APP -A 10 + BR=$($APP) + $NOTIFY_APP -i $ICON "$BR" "$(getProgressString 10 "$PRG1" "$PRG2" $BR)" ;; - *) - echo "invalid argument: \"$1\"" + "-h"|"--help") echo "arguments: [decrease|increase]" ;; + *) + BR=$($APP) + $NOTIFY_APP -i $ICON "$BR" "$(getProgressString 10 "$PRG1" "$PRG2" $BR)" + ;; esac diff --git a/bin/sway_helpers b/bin/sway_helpers index 3726909..353b44c 100644 --- a/bin/sway_helpers +++ b/bin/sway_helpers @@ -43,3 +43,20 @@ function _set_inhibit() { ;; esac } + +function getProgressString() { + ITEMS="$1" # The total number of items(the width of the bar) + FILLED_ITEM="$2" # The look of a filled item + NOT_FILLED_ITEM="$3" # The look of a not filled item + STATUS="$4" # The current progress status in percent + + # calculate how many items need to be filled and not filled + FILLED_ITEMS=$(echo "((${ITEMS} * ${STATUS})/100 + 0.5) / 1" | bc) + NOT_FILLED_ITEMS=$(echo "$ITEMS - $FILLED_ITEMS" | bc) + + # Assemble the bar string + msg=$(printf "%${FILLED_ITEMS}s" | sed "s| |${FILLED_ITEM}|g") + msg=${msg}$(printf "%${NOT_FILLED_ITEMS}s" | sed "s| |${NOT_FILLED_ITEM}|g") + echo "$msg" +} + diff --git a/bin/sway_volume b/bin/sway_volume index 5666eff..08b7b54 100755 --- a/bin/sway_volume +++ b/bin/sway_volume @@ -11,22 +11,6 @@ VOL1="●" # echo -e '\u25cc' VOL2="◌" -function getProgressString() { - ITEMS="$1" # The total number of items(the width of the bar) - FILLED_ITEM="$2" # The look of a filled item - NOT_FILLED_ITEM="$3" # The look of a not filled item - STATUS="$4" # The current progress status in percent - - # calculate how many items need to be filled and not filled - FILLED_ITEMS=$(echo "((${ITEMS} * ${STATUS})/100 + 0.5) / 1" | bc) - NOT_FILLED_ITEMS=$(echo "$ITEMS - $FILLED_ITEMS" | bc) - - # Assemble the bar string - msg=$(printf "%${FILLED_ITEMS}s" | sed "s| |${FILLED_ITEM}|g") - msg=${msg}$(printf "%${NOT_FILLED_ITEMS}s" | sed "s| |${NOT_FILLED_ITEM}|g") - echo "$msg" -} - function notify() { VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//') MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2)