]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/config.c
Merge branch 'master' into next
[i3/i3] / i3bar / src / config.c
index 179bc4642c47d2d23af6e0105b2e71b7d14ac926..0e6ba3f1b2c7e8687e08235b772b9abf7ba7d51d 100644 (file)
@@ -2,12 +2,9 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3bar - an xcb-based status- and ws-bar for i3
+ * © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
  *
- * © 2010-2011 Axel Wagner and contributors
- *
- * See file LICENSE for license information
- *
- * src/outputs.c: Maintaining the output-list
+ * config.c: Parses the configuration (received from i3).
  *
  */
 #include <string.h>
@@ -18,6 +15,8 @@
 #include <yajl/yajl_parse.h>
 #include <yajl/yajl_version.h>
 
+#include <X11/Xlib.h>
+
 #include "common.h"
 
 static char *cur_key;
@@ -63,17 +62,61 @@ static int config_null_cb(void *params_) {
  *
  */
 #if YAJL_MAJOR >= 2
-static int config_string_cb(void *params_, const unsigned char *val, size_t len) {
+static int config_string_cb(void *params_, const unsigned char *val, size_t _len) {
 #else
-static int config_string_cb(void *params_, const unsigned char *val, unsigned int len) {
+static int config_string_cb(void *params_, const unsigned char *val, unsigned int _len) {
 #endif
-    /* The id is ignored, we already have it in config.bar_id */
-    if (!strcmp(cur_key, "id"))
+    int len = (int)_len;
+    /* The id and socket_path are ignored, we already know them. */
+    if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path"))
         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, "hide", strlen("hide")));
+        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));
+        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);
+        return 1;
+    }
+
+    if (!strcmp(cur_key, "modifier")) {
+        DLOG("modifier = %.*s\n", len, val);
+        if (len == 5 && !strncmp((const char*)val, "shift", strlen("shift"))) {
+            config.modifier = ShiftMask;
+            return 1;
+        }
+        if (len == 4 && !strncmp((const char*)val, "ctrl", strlen("ctrl"))) {
+            config.modifier = ControlMask;
+            return 1;
+        }
+        if (len == 4 && !strncmp((const char*)val, "Mod", strlen("Mod"))) {
+            switch (val[3]) {
+                case '1':
+                    config.modifier = Mod1Mask;
+                    return 1;
+                case '2':
+                    config.modifier = Mod2Mask;
+                    return 1;
+                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;
     }
 
@@ -84,31 +127,30 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
     }
 
     if (!strcmp(cur_key, "status_command")) {
-        /* We cannot directly start the child here, because start_child() also
-         * needs to be run when no command was specified (to setup stdin).
-         * Therefore we save the command in 'config' and access it later in
-         * got_bar_config() */
         DLOG("command = %.*s\n", len, val);
-        asprintf(&config.command, "%.*s", len, val);
+        sasprintf(&config.command, "%.*s", len, val);
         return 1;
     }
 
     if (!strcmp(cur_key, "font")) {
         DLOG("font = %.*s\n", len, val);
-        asprintf(&config.fontname, "%.*s", len, val);
+        sasprintf(&config.fontname, "%.*s", len, val);
         return 1;
     }
 
     if (!strcmp(cur_key, "outputs")) {
-        printf("+output %.*s\n", len, val);
-        /* XXX: these are not implemented yet */
+        DLOG("+output %.*s\n", len, val);
+        int new_num_outputs = config.num_outputs + 1;
+        config.outputs = srealloc(config.outputs, sizeof(char*) * new_num_outputs);
+        sasprintf(&config.outputs[config.num_outputs], "%.*s", len, val);
+        config.num_outputs = new_num_outputs;
         return 1;
     }
 
     if (!strcmp(cur_key, "tray_output")) {
         DLOG("tray_output %.*s\n", len, val);
         FREE(config.tray_output);
-        asprintf(&config.tray_output, "%.*s", len, val);
+        sasprintf(&config.tray_output, "%.*s", len, val);
         return 1;
     }
 
@@ -116,21 +158,26 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
     do { \
         if (!strcmp(cur_key, #json_name)) { \
             DLOG(#json_name " = " #struct_name " = %.*s\n", len, val); \
-            asprintf(&(config.colors.struct_name), "%.*s", len, val); \
+            sasprintf(&(config.colors.struct_name), "%.*s", len, val); \
             return 1; \
         } \
     } while (0)
 
     COLOR(statusline, bar_fg);
     COLOR(background, bar_bg);
-    COLOR(focused_workspace_text, focus_ws_fg);
+    COLOR(separator, sep_fg);
+    COLOR(focused_workspace_border, focus_ws_border);
     COLOR(focused_workspace_bg, focus_ws_bg);
-    COLOR(active_workspace_text, active_ws_fg);
+    COLOR(focused_workspace_text, focus_ws_fg);
+    COLOR(active_workspace_border, active_ws_border);
     COLOR(active_workspace_bg, active_ws_bg);
-    COLOR(inactive_workspace_text, inactive_ws_fg);
+    COLOR(active_workspace_text, active_ws_fg);
+    COLOR(inactive_workspace_border, inactive_ws_border);
     COLOR(inactive_workspace_bg, inactive_ws_bg);
-    COLOR(urgent_workspace_text, urgent_ws_fg);
+    COLOR(inactive_workspace_text, inactive_ws_fg);
+    COLOR(urgent_workspace_border, urgent_ws_border);
     COLOR(urgent_workspace_bg, urgent_ws_bg);
+    COLOR(urgent_workspace_text, urgent_ws_fg);
 
     printf("got unexpected string %.*s for cur_key = %s\n", len, val, cur_key);
 
@@ -142,6 +189,12 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
  *
  */
 static int config_boolean_cb(void *params_, int val) {
+    if (!strcmp(cur_key, "binding_mode_indicator")) {
+        DLOG("binding_mode_indicator = %d\n", val);
+        config.disable_binding_mode_indicator = !val;
+        return 1;
+    }
+
     if (!strcmp(cur_key, "workspace_buttons")) {
         DLOG("workspace_buttons = %d\n", val);
         config.disable_ws = !val;
@@ -159,17 +212,10 @@ static int config_boolean_cb(void *params_, int val) {
 
 /* A datastructure to pass all these callbacks to yajl */
 static yajl_callbacks outputs_callbacks = {
-    &config_null_cb,
-    &config_boolean_cb,
-    NULL,
-    NULL,
-    NULL,
-    &config_string_cb,
-    NULL,
-    &config_map_key_cb,
-    NULL,
-    NULL,
-    NULL
+    .yajl_null = config_null_cb,
+    .yajl_boolean = config_boolean_cb,
+    .yajl_string = config_string_cb,
+    .yajl_map_key = config_map_key_cb,
 };
 
 /*
@@ -218,14 +264,19 @@ void free_colors(struct xcb_color_strings_t *colors) {
     } while (0)
     FREE_COLOR(bar_fg);
     FREE_COLOR(bar_bg);
+    FREE_COLOR(sep_fg);
     FREE_COLOR(active_ws_fg);
     FREE_COLOR(active_ws_bg);
+    FREE_COLOR(active_ws_border);
     FREE_COLOR(inactive_ws_fg);
     FREE_COLOR(inactive_ws_bg);
+    FREE_COLOR(inactive_ws_border);
     FREE_COLOR(urgent_ws_fg);
     FREE_COLOR(urgent_ws_bg);
+    FREE_COLOR(urgent_ws_border);
     FREE_COLOR(focus_ws_fg);
     FREE_COLOR(focus_ws_bg);
+    FREE_COLOR(focus_ws_border);
 #undef FREE_COLOR
 }