Fix the initial output geometry guessing

wvkbd adapt its height, and layout depending on if the screen
is in landscape mode or not.

The only realiable way to know which outputs our surface is
rendered on is the wl_surface->enter(wl_output) event. But we receive
this event very late in the flow. After the first frame rendering, and
commit to the surface.

There already is some code to guess the best initial tentative, on the
most simple situations, to try to avoid an immediate re-creation of the
Wayland objects, buffer, and re-rendering of the layout.

But two issues was present:

First, we need a second roundtrip of the events, after the global
handle. This make the compositor to send the wl_outputs events earlier,
giving their geometry before our first show().

Then, the code that loop on them, if we don't already know the
current_output, was wrong. Because we changed the default state to
landscaped a while ago.

We also change how this code behave, we use the very first wl_output we
know about. Every behaviors are somehow wrong at this point, this one is
the simplest.

Now when starting wvkbd with only one screen, we don't need a second
loop anymore.

On situation where multiple screens are present, it will eventually need
a second one.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Willow Barraco 2024-11-05 07:59:43 +01:00 committed by Maarten van Gompel
parent 7d195c8217
commit 9cc8931b46

10
main.c
View File

@ -561,12 +561,7 @@ flip_landscape()
if (current_output) {
keyboard.landscape = current_output->w > current_output->h;
} else if (wl_outputs_size) {
for (int i = 0; i < wl_outputs_size; i += 1) {
if (wl_outputs[i].w > wl_outputs[i].h) {
keyboard.landscape = true;
break;
}
}
keyboard.landscape = wl_outputs[0].w > wl_outputs[0].h;
}
enum layout_id layer;
@ -1047,6 +1042,9 @@ main(int argc, char **argv)
die("virtual_keyboard_manager not available\n");
}
// A second round-trip to receive wl_outputs events
wl_display_roundtrip(display);
empty_region = wl_compositor_create_region(compositor);
popup_xdg_positioner = xdg_wm_base_create_positioner(wm_base);