improve xmonad-status.c

This commit is contained in:
Don Stewart 2007-06-09 14:02:58 +00:00
parent 629650f5c6
commit b587adc724

View File

@ -12,6 +12,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
@ -20,18 +21,16 @@
int main(void) { int main(void) {
size_t len;
char workspaces[WORKSPACES];
char buf[1024]; char buf[1024];
char *s, *p, *q, current, *rest; char *s, current, *rest;
int n, i = 0; int i;
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
while (fgets(buf, sizeof(buf), stdin) != NULL) { while (fgets(buf, sizeof(buf), stdin) != NULL) {
n = strlen(buf); i = strlen(buf);
buf[n-1] = '\0'; buf[i-1] = '\0';
s = buf; s = buf;
/* extract tag of current workspace */ /* extract tag of current workspace */
@ -40,13 +39,15 @@ int main(void) {
/* split up workspace list */ /* split up workspace list */
/* extract just the tags of the workspace list */ /* extract just the tags of the workspace list */
while (i < WORKSPACES) {
workspaces[i++] = *(char *)strsep(&rest, ",");
}
/* now print out list */
for (i = 0; i < WORKSPACES; i++) { for (i = 0; i < WORKSPACES; i++) {
printf(((workspaces[i] == current) ? "[%c]" : " %c "), workspaces[i]); s = (char *)strsep(&rest, ",");
if (*s == current) {
printf("[%c]", *s);
} else if (s[2] != ':') { /* filter empty workspaces */
printf(" %c ", *s);
}
} }
putchar('\n'); putchar('\n');