From ae2751a68b20ab281ca74affd61562fb8869b639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 5 Jun 2014 18:09:47 +0200 Subject: [PATCH] main: Move pref overrides back into C Commit 6c2f3d1d178a65d moved pref overrides into JS to implement session mode specific overrides in a clean and generic way. However that approach comes with a cost - doing the overrides only after having handled over control to JS means that the core will be initialized with the non-overridden settings before changing to the correct values. In the best case this is unnecessary work, but it can in fact have a worse effect: when initializing workspaces, we will restore the previous number of workspaces when using dynamic-workspaces and reset to the configured number otherwise. As the non-overridden default for dynamic-workspaces is FALSE, we can easily end up moving the user's windows to the "wrong" workspace. Now GSettings is expected to grow support for session specific defaults, which will render our entire override system obsolete (yay!). Given that, it seems acceptable to use a less generic (and uglier) approach in the meanwhile, in order to fix aforementioned problems. So move overrides back before core initialization and just hardcode the session-mode => override-schema relation. https://bugzilla.gnome.org/show_bug.cgi?id=695487 --- js/ui/main.js | 13 ------------- js/ui/windowManager.js | 9 ++++++++- src/main.c | 21 +++++++++++++++++++++ src/shell-global.c | 31 +++++++++++++++++++++++++++++++ src/shell-global.h | 1 + 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/js/ui/main.js b/js/ui/main.js index a21af899f..6218f33d5 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -74,7 +74,6 @@ let _startDate; let _defaultCssStylesheet = null; let _cssStylesheet = null; let _a11ySettings = null; -let dynamicWorkspacesSchema = null; function _sessionUpdated() { _loadDefaultStylesheet(); @@ -111,7 +110,6 @@ function start() { sessionMode = new SessionMode.SessionMode(); sessionMode.connect('updated', _sessionUpdated); - _initializePrefs(); _initializeUI(); shellDBusService = new ShellDBus.GnomeShell(); @@ -120,17 +118,6 @@ function start() { _sessionUpdated(); } -function _initializePrefs() { - let keys = new Gio.Settings({ schema: sessionMode.overridesSchema }).list_keys(); - for (let i = 0; i < keys.length; i++) - Meta.prefs_override_preference_schema(keys[i], sessionMode.overridesSchema); - - if (keys.indexOf('dynamic-workspaces') > -1) - dynamicWorkspacesSchema = sessionMode.overridesSchema; - else - dynamicWorkspacesSchema = 'org.gnome.mutter'; -} - function _initializeUI() { // Ensure ShellWindowTracker and ShellAppUsage are initialized; this will // also initialize ShellAppSystem first. ShellAppSystem diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js index 0b77916b0..c2a2d133f 100644 --- a/js/ui/windowManager.js +++ b/js/ui/windowManager.js @@ -199,12 +199,19 @@ const WorkspaceTracker = new Lang.Class({ global.screen.connect('window-left-monitor', Lang.bind(this, this._windowLeftMonitor)); global.screen.connect('restacked', Lang.bind(this, this._windowsRestacked)); - this._workspaceSettings = new Gio.Settings({ schema: Main.dynamicWorkspacesSchema }); + this._workspaceSettings = this._getWorkspaceSettings(); this._workspaceSettings.connect('changed::dynamic-workspaces', Lang.bind(this, this._queueCheckWorkspaces)); this._nWorkspacesChanged(); }, + _getWorkspaceSettings: function() { + let settings = global.get_overrides_settings(); + if (settings.list_keys().indexOf('dynamic-workspaces') > -1) + return settings; + return new Gio.Settings({ schema: 'org.gnome.mutter' }); + }, + _checkWorkspaces: function() { let i; let emptyWorkspaces = []; diff --git a/src/main.c b/src/main.c index 55f668394..a2f497cf8 100644 --- a/src/main.c +++ b/src/main.c @@ -34,6 +34,8 @@ extern GType gnome_shell_plugin_get_type (void); #define SHELL_DBUS_SERVICE "org.gnome.Shell" #define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier" +#define OVERRIDES_SCHEMA "org.gnome.shell.overrides" + #define WM_NAME "GNOME Shell" #define GNOME_WM_KEYBINDINGS "Mutter,GNOME Shell" @@ -167,6 +169,23 @@ shell_dbus_init (gboolean replace) g_object_unref (session); } +static void +shell_prefs_init (void) +{ + ShellGlobal *global = shell_global_get (); + GSettings *settings = shell_global_get_overrides_settings (global); + char **keys, **k; + + if (!settings) + return; + + keys = g_settings_list_keys (settings); + for (keys = k = g_settings_list_keys (settings); *k; k++) + meta_prefs_override_preference_schema (*k, OVERRIDES_SCHEMA); + + g_strfreev (keys); +} + static void shell_introspection_init (void) { @@ -434,6 +453,8 @@ main (int argc, char **argv) _shell_global_init ("session-mode", session_mode, NULL); + shell_prefs_init (); + ecode = meta_run (); if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP")) diff --git a/src/shell-global.c b/src/shell-global.c index f945e36f4..18e3e0993 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -1355,6 +1355,37 @@ shell_global_get_settings (ShellGlobal *global) return global->settings; } +/** + * shell_global_get_overrides_settings: + * @global: A #ShellGlobal + * + * Get the session overrides GSettings instance. + * + * Return value: (transfer none): The GSettings object + */ +GSettings * +shell_global_get_overrides_settings (ShellGlobal *global) +{ + static GSettings *settings = NULL; + const char *schema; + + g_return_val_if_fail (SHELL_IS_GLOBAL (global), NULL); + + if (!settings) + { + if (strcmp (global->session_mode, "classic") == 0) + schema = "org.gnome.shell.extensions.classic-overrides"; + else if (strcmp (global->session_mode, "user") == 0) + schema = "org.gnome.shell.overrides"; + else + return NULL; + + settings = g_settings_new (schema); + } + + return settings; +} + /** * shell_global_get_current_time: * @global: A #ShellGlobal diff --git a/src/shell-global.h b/src/shell-global.h index 71bdf7d85..a5630ecd3 100644 --- a/src/shell-global.h +++ b/src/shell-global.h @@ -35,6 +35,7 @@ GdkScreen *shell_global_get_gdk_screen (ShellGlobal *global); MetaDisplay *shell_global_get_display (ShellGlobal *global); GList *shell_global_get_window_actors (ShellGlobal *global); GSettings *shell_global_get_settings (ShellGlobal *global); +GSettings *shell_global_get_overrides_settings (ShellGlobal *global); guint32 shell_global_get_current_time (ShellGlobal *global);