From 13dcc66cae5fb88bd973ee5ff47e512d7d14cf6f Mon Sep 17 00:00:00 2001 From: xd1le Date: Fri, 19 Feb 2016 21:47:55 +1100 Subject: [PATCH 1/7] Document literal percent sign under formatting `B<%{>` and `B<}>` on the same line have been changed to `C<%{>` and `C<}>` for consistency. --- README.pod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.pod b/README.pod index 509cfd6..dc7307a 100644 --- a/README.pod +++ b/README.pod @@ -69,7 +69,7 @@ Set the underline color of the bar. Accepts the same color formats as B<-B>. =head1 FORMATTING -lemonbar provides a screenrc-inspired formatting syntax to allow full customization at runtime. Every formatting block is opened with B<%{> and closed by B<}> and accepts the following commands, the parser tries it's best to handle malformed input. +lemonbar provides a screenrc-inspired formatting syntax to allow full customization at runtime. Every formatting block is opened with C<%{> and closed by C<}> and accepts the following commands, the parser tries it's best to handle malformed input. Use C<%%> to get a literal percent sign (C<%>). =over From f2662d75c83eb05903d85b7d7dbee9d3929829ef Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 1 Mar 2014 13:31:27 -0500 Subject: [PATCH 2/7] 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 dc7307a..b4ffccd 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 From a3fb967ad9d4885f7df6344041ce8e98a3a1cdf5 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 23 Apr 2016 08:59:38 +0200 Subject: [PATCH 3/7] Make it possible to build lemonbar w/o XINERAMA support --- lemonbar.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lemonbar.c b/lemonbar.c index 08e4704..930571c 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -11,7 +11,9 @@ #include #include #include +#if WITH_XINERAMA #include +#endif #include // Here be dragons @@ -987,6 +989,7 @@ get_randr_monitors (void) monitor_create_chain(r, valid); } +#ifdef WITH_XINERAMA void get_xinerama_monitors (void) { @@ -1015,6 +1018,7 @@ get_xinerama_monitors (void) monitor_create_chain(rects, screens); } +#endif xcb_visualid_t get_visual (void) @@ -1139,7 +1143,9 @@ init (char *wm_name) if (qe_reply && qe_reply->present) { get_randr_monitors(); - } else { + } +#if WITH_XINERAMA + else { qe_reply = xcb_get_extension_data(c, &xcb_xinerama_id); // Check if Xinerama extension is present and active @@ -1153,6 +1159,7 @@ init (char *wm_name) free(xia_reply); } } +#endif if (!monhead) { // If I fits I sits From 3dbdf9d078d4e2b776ecfc0daed124766bf22a15 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 23 Apr 2016 09:02:46 +0200 Subject: [PATCH 4/7] Update the .travis.yml to build all the features --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index fb22eea..f4dc16a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,6 @@ compiler: before_install: - sudo apt-get update -qq - sudo apt-get install -y libx11-xcb-dev libxcb-randr0-dev libxcb-xinerama0-dev +env: + - CFLAGS='-DWITH_XINERAMA=1' script: make From 40f08d5245dc85501f555a4843301633d9fd6f36 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 23 Apr 2016 09:06:00 +0200 Subject: [PATCH 5/7] Silence a warning about write() result being unused. --- lemonbar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lemonbar.c b/lemonbar.c index 930571c..c31cb26 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -1375,8 +1375,8 @@ main (int argc, char **argv) area_t *area = area_get(press_ev->event, press_ev->detail, press_ev->event_x); // Respond to the click if (area) { - write(STDOUT_FILENO, area->cmd, strlen(area->cmd)); - write(STDOUT_FILENO, "\n", 1); + (void)write(STDOUT_FILENO, area->cmd, strlen(area->cmd)); + (void)write(STDOUT_FILENO, "\n", 1); } } break; From 44a708b7a4a266ca8e91eb8a6a1b34ffa4a7a164 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 22 May 2016 15:31:42 +0200 Subject: [PATCH 6/7] Don't use optarg directly when parsing the -n switch argument. --- lemonbar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lemonbar.c b/lemonbar.c index c31cb26..36fbfb7 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -1,4 +1,5 @@ // vim:sw=4:ts=4:et: +#define _POSIX_C_SOURCE 200809L #include #include #include @@ -1303,7 +1304,7 @@ main (int argc, char **argv) exit (EXIT_SUCCESS); case 'g': (void)parse_geometry_string(optarg, geom_v); break; case 'p': permanent = true; break; - case 'n': wm_name = optarg; break; + case 'n': wm_name = strdup(optarg); break; case 'b': topbar = false; break; case 'd': dock = true; break; case 'f': font_load(optarg); break; @@ -1338,6 +1339,8 @@ main (int argc, char **argv) // Do the heavy lifting init(wm_name); + // The string is strdup'd when the command line arguments are parsed + free(wm_name); // Get the fd to Xserver pollin[1].fd = xcb_get_file_descriptor(c); From d680ea4256637bc89d59342cf6ac6c6f5fe62dec Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 22 May 2016 20:09:26 +0200 Subject: [PATCH 7/7] Set the WM_NAME for all the windows. Don't set repeatedly the property for the first window only. Thanks to @otommod for noticing this. --- lemonbar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemonbar.c b/lemonbar.c index 36fbfb7..f1b7886 100644 --- a/lemonbar.c +++ b/lemonbar.c @@ -1208,7 +1208,7 @@ init (char *wm_name) // Set the WM_NAME atom to the user specified value if (wm_name) - xcb_change_property(c, XCB_PROP_MODE_REPLACE, monhead->window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8 ,strlen(wm_name), wm_name); + xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8 ,strlen(wm_name), wm_name); } xcb_flush(c);