]> git.sur5r.net Git - i3/i3/commitdiff
Ported over some message types from -next.
authorFernando Tarlá Cardoso Lemos <fernandotcl@gmail.com>
Sat, 20 Nov 2010 21:30:53 +0000 (19:30 -0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 21 Nov 2010 20:36:19 +0000 (21:36 +0100)
include/i3/ipc.h
src/ipc.c

index 0046b6376aea8512caf1ef205bde78147354e3fd..e81f9a155ad5e7254a631c1fb04d7a6a172e6a48 100644 (file)
 #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.
index fd4f4fd8e1e6ab94e012b3f7e10593b4de7cfeec..fd4966ced71f9e19b73b1f0ed97e3dd835cf779e 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -239,7 +239,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
 }
 
 IPC_HANDLER(tree) {
-        printf("tree\n");
         yajl_gen gen = yajl_gen_alloc(NULL, NULL);
         dump_node(gen, croot, false);
 
@@ -252,68 +251,66 @@ IPC_HANDLER(tree) {
 
 }
 
-#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);
 }
 
 /*
@@ -322,48 +319,50 @@ IPC_HANDLER(get_workspaces) {
  *
  */
 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);
 }
 
 /*
@@ -441,12 +440,14 @@ IPC_HANDLER(subscribe) {
         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
 };