4 get_name (gpointer obj)
9 else if (GTK_IS_WIDGET (obj))
10 widget = GTK_WIDGET (obj);
11 else if (GTK_IS_ACCESSIBLE (obj))
12 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
15 if (GTK_IS_BUILDABLE (widget))
16 return gtk_buildable_get_name (GTK_BUILDABLE (widget));
18 return G_OBJECT_TYPE_NAME (widget);
22 compare_focus (gpointer data)
26 GtkWidget *focus_widget;
29 atk_focus = atk_get_focus_object ();
32 list = gtk_window_list_toplevels ();
33 for (l = list; l; l = l->next)
35 GtkWindow *w = l->data;
36 if (gtk_window_is_active (w))
38 focus_widget = gtk_window_get_focus (w);
44 if (GTK_IS_WIDGET (focus_widget))
45 gtk_focus = gtk_widget_get_accessible (focus_widget);
49 if (gtk_focus != atk_focus)
50 g_print ("gtk focus: %s != atk focus: %s\n",
51 get_name (gtk_focus), get_name (atk_focus));
53 return G_SOURCE_CONTINUE;
57 notify_cb (GObject *obj, GParamSpec *pspec, gpointer data)
61 if (g_strcmp0 (pspec->name, "has-focus") != 0)
64 g_object_get (obj, "has-focus", &value, NULL);
65 g_print ("widget %s %p has-focus -> %d\n", get_name (obj), obj, value);
69 state_change_cb (AtkObject *obj, const gchar *name, gboolean state_set)
73 set = atk_object_ref_state_set (obj);
74 g_print ("accessible %s %p focused -> %d\n", get_name (obj), obj,
75 atk_state_set_contains_state (set, ATK_STATE_FOCUSED));
80 main (int argc, char *argv[])
86 AtkObject *accessible;
88 gtk_init (&argc, &argv);
90 builder = gtk_builder_new ();
91 gtk_builder_add_from_file (builder, argv[1], NULL);
93 window = (GtkWidget *)gtk_builder_get_object (builder, "window1");
95 o = gtk_builder_get_objects (builder);
96 for (l = o; l;l = l->next)
98 if (!GTK_IS_WIDGET (l->data))
102 g_signal_connect (widget, "notify::has-focus", G_CALLBACK (notify_cb), NULL);
103 accessible = gtk_widget_get_accessible (widget);
104 g_signal_connect (accessible, "state-change::focused", G_CALLBACK (state_change_cb), NULL);
109 g_timeout_add (100, compare_focus, NULL);
111 gtk_widget_show_all (window);