From 9cc8931b464c1df2f362a57dec63d07821a5893b Mon Sep 17 00:00:00 2001 From: Willow Barraco Date: Tue, 5 Nov 2024 07:59:43 +0100 Subject: [PATCH] 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 Signed-off-by: Maarten van Gompel --- main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index c7f0999..f3970e6 100644 --- a/main.c +++ b/main.c @@ -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);