aslstatus.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef _ASLSTATUS_H
  2. #define _ASLSTATUS_H
  3. #include <stdio.h> /* FILE */
  4. #include <pthread.h> /* PTHREAD_MUTEX_INITIALIZER */
  5. #include <inttypes.h> /* uintmax_t in cpu_perc */
  6. #if USE_X
  7. # include <xcb/xcb.h>
  8. #endif
  9. #include "lib/util.h"
  10. #include "components/cpu.h"
  11. #include "components/wifi.h"
  12. #include "components/volume.h"
  13. #include "components/battery.h"
  14. #include "components/netspeed.h"
  15. #include "components/brightness.h"
  16. #define FUNC_ARGS (char *, const char *, uint32_t, static_data_t *)
  17. #define END \
  18. { \
  19. .pid = -1, .tid = 0, .data = { 0 }, \
  20. .static_data = { .cleanup = NULL, .data = NULL }, \
  21. .mutex = PTHREAD_MUTEX_INITIALIZER \
  22. }
  23. typedef void (*cleanup_func_t)(void *);
  24. typedef struct static_data_t {
  25. cleanup_func_t cleanup;
  26. void *data;
  27. } static_data_t;
  28. typedef void(*func_t) FUNC_ARGS;
  29. typedef struct func_data_t {
  30. func_t func;
  31. const char name[16];
  32. size_t static_size;
  33. } func_data_t;
  34. struct segment_t {
  35. pid_t pid;
  36. pthread_t tid;
  37. char data[BUFF_SZ];
  38. static_data_t static_data;
  39. pthread_mutex_t mutex;
  40. };
  41. struct arg_t {
  42. const func_data_t f;
  43. const char *fmt;
  44. const char *args;
  45. const uint32_t interval;
  46. struct segment_t segment;
  47. };
  48. #ifdef ASLSTATUS_H_NEED_COMP
  49. /* clang-format off */
  50. /* battery */
  51. void battery_perc FUNC_ARGS;
  52. #define battery_perc {battery_perc, "batt_percentage", sizeof(int)}
  53. void battery_state FUNC_ARGS;
  54. #define battery_state {battery_state, "batt_state", sizeof(int)}
  55. void battery_remaining FUNC_ARGS;
  56. #define battery_remaining \
  57. {battery_remaining, "batt_remaining", sizeof(struct remaining)}
  58. /* brightness */
  59. void brightness FUNC_ARGS;
  60. #define brightness {brightness, "brightness", sizeof(struct brightness_data)}
  61. #if USE_X
  62. /* bspwm */
  63. void bspwm_ws FUNC_ARGS;
  64. #define bspwm_ws {bspwm_ws, "bspwm", sizeof(int)}
  65. #endif
  66. /* cpu */
  67. void cpu_freq FUNC_ARGS;
  68. #define cpu_freq {cpu_freq, "cpu_freq", sizeof(int)}
  69. void cpu_perc FUNC_ARGS;
  70. #define cpu_perc {cpu_perc, "cpu_percentage", sizeof(struct cpu_data_t)}
  71. /* datetime */
  72. void datetime FUNC_ARGS;
  73. #define datetime {datetime, "datetime", 0}
  74. /* disk */
  75. void disk_free FUNC_ARGS;
  76. #define disk_free {disk_free, "disk_free", 0}
  77. void disk_perc FUNC_ARGS;
  78. #define disk_perc {disk_perc, "disk_percentage", 0}
  79. void disk_total FUNC_ARGS;
  80. #define disk_total {disk_total, "disk_total", 0}
  81. void disk_used FUNC_ARGS;
  82. #define disk_used {disk_used, "disk_used", 0}
  83. /* entropy */
  84. void entropy FUNC_ARGS;
  85. #define entropy {entropy, "entropy", sizeof(int)}
  86. /* hostname */
  87. void hostname FUNC_ARGS;
  88. #define hostname {hostname, "hostname", 0}
  89. /* ip */
  90. void ipv4 FUNC_ARGS;
  91. #define ipv4 {ipv4, "ipv4", 0}
  92. void ipv6 FUNC_ARGS;
  93. #define ipv6 {ipv6, "ipv6", 0}
  94. /* kernel_release */
  95. void kernel_release FUNC_ARGS;
  96. #define kernel_release {kernel_release, "kernel_release", 0}
  97. #if USE_X && USE_XKB
  98. /* keymap */
  99. void keymap FUNC_ARGS;
  100. #define keymap {keymap, "keymap", sizeof(char)}
  101. #endif
  102. /* load_avg */
  103. void load_avg FUNC_ARGS;
  104. #define load_avg {load_avg, "load_avg", 0}
  105. /* netspeeds */
  106. void netspeed_rx FUNC_ARGS;
  107. #define netspeed_rx {netspeed_rx, "netspeed_rx", sizeof(struct netspeed_data)}
  108. void netspeed_tx FUNC_ARGS;
  109. #define netspeed_tx {netspeed_tx, "netspeed_tx", sizeof(struct netspeed_data)}
  110. /* num_files */
  111. void num_files FUNC_ARGS;
  112. #define num_files {num_files, "num_files", 0}
  113. /* ram */
  114. void ram_free FUNC_ARGS;
  115. #define ram_free {ram_free, "ram_free", sizeof(int)}
  116. void ram_perc FUNC_ARGS;
  117. #define ram_perc {ram_perc, "ram_percentage", sizeof(int)}
  118. void ram_total FUNC_ARGS;
  119. #define ram_total {ram_total, "ram_total", 0}
  120. void ram_used FUNC_ARGS;
  121. #define ram_used {ram_used, "ram_used", sizeof(int)}
  122. /* run_command */
  123. void run_command FUNC_ARGS;
  124. #define run_command {run_command, "cmd", sizeof(pid_t)}
  125. /*
  126. * `cmd` thread name hardcoded to be used to run shell commands
  127. */
  128. /* swap */
  129. void swap_free FUNC_ARGS;
  130. #define swap_free {swap_free, "swap_free", sizeof(int)}
  131. void swap_perc FUNC_ARGS;
  132. #define swap_perc {swap_perc, "swap_percentage", sizeof(int)}
  133. void swap_total FUNC_ARGS;
  134. #define swap_total {swap_total, "swap_total", 0}
  135. void swap_used FUNC_ARGS;
  136. #define swap_used {swap_used, "swap_used", sizeof(int)}
  137. /* temperature */
  138. void temp FUNC_ARGS;
  139. #define temp {temp, "temperature", sizeof(int)}
  140. /* uptime */
  141. void uptime FUNC_ARGS;
  142. #define uptime {uptime, "uptime", 0}
  143. /* user */
  144. void gid FUNC_ARGS;
  145. #define gid {gid, "gid", 0}
  146. void uid FUNC_ARGS;
  147. #define uid {uid, "uid", 0}
  148. void username FUNC_ARGS;
  149. #define username {username, "username", 0}
  150. /* volume */
  151. void vol_perc FUNC_ARGS;
  152. #define vol_perc {vol_perc, "volume", VOLUME_STATIC_SIZE}
  153. /* wifi */
  154. void wifi_perc FUNC_ARGS;
  155. #define wifi_perc {wifi_perc, "wifi_percentage", sizeof(struct wifi_perc_data)}
  156. void wifi_essid FUNC_ARGS;
  157. #define wifi_essid {wifi_essid, "wifi_essid", sizeof(struct wifi_essid_data)}
  158. /* clang-format on */
  159. #endif /* ASLSTATUS_H_NO_COMP */
  160. #endif /* _ASLSTATUS_H */