summaryrefslogtreecommitdiff
path: root/status.c
diff options
context:
space:
mode:
Diffstat (limited to 'status.c')
-rw-r--r--status.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/status.c b/status.c
index 9acdca2..c2b8bd0 100644
--- a/status.c
+++ b/status.c
@@ -83,14 +83,15 @@ static struct element statusbar[] = {
/* Add status elements here */
/*{element_function, {seconds, nanoseconds}, {0}, {0}},*/
- {get_net_link_status, {15, 0}, {0}, {0}},
- {get_battery0_status, {60, 0}, {0}, {0}},
- {get_battery1_status, {60, 0}, {0}, {0}},
- { get_all_bat_status, {60, 0}, {0}, {0}},
- { date, {7, MSEC(500)}, {0}, {0}},
+ {get_net_link_status, {15, 0}, {0}, {0}},
+ {get_battery0_status, {60, 0}, {0}, {0}},
+ {get_battery1_status, {60, 0}, {0}, {0}},
+ { get_all_bat_status, {60, 0}, {0}, {0}},
+ { date, {7, MSEC(500)}, {0}, {0}},
};
-struct interface_status interfaces[8]; // surely noone has more than 8 interfaces.
+// surely noone has more than 8 interfaces.
+struct interface_status interfaces[8];
/* Functions */
void
@@ -211,7 +212,6 @@ get_essid(char* if_name, char* dst) {
wreq.u.essid.pointer = dst;
wreq.u.essid.length = IW_ESSID_MAX_SIZE;
- //printf("#%s#\n", dst);
// Test if we have wireless on this interface
if (ioctl(sock, SIOCGIWNAME, &wreq) != -1) {
@@ -246,21 +246,19 @@ get_net_link_status(char* buf) {
while (i < c && strcmp(name, interfaces[i].name))
i++;
- //if (i != c) {
- //printf("found %s in %d\n", name, i);
- //}
-
/* We're not interested in interfaces that are not "up" */
if (!(ifa->ifa_flags & IFF_LOWER_UP)) {
+ const size_t status_sz = sizeof(struct interface_status);
+
/* Remove it from the list */
if (i < c) {
/* Don't memmove if last element */
if (c - i > 1) {
- memmove(&interfaces[i], &interfaces[i + 1], sizeof(struct interface_status) * (c - i));
+ memmove(&interfaces[i], &interfaces[i + 1], status_sz * (c - i));
}
/* "wipe" last element */
- memset(&interfaces[c - 1], 0, sizeof(struct interface_status));
+ memset(&interfaces[c - 1], 0, status_sz);
c--;
}
@@ -433,7 +431,9 @@ main(void) {
for (i = 0; i < num_elems; i++) {
struct timespec next_fire = {0};
- statusbar[i].fire_previous = time_add(statusbar[i].fire_interval, next_fire);
+ struct element* e = &statusbar[i];
+
+ e->fire_previous = time_add(e->fire_interval, next_fire);
if (time_lt(now, next_fire)) {
/* Check if this is the next to-be-updated element */
@@ -443,13 +443,13 @@ main(void) {
continue;
}
- memset(statusbar[i].buf, 0, ELEMENT_STRBUF_SZ);
+ memset(e->buf, 0, ELEMENT_STRBUF_SZ);
- statusbar[i].f(statusbar[i].buf);
- statusbar[i].fire_previous = now;
+ e->f(statusbar[i].buf);
+ e->fire_previous = now;
/* Check if this element needs to be refreshed next, again */
- statusbar[i].fire_previous = time_add(statusbar[i].fire_interval, next_fire);
+ e->fire_previous = time_add(e->fire_interval, next_fire);
if (time_lt(next_fire, next_update)) {
next_update = next_fire;
@@ -462,12 +462,14 @@ main(void) {
*/
}
+ /* Copy the statusbar buffers into the final buffer */
char buf[STATUS_STRBUF_SZ];
memset(buf, 0, STATUS_STRBUF_SZ);
for (i = 0; i < num_elems; i++) {
if (!strlen(statusbar[i].buf))
continue;
+
strcat(buf, statusbar[i].buf);
if (i != num_elems - 1)
strcat(buf, ELEMENT_SEPERATOR);