From 8101b1aa507795224054a752dd603ec3426c40ee Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Sep 2025 19:37:28 +0100 Subject: Created better management of updates + update on SIGUSR1 --- src/modules/battery.c | 16 ++++------------ src/modules/battery.h | 2 -- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'src/modules') diff --git a/src/modules/battery.c b/src/modules/battery.c index 6c656fe..18a68de 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -7,8 +7,6 @@ #include #include -#define UPDATE_FREQUENCY 20 - static int open_battery_file(const char * name) { @@ -39,7 +37,6 @@ battery_new() b->full = battery_value(file); b->file_current = open_battery_file("charge_now"); - b->last_update = 0; close(file); @@ -58,16 +55,11 @@ void battery_update(struct battery * b) int now; float percentf; int percent; - time_t now_time = time(NULL); - - if((now_time - b->last_update) >= UPDATE_FREQUENCY) { - b->last_update = now_time; - now = battery_value(b->file_current); + now = battery_value(b->file_current); - percentf = (100.0f / b->full) * now; - percent = round(percentf); + percentf = (100.0f / b->full) * now; + percent = round(percentf); - snprintf(b->value, BATTERY_VALUE_SIZE, "%d%%", percent); - } + snprintf(b->value, BATTERY_VALUE_SIZE, "%d%%", percent); } diff --git a/src/modules/battery.h b/src/modules/battery.h index 92489b5..f358e46 100644 --- a/src/modules/battery.h +++ b/src/modules/battery.h @@ -2,14 +2,12 @@ #define _DWXINFO_MODULES_BATTERY_H_ #include -#include #define BATTERY_VALUE_SIZE 5 struct battery { int full; int file_current; - time_t last_update; char value[BATTERY_VALUE_SIZE]; }; -- cgit v1.2.3