x11/surface: Get current drag surface size with compute-size signal
authorIvan Molodetskikh <yalterz@gmail.com>
Tue, 7 Mar 2023 04:49:19 +0000 (20:49 -0800)
committerIvan Molodetskikh <yalterz@gmail.com>
Wed, 15 Mar 2023 02:41:44 +0000 (19:41 -0700)
Query and update size of drag surfaces, similarly to how it's done for
the Wayland backend in the previous commit.

gdk/x11/gdksurface-x11.c

index 044a1185fa4553f89f7fd3c8dfb7da7c86863ee6..8f56fe5e74da09c0ad9c936c75607648b1c42a03 100644 (file)
@@ -40,6 +40,7 @@
 #include "gdkglcontext-x11.h"
 #include "gdkprivate-x11.h"
 #include "gdktextureprivate.h"
+#include "gdkdragsurfacesizeprivate.h"
 
 #include "gdkseatprivate.h"
 #include "gdkprivate.h"
@@ -345,6 +346,36 @@ compute_toplevel_size (GdkSurface *surface,
   return FALSE;
 }
 
+static gboolean
+compute_drag_surface_size (GdkSurface *surface,
+                           int        *width,
+                           int        *height)
+{
+  GdkX11Surface *impl = GDK_X11_SURFACE (surface);
+  GdkDragSurfaceSize size;
+
+  gdk_drag_surface_size_init (&size);
+  size.width = impl->next_layout.configured_width;
+  size.height = impl->next_layout.configured_height;
+
+  gdk_drag_surface_notify_compute_size (GDK_DRAG_SURFACE (surface), &size);
+
+  if ((impl->last_computed_width != size.width ||
+        impl->last_computed_height != size.height) &&
+      (impl->next_layout.configured_width != size.width ||
+        impl->next_layout.configured_height != size.height))
+    {
+      *width = size.width;
+      *height = size.height;
+      impl->last_computed_width = size.width;
+      impl->last_computed_height = size.height;
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static gboolean
 compute_size_idle (gpointer user_data)
 {
@@ -394,6 +425,24 @@ gdk_x11_surface_compute_size (GdkSurface *surface)
                                        impl->surface_scale);
         }
 
+      impl->next_layout.surface_geometry_dirty = FALSE;
+      impl->next_layout.configure_pending = FALSE;
+    }
+  else if (GDK_IS_DRAG_SURFACE (surface))
+    {
+      int width, height;
+
+      if (compute_drag_surface_size (surface, &width, &height))
+        gdk_x11_surface_toplevel_resize (surface, width, height);
+
+      if (surface->resize_count == 0)
+        {
+          gdk_x11_surface_update_size (impl,
+                                       impl->next_layout.configured_width,
+                                       impl->next_layout.configured_height,
+                                       impl->surface_scale);
+        }
+
       impl->next_layout.surface_geometry_dirty = FALSE;
       impl->next_layout.configure_pending = FALSE;
     }