]> git.sur5r.net Git - i3/i3/blobdiff - src/ipc.c
Allow the commands parser to use "number" arguments by making the stack typed.
[i3/i3] / src / ipc.c
index 9d3cf363085c7473585e40dcf24a04183d69276c..1a8d28ed218189c073be4c40e9113cf8a56d9414 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -84,7 +84,7 @@ void ipc_shutdown(void) {
 IPC_HANDLER(command) {
     /* To get a properly terminated buffer, we copy
      * message_size bytes out of the buffer */
-    char *command = scalloc(message_size + 1);
+    char *command = scalloc(message_size + 1, 1);
     strncpy(command, (const char *)message, message_size);
     LOG("IPC: received: *%s*\n", command);
     yajl_gen gen = yajl_gen_alloc(NULL);
@@ -121,56 +121,92 @@ static void dump_rect(yajl_gen gen, const char *name, Rect r) {
     y(map_close);
 }
 
-static void dump_binding(yajl_gen gen, Binding *bind) {
-    y(map_open);
-    ystr("input_code");
-    y(integer, bind->keycode);
-
-    ystr("input_type");
-    ystr((const char *)(bind->input_type == B_KEYBOARD ? "keyboard" : "mouse"));
-
-    ystr("symbol");
-    if (bind->symbol == NULL)
-        y(null);
-    else
-        ystr(bind->symbol);
-
-    ystr("command");
-    ystr(bind->command);
-
-    ystr("mods");
+static void dump_event_state_mask(yajl_gen gen, Binding *bind) {
     y(array_open);
-    for (int i = 0; i < 8; i++) {
-        if (bind->mods & (1 << i)) {
+    for (int i = 0; i < 20; i++) {
+        if (bind->event_state_mask & (1 << i)) {
             switch (1 << i) {
-                case XCB_MOD_MASK_SHIFT:
+                case XCB_KEY_BUT_MASK_SHIFT:
                     ystr("shift");
                     break;
-                case XCB_MOD_MASK_LOCK:
+                case XCB_KEY_BUT_MASK_LOCK:
                     ystr("lock");
                     break;
-                case XCB_MOD_MASK_CONTROL:
+                case XCB_KEY_BUT_MASK_CONTROL:
                     ystr("ctrl");
                     break;
-                case XCB_MOD_MASK_1:
+                case XCB_KEY_BUT_MASK_MOD_1:
                     ystr("Mod1");
                     break;
-                case XCB_MOD_MASK_2:
+                case XCB_KEY_BUT_MASK_MOD_2:
                     ystr("Mod2");
                     break;
-                case XCB_MOD_MASK_3:
+                case XCB_KEY_BUT_MASK_MOD_3:
                     ystr("Mod3");
                     break;
-                case XCB_MOD_MASK_4:
+                case XCB_KEY_BUT_MASK_MOD_4:
                     ystr("Mod4");
                     break;
-                case XCB_MOD_MASK_5:
+                case XCB_KEY_BUT_MASK_MOD_5:
                     ystr("Mod5");
                     break;
+                case XCB_KEY_BUT_MASK_BUTTON_1:
+                    ystr("Button1");
+                    break;
+                case XCB_KEY_BUT_MASK_BUTTON_2:
+                    ystr("Button2");
+                    break;
+                case XCB_KEY_BUT_MASK_BUTTON_3:
+                    ystr("Button3");
+                    break;
+                case XCB_KEY_BUT_MASK_BUTTON_4:
+                    ystr("Button4");
+                    break;
+                case XCB_KEY_BUT_MASK_BUTTON_5:
+                    ystr("Button5");
+                    break;
+                case (I3_XKB_GROUP_MASK_1 << 16):
+                    ystr("Group1");
+                    break;
+                case (I3_XKB_GROUP_MASK_2 << 16):
+                    ystr("Group2");
+                    break;
+                case (I3_XKB_GROUP_MASK_3 << 16):
+                    ystr("Group3");
+                    break;
+                case (I3_XKB_GROUP_MASK_4 << 16):
+                    ystr("Group4");
+                    break;
             }
         }
     }
     y(array_close);
+}
+
+static void dump_binding(yajl_gen gen, Binding *bind) {
+    y(map_open);
+    ystr("input_code");
+    y(integer, bind->keycode);
+
+    ystr("input_type");
+    ystr((const char *)(bind->input_type == B_KEYBOARD ? "keyboard" : "mouse"));
+
+    ystr("symbol");
+    if (bind->symbol == NULL)
+        y(null);
+    else
+        ystr(bind->symbol);
+
+    ystr("command");
+    ystr(bind->command);
+
+    // This key is only provided for compatibility, new programs should use
+    // event_state_mask instead.
+    ystr("mods");
+    dump_event_state_mask(gen, bind);
+
+    ystr("event_state_mask");
+    dump_event_state_mask(gen, bind);
 
     y(map_close);
 }
@@ -400,6 +436,9 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
     ystr("fullscreen_mode");
     y(integer, con->fullscreen_mode);
 
+    ystr("sticky");
+    y(bool, con->sticky);
+
     ystr("floating");
     switch (con->floating) {
         case FLOATING_AUTO_OFF:
@@ -814,6 +853,9 @@ IPC_HANDLER(get_version) {
     ystr("human_readable");
     ystr(i3_version);
 
+    ystr("loaded_config_file_name");
+    ystr(current_configpath);
+
     y(map_close);
 
     const unsigned char *payload;
@@ -852,7 +894,7 @@ IPC_HANDLER(get_bar_config) {
 
     /* To get a properly terminated buffer, we copy
      * message_size bytes out of the buffer */
-    char *bar_id = scalloc(message_size + 1);
+    char *bar_id = scalloc(message_size + 1, 1);
     strncpy(bar_id, (const char *)message, message_size);
     LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id);
     Barconfig *current, *config = NULL;
@@ -897,10 +939,10 @@ static int add_subscription(void *extra, const unsigned char *s,
     int event = client->num_events;
 
     client->num_events++;
-    client->events = realloc(client->events, client->num_events * sizeof(char *));
+    client->events = srealloc(client->events, client->num_events * sizeof(char *));
     /* We copy the string because it is not null-terminated and strndup()
      * is missing on some BSD systems */
-    client->events[event] = scalloc(len + 1);
+    client->events[event] = scalloc(len + 1, 1);
     memcpy(client->events[event], s, len);
 
     DLOG("client is now subscribed to:\n");
@@ -1057,13 +1099,13 @@ void ipc_new_client(EV_P_ struct ev_io *w, int revents) {
 
     set_nonblock(client);
 
-    struct ev_io *package = scalloc(sizeof(struct ev_io));
+    struct ev_io *package = scalloc(1, sizeof(struct ev_io));
     ev_io_init(package, ipc_receive_message, client, EV_READ);
     ev_io_start(EV_A_ package);
 
     DLOG("IPC: new client connected on fd %d\n", w->fd);
 
-    ipc_client *new = scalloc(sizeof(ipc_client));
+    ipc_client *new = scalloc(1, sizeof(ipc_client));
     new->fd = client;
 
     TAILQ_INSERT_TAIL(&all_clients, new, clients);
@@ -1084,7 +1126,7 @@ int ipc_create_socket(const char *filename) {
     char *copy = sstrdup(resolved);
     const char *dir = dirname(copy);
     if (!path_exists(dir))
-        mkdirp(dir);
+        mkdirp(dir, DEFAULT_DIR_MODE);
     free(copy);
 
     /* Unlink the unix domain socket before */