]> git.sur5r.net Git - i3/i3/blobdiff - src/cfgparse.y
bar config: fall back to the i3 font (Thanks pl)
[i3/i3] / src / cfgparse.y
index 8232ae572bc848f760bdb48283292aa1799d7607..7cd0ce9b892230fdd075e2a4f0d5b42778520a68 100644 (file)
@@ -15,6 +15,10 @@ static pid_t configerror_pid = -1;
 
 static Match current_match;
 static Barconfig current_bar;
+/* The pattern which was specified by the user, for example -misc-fixed-*. We
+ * store this in a separate variable because in the i3 config struct we just
+ * store the i3Font. */
+static char *font_pattern;
 
 typedef struct yy_buffer_state *YY_BUFFER_STATE;
 extern int yylex(struct context *context);
@@ -280,10 +284,8 @@ static void start_configerror_nagbar(const char *config_path) {
     if (configerror_pid == 0) {
         char *editaction,
              *pageraction;
-        if (asprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path) == -1)
-            exit(1);
-        if (asprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename) == -1)
-            exit(1);
+        sasprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path);
+        sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
         char *argv[] = {
             NULL, /* will be replaced by the executable path */
             "-t",
@@ -613,6 +615,7 @@ void parse_file(const char *f) {
     yylex_destroy();
     FREE(context->line_copy);
     free(context);
+    FREE(font_pattern);
     free(new);
     free(buf);
 
@@ -695,14 +698,14 @@ void parse_file(const char *f) {
 %token                  TOK_BAR_OUTPUT              "output (bar)"
 %token                  TOK_BAR_TRAY_OUTPUT         "tray_output"
 %token                  TOK_BAR_SOCKET_PATH         "socket_path"
-%token                  TOK_BAR_MODE                "mode"
+%token                  TOK_BAR_MODE                "mode (bar)"
 %token                  TOK_BAR_HIDE                "hide"
 %token                  TOK_BAR_DOCK                "dock"
 %token                  TOK_BAR_POSITION            "position"
 %token                  TOK_BAR_BOTTOM              "bottom"
 %token                  TOK_BAR_TOP                 "top"
 %token                  TOK_BAR_STATUS_COMMAND      "status_command"
-%token                  TOK_BAR_FONT                "font"
+%token                  TOK_BAR_FONT                "font (bar)"
 %token                  TOK_BAR_WORKSPACE_BUTTONS   "workspace_buttons"
 %token                  TOK_BAR_VERBOSE             "verbose"
 %token                  TOK_BAR_COLORS              "colors"
@@ -938,7 +941,7 @@ word_or_number:
     WORD
     | NUMBER
     {
-        asprintf(&$$, "%d", $1);
+        sasprintf(&$$, "%d", $1);
     }
     ;
 
@@ -998,6 +1001,10 @@ bar:
             *(x++) = (rand() % 26) + 'a';
         }
 
+        /* If no font was explicitly set, we use the i3 font as default */
+        if (!current_bar.font)
+            current_bar.font = sstrdup(font_pattern);
+
         /* Copy the current (static) structure into a dynamically allocated
          * one, then cleanup our static one. */
         Barconfig *bar_config = scalloc(sizeof(Barconfig));
@@ -1345,7 +1352,7 @@ workspace:
         } else {
             char *ws_name = NULL;
             if ($5 == NULL) {
-                asprintf(&ws_name, "%d", ws_num);
+                sasprintf(&ws_name, "%d", ws_num);
             } else {
                 ws_name = $5;
             }
@@ -1422,20 +1429,14 @@ assign:
         if ((separator = strchr(criteria, '/')) != NULL) {
             *(separator++) = '\0';
             char *pattern;
-            if (asprintf(&pattern, "(?i)%s", separator) == -1) {
-                ELOG("asprintf failed\n");
-                break;
-            }
+            sasprintf(&pattern, "(?i)%s", separator);
             match->title = regex_new(pattern);
             free(pattern);
             printf("  title = %s\n", separator);
         }
         if (*criteria != '\0') {
             char *pattern;
-            if (asprintf(&pattern, "(?i)%s", criteria) == -1) {
-                ELOG("asprintf failed\n");
-                break;
-            }
+            sasprintf(&pattern, "(?i)%s", criteria);
             match->class = regex_new(pattern);
             free(pattern);
             printf("  class = %s\n", criteria);
@@ -1534,7 +1535,8 @@ font:
     {
         config.font = load_font($2, true);
         printf("font %s\n", $2);
-        free($2);
+        FREE(font_pattern);
+        font_pattern = $2;
     }
     ;