commit 549749c4bc2f776a3463912e202a61d9ff22e78d Author: zavok <an2qzavok@gmail.com> Date: Thu, 25 Feb 2016 03:52:02 +0300 yep Diffstat:
A | README.md | | | 11 | +++++++++++ |
A | dwmstatus.scm | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md @@ -0,0 +1,11 @@ +[dwmstatus](http://dwm.suckless.org/dwmstatus/) implemented in Guile Scheme. + +Displays: +- date and time +- messages recieved through unix domain socket located at /tmp/dwmstatus.sock + +To send messages, use something like + printf "hello world"|nc -U /tmp/dwmstatus.sock + +Edit source to config and extend. + diff --git a/dwmstatus.scm b/dwmstatus.scm @@ -0,0 +1,52 @@ +#! /bin/guile -s +!# + +(use-modules (ice-9 threads)) +(use-modules (ice-9 format)) +(use-modules (rnrs bytevectors)) + +(define Time "") +(define Message "") + +(define XSetRootName + (lambda () + (system* "xsetroot" "-name" (string-append Message Time)))) + +(define TimeThread + (make-thread + (lambda () + (while #t + (set! Time (strftime "%F %T" (localtime (current-time)))) + (XSetRootName) + (sleep 1))))) + +(define MessageThread + (call-with-new-thread + (lambda () + (define MessageFlush) + (define SockName "/tmp/dwmstatus.sock") + (define sock (socket PF_UNIX SOCK_STREAM 0)) + (define sock2 0) + (define rlen 0) + (define buf (make-bytevector 2048 0)) + (define buf2 0) + (if (access? SockName F_OK) (delete-file SockName)) + (bind sock AF_UNIX SockName) + (listen sock 16) + (while #t + (set! sock2 (car (accept sock))) + (set! rlen (recv! sock2 buf)) + (set! buf2 (make-bytevector rlen 0)) + (bytevector-copy! buf 0 buf2 0 rlen) + (set! Message (string-append (utf8->string buf2) " ")) + (XSetRootName) + (close-port sock2) + (if (thread? MessageFlush) (cancel-thread MessageFlush)) + (set! MessageFlush (call-with-new-thread + (lambda() + (sleep 3) + (set! Message ""))))) + (close sock)))) + +(join-thread TimeThread) +(join-thread MessageThread)