From 3c85d58f5a840d52e8d2b66c35d6ed7c48f969e6 Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Sun, 29 Nov 2020 22:34:25 -0700 Subject: [PATCH] xdg_shell: be smarter about expected resizes Previously in 32b93ef6 any client resize would create a new transaction, but most client resizes are actually expected since we request them. We should only need a new transaction when the client sends us an unexpected size. --- sway/desktop/xdg_shell.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index f02021e1b..80842cc4c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -291,20 +291,40 @@ static void handle_commit(struct wl_listener *listener, void *data) { new_geo.x != view->geometry.x || new_geo.y != view->geometry.y; - if (new_size) { - // The view has unexpectedly sent a new size + // Did the view send the size we expect? + bool expected = !new_size; + if (view->container->node.instruction) { + struct sway_container_state *requested = + &view->container->node.instruction->container_state; + expected = requested->content_width == new_geo.width && + requested->content_height == new_geo.height; + } + + if (new_size && expected) { + // The client has resized as requested + memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); + transaction_notify_view_ready_by_serial(view, + xdg_surface->configure_serial); + } else if (new_size && !expected) { + // The view has sent an unexpected size desktop_damage_view(view); view_update_size(view, new_geo.width, new_geo.height); memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); desktop_damage_view(view); transaction_commit_dirty(); - } - - if (view->container->node.instruction) { + if (view->container->node.instruction) { + // The size is different than requested + transaction_notify_view_ready_by_serial(view, + xdg_surface->configure_serial); + } else { + // The view has resized unprompted + transaction_notify_view_ready_immediately(view); + } + } else if (!new_size && !expected) { + // The view has unexpectedly refused to resize + desktop_damage_view(view); transaction_notify_view_ready_by_serial(view, xdg_surface->configure_serial); - } else if (new_size) { - transaction_notify_view_ready_immediately(view); } view_damage_from(view);