]> git.armaanb.net Git - dwmblocks.git/blobdiff - dwmblocks.c
added icons and delimeter
[dwmblocks.git] / dwmblocks.c
index 62908daad025a7448b17b9a604b2d5cfe28b20e6..2db3489144bb57c5bccb6e96d53113ac6c3e5db4 100644 (file)
@@ -3,16 +3,27 @@
 #include<string.h>
 #include<unistd.h>
 #include<signal.h>
-//#include<X11/Xutil.h>
 #include<X11/Xlib.h>
-//#include <X11/Xatom.h>
 #define LENGTH(X)               (sizeof(X) / sizeof (X[0]))
+
 typedef struct {
+       char* icon;
        char* command;
        unsigned int interval;
        unsigned int signal;
 } Block;
 void sighandler(int num);
+void replace(char *str, char old, char new);
+void getcmds(int time);
+void getsigcmds(int signal);
+void setupsignals();
+void getstatus(char *str);
+void setroot();
+void statusloop();
+void statusinit();
+void sighandler(int signum);
+void termhandler(int signum);
+
 
 #include "blocks.h"
 
@@ -20,7 +31,7 @@ static Display *dpy;
 static int screen;
 static Window root;
 static char statusbar[LENGTH(blocks)][50] = {0};
-static char setrootcmd[256];
+static char statusstr[256];
 static char *statuscat;
 static const char *volupcmd[]  = { "volup", NULL };
 static const char *voldowncmd[]  = { "voldown", NULL };
@@ -35,17 +46,21 @@ void replace(char *str, char old, char new)
                        str[i] = new;
 }
 
-
-void getcmd(char *cmd, char *output)
+//opens process *cmd and stores output in *output
+void getcmd(const Block *block, char *output)
 {
+       strcpy(output, block->icon);
+       char *cmd = block->command;
        FILE *cmdf = popen(cmd,"r");
        if (!cmdf)
                return;
-       int N = strlen(output);
+       //int N = strlen(output);
        char c;
-       int i = 0;
+       int i = strlen(block->icon);
        while((c = fgetc(cmdf)) != EOF)
                output[i++] = c;
+       if (delim != '\0' && --i)
+               output[i++] = delim;
        output[i++] = '\0';
        pclose(cmdf);
 }
@@ -57,7 +72,7 @@ void getcmds(int time)
        {       
                current = blocks + i;
                if ((current->interval != 0 && time % current->interval == 0) || time == -1)
-                       getcmd(current->command,statusbar[i]);
+                       getcmd(current,statusbar[i]);
        }
 }
 
@@ -68,7 +83,7 @@ void getsigcmds(int signal)
        {
                current = blocks + i;
                if (current->signal == signal)
-                       getcmd(current->command,statusbar[i]);
+                       getcmd(current,statusbar[i]);
        }
 }
 
@@ -84,13 +99,12 @@ void setupsignals()
 
 void getstatus(char *str)
 {
-       int j = 0;//15;
-       for(int i = 0; i < 5; j+=strlen(statusbar[i++]))
+       int j = 0;
+       for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++]))
        {       
                strcpy(str + j, statusbar[i]);
        }
-       //for (;j < LENGTH(str);j++)
-       str[j] = '\0';
+       str[--j] = '\0';
 
 }
 
@@ -102,16 +116,13 @@ void setroot()
        }
        screen = DefaultScreen(dpy);
        root = RootWindow(dpy, screen);
-       getstatus(setrootcmd);
-       replace(setrootcmd,'\n',' ');
-       replace(setrootcmd,EOF,' ');
-       //printf("%s\n",setrootcmd);
-       XStoreName(dpy, root, setrootcmd);
+       getstatus(statusstr);
+       XStoreName(dpy, root, statusstr);
        XCloseDisplay(dpy);
 }
 
 
-void *statusloop()
+void statusloop()
 {
        setupsignals();
        int i = 0;
@@ -143,8 +154,13 @@ void termhandler(int signum)
        exit(0);
 }
 
-int main()
+int main(int argc, char** argv)
 {
+       for(int i = 0; i < argc; i++)
+       {       
+               if (!strcmp("-d",argv[i]))
+                       delim = argv[++i][0];
+       }
        signal(SIGTERM, termhandler);
        signal(SIGINT, termhandler);
        statusinit();