a11y: Redo child-added/-removed for toplevels

Instead of monitoring the list of toplevels, rely
on GtkWindow updating the HIDDEN state before windows
get removed. This is better, since we still have the
object available when it happens, so we can pass it
to the ATs.
This commit is contained in:
Matthias Clasen 2020-10-24 15:26:12 -04:00
parent bba6d604f0
commit 2546b88661
3 changed files with 4 additions and 39 deletions

View File

@ -871,7 +871,6 @@ gtk_at_spi_context_state_change (GtkATContext *ctx,
gtk_at_spi_root_child_changed (self->root,
hidden ? GTK_ACCESSIBLE_CHILD_STATE_REMOVED
: GTK_ACCESSIBLE_CHILD_STATE_ADDED,
G_MAXUINT,
widget);
}
}

View File

@ -405,47 +405,18 @@ static const GDBusInterfaceVTable root_accessible_vtable = {
NULL,
};
static void
root_toplevels__items_changed (GtkAtSpiRoot *self,
guint position,
guint removed,
guint added,
GListModel *toplevels)
{
if (added == 1 && removed == 0)
{
GtkWidget *window;
window = GTK_WIDGET (g_list_model_get_item (self->toplevels, position));
gtk_at_spi_root_child_changed (self,
GTK_ACCESSIBLE_CHILD_STATE_ADDED,
G_MAXUINT,
window);
g_object_unref (window);
}
else if (added == 0 && removed == 1)
{
gtk_at_spi_root_child_changed (self,
GTK_ACCESSIBLE_CHILD_STATE_REMOVED,
position,
NULL);
}
else
{
g_assert_not_reached ();
}
}
void
gtk_at_spi_root_child_changed (GtkAtSpiRoot *self,
GtkAccessibleChildState state,
guint position,
GtkWidget *window)
{
guint n, i;
int idx = 0;
GVariant *window_ref;
if (!self->toplevels)
return;
/* We can be called either with a valid position and window == NULL
* or with position == G_MAXUINT and a valid window. In both cases,
* we need to determine the index of where the removed object would
@ -457,7 +428,7 @@ gtk_at_spi_root_child_changed (GtkAtSpiRoot *self,
g_object_unref (item);
if (i == position || item == GTK_ACCESSIBLE (window))
if (item == GTK_ACCESSIBLE (window))
break;
if (!gtk_accessible_should_present (item))
@ -517,11 +488,7 @@ on_registration_reply (GObject *gobject,
/* Register the cache object */
self->cache = gtk_at_spi_cache_new (self->connection, ATSPI_CACHE_PATH);
/* Monitor the top levels */
self->toplevels = gtk_window_get_toplevels ();
g_signal_connect_swapped (self->toplevels, "items-changed",
G_CALLBACK (root_toplevels__items_changed),
self);
}
static void

View File

@ -45,7 +45,6 @@ gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
void
gtk_at_spi_root_child_changed (GtkAtSpiRoot *self,
GtkAccessibleChildState state,
guint position,
GtkWidget *window);
G_END_DECLS