]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/config.c
i3bar: make modifier behave like floating_modifier
[i3/i3] / i3bar / src / config.c
index 65447e7ecaa14bf0f11af8d634f262261c29c28f..5e57e6d9b858f5710917b8a8a4f8446bb056ba73 100644 (file)
@@ -7,6 +7,8 @@
  * config.c: Parses the configuration (received from i3).
  *
  */
+#include "common.h"
+
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 
 #include <X11/Xlib.h>
 
-#include "common.h"
-
 static char *cur_key;
 static bool parsing_bindings;
+static bool parsing_tray_outputs;
 
 /*
  * Parse a key.
@@ -30,19 +31,22 @@ static bool parsing_bindings;
  */
 static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
     FREE(cur_key);
+    sasprintf(&(cur_key), "%.*s", keyLen, keyVal);
 
-    cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
-    strncpy(cur_key, (const char *)keyVal, keyLen);
-    cur_key[keyLen] = '\0';
-
-    if (strcmp(cur_key, "bindings") == 0)
+    if (strcmp(cur_key, "bindings") == 0) {
         parsing_bindings = true;
+    }
+
+    if (strcmp(cur_key, "tray_outputs") == 0) {
+        parsing_tray_outputs = true;
+    }
 
     return 1;
 }
 
 static int config_end_array_cb(void *params_) {
     parsing_bindings = false;
+    parsing_tray_outputs = false;
     return 1;
 }
 
@@ -93,31 +97,45 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
         return 0;
     }
 
