plugin-manager: Don't try to starte effect when shutting down

Add internal state (starting, running, stopping), and use this instead
of MetaDisplay struct fields to determine whether to start animations.

This fixes issues when we try to animate things when shutting down.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2716>
This commit is contained in:
Jonas Ådahl 2022-11-24 16:21:50 +01:00 committed by Marge Bot
parent c1982218e1
commit db1000e264

View File

@ -37,10 +37,18 @@
static GType plugin_type = G_TYPE_NONE; static GType plugin_type = G_TYPE_NONE;
typedef enum _PluginManagerState
{
PLUGIN_MANAGER_STATE_STARTING,
PLUGIN_MANAGER_STATE_RUNNING,
PLUGIN_MANAGER_STATE_STOPPING,
} PluginManagerState;
struct MetaPluginManager struct MetaPluginManager
{ {
MetaCompositor *compositor; MetaCompositor *compositor;
MetaPlugin *plugin; MetaPlugin *plugin;
PluginManagerState state;
}; };
void void
@ -92,14 +100,31 @@ on_confirm_display_change (MetaMonitorManager *monitors,
meta_plugin_manager_confirm_display_change (plugin_mgr); meta_plugin_manager_confirm_display_change (plugin_mgr);
} }
static void
on_started (MetaContext *context,
MetaPluginManager *plugin_mgr)
{
plugin_mgr->state = PLUGIN_MANAGER_STATE_RUNNING;
}
static void
on_prepare_shutdown (MetaContext *context,
MetaPluginManager *plugin_mgr)
{
plugin_mgr->state = PLUGIN_MANAGER_STATE_STOPPING;
}
MetaPluginManager * MetaPluginManager *
meta_plugin_manager_new (MetaCompositor *compositor) meta_plugin_manager_new (MetaCompositor *compositor)
{ {
MetaPluginManager *plugin_mgr; MetaPluginManager *plugin_mgr;
MetaPlugin *plugin; MetaPlugin *plugin;
MetaMonitorManager *monitors; MetaMonitorManager *monitors;
MetaDisplay *display;
MetaContext *context;
plugin_mgr = g_new0 (MetaPluginManager, 1); plugin_mgr = g_new0 (MetaPluginManager, 1);
plugin_mgr->state = PLUGIN_MANAGER_STATE_STARTING;
plugin_mgr->compositor = compositor; plugin_mgr->compositor = compositor;
plugin_mgr->plugin = plugin = g_object_new (plugin_type, NULL); plugin_mgr->plugin = plugin = g_object_new (plugin_type, NULL);
@ -109,6 +134,13 @@ meta_plugin_manager_new (MetaCompositor *compositor)
g_signal_connect (monitors, "confirm-display-change", g_signal_connect (monitors, "confirm-display-change",
G_CALLBACK (on_confirm_display_change), plugin_mgr); G_CALLBACK (on_confirm_display_change), plugin_mgr);
display = meta_compositor_get_display (compositor);
context = meta_display_get_context (display);
g_signal_connect (context, "started",
G_CALLBACK (on_started), plugin_mgr);
g_signal_connect (context, "prepare-shutdown",
G_CALLBACK (on_prepare_shutdown), plugin_mgr);
return plugin_mgr; return plugin_mgr;
} }
@ -143,6 +175,21 @@ meta_plugin_manager_kill_switch_workspace (MetaPluginManager *plugin_mgr)
klass->kill_switch_workspace (plugin); klass->kill_switch_workspace (plugin);
} }
static gboolean
should_start_effect (MetaPluginManager *plugin_mgr)
{
switch (plugin_mgr->state)
{
case PLUGIN_MANAGER_STATE_STARTING:
case PLUGIN_MANAGER_STATE_STOPPING:
return FALSE;
case PLUGIN_MANAGER_STATE_RUNNING:
return TRUE;
}
g_assert_not_reached ();
}
/* /*
* Public method that the compositor hooks into for events that require * Public method that the compositor hooks into for events that require
* no additional parameters. * no additional parameters.
@ -159,10 +206,9 @@ meta_plugin_manager_event_simple (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
gboolean retval = FALSE; gboolean retval = FALSE;
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return FALSE; return FALSE;
switch (event) switch (event)
@ -230,9 +276,8 @@ meta_plugin_manager_event_size_change (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return FALSE; return FALSE;
if (!klass->size_change) if (!klass->size_change)
@ -259,10 +304,9 @@ meta_plugin_manager_switch_workspace (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
gboolean retval = FALSE; gboolean retval = FALSE;
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return FALSE; return FALSE;
if (klass->switch_workspace) if (klass->switch_workspace)
@ -317,9 +361,8 @@ meta_plugin_manager_show_tile_preview (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return FALSE; return FALSE;
if (klass->show_tile_preview) if (klass->show_tile_preview)
@ -336,9 +379,8 @@ meta_plugin_manager_hide_tile_preview (MetaPluginManager *plugin_mgr)
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return FALSE; return FALSE;
if (klass->hide_tile_preview) if (klass->hide_tile_preview)
@ -359,9 +401,8 @@ meta_plugin_manager_show_window_menu (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return; return;
if (klass->show_window_menu) if (klass->show_window_menu)
@ -376,9 +417,8 @@ meta_plugin_manager_show_window_menu_for_rect (MetaPluginManager *plugin_mgr,
{ {
MetaPlugin *plugin = plugin_mgr->plugin; MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = meta_compositor_get_display (plugin_mgr->compositor);
if (display->display_opening) if (!should_start_effect (plugin_mgr))
return; return;
if (klass->show_window_menu_for_rect) if (klass->show_window_menu_for_rect)