After some digging around i figured what to do to draw text in the
status area, so i wrote a simple clock using threads. I can't
understand though why the clock doesn't get updated sometimes even
though i call drawbar() directly from the thread run method...
Any help would be appreciated, and also how could i do the same
without using threads?

-- 
Dum inter homines sumus, colamus humanitatem.
diff -up dwm-5.0.1/config.mk dwm-5.0.1-clock/config.mk
--- config.mk	2008-06-19 11:11:38.000000000 +0300
+++ config.mk	2008-07-10 17:57:48.000000000 +0300
@@ -16,7 +16,7 @@ XINERAMAFLAGS = -DXINERAMA
 
 # includes and libs
 INCS = -I. -I/usr/include -I${X11INC}
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} -lpthread
 
 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
diff -up dwm-5.0.1/dwm.c dwm-5.0.1-clock/dwm.c
--- dwm.c	2008-06-19 11:11:38.000000000 +0300
+++ dwm.c	2008-07-10 17:58:27.000000000 +0300
@@ -239,6 +239,7 @@ static Layout *lt = NULL;
 static Window root, barwin;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
+#include "clock.c"
 
 /* compile-time check if all tags fit into an uint bit array. */
 struct NumTags { char limitexceeded[sizeof(uint) * 8 < LENGTH(tags) ? -1 : 1]; };
@@ -1370,6 +1371,7 @@ setup(void) {
 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
 	XMapRaised(dpy, barwin);
 	strcpy(stext, "dwm-"VERSION);
+	clock_init();
 	drawbar();
 
 	/* EWMH support per view */
--- /dev/null	2008-06-29 22:46:41.000000000 +0300
+++ clock.c	2008-07-10 17:59:51.000000000 +0300
@@ -0,0 +1,40 @@
+#include <pthread.h>
+#include <time.h>
+#include <unistd.h>
+
+#define SHOWSECONDS
+
+#ifdef SHOWSECONDS
+#  define TIMEFMT "%d %b %T"
+#  define SLEEPDELAY 1000000
+#else
+#  define TIMEFMT "%d %b %R"
+#  define SLEEPDELAY 60000000
+#endif
+
+void *
+clock_run(void * arg)
+{
+	time_t t;
+	struct tm ctm;
+	char buf[256];
+	
+	while(1)
+	{
+		t = time(NULL);
+		localtime_r(&t, &ctm);
+		strftime(buf, 256, TIMEFMT, &ctm);
+		strcpy(stext, buf);
+		usleep(SLEEPDELAY);
+		drawbar();
+	}
+	return NULL;
+}
+
+void
+clock_init(void)
+{
+	pthread_t thread;
+	pthread_create(&thread, NULL, clock_run, NULL);
+	pthread_setschedprio(thread, 100);
+}
+

Reply via email to