From dd5d59b8f99521d5e59ebd441abb97822891e65a Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Sat, 12 Jan 2019 20:54:43 +0000 Subject: [PATCH] wmwifi: Display interface/essid in 2-second intervals Base the decision to display either the interface name or essid on a time interval rather than how many times the update() function is called. The time interval is chosen to be 2 seconds. The old logic would swap the display after update() was called 50 times. If 'interval' between updates is a sane value around 1 second, it would take 50 seconds to swap the name on display. --- wmwifi/src/wmwifi.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/wmwifi/src/wmwifi.c b/wmwifi/src/wmwifi.c index 5bbb69d..bf95dc8 100644 --- a/wmwifi/src/wmwifi.c +++ b/wmwifi/src/wmwifi.c @@ -66,6 +66,8 @@ struct theme tcur; struct theme blgt; struct wifi lwfi; time_t last_update = 0; +time_t last_swap = 0; +time_t now = 0; /* prototypes */ static void update(struct wifi *wfi); @@ -201,6 +203,8 @@ static void update(struct wifi *wfi) //char *str = calloc(1, sizeof(wfi->ifname) + sizeof(wfi->essid) + 3); char str[512]; + now = time(NULL); + /* get current link level from /proc/net/wireless */ copy_wifi(&lwfi, wfi); get_wifi_info(wfi); @@ -260,12 +264,15 @@ static void update(struct wifi *wfi) if (count > (strlen(str) * 3)) count = 1; } else { - if (count < 50) - sw = 1; - if (count >= 50) - sw = 2; - if (count == 100) - count = -1; + int diff = now - last_swap; + /* swap between ifname and essid every 2 seconds */ + if (diff <= 2) + sw = 1; + else if ((diff > 2) && (diff <= 4)) + sw = 2; + else + last_swap = now; + switch (sw) { case 1: dockapp_copyarea(display_link, pixmap, 0, 0, 58, 12, 0, 0);