Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirlad55 committed Jul 17, 2020
2 parents 8bae2f1 + 4cd4afd commit 946b1a6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
9 changes: 3 additions & 6 deletions ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,11 @@ ipc_run_command(IPCClient *ipc_client, char *msg)
* prepares a reply with the properties of all of the monitors in JSON.
*/
static void
ipc_get_monitors(IPCClient *c, Monitor *mons)
ipc_get_monitors(IPCClient *c, Monitor *mons, Monitor *selmon)
{
yajl_gen gen;
ipc_reply_init_message(&gen);
YARR(
for (Monitor *mon = mons; mon; mon = mon->next)
dump_monitor(gen, mon);
)
dump_monitors(gen, mons, selmon);

ipc_reply_prepare_send_message(gen, c, IPC_TYPE_GET_MONITORS);
}
Expand Down Expand Up @@ -1124,7 +1121,7 @@ ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons,
return -1;

if (msg_type == IPC_TYPE_GET_MONITORS)
ipc_get_monitors(c, mons);
ipc_get_monitors(c, mons, selmon);
else if (msg_type == IPC_TYPE_GET_TAGS)
ipc_get_tags(c, tags, tags_len);
else if (msg_type == IPC_TYPE_GET_LAYOUTS)
Expand Down
37 changes: 30 additions & 7 deletions yajl_dumps.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#include "yajl_dumps.h"
#include <stdint.h>

int
dump_tag(yajl_gen gen, const char *name, const int tag_mask)
{
YMAP(
YSTR("bit_mask"); YINT(tag_mask);
YSTR("name"); YSTR(name);
)

return 0;
}

int
dump_tags(yajl_gen gen, const char *tags[], int tags_len)
{
YARR(
for (int i = 0; i < tags_len; i++) {
YMAP(
YSTR("bit_mask"); YINT(1 << i);
YSTR("name"); YSTR(tags[i]);
)
}
for (int i = 0; i < tags_len; i++)
dump_tag(gen, tags[i], 1 << i);
)

return 0;
Expand Down Expand Up @@ -82,12 +89,13 @@ dump_client(yajl_gen gen, Client *c)
}

int
dump_monitor(yajl_gen gen, Monitor *mon)
dump_monitor(yajl_gen gen, Monitor *mon, int is_selected)
{
YMAP(
YSTR("master_factor"); YDOUBLE(mon->mfact);
YSTR("num_master"); YINT(mon->nmaster);
YSTR("num"); YINT(mon->num);
YSTR("is_selected"); YBOOL(is_selected);

YSTR("monitor_geometry"); YMAP(
YSTR("x"); YINT(mon->mx);
Expand Down Expand Up @@ -144,6 +152,21 @@ dump_monitor(yajl_gen gen, Monitor *mon)
return 0;
}

int
dump_monitors(yajl_gen gen, Monitor *mons, Monitor *selmon)
{
YARR(
for (Monitor *mon = mons; mon; mon = mon->next) {
if (mon == selmon)
dump_monitor(gen, mon, 1);
else
dump_monitor(gen, mon, 0);
}
)

return 0;
}

int
dump_layouts(yajl_gen gen, const Layout layouts[], const int layouts_len)
{
Expand Down
6 changes: 5 additions & 1 deletion yajl_dumps.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
#define YARR(body) { yajl_gen_array_open(gen); body yajl_gen_array_close(gen); }
#define YMAP(body) { yajl_gen_map_open(gen); body yajl_gen_map_close(gen); }

int dump_tag(yajl_gen gen, const char *name, const int tag_mask);

int dump_tags(yajl_gen gen, const char *tags[], int tags_len);

int dump_client(yajl_gen gen, Client *c);

int dump_monitor(yajl_gen gen, Monitor *mon);
int dump_monitor(yajl_gen gen, Monitor *mon, int is_selected);

int dump_monitors(yajl_gen gen, Monitor *mons, Monitor *selmon);

int dump_layouts(yajl_gen gen, const Layout layouts[], const int layouts_len);

Expand Down

0 comments on commit 946b1a6

Please sign in to comment.