bar/xcb: fallback to non-primary monitor

If the user did *not* configured a specific monitor, we prefer the
primary monitor. However, if that monitor is disconnected, yambar
would exit with:

  no matching monitor

This patch changes this, to use the *last* connected monitor. It also
improves the error message.

Note: if the user did specify a monitor in the configuration, but
perhaps misspelled it, we will *not* fallback to another monitor, but
instead log an error saying that specific monitor could not be found.
This commit is contained in:
Daniel Eklöf 2020-12-04 21:16:14 +01:00
parent d5fc1074d8
commit d0f1f762ea
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -101,27 +101,38 @@ setup(struct bar *_bar)
mon->width, mon->height, mon->x, mon->y,
mon->width_in_millimeters, mon->height_in_millimeters);
if (!((bar->monitor == NULL && mon->primary) ||
(bar->monitor != NULL && strcmp(bar->monitor, name) == 0)))
{
/* User wants a specific monitor, and this is not the one */
if (bar->monitor != NULL && strcmp(bar->monitor, name) != 0) {
free(name);
continue;
}
free(name);
backend->x = mon->x;
backend->y = mon->y;
bar->width = mon->width;
backend->y += bar->location == BAR_TOP ? 0
: screen->height_in_pixels - bar->height_with_border;
found_monitor = true;
if ((bar->monitor != NULL && strcmp(bar->monitor, name) == 0) ||
(bar->monitor == NULL && mon->primary))
{
/* Exact match */
free(name);
break;
}
free(name);
}
free(monitors);
if (!found_monitor) {
LOG_ERR("no matching monitor");
if (bar->monitor == NULL)
LOG_ERR("no monitors found");
else
LOG_ERR("no monitor '%s'", bar->monitor);
/* TODO: cleanup */
return false;
}