]> git.sur5r.net Git - i3/i3/blobdiff - src/ipc.c
Refactor the interface of commands.c
[i3/i3] / src / ipc.c
index 5143695bc29bfeb7da4a58da5e7f39aecdf4e734..3733034dec5713ae6fabaef1988beadf83010088 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
  *
@@ -119,16 +119,18 @@ IPC_HANDLER(command) {
     char *command = scalloc(message_size + 1);
     strncpy(command, (const char*)message, message_size);
     LOG("IPC: received: *%s*\n", command);
-    char *reply = parse_cmd((const char*)command);
-    char *save_reply = reply;
+    struct CommandResult *command_output = parse_command((const char*)command);
     free(command);
 
+    if (command_output->needs_tree_render)
+        tree_render();
+
     /* If no reply was provided, we just use the default success message */
-    if (reply == NULL)
-        reply = "{\"success\":true}";
-    ipc_send_message(fd, strlen(reply), I3_IPC_REPLY_TYPE_COMMAND, (const uint8_t*)reply);
+    ipc_send_message(fd, strlen(command_output->json_output),
+                     I3_IPC_REPLY_TYPE_COMMAND,
+                     (const uint8_t*)command_output->json_output);
 
-    FREE(save_reply);
+    free(command_output->json_output);
 }
 
 static void dump_rect(yajl_gen gen, const char *name, Rect r) {
@@ -274,6 +276,22 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
     ystr("fullscreen_mode");
     y(integer, con->fullscreen_mode);
 
+    ystr("floating");
+    switch (con->floating) {
+        case FLOATING_AUTO_OFF:
+            ystr("auto_off");
+            break;
+        case FLOATING_AUTO_ON:
+            ystr("auto_on");
+            break;
+        case FLOATING_USER_OFF:
+            ystr("user_off");
+            break;
+        case FLOATING_USER_ON:
+            ystr("user_on");
+            break;
+    }
+
     ystr("swallows");
     y(array_open);
     Match *match;
@@ -295,6 +313,8 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
             y(map_open);
             ystr("id");
             y(integer, con->window->id);
+            ystr("restart_mode");
+            y(bool, true);
             y(map_close);
         }
     }
@@ -573,6 +593,36 @@ IPC_HANDLER(get_bar_config) {
             ystr("hide");
         else ystr("dock");
 
+        ystr("modifier");
+        switch (config->modifier) {
+            case M_CONTROL:
+                ystr("ctrl");
+                break;
+            case M_SHIFT:
+                ystr("shift");
+                break;
+            case M_MOD1:
+                ystr("Mod1");
+                break;
+            case M_MOD2:
+                ystr("Mod2");
+                break;
+            case M_MOD3:
+                ystr("Mod3");
+                break;
+            /*
+            case M_MOD4:
+                ystr("Mod4");
+                break;
+            */
+            case M_MOD5:
+                ystr("Mod5");
+                break;
+            default:
+                ystr("Mod4");
+                break;
+        }
+
         ystr("position");
         if (config->position == P_BOTTOM)
             ystr("bottom");
@@ -600,14 +650,18 @@ IPC_HANDLER(get_bar_config) {
         y(map_open);
         YSTR_IF_SET(background);
         YSTR_IF_SET(statusline);
-        YSTR_IF_SET(focused_workspace_text);
+        YSTR_IF_SET(focused_workspace_border);
         YSTR_IF_SET(focused_workspace_bg);
-        YSTR_IF_SET(active_workspace_text);
+        YSTR_IF_SET(focused_workspace_text);
+        YSTR_IF_SET(active_workspace_border);
         YSTR_IF_SET(active_workspace_bg);
-        YSTR_IF_SET(inactive_workspace_text);
+        YSTR_IF_SET(active_workspace_text);
+        YSTR_IF_SET(inactive_workspace_border);
         YSTR_IF_SET(inactive_workspace_bg);
-        YSTR_IF_SET(urgent_workspace_text);
+        YSTR_IF_SET(inactive_workspace_text);
+        YSTR_IF_SET(urgent_workspace_border);
         YSTR_IF_SET(urgent_workspace_bg);
+        YSTR_IF_SET(urgent_workspace_text);
         y(map_close);
 
 #undef YSTR_IF_SET
@@ -627,48 +681,6 @@ IPC_HANDLER(get_bar_config) {
     y(free);
 }
 
-/*
- * Formats the reply message for a GET_LOG_MARKERS request and sends it to the
- * client.
- *
- */
-IPC_HANDLER(get_log_markers) {
-#if YAJL_MAJOR >= 2
-    yajl_gen gen = yajl_gen_alloc(NULL);
-#else
-    yajl_gen gen = yajl_gen_alloc(NULL, NULL);
-#endif
-
-    int offset_next_write, offset_last_wrap, logsize;
-    get_log_markers(&offset_next_write, &offset_last_wrap, &logsize);
-
-    y(map_open);
-    ystr("offset_next_write");
-    y(integer, offset_next_write);
-
-    ystr("offset_last_wrap");
-    y(integer, offset_last_wrap);
-
-    ystr("shmname");
-    ystr(shmlogname);
-
-    ystr("size");
-    y(integer, logsize);
-
-    y(map_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, length, I3_IPC_REPLY_TYPE_LOG_MARKERS, payload);
-    y(free);
-}
-
 /*
  * Callback for the YAJL parser (will be called when a string is parsed).
  *
@@ -754,7 +766,7 @@ 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[8] = {
+handler_t handlers[7] = {
     handle_command,
     handle_get_workspaces,
     handle_subscribe,
@@ -762,7 +774,6 @@ handler_t handlers[8] = {
     handle_tree,
     handle_get_marks,
     handle_get_bar_config,
-    handle_get_log_markers
 };
 
 /*