From 1e34ea7f980aa845218735ea16072d2c2f14f9ed Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Sat, 12 Jan 2019 15:22:06 +0000 Subject: [PATCH] wmwifi: call usleep() directly in main loop I noticed using powertop that the number of wakeups per second generated by wmwifi did not correlate well with the update interval, where I'd expect approximately 1 wakeup if the update interval was 1 sec. Strangely enough, calling the function dockapp_nextevent_or_timeout(&event, update_interval * 1000) in the main loop (note that I already replaced * 100 by * 1000 above) with update_interval = 1 generates around 15 wakeups/sec here. Calling usleep() in the loop instead leads to fewer wakeups, around 1/sec. Signed-off-by: Carlos R. Mafra --- wmwifi/src/wmwifi.c | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/wmwifi/src/wmwifi.c b/wmwifi/src/wmwifi.c index ce50365..5bbb69d 100644 --- a/wmwifi/src/wmwifi.c +++ b/wmwifi/src/wmwifi.c @@ -65,6 +65,7 @@ struct theme { struct theme tcur; struct theme blgt; struct wifi lwfi; +time_t last_update = 0; /* prototypes */ static void update(struct wifi *wfi); @@ -122,36 +123,36 @@ int main(int argc, char **argv) draw_text("link", 32, 47, False); /* Main loop */ - for (i = 0;; i++) { - /* CHANGED */ - if (dockapp_nextevent_or_timeout(&event, update_interval * 100)) { - /* Next Event */ - switch (event.type) { - case ButtonPress: - bevent = (XButtonPressedEvent *) & event; - switch (bevent->button & 0xff) { - case Button1: - scroll = (scroll) ? False : True; - count = 0; - break; - case Button2: - next_if(&wfi); - break; - case Button3: - switch_interface(&wfi); - break; - } - break; - default: /* make gcc happy */ - break; - } - } else { - /* Time Out */ - update(&wfi); - } - } + while (1) { + if (time(NULL) != last_update) + update(&wfi); - return 0; + while (XPending(display)) { + XNextEvent(display, &event); + + switch (event.type) { + case ButtonPress: + bevent = (XButtonPressedEvent *) & event; + switch (bevent->button & 0xff) { + case Button1: + scroll = (scroll) ? False : True; + count = 0; + break; + case Button2: + next_if(&wfi); + break; + case Button3: + switch_interface(&wfi); + break; + } + break; + default: /* make gcc happy */ + break; + } + } + usleep(update_interval*1000000L); + } + return 0; } static void do_theme(struct theme thm) @@ -288,6 +289,7 @@ static void update(struct wifi *wfi) /* show */ } dockapp_copy2window(pixmap); + time(&last_update); } static void refresh(struct theme thm) {