[gtk/wip/matthiasc/popup2: 349/353] widget: Review and replace uses of get_toplevel



commit f139cf29c57d26a9b859bbd4f6b2476386445350
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 17 19:41:26 2019 -0400

    widget: Review and replace uses of get_toplevel
    
    Now that roots can have parent widgets, we need to
    carefully examine all calls of gtk_widget_get_toplevel,
    and replace them with gtk_widget_get_root if we want
    the nearest root, and not the ultimate end of the parent
    chain.

 gtk/a11y/gtkmenuitemaccessible.c |   9 ++--
 gtk/gtkappchooserbutton.c        |  12 ++---
 gtk/gtkcellrendereraccel.c       |   2 +-
 gtk/gtkcolorbutton.c             |   2 +-
 gtk/gtkcoloreditor.c             |   6 +--
 gtk/gtkdnd.c                     |  10 ++--
 gtk/gtkdragdest.c                |  11 ++--
 gtk/gtklabel.c                   |  29 +++++------
 gtk/gtkmain.c                    |  31 +++++-------
 gtk/gtkpopup.c                   |   3 +-
 gtk/gtkwidget.c                  | 105 ++++++++++++++++++++-------------------
 gtk/gtkwindow.c                  |   2 +-
 12 files changed, 108 insertions(+), 114 deletions(-)
