main: Move pref overrides back into C

Commit 6c2f3d1d17 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
This commit is contained in:
Florian Müllner 2014-06-05 18:09:47 +02:00
parent 589becbc79
commit ae2751a68b
5 changed files with 61 additions and 14 deletions

View File

@ -74,7 +74,6 @@ let _startDate;
let _defaultCssStylesheet = null; let _defaultCssStylesheet = null;
let _cssStylesheet = null; let _cssStylesheet = null;
let _a11ySettings = null; let _a11ySettings = null;
let dynamicWorkspacesSchema = null;
function _sessionUpdated() { function _sessionUpdated() {
_loadDefaultStylesheet(); _loadDefaultStylesheet();
@ -111,7 +110,6 @@ function start() {
sessionMode = new SessionMode.SessionMode(); sessionMode = new SessionMode.SessionMode();
sessionMode.connect('updated', _sessionUpdated); sessionMode.connect('updated', _sessionUpdated);
_initializePrefs();
_initializeUI(); _initializeUI();
shellDBusService = new ShellDBus.GnomeShell(); shellDBusService = new ShellDBus.GnomeShell();
@ -120,17 +118,6 @@ function start() {
_sessionUpdated(); _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() { function _initializeUI() {
// Ensure ShellWindowTracker and ShellAppUsage are initialized; this will // Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
// also initialize ShellAppSystem first. ShellAppSystem // also initialize ShellAppSystem first. ShellAppSystem

View File

@ -199,12 +199,19 @@ const WorkspaceTracker = new Lang.Class({
global.screen.connect('window-left-monitor', Lang.bind(this, this._windowLeftMonitor)); global.screen.connect('window-left-monitor', Lang.bind(this, this._windowLeftMonitor));
global.screen.connect('restacked', Lang.bind(this, this._windowsRestacked)); 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._workspaceSettings.connect('changed::dynamic-workspaces', Lang.bind(this, this._queueCheckWorkspaces));
this._nWorkspacesChanged(); 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() { _checkWorkspaces: function() {
let i; let i;
let emptyWorkspaces = []; let emptyWorkspaces = [];

View File

@ -34,6 +34,8 @@ extern GType gnome_shell_plugin_get_type (void);
#define SHELL_DBUS_SERVICE "org.gnome.Shell" #define SHELL_DBUS_SERVICE "org.gnome.Shell"
#define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier" #define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier"
#define OVERRIDES_SCHEMA "org.gnome.shell.overrides"
#define WM_NAME "GNOME Shell" #define WM_NAME "GNOME Shell"
#define GNOME_WM_KEYBINDINGS "Mutter,GNOME Shell" #define GNOME_WM_KEYBINDINGS "Mutter,GNOME Shell"
@ -167,6 +169,23 @@ shell_dbus_init (gboolean replace)
g_object_unref (session); 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 static void
shell_introspection_init (void) shell_introspection_init (void)
{ {
@ -434,6 +453,8 @@ main (int argc, char **argv)
_shell_global_init ("session-mode", session_mode, NULL); _shell_global_init ("session-mode", session_mode, NULL);
shell_prefs_init ();
ecode = meta_run (); ecode = meta_run ();
if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP")) if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP"))

View File

@ -1355,6 +1355,37 @@ shell_global_get_settings (ShellGlobal *global)
return global->settings; 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: * shell_global_get_current_time:
* @global: A #ShellGlobal * @global: A #ShellGlobal

View File

@ -35,6 +35,7 @@ GdkScreen *shell_global_get_gdk_screen (ShellGlobal *global);
MetaDisplay *shell_global_get_display (ShellGlobal *global); MetaDisplay *shell_global_get_display (ShellGlobal *global);
GList *shell_global_get_window_actors (ShellGlobal *global); GList *shell_global_get_window_actors (ShellGlobal *global);
GSettings *shell_global_get_settings (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); guint32 shell_global_get_current_time (ShellGlobal *global);