Compare commits

...

5 Commits

Author SHA1 Message Date
Matthias Clasen
07959e50ad tooltipwindow: Stop using the ::size-allocate signal
Instead of connecting to ::size-allocate, call
gtk_native_set_tooltip and rely on the native
to allocate the tooltip window.
2020-05-05 22:11:55 -04:00
Matthias Clasen
b72de7e067 popover: Implement set_tooltip
Store the tooltip, and call check_resize on it
when necessary.
2020-05-05 22:11:13 -04:00
Matthias Clasen
a8df66f4fc window: Implement set_tooltip
Store the tooltip, and call check_resize on it
when necessary.
2020-05-05 22:10:39 -04:00
Matthias Clasen
4148764f10 native: Add a set_tooltip method
This lets us associate a tooltip window with the
native, so we can allocate it when necessary, without
having to rely on the ::size-allocate signal.
2020-05-05 22:09:44 -04:00
Matthias Clasen
1ec51a6b92 tooltipwindow: Drop some dead code 2020-05-05 21:19:20 -04:00
5 changed files with 62 additions and 33 deletions

View File

@@ -60,12 +60,19 @@ gtk_native_default_check_resize (GtkNative *self)
{
}
static void
gtk_native_default_set_tooltip (GtkNative *self,
GtkNative *tooltip)
{
}
static void
gtk_native_default_init (GtkNativeInterface *iface)
{
iface->get_renderer = gtk_native_default_get_renderer;
iface->get_surface_transform = gtk_native_default_get_surface_transform;
iface->check_resize = gtk_native_default_check_resize;
iface->set_tooltip = gtk_native_default_set_tooltip;
}
/**
@@ -149,3 +156,14 @@ gtk_native_get_for_surface (GdkSurface *surface)
return NULL;
}
void
gtk_native_set_tooltip (GtkNative *self,
GtkNative *tooltip)
{
g_return_if_fail (GTK_IS_NATIVE (self));
g_return_if_fail (tooltip == NULL || GTK_IS_NATIVE (tooltip));
GTK_NATIVE_GET_IFACE (self)->set_tooltip (self, tooltip);
}

View File

@@ -53,6 +53,9 @@ struct _GtkNativeInterface
int *y);
void (* check_resize) (GtkNative *self);
void (* set_tooltip) (GtkNative *self,
GtkNative *tooltip);
};
GDK_AVAILABLE_IN_ALL
@@ -67,6 +70,10 @@ GdkSurface *gtk_native_get_surface (GtkNative *self);
GDK_AVAILABLE_IN_ALL
GskRenderer *gtk_native_get_renderer (GtkNative *self);
GDK_AVAILABLE_IN_ALL
void gtk_native_set_tooltip (GtkNative *self,
GtkNative *tooltip);
G_END_DECLS
#endif /* __GTK_NATIVE_H__ */

View File

@@ -156,6 +156,8 @@ typedef struct {
GtkCssNode *arrow_node;
GskRenderNode *arrow_render_node;
GtkNative *tooltip;
GdkPopupLayout *layout;
GdkRectangle final_rect;
GtkPositionType final_position;
@@ -231,6 +233,16 @@ gtk_popover_native_get_surface_transform (GtkNative *native,
_gtk_css_number_value_get (style->size->padding_top, 100);
}
static void
gtk_popover_native_set_tooltip (GtkNative *native,
GtkNative *tooltip)
{
GtkPopover *popover = GTK_POPOVER (native);
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
priv->tooltip = tooltip;
}
static gboolean
is_gravity_facing_north (GdkGravity gravity)
{
@@ -1420,6 +1432,9 @@ gtk_popover_size_allocate (GtkWidget *widget,
gtk_popover_update_shape (popover);
g_clear_pointer (&priv->arrow_render_node, gsk_render_node_unref);
}
if (priv->tooltip && gtk_widget_get_visible (GTK_WIDGET (priv->tooltip)))
gtk_native_check_resize (priv->tooltip);
}
static void
@@ -1890,6 +1905,7 @@ gtk_popover_native_interface_init (GtkNativeInterface *iface)
iface->get_renderer = gtk_popover_native_get_renderer;
iface->get_surface_transform = gtk_popover_native_get_surface_transform;
iface->check_resize = gtk_popover_native_check_resize;
iface->set_tooltip = gtk_popover_native_set_tooltip;
}
static GtkBuildableIface *parent_buildable_iface;

View File

