summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-05-01 22:41:20 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-05-01 23:05:09 +0000
commit33a8108f199e659a1596324e0daf2b866d55c495 (patch)
tree917f5ee91a77a4adf30ff1e52e07d8237911d3d6
parent78d254370c5240b76d320f8ceb374da153843926 (diff)
downloadgtk+-33a8108f199e659a1596324e0daf2b866d55c495.tar.gz
window: Implement display change via root/unroot
Export gtk_widget_root/unroot privately, make them work on roots, and use them in gtk_window_set_display. This gets us to a single way to listen for display changes, the root property.
-rw-r--r--gtk/gtkwidget.c41
-rw-r--r--gtk/gtkwidgetprivate.h2
-rw-r--r--gtk/gtkwindow.c4
3 files changed, 27 insertions, 20 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index a458e8aca3..abd5f5fc24 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -632,8 +632,6 @@ static void gtk_widget_real_move_focus (GtkWidget
GtkDirectionType direction);
static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
GtkDirectionType direction);
-static void gtk_widget_root (GtkWidget *widget);
-static void gtk_widget_unroot (GtkWidget *widget);
#ifdef G_ENABLE_CONSISTENCY_CHECKS
static void gtk_widget_verify_invariants (GtkWidget *widget);
static void gtk_widget_push_verify_invariants (GtkWidget *widget);
@@ -2865,21 +2863,22 @@ gtk_widget_new (GType type,
return widget;
}
-static void
+void
gtk_widget_root (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
- /* roots are rooted by default */
- if (GTK_IS_ROOT (widget))
- return;
-
- g_assert (priv->root == NULL);
g_assert (!priv->realized);
- g_assert (priv->parent);
- g_assert (priv->parent->priv->root);
- priv->root = priv->parent->priv->root;
+ if (GTK_IS_ROOT (widget))
+ {
+ g_assert (priv->root == GTK_ROOT (widget));
+ }
+ else
+ {
+ g_assert (priv->root == NULL);
+ priv->root = priv->parent->priv->root;
+ }
if (priv->context)
gtk_style_context_set_display (priv->context, gtk_root_get_display (priv->root));
@@ -2889,19 +2888,16 @@ gtk_widget_root (GtkWidget *widget)
GTK_WIDGET_GET_CLASS (widget)->root (widget);
- g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
+ if (!GTK_IS_ROOT (widget))
+ g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
}
-static void
+void
gtk_widget_unroot (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkWidgetSurfaceTransformData *surface_transform_data;
- /* roots are rooted by default and cannot be unrooted */
- if (GTK_IS_ROOT (widget))
- return;
-
g_assert (priv->root);
g_assert (!priv->realized);
@@ -2915,9 +2911,16 @@ gtk_widget_unroot (GtkWidget *widget)
if (priv->context)
gtk_style_context_set_display (priv->context, gdk_display_get_default ());
- priv->root = NULL;
+ if (g_object_get_qdata (G_OBJECT (widget), quark_pango_context))
+ g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
+
+ _gtk_tooltip_hide (widget);
- g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
+ if (!GTK_IS_ROOT (widget))
+ {
+ priv->root = NULL;
+ g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
+ }
}
/**
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 8d8b656be0..11fd41a673 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -209,6 +209,8 @@ struct _GtkWidgetPrivate
GdkCursor *cursor;
};
+void gtk_widget_root (GtkWidget *widget);
+void gtk_widget_unroot (GtkWidget *widget);
GtkCssNode * gtk_widget_get_css_node (GtkWidget *widget);
void _gtk_widget_set_visible_flag (GtkWidget *widget,
gboolean visible);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index bdff204913..de59910b0c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -8510,7 +8510,9 @@ gtk_window_set_display (GtkWindow *window,
G_CALLBACK (gtk_window_on_theme_variant_changed), window);
#endif
- _gtk_widget_propagate_display_changed (widget, previous_display);
+ gtk_widget_unroot (widget);
+ gtk_widget_root (widget);
+
g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_DISPLAY]);
if (was_mapped)