I want to get gdkwindow, I know there are method listing all gdk window opened in the desktop, But how to Get a GtkWindow? I know GtkWindow has a property gdkwindow, but How to Get GtkWindow by GdkWindow?
Asked
Active
Viewed 1,085 times
1
-
1Can you explain what you're trying to accomplish and what if any additional data/widgets are available to you? – Uyghur Lives Matter Mar 08 '14 at 15:49
-
1@cpburnz how to get gtkwindow instance by a gdkwindow xid? – user3085513 Mar 08 '14 at 16:01
1 Answers
2
Without more context I can't really answer your question any better, but try using gtk.window_list_toplevels()
. It will return the list of all top-level GTK windows for the current process.
Here's how you would devise a method to return the corresponding top-level GTK window from a GDK window XID.
def find_gtk_window(xid):
for gtk_window in gtk.window_list_toplevels():
if gtk_window.window.xid == xid:
return gtk_window
But, if you want to list all GTK windows of other processes, then that's not (easily) possible. An answer to How do I get a list of all windows on my gnome2 desktop using pygtk? describes the situtation pretty well.

Community
- 1
- 1

Uyghur Lives Matter
- 18,820
- 42
- 108
- 144
-
I have a question. When I running a window1, then i open a filedialog. why can't I directly close window1 other than close filedialog first. but sometime in other app, the older window can be closed first. what's the reason, for example GtkFileChooserButton and GtkFileChooserDialog. – user3085513 Mar 08 '14 at 17:27
-
GtkFileChooserButton(can close old window first) and GtkFileChooserDialog(cannot and should close dialog first). code there [https://github.com/majorsilence/pygtknotebook/tree/master/examples/more-pygtk](https://github.com/majorsilence/pygtknotebook/tree/master/examples/more-pygtk) – user3085513 Mar 08 '14 at 17:33
-
@user3085513 That should really be posted as a separate question, but that has to due with [`GTK_DIALOG_MODAL`](https://developer.gnome.org/gtk2/stable/GtkDialog.html#GtkDialogFlags). If you want to be able to go back to the parent window without closing the dialog, make sure to unset the `GTK_DIALOG_MODAL` flag which can be done with [`gtk_window_set_model()`](https://developer.gnome.org/gtk2/stable/GtkWindow.html#gtk-window-set-modal). – Uyghur Lives Matter Mar 08 '14 at 17:39
-
-
I Know we can get gdkwindow from GtkWindow using gtk.Window.get_window(), Is It possible to Get GtkWindow by a Gdkwindow I already have? Do you know GtkParasite , a tool inspecting gtkwigdets, – user3085513 Mar 09 '14 at 05:51
-
1As the answer says, you can't get GtkWindows from other processes. GtkParasite works because it is a module that is dynamically loaded into the process that you are inspecting, so it uses `gtk_window_list_toplevels()` to get the current process's windows. – ptomato Mar 09 '14 at 19:58