From 1db7c3761ac1abc25b1951d6d2e1679d7656450f Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 05:40:39 +0000 Subject: [PATCH 01/15] feat swayosd integration --- Configs/.local/share/bin/brightnesscontrol.sh | 8 + Configs/.local/share/bin/volumecontrol.sh | 179 +++++++++++------- 2 files changed, 115 insertions(+), 72 deletions(-) diff --git a/Configs/.local/share/bin/brightnesscontrol.sh b/Configs/.local/share/bin/brightnesscontrol.sh index 5bbf06cd46..6d4730451f 100755 --- a/Configs/.local/share/bin/brightnesscontrol.sh +++ b/Configs/.local/share/bin/brightnesscontrol.sh @@ -3,6 +3,12 @@ scrDir=`dirname "$(realpath "$0")"` source $scrDir/globalcontrol.sh +# Check if SwayOSD is installed +use_swayosd=false +if command -v swayosd-client &> /dev/null && pgrep -x swayosd-server > /dev/null; then + use_swayosd=true +fi + function print_error { cat << "EOF" @@ -28,6 +34,7 @@ function get_brightness { case $1 in i) # increase the backlight + $use_swayosd && swayosd-client --brightness raise "$step" && exit 0 if [[ $(get_brightness) -lt 10 ]] ; then # increase the backlight by 1% if less than 10% brightnessctl set +1% @@ -37,6 +44,7 @@ i) # increase the backlight fi send_notification ;; d) # decrease the backlight + $use_swayosd && swayosd-client --brightness lower "$step" && exit 0 if [[ $(get_brightness) -le 1 ]] ; then # avoid 0% brightness brightnessctl set 1% diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 66ed7c46cf..3e363fd05d 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -1,21 +1,40 @@ #!/usr/bin/env sh +# Source global control script scrDir=$(dirname "$(realpath "$0")") -source $scrDir/globalcontrol.sh - -# define functions - -print_error() { - cat <<"EOF" - ./volumecontrol.sh -[device] - ...valid device are... - i -- input device - o -- output device - p -- player application - ...valid actions are... - i -- increase volume [+5] - d -- decrease volume [-5] - m -- mute [x] +source "$scrDir/globalcontrol.sh" + +# Check if SwayOSD is installed +use_swayosd=false +if command -v swayosd-client &> /dev/null && pgrep -x swayosd-server > /dev/null; then + use_swayosd=true +fi + +# Define functions + +print_usage() { + cat < [step] + +Devices: + -i Input device + -o Output device + -p Player application + +Actions: + i Increase volume + d Decrease volume + m Toggle mute + s Select output device + t Toggle to next output device + +Optional: + step Volume change step (default: 5) + +Examples: + ./volumecontrol.sh -o i 5 # Increase output volume by 5 + ./volumecontrol.sh -i m # Toggle input mute + ./volumecontrol.sh -p spotify d 10 # Decrease Spotify volume by 10 EOF exit 1 } @@ -37,78 +56,94 @@ notify_mute() { fi } -action_pamixer() { - pamixer "${srce}" -"${1}" "${step}" - vol=$(pamixer "${srce}" --get-volume | cat) +change_volume() { + local action=$1 + local step=$2 + local device=$3 + + case $device in + "pamixer") + $use_swayosd && swayosd-client --output-volume $(sed 's/i/raise/;s/d/lower/' <<< "$action") "$step" && exit 0 + pamixer $srce -"$action" "$step" + vol=$(pamixer $srce --get-volume) + ;; + "playerctl") + $use_swayosd && swayosd-client --input-volume $(sed 's/i/raise/;s/d/lower/' <<< "$action") "$step" && exit 0 + [ "$action" == "i" ] && delta="+" || delta="-" + playerctl --player="$srce" volume "0.0${step}${delta}" + vol=$(playerctl --player="$srce" volume | awk '{ printf "%.0f\n", $0 * 100 }') + ;; + esac + + notify_vol } -action_playerctl() { - [ "${1}" == "i" ] && pvl="+" || pvl="-" - playerctl --player="${srce}" volume "0.0${step}${pvl}" - vol=$(playerctl --player="${srce}" volume | awk '{ printf "%.0f\n", $0 * 100 }') +toggle_mute() { + local device=$1 + + case $device in + "pamixer") + $use_swayosd && swayosd-client --input-volume mute-toggle && exit 0 + pamixer $srce -t + notify_mute + ;; + "playerctl") + $use_swayosd && swayosd-client --output-volume mute-toggle && exit 0 + playerctl --player="$srce" volume 0 + notify_mute + ;; + esac } select_output() { - if [ "$@" ]; then - desc="$*" - device=$(pactl list sinks | grep -C2 -F "Description: $desc" | grep Name | cut -d: -f2 | xargs) + local selection=$1 + if [ -n "$selection" ]; then + device=$(pactl list sinks | grep -C2 -F "Description: $selection" | grep Name | cut -d: -f2 | xargs) if pactl set-default-sink "$device"; then - notify-send -t 2000 -r 2 -u low "Activated: $desc" + notify-send -t 2000 -r 2 -u low "Activated: $selection" else - notify-send -t 2000 -r 2 -u critical "Error activating $desc" + notify-send -t 2000 -r 2 -u critical "Error activating $selection" fi else - pactl list sinks | grep -ie "Description:" | awk -F ': ' '{print $2}' | sort | - while IFS= read -r x; do echo "$x"; done + pactl list sinks | grep -ie "Description:" | awk -F ': ' '{print $2}' | sort fi } -# eval device option - -while getopts iop:s: DeviceOpt; do - case "${DeviceOpt}" in - i) - nsink=$(pamixer --list-sources | awk -F '"' 'END {print $(NF - 1)}') - [ -z "${nsink}" ] && echo "ERROR: Input device not found..." && exit 0 - ctrl="pamixer" - srce="--default-source" - ;; - o) - nsink=$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}') - [ -z "${nsink}" ] && echo "ERROR: Output device not found..." && exit 0 - ctrl="pamixer" - srce="" - ;; - p) - player_name="${OPTARG}" - nsink=$(playerctl --list-all | grep -w "${player_name}") - [ -z "${nsink}" ] && echo "ERROR: Player ${player_name} not active..." && exit 0 - ctrl="playerctl" - srce="${player_name}" - ;; - s) - default_sink="$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}')" - export selected_sink="$(select_output "${@}" | rofi -dmenu -select "${default_sink}" -config "${confDir}/rofi/notification.rasi")" - select_output "$selected_sink" - exit - ;; - *) print_error ;; - esac -done +toggle_output() { + local default_sink=$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}') + mapfile -t sink_array < <(select_output) + local current_index=$(printf '%s\n' "${sink_array[@]}" | grep -n "$default_sink" | cut -d: -f1) + local next_index=$(( (current_index % ${#sink_array[@]}) + 1 )) + local next_sink="${sink_array[next_index-1]}" + select_output "$next_sink" +} -# set default variables +# Main script logic +# Set default variables icodir="${confDir}/dunst/icons/vol" -shift $((OPTIND - 1)) -step="${2:-5}" +step=5 + +# Parse options +while getopts "iopst" opt; do + case $opt in + i) device="pamixer"; srce="--default-source"; nsink=$(pamixer --list-sources | awk -F '"' 'END {print $(NF - 1)}') ;; + o) device="pamixer"; srce=""; nsink=$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}') ;; + p) device="playerctl"; srce="$OPTARG"; nsink=$(playerctl --list-all | grep -w "$srce") ;; + s) select_output "$(select_output | rofi -dmenu -config "${confDir}/rofi/notification.rasi")"; exit ;; + t) toggle_output; exit ;; + *) print_usage ;; + esac +done -# execute action +shift $((OPTIND-1)) -case "${1}" in -i) action_${ctrl} i ;; -d) action_${ctrl} d ;; -m) "${ctrl}" "${srce}" -t && notify_mute && exit 0 ;; -*) print_error ;; -esac +# Check if device is set +[ -z "$device" ] && print_usage -notify_vol +# Execute action +case $1 in + i|d) change_volume "$1" "${2:-$step}" "$device" ;; + m) toggle_mute "$device" ;; + *) print_usage ;; +esac From f98322bba1111f208fa28f6c098731eef9a188d2 Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 05:58:58 +0000 Subject: [PATCH 02/15] Use the toggle output I found from discord --- Configs/.local/share/bin/volumecontrol.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 3e363fd05d..4181ef9e1a 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -16,17 +16,17 @@ print_usage() { cat < [step] -Devices: +Devices/Actions: -i Input device -o Output device -p Player application + -s Select output device + -t Toggle to next output device Actions: i Increase volume d Decrease volume m Toggle mute - s Select output device - t Toggle to next output device Optional: step Volume change step (default: 5) @@ -145,5 +145,6 @@ shift $((OPTIND-1)) case $1 in i|d) change_volume "$1" "${2:-$step}" "$device" ;; m) toggle_mute "$device" ;; + *) print_usage ;; esac From 1654e79fc5d6b7040e0fd963b38ab45d1f692fb3 Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 06:11:23 +0000 Subject: [PATCH 03/15] Added the exec on the userprefs.t2 --- Configs/.config/hypr/userprefs.t2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Configs/.config/hypr/userprefs.t2 b/Configs/.config/hypr/userprefs.t2 index 780362bd9d..ba1fac5dca 100644 --- a/Configs/.config/hypr/userprefs.t2 +++ b/Configs/.config/hypr/userprefs.t2 @@ -22,7 +22,8 @@ bind = $mainMod+Shift, G, exec, pkill -x rofi || $scrPath/gamelauncher.sh # laun # exec-once = swayidle -w timeout 600 'swaylock' timeout 900 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' # lock after 10 mins, sleep after 15 mins // install swayidle # exec-once = swayidle -w timeout 1200 'swaylock; hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' timeout 1800 'systemctl suspend' # lock and sleep after 20 mins, suspend after 30 mins // install swayidle # exec-once = libinput-gestures // install libinput-gestures - +exec-once = swayosd-server # enable swayosd service +exec-once = pkexec swayosd-libinput-backend # swayosd service for keyboard input # █░█░█ █ █▄░█ █▀▄ █▀█ █░█░█   █▀█ █░█ █░░ █▀▀ █▀ # ▀▄▀▄▀ █ █░▀█ █▄▀ █▄█ ▀▄▀▄▀   █▀▄ █▄█ █▄▄ ██▄ ▄█ From acf2e06a6f5e5f6ef6caa13a610ed2c1acb8bed4 Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 06:11:41 +0000 Subject: [PATCH 04/15] Added the exec on the userprefs.t2 --- Configs/.config/hypr/userprefs.t2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Configs/.config/hypr/userprefs.t2 b/Configs/.config/hypr/userprefs.t2 index ba1fac5dca..6d48282e58 100644 --- a/Configs/.config/hypr/userprefs.t2 +++ b/Configs/.config/hypr/userprefs.t2 @@ -22,8 +22,8 @@ bind = $mainMod+Shift, G, exec, pkill -x rofi || $scrPath/gamelauncher.sh # laun # exec-once = swayidle -w timeout 600 'swaylock' timeout 900 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' # lock after 10 mins, sleep after 15 mins // install swayidle # exec-once = swayidle -w timeout 1200 'swaylock; hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' timeout 1800 'systemctl suspend' # lock and sleep after 20 mins, suspend after 30 mins // install swayidle # exec-once = libinput-gestures // install libinput-gestures -exec-once = swayosd-server # enable swayosd service -exec-once = pkexec swayosd-libinput-backend # swayosd service for keyboard input +# exec-once = swayosd-server # enable swayosd service +# exec-once = pkexec swayosd-libinput-backend # swayosd service for keyboard input # █░█░█ █ █▄░█ █▀▄ █▀█ █░█░█   █▀█ █░█ █░░ █▀▀ █▀ # ▀▄▀▄▀ █ █░▀█ █▄▀ █▄█ ▀▄▀▄▀   █▀▄ █▄█ █▄▄ ██▄ ▄█ From a63c4cf3709ba7c1faea1319ce95085544e5459b Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 08:00:29 +0000 Subject: [PATCH 05/15] fix volume input and output --- Configs/.local/share/bin/volumecontrol.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 4181ef9e1a..20a37b5884 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -60,15 +60,13 @@ change_volume() { local action=$1 local step=$2 local device=$3 - case $device in "pamixer") - $use_swayosd && swayosd-client --output-volume $(sed 's/i/raise/;s/d/lower/' <<< "$action") "$step" && exit 0 + $use_swayosd && swayosd-client "$(sed 's/--default-source/--input-volume/;s/^$/--output-volume/' <<< "${srce:-}")" "$(sed 's/i/+/;s/d/-/' <<< "${action}${step}")" && exit 0 pamixer $srce -"$action" "$step" vol=$(pamixer $srce --get-volume) ;; "playerctl") - $use_swayosd && swayosd-client --input-volume $(sed 's/i/raise/;s/d/lower/' <<< "$action") "$step" && exit 0 [ "$action" == "i" ] && delta="+" || delta="-" playerctl --player="$srce" volume "0.0${step}${delta}" vol=$(playerctl --player="$srce" volume | awk '{ printf "%.0f\n", $0 * 100 }') @@ -80,15 +78,13 @@ change_volume() { toggle_mute() { local device=$1 - case $device in - "pamixer") - $use_swayosd && swayosd-client --input-volume mute-toggle && exit 0 + "pamixer") + $use_swayosd && swayosd-client $(sed 's/--default-source/--input-volume/;s/^$/--output-volume/' <<< "${srce:-}") mute-toggle && exit 0 pamixer $srce -t notify_mute ;; "playerctl") - $use_swayosd && swayosd-client --output-volume mute-toggle && exit 0 playerctl --player="$srce" volume 0 notify_mute ;; @@ -123,7 +119,6 @@ toggle_output() { # Set default variables icodir="${confDir}/dunst/icons/vol" step=5 - # Parse options while getopts "iopst" opt; do case $opt in From 16f7a35dbf9364cba1aaf269d0df6313bfe34f06 Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 08:51:14 +0000 Subject: [PATCH 06/15] fix volume --- Configs/.local/share/bin/brightnesscontrol.sh | 46 +++++++++++-------- Configs/.local/share/bin/volumecontrol.sh | 8 ++-- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Configs/.local/share/bin/brightnesscontrol.sh b/Configs/.local/share/bin/brightnesscontrol.sh index 6d4730451f..06eea44b3a 100755 --- a/Configs/.local/share/bin/brightnesscontrol.sh +++ b/Configs/.local/share/bin/brightnesscontrol.sh @@ -1,5 +1,8 @@ #!/usr/bin/env sh +# Check if the script is already running +pgrep -cf "${0##*/}" | grep -qv 1 && exit 1 + scrDir=`dirname "$(realpath "$0")"` source $scrDir/globalcontrol.sh @@ -11,11 +14,15 @@ fi function print_error { -cat << "EOF" - ./brightnesscontrol.sh +cat << EOF + $(basename ${0}) [step] ...valid actions are... i -- ncrease brightness [+5%] d -- ecrease brightness [-5%] + + Example: + $(basename ${0}) i 10 # Increase brightness by 10% + $(basename ${0}) d # Decrease brightness by default step (5%) EOF } @@ -32,31 +39,34 @@ function get_brightness { brightnessctl -m | grep -o '[0-9]\+%' | head -c-2 } +step="${2:-5}" + case $1 in -i) # increase the backlight - $use_swayosd && swayosd-client --brightness raise "$step" && exit 0 +i|-i) # increase the backlight if [[ $(get_brightness) -lt 10 ]] ; then # increase the backlight by 1% if less than 10% - brightnessctl set +1% - else - # increase the backlight by 5% otherwise - brightnessctl set +5% + step=1 fi + + $use_swayosd && swayosd-client --brightness raise "$step" && exit 0 + brightnessctl set +${step}% send_notification ;; -d) # decrease the backlight - $use_swayosd && swayosd-client --brightness lower "$step" && exit 0 - if [[ $(get_brightness) -le 1 ]] ; then - # avoid 0% brightness - brightnessctl set 1% - elif [[ $(get_brightness) -le 10 ]] ; then +d|-d) # decrease the backlight + + if [[ $(get_brightness) -le 10 ]] ; then # decrease the backlight by 1% if less than 10% - brightnessctl set 1%- + step=1 + fi + + if [[ $(get_brightness) -le 1 ]]; then + $use_swayosd && exit 0 + brightnessctl set ${step}% else - # decrease the backlight by 5% otherwise - brightnessctl set 5%- + $use_swayosd && swayosd-client --brightness lower "$step" && exit 0 + brightnessctl set ${step}%- fi + send_notification ;; *) # print error print_error ;; esac - diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 20a37b5884..a920870e4a 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -14,7 +14,7 @@ fi print_usage() { cat < [step] +Usage: $(basename ${0}) -[device] [step] Devices/Actions: -i Input device @@ -32,9 +32,9 @@ Optional: step Volume change step (default: 5) Examples: - ./volumecontrol.sh -o i 5 # Increase output volume by 5 - ./volumecontrol.sh -i m # Toggle input mute - ./volumecontrol.sh -p spotify d 10 # Decrease Spotify volume by 10 + $(basename ${0}) -o i 5 # Increase output volume by 5 + $(basename ${0}) -i m # Toggle input mute + $(basename ${0}) -p spotify d 10 # Decrease Spotify volume by 10 EOF exit 1 } From 8895fb9a3dad0d6879e7a719aee6777e53da31bf Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 10:00:31 +0000 Subject: [PATCH 07/15] fix player selection --- Configs/.local/share/bin/volumecontrol.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index a920870e4a..5a80786f03 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -34,7 +34,9 @@ Optional: Examples: $(basename ${0}) -o i 5 # Increase output volume by 5 $(basename ${0}) -i m # Toggle input mute - $(basename ${0}) -p spotify d 10 # Decrease Spotify volume by 10 + $(basename ${0}) -p spotify d 10 # Decrease Spotify volume by 10 + $(basename ${0}) -p '' d 10 # Decrease volume by 10 for all players + EOF exit 1 } @@ -120,11 +122,11 @@ toggle_output() { icodir="${confDir}/dunst/icons/vol" step=5 # Parse options -while getopts "iopst" opt; do +while getopts "iop:st" opt; do case $opt in i) device="pamixer"; srce="--default-source"; nsink=$(pamixer --list-sources | awk -F '"' 'END {print $(NF - 1)}') ;; o) device="pamixer"; srce=""; nsink=$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}') ;; - p) device="playerctl"; srce="$OPTARG"; nsink=$(playerctl --list-all | grep -w "$srce") ;; + p) device="playerctl"; srce="${OPTARG}"; nsink=$(playerctl --list-all | grep -w "$srce") ;; s) select_output "$(select_output | rofi -dmenu -config "${confDir}/rofi/notification.rasi")"; exit ;; t) toggle_output; exit ;; *) print_usage ;; From bff4e3c733edd81145fb0ed2f5eb83c395283a8b Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 10:58:13 +0000 Subject: [PATCH 08/15] clean up --- Configs/.local/share/bin/volumecontrol.sh | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 5a80786f03..73c5d936ce 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -6,7 +6,7 @@ source "$scrDir/globalcontrol.sh" # Check if SwayOSD is installed use_swayosd=false -if command -v swayosd-client &> /dev/null && pgrep -x swayosd-server > /dev/null; then +if command -v swayosd-client >/dev/null 2>&1 && pgrep -x swayosd-server >/dev/null; then use_swayosd=true fi @@ -14,14 +14,14 @@ fi print_usage() { cat < [step] +Usage: $(basename "$0") -[device] [step] Devices/Actions: -i Input device -o Output device -p Player application - -s Select output device - -t Toggle to next output device + -s Select output device + -t Toggle to next output device Actions: i Increase volume @@ -32,17 +32,17 @@ Optional: step Volume change step (default: 5) Examples: - $(basename ${0}) -o i 5 # Increase output volume by 5 - $(basename ${0}) -i m # Toggle input mute - $(basename ${0}) -p spotify d 10 # Decrease Spotify volume by 10 - $(basename ${0}) -p '' d 10 # Decrease volume by 10 for all players + $(basename "$0") -o i 5 # Increase output volume by 5 + $(basename "$0") -i m # Toggle input mute + $(basename "$0") -p spotify d 10 # Decrease Spotify volume by 10 + $(basename "$0") -p '' d 10 # Decrease volume by 10 for all players EOF exit 1 } notify_vol() { - angle="$(((($vol + 2) / 5) * 5))" + angle=$(( (($vol + 2) / 5) * 5 )) ico="${icodir}/vol-${angle}.svg" bar=$(seq -s "." $(($vol / 15)) | sed 's/[0-9]//g') notify-send -a "t2" -r 91190 -t 800 -i "${ico}" "${vol}${bar}" "${nsink}" @@ -62,15 +62,19 @@ change_volume() { local action=$1 local step=$2 local device=$3 + local delta="-" + local mode="--output-volume" + + [ "${action}" = "i" ] && delta="+" + [ "${srce}" = "--default-source" ] && mode="--input-volume" case $device in "pamixer") - $use_swayosd && swayosd-client "$(sed 's/--default-source/--input-volume/;s/^$/--output-volume/' <<< "${srce:-}")" "$(sed 's/i/+/;s/d/-/' <<< "${action}${step}")" && exit 0 + $use_swayosd && swayosd-client ${mode} "${delta}${step}" && exit 0 pamixer $srce -"$action" "$step" vol=$(pamixer $srce --get-volume) ;; "playerctl") - [ "$action" == "i" ] && delta="+" || delta="-" - playerctl --player="$srce" volume "0.0${step}${delta}" + playerctl --player="$srce" volume "$(awk -v step="$step" 'BEGIN {print step/100}')${delta}" vol=$(playerctl --player="$srce" volume | awk '{ printf "%.0f\n", $0 * 100 }') ;; esac @@ -80,9 +84,11 @@ change_volume() { toggle_mute() { local device=$1 + local mode="--output-volume" + [ "${srce}" = "--default-source" ] && mode="--input-volume" case $device in "pamixer") - $use_swayosd && swayosd-client $(sed 's/--default-source/--input-volume/;s/^$/--output-volume/' <<< "${srce:-}") mute-toggle && exit 0 + $use_swayosd && swayosd-client "${mode}" mute-toggle && exit 0 pamixer $srce -t notify_mute ;; @@ -142,6 +148,5 @@ shift $((OPTIND-1)) case $1 in i|d) change_volume "$1" "${2:-$step}" "$device" ;; m) toggle_mute "$device" ;; - *) print_usage ;; esac From 69d77c441d3f0ae4350b6bddf2bc7797787a7e07 Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 13:18:35 +0000 Subject: [PATCH 09/15] fix the mute toggle or playerctl using a temp file This issue is from the old volume script --- Configs/.local/share/bin/volumecontrol.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Configs/.local/share/bin/volumecontrol.sh b/Configs/.local/share/bin/volumecontrol.sh index 73c5d936ce..b4f6697e60 100755 --- a/Configs/.local/share/bin/volumecontrol.sh +++ b/Configs/.local/share/bin/volumecontrol.sh @@ -93,7 +93,18 @@ toggle_mute() { notify_mute ;; "playerctl") - playerctl --player="$srce" volume 0 + local volume_file="/tmp/$(basename "$0")_last_volume_${srce:-all}" + if [ "$(playerctl --player="$srce" volume | awk '{ printf "%.2f", $0 }')" != "0.00" ]; then + playerctl --player="$srce" volume | awk '{ printf "%.2f", $0 }' > "$volume_file" + playerctl --player="$srce" volume 0 + else + if [ -f "$volume_file" ]; then + last_volume=$(cat "$volume_file") + playerctl --player="$srce" volume "$last_volume" + else + playerctl --player="$srce" volume 0.5 # Default to 50% if no saved volume + fi + fi notify_mute ;; esac From bee6695e0625b7023f7a60be2f1f455dca70333c Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 16:26:58 +0000 Subject: [PATCH 10/15] functions on sh --- Configs/.local/share/bin/brightnesscontrol.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Configs/.local/share/bin/brightnesscontrol.sh b/Configs/.local/share/bin/brightnesscontrol.sh index 06eea44b3a..c74f2f1267 100755 --- a/Configs/.local/share/bin/brightnesscontrol.sh +++ b/Configs/.local/share/bin/brightnesscontrol.sh @@ -8,11 +8,11 @@ source $scrDir/globalcontrol.sh # Check if SwayOSD is installed use_swayosd=false -if command -v swayosd-client &> /dev/null && pgrep -x swayosd-server > /dev/null; then +if command -v swayosd-client >/dev/null 2>&1 && pgrep -x swayosd-server >/dev/null; then use_swayosd=true fi -function print_error +print_error() { cat << EOF $(basename ${0}) [step] @@ -26,7 +26,7 @@ cat << EOF EOF } -function send_notification { +send_notification() { brightness=`brightnessctl info | grep -oP "(?<=\()\d+(?=%)" | cat` brightinfo=$(brightnessctl info | awk -F "'" '/Device/ {print $2}') angle="$(((($brightness + 2) / 5) * 5))" @@ -35,7 +35,7 @@ function send_notification { notify-send -a "t2" -r 91190 -t 800 -i "${ico}" "${brightness}${bar}" "${brightinfo}" } -function get_brightness { +get_brightness() { brightnessctl -m | grep -o '[0-9]\+%' | head -c-2 } @@ -59,8 +59,8 @@ d|-d) # decrease the backlight fi if [[ $(get_brightness) -le 1 ]]; then - $use_swayosd && exit 0 brightnessctl set ${step}% + $use_swayosd && exit 0 else $use_swayosd && swayosd-client --brightness lower "$step" && exit 0 brightnessctl set ${step}%- From d0d853e8c4452991105ee419002c129cad5f44fc Mon Sep 17 00:00:00 2001 From: keth-real Date: Fri, 13 Sep 2024 16:34:09 +0000 Subject: [PATCH 11/15] err msg --- Configs/.local/share/bin/brightnesscontrol.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configs/.local/share/bin/brightnesscontrol.sh b/Configs/.local/share/bin/brightnesscontrol.sh index c74f2f1267..c7726e5667 100755 --- a/Configs/.local/share/bin/brightnesscontrol.sh +++ b/Configs/.local/share/bin/brightnesscontrol.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Check if the script is already running -pgrep -cf "${0##*/}" | grep -qv 1 && exit 1 +pgrep -cf "${0##*/}" | grep -qv 1 && echo "An instance of the script is already running..." && exit 1 scrDir=`dirname "$(realpath "$0")"` source $scrDir/globalcontrol.sh From b5439ce5b60a96a48c8e05c0af8c71f57c878978 Mon Sep 17 00:00:00 2001 From: Khing <53417443+kRHYME7@users.noreply.github.com> Date: Sat, 14 Sep 2024 01:47:02 +0800 Subject: [PATCH 12/15] Update userprefs.t2 --- Configs/.config/hypr/userprefs.t2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configs/.config/hypr/userprefs.t2 b/Configs/.config/hypr/userprefs.t2 index 6d48282e58..34fd3145b0 100644 --- a/Configs/.config/hypr/userprefs.t2 +++ b/Configs/.config/hypr/userprefs.t2 @@ -23,7 +23,7 @@ bind = $mainMod+Shift, G, exec, pkill -x rofi || $scrPath/gamelauncher.sh # laun # exec-once = swayidle -w timeout 1200 'swaylock; hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' timeout 1800 'systemctl suspend' # lock and sleep after 20 mins, suspend after 30 mins // install swayidle # exec-once = libinput-gestures // install libinput-gestures # exec-once = swayosd-server # enable swayosd service -# exec-once = pkexec swayosd-libinput-backend # swayosd service for keyboard input +# exec-once = pkexec swayosd-libinput-backend | - # swayosd service for keyboard input. Need to add the '| -' for now so the daemon won't exit # █░█░█ █ █▄░█ █▀▄ █▀█ █░█░█   █▀█ █░█ █░░ █▀▀ █▀ # ▀▄▀▄▀ █ █░▀█ █▄▀ █▄█ ▀▄▀▄▀   █▀▄ █▄█ █▄▄ ██▄ ▄█ From 6b3dac6c096ad53a2976de8ebaf3be4c1d1eef5b Mon Sep 17 00:00:00 2001 From: keth-real Date: Sat, 14 Sep 2024 13:51:47 +0800 Subject: [PATCH 13/15] Update userprefs.t2 --- Configs/.config/hypr/userprefs.t2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configs/.config/hypr/userprefs.t2 b/Configs/.config/hypr/userprefs.t2 index 34fd3145b0..1a6102591f 100644 --- a/Configs/.config/hypr/userprefs.t2 +++ b/Configs/.config/hypr/userprefs.t2 @@ -23,7 +23,7 @@ bind = $mainMod+Shift, G, exec, pkill -x rofi || $scrPath/gamelauncher.sh # laun # exec-once = swayidle -w timeout 1200 'swaylock; hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' timeout 1800 'systemctl suspend' # lock and sleep after 20 mins, suspend after 30 mins // install swayidle # exec-once = libinput-gestures // install libinput-gestures # exec-once = swayosd-server # enable swayosd service -# exec-once = pkexec swayosd-libinput-backend | - # swayosd service for keyboard input. Need to add the '| -' for now so the daemon won't exit +# exec-once = `pkexec swayosd-libinput-backend` # swayosd service for keyboard input (requires to be run in a subshell) # █░█░█ █ █▄░█ █▀▄ █▀█ █░█░█   █▀█ █░█ █░░ █▀▀ █▀ # ▀▄▀▄▀ █ █░▀█ █▄▀ █▄█ ▀▄▀▄▀   █▀▄ █▄█ █▄▄ ██▄ ▄█ From bad8557152e83f0ff63cf088caa964ce6c7e646a Mon Sep 17 00:00:00 2001 From: keth-real Date: Sat, 14 Sep 2024 06:11:17 +0000 Subject: [PATCH 14/15] option to skip wallbash template --- Configs/.local/share/bin/swwwallbash.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Configs/.local/share/bin/swwwallbash.sh b/Configs/.local/share/bin/swwwallbash.sh index b0df1d33e6..278be7875a 100755 --- a/Configs/.local/share/bin/swwwallbash.sh +++ b/Configs/.local/share/bin/swwwallbash.sh @@ -31,8 +31,11 @@ set +a fn_wallbash () { local tplt="${1}" + [ -f "${hydeConfDir}/hyde.conf" ] && source "${hydeConfDir}/hyde.conf" + # Skips the the template declared in ./hyde.conf + [[ " ${skip_wallbash[@]} " =~ " ${tplt} " ]] && echo "[skip: template] ${tplt}" && return 0 eval target="$(head -1 "${tplt}" | awk -F '|' '{print $1}')" - [ ! -d "$(dirname "${target}")" ] && echo "[skip] \"${target}\"" && return 0 + [ ! -d "$(dirname "${target}")" ] && echo "[skip: no dir] \"${target}\"" && return 0 appexe="$(head -1 "${tplt}" | awk -F '|' '{print $2}')" sed '1d' "${tplt}" > "${target}" From 295cc2ef3f8d47f3804edc9a0ab76ab27b363aae Mon Sep 17 00:00:00 2001 From: keth-real Date: Sat, 14 Sep 2024 06:21:15 +0000 Subject: [PATCH 15/15] Revert "option to skip wallbash template" This reverts commit bad8557152e83f0ff63cf088caa964ce6c7e646a. --- Configs/.local/share/bin/swwwallbash.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Configs/.local/share/bin/swwwallbash.sh b/Configs/.local/share/bin/swwwallbash.sh index 278be7875a..b0df1d33e6 100755 --- a/Configs/.local/share/bin/swwwallbash.sh +++ b/Configs/.local/share/bin/swwwallbash.sh @@ -31,11 +31,8 @@ set +a fn_wallbash () { local tplt="${1}" - [ -f "${hydeConfDir}/hyde.conf" ] && source "${hydeConfDir}/hyde.conf" - # Skips the the template declared in ./hyde.conf - [[ " ${skip_wallbash[@]} " =~ " ${tplt} " ]] && echo "[skip: template] ${tplt}" && return 0 eval target="$(head -1 "${tplt}" | awk -F '|' '{print $1}')" - [ ! -d "$(dirname "${target}")" ] && echo "[skip: no dir] \"${target}\"" && return 0 + [ ! -d "$(dirname "${target}")" ] && echo "[skip] \"${target}\"" && return 0 appexe="$(head -1 "${tplt}" | awk -F '|' '{print $2}')" sed '1d' "${tplt}" > "${target}"