Gdk/Win32: Fix resizing surfaces
authorChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 2 Feb 2021 09:30:55 +0000 (17:30 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 2 Feb 2021 09:36:32 +0000 (17:36 +0800)
This attempts to fix the counter-intuitive resizing of surfaces in GTK4 where
the surface grows or shrinks at the right and/or bottom edge when the window
resized from the top and/or left edge(s).

This is not yet perfect as the window stutters upon resizing from the top
and/or left edges, but at least makes resizing more intuitive.

gdk/win32/gdksurface-win32.c
gdk/win32/gdksurface-win32.h

index b9ec79e9edbc632408c368e6de4f5fb3aab7a780..c690fed206a897c8065c4954249ec26e29749c34 100644 (file)
@@ -1633,42 +1633,48 @@ gdk_win32_surface_get_geometry (GdkSurface *window,
       RECT rect;
       GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
 
-      API_CALL (GetClientRect, (GDK_SURFACE_HWND (window), &rect));
-
-         POINT pt;
+      if (GDK_IS_TOPLEVEL (window) && impl->drag_move_resize_context.native_move_resize_pending)
+         rect = impl->next_layout.configured_rect;
+      else
+        {
+          POINT pt;
           GdkSurface *parent;
-         
+
           if (GDK_IS_TOPLEVEL (window))
             parent = NULL;
           else if (GDK_IS_POPUP (window))
             parent = gdk_popup_get_parent (GDK_POPUP (window));
           else
             parent = NULL;
-         
 
-         pt.x = rect.left;
-         pt.y = rect.top;
-         ClientToScreen (GDK_SURFACE_HWND (window), &pt);
-          if (parent)
-           ScreenToClient (GDK_SURFACE_HWND (parent), &pt);
-         rect.left = pt.x;
-         rect.top = pt.y;
+          API_CALL (GetClientRect, (GDK_SURFACE_HWND (window), &rect));
 
-         pt.x = rect.right;
-         pt.y = rect.bottom;
-         ClientToScreen (GDK_SURFACE_HWND (window), &pt);
+          pt.x = rect.left;
+          pt.y = rect.top;
+             ClientToScreen (GDK_SURFACE_HWND (window), &pt);
           if (parent)
-           ScreenToClient (GDK_SURFACE_HWND (parent), &pt);
-         rect.right = pt.x;
-         rect.bottom = pt.y;
+            ScreenToClient (GDK_SURFACE_HWND (parent), &pt);
 
-         if (parent == NULL)
-           {
-             rect.left += _gdk_offset_x * impl->surface_scale;
-             rect.top += _gdk_offset_y * impl->surface_scale;
-             rect.right += _gdk_offset_x * impl->surface_scale;
-             rect.bottom += _gdk_offset_y * impl->surface_scale;
-           }
+          rect.left = pt.x;
+          rect.top = pt.y;
+
+          pt.x = rect.right;
+          pt.y = rect.bottom;
+          ClientToScreen (GDK_SURFACE_HWND (window), &pt);
+          if (parent)
+            ScreenToClient (GDK_SURFACE_HWND (parent), &pt);
+
+          rect.right = pt.x;
+          rect.bottom = pt.y;
+
+             if (parent == NULL)
+               {
+                 rect.left += _gdk_offset_x * impl->surface_scale;
+                 rect.top += _gdk_offset_y * impl->surface_scale;
+                 rect.right += _gdk_offset_x * impl->surface_scale;
+                 rect.bottom += _gdk_offset_y * impl->surface_scale;
+               }
+        }
 
       if (x)
        *x = rect.left / impl->surface_scale;
@@ -3947,6 +3953,8 @@ gdk_win32_surface_do_move_resize_drag (GdkSurface *window,
 
           impl->unscaled_width = new_rect.right - new_rect.left;
           impl->unscaled_height = new_rect.bottom - new_rect.top;
+
+          impl->next_layout.configured_rect = new_rect;
           impl->next_layout.configured_width = (impl->unscaled_width + scale - 1) / scale;
           impl->next_layout.configured_height = (impl->unscaled_height + scale - 1) / scale;
         }
index 7c937cd0fc84634171d6c1768b867d6e0c00bdb3..6be358338ba5e883ed8ec04d0659708fabdc69b4 100644 (file)
@@ -342,6 +342,7 @@ struct _GdkWin32Surface
   struct {
     int configured_width;
     int configured_height;
+    RECT configured_rect;
   } next_layout;
 
 #ifdef GDK_WIN32_ENABLE_EGL