diff options
author | Justine Smithies <justine@smithies.me.uk> | 2023-08-22 19:46:15 +0100 |
---|---|---|
committer | Justine Smithies <justine@smithies.me.uk> | 2023-08-22 19:46:15 +0100 |
commit | 6aaea9cf4b283d41016e60735f52c8feb3cd0c9e (patch) | |
tree | ffc170bb7f267247b60908ac9125fcc02175afd9 /.config/qtile/statusbar | |
parent | 86c0c3694c93025dfec23f27266905c12f446a4e (diff) |
Initial commit
Diffstat (limited to '.config/qtile/statusbar')
-rwxr-xr-x | .config/qtile/statusbar/battery.py | 89 | ||||
-rwxr-xr-x | .config/qtile/statusbar/brightnesscontrol | 44 | ||||
-rwxr-xr-x | .config/qtile/statusbar/calendar.sh | 26 | ||||
-rwxr-xr-x | .config/qtile/statusbar/idleinhibit | 32 | ||||
-rwxr-xr-x | .config/qtile/statusbar/network.sh | 45 | ||||
-rwxr-xr-x | .config/qtile/statusbar/void-updates.sh | 13 | ||||
-rwxr-xr-x | .config/qtile/statusbar/volumecontrol | 107 |
7 files changed, 356 insertions, 0 deletions
diff --git a/.config/qtile/statusbar/battery.py b/.config/qtile/statusbar/battery.py new file mode 100755 index 0000000..a4fa33a --- /dev/null +++ b/.config/qtile/statusbar/battery.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 + +import psutil +import argparse +import subprocess + + +def secs2hours(secs): + mm, ss = divmod(secs, 60) + hh, mm = divmod(mm, 60) + return "%d:%02d:%02d" % (hh, mm, ss) + + +parser = argparse.ArgumentParser() +parser.add_argument('--c', + choices=('status', 'left-click', 'middle-click', 'right-click'), + dest='command', + default='status', + help='Allowed values are status, left-click, middle-click and right-click' + ) +args = parser.parse_args() + +battery = psutil.sensors_battery() +icon = "" +percent = int(battery.percent) +time_left = battery.secsleft +isPlugged = battery.power_plugged +remaining = secs2hours(time_left) + +if args.command == "status": + if isPlugged: + if percent == 100: + icon = "" + elif percent > 89 and percent < 100: + icon = "" + elif percent > 79 and percent < 90: + icon = "" + elif percent > 69 and percent < 80: + icon = "" + elif percent > 59 and percent < 70: + icon = "" + elif percent > 49 and percent < 60: + icon = "" + elif percent > 39 and percent < 50: + icon = "" + elif percent > 29 and percent < 40: + icon = "" + elif percent > 19 and percent < 30: + icon = "" + elif percent > 9 and percent < 20: + icon = "" + elif percent > 0 and percent < 10: + icon = "" + message = str(percent) + "%" + print(icon, message, end="") + else: + if percent == 100: + icon = "" + elif percent > 89 and percent < 100: + icon = "" + elif percent > 79 and percent < 90: + icon = "" + elif percent > 69 and percent < 80: + icon = "" + elif percent > 59 and percent < 70: + icon = "" + elif percent > 49 and percent < 60: + icon = "" + elif percent > 39 and percent < 50: + icon = "" + elif percent > 29 and percent < 40: + icon = "" + elif percent > 19 and percent < 30: + icon = "" + elif percent > 9 and percent < 20: + icon = "" + elif percent > 0 and percent < 10: + icon = "" + message = str(percent) + "%" + print(icon, message, end="") +if args.command == "left-click": + if not isPlugged: + subprocess.call(["notify-send", "-r", "55555", "-u", "normal", "Est remaining time left: " + remaining]) + else: + subprocess.call(["notify-send", "-r", "55555", "-u", "normal", str(percent) + "% Charged"]) +if args.command == "middle-click": + print("Middle click") +if args.command == "right-click": + print("Right click") diff --git a/.config/qtile/statusbar/brightnesscontrol b/.config/qtile/statusbar/brightnesscontrol new file mode 100755 index 0000000..304c187 --- /dev/null +++ b/.config/qtile/statusbar/brightnesscontrol @@ -0,0 +1,44 @@ +#!/bin/bash + +# 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 + +function send_notification { + icon=/usr/share/icons/Papirus-Dark/16x16/actions/brightnesssettings.svg + brightness=$(light -G) + brightness=$(echo "$brightness" | awk '{print ($0-int($0)<0.499)?int($0):int($0)+1}') + # 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') + #brightness=$((brightness *100 / 255 )) + #echo $bar + #echo $test + # Send the notification + notify-send -i "$icon" -r 5555 -u normal "$bar $brightness" +} + +case $1 in + up) + # increase the backlight by 5% + light -A 5 + send_notification + canberra-gtk-play -i audio-volume-change + ;; + down) + # decrease the backlight by 5% + light -U 5 + send_notification + canberra-gtk-play -i audio-volume-change + ;; + *) + brightness=$(light -G) + brightness=$(echo "$brightness" | awk '{print ($0-int($0)<0.499)?int($0):int($0)+1}') + icon="" + printf "%s" "$icon $brightness" "%" + ;; +esac diff --git a/.config/qtile/statusbar/calendar.sh b/.config/qtile/statusbar/calendar.sh new file mode 100755 index 0000000..71de700 --- /dev/null +++ b/.config/qtile/statusbar/calendar.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Calendar script + +function ShowCalendar() { + notify-send -i "calendar" " 📅 Calendar" "$(cal --color=always | sed "s/..7m/<b><span color=\"#fabd2f\">/;s/..27m/<\/span><\/b>/")" -r 124 +} + +function EditCalendar() { + echo +} + +case "$1" in + show) + ShowCalendar + ;; + + edit) + EditCalendar + ;; + + *) + echo $"Usage: ${0##*/} {show|edit}" + exit 1 + +esac diff --git a/.config/qtile/statusbar/idleinhibit b/.config/qtile/statusbar/idleinhibit new file mode 100755 index 0000000..7ff61a6 --- /dev/null +++ b/.config/qtile/statusbar/idleinhibit @@ -0,0 +1,32 @@ +#!/bin/bash + +# Qtile swayidle toggle +function toggle { +if pgrep "swayidle" > /dev/null +then + pkill swayidle + notify-send -r 5556 -u normal " Swayidle Inactive" +else + swayidle \ + timeout 5 'qtile cmd-obj -o core -f hide_cursor' resume 'qtile cmd-obj -o core -f unhide_cursor' \ + timeout 300 'swaylock -f -i $wallpaper' \ + timeout 600 'wlopm --off \*' resume 'wlopm --on \*' & + notify-send -r 5556 -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/qtile/statusbar/network.sh b/.config/qtile/statusbar/network.sh new file mode 100755 index 0000000..eb98999 --- /dev/null +++ b/.config/qtile/statusbar/network.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# This script requires dnsutils aka bind to fetch the WAN IP address + +# Shows the connections names +# nmcli connection show --active | grep 'ethernet' | awk '{ print $1 }' FS=' ' +# nmcli connection show --active | grep 'wifi' | awk '{ print $1 }' FS=' ' + +# Show ethernet interface name +# nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' ' + +# Show wifi interface name +# nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' ' + +function ShowInfo { + if [ "$(nmcli connection show --active | grep -oh "\w*ethernet\w*")" == "ethernet" ]; then + wan="$(dig +short myip.opendns.com @resolver1.opendns.com)" + connection="$(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' '): $(nmcli connection show --active | grep 'ethernet' | awk '{ print $1 }' FS=' ') - $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' ') | awk '{print $2}' FS='[:/]') +WAN IP: $wan" + elif [ "$(nmcli connection show --active | grep -oh "\w*wifi\w*")" == "wifi" ]; then + wan="$(dig +short myip.opendns.com @resolver1.opendns.com)" + connection="$(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' '): $(nmcli connection show --active | grep 'wifi' | awk '{ print $1 }' FS=' ') - $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' ') | awk '{print $2}' FS='[:/]') +WAN IP: $wan" + else + connection="No active connection." + fi + notify-send -i "network-idle" "$connection" -r 123 +} + +function IconUpdate() { + if [ "$(nmcli connection show --active | grep -oh "\w*ethernet\w*")" == "ethernet" ]; then + icon=" " + elif [ "$(nmcli connection show --active | grep -oh "\w*wifi\w*")" == "wifi" ]; then + icon=" " + else + icon=" " + fi + printf "%s" "$icon" +} + +if [ "$1" = "ShowInfo" ]; then + ShowInfo +else + IconUpdate +fi diff --git a/.config/qtile/statusbar/void-updates.sh b/.config/qtile/statusbar/void-updates.sh new file mode 100755 index 0000000..94298ae --- /dev/null +++ b/.config/qtile/statusbar/void-updates.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +case $1 in + key-update) + foot bash -c "sudo xbps-install -Suv" + qtile cmd-obj -o widget checkupdates -f force_update + ;; + *) + # Supress error codes to stop issues with CheckUpdates widget + xbps-install -Mun 2> /dev/null + exit 0 + ;; +esac diff --git a/.config/qtile/statusbar/volumecontrol b/.config/qtile/statusbar/volumecontrol new file mode 100755 index 0000000..62c4cc2 --- /dev/null +++ b/.config/qtile/statusbar/volumecontrol @@ -0,0 +1,107 @@ +#!/bin/bash + +# You can call this script like this: +# volumecontrol up +# volumecontrol down +# volumecontrol mute + +function get_volume { + amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1 +} + +function is_mute { + amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null +} + +function 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" = "0" ]; then + icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-muted.png" +notify-send -i "$icon_name" -r 5556 -u normal "$volume" + else + if [ "$volume" -lt "10" ]; then + icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-low.png" +notify-send -i "$icon_name" -r 5556 -u normal "$volume" + else + if [ "$volume" -lt "30" ]; then + icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-low.png" + else + if [ "$volume" -lt "70" ]; then + icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-medium.png" + else + icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-high.png" + fi + fi + fi +fi +bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g') +# Send the notification +notify-send -i "$icon_name" -r 5556 -u normal "$bar $volume" +} + +case $1 in + up) + # Set the volume on (if it was muted) + amixer set Master on > /dev/null + # Up the volume (+ 2%) + amixer sset Master 2%+ > /dev/null + send_notification + canberra-gtk-play -i audio-volume-change + ;; + down) + amixer set Master on > /dev/null + amixer sset Master 2%- > /dev/null + send_notification + canberra-gtk-play -i audio-volume-change + ;; + mute) + # Toggle mute + amixer set Master 1+ toggle > /dev/null + if is_mute ; then + notify-send -i "/usr/share/icons/Adwaita/16x16/legacy/audio-volume-muted.png" -r 5556 -u normal "$bar 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="" + volume=" M " + fi + + +if is_mute; then + icon="" + volume=" M " +fi + +printf "%s" "$icon $volume%" + ;; +esac |