Florian Müllner 4fffe76
From 0c0cc4ce1d3e08eba3e701d565398e01aa479ff7 Mon Sep 17 00:00:00 2001
77345fe
From: Ray Strode <rstrode@redhat.com>
77345fe
Date: Wed, 16 Aug 2023 11:13:39 -0400
77345fe
Subject: [PATCH 2/3] status/keyboard: Load keyboard from system settings if
77345fe
 gsettings unconfigured
77345fe
Florian Müllner 4fffe76
Right now if a user hasn't configured their input sources, the code
Florian Müllner 4fffe76
falls back to
77345fe
using the current layout on Xorg and the mutter default with wayland.
77345fe
77345fe
This commit changes the code to instead fall back to using the system
77345fe
default (as configured by localed).
77345fe
---
Florian Müllner 4fffe76
 js/ui/status/keyboard.js | 62 +++++++++++++++++++++++++++++++---------
Florian Müllner 4fffe76
 1 file changed, 48 insertions(+), 14 deletions(-)
77345fe
77345fe
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
Florian Müllner 4fffe76
index 4ef2f355d3..d91eb41bc6 100644
77345fe
--- a/js/ui/status/keyboard.js
77345fe
+++ b/js/ui/status/keyboard.js
Florian Müllner 4293386
@@ -22,6 +22,9 @@ import * as Util from '../../misc/util.js';
77345fe
 export const INPUT_SOURCE_TYPE_XKB = 'xkb';
77345fe
 export const INPUT_SOURCE_TYPE_IBUS = 'ibus';
77345fe
 
