Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
8.2 KiB

  1. #include "yajl_dumps.h"
  2. #include <stdint.h>
  3. int
  4. dump_tag(yajl_gen gen, const char *name, const int tag_mask)
  5. {
  6. // clang-format off
  7. YMAP(
  8. YSTR("bit_mask"); YINT(tag_mask);
  9. YSTR("name"); YSTR(name);
  10. )
  11. // clang-format on
  12. return 0;
  13. }
  14. int
  15. dump_tags(yajl_gen gen, int tags_len)
  16. {
  17. // clang-format off
  18. YARR(
  19. for (int i = 0; i < tags_len; i++)
  20. dump_tag(gen, tagicon(mons, i), 1 << i);
  21. )
  22. // clang-format on
  23. return 0;
  24. }
  25. int
  26. dump_client(yajl_gen gen, Client *c)
  27. {
  28. // clang-format off
  29. YMAP(
  30. YSTR("name"); YSTR(c->name);
  31. YSTR("tags"); YINT(c->tags);
  32. YSTR("window_id"); YINT(c->win);
  33. YSTR("monitor_number"); YINT(c->mon->num);
  34. YSTR("geometry"); YMAP(
  35. YSTR("current"); YMAP (
  36. YSTR("x"); YINT(c->x);
  37. YSTR("y"); YINT(c->y);
  38. YSTR("width"); YINT(c->w);
  39. YSTR("height"); YINT(c->h);
  40. )
  41. YSTR("old"); YMAP(
  42. YSTR("x"); YINT(c->oldx);
  43. YSTR("y"); YINT(c->oldy);
  44. YSTR("width"); YINT(c->oldw);
  45. YSTR("height"); YINT(c->oldh);
  46. )
  47. )
  48. YSTR("size_hints"); YMAP(
  49. YSTR("base"); YMAP(
  50. YSTR("width"); YINT(c->basew);
  51. YSTR("height"); YINT(c->baseh);
  52. )
  53. YSTR("step"); YMAP(
  54. YSTR("width"); YINT(c->incw);
  55. YSTR("height"); YINT(c->inch);
  56. )
  57. YSTR("max"); YMAP(
  58. YSTR("width"); YINT(c->maxw);
  59. YSTR("height"); YINT(c->maxh);
  60. )
  61. YSTR("min"); YMAP(
  62. YSTR("width"); YINT(c->minw);
  63. YSTR("height"); YINT(c->minh);
  64. )
  65. YSTR("aspect_ratio"); YMAP(
  66. YSTR("min"); YDOUBLE(c->mina);
  67. YSTR("max"); YDOUBLE(c->maxa);
  68. )
  69. )
  70. YSTR("border_width"); YMAP(
  71. YSTR("current"); YINT(c->bw);
  72. YSTR("old"); YINT(c->oldbw);
  73. )
  74. YSTR("states"); YMAP(
  75. YSTR("is_fixed"); YBOOL(c->isfixed);
  76. YSTR("is_floating"); YBOOL(c->isfloating);
  77. YSTR("is_urgent"); YBOOL(c->isurgent);
  78. YSTR("never_focus"); YBOOL(c->neverfocus);
  79. YSTR("old_state"); YBOOL(c->oldstate);
  80. YSTR("is_fullscreen"); YBOOL(c->isfullscreen);
  81. )
  82. )
  83. // clang-format on
  84. return 0;
  85. }
  86. int
  87. dump_monitor(yajl_gen gen, Monitor *mon, int is_selected)
  88. {
  89. // clang-format off
  90. YMAP(
  91. YSTR("master_factor"); YDOUBLE(mon->mfact);
  92. YSTR("num_master"); YINT(mon->nmaster);
  93. YSTR("num"); YINT(mon->num);
  94. YSTR("is_selected"); YBOOL(is_selected);
  95. YSTR("monitor_geometry"); YMAP(
  96. YSTR("x"); YINT(mon->mx);
  97. YSTR("y"); YINT(mon->my);
  98. YSTR("width"); YINT(mon->mw);
  99. YSTR("height"); YINT(mon->mh);
  100. )
  101. YSTR("window_geometry"); YMAP(
  102. YSTR("x"); YINT(mon->wx);
  103. YSTR("y"); YINT(mon->wy);
  104. YSTR("width"); YINT(mon->ww);
  105. YSTR("height"); YINT(mon->wh);
  106. )
  107. YSTR("tagset"); YMAP(
  108. YSTR("current"); YINT(mon->tagset[mon->seltags]);
  109. YSTR("old"); YINT(mon->tagset[mon->seltags ^ 1]);
  110. )
  111. YSTR("tag_state"); dump_tag_state(gen, mon->tagstate);
  112. YSTR("clients"); YMAP(
  113. YSTR("selected"); YINT(mon->sel ? mon->sel->win : 0);
  114. YSTR("stack"); YARR(
  115. for (Client* c = mon->stack; c; c = c->snext)
  116. YINT(c->win);
  117. )
  118. YSTR("all"); YARR(
  119. for (Client* c = mon->clients; c; c = c->next)
  120. YINT(c->win);
  121. )
  122. )
  123. YSTR("layout"); YMAP(
  124. YSTR("symbol"); YMAP(
  125. YSTR("current"); YSTR(mon->ltsymbol);
  126. YSTR("old"); YSTR(mon->lastltsymbol);
  127. )
  128. YSTR("address"); YMAP(
  129. YSTR("current"); YINT((uintptr_t)mon->lt[mon->sellt]);
  130. YSTR("old"); YINT((uintptr_t)mon->lt[mon->sellt ^ 1]);
  131. )
  132. )
  133. YSTR("bar"); YMAP(
  134. YSTR("y"); YINT(mon->bar->by);
  135. YSTR("is_shown"); YBOOL(mon->showbar);
  136. YSTR("is_top"); YBOOL(mon->bar->topbar);
  137. YSTR("window_id"); YINT(mon->bar->win);
  138. )
  139. )
  140. // clang-format on
  141. return 0;
  142. }
  143. int
  144. dump_monitors(yajl_gen gen, Monitor *mons, Monitor *selmon)
  145. {
  146. // clang-format off
  147. YARR(
  148. for (Monitor *mon = mons; mon; mon = mon->next) {
  149. if (mon == selmon)
  150. dump_monitor(gen, mon, 1);
  151. else
  152. dump_monitor(gen, mon, 0);
  153. }
  154. )
  155. // clang-format on
  156. return 0;
  157. }
  158. int
  159. dump_layouts(yajl_gen gen, const Layout layouts[], const int layouts_len)
  160. {
  161. // clang-format off
  162. YARR(
  163. for (int i = 0; i < layouts_len; i++) {
  164. YMAP(
  165. // Check for a NULL pointer. The cycle layouts patch adds an entry at
  166. // the end of the layouts array with a NULL pointer for the symbol
  167. YSTR("symbol"); YSTR((layouts[i].symbol ? layouts[i].symbol : ""));
  168. YSTR("address"); YINT((uintptr_t)(layouts + i));
  169. )
  170. }
  171. )
  172. // clang-format on
  173. return 0;
  174. }
  175. int
  176. dump_tag_state(yajl_gen gen, TagState state)
  177. {
  178. // clang-format off
  179. YMAP(
  180. YSTR("selected"); YINT(state.selected);
  181. YSTR("occupied"); YINT(state.occupied);
  182. YSTR("urgent"); YINT(state.urgent);
  183. )
  184. // clang-format on
  185. return 0;
  186. }
  187. int
  188. dump_tag_event(yajl_gen gen, int mon_num, TagState old_state,
  189. TagState new_state)
  190. {
  191. // clang-format off
  192. YMAP(
  193. YSTR("tag_change_event"); YMAP(
  194. YSTR("monitor_number"); YINT(mon_num);
  195. YSTR("old_state"); dump_tag_state(gen, old_state);
  196. YSTR("new_state"); dump_tag_state(gen, new_state);
  197. )
  198. )
  199. // clang-format on
  200. return 0;
  201. }
  202. int
  203. dump_client_focus_change_event(yajl_gen gen, Client *old_client,
  204. Client *new_client, int mon_num)
  205. {
  206. // clang-format off
  207. YMAP(
  208. YSTR("client_focus_change_event"); YMAP(
  209. YSTR("monitor_number"); YINT(mon_num);
  210. YSTR("old_win_id"); old_client == NULL ? YNULL() : YINT(old_client->win);
  211. YSTR("new_win_id"); new_client == NULL ? YNULL() : YINT(new_client->win);
  212. )
  213. )
  214. // clang-format on
  215. return 0;
  216. }
  217. int
  218. dump_layout_change_event(yajl_gen gen, const int mon_num,
  219. const char *old_symbol, const Layout *old_layout,
  220. const char *new_symbol, const Layout *new_layout)
  221. {
  222. // clang-format off
  223. YMAP(
  224. YSTR("layout_change_event"); YMAP(
  225. YSTR("monitor_number"); YINT(mon_num);
  226. YSTR("old_symbol"); YSTR(old_symbol);
  227. YSTR("old_address"); YINT((uintptr_t)old_layout);
  228. YSTR("new_symbol"); YSTR(new_symbol);
  229. YSTR("new_address"); YINT((uintptr_t)new_layout);
  230. )
  231. )
  232. // clang-format on
  233. return 0;
  234. }
  235. int
  236. dump_monitor_focus_change_event(yajl_gen gen, const int last_mon_num,
  237. const int new_mon_num)
  238. {
  239. // clang-format off
  240. YMAP(
  241. YSTR("monitor_focus_change_event"); YMAP(
  242. YSTR("old_monitor_number"); YINT(last_mon_num);
  243. YSTR("new_monitor_number"); YINT(new_mon_num);
  244. )
  245. )
  246. // clang-format on
  247. return 0;
  248. }
  249. int
  250. dump_focused_title_change_event(yajl_gen gen, const int mon_num,
  251. const Window client_id, const char *old_name,
  252. const char *new_name)
  253. {
  254. // clang-format off
  255. YMAP(
  256. YSTR("focused_title_change_event"); YMAP(
  257. YSTR("monitor_number"); YINT(mon_num);
  258. YSTR("client_window_id"); YINT(client_id);
  259. YSTR("old_name"); YSTR(old_name);
  260. YSTR("new_name"); YSTR(new_name);
  261. )
  262. )
  263. // clang-format on
  264. return 0;
  265. }
  266. int
  267. dump_client_state(yajl_gen gen, const ClientState *state)
  268. {
  269. // clang-format off
  270. YMAP(
  271. YSTR("old_state"); YBOOL(state->oldstate);
  272. YSTR("is_fixed"); YBOOL(state->isfixed);
  273. YSTR("is_floating"); YBOOL(state->isfloating);
  274. YSTR("is_fullscreen"); YBOOL(state->isfullscreen);
  275. YSTR("is_urgent"); YBOOL(state->isurgent);
  276. YSTR("never_focus"); YBOOL(state->neverfocus);
  277. )
  278. // clang-format on
  279. return 0;
  280. }
  281. int
  282. dump_focused_state_change_event(yajl_gen gen, const int mon_num,
  283. const Window client_id,
  284. const ClientState *old_state,
  285. const ClientState *new_state)
  286. {
  287. // clang-format off
  288. YMAP(
  289. YSTR("focused_state_change_event"); YMAP(
  290. YSTR("monitor_number"); YINT(mon_num);
  291. YSTR("client_window_id"); YINT(client_id);
  292. YSTR("old_state"); dump_client_state(gen, old_state);
  293. YSTR("new_state"); dump_client_state(gen, new_state);
  294. )
  295. )
  296. // clang-format on
  297. return 0;
  298. }
  299. int
  300. dump_error_message(yajl_gen gen, const char *reason)
  301. {
  302. // clang-format off
  303. YMAP(
  304. YSTR("result"); YSTR("error");
  305. YSTR("reason"); YSTR(reason);
  306. )
  307. // clang-format on
  308. return 0;
  309. }