config.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <unistd.h>
  2. #include <X11/Xlib.h>
  3. #include "modules/status.h"
  4. #include "modules/clock.h"
  5. #include "modules/cpu.h"
  6. #include "modules/ram.h"
  7. #include "modules/network.h"
  8. #include "modules/batteries.h"
  9. static Layout
  10. layouts[] = {
  11. // FORMAT SIZE TYPE FUNCTION
  12. {" down: %0.1LfkB/s ", 32, type_long_double, {.Lf = get_down_kbps}},
  13. {" up: %0.1LfkB/s ", 32, type_long_double, {.Lf = get_up_kbps}},
  14. {" cpu: %0.1Lf%% ", 8, type_long_double, {.Lf = get_cpu}},
  15. {" ram: %0.1Lf%% ", 8, type_long_double, {.Lf = get_ram}},
  16. {" battery: %d%% ", 16, type_int, {.d = read_batteries}},
  17. {" time: %02d:", 16, type_int, {.d = get_hour}},
  18. {"%02d ", 8, type_int, {.d = get_minute}},
  19. };
  20. void
  21. set_status(char * str)
  22. {
  23. Display * dpy;
  24. if (!(dpy = XOpenDisplay(NULL))) {
  25. fprintf(stderr, "status: cannot open display.\n");
  26. return;
  27. }
  28. XStoreName(dpy, DefaultRootWindow(dpy), str);
  29. XSync(dpy, False);
  30. XCloseDisplay(dpy);
  31. }
  32. void
  33. update_arg(Arg * arg)
  34. {
  35. arg->last_time = get_time(NULL);
  36. arg->last_down_bytes = read_down_bytes(NULL);
  37. arg->last_up_bytes = read_up_bytes(NULL);
  38. long * jiffies = get_jiffies(NULL);
  39. arg->last_jiffies[0] = (long *) jiffies[0];
  40. arg->last_jiffies[1] = (long *) jiffies[1];
  41. sleep(1);
  42. }