xbattmon

simple battery monitor for X
git clone git://git.2f30.org/xbattmon
Log | Files | Refs | README | LICENSE

commit 034d6076d1fd3e29bb9fa2c1af6e7531cfb7d887
parent da9f55fc9f17cdc66396fd1a3632bb61964970db
Author: lostd <lostd@2f30.org>
Date:   Thu, 11 Jun 2015 00:12:28 +0100

Pace blinking when redraw is forced by expose events

Diffstat:
Mxbattmon.c | 16++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/xbattmon.c b/xbattmon.c @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "arg.h" @@ -147,10 +148,21 @@ redraw(void) { int pos; unsigned long done, left; + static struct timespec oldtp = { 0 }; + struct timespec tp; + unsigned int delta; if (state == AC_OFF && batcap <= critical) { - timeout = 500; - blink = !blink; + clock_gettime(CLOCK_MONOTONIC, &tp); + delta = (tp.tv_sec * 1000 + tp.tv_nsec / 1000000) + - (oldtp.tv_sec * 1000 + oldtp.tv_nsec / 1000000); + if (delta < 500) { + timeout = 500 - delta; + } else { + timeout = 500; + blink = !blink; + oldtp = tp; + } } else { timeout = 5000; blink = 0;