diff -ruN dwm_old/config.default.h dwm/config.default.h --- dwm_old/config.default.h Sun Jun 10 11:31:13 2007 +++ dwm/config.default.h Sun Jun 10 15:29:33 2007 @@ -10,6 +10,7 @@ #define SELBORDERCOLOR "#ff0000" #define SELBGCOLOR "#006699" #define SELFGCOLOR "#ffffff" +#define CLOCKFORMAT "- %H:%M:%S" /* see 'man strftime' */ /* tagging */ #define TAGS \ diff -ruN dwm_old/draw.c dwm/draw.c --- dwm_old/draw.c Sun Jun 10 11:31:13 2007 +++ dwm/draw.c Sun Jun 10 15:23:24 2007 @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #include "dwm.h" #include +#include /* static */ @@ -50,7 +51,10 @@ void drawstatus(void) { - int i, x; + int i, x, clock_w; + struct tm curr_time; + time_t unix_time; + char time_text[64]; dc.x = dc.y = 0; for(i = 0; i < ntags; i++) { @@ -68,11 +72,28 @@ dc.w = blw; drawtext(lt->symbol, dc.norm); x = dc.x + dc.w; + time_text[sizeof time_text - 1] = '\0'; + unix_time = time(NULL); + localtime_r(&unix_time, &curr_time); + strftime(time_text, sizeof time_text - 1, CLOCKFORMAT, &curr_time); + if (time_text[0] != '\0') { + dc.w = textw(time_text); + dc.x = sw - dc.w; + if (dc.x < x) { + dc.x = x; + dc.w = sw - x; + } + drawtext(time_text, dc.norm); + clock_w = dc.w; + } else { + clock_w = 0; + } + dc.w = textw(stext); - dc.x = sw - dc.w; + dc.x = dc.x - dc.w; if(dc.x < x) { dc.x = x; - dc.w = sw - x; + dc.w = sw - x - clock_w; } drawtext(stext, dc.norm); if((dc.w = dc.x - x) > bh) { diff -ruN dwm_old/main.c dwm/main.c --- dwm_old/main.c Sun Jun 10 11:31:13 2007 +++ dwm/main.c Sun Jun 10 15:23:24 2007 @@ -273,6 +274,7 @@ char *p; int r, xfd; fd_set rd; + struct timeval tv; XEvent ev; if(argc == 2 && !strcmp("-v", argv[1])) @@ -309,7 +311,9 @@ if(readin) FD_SET(STDIN_FILENO, &rd); FD_SET(xfd, &rd); - if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { + tv.tv_sec = 1; + tv.tv_usec = 0; + if(select(xfd + 1, &rd, NULL, NULL, &tv) == -1) { if(errno == EINTR) continue; eprint("select failed\n"); @@ -331,13 +335,15 @@ if(p > stext) strncpy(stext, p + 1, sizeof stext); } - drawstatus(); } - while(XPending(dpy)) { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - (handler[ev.type])(&ev); /* call handler */ + if (FD_ISSET(xfd, &rd)) { + while(XPending(dpy)) { + XNextEvent(dpy, &ev); + if(handler[ev.type]) + (handler[ev.type])(&ev); /* call handler */ + } } + drawstatus(); } cleanup(); XCloseDisplay(dpy);