Florian Müllner 4fffe76
From d060baeb69a2a7d80fe403fc8eec90e20aa6cb7f Mon Sep 17 00:00:00 2001
77345fe
From: Ray Strode <rstrode@redhat.com>
77345fe
Date: Wed, 16 Aug 2023 14:09:50 -0400
77345fe
Subject: [PATCH 3/3] status/keyboard: Use gnome-desktop API for getting
77345fe
 default input sources list
77345fe
77345fe
At the moment, gnome-shell tries to figure out the default input sources
77345fe
from localed. It fails to take into account the system locale and input
77345fe
methods.
77345fe
77345fe
This commit switches it to use a new function in gnome-desktop,
77345fe
gnome_get_default_input_sources, which does most of the heavy
77345fe
lifting itself, instead.
77345fe
---
Florian Müllner 4fffe76
 js/ui/status/keyboard.js | 59 ++++++++++++++++++----------------------
Florian Müllner 4fffe76
 1 file changed, 27 insertions(+), 32 deletions(-)
77345fe
77345fe
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
Florian Müllner 4fffe76
index d91eb41bc6..19c36031f6 100644
77345fe
--- a/js/ui/status/keyboard.js
77345fe
+++ b/js/ui/status/keyboard.js
Florian Müllner 4293386
@@ -3,6 +3,7 @@
77345fe
 import Clutter from 'gi://Clutter';
77345fe
 import Gio from 'gi://Gio';
77345fe
 import GLib from 'gi://GLib';
77345fe
+import GnomeDesktop from 'gi://GnomeDesktop';
77345fe
 import GObject from 'gi://GObject';
77345fe
 import IBus from 'gi://IBus';
77345fe
 import Meta from 'gi://Meta';
Florian Müllner 4293386
@@ -25,6 +26,8 @@ export const INPUT_SOURCE_TYPE_IBUS = 'ibus';
77345fe
 const DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
77345fe
 const KEY_INPUT_SOURCES = 'sources';
77345fe
 
77345fe
+Gio._promisify(GnomeDesktop, 'get_default_input_sources');
77345fe
+
77345fe
 export const LayoutMenuItem = GObject.registerClass(
77345fe
 class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
77345fe
     _init(displayName, shortName) {
Florian Müllner 4fffe76
@@ -202,9 +205,9 @@ class InputSourceSystemSettings extends InputSourceSettings {
77345fe
         this._BUS_IFACE = 'org.freedesktop.locale1';
77345fe
         this._BUS_PROPS_IFACE = 'org.freedesktop.DBus.Properties';
77345fe
 
77345fe
-        this._layouts = '';
77345fe
-        this._variants = '';
77345fe
-        this._options = '';
77345fe
+        this._inputSourceIds = [];
77345fe
+        this._inputSourceTypes = [];
77345fe
+        this._options = [];
Florian Müllner 4fffe76
         this._model = '';
77345fe
 
77345fe
         this._reload().catch(error => {
Florian Müllner 4fffe76
@@ -221,30 +224,22 @@ class InputSourceSystemSettings extends InputSourceSettings {
77345fe
     }
77345fe
 
77345fe
     async _reload() {
77345fe
-        let props;
77345fe
+        let inputSourceIds;
77345fe
+        let inputSourceTypes;
77345fe
+        let options;
Florian Müllner 4fffe76
+        let model;
77345fe
         try {
77345fe
-            const result = await Gio.DBus.system.call(
77345fe
-                this._BUS_NAME,
77345fe
-                this._BUS_PATH,
77345fe
-                this._BUS_PROPS_IFACE,
77345fe
-                'GetAll',
77345fe
-                new GLib.Variant('(s)', [this._BUS_IFACE]),
77345fe
-                null, Gio.DBusCallFlags.NONE, -1, null);
77345fe
-            [props] = result.deepUnpack();
Florian Müllner 4fffe76
+            [inputSourceIds, inputSourceTypes, options, model] =
Florian Müllner 4fffe76
+                await GnomeDesktop.get_default_input_sources(null);
77345fe
         } catch (e) {
77345fe
-            log(`Could not get properties from ${this._BUS_NAME}`);
77345fe
+            logError(e, 'Could not get default input sources');
77345fe
             return;
77345fe
         }
77345fe
 
77345fe
-        const layouts = props['X11Layout'].unpack();
77345fe
-        const variants = props['X11Variant'].unpack();
77345fe
-        const options = props['X11Options'].unpack();
Florian Müllner 4fffe76
-        const model = props['X11Model'].unpack();
77345fe
-
77345fe
-        if (layouts !== this._layouts ||
77345fe
-            variants !== this._variants) {
77345fe
-            this._layouts = layouts;
77345fe
-            this._variants = variants;
77345fe
+        if (inputSourceIds !== this._inputSourceIds ||
77345fe
+            inputSourceTypes !== this._inputSourceTypes) {
77345fe
+            this._inputSourceIds = inputSourceIds;
77345fe
+            this._inputSourceTypes = inputSourceTypes;
77345fe
             this._emitInputSourcesChanged();
77345fe
         }
77345fe
         if (options !== this._options) {
Florian Müllner 4fffe76
@@ -258,21 +253,21 @@ class InputSourceSystemSettings extends InputSourceSettings {
77345fe
     }
77345fe
 
77345fe
     get inputSources() {
77345fe
-        let sourcesList = [];
77345fe
-        let layouts = this._layouts.split(',');
77345fe
-        let variants = this._variants.split(',');
77345fe
-
77345fe
-        for (let i = 0; i < layouts.length && !!layouts[i]; i++) {
77345fe
-            let id = layouts[i];
77345fe
-            if (variants[i])
77345fe
-                id += `+${variants[i]}`;
77345fe
-            sourcesList.push({type: INPUT_SOURCE_TYPE_XKB, id});
77345fe
+        let sourcesList;
77345fe
+
77345fe
+        if (this._inputSourceIds) {
77345fe
+            sourcesList = this._inputSourceIds.map((id, index) => {
Florian Müllner 4fffe76
+                return {type: this._inputSourceTypes[index], id};
77345fe
+            });
77345fe
+        } else {
77345fe
+            sourcesList = [];
77345fe
         }
77345fe
+
77345fe
         return sourcesList;
77345fe
     }
77345fe
 
77345fe
     get keyboardOptions() {
77345fe
-        return this._options.split(',');
77345fe
+        return this._options;
77345fe
     }
77345fe
 
Florian Müllner 4fffe76
     get keyboardModel() {
77345fe
-- 
Florian Müllner 4fffe76
2.43.1
77345fe