X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fipc.c;h=031ee9ab5d78bea6369b740bdc84f760fb734c99;hb=db33da225842fe8c3be296b48aba6e9d1bbe0c0d;hp=fa3513bc352ee74dba2879ff644d981c265943f5;hpb=51bfdbf0a840833830030c1752a4ea6d414b9347;p=i3%2Fi3 diff --git a/src/ipc.c b/src/ipc.c index fa3513bc..031ee9ab 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -59,8 +59,10 @@ static bool mkdirp(const char *path) { copy[strlen(copy)-1] = '\0'; char *sep = strrchr(copy, '/'); - if (sep == NULL) + if (sep == NULL) { + FREE(copy); return false; + } *sep = '\0'; bool result = false; if (mkdirp(copy)) @@ -77,7 +79,7 @@ static void ipc_send_message(int fd, const unsigned char *payload, char msg[buffer_size]; char *walk = msg; - strcpy(walk, "i3-ipc"); + strncpy(walk, "i3-ipc", buffer_size - 1); walk += strlen("i3-ipc"); memcpy(walk, &message_size, sizeof(uint32_t)); walk += sizeof(uint32_t); @@ -147,7 +149,8 @@ IPC_HANDLER(command) { char *command = scalloc(message_size + 1); strncpy(command, (const char*)message, message_size); LOG("IPC: received: *%s*\n", command); - const char *reply = parse_cmd((const char*)command); + char *reply = parse_cmd((const char*)command); + char *save_reply = reply; free(command); /* If no reply was provided, we just use the default success message */ @@ -155,6 +158,8 @@ IPC_HANDLER(command) { reply = "{\"success\":true}"; ipc_send_message(fd, (const unsigned char*)reply, I3_IPC_REPLY_TYPE_COMMAND, strlen(reply)); + + FREE(save_reply); } static void dump_rect(yajl_gen gen, const char *name, Rect r) { @@ -193,13 +198,20 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { } ystr("percent"); - y(double, con->percent); + if (con->percent == 0.0) + y(null); + else y(double, con->percent); ystr("urgent"); - y(integer, con->urgent); + y(bool, con->urgent); + + if (con->mark != NULL) { + ystr("mark"); + ystr(con->mark); + } ystr("focused"); - y(integer, (con == focused)); + y(bool, (con == focused)); ystr("layout"); switch (con->layout) { @@ -238,7 +250,10 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { dump_rect(gen, "geometry", con->geometry); ystr("name"); - ystr(con->name); + if (con->window && con->window->name_json) + ystr(con->window->name_json); + else + ystr(con->name); if (con->type == CT_WORKSPACE) { ystr("num"); @@ -269,7 +284,7 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { ystr("focus"); y(array_open); - TAILQ_FOREACH(node, &(con->focus_head), nodes) { + TAILQ_FOREACH(node, &(con->focus_head), focused) { y(integer, (long int)node); } y(array_close); @@ -328,6 +343,7 @@ IPC_HANDLER(tree) { y(free); } + /* * Formats the reply message for a GET_WORKSPACES request and sends it to the * client @@ -437,7 +453,7 @@ IPC_HANDLER(get_outputs) { ystr("current_workspace"); Con *ws = NULL; - if (output->con && (ws = con_get_fullscreen_con(output->con))) + if (output->con && (ws = con_get_fullscreen_con(output->con, CF_OUTPUT))) ystr(ws->name); else y(null); @@ -458,6 +474,38 @@ IPC_HANDLER(get_outputs) { y(free); } +/* + * Formats the reply message for a GET_MARKS request and sends it to the + * client + * + */ +IPC_HANDLER(get_marks) { +#if YAJL_MAJOR >= 2 + yajl_gen gen = yajl_gen_alloc(NULL); +#else + yajl_gen gen = yajl_gen_alloc(NULL, NULL); +#endif + y(array_open); + + Con *con; + TAILQ_FOREACH(con, &all_cons, all_cons) + if (con->mark != NULL) + ystr(con->mark); + + y(array_close); + + const unsigned char *payload; +#if YAJL_MAJOR >= 2 + size_t length; +#else + unsigned int length; +#endif + y(get_buf, &payload, &length); + + ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_MARKS, length); + y(free); +} + /* * Callback for the YAJL parser (will be called when a string is parsed). * @@ -545,12 +593,13 @@ IPC_HANDLER(subscribe) { /* The index of each callback function corresponds to the numeric * value of the message type (see include/i3/ipc.h) */ -handler_t handlers[5] = { +handler_t handlers[6] = { handle_command, handle_get_workspaces, handle_subscribe, handle_get_outputs, - handle_tree + handle_tree, + handle_get_marks }; /* @@ -673,7 +722,7 @@ void ipc_new_client(EV_P_ struct ev_io *w, int revents) { ev_io_init(package, ipc_receive_message, client, EV_READ); ev_io_start(EV_A_ package); - DLOG("IPC: new client connected\n"); + DLOG("IPC: new client connected on fd %d\n", w->fd); ipc_client *new = scalloc(sizeof(ipc_client)); new->fd = client;