77345fe
+const DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
77345fe
+const KEY_INPUT_SOURCES = 'sources';
77345fe
+
77345fe
 export const LayoutMenuItem = GObject.registerClass(
77345fe
 class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
77345fe
     _init(displayName, shortName) {
Florian Müllner 4fffe76
@@ -278,18 +281,16 @@ class InputSourceSystemSettings extends InputSourceSettings {
77345fe
 }
77345fe
 
77345fe
 class InputSourceSessionSettings extends InputSourceSettings {
77345fe
-    constructor() {
77345fe
+    constructor(settings) {
77345fe
         super();
77345fe
 
77345fe
-        this._DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
77345fe
-        this._KEY_INPUT_SOURCES = 'sources';
77345fe
         this._KEY_MRU_SOURCES = 'mru-sources';
77345fe
         this._KEY_KEYBOARD_OPTIONS = 'xkb-options';
Florian Müllner 4fffe76
         this._KEY_KEYBOARD_MODEL = 'xkb-model';
77345fe
         this._KEY_PER_WINDOW = 'per-window';
77345fe
 
77345fe
-        this._settings = new Gio.Settings({schema_id: this._DESKTOP_INPUT_SOURCES_SCHEMA});
77345fe
-        this._settings.connect(`changed::${this._KEY_INPUT_SOURCES}`, this._emitInputSourcesChanged.bind(this));
77345fe
+        this._settings = settings;
77345fe
+        this._settings.connect(`changed::${KEY_INPUT_SOURCES}`, this._emitInputSourcesChanged.bind(this));
77345fe
         this._settings.connect(`changed::${this._KEY_KEYBOARD_OPTIONS}`, this._emitKeyboardOptionsChanged.bind(this));
Florian Müllner 4fffe76
         this._settings.connect(`changed::${this._KEY_KEYBOARD_MODEL}`, this._emitKeyboardModelChanged.bind(this));
77345fe
         this._settings.connect(`changed::${this._KEY_PER_WINDOW}`, this._emitPerWindowChanged.bind(this));
Florian Müllner 4fffe76
@@ -308,7 +309,7 @@ class InputSourceSessionSettings extends InputSourceSettings {
77345fe
     }
77345fe
 
77345fe
     get inputSources() {
77345fe
-        return this._getSourcesList(this._KEY_INPUT_SOURCES);
77345fe
+        return this._getSourcesList(KEY_INPUT_SOURCES);
77345fe
     }
77345fe
 
77345fe
     get mruSources() {
Florian Müllner 4fffe76
@@ -363,13 +364,6 @@ export class InputSourceManager extends Signals.EventEmitter {
77345fe
                 Meta.KeyBindingFlags.IS_REVERSED,
77345fe
                 Shell.ActionMode.ALL,
77345fe
                 this._switchInputSource.bind(this));
77345fe
-        if (Main.sessionMode.isGreeter)
77345fe
-            this._settings = new InputSourceSystemSettings();
77345fe
-        else
77345fe
-            this._settings = new InputSourceSessionSettings();
77345fe
-        this._settings.connect('input-sources-changed', this._inputSourcesChanged.bind(this));
77345fe
-        this._settings.connect('keyboard-options-changed', this._keyboardOptionsChanged.bind(this));
Florian Müllner 4fffe76
-        this._settings.connect('keyboard-model-changed', this._keyboardModelChanged.bind(this));
77345fe
 
77345fe
         this._xkbInfo = KeyboardManager.getXkbInfo();
77345fe
         this._keyboardManager = KeyboardManager.getKeyboardManager();
Florian Müllner 4fffe76
@@ -381,16 +375,56 @@ export class InputSourceManager extends Signals.EventEmitter {
77345fe
         this._ibusManager.connect('property-updated', this._ibusPropertyUpdated.bind(this));
77345fe
         this._ibusManager.connect('set-content-type', this._ibusSetContentType.bind(this));
77345fe
 
77345fe
+        this._inputSettings = new Gio.Settings({schema_id: DESKTOP_INPUT_SOURCES_SCHEMA});
77345fe
+        this._setupInputSettings();
77345fe
+
77345fe
         global.display.connect('modifiers-accelerator-activated', this._modifiersSwitcher.bind(this));
77345fe
 
77345fe
         this._sourcesPerWindow = false;
77345fe
         this._focusWindowNotifyId = 0;
77345fe
-        this._settings.connect('per-window-changed', this._sourcesPerWindowChanged.bind(this));
77345fe
         this._sourcesPerWindowChanged();
77345fe
         this._disableIBus = false;
77345fe
         this._reloading = false;
77345fe
     }
77345fe
 
77345fe
+    _sessionHasNoInputSettings() {
77345fe
+        return this._inputSettings.get_user_value(KEY_INPUT_SOURCES) === null;
77345fe
+    }
77345fe
+
77345fe
+    _reloadInputSettings() {
77345fe
+        const hadNoSessionInputSettings = this._hasNoSessionInputSettings;
77345fe
+
77345fe
+        if (Main.sessionMode.isGreeter)
77345fe
+            this._hasNoSessionInputSettings = true;
77345fe
+        else
77345fe
+            this._hasNoSessionInputSettings = this._sessionHasNoInputSettings();
77345fe
+
77345fe
+        if (this._settings && hadNoSessionInputSettings === this._hasNoSessionInputSettings)
77345fe
+            return;
77345fe
+
77345fe
+        this._settings?.disconnectObject(this);
77345fe
+
77345fe
+        if (this._hasNoSessionInputSettings)
77345fe
+            this._settings = new InputSourceSystemSettings();
77345fe
+        else
77345fe
+            this._settings = new InputSourceSessionSettings(this._inputSettings);
77345fe
+
Florian Müllner 4fffe76
+        this._settings.connectObject(
Florian Müllner 4fffe76
+            'input-sources-changed', this._inputSourcesChanged.bind(this),
Florian Müllner 4fffe76
+            'keyboard-options-changed', this._keyboardOptionsChanged.bind(this),
Florian Müllner 4fffe76
+            'keyboard-model-changed', this._keyboardModelChanged.bind(this),
Florian Müllner 4fffe76
+            'per-window-changed', this._sourcesPerWindowChanged.bind(this),
Florian Müllner 4fffe76
+            this);
77345fe
+        this.reload();
77345fe
+    }
77345fe
+
77345fe
+    _setupInputSettings() {
77345fe
+        if (!Main.sessionMode.isGreeter)
77345fe
+            this._inputSettings.connect(`changed::${KEY_INPUT_SOURCES}`, this._reloadInputSettings.bind(this));
77345fe
+
77345fe
+        this._reloadInputSettings();
77345fe
+    }
77345fe
+
77345fe
     reload() {
77345fe
         this._reloading = true;
77345fe
         this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions);
77345fe
-- 
Florian Müllner 4fffe76
2.43.1
77345fe