From 49fdc25f377481f0897ea10bd7943127cf5b721f Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Wed, 22 Jul 2015 17:39:31 +0200 Subject: [PATCH 1/2] Fixed font selection Font selection now correctly handles - as a special case. This change is also reflected in the documentation. --- README.pod | 2 +- lemonbar.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.pod b/README.pod index 5cadd5e..44f09f0 100644 --- a/README.pod +++ b/README.pod @@ -87,7 +87,7 @@ Set the text foreground color. The parameter I can be I<-> or a color in =item BI -Set the font used to draw the following text. The parameter I is a 1-based index of the font list supplied to bar. Any other value (for example I<->) resets the bar to normal behaviour (matching the first font that can be used for that character). If the selected font can't be used to draw a character, lemonbar will fall back to normal behaviour for that character. +Set the font used to draw the following text. The parameter I can either be I<-> or the 1-based index of the slot which contains the desired font. If the parameter is I<-> lemonbar resets to the normal behavior (matching the first font that can be used for the character). If the selected font can't be used to draw a character, lemonbar will fall back to normal behavior for that character =item BI diff --git a/lemonbar.c b/lemonbar.c index c956115..4d61120 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -540,6 +540,11 @@ parse (char *text) break; case 'T': + if(*p == '-') { //Reset to automatic font selection + font_index = -1; + p++; + break; + } font_index = (int)strtoul(p, &ep, 10); // User-specified 'font_index' ∊ (0,font_count] // Otherwise just fallback to the automatic font selection From 73d8c58286bdd599ff1bf94d11a8ad5a8e07372a Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Wed, 22 Jul 2015 22:46:30 +0200 Subject: [PATCH 2/2] Conform to coding standard and errors An error will not be printed if the parameter to `T` is not valid (- or a number) and the token will be eaten (just like when an invalid attribute is found) --- lemonbar.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lemonbar.c b/lemonbar.c index 4d61120..316804b 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -540,18 +540,22 @@ parse (char *text) break; case 'T': - if(*p == '-') { //Reset to automatic font selection + if (*p == '-') { //Reset to automatic font selection font_index = -1; p++; break; - } - font_index = (int)strtoul(p, &ep, 10); - // User-specified 'font_index' ∊ (0,font_count] - // Otherwise just fallback to the automatic font selection - if (!font_index || font_index > font_count) + } else if (isdigit(*p)) { + font_index = (int)strtoul(p, &ep, 10); + // User-specified 'font_index' ∊ (0,font_count] + // Otherwise just fallback to the automatic font selection + if (!font_index || font_index > font_count) font_index = -1; - p = ep; - break; + p = ep; + break; + } else { + fprintf(stderr, "Invalid font slot \"%c\"\n", *p++); //Swallow the token + break; + } // In case of error keep parsing after the closing } default: