From 3546890578598090dbf1b33c10477e439fbf442f Mon Sep 17 00:00:00 2001 From: John Vogel Date: Wed, 28 May 2014 20:38:36 -0400 Subject: [PATCH 1/6] Clear all pixmaps at start of parse, but not at each ${S} command. --- bar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bar.c b/bar.c index 6346870..a40bfae 100644 --- a/bar.c +++ b/bar.c @@ -302,7 +302,8 @@ parse (char *text) memset(&astack, 0, sizeof(area_stack_t)); - fill_rect(cur_mon->pixmap, gc[GC_CLEAR], 0, 0, bw, bh); + for (monitor_t *m = monhead; m != NULL; m = m->next) + fill_rect(m->pixmap, gc[GC_CLEAR], 0, 0, m->width, bh); for (;;) { if (*p == '\0' || *p == '\n') @@ -356,7 +357,6 @@ parse (char *text) p++; pos_x = 0; - fill_rect(cur_mon->pixmap, gc[GC_CLEAR], 0, 0, cur_mon->width, bh); break; /* In case of error keep parsing after the closing } */ From c2336460126e0463d37b3b6649fa8a5ddc6b920d Mon Sep 17 00:00:00 2001 From: John Vogel Date: Wed, 28 May 2014 21:00:58 -0400 Subject: [PATCH 2/6] Consider all monitors for geometry settings/checks. --- bar.c | 61 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/bar.c b/bar.c index a40bfae..e6c4baa 100644 --- a/bar.c +++ b/bar.c @@ -562,14 +562,40 @@ rect_sort_cb (const void *p1, const void *p2) void monitor_create_chain (xcb_rectangle_t *rects, const int num) { - int width = bw; + int i; + int width = 0, height = 0; int left = bx; /* Sort before use */ qsort(rects, num, sizeof(xcb_rectangle_t), rect_sort_cb); + for (i = 0; i < num; i++) { + int h = rects[i].y + rects[i].height; + /* Accumulated width of all monitors */ + width += rects[i].width; + /* Get height of screen from y_offset + height of lowest monitor */ + if (h >= height) + height = h; + } + + /* Check the geometry */ + if (bx + bw > width || by + bh > height) { + fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); + exit(EXIT_FAILURE); + } + + + if (bw < 0) + bw = width - bx; + + if (bh < 0 || bh > height) + bh = main_font->height + bu + 2; + /* Left is a positive number or zero therefore monitors with zero width are excluded */ - for (int i = 0; i < num; i++) { + width = bw; + for (i = 0; i < num; i++) { + if (rects[i].y + rects[i].height < by) + continue; if (rects[i].width > left) { monitor_t *mon = monitor_new( rects[i].x + left, @@ -755,10 +781,6 @@ xconn (void) void init (void) { - /* If I fits I sits */ - if (bw < 0) - bw = scr->width_in_pixels - bx; - /* Load the fonts */ main_font = font_load(mfont ? mfont : "fixed"); if (!main_font) @@ -771,10 +793,6 @@ init (void) /* To make the alignment uniform */ main_font->height = alt_font->height = max(main_font->height, alt_font->height); - /* Adjust the height */ - if (bh < 0 || bh > scr->height_in_pixels) - bh = main_font->height + bu + 2; - /* Generate a list of screens */ const xcb_query_extension_reply_t *qe_reply; @@ -801,9 +819,24 @@ init (void) } } - if (!monhead) + if (!monhead) { + /* Check the geometry */ + if (bx + bw > scr->width_in_pixels || by + bh > scr->height_in_pixels) { + fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); + exit(EXIT_FAILURE); + } + + /* If I fits I sits */ + if (bw < 0) + bw = scr->width_in_pixels - bx; + + /* Adjust the height */ + if (bh < 0 || bh > scr->height_in_pixels) + bh = main_font->height + bu + 2; + /* If no RandR outputs or Xinerama screens, fall back to using whole screen */ monhead = monitor_new(0, 0, bw, scr->height_in_pixels); + } if (!monhead) exit(EXIT_FAILURE); @@ -999,12 +1032,6 @@ main (int argc, char **argv) bx = geom_v[2]; by = geom_v[3]; - /* Check the geometry */ - if (bx + bw > scr->width_in_pixels || by + bh > scr->height_in_pixels) { - fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); - return EXIT_FAILURE; - } - /* Do the heavy lifting */ init(); /* Get the fd to Xserver */ From caf14a0ec417e95792235d09d398bd6a5d90bb5d Mon Sep 17 00:00:00 2001 From: John Vogel Date: Sat, 31 May 2014 21:52:48 -0400 Subject: [PATCH 3/6] Don't send zero width rects to monitor_create_chain --- bar.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bar.c b/bar.c index e6c4baa..df5b13f 100644 --- a/bar.c +++ b/bar.c @@ -624,7 +624,7 @@ get_randr_monitors (void) { xcb_randr_get_screen_resources_current_reply_t *rres_reply; xcb_randr_output_t *outputs; - int num, valid = 0; + int i, j, num, valid = 0; rres_reply = xcb_randr_get_screen_resources_current_reply(c, xcb_randr_get_screen_resources_current(c, scr->root), NULL); @@ -647,7 +647,7 @@ get_randr_monitors (void) xcb_rectangle_t rects[num]; /* Get all outputs */ - for (int i = 0; i < num; i++) { + for (i = 0; i < num; i++) { xcb_randr_get_output_info_reply_t *oi_reply; xcb_randr_get_crtc_info_reply_t *ci_reply; @@ -683,11 +683,11 @@ get_randr_monitors (void) free(rres_reply); /* Check for clones and inactive outputs */ - for (int i = 0; i < num; i++) { + for (i = 0; i < num; i++) { if (rects[i].width == 0) continue; - for (int j = 0; j < num; j++) { + for (j = 0; j < num; j++) { /* Does I countain J ? */ if (i != j && rects[j].width) { @@ -705,7 +705,11 @@ get_randr_monitors (void) return; } - monitor_create_chain(rects, num); + for (i = j = 0; i < num && j < valid; i++) + if (rects[i].width != 0) + r[j++] = rects[i]; + + monitor_create_chain(r, valid); } void From e81c1ff8cb8a2c9da46532dc6275e64844c3a4f8 Mon Sep 17 00:00:00 2001 From: John Vogel Date: Sat, 31 May 2014 21:56:50 -0400 Subject: [PATCH 4/6] Put geometry checks after width/height adjust --- bar.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bar.c b/bar.c index df5b13f..b51b299 100644 --- a/bar.c +++ b/bar.c @@ -578,19 +578,18 @@ monitor_create_chain (xcb_rectangle_t *rects, const int num) height = h; } - /* Check the geometry */ - if (bx + bw > width || by + bh > height) { - fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); - exit(EXIT_FAILURE); - } - - if (bw < 0) bw = width - bx; if (bh < 0 || bh > height) bh = main_font->height + bu + 2; + /* Check the geometry */ + if (bx + bw > width || by + bh > height) { + fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); + exit(EXIT_FAILURE); + } + /* Left is a positive number or zero therefore monitors with zero width are excluded */ width = bw; for (i = 0; i < num; i++) { From 8a7015fce240b3e9982781694f7efb4375881292 Mon Sep 17 00:00:00 2001 From: John Vogel Date: Sat, 31 May 2014 22:01:14 -0400 Subject: [PATCH 5/6] Add omitted variable declaration --- bar.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bar.c b/bar.c index b51b299..e99ee66 100644 --- a/bar.c +++ b/bar.c @@ -704,6 +704,8 @@ get_randr_monitors (void) return; } + xcb_rectangle_t r[valid]; + for (i = j = 0; i < num && j < valid; i++) if (rects[i].width != 0) r[j++] = rects[i]; From 99e927ee702d59708960bc76aac9ec23833e4a87 Mon Sep 17 00:00:00 2001 From: John Vogel Date: Sun, 1 Jun 2014 09:21:06 -0400 Subject: [PATCH 6/6] Put geom checks after adjust for non-multi also --- bar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bar.c b/bar.c index e99ee66..847e443 100644 --- a/bar.c +++ b/bar.c @@ -825,12 +825,6 @@ init (void) } if (!monhead) { - /* Check the geometry */ - if (bx + bw > scr->width_in_pixels || by + bh > scr->height_in_pixels) { - fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); - exit(EXIT_FAILURE); - } - /* If I fits I sits */ if (bw < 0) bw = scr->width_in_pixels - bx; @@ -839,6 +833,12 @@ init (void) if (bh < 0 || bh > scr->height_in_pixels) bh = main_font->height + bu + 2; + /* Check the geometry */ + if (bx + bw > scr->width_in_pixels || by + bh > scr->height_in_pixels) { + fprintf(stderr, "The geometry specified doesn't fit the screen!\n"); + exit(EXIT_FAILURE); + } + /* If no RandR outputs or Xinerama screens, fall back to using whole screen */ monhead = monitor_new(0, 0, bw, scr->height_in_pixels); }