From 02a74cc0b499f6a93c25ea8cd392af977298d60a Mon Sep 17 00:00:00 2001 From: spv Date: Sun, 21 Sep 2025 00:59:56 -0400 Subject: use signal ipc instead of sleep loop --- src/light_thread.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/light_thread.c') diff --git a/src/light_thread.c b/src/light_thread.c index 1d273a0..20b7bb9 100644 --- a/src/light_thread.c +++ b/src/light_thread.c @@ -2,14 +2,13 @@ #include -#include -#include - #include "common.h" #include "consts.h" #include "config.h" #include "backlight.h" +static pid_t keypress_pid; + uint64_t time_since_press(void) { struct timeval now; @@ -30,12 +29,24 @@ uint64_t time_since_press(void) { return diff; } -int light_thread(void) { - while (1) { - if (time_since_press() > BACKLIGHT_TIME) backlight_off(); - else backlight_on(); +void handler(int _) { + if (time_since_press() > BACKLIGHT_TIME) { + backlight_off(); + } else { + backlight_on(); - usleep(THREAD_WAIT); + handler(_); + } +} + +int light_thread(pid_t _keypress_pid) { + keypress_pid = _keypress_pid; + + signal(SIGCONT, handler); + + while (1) { + pause(); +// usleep(THREAD_WAIT); } return 0; -- cgit v1.2.3