diff options
author | Timmy Keller <tjk@tjkeller.xyz> | 2024-09-09 21:08:07 -0500 |
---|---|---|
committer | Timmy Keller <tjk@tjkeller.xyz> | 2024-09-09 21:08:07 -0500 |
commit | 40c551385f20cc95a1b6571c4b1946cbed226f85 (patch) | |
tree | bd561084f82a817346bab048a403dd6304a925cf | |
parent | 8e929bd44420ed9a3bc0b6a030cebbdfcafebf4d (diff) | |
download | lowbat-40c551385f20cc95a1b6571c4b1946cbed226f85.tar.xz lowbat-40c551385f20cc95a1b6571c4b1946cbed226f85.zip |
update makefile to build & install, include manpage, make notification persistent and change urgency
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | lowbat.1 | 28 | ||||
-rw-r--r-- | lowbat.c | 8 | ||||
-rwxr-xr-x | shlowbat | 4 |
4 files changed, 45 insertions, 10 deletions
@@ -7,20 +7,25 @@ TARGET = lowbat SRCS = lowbat.c OBJS = $(SRCS:.c=.o) -# Default target all: $(TARGET) -# Build target $(TARGET): $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) -# Compile source files %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ -# Clean up build files clean: rm -f $(TARGET) $(OBJS) -# Phony targets +install: all + mkdir -p /usr/local/bin + cp lowbat /usr/local/bin/lowbat + chmod 755 /usr/local/bin/lowbat + cp lowbat.1 /usr/local/share/man/man1/lowbat.1 + chmod 644 /usr/local/share/man/man1/lowbat.1 + +uninstall: + rm -f /usr/local/bin/lowbat /usr/local/share/man/man1/lowbat.1 + .PHONY: all clean diff --git a/lowbat.1 b/lowbat.1 new file mode 100644 index 0000000..1d0d66f --- /dev/null +++ b/lowbat.1 @@ -0,0 +1,28 @@ +.TH LOWBAT 1 lowbat\-1.0 +.SH NAME +lowbat - A minimal battery level monitor daemon, written in C +.SH DESCRIPTION +lowbat is configured by default to check the system battery level every 3 +seconds. It is able to detect each battery installed and the system, and +calculate the remaining capacity of all batteries combined. Batteries added to +the system during runtime will also be detected. +.P +The daemon will send a warning notification the user when their battery level +drops below 20% while the batteries are discharging, and another critical +warning at 5%. +.P +The current battery level will also be displayed in stdout. +.SH USAGE +Call the lowbat executable in your xinitrc or xprofile. +.SH CUSTOMIZATION +There are no runtime flags or configuration files. Simply modify the source +code to suit your needs. +.SH COPYRIGHT +Copyright 2024 Tim Keller. +MIT License. +.P +.BR <https://TJKeller.xyz> +.SH SEE ALSO +.BR notify-send(1) +.P +.BR <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power> @@ -64,11 +64,13 @@ void load_installed_batteries() { closedir(dir); } -void notifysend(char *title, char *content) { +void notifysend(char *title, char *content, NotifyUrgency urgency) { NotifyNotification *notif; notify_init("lowbat"); notif = notify_notification_new(title, content, NULL); + notify_notification_set_timeout(notif, NOTIFY_EXPIRES_NEVER); + notify_notification_set_urgency(notif, urgency); notify_notification_show(notif, NULL); } @@ -133,12 +135,12 @@ int main() { if (discharging) { if (capacity <= 5 && !w_lowbat_crit) { sprintf(msg, "%d%% remains", capacity); // TODO snprintf me plz - notifysend("Critical Low Battery Warning", msg); + notifysend("Critical Low Battery Warning", msg, NOTIFY_URGENCY_CRITICAL); w_lowbat_crit = w_lowbat = 1; } else if (capacity <= 20 && !w_lowbat) { sprintf(msg, "%d%% remains", capacity); - notifysend("Low Battery Warning", msg); + notifysend("Low Battery Warning", msg, NOTIFY_URGENCY_NORMAL); w_lowbat = 1; } @@ -13,9 +13,9 @@ while true; do if is_discharging; then if [ $capacity -le 5 ] && [ $warning_level -lt 2 ]; then - notify_send "Critical Low Battery Warning" "${capacity}% remains" + notify-send -u critical -w "Critical Low Battery Warning" "${capacity}% remains" elif [ $capacity -le 20 ] && [ $warning_level -lt 1 ]; then - notify_send "Low Battery Warning" "${capacity}% remains" + notify-send -u normal -w "Low Battery Warning" "${capacity}% remains" fi else warning_level=0 |