dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

yajl_dumps.c (8463B)


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