2020-05-22 01:55:37 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-03-03 18:26:11 +01:00
|
|
|
lower_battery_threshold=10
|
|
|
|
KBD="";
|
|
|
|
oldKBD="";
|
2024-03-22 13:26:13 +01:00
|
|
|
intern="eDP";
|
|
|
|
extern="HDMI-A-0";
|
2020-03-03 18:26:11 +01:00
|
|
|
|
2019-10-29 13:56:54 +01:00
|
|
|
function kb_routine {
|
2024-03-22 13:26:13 +01:00
|
|
|
oldKBD="$KBD";
|
|
|
|
case "$(xset -q | grep -A 0 'LED' | cut -c59-67)" in
|
|
|
|
"00000000")
|
|
|
|
KBD="Europe" ;;
|
|
|
|
"00001000")
|
|
|
|
KBD="Deutsch" ;;
|
|
|
|
*) KBD="unknown" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$KBD" != "$oldKBD" ]; then
|
|
|
|
dunstify -r 1 "$KBD";
|
|
|
|
fi
|
2019-10-29 13:56:54 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function battery_routine {
|
2024-03-22 13:26:13 +01:00
|
|
|
capacity=$(< /sys/class/power_supply/BAT0/capacity)
|
|
|
|
if [[ $capacity -lt lower_battery_threshold ]]; then
|
|
|
|
acpi | grep -q '0: Discharging' && dunstify "Battery at $capacity%";
|
|
|
|
sleep 60;
|
|
|
|
fi
|
2019-10-29 13:56:54 +01:00
|
|
|
}
|
|
|
|
|
2024-03-22 13:26:13 +01:00
|
|
|
|
|
|
|
function monitor {
|
|
|
|
oldmonstats="$monstats"
|
|
|
|
if xrandr | grep "$extern disconnected"; then
|
|
|
|
monstats="$intern"
|
|
|
|
xrandr --output "$extern" --off --output "$intern" --auto
|
|
|
|
else
|
|
|
|
monstats="$extern"
|
|
|
|
xrandr --output "$intern" --off --output "$extern" --auto
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$oldmonstats" != "$monstats" ]; then
|
|
|
|
dunstify -r 1 "Using $monstats.";
|
|
|
|
fi
|
|
|
|
}
|
2019-10-29 13:56:54 +01:00
|
|
|
while :
|
|
|
|
do
|
2024-03-22 13:26:13 +01:00
|
|
|
kb_routine;
|
|
|
|
battery_routine;
|
|
|
|
monitor;
|
|
|
|
sleep 1;
|
2019-08-14 22:05:24 +02:00
|
|
|
done
|