#define I3_IPC_MESSAGE_TYPE_COMMAND 0
/** Requests the current workspaces from i3 */
-#define I3_IPC_MESSAGE_TYPE_GET_TREE 1
+#define I3_IPC_MESSAGE_TYPE_GET_WORKSPACES 1
+
+/** Subscribe to the specified events */
+#define I3_IPC_MESSAGE_TYPE_SUBSCRIBE 2
+
+/** Requests the current outputs from i3 */
+#define I3_IPC_MESSAGE_TYPE_GET_OUTPUTS 3
+
+/** Requests the tree layout from i3 */
+#define I3_IPC_MESSAGE_TYPE_GET_TREE 4
/*
#define I3_IPC_REPLY_TYPE_COMMAND 0
/** Workspaces reply type */
-#define I3_IPC_REPLY_TYPE_TREE 1
+#define I3_IPC_REPLY_TYPE_WORKSPACES 1
+
+/** Subscription reply type */
+#define I3_IPC_REPLY_TYPE_SUBSCRIBE 2
+
+/** Outputs reply type */
+#define I3_IPC_REPLY_TYPE_OUTPUTS 3
+
+/** Tree reply type */
+#define I3_IPC_REPLY_TYPE_TREE 4
+
/*
* Events from i3 to clients. Events have the first bit set high.
}
IPC_HANDLER(tree) {
- printf("tree\n");
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
dump_node(gen, croot, false);
}
-#if 0
/*
* Formats the reply message for a GET_WORKSPACES request and sends it to the
* client
*
*/
IPC_HANDLER(get_workspaces) {
- Workspace *ws;
+ yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+ y(array_open);
- Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack));
- if (last_focused == SLIST_END(&(c_ws->focus_stack)))
- last_focused = NULL;
+ Con *focused_ws = con_get_workspace(focused);
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
- y(array_open);
-
- TAILQ_FOREACH(ws, workspaces, workspaces) {
- if (ws->output == NULL)
- continue;
+ Con *output;
+ TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
+ Con *ws;
+ TAILQ_FOREACH(ws, &(output->nodes_head), nodes) {
+ assert(ws->type == CT_WORKSPACE);
+ y(map_open);
- y(map_open);
- ystr("num");
- y(integer, ws->num + 1);
+ ystr("num");
+ y(integer, con_num_children(ws));
- ystr("name");
- ystr(ws->utf8_name);
+ ystr("name");
+ ystr(ws->name);
- ystr("visible");
- y(bool, ws->output->current_workspace == ws);
+ ystr("visible");
+ y(bool, workspace_is_visible(ws));
- ystr("focused");
- y(bool, c_ws == ws);
+ ystr("focused");
+ y(bool, ws == focused_ws);
- ystr("rect");
- y(map_open);
- ystr("x");
- y(integer, ws->rect.x);
- ystr("y");
- y(integer, ws->rect.y);
- ystr("width");
- y(integer, ws->rect.width);
- ystr("height");
- y(integer, ws->rect.height);
- y(map_close);
+ ystr("rect");
+ y(map_open);
+ ystr("x");
+ y(integer, ws->rect.x);
+ ystr("y");
+ y(integer, ws->rect.y);
+ ystr("width");
+ y(integer, ws->rect.width);
+ ystr("height");
+ y(integer, ws->rect.height);
+ y(map_close);
- ystr("output");
- ystr(ws->output->name);
+ ystr("output");
+ ystr(output->name);
- ystr("urgent");
- y(bool, ws->urgent);
+ ystr("urgent");
+ y(bool, ws->urgent);
- y(map_close);
+ y(map_close);
}
+ }
- y(array_close);
+ y(array_close);
- const unsigned char *payload;
- unsigned int length;
- y(get_buf, &payload, &length);
+ const unsigned char *payload;
+ unsigned int length;
+ y(get_buf, &payload, &length);
- ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
- y(free);
+ ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
+ y(free);
}
/*
*
*/
IPC_HANDLER(get_outputs) {
- Output *output;
+ yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+ y(array_open);
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
- y(array_open);
+ Output *output;
+ TAILQ_FOREACH(output, &outputs, outputs) {
+ y(map_open);
- TAILQ_FOREACH(output, &outputs, outputs) {
- y(map_open);
-
- ystr("name");
- ystr(output->name);
-
- ystr("active");
- y(bool, output->active);
-
- ystr("rect");
- y(map_open);
- ystr("x");
- y(integer, output->rect.x);
- ystr("y");
- y(integer, output->rect.y);
- ystr("width");
- y(integer, output->rect.width);
- ystr("height");
- y(integer, output->rect.height);
- y(map_close);
-
- ystr("current_workspace");
- if (output->current_workspace == NULL)
- y(null);
- else y(integer, output->current_workspace->num + 1);
-
- y(map_close);
- }
+ ystr("name");
+ ystr(output->name);
- y(array_close);
+ ystr("active");
+ y(bool, output->active);
- const unsigned char *payload;
- unsigned int length;
- y(get_buf, &payload, &length);
+ ystr("rect");
+ y(map_open);
+ ystr("x");
+ y(integer, output->rect.x);
+ ystr("y");
+ y(integer, output->rect.y);
+ ystr("width");
+ y(integer, output->rect.width);
+ ystr("height");
+ y(integer, output->rect.height);
+ y(map_close);
- ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
- y(free);
+ /*
+ * XXX
+ * No idea how to handle this, where should we get this data from?
+ * I think we might need to keep a reference to the CT_OUTPUT Con in Output
+ */
+ ystr("current_workspace");
+ y(null);
+
+ y(map_close);
+ }
+
+ y(array_close);
+
+ const unsigned char *payload;
+ unsigned int length;
+ y(get_buf, &payload, &length);
+
+ ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
+ y(free);
}
/*
ipc_send_message(fd, (const unsigned char*)reply,
I3_IPC_REPLY_TYPE_SUBSCRIBE, strlen(reply));
}
-#endif
/* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */
-handler_t handlers[2] = {
+handler_t handlers[5] = {
handle_command,
+ handle_get_workspaces,
+ handle_subscribe,
+ handle_get_outputs,
handle_tree
};