dragsurface: Add compute-size signal
authorIvan Molodetskikh <yalterz@gmail.com>
Sun, 5 Mar 2023 18:14:56 +0000 (10:14 -0800)
committerIvan Molodetskikh <yalterz@gmail.com>
Wed, 15 Mar 2023 02:41:44 +0000 (19:41 -0700)
Similarly to GdkToplevel, GdkDragSurface's compute-size should be called
by backends to query the current surface size, and should be connected
to by widget implementations (like GtkDragIcon) to report the current
size.

GdkDragSurface-backed widgets are not parented to an existing widget,
unlike popovers, and like toplevels. This means that there's nobody to
actively call gdk_drag_surface_present() to update the size, and
GdkDragSurface should do it on its own, just like GdkToplevel.

gdk/gdkdragsurface.c
gdk/gdkdragsurfaceprivate.h

index 97c3e7dd36ac92922760a7f18ff2470776ed5b76..dcb6c28cca768ed5a516143be2aad556d94180f5 100644 (file)
 
 G_DEFINE_INTERFACE (GdkDragSurface, gdk_drag_surface, GDK_TYPE_SURFACE)
 
+enum
+{
+  COMPUTE_SIZE,
+
+  N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
+void
+gdk_drag_surface_notify_compute_size (GdkDragSurface     *surface,
+                                      GdkDragSurfaceSize *size)
+{
+  g_signal_emit (surface, signals[COMPUTE_SIZE], 0, size);
+}
+
 static gboolean
 gdk_drag_surface_default_present (GdkDragSurface *drag_surface,
                                   int          width,
@@ -49,6 +65,35 @@ static void
 gdk_drag_surface_default_init (GdkDragSurfaceInterface *iface)
 {
   iface->present = gdk_drag_surface_default_present;
+
+  /**
+   * GdkDragSurface::compute-size:
+   * @surface: a `GdkDragSurface`
+   * @size: (type Gdk.DragSurfaceSize) (out caller-allocates): a
+   * `GdkDragSurfaceSize`
+   *
+   * Emitted when the size for the surface needs to be computed, when it is
+   * present.
+   *
+   * It will normally be emitted during the native surface layout cycle when the
+   * surface size needs to be recomputed.
+   *
+   * It is the responsibility of the drag surface user to handle this signal and
+   * compute the desired size of the surface, storing the computed size in the
+   * [struct@Gdk.DragSurfaceSize] object. Failing to do so will result in an
+   * arbitrary size being used as a result.
+   *
+   * Since: 4.12
+   */
+  signals[COMPUTE_SIZE] =
+    g_signal_new (I_("compute-size"),
+                  GDK_TYPE_DRAG_SURFACE,
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  NULL,
+                  G_TYPE_NONE, 1,
+                  GDK_TYPE_DRAG_SURFACE_SIZE);
 }
 
 /**
index e32cfd780c22b7873533f6177b1ddca40ea24528..d565b8418d65f8d50ee44cdb9eac9fd81a5443c3 100644 (file)
@@ -2,6 +2,7 @@
 #define __GDK_DRAG_SURFACE_PRIVATE_H__
 
 #include "gdkdragsurface.h"
+#include "gdkdragsurfacesize.h"
 
 G_BEGIN_DECLS
 
@@ -15,6 +16,9 @@ struct _GdkDragSurfaceInterface
                         int             height);
 };
 
+void gdk_drag_surface_notify_compute_size (GdkDragSurface     *surface,
+                                           GdkDragSurfaceSize *size);
+
 G_END_DECLS
 
 #endif /* __GDK_DRAG_SURFACE_PRIVATE_H__ */