dragicon: Handle compute-size
Compute our size when requested by the backend. This makes GtkDragIcons actually recompute their size when it changes, instead of getting stuck with the first size and potentially underallocating.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
|
||||
#include "gdk/gdksurfaceprivate.h"
|
||||
#include "gdk/gdkdragsurfacesize.h"
|
||||
|
||||
/* for the drag icons */
|
||||
#include "gtkcolorswatchprivate.h"
|
||||
@@ -183,6 +184,16 @@ surface_render (GdkSurface *surface,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
surface_compute_size (GdkDragSurface *surface,
|
||||
GdkDragSurfaceSize *size,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkRequisition nat_size;
|
||||
gtk_widget_get_preferred_size (widget, NULL, &nat_size);
|
||||
gdk_drag_surface_size_set_size (size, nat_size.width, nat_size.height);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_icon_realize (GtkWidget *widget)
|
||||
{
|
||||
@@ -193,6 +204,7 @@ gtk_drag_icon_realize (GtkWidget *widget)
|
||||
gdk_surface_set_widget (icon->surface, widget);
|
||||
|
||||
g_signal_connect (icon->surface, "render", G_CALLBACK (surface_render), widget);
|
||||
g_signal_connect (icon->surface, "compute-size", G_CALLBACK (surface_compute_size), widget);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_drag_icon_parent_class)->realize (widget);
|
||||
|
||||
@@ -216,6 +228,7 @@ gtk_drag_icon_unrealize (GtkWidget *widget)
|
||||
if (icon->surface)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (icon->surface, surface_render, widget);
|
||||
g_signal_handlers_disconnect_by_func (icon->surface, surface_compute_size, widget);
|
||||
gdk_surface_set_widget (icon->surface, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user