randalltux

dwmstatus

Apr 4th, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5. #include <X11/Xlib.h>
  6.  
  7. static Display *dpy;
  8.  
  9.  
  10. void setstatus(char *str) {
  11.     XStoreName(dpy, DefaultRootWindow(dpy), str);
  12.     XSync(dpy, False);
  13. }
  14.  
  15. int getdatetime(char *status, size_t size) {
  16.     time_t result;
  17.     struct tm *resulttm;
  18.  
  19.     result = time(NULL);
  20.     resulttm = localtime(&result);
  21.    
  22.     return strftime(status, size, "\x06 %d.%m \x07//\x06 %I:%M  ", resulttm);
  23. }
  24.  
  25. int main(void) {
  26.     char status[100];
  27.     int l = 0;
  28.  
  29.     if (!(dpy = XOpenDisplay(NULL))) {
  30.         fprintf(stderr, "Cannot open display.\n");
  31.         return 1;
  32.     }
  33.  
  34.     for (;;sleep(2)) {
  35.         l = getdatetime(status, sizeof(status) - l);
  36.         setstatus(status);
  37.     }
  38.  
  39.     free(status);
  40.     XCloseDisplay(dpy);
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment