comp: Fix running with XRT_COMPOSITOR_XCB_FULLSCREEN=1

It required XRT_COMPOSITOR_XCB_DISPLAY to be set to a valid display or the
swapchain creation would fail because the requested width x height was 0x0.

Now the first display with a size other than 0x0 is selected when the current
selected display is 0x0.

fixes #148
This commit is contained in:
Christoph Haag 2022-01-13 12:27:17 +01:00 committed by Jakob Bornecrantz
parent 77f19161fb
commit 8d5847d5a9

View file

@ -176,6 +176,21 @@ comp_window_xcb_list_screens(struct comp_window_xcb *w, xcb_screen_t *screen)
}
}
static bool
select_new_current_display(struct comp_target *ct)
{
struct comp_window_xcb *w_xcb = (struct comp_window_xcb *)ct;
for (uint32_t i = 0; i < w_xcb->display_count; i++) {
if (w_xcb->displays[i].size.width != 0 && w_xcb->displays[i].size.height != 0) {
w_xcb->base.base.c->settings.display = i;
COMP_DEBUG(ct->c, "Select new current display %d: %s", i, w_xcb->displays[i].name);
return true;
}
}
return false;
}
static bool
comp_window_xcb_init(struct comp_target *ct)
{
@ -207,10 +222,27 @@ comp_window_xcb_init(struct comp_target *ct)
ct->c->settings.display = 0;
struct comp_window_xcb_display *d = comp_window_xcb_current_display(w_xcb);
ct->c->settings.preferred.width = d->size.width;
ct->c->settings.preferred.height = d->size.height;
// TODO: size cb
// set_size_cb(settings->width, settings->height);
if (d->size.width == 0 || d->size.height == 0) {
COMP_WARN(ct->c, "Selected display %d has no size", w_xcb->base.base.c->settings.display);
if (select_new_current_display(ct)) {
d = comp_window_xcb_current_display(w_xcb);
COMP_WARN(ct->c, "Falling back to display %d: %s", w_xcb->base.base.c->settings.display,
d->name);
} else {
COMP_ERROR(ct->c, "No suitable display found, disabling fullscreen");
w_xcb->base.base.c->settings.fullscreen = false;
}
}
if (d->size.width != 0 && d->size.height != 0) {
ct->c->settings.preferred.width = d->size.width;
ct->c->settings.preferred.height = d->size.height;
COMP_DEBUG(ct->c, "Setting window size %dx%d.", d->size.width, d->size.height);
// TODO: size cb
// set_size_cb(settings->width, settings->height);
}
}
comp_window_xcb_create_window(w_xcb, ct->c->settings.preferred.width, ct->c->settings.preferred.height);
@ -316,9 +348,13 @@ comp_window_xcb_get_randr_outputs(struct comp_window_xcb *w)
.position = {crtc_reply->x, crtc_reply->y},
.size = {crtc_reply->width, crtc_reply->height},
};
memcpy(w->displays[i].name, name, name_len);
w->displays[i].name[name_len] = '\0';
COMP_DEBUG(w->base.base.c, "randr output %d: %s: %dx%d", i, w->displays[i].name, crtc_reply->width,
crtc_reply->height);
free(crtc_reply);
free(output_reply);
}