---
diff --git a/gtk/a11y/gtkmenuitemaccessible.c b/gtk/a11y/gtkmenuitemaccessible.c
index 41cf7417b5..01b13aeed4 100644
--- a/gtk/a11y/gtkmenuitemaccessible.c
+++ b/gtk/a11y/gtkmenuitemaccessible.c
@@ -534,12 +534,11 @@ gtk_menu_item_accessible_get_keybinding (AtkAction *action,
 
       if (GTK_IS_MENU_BAR (parent))
         {
-          GtkWidget *toplevel;
+          GtkRoot *root;
 
-          toplevel = gtk_widget_get_toplevel (parent);
-          if (toplevel && GTK_IS_WINDOW (toplevel))
-            mnemonic_modifier =
-              gtk_window_get_mnemonic_modifier (GTK_WINDOW (toplevel));
+          root = gtk_widget_get_root (parent);
+          if (root && GTK_IS_WINDOW (root))
+            mnemonic_modifier = gtk_window_get_mnemonic_modifier (GTK_WINDOW (root));
         }
 
       child = find_item_label (temp_item);
diff --git a/gtk/gtkappchooserbutton.c b/gtk/gtkappchooserbutton.c
index f8721a0720..a222f17f77 100644
--- a/gtk/gtkappchooserbutton.c
+++ b/gtk/gtkappchooserbutton.c
@@ -259,16 +259,14 @@ other_application_item_activated_cb (GtkAppChooserButton *self)
 {
   GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
   GtkWidget *dialog, *widget;
-  GtkWindow *toplevel;
+  GtkRoot *root;
 
-  toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
-  dialog = gtk_app_chooser_dialog_new_for_content_type (toplevel,
+  root = gtk_widget_get_root (GTK_WIDGET (self));
+  dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (root),
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         priv->content_type);
-
-  gtk_window_set_modal (GTK_WINDOW (dialog), gtk_window_get_modal (toplevel));
-  gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog),
-                                      priv->heading);
+  gtk_window_set_modal (GTK_WINDOW (dialog), gtk_window_get_modal (GTK_WINDOW (root)));
+  gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), priv->heading);
 
   widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
   g_object_set (widget,
diff --git a/gtk/gtkcellrendereraccel.c b/gtk/gtkcellrendereraccel.c
index 14a669b431..201656df17 100644
--- a/gtk/gtkcellrendereraccel.c
+++ b/gtk/gtkcellrendereraccel.c
@@ -452,7 +452,7 @@ gtk_cell_renderer_accel_start_editing (GtkCellRenderer      *cell,
   if (!is_editable)
     return NULL;
 
-  surface = gtk_widget_get_surface (gtk_widget_get_toplevel (widget));
+  surface = gtk_widget_get_surface (widget);
 
   if (event)
     seat = gdk_event_get_seat (event);
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 7e10a78abc..145d9985ba 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -524,7 +524,7 @@ ensure_dialog (GtkColorButton *button)
   priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (priv->title, NULL);
   gtk_window_set_hide_on_close (GTK_WINDOW (dialog), TRUE);
 
-  if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+  if (GTK_IS_WINDOW (parent))
   {
     if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
       gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c
index e6b4035d1e..5f341ffe58 100644
--- a/gtk/gtkcoloreditor.c
+++ b/gtk/gtkcoloreditor.c
@@ -193,7 +193,7 @@ popup_edit (GtkWidget      *widget,
             GtkColorEditor *editor)
 {
   GtkWidget *popup = NULL;
-  GtkWidget *toplevel;
+  GtkRoot *root;
   GtkWidget *focus;
   gint position;
   gint s, e;
@@ -224,8 +224,8 @@ popup_edit (GtkWidget      *widget,
   else if (popup)
     {
       dismiss_current_popup (editor);
-      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
-      g_set_object (&editor->priv->popdown_focus, gtk_root_get_focus (GTK_ROOT (toplevel)));
+      root = gtk_widget_get_root (GTK_WIDGET (editor));
+      g_set_object (&editor->priv->popdown_focus, gtk_root_get_focus (root));
       editor->priv->current_popup = popup;
       editor->priv->popup_position = position;
       gtk_widget_show (popup);
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 8c1312c383..ef7fb3be96 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -884,7 +884,7 @@ gtk_drag_begin_internal (GtkWidget          *widget,
                          int                 y)
 {
   GtkDragSourceInfo *info;
-  GtkWidget *toplevel;
+  GtkRoot *root;
   GdkDrag *drag;
   double px, py;
   int dx, dy;
@@ -893,9 +893,9 @@ gtk_drag_begin_internal (GtkWidget          *widget,
   if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
     device = gdk_device_get_associated_device (device);
 
-  toplevel = gtk_widget_get_toplevel (widget);
-  gtk_widget_translate_coordinates (widget, toplevel, x, y, &x, &y);
-  gdk_surface_get_device_position (gtk_widget_get_surface (toplevel),
+  root = gtk_widget_get_root (widget);
+  gtk_widget_translate_coordinates (widget, GTK_WIDGET (root), x, y, &x, &y);
+  gdk_surface_get_device_position (gtk_widget_get_surface (GTK_WIDGET (root)),
                                    device,
                                    &px, &py,
                                    NULL);
@@ -906,7 +906,7 @@ gtk_drag_begin_internal (GtkWidget          *widget,
   content->widget = g_object_ref (widget);
   content->formats = gdk_content_formats_ref (target_list);
 
-  drag = gdk_drag_begin (gtk_widget_get_surface (toplevel), device, GDK_CONTENT_PROVIDER (content), actions, 
dx, dy);
+  drag = gdk_drag_begin (gtk_widget_get_surface (GTK_WIDGET (root)), device, GDK_CONTENT_PROVIDER (content), 
actions, dx, dy);
   if (drag == NULL)
     {
       g_object_unref (content);
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index b2dcd78ef2..5ce9f1e441 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -34,10 +34,9 @@
 static void
 gtk_drag_dest_realized (GtkWidget *widget)
 {
-  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+  GtkRoot *root = gtk_widget_get_root (widget);
 
-  if (gtk_widget_is_toplevel (toplevel))
-    gdk_surface_register_dnd (gtk_widget_get_surface (toplevel));
+  gdk_surface_register_dnd (gtk_widget_get_surface (GTK_WIDGET (root)));
 }
 
 static void
@@ -45,10 +44,10 @@ gtk_drag_dest_hierarchy_changed (GtkWidget  *widget,
                                  GParamSpec *pspec,
                                  gpointer    data)
 {
-  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+  GtkRoot *root = gtk_widget_get_root (widget);
 
-  if (gtk_widget_is_toplevel (toplevel) && gtk_widget_get_realized (toplevel))
-    gdk_surface_register_dnd (gtk_widget_get_surface (toplevel));
+  if (root && gtk_widget_get_realized (GTK_WIDGET (root)))
+    gdk_surface_register_dnd (gtk_widget_get_surface (GTK_WIDGET (root)));
 }
 
 static void
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index d7b5fa82ee..4ad8ff1a69 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4559,28 +4559,28 @@ static void
 connect_mnemonics_visible_notify (GtkLabel *label)
 {
   GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
-  GtkWidget *toplevel;
+  GtkRoot *root;
   gboolean connected;
 
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (label));
+  root = gtk_widget_get_root (GTK_WIDGET (label));
 
-  if (!GTK_IS_WINDOW (toplevel))
+  if (!GTK_IS_WINDOW (root))
     return;
 
   /* always set up this widgets initial value */
   priv->mnemonics_visible =
-    gtk_window_get_mnemonics_visible (GTK_WINDOW (toplevel));
+    gtk_window_get_mnemonics_visible (GTK_WINDOW (root));
 
   connected =
-    GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (toplevel), quark_mnemonics_visible_connected));
+    GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (root), quark_mnemonics_visible_connected));
 
   if (!connected)
     {
-      g_signal_connect (toplevel,
+      g_signal_connect (root,
                         "notify::mnemonics-visible",
                         G_CALLBACK (label_mnemonics_visible_changed),
                         label);
-      g_object_set_qdata (G_OBJECT (toplevel),
+      g_object_set_qdata (G_OBJECT (root),
                           quark_mnemonics_visible_connected,
                           GINT_TO_POINTER (1));
     }
@@ -5871,12 +5871,10 @@ gtk_label_move_cursor (GtkLabel       *label,
                                                  count > 0 ?
                                                  GTK_DIR_RIGHT : GTK_DIR_LEFT))
                     {
-                      GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (label));
+                      GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (label));
 
-                      if (toplevel)
-                        gtk_widget_child_focus (toplevel,
-                                                count > 0 ?
-                                                GTK_DIR_RIGHT : GTK_DIR_LEFT);
+                      if (root)
+                        gtk_widget_child_focus (root, count > 0 ? GTK_DIR_RIGHT : GTK_DIR_LEFT);
                     }
                 }
               else
@@ -6158,11 +6156,14 @@ gtk_label_activate_link (GtkLabel    *label,
                          const gchar *uri)
 {
   GtkWidget *widget = GTK_WIDGET (label);
-  GtkWidget *top_level = gtk_widget_get_toplevel (widget);
+  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
   guint32 timestamp = gtk_get_current_event_time ();
   GError *error = NULL;
 
-  if (!gtk_show_uri_on_window (GTK_WINDOW (top_level), uri, timestamp, &error))
+  if (!GTK_IS_WINDOW (toplevel))
+    return;
+
+  if (!gtk_show_uri_on_window (GTK_WINDOW (toplevel), uri, timestamp, &error))
     {
       g_warning ("Unable to show '%s': %s", uri, error->message);
       g_error_free (error);
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 23721bb1b3..759526d6cd 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1660,7 +1660,6 @@ handle_pointing_event (GdkEvent *event)
 {
   GtkWidget *target = NULL, *old_target = NULL, *event_widget;
   GtkRoot *toplevel;
-  GtkWidget *toplevel_widget;
   GdkEventSequence *sequence;
   GdkDevice *device;
   gdouble x, y;
@@ -1670,11 +1669,7 @@ handle_pointing_event (GdkEvent *event)
   if (!device || !gdk_event_get_coords (event, &x, &y))
     return event_widget;
 
-  toplevel_widget = gtk_widget_get_toplevel (event_widget);
-  if (!GTK_IS_ROOT (toplevel_widget))
-    return event_widget;
-
-  toplevel = GTK_ROOT (toplevel_widget);
+  toplevel = gtk_widget_get_root (event_widget);
 
   sequence = gdk_event_get_event_sequence (event);
 
@@ -1702,10 +1697,10 @@ handle_pointing_event (GdkEvent *event)
       target = gtk_root_lookup_pointer_focus_implicit_grab (toplevel, device, sequence);
 
       if (!target)
-        target = gtk_widget_pick (toplevel_widget, x, y);
+        target = gtk_widget_pick (GTK_WIDGET (toplevel), x, y);
 
       if (!target)
-        target = toplevel_widget;
+        target = GTK_WIDGET (toplevel);
 
       old_target = update_pointer_focus_state (toplevel, event, target);
 
@@ -1911,7 +1906,7 @@ gtk_main_do_event (GdkEvent *event)
     case GDK_DELETE:
       g_object_ref (target_widget);
       if (!gtk_window_group_get_current_grab (window_group) ||
-          gtk_widget_get_toplevel (gtk_window_group_get_current_grab (window_group)) == target_widget)
+          GTK_WIDGET (gtk_widget_get_root (gtk_window_group_get_current_grab (window_group))) == 
target_widget)
         {
           if (!GTK_IS_WINDOW (target_widget) ||
               !gtk_window_emit_close_request (GTK_WINDOW (target_widget)))
@@ -1944,11 +1939,11 @@ gtk_main_do_event (GdkEvent *event)
     case GDK_KEY_RELEASE:
       /* make focus visible in a window that receives a key event */
       {
-        GtkWidget *window;
+        GtkRoot *root;
 
-        window = gtk_widget_get_toplevel (grab_widget);
-        if (GTK_IS_WINDOW (window))
-          gtk_window_set_focus_visible (GTK_WINDOW (window), TRUE);
+        root = gtk_widget_get_root (grab_widget);
+        if (GTK_IS_WINDOW (root))
+          gtk_window_set_focus_visible (GTK_WINDOW (root), TRUE);
       }
 
       /* Catch alt press to enable auto-mnemonics;
@@ -1960,17 +1955,17 @@ gtk_main_do_event (GdkEvent *event)
           !GTK_IS_MENU_SHELL (grab_widget))
         {
           gboolean mnemonics_visible;
-          GtkWidget *window;
+          GtkRoot *root;
 
           mnemonics_visible = (event->any.type == GDK_KEY_PRESS);
 
-          window = gtk_widget_get_toplevel (grab_widget);
-          if (GTK_IS_WINDOW (window))
+          root = gtk_widget_get_root (grab_widget);
+          if (GTK_IS_WINDOW (root))
             {
               if (mnemonics_visible)
-                _gtk_window_schedule_mnemonics_visible (GTK_WINDOW (window));
+                _gtk_window_schedule_mnemonics_visible (GTK_WINDOW (root));
               else
-                gtk_window_set_mnemonics_visible (GTK_WINDOW (window), FALSE);
+                gtk_window_set_mnemonics_visible (GTK_WINDOW (root), FALSE);
             }
         }
       /* else fall through */
diff --git a/gtk/gtkpopup.c b/gtk/gtkpopup.c
index 9d8abe2b7e..1910cb124f 100644
--- a/gtk/gtkpopup.c
+++ b/gtk/gtkpopup.c
@@ -113,7 +113,8 @@ gtk_popup_move_resize (GtkPopup *popup)
   rect.y = 0;
   rect.width = gtk_widget_get_width (priv->relative_to);
   rect.height = gtk_widget_get_height (priv->relative_to);
-  gtk_widget_translate_coordinates (priv->relative_to, gtk_widget_get_toplevel (priv->relative_to),
+  gtk_widget_translate_coordinates (priv->relative_to,
+                                    GTK_WIDGET (gtk_widget_get_root (priv->relative_to)),
                                     rect.x, rect.y, &rect.x, &rect.y);
 #if 0
   gdk_surface_move_to_rect (priv->surface,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index ab8d0e7c88..b3ef189a18 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2536,7 +2536,7 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
 
   gdk_event_get_coords (event, &x, &y);
   if (!gtk_widget_compute_point (event_widget,
-                                 gtk_widget_get_toplevel (event_widget),
+                                 GTK_WIDGET (gtk_widget_get_root (event_widget)),
                                  &GRAPHENE_POINT_INIT (x, y),
                                  &p))
       return;
@@ -2998,7 +2998,7 @@ gtk_widget_unparent (GtkWidget *widget)
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
   GtkWidget *old_parent;
   GtkWidget *old_prev_sibling;
-  GtkWidget *toplevel;
+  GtkRoot *root;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
@@ -3011,9 +3011,9 @@ gtk_widget_unparent (GtkWidget *widget)
 
   g_object_freeze_notify (G_OBJECT (widget));
 
-  toplevel = _gtk_widget_get_toplevel (widget);
-  if (_gtk_widget_is_toplevel (toplevel))
-    _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
+  root = _gtk_widget_get_root (widget);
+  if (GTK_IS_WINDOW (root))
+    _gtk_window_unset_focus_and_default (GTK_WINDOW (root), widget);
 
   if (gtk_widget_get_focus_child (priv->parent) == widget)
     gtk_widget_set_focus_child (priv->parent, NULL);
@@ -3036,7 +3036,7 @@ gtk_widget_unparent (GtkWidget *widget)
   if (priv->root)
     gtk_widget_unroot (widget);
 
-  toplevel = NULL;
+  root = NULL;
 
   /* Removing a widget from a container restores the child visible
    * flag to the default state, so it doesn't affect the child
@@ -3260,14 +3260,15 @@ gtk_widget_hide (GtkWidget *widget)
 
   if (_gtk_widget_get_visible (widget))
     {
-      GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
       GtkWidget *parent;
+      GtkRoot *root;
 
       g_object_ref (widget);
       gtk_widget_push_verify_invariants (widget);
 
-      if (toplevel != widget && _gtk_widget_is_toplevel (toplevel))
-        _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
+      root = _gtk_widget_get_root (widget);
+      if (GTK_WIDGET (root) != widget && GTK_IS_WINDOW (root))
+        _gtk_window_unset_focus_and_default (GTK_WINDOW (root), widget);
 
       /* a parent may now be expand=FALSE since we're hidden. */
       if (priv->need_compute_expand ||
@@ -3310,11 +3311,11 @@ gtk_widget_real_hide (GtkWidget *widget)
 static void
 update_cursor_on_state_change (GtkWidget *widget)
 {
-  GtkWidget *toplevel;
+  GtkRoot *root;
 
-  toplevel = gtk_widget_get_toplevel (widget);
-  if (GTK_IS_ROOT (toplevel))
-    gtk_root_update_pointer_focus_on_state_change (GTK_ROOT (toplevel), widget);
+  root = _gtk_widget_get_root (widget);
+  if (root)
+    gtk_root_update_pointer_focus_on_state_change (root, widget);
 }
 
 /**
@@ -3977,14 +3978,14 @@ gtk_widget_get_frame_clock (GtkWidget *widget)
 
   if (priv->realized)
     {
-      /* We use gtk_widget_get_toplevel() here to make it explicit that
+      /* We use gtk_widget_get_root() here to make it explicit that
        * the frame clock is a property of the toplevel that a widget
        * is anchored to; gdk_surface_get_toplevel() will go up the
        * hierarchy anyways, but should squash any funny business with
        * reparenting windows and widgets.
        */
-      GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
-      GdkSurface *surface = _gtk_widget_get_surface (toplevel);
+      GtkRoot *root = _gtk_widget_get_root (widget);
+      GdkSurface *surface = _gtk_widget_get_surface (GTK_WIDGET (root));
       g_assert (surface != NULL);
 
       return gdk_surface_get_frame_clock (surface);
@@ -4430,7 +4431,7 @@ gtk_widget_translate_coordinates (GtkWidget  *src_widget,
  *
  * Translates the given @point in @widget's coordinates to coordinates
  * relative to @target’s coodinate system. In order to perform this
- * operation, both widgets must share a common ancestor.
+ * operation, both widgets must share a common root.
  *
  * Returns: %TRUE if the point could be determined, %FALSE on failure.
  *   In this case, 0 is stored in @out_point.
@@ -5384,10 +5385,11 @@ static void
 gtk_widget_real_move_focus (GtkWidget         *widget,
                             GtkDirectionType   direction)
 {
-  GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
+  GtkRoot *root;
 
-  if (widget != toplevel && GTK_IS_WINDOW (toplevel))
-    g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0, direction);
+  root = _gtk_widget_get_root (widget);
+  if (widget != GTK_WIDGET (root))
+    g_signal_emit (root, widget_signals[MOVE_FOCUS], 0, direction);
 }
 
 static gboolean
@@ -5510,12 +5512,10 @@ gtk_widget_has_visible_focus (GtkWidget *widget)
 
   if (priv->has_focus)
     {
-      GtkWidget *toplevel;
+      GtkRoot *root = _gtk_widget_get_root (widget);
 
-      toplevel = _gtk_widget_get_toplevel (widget);
-
-      if (GTK_IS_WINDOW (toplevel))
-        draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
+      if (GTK_IS_WINDOW (root))
+        draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (root));
       else
         draw_focus = TRUE;
     }
@@ -5803,7 +5803,8 @@ gtk_widget_device_is_shadowed (GtkWidget *widget,
                                GdkDevice *device)
 {
   GtkWindowGroup *group;
-  GtkWidget *grab_widget, *toplevel;
+  GtkWidget *grab_widget;
+  GtkRoot *root;
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
@@ -5811,10 +5812,10 @@ gtk_widget_device_is_shadowed (GtkWidget *widget,
   if (!_gtk_widget_get_realized (widget))
     return TRUE;
 
-  toplevel = _gtk_widget_get_toplevel (widget);
+  root = _gtk_widget_get_root (widget);
 
-  if (GTK_IS_WINDOW (toplevel))
-    group = gtk_window_get_group (GTK_WINDOW (toplevel));
+  if (GTK_IS_WINDOW (root))
+    group = gtk_window_get_group (GTK_WINDOW (root));
   else
     group = gtk_window_get_group (NULL);
 
@@ -6178,9 +6179,11 @@ gtk_widget_get_has_surface (GtkWidget *widget)
 gboolean
 gtk_widget_is_toplevel (GtkWidget *widget)
 {
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
 
-  return GTK_IS_ROOT (widget);
+  return priv->parent == NULL && GTK_IS_ROOT (widget);
 }
 
 /**
@@ -6353,12 +6356,6 @@ gtk_widget_reposition_after (GtkWidget *widget,
       return;
     }
 
-  if (_gtk_widget_is_toplevel (widget))
-    {
-      g_warning ("Can't set a parent on a toplevel widget");
-      return;
-    }
-
   data.old_scale_factor = gtk_widget_get_scale_factor (widget);
 
   /* keep this function in sync with gtk_menu_attach_to_widget()
@@ -7247,13 +7244,13 @@ gtk_widget_set_child_visible (GtkWidget *widget,
     priv->child_visible = TRUE;
   else
     {
-      GtkWidget *toplevel;
+      GtkRoot *root;
 
       priv->child_visible = FALSE;
 
-      toplevel = _gtk_widget_get_toplevel (widget);
-      if (toplevel != widget && _gtk_widget_is_toplevel (toplevel))
-       _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
+      root = _gtk_widget_get_root (widget);
+      if (GTK_WIDGET (root) != widget && GTK_IS_WINDOW (root))
+       _gtk_window_unset_focus_and_default (GTK_WINDOW (root), widget);
     }
 
   if (priv->parent && _gtk_widget_get_realized (priv->parent))
@@ -7325,7 +7322,7 @@ _gtk_widget_scale_changed (GtkWidget *widget)
 gint
 gtk_widget_get_scale_factor (GtkWidget *widget)
 {
-  GtkWidget *toplevel;
+  GtkRoot *root;
   GdkDisplay *display;
   GdkMonitor *monitor;
 
@@ -7334,9 +7331,9 @@ gtk_widget_get_scale_factor (GtkWidget *widget)
   if (_gtk_widget_get_realized (widget))
     return gdk_surface_get_scale_factor (_gtk_widget_get_surface (widget));
 
-  toplevel = _gtk_widget_get_toplevel (widget);
-  if (toplevel && toplevel != widget)
-    return gtk_widget_get_scale_factor (toplevel);
+  root = _gtk_widget_get_root (widget);
+  if (root && GTK_WIDGET (root) != widget)
+    return gtk_widget_get_scale_factor (GTK_WIDGET (root));
 
   /* else fall back to something that is more likely to be right than
    * just returning 1:
@@ -10161,7 +10158,8 @@ _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
   if (g_slist_length (accel_groups) == 0)
     {
       accel_group = gtk_accel_group_new ();
-      gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
+      if (GTK_IS_WINDOW (toplevel))
+        gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
     }
   else
     {
@@ -10257,14 +10255,14 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
   if (strcmp (tagname, "accelerator") == 0)
     {
       AccelGroupParserData *accel_data;
-      GtkWidget *toplevel;
+      GtkRoot *root;
 
       accel_data = (AccelGroupParserData*)user_data;
       g_assert (accel_data->object);
 
-      toplevel = _gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
+      root = _gtk_widget_get_root (GTK_WIDGET (accel_data->object));
 
-      _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
+      _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), GTK_WIDGET (root), user_data);
     }
   else if (strcmp (tagname, "accessibility") == 0)
     {
@@ -11142,6 +11140,9 @@ gtk_widget_compute_transform (GtkWidget         *widget,
   g_return_val_if_fail (GTK_IS_WIDGET (target), FALSE);
   g_return_val_if_fail (out_transform != NULL, FALSE);
 
+  if (widget->priv->root != target->priv->root)
+    return FALSE;
+
   /* optimization for common case: parent wants coordinates of a direct child */
   if (target == widget->priv->parent)
     {
@@ -13388,7 +13389,7 @@ gtk_widget_set_cursor (GtkWidget *widget,
                        GdkCursor *cursor)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-  GtkWidget *toplevel;
+  GtkRoot *root;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (cursor == NULL || GDK_IS_CURSOR (cursor));
@@ -13396,9 +13397,9 @@ gtk_widget_set_cursor (GtkWidget *widget,
   if (!g_set_object (&priv->cursor, cursor))
     return;
 
-  toplevel = gtk_widget_get_toplevel (widget);
-  if (GTK_IS_WINDOW (toplevel))
-    gtk_window_maybe_update_cursor (GTK_WINDOW (toplevel), widget, NULL);
+  root = _gtk_widget_get_root (widget);
+  if (root)
+    gtk_root_maybe_update_cursor (root, widget, NULL);
 
   g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CURSOR]);
 }
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index f08c29420c..872d9c9c86 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6482,7 +6482,7 @@ gtk_window_propagate_key_event (GtkWindow        *window,
   
   while (!handled &&
          focus && focus != widget &&
-         gtk_widget_get_toplevel (focus) == widget)
+         gtk_widget_get_root (focus) == GTK_ROOT (widget))
     {
       GtkWidget *parent;
       


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]