Hi all,
How can we get information (type, status and label) about a focused widget in another GTK application? (The “gtk_window_get_focus” and “GTK_WIDGET_TYPE” would be usefull only if we could get a pointer to this “another” GtkWindow, but I think it's not possible).
Obviously, the another GTK application must be the top level of the current screen, and I think that, to work (and interact) with another top level application, is possible only using GDK (or Xlib) resources. Then I wrote the following code (see below), but (for the time being) it gives us only the name of the top level (focused) application, and I would like to reach the focused widget information too.
The reason: I'd like to reach those informations to drive (help by audio returns) the user actions in this another application, cause I'll start (or at least I'll try a lot) to work on a Screen Reader project.
Thanks very much, Samer Eberlin.
/* = = = = = = = = = = = = Start Code = = = = = = = = = = = = = = = = */
#include <gtk/gtk.h> #include <gdk/gdkx.h>
/**********************************************************************/ /* Main function: *****************************************************/ /**********************************************************************/ int main (int argc, char *argv[]) { /* Function prototypes */ void GetWin (Window*);
/* Variables */ Window toplevel; XEvent ev;
/* GDK init */ gtk_init (&argc, &argv);
/* GetWin function */ GetWin (&toplevel);
/* Main Loop */ while (1) { XNextEvent (GDK_DISPLAY(), &ev); switch (ev.type) { case FocusOut: GetWin (&toplevel); break; default: break; } } return 0; }
/**********************************************************************/ /* GetWin: gets the focused window: ***********************************/ /**********************************************************************/ void GetWin (Window *toplevel) { /* Variables */ Window win, focwin, root, parent, *children; int focus; unsigned int nchildren; GtkWidget *dialog; XClassHint ch; ch.res_name = NULL; ch.res_class = NULL;
/* XGet functions */ XGetInputFocus (GDK_DISPLAY(), &focwin, &focus); XGetClassHint (GDK_DISPLAY(), focwin, &ch); if (ch.res_class != NULL) win = focwin; else { XQueryTree (GDK_DISPLAY(), focwin, &root, &parent, &children, &nchildren); XFree (children); XGetClassHint (GDK_DISPLAY(), parent, &ch); win = parent; }
/* Focus change */ if (win != *toplevel) { printf ("The focused window's name is: \"%s\"\n", ch.res_class); dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, ch.res_class); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); XSelectInput (GDK_DISPLAY(), win, FocusChangeMask); *toplevel = win; } }
/* = = = = = = = = = = = = End Code = = = = = = = = = = = = = = = = = */
_______________________________________________ gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list