The answer is actually OS independent - you can do it in GTK. You can get a list of all the top-level windows from the application using gtk.window_list_toplevels(), and then iterate over it until you find the one where it window.is_active()returns True.
If you want to view other windows than those from your application, then you can try gtk.gdk.screen_get_default().get_toplevel_windows(), but this will only result in GDK windows, not GTK windows, because you have no way of knowing if these GDK windows are really associated with GTK windows.
source
share