From c3dde05d338d78b0f6f1c3d3fb16e47513af4351 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 5 Mar 2023 10:14:56 -0800 Subject: [PATCH] dragsurface: Add compute-size signal 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 | 45 +++++++++++++++++++++++++++++++++++++ gdk/gdkdragsurfaceprivate.h | 4 ++++ 2 files changed, 49 insertions(+) diff --git a/gdk/gdkdragsurface.c b/gdk/gdkdragsurface.c index 97c3e7dd36..dcb6c28cca 100644 --- a/gdk/gdkdragsurface.c +++ b/gdk/gdkdragsurface.c @@ -37,6 +37,22 @@ 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); } /** diff --git a/gdk/gdkdragsurfaceprivate.h b/gdk/gdkdragsurfaceprivate.h index e32cfd780c..d565b8418d 100644 --- a/gdk/gdkdragsurfaceprivate.h +++ b/gdk/gdkdragsurfaceprivate.h @@ -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__ */ -- 2.30.2