@@ -191,13 +191,6 @@ surface_state_changed (GtkWidget *widget)
}
}
static void
surface_size_changed (GtkWidget *widget,
guint width,
guint height)
{
}
static gboolean
surface_render (GdkSurface *surface,
cairo_region_t *region,
@@ -228,7 +221,6 @@ gtk_tooltip_window_realize (GtkWidget *widget)
gdk_surface_set_widget (window->surface, widget);
g_signal_connect_swapped (window->surface, "notify::state", G_CALLBACK (surface_state_changed), widget);
g_signal_connect_swapped (window->surface, "size-changed", G_CALLBACK (surface_size_changed), widget);
g_signal_connect (window->surface, "render", G_CALLBACK (surface_render), widget);
g_signal_connect (window->surface, "event", G_CALLBACK (surface_event), widget);
@@ -248,7 +240,6 @@ gtk_tooltip_window_unrealize (GtkWidget *widget)
g_clear_object (&window->renderer);
g_signal_handlers_disconnect_by_func (window->surface, surface_state_changed, widget);
g_signal_handlers_disconnect_by_func (window->surface, surface_size_changed, widget);
g_signal_handlers_disconnect_by_func (window->surface, surface_render, widget);
g_signal_handlers_disconnect_by_func (window->surface, surface_event, widget);
gdk_surface_set_widget (window->surface, NULL);
@@ -364,12 +355,6 @@ gtk_tooltip_window_hide (GtkWidget *widget)
gtk_widget_unmap (widget);
}
static void size_changed (GtkWidget *widget,
int width,
int height,
int baseline,
GtkTooltipWindow *window);
static void
gtk_tooltip_window_dispose (GObject *object)
{
@@ -377,7 +362,7 @@ gtk_tooltip_window_dispose (GObject *object)
if (window->relative_to)
{
g_signal_handlers_disconnect_by_func (window->relative_to, size_changed, window);
gtk_native_set_tooltip (GTK_NATIVE (window->relative_to), NULL);
gtk_widget_unparent (GTK_WIDGET (window));
}
@@ -532,16 +517,6 @@ gtk_tooltip_window_set_custom_widget (GtkTooltipWindow *window,
}
}
static void
size_changed (GtkWidget *widget,
int width,
int height,
int baseline,
GtkTooltipWindow *window)
{
gtk_native_check_resize (GTK_NATIVE (window));
}
void
gtk_tooltip_window_set_relative_to (GtkTooltipWindow *window,
GtkWidget *relative_to)
@@ -555,7 +530,7 @@ gtk_tooltip_window_set_relative_to (GtkTooltipWindow *window,
if (window->relative_to)
{
g_signal_handlers_disconnect_by_func (window->relative_to, size_changed, window);
gtk_native_set_tooltip (GTK_NATIVE (window->relative_to), NULL);
gtk_widget_unparent (GTK_WIDGET (window));
}
@@ -563,9 +538,7 @@ gtk_tooltip_window_set_relative_to (GtkTooltipWindow *window,
if (window->relative_to)
{
g_signal_connect (window->relative_to, "size-allocate", G_CALLBACK (size_changed), window);
gtk_css_node_set_parent (gtk_widget_get_css_node (GTK_WIDGET (window)),
gtk_widget_get_css_node (relative_to));
gtk_native_set_tooltip (GTK_NATIVE (relative_to), GTK_NATIVE (window));
gtk_widget_set_parent (GTK_WIDGET (window), relative_to);
}

View File

@@ -267,6 +267,8 @@ typedef struct
GdkToplevelLayout *layout;
GdkCursor *resize_cursor;
GtkNative *tooltip;
} GtkWindowPrivate;
enum {
@@ -2130,6 +2132,16 @@ gtk_window_native_get_renderer (GtkNative *native)
return priv->renderer;
}
static void
gtk_window_native_set_tooltip (GtkNative *native,
GtkNative *tooltip)
{
GtkWindow *self = GTK_WINDOW (native);
GtkWindowPrivate *priv = gtk_window_get_instance_private (self);
priv->tooltip = tooltip;
}
static GtkConstraintSolver *
gtk_window_root_get_constraint_solver (GtkRoot *root)
{
@@ -2222,6 +2234,7 @@ gtk_window_native_interface_init (GtkNativeInterface *iface)
iface->get_renderer = gtk_window_native_get_renderer;
iface->get_surface_transform = gtk_window_native_get_surface_transform;
iface->check_resize = gtk_window_native_check_resize;
iface->set_tooltip = gtk_window_native_set_tooltip;
}
/**
@@ -5080,13 +5093,15 @@ gtk_window_size_allocate (GtkWidget *widget,
{
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
GtkWidget *child = priv->child;
GtkAllocation child_allocation;
_gtk_window_set_allocation (window, width, height, &child_allocation);
if (child && gtk_widget_get_visible (child))
gtk_widget_size_allocate (child, &child_allocation, -1);
if (priv->child && gtk_widget_get_visible (priv->child))
gtk_widget_size_allocate (priv->child, &child_allocation, -1);
if (priv->tooltip && gtk_widget_get_visible (GTK_WIDGET (priv->tooltip)))
gtk_native_check_resize (priv->tooltip);
}
gboolean