summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-08-22 10:25:56 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-08-22 10:25:56 +0300
commitd6a8b96322f46e22b81cad00241f45450cfb73a0 (patch)
treed049bf4f57962319a62d421a281917f3517910fa
parentb7c5168e977b38cd360f9894200cc26f282aba30 (diff)
downloaddotfiles-d6a8b96322f46e22b81cad00241f45450cfb73a0.tar
dotfiles-d6a8b96322f46e22b81cad00241f45450cfb73a0.tar.gz
dotfiles-d6a8b96322f46e22b81cad00241f45450cfb73a0.zip
Updated battery notifications functionality
-rw-r--r--.config/dunst/dunstrc2
-rw-r--r--.config/tint2/tint2rc10
-rwxr-xr-xbattery-status.sh26
3 files changed, 26 insertions, 12 deletions
diff --git a/.config/dunst/dunstrc b/.config/dunst/dunstrc
index c72c1a2..5411a22 100644
--- a/.config/dunst/dunstrc
+++ b/.config/dunst/dunstrc
@@ -343,7 +343,7 @@
[urgency_critical]
background = "#c35b5b"
foreground = "#ffffff"
- timeout = 30
+ timeout = 120
# Icon for notifications with critical urgency, uncomment to enable
#icon = /path/to/icon
diff --git a/.config/tint2/tint2rc b/.config/tint2/tint2rc
index 1869b54..4e452e4 100644
--- a/.config/tint2/tint2rc
+++ b/.config/tint2/tint2rc
@@ -1,4 +1,4 @@
-#---- Generated by tint2conf 512e ----
+#---- Generated by tint2conf c756 ----
# See https://gitlab.com/o9000/tint2/wikis/Configure for
# full documentation of the configuration options.
#-------------------------------------
@@ -182,8 +182,8 @@ clock_dwheel_command =
#-------------------------------------
# Battery
battery_tooltip = 1
-battery_low_status = 10
-battery_low_cmd = notify-send -u critical -i battery-low 'Battery low!'
+battery_low_status = 0
+battery_low_cmd =
battery_full_cmd =
bat1_font = sans 10
bat2_font = sans 6
@@ -198,8 +198,8 @@ battery_rclick_command =
battery_mclick_command =
battery_uwheel_command =
battery_dwheel_command =
-ac_connected_cmd =
-ac_disconnected_cmd =
+ac_connected_cmd = notify-send -u low -i ac-adapter 'AC Connected'
+ac_disconnected_cmd = notify-send -u low -i battery 'AC Disconnected'
#-------------------------------------
# Separator 1
diff --git a/battery-status.sh b/battery-status.sh
index d796568..990036e 100755
--- a/battery-status.sh
+++ b/battery-status.sh
@@ -1,26 +1,36 @@
#!/bin/bash
battery_notify () {
+ # if battery percentage is equal to given one, if battery percentage inside /tmp/battery.tmp is not equal to given one and if power indicator is the given on
if [ ${__bat_per} -eq $1 ] && ! grep -q $1 "/tmp/battery.tmp" && [[ ${__bat_power} = $2 ]]; then
- notify-send -u critical -i battery-low "$3"
- echo $1 >> /tmp/battery.tmp
+ # Send notification and rewrite battery.tmp file with current percentage
+ notify-send -u critical -i battery-low -t 99999999 "$3"
+ echo $1 > /tmp/battery.tmp
fi
}
+# If upower command is available
if command -v upower > /dev/null 2>&1 ; then
+
+ # Get battery power indicator (charging/discharging/fully charged) and stop script if there is no value for it (if there is no battery in device)
__bat_power=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}')
if [[ -n ${__bat_per} ]]; then
exit
fi
+
+ # Set the battery power indicator icon
__bat_power_ind=""
if [[ ${__bat_power} = "charging" ]]; then __bat_power_ind=""
elif [[ ${__bat_power} = "discharging" ]]; then __bat_power_ind=""
elif [[ ${__bat_power} = "fully-charged" ]]; then __bat_power_ind=""
fi
+
+ # Get the battery percentage, time until the battery is empty and time until the battery is full
__bat_per=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | awk '{print $2}' | sed "s|%||g")
__time_empt=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to empty" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]')
__time_full=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to full" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]')
+ # Print the battery power indicator icon, percentage and time until empty or time until full
echo -n " ${__bat_power_ind} ${__bat_per}%"
if [[ ${__bat_power} = "discharging" ]]; then
echo " ${__time_empt}"
@@ -28,12 +38,16 @@ if command -v upower > /dev/null 2>&1 ; then
echo " ${__time_full}"
fi
+ # Create the temporary battery file, if it doesn't exist
if [ ! -f "/tmp/battery.tmp" ]; then
touch /tmp/battery.tmp
fi
- battery_notify 100 'fully-charged' 'Battery charged!'
- battery_notify 15 'discharging' 'Battery low (15%)!'
- battery_notify 10 'discharging' 'Battery lower (10%)!!'
- battery_notify 5 'discharging' 'Battery critical (5%)!!!'
+ # Setup for battery notifications
+ battery_notify 100 'fully-charged' 'Battery 100%'
+ battery_notify 80 'charging' 'Battery 80%'
+ battery_notify 20 'discharging' 'Battery 20%'
+ battery_notify 15 'discharging' 'Battery 15%'
+ battery_notify 10 'discharging' 'Battery 10%'
+ battery_notify 5 'discharging' 'Battery 5%'
fi