From b083169ee4c6d0c76dd386fc0b937f83fb655b08 Mon Sep 17 00:00:00 2001 From: Willow Barraco Date: Wed, 28 Feb 2024 11:08:53 +0100 Subject: [PATCH] Minimise visual glitches when starting Most of the time, the first frame have to be rendered without knowing which output is the current one. It means the first window could have incorrect dimensions. This cause other program surface to shrink, then grow back. Let's try a smoother approach: If we don't know the current output, we could check if one of them is landscaped. If this is the case, we start landscaped to minimise the visual glitch. Also, the compositor might choose to not send any output geometry information before the first surface role is assigned (sway master 829c75b9). Meaning after our initial set_size request. So we have to start landscaped, and eventually flip to horizontal. Thanks to the patch "Skip the first resize when landscaped while starting", we do not draw multiple time on the buffer when we switch to vertical mode. This should cover most of the cases, and produce a more discrete start. Signed-off-by: Willow Barraco Signed-off-by: Maarten van Gompel --- main.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index a17812c..bc73c8a 100644 --- a/main.c +++ b/main.c @@ -528,7 +528,18 @@ static const struct wp_fractional_scale_v1_listener void flip_landscape() { - keyboard.landscape = current_output->w > current_output->h; + bool previous_landscape = keyboard.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; + } + } + } enum layout_id layer; if (keyboard.landscape) { @@ -709,6 +720,8 @@ show() wl_display_sync(display); + flip_landscape(); + draw_surf.surf = wl_compositor_create_surface(compositor); wl_surface_add_listener(draw_surf.surf, &surface_listener, NULL); if (wfs_mgr && viewporter) { @@ -773,8 +786,8 @@ main(int argc, char **argv) /* parse command line arguments */ char *layer_names_list = NULL, *landscape_layer_names_list = NULL; char *fc_font_pattern = NULL; - height = normal_height = KBD_PIXEL_HEIGHT; - landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT; + height = landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT; + normal_height = KBD_PIXEL_HEIGHT; char *tmp; if ((tmp = getenv("WVKBD_LAYERS"))) @@ -790,6 +803,7 @@ main(int argc, char **argv) keyboard.layers = (enum layout_id *)&layers; keyboard.landscape_layers = (enum layout_id *)&landscape_layers; keyboard.schemes = schemes; + keyboard.landscape = true; keyboard.layer_index = 0; keyboard.preferred_scale = 1; keyboard.preferred_fractional_scale = 0; @@ -896,13 +910,13 @@ main(int argc, char **argv) usage(argv[0]); exit(1); } - height = normal_height = atoi(argv[++i]); + normal_height = atoi(argv[++i]); } else if (!strcmp(argv[i], "-L")) { if (i >= argc - 1) { usage(argv[0]); exit(1); } - landscape_height = atoi(argv[++i]); + height = landscape_height = atoi(argv[++i]); } else if (!strcmp(argv[i], "-D")) { keyboard.debug = true; } else if ((!strcmp(argv[i], "-fn")) || (!strcmp(argv[i], "--fn"))) {