dwmstatus.scm

dwm status printer in guile scheme
Log | Files | Refs | README

dwmstatus.scm (1331B)


      1 #! /bin/guile -s
      2 !#
      3 
      4 (use-modules (rnrs bytevectors))
      5 
      6 (define Time "")
      7 (define Message "")
      8 
      9 (define xsetrootname
     10   (lambda ()
     11     (system* "xsetroot" "-name" (string-append Message Time))))
     12 
     13 (define time-thread
     14   (call-with-new-thread
     15     (lambda ()
     16       (while #t
     17 	     (set! Time (strftime "%F %T" (localtime (current-time))))
     18 	     (xsetrootname)
     19 	     (sleep 1)))))
     20 
     21 (define message-thread
     22   (call-with-new-thread
     23     (lambda ()
     24       (define message-flush)
     25       (define sock-name "/tmp/dwmstatus.sock")
     26       (define sock (socket PF_UNIX SOCK_STREAM 0))
     27       (define sock2 0)
     28       (define rlen 0)
     29       (define buf (make-bytevector 2048 0))
     30       (define buf2 0)
     31       (if (access? sock-name F_OK) (delete-file sock-name))
     32       (bind sock AF_UNIX sock-name)
     33       (listen sock 16)
     34       (while #t
     35 	     (set! sock2 (car (accept sock)))
     36 	     (set! rlen (recv! sock2 buf))
     37 	     (set! buf2 (make-bytevector rlen 0))
     38 	     (bytevector-copy! buf 0 buf2 0 rlen)
     39 	     (set! Message (string-append (utf8->string buf2) " "))
     40 	     (xsetrootname)
     41 	     (close-port sock2)
     42 	     (if (thread? message-flush) (cancel-thread message-mlush))
     43 	     (set! message-flush (call-with-new-thread
     44 				  (lambda()
     45 				    (sleep 3)
     46 				    (set! Message "")))))
     47       (close sock))))
     48 
     49 (join-thread time-thread)
     50 (join-thread message-thread)