From dad06fa423ec3cc1f54c0266d27024df74ef4702 Mon Sep 17 00:00:00 2001 From: Leorize Date: Thu, 1 Dec 2022 07:11:57 +0000 Subject: [PATCH] keyboard: Add keyboard model configuration support Enables the use of a new `xkb-model` dconf key to let user configure their desired keyboard model. Also included is additional glue for respecting X11Model set at the system level (ie. via `localectl`). For simplicity, this assumes the use of one global keyboard model. Part-of: --- js/misc/keyboardManager.js | 12 +++++++++--- js/ui/status/keyboard.js | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/js/misc/keyboardManager.js b/js/misc/keyboardManager.js index ed2bdddc8..d63bd1fec 100644 --- a/js/misc/keyboardManager.js +++ b/js/misc/keyboardManager.js @@ -60,15 +60,17 @@ class KeyboardManager { _applyLayoutGroup(group) { let options = this._buildOptionsString(); let [layouts, variants] = this._buildGroupStrings(group); + let model = this._xkbModel; if (this._currentKeymap && this._currentKeymap.layouts === layouts && this._currentKeymap.variants === variants && - this._currentKeymap.options === options) + this._currentKeymap.options === options && + this._currentKeymap.model === model) return; - this._currentKeymap = {layouts, variants, options}; - global.backend.set_keymap(layouts, variants, options); + this._currentKeymap = {layouts, variants, options, model}; + global.backend.set_keymap(layouts, variants, options, model); } _applyLayoutGroupIndex(idx) { @@ -158,6 +160,10 @@ class KeyboardManager { this._xkbOptions = options; } + setKeyboardModel(model) { + this._xkbModel = model; + } + _buildOptionsString() { let options = this._xkbOptions.join(','); return options; diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js index e285eb495..cfc0a01f6 100644 --- a/js/ui/status/keyboard.js +++ b/js/ui/status/keyboard.js @@ -161,6 +161,10 @@ class InputSourceSettings extends Signals.EventEmitter { this.emit('keyboard-options-changed'); } + _emitKeyboardModelChanged() { + this.emit('keyboard-model-changed'); + } + _emitPerWindowChanged() { this.emit('per-window-changed'); } @@ -198,6 +202,7 @@ class InputSourceSystemSettings extends InputSourceSettings { this._layouts = ''; this._variants = ''; this._options = ''; + this._model = ''; this._reload(); @@ -229,6 +234,7 @@ class InputSourceSystemSettings extends InputSourceSettings { const layouts = props['X11Layout'].unpack(); const variants = props['X11Variant'].unpack(); const options = props['X11Options'].unpack(); + const model = props['X11Model'].unpack(); if (layouts !== this._layouts || variants !== this._variants) { @@ -240,6 +246,10 @@ class InputSourceSystemSettings extends InputSourceSettings { this._options = options; this._emitKeyboardOptionsChanged(); } + if (model !== this._model) { + this._model = model; + this._emitKeyboardModelChanged(); + } } get inputSources() { @@ -259,6 +269,10 @@ class InputSourceSystemSettings extends InputSourceSettings { get keyboardOptions() { return this._options.split(','); } + + get keyboardModel() { + return this._model; + } } class InputSourceSessionSettings extends InputSourceSettings { @@ -269,11 +283,13 @@ class InputSourceSessionSettings extends InputSourceSettings { this._KEY_INPUT_SOURCES = 'sources'; this._KEY_MRU_SOURCES = 'mru-sources'; this._KEY_KEYBOARD_OPTIONS = 'xkb-options'; + this._KEY_KEYBOARD_MODEL = 'xkb-model'; this._KEY_PER_WINDOW = 'per-window'; this._settings = new Gio.Settings({schema_id: this._DESKTOP_INPUT_SOURCES_SCHEMA}); this._settings.connect(`changed::${this._KEY_INPUT_SOURCES}`, this._emitInputSourcesChanged.bind(this)); this._settings.connect(`changed::${this._KEY_KEYBOARD_OPTIONS}`, this._emitKeyboardOptionsChanged.bind(this)); + this._settings.connect(`changed::${this._KEY_KEYBOARD_MODEL}`, this._emitKeyboardModelChanged.bind(this)); this._settings.connect(`changed::${this._KEY_PER_WINDOW}`, this._emitPerWindowChanged.bind(this)); } @@ -306,6 +322,10 @@ class InputSourceSessionSettings extends InputSourceSettings { return this._settings.get_strv(this._KEY_KEYBOARD_OPTIONS); } + get keyboardModel() { + return this._settings.get_string(this._KEY_KEYBOARD_MODEL); + } + get perWindow() { return this._settings.get_boolean(this._KEY_PER_WINDOW); } @@ -347,6 +367,7 @@ export class InputSourceManager extends Signals.EventEmitter { this._settings = new InputSourceSessionSettings(); this._settings.connect('input-sources-changed', this._inputSourcesChanged.bind(this)); this._settings.connect('keyboard-options-changed', this._keyboardOptionsChanged.bind(this)); + this._settings.connect('keyboard-model-changed', this._keyboardModelChanged.bind(this)); this._xkbInfo = KeyboardManager.getXkbInfo(); this._keyboardManager = KeyboardManager.getKeyboardManager(); @@ -371,6 +392,7 @@ export class InputSourceManager extends Signals.EventEmitter { reload() { this._reloading = true; this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions); + this._keyboardManager.setKeyboardModel(this._settings.keyboardModel); this._inputSourcesChanged(); this._reloading = false; } @@ -435,6 +457,11 @@ export class InputSourceManager extends Signals.EventEmitter { this._keyboardManager.reapply(); } + _keyboardModelChanged() { + this._keyboardManager.setKeyboardModel(this._settings.keyboardModel); + this._keyboardManager.reapply(); + } + _updateMruSettings() { // If IBus is not ready we don't have a full picture of all // the available sources, so don't update the setting