diff options
| author | Justine Smithies <justine@smithies.me.uk> | 2025-06-15 12:38:40 +0100 | 
|---|---|---|
| committer | Justine Smithies <justine@smithies.me.uk> | 2025-06-15 12:38:40 +0100 | 
| commit | b90ad8355b4b71ad328aba0943a62a123fb5b88d (patch) | |
| tree | 58d8bba26b6a2a866af4abe138961adb2c32e9d3 /.config/waybar/scripts | |
| parent | d029adec94282882510be0d4398709a818b880ad (diff) | |
Initial commit for MaomaoWM - Still a WIP
Diffstat (limited to '.config/waybar/scripts')
| -rwxr-xr-x | .config/waybar/scripts/battery.sh | 53 | ||||
| -rwxr-xr-x | .config/waybar/scripts/brightnesscontrol.sh | 40 | ||||
| -rwxr-xr-x | .config/waybar/scripts/calendar.sh | 26 | ||||
| -rwxr-xr-x | .config/waybar/scripts/date-time.sh | 12 | ||||
| -rwxr-xr-x | .config/waybar/scripts/idleinhibit.sh | 28 | ||||
| -rwxr-xr-x | .config/waybar/scripts/swayidle-update.sh | 7 | ||||
| -rwxr-xr-x | .config/waybar/scripts/volumecontrol.sh | 130 | 
7 files changed, 296 insertions, 0 deletions
diff --git a/.config/waybar/scripts/battery.sh b/.config/waybar/scripts/battery.sh new file mode 100755 index 0000000..73fe1cd --- /dev/null +++ b/.config/waybar/scripts/battery.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# Send a notification if battery is low, change status in info file accordingly +notify_low () { + +  # Battery isn't much but is charging (don't notify) +  [ "$status" = "on-line" ] && return + +  # Battery critically low +  if [ "$capacity" -le 10 ] && ! grep -q critically-low "$lowinfo"; then +    notify-send -i "$HOME/.config/icons/critical-battery.png" -u critical "Battery critically low!"  +    echo critically-low >"$lowinfo" + +  # Battery is low  +  elif [ "$capacity" -le 20 ] && ! grep -q low "$lowinfo"; then +    notify-send -i "$HOME/.config/icons/low-battery.png" -t 5500 "Battery low!" +    echo low >"$lowinfo" +  fi +} + +status="$(apm | grep -E "AC Line status:" | sed -n -e 's/^.*AC Line status: //p')" +capacity="$(apm | grep -E "Remaining battery life:" | head -1 | sed -n -e 's/^.*Remaining battery life: //p' | sed 's/.$//')" + +# Get the low battery status from file ~/.cache/battery-low-status +lowinfo="$HOME/.cache/battery-low-status" +[ ! -e "$lowinfo" ] && touch "$lowinfo" + + +case $1 in +  left-click) +    ;; +  *) +    # Set charging icon and capacity icon +    [ "$status" = "on-line" ] && charging_icon="" || charging_icon="" +    [ "$capacity" -gt 100 ] && capacity=100 +    if   [ "$capacity" -lt 15 ]; then capacity_icon='  '  +    elif [ "$capacity" -lt 40 ]; then capacity_icon='  ' +    elif [ "$capacity" -lt 60 ]; then capacity_icon='  '  +    elif [ "$capacity" -lt 90 ]; then capacity_icon='  ' +    else capacity_icon='  '  +    fi + +    # Report low battery                                          +    [ "$capacity" -le 20 ] && notify_low + +    # Reset low battery information in these cases +    { [ "$capacity" -gt 20 ] || [ "$status" = "Charging" ]; } && [ -n "$(cat "$lowinfo")" ] && echo "" >"$lowinfo" + +    text=$capacity +    alt=" "$charging_icon +    echo "{\"text\": \"$text"\", \"alt\": \"$alt"\", \"tooltip\":\"$tooltip\", \"class\": \"$class\", \"percentage\":"$capacity"}" +    ;; +esac diff --git a/.config/waybar/scripts/brightnesscontrol.sh b/.config/waybar/scripts/brightnesscontrol.sh new file mode 100755 index 0000000..a59e410 --- /dev/null +++ b/.config/waybar/scripts/brightnesscontrol.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# You can call this script like this: +# brightnessControl up +# brightnessControl down + +# Script inspired by these wonderful people: +# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh +# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a + +send_notification() { +  icon="/usr/share/icons/Adwaita/symbolic/status/daytime-sunrise-symbolic.svg" +  brightness=$(backlight -q) +  # Make the bar with the special character ─ (it's not dash -) +  # https://en.wikipedia.org/wiki/Box-drawing_character +  bar=$(seq -s "─" 0 $((brightness / 10 )) | sed 's/[0-9]//g') +  # Send the notification +  fyi -i "$icon" --hint=string:x-canonical-private-synchronous:brightness -u normal "$bar  $brightness" +} + +case $1 in +  up) +    backlight + 4 +    backlight > ~/.cache/brightness +    send_notification +    # canberra-gtk-play -i audio-volume-change +    ;; +  down) +    backlight - 4 +    backlight > ~/.cache/brightness +    send_notification +    # canberra-gtk-play -i audio-volume-change +    ;; +  *) +    text=$(backlight -q) +    icon="" +    # printf "%s" "$icon $brightness" "%" +    echo "{\"text\":\""$text"\", \"tooltip\":\""$tooltip"\"}" +    ;; +esac diff --git a/.config/waybar/scripts/calendar.sh b/.config/waybar/scripts/calendar.sh new file mode 100755 index 0000000..82ddd92 --- /dev/null +++ b/.config/waybar/scripts/calendar.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Calendar script + +ShowCalendar() { +	fyi -a "Calendar" --hint string:x-canonical-private-synchronous:calendar "     📅 Calendar" "$(cal | sed "s/\<$(date +%-d)\>/<span color='#fabd2f'><b>$(date +%-d)<\/b><\/span>/")" +} + +EditCalendar() { +  echo  +} + +case "$1" in +        show) +            ShowCalendar +            ;; +          +        edit) +            EditCalendar +            ;; +          +        *) +            echo $"Usage: ${0##*/} {show|edit}" +            exit 1 +  +esac diff --git a/.config/waybar/scripts/date-time.sh b/.config/waybar/scripts/date-time.sh new file mode 100755 index 0000000..6ce5e30 --- /dev/null +++ b/.config/waybar/scripts/date-time.sh @@ -0,0 +1,12 @@ +#!/bin/sh +DaySuffix() { +  case `date +%-d` in +    1|21|31) echo "st";; +    2|22)    echo "nd";; +    3|23)    echo "rd";; +    *)       echo "th";; +  esac +} +text=$(date "+%A %-d`DaySuffix` %B %Y - %H:%M ") + +echo "{\"text\":\""$text"\", \"tooltip\":\""$tooltip"\"}" diff --git a/.config/waybar/scripts/idleinhibit.sh b/.config/waybar/scripts/idleinhibit.sh new file mode 100755 index 0000000..c24f715 --- /dev/null +++ b/.config/waybar/scripts/idleinhibit.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# Swayidle toggle +toggle() { +	if pgrep "swayidle" > /dev/null +	then +					pkill swayidle +					notify-send --hint=string:x-canonical-private-synchronous:idleinhibit -u normal "   Swayidle Inactive" +  else +	        sh "$HOME/.config/river/scripts/swayidle-update.sh" +	        notify-send --hint=string:x-canonical-private-synchronous:idleinhibit -u normal "  Swayidle Active" +  fi +} + +case $1 in +	toggle) +		toggle +		;; +	*) +		if pgrep "swayidle" > /dev/null +		then +			icon="" +		else +			icon="" +		fi +		printf "%s" "$icon " +		;; +esac diff --git a/.config/waybar/scripts/swayidle-update.sh b/.config/waybar/scripts/swayidle-update.sh new file mode 100755 index 0000000..f451b38 --- /dev/null +++ b/.config/waybar/scripts/swayidle-update.sh @@ -0,0 +1,7 @@ +#!/bin/sh +pkill -f swayidle +read -r wallpaper<"$HOME/.cache/wallpaper"  +swayidle -w \ +  timeout 300 "swaylock -f -i $wallpaper" \ +  timeout 600 "wlopm --off \*;swaylock -F -i $wallpaper" resume "wlopm --on \*" \ +  before-sleep "swaylock -f -i $wallpaper" & diff --git a/.config/waybar/scripts/volumecontrol.sh b/.config/waybar/scripts/volumecontrol.sh new file mode 100755 index 0000000..3359046 --- /dev/null +++ b/.config/waybar/scripts/volumecontrol.sh @@ -0,0 +1,130 @@ +#!/bin/sh  + +# You can call this script like this: +# volumecontrol up +# volumecontrol down +# volumecontrol mute + +get_volume() { +    # pactl get-sink-volume @DEFAULT_SINK@ | grep '%' | cut -d '%' -f 1 | cut -d ' ' -f 6 +    echo "scale=1; $(mixer vol | grep 'vol.volume=' | cut -d '=' -f 2 | cut -d ':' -f 1)*100" | bc | cut -d '.' -f 1 +} + +is_mute() { +    # pactl get-sink-mute @DEFAULT_SINK@ | grep 'Mute: yes' >> /dev/null +    mixer vol | grep 'vol.mute=on' >> /dev/null +} + +send_notification() { +	volume=$(get_volume) +    # Make the bar with the special character ─ (it's not dash -) +    # https://en.wikipedia.org/wiki/Box-drawing_character +	if [ "$volume" = "100" ]; then +		icon="" +	elif [ "$volume" -ge "89" ] && [ "$volume" -le "100" ]; then +		icon="" +	elif [ "$volume" -ge "79" ] && [ "$volume" -le "90" ]; then +		icon="" +	elif [ "$volume" -ge "69" ] && [ "$volume" -le "80" ]; then +		icon="" +	elif [ "$volume" -ge "59" ] && [ "$volume" -le "70" ]; then +		icon="" +	elif [ "$volume" -ge "49" ] && [ "$volume" -le "60" ]; then +		icon="" +	elif [ "$volume" -ge "39" ] && [ "$volume" -le "50" ]; then +		icon="" +	elif [ "$volume" -ge "29" ] && [ "$volume" -le "40" ]; then +		icon="" +	elif [ "$volume" -ge "19" ] && [ "$volume" -le "30" ]; then +		icon="" +	elif [ "$volume" -ge "9" ] && [ "$volume" -le "20" ]; then +		icon="" +	elif [ "$volume" -gt "0" ] && [ "$volume" -le "10" ]; then +		icon="" +	elif [ "$volume" -eq "0" ]; then +		icon="" +		class="muted" +	fi +bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g') +# Send the notification +fyi --hint=string:x-canonical-private-synchronous:volumecontrol -u normal "$icon  $bar  $volume" +} + +case $1 in +    up) +	# pactl set-sink-mute @DEFAULT_SINK@ 0 +	mixer vol.mute=off +	# Up the volume (+ 2%) +	# pactl set-sink-volume @DEFAULT_SINK@ +2% +	mixer vol.volume=+2% +	mixer vol > ~/.cache/audio-volume +	send_notification +	# canberra-gtk-play -i audio-volume-change +	;; +    down) +	# pactl set-sink-mute @DEFAULT_SINK@ 0 +	mixer vol.mute=off +	# pactl set-sink-volume @DEFAULT_SINK@ -2% +	mixer vol.volume=-2% +	mixer vol > ~/.cache/audio-volume +	send_notification +	# canberra-gtk-play -i audio-volume-change +	;; +    mute) +    	# Toggle mute +	# pactl set-sink-mute @DEFAULT_SINK@ toggle +	mixer vol.mute=toggle +	mixer vol > ~/.cache/audio-volume +	if is_mute ; then +    icon="" +    class="muted" +    text="<span color='#202020' bgcolor='#ff00aa' > $icon </span> $volume" +    fyi --hint=string:x-canonical-private-synchronous:volumecontrol -u normal "$icon  Audio Muted" +	else +	   send_notification +	   # canberra-gtk-play -i audio-volume-change +	fi +	;; +    *) +	volume="$(get_volume)" + +	if [ "$volume" = "100" ]; then +		icon="" +	elif [ "$volume" -ge "89" ] && [ "$volume" -le "100" ]; then +		icon="" +	elif [ "$volume" -ge "79" ] && [ "$volume" -le "90" ]; then +		icon="" +	elif [ "$volume" -ge "69" ] && [ "$volume" -le "80" ]; then +		icon="" +	elif [ "$volume" -ge "59" ] && [ "$volume" -le "70" ]; then +		icon="" +	elif [ "$volume" -ge "49" ] && [ "$volume" -le "60" ]; then +		icon="" +	elif [ "$volume" -ge "39" ] && [ "$volume" -le "50" ]; then +		icon="" +	elif [ "$volume" -ge "29" ] && [ "$volume" -le "40" ]; then +		icon="" +	elif [ "$volume" -ge "19" ] && [ "$volume" -le "30" ]; then +		icon="" +	elif [ "$volume" -ge "9" ] && [ "$volume" -le "20" ]; then +		icon="" +	elif [ "$volume" -gt "0" ] && [ "$volume" -le "10" ]; then +		icon="" +	elif [ "$volume" -eq "0" ]; then +		icon="" +    class="muted" +	fi + + +if is_mute || [ "$class" = 'muted' ]; then +		icon="" +    class="muted" +    text="<span color='#202020' bgcolor='#cc241d' > $icon  </span> $volume" +  else +    text="<span color='#202020' bgcolor='#d65d0e' > $icon  </span> $volume" +fi + +alt=$icon +echo "{\"text\": \"$text"\", \"alt\": \"$alt"\", \"tooltip\":\"$tooltip\", \"class\": \"$class\", \"percentage\":"$volume"}" +  ;; +esac  | 
