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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2583>
This commit is contained in:
parent
11e9fbf264
commit
dad06fa423
@ -60,15 +60,17 @@ class KeyboardManager {
|
|||||||
_applyLayoutGroup(group) {
|
_applyLayoutGroup(group) {
|
||||||
let options = this._buildOptionsString();
|
let options = this._buildOptionsString();
|
||||||
let [layouts, variants] = this._buildGroupStrings(group);
|
let [layouts, variants] = this._buildGroupStrings(group);
|
||||||
|
let model = this._xkbModel;
|
||||||
|
|
||||||
if (this._currentKeymap &&
|
if (this._currentKeymap &&
|
||||||
this._currentKeymap.layouts === layouts &&
|
this._currentKeymap.layouts === layouts &&
|
||||||
this._currentKeymap.variants === variants &&
|
this._currentKeymap.variants === variants &&
|
||||||
this._currentKeymap.options === options)
|
this._currentKeymap.options === options &&
|
||||||
|
this._currentKeymap.model === model)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._currentKeymap = {layouts, variants, options};
|
this._currentKeymap = {layouts, variants, options, model};
|
||||||
global.backend.set_keymap(layouts, variants, options);
|
global.backend.set_keymap(layouts, variants, options, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyLayoutGroupIndex(idx) {
|
_applyLayoutGroupIndex(idx) {
|
||||||
@ -158,6 +160,10 @@ class KeyboardManager {
|
|||||||
this._xkbOptions = options;
|
this._xkbOptions = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setKeyboardModel(model) {
|
||||||
|
this._xkbModel = model;
|
||||||
|
}
|
||||||
|
|
||||||
_buildOptionsString() {
|
_buildOptionsString() {
|
||||||
let options = this._xkbOptions.join(',');
|
let options = this._xkbOptions.join(',');
|
||||||
return options;
|
return options;
|
||||||
|
@ -161,6 +161,10 @@ class InputSourceSettings extends Signals.EventEmitter {
|
|||||||
this.emit('keyboard-options-changed');
|
this.emit('keyboard-options-changed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_emitKeyboardModelChanged() {
|
||||||
|
this.emit('keyboard-model-changed');
|
||||||
|
}
|
||||||
|
|
||||||
_emitPerWindowChanged() {
|
_emitPerWindowChanged() {
|
||||||
this.emit('per-window-changed');
|
this.emit('per-window-changed');
|
||||||
}
|
}
|
||||||
@ -198,6 +202,7 @@ class InputSourceSystemSettings extends InputSourceSettings {
|
|||||||
this._layouts = '';
|
this._layouts = '';
|
||||||
this._variants = '';
|
this._variants = '';
|
||||||
this._options = '';
|
this._options = '';
|
||||||
|
this._model = '';
|
||||||
|
|
||||||
this._reload();
|
this._reload();
|
||||||
|
|
||||||
@ -229,6 +234,7 @@ class InputSourceSystemSettings extends InputSourceSettings {
|
|||||||
const layouts = props['X11Layout'].unpack();
|
const layouts = props['X11Layout'].unpack();
|
||||||
const variants = props['X11Variant'].unpack();
|
const variants = props['X11Variant'].unpack();
|
||||||
const options = props['X11Options'].unpack();
|
const options = props['X11Options'].unpack();
|
||||||
|
const model = props['X11Model'].unpack();
|
||||||
|
|
||||||
if (layouts !== this._layouts ||
|
if (layouts !== this._layouts ||
|
||||||
variants !== this._variants) {
|
variants !== this._variants) {
|
||||||
@ -240,6 +246,10 @@ class InputSourceSystemSettings extends InputSourceSettings {
|
|||||||
this._options = options;
|
this._options = options;
|
||||||
this._emitKeyboardOptionsChanged();
|
this._emitKeyboardOptionsChanged();
|
||||||
}
|
}
|
||||||
|
if (model !== this._model) {
|
||||||
|
this._model = model;
|
||||||
|
this._emitKeyboardModelChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get inputSources() {
|
get inputSources() {
|
||||||
@ -259,6 +269,10 @@ class InputSourceSystemSettings extends InputSourceSettings {
|
|||||||
get keyboardOptions() {
|
get keyboardOptions() {
|
||||||
return this._options.split(',');
|
return this._options.split(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get keyboardModel() {
|
||||||
|
return this._model;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InputSourceSessionSettings extends InputSourceSettings {
|
class InputSourceSessionSettings extends InputSourceSettings {
|
||||||
@ -269,11 +283,13 @@ class InputSourceSessionSettings extends InputSourceSettings {
|
|||||||
this._KEY_INPUT_SOURCES = 'sources';
|
this._KEY_INPUT_SOURCES = 'sources';
|
||||||
this._KEY_MRU_SOURCES = 'mru-sources';
|
this._KEY_MRU_SOURCES = 'mru-sources';
|
||||||
this._KEY_KEYBOARD_OPTIONS = 'xkb-options';
|
this._KEY_KEYBOARD_OPTIONS = 'xkb-options';
|
||||||
|
this._KEY_KEYBOARD_MODEL = 'xkb-model';
|
||||||
this._KEY_PER_WINDOW = 'per-window';
|
this._KEY_PER_WINDOW = 'per-window';
|
||||||
|
|
||||||
this._settings = new Gio.Settings({schema_id: this._DESKTOP_INPUT_SOURCES_SCHEMA});
|
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_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_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));
|
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);
|
return this._settings.get_strv(this._KEY_KEYBOARD_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get keyboardModel() {
|
||||||
|
return this._settings.get_string(this._KEY_KEYBOARD_MODEL);
|
||||||
|
}
|
||||||
|
|
||||||
get perWindow() {
|
get perWindow() {
|
||||||
return this._settings.get_boolean(this._KEY_PER_WINDOW);
|
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 = new InputSourceSessionSettings();
|
||||||
this._settings.connect('input-sources-changed', this._inputSourcesChanged.bind(this));
|
this._settings.connect('input-sources-changed', this._inputSourcesChanged.bind(this));
|
||||||
this._settings.connect('keyboard-options-changed', this._keyboardOptionsChanged.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._xkbInfo = KeyboardManager.getXkbInfo();
|
||||||
this._keyboardManager = KeyboardManager.getKeyboardManager();
|
this._keyboardManager = KeyboardManager.getKeyboardManager();
|
||||||
@ -371,6 +392,7 @@ export class InputSourceManager extends Signals.EventEmitter {
|
|||||||
reload() {
|
reload() {
|
||||||
this._reloading = true;
|
this._reloading = true;
|
||||||
this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions);
|
this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions);
|
||||||
|
this._keyboardManager.setKeyboardModel(this._settings.keyboardModel);
|
||||||
this._inputSourcesChanged();
|
this._inputSourcesChanged();
|
||||||
this._reloading = false;
|
this._reloading = false;
|
||||||
}
|
}
|
||||||
@ -435,6 +457,11 @@ export class InputSourceManager extends Signals.EventEmitter {
|
|||||||
this._keyboardManager.reapply();
|
this._keyboardManager.reapply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_keyboardModelChanged() {
|
||||||
|
this._keyboardManager.setKeyboardModel(this._settings.keyboardModel);
|
||||||
|
this._keyboardManager.reapply();
|
||||||
|
}
|
||||||
|
|
||||||
_updateMruSettings() {
|
_updateMruSettings() {
|
||||||
// If IBus is not ready we don't have a full picture of all
|
// If IBus is not ready we don't have a full picture of all
|
||||||
// the available sources, so don't update the setting
|
// the available sources, so don't update the setting
|
||||||
|
Loading…
x
Reference in New Issue
Block a user