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.
This commit is contained in:
Carlos R. Mafra 2019-01-12 20:54:43 +00:00
parent 1e34ea7f98
commit dd5d59b8f9
1 changed files with 13 additions and 6 deletions

View File

@ -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);