tests/test-shell: Emulate overview grabs

This mimics what gnome-shell does when the overview is shown. This means
having a grab active, and setting the keyboard focus to the stage
itself.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3185>
This commit is contained in:
Jonas Ådahl 2023-08-15 22:08:11 +02:00 committed by Marge Bot
parent 524c9aa458
commit 8268ec2ee8

View File

@ -63,6 +63,11 @@ struct _MetaTestShell
ClutterActor *background_group; ClutterActor *background_group;
MetaPluginInfo info; MetaPluginInfo info;
struct {
ClutterGrab *grab;
ClutterActor *prev_focus;
} overview;
}; };
typedef struct _ActorPrivate typedef struct _ActorPrivate
@ -287,6 +292,28 @@ on_monitors_changed (MetaMonitorManager *monitor_manager,
g_rand_free (rand); g_rand_free (rand);
} }
static void
on_overlay_key (MetaDisplay *display,
MetaTestShell *test_shell)
{
MetaContext *context = meta_display_get_context (display);
MetaBackend *backend = meta_context_get_backend (context);
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
if (!test_shell->overview.grab)
{
test_shell->overview.grab = clutter_stage_grab (stage, CLUTTER_ACTOR (stage));
test_shell->overview.prev_focus = clutter_stage_get_key_focus (stage);
clutter_stage_set_key_focus (stage, CLUTTER_ACTOR (stage));
}
else
{
g_clear_pointer (&test_shell->overview.grab, clutter_grab_dismiss);
clutter_stage_set_key_focus (stage,
g_steal_pointer (&test_shell->overview.prev_focus));
}
}
static void static void
prepare_shutdown (MetaBackend *backend, prepare_shutdown (MetaBackend *backend,
MetaTestShell *test_shell) MetaTestShell *test_shell)
@ -312,6 +339,9 @@ meta_test_shell_start (MetaPlugin *plugin)
G_CALLBACK (on_monitors_changed), plugin); G_CALLBACK (on_monitors_changed), plugin);
on_monitors_changed (monitor_manager, plugin); on_monitors_changed (monitor_manager, plugin);
g_signal_connect (display, "overlay-key",
G_CALLBACK (on_overlay_key), plugin);
g_signal_connect (backend, "prepare-shutdown", g_signal_connect (backend, "prepare-shutdown",
G_CALLBACK (prepare_shutdown), G_CALLBACK (prepare_shutdown),
test_shell); test_shell);