GDK-Win32: Fix AeroSnap indicator and positioning
authorChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 6 Jul 2021 09:15:39 +0000 (17:15 +0800)
committerLuca Bacci <luca.bacci982@gmail.com>
Thu, 18 Nov 2021 11:40:57 +0000 (12:40 +0100)
Ensure that we take the DPI scaling into account so that surfaces will
be placed at their correct positions upon an AeroSnap operation on HiDPI
displays.

Also, use the X coordinate of the surface as-is during snap up so that
we do not inadvertently move the surface to the very left.  Also fix the
AeroSnap indicator drawing for snap up so that it is drawn at the
correct places.

Since we are updating these functions, make the old GdkWindow-era
variable names to match better the names we use nowadays.

gdk/win32/gdksurface-win32.c

index 15098661917802d2f4fc305dd8cbdd737613e7b7..1a26009dd436f478afa5a0618203d3e5b1b991e6 100644 (file)
@@ -2291,95 +2291,87 @@ stash_window (GdkSurface          *window,
 }
 
 static void
-snap_up (GdkSurface *window)
+snap_up (GdkSurface *surface)
 {
   SHORT maxysize;
   int x, y;
   int width, height;
   GdkWin32Surface *impl;
 
-  impl = GDK_WIN32_SURFACE (window);
+  impl = GDK_WIN32_SURFACE (surface);
 
   impl->snap_state = GDK_WIN32_AEROSNAP_STATE_FULLUP;
 
-  stash_window (window, impl);
+  stash_window (surface, impl);
 
   maxysize = GetSystemMetrics (SM_CYVIRTUALSCREEN) / impl->surface_scale;
   x = y = 0;
-  width = gdk_surface_get_width (window);
+  width = gdk_surface_get_width (surface);
 
   y = 0;
   height = maxysize;
 
-  x = x - impl->shadow.left;
-  y = y - impl->shadow.top;
+  x = surface->x - impl->shadow.left / impl->surface_scale;
+  y = y - impl->shadow.top / impl->surface_scale;
   width += impl->shadow_x;
   height += impl->shadow_y;
 
-  /* XXX: FIXME, AeroSnap snap_up() not really working well,
-   *
-   *    * The snap_up() puts the window at the top left corner.
-   *    * Without the following call, the height maximizes but we see a spew of
-   *      "GdkToplevelSize: geometry size (x,y) exceeds bounds" warnings
-   */
-  compute_toplevel_size (window, TRUE, &width, &height);
-
-  gdk_win32_surface_move_resize (window, x, y, width, height);
+  gdk_win32_surface_move_resize (surface, x, y, width, height);
 }
 
 static void
-snap_left (GdkSurface  *window,
+snap_left (GdkSurface *surface,
            GdkMonitor *monitor,
            GdkMonitor *snap_monitor)
 {
   GdkRectangle rect;
   GdkWin32Surface *impl;
 
-  impl = GDK_WIN32_SURFACE (window);
+  impl = GDK_WIN32_SURFACE (surface);
 
   impl->snap_state = GDK_WIN32_AEROSNAP_STATE_HALFLEFT;
 
   gdk_win32_monitor_get_workarea (snap_monitor, &rect);
 
-  stash_window (window, impl);
+  stash_window (surface, impl);
 
   rect.width = rect.width / 2;
 
-  rect.x = rect.x - impl->shadow.left;
-  rect.y = rect.y - impl->shadow.top;
+  rect.x = rect.x - impl->shadow.left / impl->surface_scale;
+  rect.y = rect.y - impl->shadow.top / impl->surface_scale;
   rect.width = rect.width + impl->shadow_x;
   rect.height = rect.height + impl->shadow_y;
 
-  gdk_win32_surface_move_resize (window,
+  gdk_win32_surface_move_resize (surface,
                                  rect.x, rect.y,
                                  rect.width, rect.height);
 }
 
 static void
-snap_right (GdkSurface  *window,
+snap_right (GdkSurface *surface,
             GdkMonitor *monitor,
             GdkMonitor *snap_monitor)
 {
   GdkRectangle rect;
   GdkWin32Surface *impl;
 
-  impl = GDK_WIN32_SURFACE (window);
+  impl = GDK_WIN32_SURFACE (surface);
 
   impl->snap_state = GDK_WIN32_AEROSNAP_STATE_HALFRIGHT;
 
   gdk_win32_monitor_get_workarea (snap_monitor, &rect);
 
-  stash_window (window, impl);
+  stash_window (surface, impl);
 
   rect.width = rect.width / 2;
   rect.x += rect.width;
 
-  rect.x = rect.x - impl->shadow.left;
-  rect.y = rect.y - impl->shadow.top;
+  rect.x = rect.x - impl->shadow.left / impl->surface_scale;
+  rect.y = rect.y - impl->shadow.top / impl->surface_scale;
   rect.width = rect.width + impl->shadow_x;
   rect.height = rect.height + impl->shadow_y;
 
-  gdk_win32_surface_move_resize (window,
+  gdk_win32_surface_move_resize (surface,
                                  rect.x, rect.y,
                                  rect.width, rect.height);
 }
@@ -3010,6 +3002,7 @@ update_fullup_indicator (GdkSurface                   *window,
   to.height = gdk_surface_get_height (window);
 
   to.y = 0;
+  to.x = window->x;
   to.height = maxysize;
   from = context->indicator_target;
 
@@ -3162,6 +3155,7 @@ start_indicator (GdkSurface                   *window,
       end_size.height = workarea.height;
       break;
     case GDK_WIN32_AEROSNAP_STATE_FULLUP:
+      start_size.x = end_size.x = window->x;
       end_size.y = 0;
       end_size.height = maxysize;
       break;