sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 721bc541169be09cfc80501e781a4bf334e056ba
parent 284b21b338012907e233dff549ddc78a4ba3b78b
Author: levi0x0 <levi0x0x@gmail.com>
Date:   Sat, 28 Feb 2015 10:51:17 +0000

added sprint, the setRoot bug fixed, added for loop for spawn()

Diffstat:
Mdwm.suckless.org/dwmstatus/barM.c | 61++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 44 insertions(+), 17 deletions(-)

diff --git a/dwm.suckless.org/dwmstatus/barM.c b/dwm.suckless.org/dwmstatus/barM.c @@ -11,33 +11,60 @@ * Read main() to configure your new status Bar. * * compile: gcc -o barM barM.c -lX11 + * + * mv barM /usr/local/bin/ */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> +#include <stdarg.h> #include <X11/Xlib.h> -#define VERSION "0.10" -#define TIME_FORMAT " (%H:%M) (%d-%m-%Y)" +/* + * Put this in your .xinitrc file: + * + * while true;do + * $(barM) + * done & + * + */ + +#define VERSION "0.11" +#define TIME_FORMAT "(%H:%M) (%d-%m-%Y)" #define MAXSTR 1024 -char * TimeADate(void) { - static char buffer[MAXSTR]; +static char status[MAXSTR]; - /* get time*/ - time_t now = time(0); +/*append here your commands*/ +char *commands[] = {"uname", + "free -mh | awk 'NR==2{print $3\"/\"$2}'" +}; +/* will append the buffer to status*/ +void sprint(char *format, ...) { + va_list li; + static char s[MAXSTR]; + va_start(li, format); + vsprintf(s, format, li); + va_end(li); - /* Read the time by the foramt*/ - strftime(buffer, MAXSTR, TIME_FORMAT, localtime(&now)); + strcat(status, s); +} - /* Return the buffer content*/ - return buffer; +/* returen the date*/ +char * date(void) { + static char date[MAXSTR]; + + time_t now = time(0); + + strftime(date, MAXSTR, TIME_FORMAT, localtime(&now)); + return date; } +/* open a pipe for a new coomand and return the output*/ char * spawn(char *c) { FILE *proc; static char buffer[MAXSTR]; @@ -57,7 +84,6 @@ char * spawn(char *c) { void XSetRoot(char *name) { Display *display; - /* try open display*/ if (( display = XOpenDisplay(0x0)) == NULL ) { fprintf(stderr, "[barM] cannot open display!\n"); exit(1); @@ -69,15 +95,16 @@ void XSetRoot(char *name) { XCloseDisplay(display); } -int main(int argc, char **argv) { - char status[MAXSTR]; - - sprintf(status, "(%s) %s", spawn("free -mh | awk 'NR==2{print $3\"/\"$2}'"), - TimeADate()); +int main(int argc, char **argv) { + int i = 0; + for(i = 0; commands[i]; i++ ) { + sprint("(%s) ", spawn(commands[i])); + } + sprint("%s", date()); XSetRoot(status); - /*sleep function*/ + /* sleep by default you dont need to add it to your bash*/ sleep(1); return 0;