From c93e402a898d2e45b4b15e176d5d428a54797d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2022 01:42:14 +0200 Subject: [PATCH] monitor-manager: Ensure monitors settings after backend has been updated The monitors settings such as the privacy screen property is propagated to the monitors via kms updates, however during initialization and on monitors changes, we end up clearing the pending KMS updates because such settings are added to the queue before the backend has fully initialized the monitors, and this may lead to discarding all the pending updates, including the one we've just planned. To avoid this, move settings applications after we've both initialized the backend and notified it about changes. Also avoid to try set the settings during actual initialization, but delay that after post-init. Part-of: --- src/backends/meta-monitor-manager-private.h | 1 + src/backends/meta-monitor-manager.c | 37 +++++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index 12bb84038..edf7e4501 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -70,6 +70,7 @@ typedef enum _MetaLogicalMonitorLayoutMode typedef enum { META_PRIVACY_SCREEN_CHANGE_STATE_NONE, + META_PRIVACY_SCREEN_CHANGE_STATE_INIT, META_PRIVACY_SCREEN_CHANGE_STATE_PENDING_HOTKEY, META_PRIVACY_SCREEN_CHANGE_STATE_PENDING_SETTING, } MetaPrivacyScreenChangeState; diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 83fe10780..be99b4664 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -1080,21 +1080,25 @@ get_global_privacy_screen_state (MetaMonitorManager *manager) return global_state; } -static void -apply_privacy_screen_settings (MetaMonitorManager *manager) +static gboolean +privacy_screen_needs_update (MetaMonitorManager *manager) { MetaSettings *settings = meta_backend_get_settings (manager->backend); MetaPrivacyScreenState privacy_screen_state = get_global_privacy_screen_state (manager); if (privacy_screen_state == META_PRIVACY_SCREEN_UNAVAILABLE) - return; + return FALSE; - if (!!(privacy_screen_state & META_PRIVACY_SCREEN_ENABLED) == - meta_settings_is_privacy_screen_enabled (settings)) - return; + return (!!(privacy_screen_state & META_PRIVACY_SCREEN_ENABLED) != + meta_settings_is_privacy_screen_enabled (settings)); +} - if (ensure_monitors_settings (manager)) +static void +apply_privacy_screen_settings (MetaMonitorManager *manager) +{ + if (privacy_screen_needs_update (manager) && + ensure_monitors_settings (manager)) { manager->privacy_screen_change_state = META_PRIVACY_SCREEN_CHANGE_STATE_PENDING_SETTING; @@ -1181,7 +1185,8 @@ meta_monitor_manager_setup (MetaMonitorManager *manager) meta_monitor_manager_ensure_initial_config (manager); - apply_privacy_screen_settings (manager); + if (privacy_screen_needs_update (manager)) + manager->privacy_screen_change_state = META_PRIVACY_SCREEN_CHANGE_STATE_INIT; manager->in_init = FALSE; } @@ -1506,7 +1511,8 @@ meta_monitor_manager_maybe_emit_privacy_screen_change (MetaMonitorManager *manag { MetaPrivacyScreenChangeState reason = manager->privacy_screen_change_state; - if (reason == META_PRIVACY_SCREEN_CHANGE_STATE_NONE) + if (reason == META_PRIVACY_SCREEN_CHANGE_STATE_NONE || + reason == META_PRIVACY_SCREEN_CHANGE_STATE_INIT) return; if (reason == META_PRIVACY_SCREEN_CHANGE_STATE_PENDING_HOTKEY) @@ -3561,10 +3567,10 @@ meta_monitor_manager_rebuild (MetaMonitorManager *manager, meta_monitor_manager_update_logical_state (manager, config); - ensure_monitors_settings (manager); - meta_monitor_manager_notify_monitors_changed (manager); + ensure_monitors_settings (manager); + g_list_free_full (old_logical_monitors, g_object_unref); } @@ -3840,6 +3846,15 @@ meta_monitor_manager_post_init (MetaMonitorManager *manager) ClutterBackend *clutter_backend; ClutterSeat *seat; + if (manager->privacy_screen_change_state == + META_PRIVACY_SCREEN_CHANGE_STATE_INIT) + { + manager->privacy_screen_change_state = + META_PRIVACY_SCREEN_CHANGE_STATE_NONE; + } + + apply_privacy_screen_settings (manager); + clutter_backend = meta_backend_get_clutter_backend (manager->backend); seat = clutter_backend_get_default_seat (clutter_backend);