From d51608a2c9fbab4b9e82b851130fa050c91a5a45 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 7 Aug 2020 16:54:09 -0400 Subject: [PATCH 1/4] wayland: Don't emit premature configure events We should not emit configure events before we are realized - size changes at this point are not relevant. This gets rid of a mysterious emission of GdkSurface::size-changed with a size of 52x52, that is happening when GtkWindow sets the shadow_width before the window is mapped. --- gdk/wayland/gdksurface-wayland.c | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index e05fdc4b63..ccc4fa67ef 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -881,24 +881,6 @@ gdk_wayland_surface_finalize (GObject *object) G_OBJECT_CLASS (gdk_wayland_surface_parent_class)->finalize (object); } -static void -gdk_wayland_surface_resize (GdkSurface *surface, - int width, - int height, - int scale) -{ - GdkDisplay *display; - GdkEvent *event; - - event = gdk_configure_event_new (surface, width, height); - - gdk_wayland_surface_update_size (surface, width, height, scale); - _gdk_surface_update_size (surface); - - display = gdk_surface_get_display (surface); - _gdk_wayland_display_deliver_event (display, event); -} - static gboolean is_realized_shell_surface (GdkWaylandSurface *impl) { @@ -920,6 +902,26 @@ is_realized_popup (GdkWaylandSurface *impl) impl->display_server.zxdg_popup_v6); } +static void +gdk_wayland_surface_resize (GdkSurface *surface, + int width, + int height, + int scale) +{ + gdk_wayland_surface_update_size (surface, width, height, scale); + _gdk_surface_update_size (surface); + + if (is_realized_shell_surface (GDK_WAYLAND_SURFACE (surface))) + { + GdkDisplay *display; + GdkEvent *event; + + event = gdk_configure_event_new (surface, width, height); + display = gdk_surface_get_display (surface); + _gdk_wayland_display_deliver_event (display, event); + } +} + static void gdk_wayland_surface_show (GdkSurface *surface, gboolean already_mapped); static void gdk_wayland_surface_hide (GdkSurface *surface); From e5cd2568c8072caad0e6b974ffd6d080462ad218 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Oct 2020 20:15:33 -0400 Subject: [PATCH 2/4] wayland: Don't save size when tiled Don't remember the surface size when we are in tiled state either. This matches the 'fixed_size' condition in gdk_wayland_surface_configure_toplevel. This change fixes an issue where moving a window first to tiled, then to maximized state and back would lead to the unmaximized window having the tiled dimensions. --- gdk/wayland/gdksurface-wayland.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index ccc4fa67ef..87eaae752d 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -333,7 +333,9 @@ _gdk_wayland_surface_save_size (GdkSurface *surface) { GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); - if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | GDK_TOPLEVEL_STATE_MAXIMIZED)) + if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | + GDK_TOPLEVEL_STATE_MAXIMIZED | + GDK_TOPLEVEL_STATE_TILED)) return; impl->saved_width = surface->width - impl->margin_left - impl->margin_right; From 082edd957e0fc4cd5dd6109664ba4c0b65f643c7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Oct 2020 20:17:50 -0400 Subject: [PATCH 3/4] wayland: Don't forget to reapply margins When using the saved size because the compositor told us to, we were forgetting to readd the margins. The visible symptom of this was the window getting smaller every time we went to tiled state and back. --- gdk/wayland/gdksurface-wayland.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index 87eaae752d..72cbc8c2d7 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -1354,6 +1354,11 @@ gdk_wayland_surface_configure_toplevel (GdkSurface *surface) /* Save size for next time we get 0x0 */ _gdk_wayland_surface_save_size (surface); } + else + { + width += impl->margin_left + impl->margin_right; + height += impl->margin_top + impl->margin_bottom; + } gdk_wayland_surface_resize (surface, width, height, impl->scale); } From 20fb7812df5134b84a0e4805f7d0aebe0bfeb1be Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Oct 2020 20:22:02 -0400 Subject: [PATCH 4/4] window: Fix window size snapping back We were not updating the remembered size at all when the window is interactively resized, causing it to snap back to its default size the next time we call gdk_toplevel_present(). This is a bandaid fix to prevent very broken resizing behavior, until we have properly redone toplevel sizing. Fixes: #3076 --- gtk/gtkwindow.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 947b178f76..7377502371 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -4729,6 +4729,22 @@ surface_size_changed (GtkWidget *widget, check_scale_changed (GTK_WINDOW (widget)); + if (!(priv->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | + GDK_TOPLEVEL_STATE_MAXIMIZED | + GDK_TOPLEVEL_STATE_TILED | + GDK_TOPLEVEL_STATE_TOP_TILED | + GDK_TOPLEVEL_STATE_RIGHT_TILED | + GDK_TOPLEVEL_STATE_BOTTOM_TILED | + GDK_TOPLEVEL_STATE_LEFT_TILED | + GDK_TOPLEVEL_STATE_MINIMIZED))) + { + GtkWindowGeometryInfo *info; + + info = gtk_window_get_geometry_info (GTK_WINDOW (widget), TRUE); + info->last.configure_request.width = width; + info->last.configure_request.height = height; + } + /* priv->configure_request_count incremented for each * configure request, and decremented to a min of 0 for * each configure notify. @@ -5490,7 +5506,6 @@ gtk_window_move_resize (GtkWindow *window) info->last.geometry = new_geometry; info->last.flags = new_flags; info->last.configure_request = new_request; - /* need to set PPosition so the WM will look at our position, * but we don't want to count PPosition coming and going as a hints * change for future iterations. So we saved info->last prior to