+    if (parsing_tray_outputs) {
+        DLOG("Adding tray_output = %.*s to the list.\n", len, val);
+        tray_output_t *tray_output = scalloc(1, sizeof(tray_output_t));
+        sasprintf(&(tray_output->output), "%.*s", len, val);
+        TAILQ_INSERT_TAIL(&(config.tray_outputs), tray_output, tray_outputs);
+        return 1;
+    }
+
     if (!strcmp(cur_key, "mode")) {
         DLOG("mode = %.*s, len = %d\n", len, val, len);
-        config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
-                                                                                                   : (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
-                                                                                                                                                                      : M_INVISIBLE));
+        config.hide_on_modifier = (len == strlen("dock") && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
+                                                                                                                : (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
+                                                                                                                                                                                                : M_INVISIBLE));
         return 1;
     }
 
     if (!strcmp(cur_key, "hidden_state")) {
         DLOG("hidden_state = %.*s, len = %d\n", len, val, len);
-        config.hidden_state = (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
+        config.hidden_state = (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
         return 1;
     }
 
+    /* Kept for backwards compatibility. */
     if (!strcmp(cur_key, "modifier")) {
         DLOG("modifier = %.*s\n", len, val);
-        if (len == 5 && !strncmp((const char *)val, "shift", strlen("shift"))) {
+        if (len == strlen("none") && !strncmp((const char *)val, "none", strlen("none"))) {
+            config.modifier = XCB_NONE;
+            return 1;
+        }
+
+        if (len == strlen("shift") && !strncmp((const char *)val, "shift", strlen("shift"))) {
             config.modifier = ShiftMask;
             return 1;
         }
-        if (len == 4 && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
+        if (len == strlen("ctrl") && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
             config.modifier = ControlMask;
             return 1;
         }
-        if (len == 4 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
+        if (len == strlen("Mod") + 1 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
             switch (val[3]) {
                 case '1':
                     config.modifier = Mod1Mask;
@@ -128,16 +146,12 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
                 case '3':
                     config.modifier = Mod3Mask;
                     return 1;
-                /*
-                case '4':
-                    config.modifier = Mod4Mask;
-                    return 1;
-                */
                 case '5':
                     config.modifier = Mod5Mask;
                     return 1;
             }
         }
+
         config.modifier = Mod4Mask;
         return 1;
     }
@@ -146,7 +160,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
      * users updating from that version and restarting i3bar before i3. */
     if (!strcmp(cur_key, "wheel_up_cmd")) {
         DLOG("wheel_up_cmd = %.*s\n", len, val);
-        binding_t *binding = scalloc(sizeof(binding_t));
+        binding_t *binding = scalloc(1, sizeof(binding_t));
         binding->input_code = 4;
         sasprintf(&(binding->command), "%.*s", len, val);
         TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
@@ -157,7 +171,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
      * users updating from that version and restarting i3bar before i3. */
     if (!strcmp(cur_key, "wheel_down_cmd")) {
         DLOG("wheel_down_cmd = %.*s\n", len, val);
-        binding_t *binding = scalloc(sizeof(binding_t));
+        binding_t *binding = scalloc(1, sizeof(binding_t));
         binding->input_code = 5;
         sasprintf(&(binding->command), "%.*s", len, val);
         TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
@@ -166,18 +180,20 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
 
     if (!strcmp(cur_key, "position")) {
         DLOG("position = %.*s\n", len, val);
-        config.position = (len == 3 && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
+        config.position = (len == strlen("top") && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
         return 1;
     }
 
     if (!strcmp(cur_key, "status_command")) {
         DLOG("command = %.*s\n", len, val);
+        FREE(config.command);
         sasprintf(&config.command, "%.*s", len, val);
         return 1;
     }
 
     if (!strcmp(cur_key, "font")) {
         DLOG("font = %.*s\n", len, val);
+        FREE(config.fontname);
         sasprintf(&config.fontname, "%.*s", len, val);
         return 1;
     }
@@ -198,10 +214,13 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
         return 1;
     }
 
+    /* We keep the old single tray_output working for users who only restart i3bar
+     * after updating. */
     if (!strcmp(cur_key, "tray_output")) {
-        DLOG("tray_output %.*s\n", len, val);
-        FREE(config.tray_output);
-        sasprintf(&config.tray_output, "%.*s", len, val);
+        DLOG("Found deprecated key tray_output %.*s.\n", len, val);
+        tray_output_t *tray_output = scalloc(1, sizeof(tray_output_t));
+        sasprintf(&(tray_output->output), "%.*s", len, val);
+        TAILQ_INSERT_TAIL(&(config.tray_outputs), tray_output, tray_outputs);
         return 1;
     }
 
@@ -217,6 +236,9 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
     COLOR(statusline, bar_fg);
     COLOR(background, bar_bg);
     COLOR(separator, sep_fg);
+    COLOR(focused_statusline, focus_bar_fg);
+    COLOR(focused_background, focus_bar_bg);
+    COLOR(focused_separator, focus_sep_fg);
     COLOR(focused_workspace_border, focus_ws_border);
     COLOR(focused_workspace_bg, focus_ws_bg);
     COLOR(focused_workspace_text, focus_ws_fg);
@@ -243,6 +265,21 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
  *
  */
 static int config_boolean_cb(void *params_, int val) {
+    if (parsing_bindings) {
+        if (strcmp(cur_key, "release") == 0) {
+            binding_t *binding = TAILQ_LAST(&(config.bindings), bindings_head);
+            if (binding == NULL) {
+                ELOG("There is no binding to put the current command onto. This is a bug in i3.\n");
+                return 0;
+            }
+
+            binding->release = val;
+            return 1;
+        }
+
+        ELOG("Unknown key \"%s\" while parsing bar bindings.\n", cur_key);
+    }
+
     if (!strcmp(cur_key, "binding_mode_indicator")) {
         DLOG("binding_mode_indicator = %d\n", val);
         config.disable_binding_mode_indicator = !val;
@@ -261,6 +298,12 @@ static int config_boolean_cb(void *params_, int val) {
         return 1;
     }
 
+    if (!strcmp(cur_key, "strip_workspace_name")) {
+        DLOG("strip_workspace_name = %d\n", val);
+        config.strip_ws_name = val;
+        return 1;
+    }
+
     if (!strcmp(cur_key, "verbose")) {
         DLOG("verbose = %d\n", val);
         config.verbose = val;
@@ -277,7 +320,7 @@ static int config_boolean_cb(void *params_, int val) {
 static int config_integer_cb(void *params_, long long val) {
     if (parsing_bindings) {
         if (strcmp(cur_key, "input_code") == 0) {
-            binding_t *binding = scalloc(sizeof(binding_t));
+            binding_t *binding = scalloc(1, sizeof(binding_t));
             binding->input_code = val;
             TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
 
@@ -294,6 +337,12 @@ static int config_integer_cb(void *params_, long long val) {
         return 1;
     }
 
+    if (!strcmp(cur_key, "modifier")) {
+        DLOG("modifier = %lld\n", val);
+        config.modifier = (uint32_t)val;
+        return 1;
+    }
+
     return 0;
 }
 
@@ -317,6 +366,7 @@ void parse_config_json(char *json) {
     handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
 
     TAILQ_INIT(&(config.bindings));
+    TAILQ_INIT(&(config.tray_outputs));
 
     state = yajl_parse(handle, (const unsigned char *)json, strlen(json));
 
@@ -346,6 +396,9 @@ void free_colors(struct xcb_color_strings_t *colors) {
     FREE_COLOR(bar_fg);
     FREE_COLOR(bar_bg);
     FREE_COLOR(sep_fg);
+    FREE_COLOR(focus_bar_fg);
+    FREE_COLOR(focus_bar_bg);
+    FREE_COLOR(focus_sep_fg);
     FREE_COLOR(active_ws_fg);
     FREE_COLOR(active_ws_bg);
     FREE_COLOR(active_ws_border);