From 1143e46d20bd5e0f04b43e7193c44406a5c858da Mon Sep 17 00:00:00 2001 From: Shaun Inman Date: Fri, 13 Jan 2023 20:10:14 -0500 Subject: [PATCH] keymon should dump any input received during sleep --- src/keymon/keymon.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/keymon/keymon.c b/src/keymon/keymon.c index d36c1e8..f1bc762 100644 --- a/src/keymon/keymon.c +++ b/src/keymon/keymon.c @@ -65,17 +65,31 @@ int main (int argc, char *argv[]) { inputs[i] = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); } - register uint32_t input; - register uint32_t val; - register uint32_t menu_pressed = 0; - register uint32_t power_pressed = 0; + uint32_t input; + uint32_t val; + uint32_t menu_pressed = 0; + uint32_t power_pressed = 0; uint32_t repeat_volume = 0; + uint8_t ignore; + uint64_t then; + uint64_t now; + struct timeval tod; + + gettimeofday(&tod, NULL); + then = tod.tv_sec * 1000 + tod.tv_usec / 1000; + ignore = 0; + // TODO: enable key repeat (not supported natively) while (1) { + gettimeofday(&tod, NULL); + now = tod.tv_sec * 1000 + tod.tv_usec / 1000; + if ((int)(now-then)>20) ignore = 1; // ignore input that arrived during sleep + for (int i=0; i REPEAT )) continue; switch (ev.code) { @@ -128,6 +142,9 @@ int main (int argc, char *argv[]) { } } } + then = now; + ignore = 0; + usleep(16666); // 60fps } }