aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--lowbat.128
-rw-r--r--lowbat.c8
-rwxr-xr-xshlowbat4
4 files changed, 45 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 180a311..8b6efbb 100644
--- a/Makefile
+++ b/Makefile
@@ -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>
diff --git a/lowbat.c b/lowbat.c
index 14f10a2..f3855bc 100644
--- a/lowbat.c
+++ b/lowbat.c
@@ -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;
}
diff --git a/shlowbat b/shlowbat
index a02ce56..a4fb9d7 100755
--- a/shlowbat
+++ b/shlowbat
@@ -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