]> git.sur5r.net Git - i3/i3/blobdiff - src/ipc.c
Merge branch 'tree' into next
[i3/i3] / src / ipc.c
index b76d2bb186c31aa6ae88ad6835da47897b1ff17c..b2cd482c3f1ba4023a3d15d09b4db7b90540e472 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -3,7 +3,7 @@
  *
  * i3 - an improved dynamic tiling window manager
  *
- * © 2009-2010 Michael Stapelberg and contributors
+ * © 2009-2011 Michael Stapelberg and contributors
  *
  * See file LICENSE for license information.
  *
@@ -17,6 +17,7 @@
 #include <ev.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_parse.h>
+#include <yajl/yajl_version.h>
 
 #include "all.h"
 
@@ -76,7 +77,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 +148,6 @@ IPC_HANDLER(command) {
     strncpy(command, (const char*)message, message_size);
     LOG("IPC: received: *%s*\n", command);
     const char *reply = parse_cmd((const char*)command);
-    tree_render();
     free(command);
 
     /* If no reply was provided, we just use the default success message */
@@ -193,19 +193,47 @@ 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);
 
     ystr("focused");
-    y(integer, (con == focused));
+    y(bool, (con == focused));
 
     ystr("layout");
-    y(integer, con->layout);
+    switch (con->layout) {
+        case L_DEFAULT:
+            ystr("default");
+            break;
+        case L_STACKED:
+            ystr("stacked");
+            break;
+        case L_TABBED:
+            ystr("tabbed");
+            break;
+        case L_DOCKAREA:
+            ystr("dockarea");
+            break;
+        case L_OUTPUT:
+            ystr("output");
+            break;
+    }
 
     ystr("border");
-    y(integer, con->border_style);
+    switch (con->border_style) {
+        case BS_NORMAL:
+            ystr("normal");
+            break;
+        case BS_NONE:
+            ystr("none");
+            break;
+        case BS_1PIXEL:
+            ystr("1pixel");
+            break;
+    }
 
     dump_rect(gen, "rect", con->rect);
     dump_rect(gen, "window_rect", con->window_rect);
@@ -282,12 +310,20 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
 
 IPC_HANDLER(tree) {
     setlocale(LC_NUMERIC, "C");
+#if YAJL_MAJOR >= 2
+    yajl_gen gen = yajl_gen_alloc(NULL);
+#else
     yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
     dump_node(gen, croot, false);
     setlocale(LC_NUMERIC, "");
 
     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_TREE, length);
@@ -300,7 +336,11 @@ IPC_HANDLER(tree) {
  *
  */
 IPC_HANDLER(get_workspaces) {
+#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 *focused_ws = con_get_workspace(focused);
@@ -351,7 +391,11 @@ IPC_HANDLER(get_workspaces) {
     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_WORKSPACES, length);
@@ -364,7 +408,11 @@ IPC_HANDLER(get_workspaces) {
  *
  */
 IPC_HANDLER(get_outputs) {
+#if YAJL_MAJOR >= 2
+    yajl_gen gen = yajl_gen_alloc(NULL);
+#else
     yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
     y(array_open);
 
     Output *output;
@@ -391,7 +439,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);
 
@@ -401,7 +449,11 @@ IPC_HANDLER(get_outputs) {
     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_OUTPUTS, length);
@@ -412,8 +464,13 @@ IPC_HANDLER(get_outputs) {
  * Callback for the YAJL parser (will be called when a string is parsed).
  *
  */
+#if YAJL_MAJOR < 2
 static int add_subscription(void *extra, const unsigned char *s,
                             unsigned int len) {
+#else
+static int add_subscription(void *extra, const unsigned char *s,
+                            size_t len) {
+#endif
     ipc_client *client = extra;
 
     DLOG("should add subscription to extra %p, sub %.*s\n", client, len, s);
@@ -463,7 +520,11 @@ IPC_HANDLER(subscribe) {
     memset(&callbacks, 0, sizeof(yajl_callbacks));
     callbacks.yajl_string = add_subscription;
 
+#if YAJL_MAJOR >= 2
+    p = yajl_alloc(&callbacks, NULL, (void*)client);
+#else
     p = yajl_alloc(&callbacks, NULL, NULL, (void*)client);
+#endif
     stat = yajl_parse(p, (const unsigned char*)message, message_size);
     if (stat != yajl_status_ok) {
         unsigned char *err;
@@ -563,7 +624,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
         n -= strlen(I3_IPC_MAGIC);
 
         /* The next 32 bit after the magic are the message size */
-        uint32_t message_size = *((uint32_t*)message);
+        uint32_t message_size;
+        memcpy(&message_size, (uint32_t*)message, sizeof(uint32_t));
         message += sizeof(uint32_t);
         n -= sizeof(uint32_t);
 
@@ -573,7 +635,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
         }
 
         /* The last 32 bits of the header are the message type */
-        uint32_t message_type = *((uint32_t*)message);
+        uint32_t message_type;
+        memcpy(&message_type, (uint32_t*)message, sizeof(uint32_t));
         message += sizeof(uint32_t);
         n -= sizeof(uint32_t);
 
@@ -629,7 +692,6 @@ int ipc_create_socket(const char *filename) {
     int sockfd;
 
     FREE(current_socketpath);
-    current_socketpath = NULL;
 
     char *resolved = resolve_tilde(filename);
     DLOG("Creating IPC-socket at %s\n", resolved);