From 0f2cfbab28d1d4d5b5aa04a81a5adfec2d6e5ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Bon?= Date: Tue, 19 Jan 2016 14:18:16 +0100 Subject: [PATCH 1/2] Implement [Issue #161 - Feature request] Feature: add a parametere to set the default underline color. Usage: lemonbar -Ucolor By the way this also fix a strange behavior whereas '%{+u}correct%{U-}strange' made the second underline of the same color as the background instead of the foreground. --- README.pod | 6 +++++- lemonbar.c | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.pod b/README.pod index 8173b4a..509cfd6 100644 --- a/README.pod +++ b/README.pod @@ -6,7 +6,7 @@ lemonbar - Featherweight lemon-scented bar =head1 SYNOPSIS -I [-h | -g IBIB<+>IB<+>I | -b | -d | -f I | -p | -n I | -u I | -B I | -F I] +I [-h | -g IBIB<+>IB<+>I | -b | -d | -f I | -p | -n I | -u I | -B I | -F I | -U I] =head1 DESCRIPTION @@ -61,6 +61,10 @@ Set the background color of the bar. I must be specified in the hex forma Set the foreground color of the bar. Accepts the same color formats as B<-B>. +=item B<-U> I + +Set the underline color of the bar. Accepts the same color formats as B<-B>. + =back =head1 FORMATTING diff --git a/lemonbar.c b/lemonbar.c index cfd4d9b..2198731 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -95,7 +95,7 @@ static bool topbar = true; static int bw = -1, bh = -1, bx = 0, by = 0; static int bu = 1; // Underline height static rgba_t fgc, bgc, ugc; -static rgba_t dfgc, dbgc; +static rgba_t dfgc, dbgc, dugc; static area_stack_t area_stack; void @@ -520,7 +520,7 @@ parse (char *text) case 'B': bgc = parse_color(p, &p, dbgc); update_gc(); break; case 'F': fgc = parse_color(p, &p, dfgc); update_gc(); break; - case 'U': ugc = parse_color(p, &p, dbgc); update_gc(); break; + case 'U': ugc = parse_color(p, &p, dugc); update_gc(); break; case 'S': if (*p == '+' && cur_mon->next) @@ -1238,8 +1238,7 @@ main (int argc, char **argv) // B/W combo dbgc = bgc = (rgba_t)0x00000000U; dfgc = fgc = (rgba_t)0xffffffffU; - - ugc = fgc; + dugc = ugc = fgc; // A safe default areas = 10; @@ -1248,7 +1247,7 @@ main (int argc, char **argv) // Connect to the Xserver and initialize scr xconn(); - while ((ch = getopt(argc, argv, "hg:bdf:a:pu:B:F:n:")) != -1) { + while ((ch = getopt(argc, argv, "hg:bdf:a:pu:B:F:U:n:")) != -1) { switch (ch) { case 'h': printf ("lemonbar version %s\n", VERSION); @@ -1274,6 +1273,7 @@ main (int argc, char **argv) case 'u': bu = strtoul(optarg, NULL, 10); break; case 'B': dbgc = bgc = parse_color(optarg, NULL, (rgba_t)0x00000000U); break; case 'F': dfgc = fgc = parse_color(optarg, NULL, (rgba_t)0xffffffffU); break; + case 'U': dugc = ugc = parse_color(optarg, NULL, fgc); break; case 'a': areas = strtoul(optarg, NULL, 10); break; } } From 892e43a3bc25b78af44b366996532da7f44abc20 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 1 Mar 2014 13:31:27 -0500 Subject: [PATCH 2/2] Add pixel offset Add a formatting command to offset the text position by a pixel amount. --- README.pod | 4 ++++ lemonbar.c | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.pod b/README.pod index 509cfd6..9fbba94 100644 --- a/README.pod +++ b/README.pod @@ -89,6 +89,10 @@ Aligns the following text to the center of the screen. Aligns the following text to the right side of the screen. +=item BI + +Offset the current position by I pixels in the alignment direction. + =item BI Set the text background color. The parameter I can be I<-> or a color in one of the formats mentioned before. The special value I<-> resets the color to the default one. diff --git a/lemonbar.c b/lemonbar.c index 2198731..08e4704 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -186,14 +186,8 @@ xcb_void_cookie_t xcb_poly_text_16_simple(xcb_connection_t * c, } int -draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) +shift (monitor_t *mon, int x, int align, int ch_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: xcb_copy_area(c, mon->pixmap, mon->pixmap, gc[GC_DRAW], @@ -213,6 +207,34 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) // Draw the background first fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, ch_width, bh); + return x; +} + +void +draw_lines (monitor_t *mon, int x, int w) +{ + /* We can render both at the same time */ + if (attrs & ATTR_OVERL) + fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, w, bu); + if (attrs & ATTR_UNDERL) + fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, w, bu); +} + +void +draw_shift (monitor_t *mon, int x, int align, int w) +{ + x = shift(mon, x, align, w); + draw_lines(mon, x, w); +} + +int +draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) +{ + int ch_width = (cur_font->width_lut) ? + cur_font->width_lut[ch - cur_font->char_min].character_width: + cur_font->width; + + x = shift(mon, x, align, ch_width); // xcb accepts string in UCS-2 BE, so swap ch = (ch >> 8) | (ch << 8); @@ -222,11 +244,7 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) x, bh / 2 + cur_font->height / 2 - cur_font->descent, 1, &ch); - // We can render both at the same time - if (attrs & ATTR_OVERL) - fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, ch_width, bu); - if (attrs & ATTR_UNDERL) - fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, ch_width, bu); + draw_lines(mon, x, ch_width); return ch_width; } @@ -490,6 +508,7 @@ parse (char *text) if (p[0] == '%' && p[1] == '{' && (block_end = strchr(p++, '}'))) { p++; while (p < block_end) { + int w; while (isspace(*p)) p++; @@ -542,6 +561,17 @@ parse (char *text) p++; pos_x = 0; break; + case 'O': + errno = 0; + w = (int) strtoul(p, &p, 10); + if (errno) + continue; + + draw_shift(cur_mon, pos_x, align, w); + + pos_x += w; + area_shift(cur_mon->window, align, w); + break; case 'T': if (*p == '-') { //Reset to automatic font selection