This function returns the topmost widget in the container hierarchy
widget is a part of. If widget has no parent widgets, it will be
returned as the topmost widget. No reference will be added to the
returned widget; it should not be unreferenced.
Note the difference in behavior vs. Widget.getAncestor;
gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)
would return
NULL if widget wasn’t inside a toplevel window, and if the
window was inside a [GtkWindow-derived|GtkWindow-derived] widget which was in turn
inside the toplevel gtk.Window While the second case may
seem unlikely, it actually happens when a gtk.Plug is embedded
inside a gtk.Socket within the same application.
To reliably find the toplevel gtk.Window, use
Widget.getToplevel and call GTK_IS_WINDOW()
on the result. For instance, to get the title of a widget's toplevel
window, one might use:
This function returns the topmost widget in the container hierarchy widget is a part of. If widget has no parent widgets, it will be returned as the topmost widget. No reference will be added to the returned widget; it should not be unreferenced.
Note the difference in behavior vs. Widget.getAncestor; gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW) would return NULL if widget wasn’t inside a toplevel window, and if the window was inside a [GtkWindow-derived|GtkWindow-derived] widget which was in turn inside the toplevel gtk.Window While the second case may seem unlikely, it actually happens when a gtk.Plug is embedded inside a gtk.Socket within the same application.
To reliably find the toplevel gtk.Window, use Widget.getToplevel and call GTK_IS_WINDOW() on the result. For instance, to get the title of a widget's toplevel window, one might use: