]> git.sur5r.net Git - i3/i3/commitdiff
i3bar: Implement the output option
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 21 Oct 2011 21:17:41 +0000 (22:17 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 21 Oct 2011 21:17:41 +0000 (22:17 +0100)
i3bar/include/config.h
i3bar/src/config.c
i3bar/src/outputs.c
i3bar/src/workspaces.c

index b914954c21a9b2c0cfd00d1d5dab3cae75e1364c..c5fc218c15d7e195ed0d639fb8f220f788c94e49 100644 (file)
@@ -19,6 +19,8 @@ typedef struct config_t {
     char         *command;
     char         *fontname;
     char         *tray_output;
+    int          num_outputs;
+    char         **outputs;
 } config_t;
 
 config_t config;
index 179bc4642c47d2d23af6e0105b2e71b7d14ac926..9e4552ed8ba0d085dba64231afad2f5696fbc7d2 100644 (file)
@@ -100,8 +100,11 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
     }
 
     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);
+        asprintf(&config.outputs[config.num_outputs], "%.*s", len, val);
+        config.num_outputs = new_num_outputs;
         return 1;
     }
 
index 98939fb42d00ba72ddcbae5713cc057c66eb66b0..6278974f761a2c4c78e214b56d5330dd3a5f6f0e 100644 (file)
@@ -26,7 +26,7 @@ struct outputs_json_params {
     i3_output           *outputs_walk;
     char                *cur_key;
     char                *json;
-    bool                init;
+    bool                in_rect;
 };
 
 /*
@@ -171,6 +171,10 @@ static int outputs_start_map_cb(void *params_) {
         return 1;
     }
 
+    if (!strcmp(params->cur_key, "rect")) {
+        params->in_rect = true;
+    }
+
     return 1;
 }
 
@@ -180,7 +184,33 @@ static int outputs_start_map_cb(void *params_) {
  */
 static int outputs_end_map_cb(void *params_) {
     struct outputs_json_params *params = (struct outputs_json_params*) params_;
-    /* FIXME: What is at the end of a rect? */
+    if (params->in_rect) {
+        params->in_rect = false;
+        /* Ignore the end of a rect */
+        return 1;
+    }
+
+    /* See if we actually handle that output */
+    if (config.num_outputs > 0) {
+        bool handle_output = false;
+        for (int c = 0; c < config.num_outputs; c++) {
+            if (strcasecmp(params->outputs_walk->name, config.outputs[c]) != 0)
+                continue;
+
+            handle_output = true;
+            break;
+        }
+        if (!handle_output) {
+            DLOG("Ignoring output \"%s\", not configured to handle it.\n",
+                 params->outputs_walk->name);
+            FREE(params->outputs_walk->name);
+            FREE(params->outputs_walk->workspaces);
+            FREE(params->outputs_walk->trayclients);
+            FREE(params->outputs_walk);
+            FREE(params->cur_key);
+            return 1;
+        }
+    }
 
     i3_output *target = get_output_by_name(params->outputs_walk->name);
 
@@ -249,6 +279,7 @@ void parse_outputs_json(char *json) {
     params.outputs_walk = NULL;
     params.cur_key = NULL;
     params.json = json;
+    params.in_rect = false;
 
     yajl_handle handle;
     yajl_status state;
index c2bb886c35961fd2b0d061b95a6bd3a8fd4205d4..bb00f0ba8be1c3f4b2daa35576b93145ac5e99e4 100644 (file)
@@ -144,11 +144,14 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne
             output_name = smalloc(sizeof(const unsigned char) * (len + 1));
             strncpy(output_name, (const char*) val, len);
             output_name[len] = '\0';
-            params->workspaces_walk->output = get_output_by_name(output_name);
+            i3_output *target = get_output_by_name(output_name);
+            if (target) {
+                params->workspaces_walk->output = target;
 
-            TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces,
-                              params->workspaces_walk,
-                              tailq);
+                TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces,
+                                  params->workspaces_walk,
+                                  tailq);
+            }
 
             FREE(output_name);
             return 1;