From c32ed90899dd1047bc8bab171a60d7de6f4af34f Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 11 Dec 2022 01:03:47 -0700 Subject: update stuff, add relevant x scripts --- x/.xinitrc | 2 +- x/.xinitrc-not-docked | 1 + x/battery.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ x/startdwm.sh | 16 ++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 x/battery.pl create mode 100755 x/startdwm.sh (limited to 'x') diff --git a/x/.xinitrc b/x/.xinitrc index efd3270..dee608b 100644 --- a/x/.xinitrc +++ b/x/.xinitrc @@ -46,7 +46,7 @@ fi #spotifyd & # set up monitors -sh ~/.screenlayout/screenlayout.sh & +sh ~/.config/screenlayout.sh & # set default audio device to be dock audio jack pulseaudio -k && pacmd set-default-sink alsa_output.usb-0c76_USB_PnP_Audio_Device-00.analog-stereo & diff --git a/x/.xinitrc-not-docked b/x/.xinitrc-not-docked index 51aa3ae..b18ab1c 100644 --- a/x/.xinitrc-not-docked +++ b/x/.xinitrc-not-docked @@ -1,3 +1,4 @@ +#!/bin/sh # executed by startx-not-docked # for use when dingo is NOT docked export DOCKED=false diff --git a/x/battery.pl b/x/battery.pl new file mode 100755 index 0000000..b98707a --- /dev/null +++ b/x/battery.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +$| = 1; + +my $CRITICAL = undef; +my $LOW = undef; +my $CHARGING = undef; +my $DEAD_LEVEL = 2; +my $CRITICAL_LEVEL = 5; +my $LOW_LEVEL = 10; + +while (1) { + my @acpi = split " ", `acpi | grep "Discharging" | grep -v "rate information"`; + my $battery_level = $acpi[3]; + my $status = $acpi[2]; + my $sent = undef; + $battery_level =~ s/%,//g; + $status =~ s/,//g; + + if ($status =~ "Discharging") { + $CHARGING = undef; + if (!$CRITICAL) { + if (int($battery_level) <= int($CRITICAL_LEVEL)) { + $CRITICAL = 'def'; + $sent = 'def'; + system "notify-send -i \"battery-empty\" -t 0 -u critical \"BATTERY CRITICAL\" \"Battery level is ${battery_level}%\n\nCharge the system NOW.\"" + } + } if (!$LOW && !$sent) { + if (int($battery_level) <= int($LOW_LEVEL)) { + $LOW = 'def'; + $sent = 'def'; + system "notify-send -i \"battery-caution\" -t 0 -u normal \"BATTERY LOW\" \"Battery level is ${battery_level}%\n\nCharge the system soon.\"" + } + } if (int($battery_level) <= int($DEAD_LEVEL)) { + system "notify-send -t 0 -u critical \"SHUTTING DOWN\" \"Battery level is too low. The system will shutdown in 2 minutes to prevent corruption.\n\nCharge the system NOW to cancel the shutdown.\""; + system "doas shutdown -Ph 2 &"; + } + } else { + if (!$CHARGING) { + $CHARGING = 'def'; + $CRITICAL = undef; + $LOW = undef; + system "doas shutdown -c"; + system "notify-send -t 3000 -i \"battery-good-charging\" \"System is now charging\""; + } + } + + sleep 30; +} diff --git a/x/startdwm.sh b/x/startdwm.sh new file mode 100755 index 0000000..4625951 --- /dev/null +++ b/x/startdwm.sh @@ -0,0 +1,16 @@ +# stolen from https://wiki.archlinux.org/title/Dwm#Restart_dwm +# relaunch DWM if the binary changes, otherwise bail +csum="" +new_csum=$(sha1sum $(which dwm)) +while true +do + if [ "$csum" != "$new_csum" ] + then + csum=$new_csum + dbus-launch dwm + else + exit 0 + fi + new_csum=$(sha1sum $(which dwm)) + sleep 0.5 +done -- cgit v1.2.3