From b82d96a68e4a4d14dff5c79c7ebd1da95ef85241 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 15 Apr 2015 10:21:52 +0200 Subject: [PATCH 1/4] Use the maximum width reported by the font if the attributes table isn't found --- lemonbar.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lemonbar.c b/lemonbar.c index 5f36f41..c7a53ba 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -22,7 +22,7 @@ typedef struct font_t { xcb_font_t ptr; - int descent, height; + int descent, height, width; uint16_t char_max; uint16_t char_min; xcb_charinfo_t *width_lut; @@ -180,13 +180,18 @@ xcb_void_cookie_t xcb_poly_text_16_simple(xcb_connection_t * c, xcb_parts[6].iov_len = -(xcb_parts[4].iov_len + xcb_parts[5].iov_len) & 3; xcb_ret.sequence = xcb_send_request(c, 0, xcb_parts + 2, &xcb_req); + return xcb_ret; } int draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) { - int ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width; + int ch_width; + + ch_width = (cur_font->width_lut) ? + cur_font->width_lut[ch - cur_font->char_min].character_width: + cur_font->width; switch (align) { case ALIGN_C: @@ -432,10 +437,13 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x bool font_has_glyph (font_t *font, const uint16_t c) { - return (c >= font->char_min && - c <= font->char_max && - font->width_lut && - font->width_lut[c - font->char_min].character_width); + if (c < font->char_min || c > font->char_max) + return false; + + if (font->width_lut && font->width_lut[c - font->char_min].character_width == 0) + return false; + + return true; } // returns NULL if character cannot be printed @@ -628,6 +636,7 @@ font_load (const char *str) ret->ptr = font; ret->descent = font_info->font_descent; ret->height = font_info->font_ascent + font_info->font_descent; + ret->width = font_info->max_bounds.character_width; ret->char_max = font_info->max_byte1 << 8 | font_info->max_char_or_byte2; ret->char_min = font_info->min_byte1 << 8 | font_info->min_char_or_byte2; From 25c3441925272978596df7964aeec68c295ad0b5 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 15 Apr 2015 11:04:53 +0200 Subject: [PATCH 2/4] travis: Run a apt-get update before installing the needed packages --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be842ec..fb22eea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,6 @@ compiler: - clang - gcc before_install: - - sudo apt-get install -qq libx11-xcb-dev libxcb-randr0-dev libxcb-xinerama0-dev + - sudo apt-get update -qq + - sudo apt-get install -y libx11-xcb-dev libxcb-randr0-dev libxcb-xinerama0-dev script: make From 7880eac8c9b15810a2089ca8636b3d51d433a4b4 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 23 Apr 2015 23:07:42 +0200 Subject: [PATCH 3/4] Minor change to -f handling Remove the ability of the -f switch to accept a comma-separated list of fonts. The user is expected to use multiple times -f whenever he wants to specify one or more fonts. This has the side effect of enabling the user to use fonts whose name contains a comma. --- README.pod | 3 ++- lemonbar.c | 64 ++++++++---------------------------------------------- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/README.pod b/README.pod index afbed83..5cadd5e 100644 --- a/README.pod +++ b/README.pod @@ -34,7 +34,8 @@ Force docking without asking the window manager. This is needed if the window ma =item B<-f> I -Comma separated list of fonts, lemonbar supports a maximum of five fonts (the limit can be tweaked by changing the MAX_FONT_COUNT parameter in the source). +Define the font to load into one of the five slots (the number of slots is hardcoded and can be tweaked by +changing the MAX_FONT_COUNT parameter in the source code). =item B<-p> diff --git a/lemonbar.c b/lemonbar.c index c7a53ba..929f90d 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -609,8 +609,8 @@ parse (char *text) } } -font_t * -font_load (const char *str) +void +font_load (const char *pattern) { xcb_query_font_cookie_t queryreq; xcb_query_font_reply_t *font_info; @@ -619,16 +619,16 @@ font_load (const char *str) font = xcb_generate_id(c); - cookie = xcb_open_font_checked(c, font, strlen(str), str); + cookie = xcb_open_font_checked(c, font, strlen(pattern), pattern); if (xcb_request_check (c, cookie)) { - fprintf(stderr, "Could not load font \"%s\"\n", str); - return NULL; + fprintf(stderr, "Could not load font \"%s\"\n", pattern); + return; } font_t *ret = calloc(1, sizeof(font_t)); if (!ret) - return NULL; + return; queryreq = xcb_query_font(c, font); font_info = xcb_query_font_reply(c, queryreq, NULL); @@ -649,7 +649,7 @@ font_load (const char *str) free(font_info); - return ret; + font_list[font_count++] = ret; } enum { @@ -1035,48 +1035,6 @@ parse_geometry_string (char *str, int *tmp) return true; } -void -parse_font_list (char *str) -{ - char *tok, *end; - - if (!str) - return; - - tok = strtok(str, ","); - - while (tok) { - if (font_count > MAX_FONT_COUNT - 1) { - fprintf(stderr, "Too many fonts; maximum %i\n", MAX_FONT_COUNT); - return; - } - - // Strip the leading and trailing whitespaces - while (isspace(*tok) || iscntrl(*tok)) - tok++; - - end = tok + strlen(tok) - 1; - - while ((end > tok && isspace(*end)) || iscntrl(*end)) - end--; - - *(end + 1) = '\0'; - - if (tok[0]) { - // Load the selected font - font_t *font = font_load(tok); - if (font) - font_list[font_count++] = font; - } - else - fprintf(stderr, "Empty font name, skipping...\n"); - - tok = strtok(NULL, ","); - } -} - - - void xconn (void) { @@ -1100,13 +1058,9 @@ xconn (void) void init (void) { - // This has to be declared as an array because otherwise the compiler would turn it into a const - // string, making strtok choke very hard on this - char fallback_font[] = "fixed"; - // Try to load a default font if (!font_count) - parse_font_list(fallback_font); + font_load("fixed"); // We tried and failed hard, there's something wrong if (!font_count) @@ -1279,7 +1233,7 @@ main (int argc, char **argv) case 'p': permanent = true; break; case 'b': topbar = false; break; case 'd': dock = true; break; - case 'f': parse_font_list(optarg); break; + case 'f': font_load(optarg); break; case 'u': bu = strtoul(optarg, NULL, 10); break; case 'B': dbgc = bgc = parse_color(optarg, NULL, (rgba_t)scr->black_pixel); break; case 'F': dfgc = fgc = parse_color(optarg, NULL, (rgba_t)scr->white_pixel); break; From a9f285fd2866ab3451b8dd7468853c141691024f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 3 May 2015 17:06:36 +0200 Subject: [PATCH 4/4] Update the usage text The -f option doesn't accept a comma separated list of font names anymore --- lemonbar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemonbar.c b/lemonbar.c index 929f90d..c956115 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -1223,7 +1223,7 @@ main (int argc, char **argv) "\t-g Set the bar geometry {width}x{height}+{xoffset}+{yoffset}\n" "\t-b Put the bar at the bottom of the screen\n" "\t-d Force docking (use this if your WM isn't EWMH compliant)\n" - "\t-f Bar font list, comma separated\n" + "\t-f Set the font name to use\n" "\t-p Don't close after the data ends\n" "\t-u Set the underline/overline height in pixels\n" "\t-B Set background color in #AARRGGBB\n"