6 //#include<X11/Xutil.h>
8 //#include <X11/Xatom.h>
9 #define LENGTH(X) (sizeof(X) / sizeof (X[0]))
12 unsigned int interval;
15 void sighandler(int num);
22 static char statusbar[LENGTH(blocks)][50] = {0};
23 static char setrootcmd[256];
24 static char *statuscat;
25 static const char *volupcmd[] = { "volup", NULL };
26 static const char *voldowncmd[] = { "voldown", NULL };
27 static const char *volmutecmd[] = { "volmute", NULL };
28 static int statusContinue = 1,volmuted = 0;
30 void replace(char *str, char old, char new)
33 for(int i = 0; i < N; i++)
39 void getcmd(char *cmd, char *output)
41 FILE *cmdf = popen(cmd,"r");
44 int N = strlen(output);
47 while((c = fgetc(cmdf)) != EOF)
53 void getcmds(int time)
56 for(int i = 0; i < LENGTH(blocks); i++)
59 if ((current->interval != 0 && time % current->interval == 0) || time == -1)
60 getcmd(current->command,statusbar[i]);
64 void getsigcmds(int signal)
67 for (int i = 0; i < LENGTH(blocks); i++)
70 if (current->signal == signal)
71 getcmd(current->command,statusbar[i]);
77 for(int i = 0; i < LENGTH(blocks); i++)
79 if (blocks[i].signal > 0)
80 signal(SIGRTMIN+blocks[i].signal, sighandler);
85 void getstatus(char *str)
88 for(int i = 0; i < 5; j+=strlen(statusbar[i++]))
90 strcpy(str + j, statusbar[i]);
92 //for (;j < LENGTH(str);j++)
99 Display *d = XOpenDisplay(NULL);
103 screen = DefaultScreen(dpy);
104 root = RootWindow(dpy, screen);
105 getstatus(setrootcmd);
106 replace(setrootcmd,'\n',' ');
107 replace(setrootcmd,EOF,' ');
108 //printf("%s\n",setrootcmd);
109 XStoreName(dpy, root, setrootcmd);
119 while(statusContinue)
134 void sighandler(int signum)
136 getsigcmds(signum-SIGRTMIN);
140 void termhandler(int signum)
148 signal(SIGTERM, termhandler);
149 signal(SIGINT, termhandler);