diff options
Diffstat (limited to 'dwmstatus.c')
-rw-r--r-- | dwmstatus.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/dwmstatus.c b/dwmstatus.c new file mode 100644 index 0000000..1cb707d --- /dev/null +++ b/dwmstatus.c @@ -0,0 +1,121 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <X11/Xlib.h> + +#include "kconfig.h" +#include "dwmstatus.h" + +static Display *dpy; + + +int +stradd( bbuf *a, bbuf *b ) +{ + int i=0,j=0; + for ( i=0; + i<a->size-1, a->str[i]!='\0'; + i++){} + + for (j=0; + (i+j)<a->size-1, j<b->size-1; + j++) + { + a->str[i+j] = b->str[j]; + } + return 0; +} + +void +setstatus(char *str) +{ + XStoreName(dpy, DefaultRootWindow(dpy), str); + XSync(dpy, False); +} + +int main( int argc, char **argv ) +{ + int cmd_status=0; + + int i=0; + for (i=1; i<argc; i++ ) + { + if ( strncmp( argv[i], "-t", 2 ) == 0 ) + cmd_status = 1; + if ( strncmp( argv[i], "-h", 2) == 0) + { + printf("Help\n-t : run in terminal mode\n"); + return 0; + } + } + +#ifdef CONFIG_STATUS_UTF8 + setlocale( LC_CTYPE, "" ); +#endif + //char *status=NULL; + bbuf status; memset( &status, 0, sizeof(status) ); + bbuf time; memset( &time, 0, sizeof(time) ); + bbuf date; memset( &date, 0, sizeof(date) ); + bbuf temp; memset( &temp, 0, sizeof(temp) ); + bbuf cpu; memset( &cpu, 0, sizeof(cpu) ); + bbuf batt; memset( &batt, 0, sizeof(batt) ); + + if (status.size == 0) + { + status.size = 1024; + status.str = malloc( status.size ); + memset( status.str, 0, status.size ); + } + + //if cannot open display maybe we are in terminal but we ignore it + //while there was no direct command to workin in terminal we dont + //run programm in terminal mode + if (!(dpy = XOpenDisplay(NULL))) + { + printf("cannot open display.\n"); + return -1; + } + + for (;;sleep(1)) + { + status.str[0]=0; + + #ifdef CONFIG_STATUS_BATTERY + print_batt( &batt ); + stradd( &status, &batt ); + #endif + + #ifdef CONFIG_STATUS_CPU + print_cpu( &cpu ); + stradd( &status, &cpu ); + #endif + + #ifdef CONFIG_STATUS_TEMP + print_temp( &temp ); + stradd( &status, &temp ); + #endif + + #ifdef CONFIG_STATUS_TIME + print_time( &time ); + stradd( &status, &time ); + #endif + + #ifdef CONFIG_STATUS_DATE + print_date( &date ); + stradd( &status, &date ); + #endif + + if ( cmd_status == 1) + { + wprintf(L"%s\n", status.str); + } + else + { + setstatus(status.str); + } + } + + XCloseDisplay(dpy); + + return 0; +} |