2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported InputSourceIndicator */
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, IBus, Meta, Shell, St } = imports.gi;
|
2013-03-11 23:06:32 -04:00
|
|
|
const Gettext = imports.gettext;
|
2022-07-04 18:30:44 -04:00
|
|
|
const Signals = imports.misc.signals;
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2014-02-14 10:11:28 -05:00
|
|
|
const IBusManager = imports.misc.ibusManager;
|
|
|
|
const KeyboardManager = imports.misc.keyboardManager;
|
2011-06-21 18:26:57 -04:00
|
|
|
const Main = imports.ui.main;
|
2011-01-04 17:04:56 -05:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2012-12-10 14:35:29 -05:00
|
|
|
const SwitcherPopup = imports.ui.switcherPopup;
|
2011-02-05 13:30:16 -05:00
|
|
|
const Util = imports.misc.util;
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2019-05-10 17:17:55 -04:00
|
|
|
var INPUT_SOURCE_TYPE_XKB = 'xkb';
|
|
|
|
var INPUT_SOURCE_TYPE_IBUS = 'ibus';
|
2012-05-29 13:30:14 -04:00
|
|
|
|
2019-04-12 17:00:49 -04:00
|
|
|
var LayoutMenuItem = GObject.registerClass(
|
|
|
|
class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
|
|
|
|
_init(displayName, shortName) {
|
|
|
|
super._init();
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2019-10-21 14:44:00 -04:00
|
|
|
this.label = new St.Label({
|
|
|
|
text: displayName,
|
|
|
|
x_expand: true,
|
|
|
|
});
|
2012-04-18 22:01:29 -04:00
|
|
|
this.indicator = new St.Label({ text: shortName });
|
2019-10-21 14:44:00 -04:00
|
|
|
this.add_child(this.label);
|
2019-04-12 17:00:49 -04:00
|
|
|
this.add(this.indicator);
|
|
|
|
this.label_actor = this.label;
|
2011-01-04 17:04:56 -05:00
|
|
|
}
|
2019-04-12 17:00:49 -04:00
|
|
|
});
|
2012-12-13 10:31:03 -05:00
|
|
|
|
2022-07-04 18:30:44 -04:00
|
|
|
var InputSource = class extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(type, id, displayName, shortName, index) {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2012-12-13 10:31:03 -05:00
|
|
|
this.type = type;
|
|
|
|
this.id = id;
|
|
|
|
this.displayName = displayName;
|
|
|
|
this._shortName = shortName;
|
|
|
|
this.index = index;
|
|
|
|
|
2012-12-13 14:48:13 -05:00
|
|
|
this.properties = null;
|
2014-06-05 12:47:48 -04:00
|
|
|
|
|
|
|
this.xkbId = this._getXkbId();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-13 10:31:03 -05:00
|
|
|
|
|
|
|
get shortName() {
|
|
|
|
return this._shortName;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-13 10:31:03 -05:00
|
|
|
|
|
|
|
set shortName(v) {
|
|
|
|
this._shortName = v;
|
2014-05-30 09:29:03 -04:00
|
|
|
this.emit('changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-13 10:31:03 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate(interactive) {
|
2016-05-25 14:54:33 -04:00
|
|
|
this.emit('activate', !!interactive);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-05 12:47:48 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getXkbId() {
|
2014-06-05 12:47:48 -04:00
|
|
|
let engineDesc = IBusManager.getIBusManager().getEngineDesc(this.id);
|
|
|
|
if (!engineDesc)
|
|
|
|
return this.id;
|
|
|
|
|
|
|
|
if (engineDesc.variant && engineDesc.variant.length > 0)
|
2022-02-07 09:14:06 -05:00
|
|
|
return `${engineDesc.layout}+${engineDesc.variant}`;
|
2014-06-05 12:47:48 -04:00
|
|
|
else
|
|
|
|
return engineDesc.layout;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-12-13 10:31:03 -05:00
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var InputSourcePopup = GObject.registerClass(
|
|
|
|
class InputSourcePopup extends SwitcherPopup.SwitcherPopup {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(items, action, actionBackward) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init(items);
|
2012-12-10 14:35:29 -05:00
|
|
|
|
|
|
|
this._action = action;
|
|
|
|
this._actionBackward = actionBackward;
|
|
|
|
|
|
|
|
this._switcherList = new InputSourceSwitcher(this._items);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_keyPressHandler(keysym, action) {
|
2012-12-10 14:35:29 -05:00
|
|
|
if (action == this._action)
|
2014-08-12 11:55:22 -04:00
|
|
|
this._select(this._next());
|
2012-12-10 14:35:29 -05:00
|
|
|
else if (action == this._actionBackward)
|
2014-08-12 11:55:22 -04:00
|
|
|
this._select(this._previous());
|
2019-11-05 14:37:28 -05:00
|
|
|
else if (keysym == Clutter.KEY_Left)
|
2012-12-10 14:35:29 -05:00
|
|
|
this._select(this._previous());
|
2019-11-05 14:37:28 -05:00
|
|
|
else if (keysym == Clutter.KEY_Right)
|
2012-12-10 14:35:29 -05:00
|
|
|
this._select(this._next());
|
2014-05-26 09:27:16 -04:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_finish() {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._finish();
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2016-05-25 14:54:33 -04:00
|
|
|
this._items[this._selectedIndex].activate(true);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-12-10 14:35:29 -05:00
|
|
|
});
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var InputSourceSwitcher = GObject.registerClass(
|
|
|
|
class InputSourceSwitcher extends SwitcherPopup.SwitcherList {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(items) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init(true);
|
2012-12-10 14:35:29 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
this._addIcon(items[i]);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addIcon(item) {
|
2012-12-10 14:35:29 -05:00
|
|
|
let box = new St.BoxLayout({ vertical: true });
|
|
|
|
|
|
|
|
let bin = new St.Bin({ style_class: 'input-source-switcher-symbol' });
|
2020-01-03 07:06:08 -05:00
|
|
|
let symbol = new St.Label({
|
|
|
|
text: item.shortName,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2012-12-10 14:35:29 -05:00
|
|
|
bin.set_child(symbol);
|
2019-10-21 14:44:00 -04:00
|
|
|
box.add_child(bin);
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2020-01-03 07:06:08 -05:00
|
|
|
let text = new St.Label({
|
|
|
|
text: item.displayName,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
2019-10-21 14:44:00 -04:00
|
|
|
box.add_child(text);
|
2012-12-10 14:35:29 -05:00
|
|
|
|
|
|
|
this.addItem(box, text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-04 18:30:44 -04:00
|
|
|
var InputSourceSettings = class extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor() {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2019-04-18 16:55:34 -04:00
|
|
|
if (this.constructor === InputSourceSettings)
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new TypeError(`Cannot instantiate abstract class ${this.constructor.name}`);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_emitInputSourcesChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
this.emit('input-sources-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_emitKeyboardOptionsChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
this.emit('keyboard-options-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_emitPerWindowChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
this.emit('per-window-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
get inputSources() {
|
|
|
|
return [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2016-05-23 19:24:50 -04:00
|
|
|
get mruSources() {
|
|
|
|
return [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-23 19:24:50 -04:00
|
|
|
|
|
|
|
set mruSources(sourcesList) {
|
|
|
|
// do nothing
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-23 19:24:50 -04:00
|
|
|
|
2015-03-16 10:10:47 -04:00
|
|
|
get keyboardOptions() {
|
|
|
|
return [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
get perWindow() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var InputSourceSystemSettings = class extends InputSourceSettings {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
this._BUS_NAME = 'org.freedesktop.locale1';
|
|
|
|
this._BUS_PATH = '/org/freedesktop/locale1';
|
|
|
|
this._BUS_IFACE = 'org.freedesktop.locale1';
|
|
|
|
this._BUS_PROPS_IFACE = 'org.freedesktop.DBus.Properties';
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
this._layouts = '';
|
|
|
|
this._variants = '';
|
|
|
|
this._options = '';
|
|
|
|
|
|
|
|
this._reload();
|
|
|
|
|
|
|
|
Gio.DBus.system.signal_subscribe(this._BUS_NAME,
|
|
|
|
this._BUS_PROPS_IFACE,
|
|
|
|
'PropertiesChanged',
|
|
|
|
this._BUS_PATH,
|
|
|
|
null,
|
|
|
|
Gio.DBusSignalFlags.NONE,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._reload.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
async _reload() {
|
|
|
|
let props;
|
|
|
|
try {
|
|
|
|
const result = await Gio.DBus.system.call(
|
|
|
|
this._BUS_NAME,
|
|
|
|
this._BUS_PATH,
|
|
|
|
this._BUS_PROPS_IFACE,
|
|
|
|
'GetAll',
|
|
|
|
new GLib.Variant('(s)', [this._BUS_IFACE]),
|
|
|
|
null, Gio.DBusCallFlags.NONE, -1, null);
|
2022-08-10 05:56:14 -04:00
|
|
|
[props] = result.deepUnpack();
|
2019-12-19 14:50:37 -05:00
|
|
|
} catch (e) {
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`Could not get properties from ${this._BUS_NAME}`);
|
2019-12-19 14:50:37 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const layouts = props['X11Layout'].unpack();
|
|
|
|
const variants = props['X11Variant'].unpack();
|
|
|
|
const options = props['X11Options'].unpack();
|
|
|
|
|
|
|
|
if (layouts !== this._layouts ||
|
|
|
|
variants !== this._variants) {
|
|
|
|
this._layouts = layouts;
|
|
|
|
this._variants = variants;
|
|
|
|
this._emitInputSourcesChanged();
|
|
|
|
}
|
|
|
|
if (options !== this._options) {
|
|
|
|
this._options = options;
|
|
|
|
this._emitKeyboardOptionsChanged();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
get inputSources() {
|
|
|
|
let sourcesList = [];
|
|
|
|
let layouts = this._layouts.split(',');
|
|
|
|
let variants = this._variants.split(',');
|
|
|
|
|
|
|
|
for (let i = 0; i < layouts.length && !!layouts[i]; i++) {
|
|
|
|
let id = layouts[i];
|
2019-06-29 18:33:20 -04:00
|
|
|
if (variants[i])
|
2022-02-07 09:14:06 -05:00
|
|
|
id += `+${variants[i]}`;
|
2019-08-19 15:06:04 -04:00
|
|
|
sourcesList.push({ type: INPUT_SOURCE_TYPE_XKB, id });
|
2015-03-16 10:10:47 -04:00
|
|
|
}
|
|
|
|
return sourcesList;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
get keyboardOptions() {
|
|
|
|
return this._options.split(',');
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var InputSourceSessionSettings = class extends InputSourceSettings {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
this._DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
|
|
|
|
this._KEY_INPUT_SOURCES = 'sources';
|
|
|
|
this._KEY_MRU_SOURCES = 'mru-sources';
|
|
|
|
this._KEY_KEYBOARD_OPTIONS = 'xkb-options';
|
|
|
|
this._KEY_PER_WINDOW = 'per-window';
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
this._settings = new Gio.Settings({ schema_id: this._DESKTOP_INPUT_SOURCES_SCHEMA });
|
2022-02-07 09:14:06 -05:00
|
|
|
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_PER_WINDOW}`, this._emitPerWindowChanged.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getSourcesList(key) {
|
2015-03-16 10:10:47 -04:00
|
|
|
let sourcesList = [];
|
2016-05-24 14:55:13 -04:00
|
|
|
let sources = this._settings.get_value(key);
|
2015-03-16 10:10:47 -04:00
|
|
|
let nSources = sources.n_children();
|
|
|
|
|
|
|
|
for (let i = 0; i < nSources; i++) {
|
2022-08-10 05:56:14 -04:00
|
|
|
let [type, id] = sources.get_child_value(i).deepUnpack();
|
2019-08-19 15:06:04 -04:00
|
|
|
sourcesList.push({ type, id });
|
2015-03-16 10:10:47 -04:00
|
|
|
}
|
|
|
|
return sourcesList;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2016-05-24 14:55:13 -04:00
|
|
|
get inputSources() {
|
|
|
|
return this._getSourcesList(this._KEY_INPUT_SOURCES);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-24 14:55:13 -04:00
|
|
|
|
2016-05-23 19:24:50 -04:00
|
|
|
get mruSources() {
|
|
|
|
return this._getSourcesList(this._KEY_MRU_SOURCES);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-23 19:24:50 -04:00
|
|
|
|
|
|
|
set mruSources(sourcesList) {
|
|
|
|
let sources = GLib.Variant.new('a(ss)', sourcesList);
|
|
|
|
this._settings.set_value(this._KEY_MRU_SOURCES, sources);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-23 19:24:50 -04:00
|
|
|
|
2015-03-16 10:10:47 -04:00
|
|
|
get keyboardOptions() {
|
|
|
|
return this._settings.get_strv(this._KEY_KEYBOARD_OPTIONS);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-16 10:10:47 -04:00
|
|
|
|
|
|
|
get perWindow() {
|
|
|
|
return this._settings.get_boolean(this._KEY_PER_WINDOW);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2015-03-16 10:10:47 -04:00
|
|
|
|
2022-07-04 18:30:44 -04:00
|
|
|
var InputSourceManager = class extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor() {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2012-12-13 10:31:03 -05:00
|
|
|
// All valid input sources currently in the gsettings
|
|
|
|
// KEY_INPUT_SOURCES list indexed by their index there
|
|
|
|
this._inputSources = {};
|
2012-12-13 14:48:13 -05:00
|
|
|
// All valid input sources currently in the gsettings
|
|
|
|
// KEY_INPUT_SOURCES list of type INPUT_SOURCE_TYPE_IBUS
|
|
|
|
// indexed by the IBus ID
|
|
|
|
this._ibusSources = {};
|
2012-12-13 10:31:03 -05:00
|
|
|
|
|
|
|
this._currentSource = null;
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2012-12-10 14:34:43 -05:00
|
|
|
// All valid input sources currently in the gsettings
|
|
|
|
// KEY_INPUT_SOURCES list ordered by most recently used
|
|
|
|
this._mruSources = [];
|
2015-03-28 14:09:34 -04:00
|
|
|
this._mruSourcesBackup = null;
|
2012-12-10 14:35:29 -05:00
|
|
|
this._keybindingAction =
|
|
|
|
Main.wm.addKeybinding('switch-input-source',
|
2014-06-24 15:17:09 -04:00
|
|
|
new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings" }),
|
2014-05-29 17:28:44 -04:00
|
|
|
Meta.KeyBindingFlags.NONE,
|
2014-12-11 09:35:40 -05:00
|
|
|
Shell.ActionMode.ALL,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._switchInputSource.bind(this));
|
2012-12-10 14:35:29 -05:00
|
|
|
this._keybindingActionBackward =
|
|
|
|
Main.wm.addKeybinding('switch-input-source-backward',
|
2014-06-24 15:17:09 -04:00
|
|
|
new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings" }),
|
2014-05-29 17:23:32 -04:00
|
|
|
Meta.KeyBindingFlags.IS_REVERSED,
|
2014-12-11 09:35:40 -05:00
|
|
|
Shell.ActionMode.ALL,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._switchInputSource.bind(this));
|
2015-03-16 10:10:47 -04:00
|
|
|
if (Main.sessionMode.isGreeter)
|
|
|
|
this._settings = new InputSourceSystemSettings();
|
|
|
|
else
|
|
|
|
this._settings = new InputSourceSessionSettings();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._settings.connect('input-sources-changed', this._inputSourcesChanged.bind(this));
|
|
|
|
this._settings.connect('keyboard-options-changed', this._keyboardOptionsChanged.bind(this));
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2014-02-14 10:11:28 -05:00
|
|
|
this._xkbInfo = KeyboardManager.getXkbInfo();
|
2014-06-05 12:47:48 -04:00
|
|
|
this._keyboardManager = KeyboardManager.getKeyboardManager();
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2012-12-10 14:34:43 -05:00
|
|
|
this._ibusReady = false;
|
2014-02-14 07:35:05 -05:00
|
|
|
this._ibusManager = IBusManager.getIBusManager();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._ibusManager.connect('ready', this._ibusReadyCallback.bind(this));
|
|
|
|
this._ibusManager.connect('properties-registered', this._ibusPropertiesRegistered.bind(this));
|
|
|
|
this._ibusManager.connect('property-updated', this._ibusPropertyUpdated.bind(this));
|
|
|
|
this._ibusManager.connect('set-content-type', this._ibusSetContentType.bind(this));
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
global.display.connect('modifiers-accelerator-activated', this._modifiersSwitcher.bind(this));
|
2013-03-28 21:35:32 -04:00
|
|
|
|
2013-01-08 20:01:33 -05:00
|
|
|
this._sourcesPerWindow = false;
|
|
|
|
this._focusWindowNotifyId = 0;
|
2017-12-01 19:27:35 -05:00
|
|
|
this._settings.connect('per-window-changed', this._sourcesPerWindowChanged.bind(this));
|
2013-01-08 20:01:33 -05:00
|
|
|
this._sourcesPerWindowChanged();
|
2014-11-27 03:23:01 -05:00
|
|
|
this._disableIBus = false;
|
2018-08-31 07:22:23 -04:00
|
|
|
this._reloading = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
reload() {
|
2018-08-31 07:22:23 -04:00
|
|
|
this._reloading = true;
|
2015-03-16 10:10:47 -04:00
|
|
|
this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions);
|
2014-05-29 12:42:46 -04:00
|
|
|
this._inputSourcesChanged();
|
2018-08-31 07:22:23 -04:00
|
|
|
this._reloading = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-22 18:27:06 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ibusReadyCallback(im, ready) {
|
2012-12-10 14:34:43 -05:00
|
|
|
if (this._ibusReady == ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._ibusReady = ready;
|
|
|
|
this._mruSources = [];
|
|
|
|
this._inputSourcesChanged();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 14:34:43 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_modifiersSwitcher() {
|
2013-03-28 21:35:32 -04:00
|
|
|
let sourceIndexes = Object.keys(this._inputSources);
|
|
|
|
if (sourceIndexes.length == 0) {
|
2014-02-14 10:11:28 -05:00
|
|
|
KeyboardManager.releaseKeyboard();
|
2013-03-28 21:35:32 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let is = this._currentSource;
|
|
|
|
if (!is)
|
|
|
|
is = this._inputSources[sourceIndexes[0]];
|
|
|
|
|
|
|
|
let nextIndex = is.index + 1;
|
|
|
|
if (nextIndex > sourceIndexes[sourceIndexes.length - 1])
|
|
|
|
nextIndex = 0;
|
|
|
|
|
|
|
|
while (!(is = this._inputSources[nextIndex]))
|
|
|
|
nextIndex += 1;
|
|
|
|
|
2016-05-25 14:54:33 -04:00
|
|
|
is.activate(true);
|
2013-03-28 21:35:32 -04:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-03-28 21:35:32 -04:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
_switchInputSource(display, window, binding) {
|
2013-03-02 10:51:00 -05:00
|
|
|
if (this._mruSources.length < 2)
|
|
|
|
return;
|
|
|
|
|
2013-03-29 18:19:02 -04:00
|
|
|
// HACK: Fall back on simple input source switching since we
|
|
|
|
// can't show a popup switcher while a GrabHelper grab is in
|
|
|
|
// effect without considerable work to consolidate the usage
|
|
|
|
// of pushModal/popModal and grabHelper. See
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=695143 .
|
2015-02-25 19:05:29 -05:00
|
|
|
if (Main.actionMode == Shell.ActionMode.POPUP) {
|
2013-03-29 18:19:02 -04:00
|
|
|
this._modifiersSwitcher();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-11 07:13:41 -05:00
|
|
|
this._switcherPopup = new InputSourcePopup(
|
|
|
|
this._mruSources, this._keybindingAction, this._keybindingActionBackward);
|
|
|
|
this._switcherPopup.connect('destroy', () => {
|
|
|
|
this._switcherPopup = null;
|
|
|
|
});
|
|
|
|
if (!this._switcherPopup.show(
|
|
|
|
binding.is_reversed(), binding.get_name(), binding.get_mask()))
|
|
|
|
this._switcherPopup.fadeAndDestroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 14:35:29 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_keyboardOptionsChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
this._keyboardManager.setKeyboardOptions(this._settings.keyboardOptions);
|
2014-06-05 12:47:48 -04:00
|
|
|
this._keyboardManager.reapply();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateMruSettings() {
|
2016-05-23 19:24:50 -04:00
|
|
|
// If IBus is not ready we don't have a full picture of all
|
|
|
|
// the available sources, so don't update the setting
|
|
|
|
if (!this._ibusReady)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If IBus is temporarily disabled, don't update the setting
|
|
|
|
if (this._disableIBus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let sourcesList = [];
|
|
|
|
for (let i = 0; i < this._mruSources.length; ++i) {
|
|
|
|
let source = this._mruSources[i];
|
|
|
|
sourcesList.push([source.type, source.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._settings.mruSources = sourcesList;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-23 19:24:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_currentInputSourceChanged(newSource) {
|
2013-02-07 03:27:55 -05:00
|
|
|
let oldSource;
|
|
|
|
[oldSource, this._currentSource] = [this._currentSource, newSource];
|
|
|
|
|
2014-05-30 09:29:03 -04:00
|
|
|
this.emit('current-source-changed', oldSource);
|
2012-12-13 14:48:13 -05:00
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
for (let i = 1; i < this._mruSources.length; ++i) {
|
2012-12-10 14:34:43 -05:00
|
|
|
if (this._mruSources[i] == newSource) {
|
|
|
|
let currentSource = this._mruSources.splice(i, 1);
|
|
|
|
this._mruSources = currentSource.concat(this._mruSources);
|
|
|
|
break;
|
|
|
|
}
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2013-01-08 20:01:33 -05:00
|
|
|
this._changePerWindowSource();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-05-15 13:31:02 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateInputSource(is, interactive) {
|
2018-08-31 07:22:23 -04:00
|
|
|
// The focus changes during holdKeyboard/releaseKeyboard may trick
|
|
|
|
// the client into hiding UI containing the currently focused entry.
|
|
|
|
// So holdKeyboard/releaseKeyboard are not called when
|
|
|
|
// 'set-content-type' signal is received.
|
|
|
|
// E.g. Focusing on a password entry in a popup in Xorg Firefox
|
|
|
|
// will emit 'set-content-type' signal.
|
|
|
|
// https://gitlab.gnome.org/GNOME/gnome-shell/issues/391
|
|
|
|
if (!this._reloading)
|
|
|
|
KeyboardManager.holdKeyboard();
|
2014-06-05 12:47:48 -04:00
|
|
|
this._keyboardManager.apply(is.xkbId);
|
|
|
|
|
|
|
|
// All the "xkb:..." IBus engines simply "echo" back symbols,
|
|
|
|
// despite their naming implying differently, so we always set
|
|
|
|
// one in order for XIM applications to work given that we set
|
|
|
|
// XMODIFIERS=@im=ibus in the first place so that they can
|
|
|
|
// work without restarting when/if the user adds an IBus input
|
|
|
|
// source.
|
|
|
|
let engine;
|
|
|
|
if (is.type == INPUT_SOURCE_TYPE_IBUS)
|
|
|
|
engine = is.id;
|
|
|
|
else
|
|
|
|
engine = 'xkb:us::eng';
|
|
|
|
|
2018-08-31 07:22:23 -04:00
|
|
|
if (!this._reloading)
|
|
|
|
this._ibusManager.setEngine(engine, KeyboardManager.releaseKeyboard);
|
|
|
|
else
|
|
|
|
this._ibusManager.setEngine(engine);
|
2014-06-05 12:47:48 -04:00
|
|
|
this._currentInputSourceChanged(is);
|
2016-05-23 19:24:50 -04:00
|
|
|
|
|
|
|
if (interactive)
|
|
|
|
this._updateMruSettings();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-05 12:47:48 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateMruSources() {
|
2016-05-25 14:28:57 -04:00
|
|
|
let sourcesList = [];
|
2022-09-14 14:20:14 -04:00
|
|
|
for (let i of Object.keys(this._inputSources).sort((a, b) => a - b))
|
2016-05-25 14:28:57 -04:00
|
|
|
sourcesList.push(this._inputSources[i]);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._keyboardManager.setUserLayouts(sourcesList.map(x => x.xkbId));
|
2016-05-25 14:28:57 -04:00
|
|
|
|
|
|
|
if (!this._disableIBus && this._mruSourcesBackup) {
|
|
|
|
this._mruSources = this._mruSourcesBackup;
|
|
|
|
this._mruSourcesBackup = null;
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:24:50 -04:00
|
|
|
// Initialize from settings when we have no MRU sources list
|
|
|
|
if (this._mruSources.length == 0) {
|
|
|
|
let mruSettings = this._settings.mruSources;
|
|
|
|
for (let i = 0; i < mruSettings.length; i++) {
|
|
|
|
let mruSettingSource = mruSettings[i];
|
|
|
|
let mruSource = null;
|
|
|
|
|
|
|
|
for (let j = 0; j < sourcesList.length; j++) {
|
|
|
|
let source = sourcesList[j];
|
|
|
|
if (source.type == mruSettingSource.type &&
|
|
|
|
source.id == mruSettingSource.id) {
|
|
|
|
mruSource = source;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mruSource)
|
|
|
|
this._mruSources.push(mruSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 14:28:57 -04:00
|
|
|
let mruSources = [];
|
status: Ignore prior single-element lists updating input sources MRU
Consider the existing input sources MRU only valid if it contained
more than one element to pick from. Fixes the following situation
with initial-setup sessions:
- Initial setup Session starts, with several input sources already
configured ("us" between them)
- InputSourceManager initializes, only the default "us" keymap is
available
- MRU list is constructed, "us" is picked
- InputSourceManager catches up with session configuration, the
other extra sources are added
- MRU list is reconstructed, "us" is already the most recent
- Session ends up with "us" picked, regardless of its position in
the list, and no MRU existing prior to startup
If we consider the intermediate single-element MRU list invalid,
it is still possible to pick the best default source between all
the configured ones (the one that was put first in the list,
basically), after initialization is complete.
But also, it is unnecessary to have if there is a single source to
pick from. After the sources list has two elements or more, the
MRU list will become effective and preserved during changes to
the available sources.
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5873
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2495>
2022-09-19 16:35:15 -04:00
|
|
|
if (this._mruSources.length > 1) {
|
|
|
|
for (let i = 0; i < this._mruSources.length; i++) {
|
|
|
|
for (let j = 0; j < sourcesList.length; j++) {
|
|
|
|
if (this._mruSources[i].type === sourcesList[j].type &&
|
|
|
|
this._mruSources[i].id === sourcesList[j].id) {
|
|
|
|
mruSources = mruSources.concat(sourcesList.splice(j, 1));
|
|
|
|
break;
|
|
|
|
}
|
2016-05-25 14:28:57 -04:00
|
|
|
}
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2016-05-25 14:28:57 -04:00
|
|
|
}
|
status: Ignore prior single-element lists updating input sources MRU
Consider the existing input sources MRU only valid if it contained
more than one element to pick from. Fixes the following situation
with initial-setup sessions:
- Initial setup Session starts, with several input sources already
configured ("us" between them)
- InputSourceManager initializes, only the default "us" keymap is
available
- MRU list is constructed, "us" is picked
- InputSourceManager catches up with session configuration, the
other extra sources are added
- MRU list is reconstructed, "us" is already the most recent
- Session ends up with "us" picked, regardless of its position in
the list, and no MRU existing prior to startup
If we consider the intermediate single-element MRU list invalid,
it is still possible to pick the best default source between all
the configured ones (the one that was put first in the list,
basically), after initialization is complete.
But also, it is unnecessary to have if there is a single source to
pick from. After the sources list has two elements or more, the
MRU list will become effective and preserved during changes to
the available sources.
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5873
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2495>
2022-09-19 16:35:15 -04:00
|
|
|
|
2016-05-25 14:28:57 -04:00
|
|
|
this._mruSources = mruSources.concat(sourcesList);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-05-25 14:28:57 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_inputSourcesChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
let sources = this._settings.inputSources;
|
|
|
|
let nSources = sources.length;
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2017-10-28 03:23:02 -04:00
|
|
|
this._currentSource = null;
|
2012-12-13 10:31:03 -05:00
|
|
|
this._inputSources = {};
|
2012-12-13 14:48:13 -05:00
|
|
|
this._ibusSources = {};
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2014-10-10 09:54:30 -04:00
|
|
|
let infosList = [];
|
2012-04-18 22:01:29 -04:00
|
|
|
for (let i = 0; i < nSources; i++) {
|
2012-12-13 10:31:03 -05:00
|
|
|
let displayName;
|
|
|
|
let shortName;
|
2015-03-16 10:10:47 -04:00
|
|
|
let type = sources[i].type;
|
|
|
|
let id = sources[i].id;
|
2012-12-13 10:31:03 -05:00
|
|
|
let exists = false;
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2012-05-29 13:30:14 -04:00
|
|
|
if (type == INPUT_SOURCE_TYPE_XKB) {
|
2019-01-29 14:20:09 -05:00
|
|
|
[exists, displayName, shortName] =
|
2012-05-29 13:30:14 -04:00
|
|
|
this._xkbInfo.get_layout_info(id);
|
|
|
|
} else if (type == INPUT_SOURCE_TYPE_IBUS) {
|
2014-11-27 03:23:01 -05:00
|
|
|
if (this._disableIBus)
|
|
|
|
continue;
|
2012-05-29 13:30:14 -04:00
|
|
|
let engineDesc = this._ibusManager.getEngineDesc(id);
|
|
|
|
if (engineDesc) {
|
2012-08-31 12:14:48 -04:00
|
|
|
let language = IBus.get_language_name(engineDesc.get_language());
|
2013-03-11 23:06:32 -04:00
|
|
|
let longName = engineDesc.get_longname();
|
|
|
|
let textdomain = engineDesc.get_textdomain();
|
|
|
|
if (textdomain != '')
|
|
|
|
longName = Gettext.dgettext(textdomain, longName);
|
2012-12-13 10:31:03 -05:00
|
|
|
exists = true;
|
2022-02-07 09:14:06 -05:00
|
|
|
displayName = `${language} (${longName})`;
|
2012-12-13 10:31:03 -05:00
|
|
|
shortName = this._makeEngineShortName(engineDesc);
|
2012-05-29 13:30:14 -04:00
|
|
|
}
|
|
|
|
}
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2014-10-10 09:54:30 -04:00
|
|
|
if (exists)
|
2019-08-19 15:06:04 -04:00
|
|
|
infosList.push({ type, id, displayName, shortName });
|
2014-10-10 09:54:30 -04:00
|
|
|
}
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2014-10-10 09:54:30 -04:00
|
|
|
if (infosList.length == 0) {
|
|
|
|
let type = INPUT_SOURCE_TYPE_XKB;
|
|
|
|
let id = KeyboardManager.DEFAULT_LAYOUT;
|
2019-01-28 20:27:05 -05:00
|
|
|
let [, displayName, shortName] = this._xkbInfo.get_layout_info(id);
|
2019-08-19 15:06:04 -04:00
|
|
|
infosList.push({ type, id, displayName, shortName });
|
2014-10-10 09:54:30 -04:00
|
|
|
}
|
2012-04-18 22:01:29 -04:00
|
|
|
|
2014-10-10 09:54:30 -04:00
|
|
|
let inputSourcesByShortName = {};
|
|
|
|
for (let i = 0; i < infosList.length; i++) {
|
|
|
|
let is = new InputSource(infosList[i].type,
|
|
|
|
infosList[i].id,
|
|
|
|
infosList[i].displayName,
|
|
|
|
infosList[i].shortName,
|
|
|
|
i);
|
2017-12-01 19:27:35 -05:00
|
|
|
is.connect('activate', this.activateInputSource.bind(this));
|
2012-12-13 10:31:03 -05:00
|
|
|
|
|
|
|
if (!(is.shortName in inputSourcesByShortName))
|
|
|
|
inputSourcesByShortName[is.shortName] = [];
|
|
|
|
inputSourcesByShortName[is.shortName].push(is);
|
|
|
|
|
|
|
|
this._inputSources[is.index] = is;
|
2012-12-13 14:48:13 -05:00
|
|
|
|
|
|
|
if (is.type == INPUT_SOURCE_TYPE_IBUS)
|
|
|
|
this._ibusSources[is.id] = is;
|
2011-01-04 17:04:56 -05:00
|
|
|
}
|
|
|
|
|
2012-12-13 10:31:03 -05:00
|
|
|
for (let i in this._inputSources) {
|
|
|
|
let is = this._inputSources[i];
|
|
|
|
if (inputSourcesByShortName[is.shortName].length > 1) {
|
|
|
|
let sub = inputSourcesByShortName[is.shortName].indexOf(is) + 1;
|
|
|
|
is.shortName += String.fromCharCode(0x2080 + sub);
|
2012-04-18 22:01:29 -04:00
|
|
|
}
|
2011-01-04 17:04:56 -05:00
|
|
|
}
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
this.emit('sources-changed');
|
|
|
|
|
2016-05-25 14:28:57 -04:00
|
|
|
this._updateMruSources();
|
2012-12-10 14:34:43 -05:00
|
|
|
|
2015-03-28 14:09:34 -04:00
|
|
|
if (this._mruSources.length > 0)
|
2016-05-25 14:54:33 -04:00
|
|
|
this._mruSources[0].activate(false);
|
2014-11-10 05:09:08 -05:00
|
|
|
|
|
|
|
// All ibus engines are preloaded here to reduce the launching time
|
|
|
|
// when users switch the input sources.
|
|
|
|
this._ibusManager.preloadEngines(Object.keys(this._ibusSources));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-04 17:04:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_makeEngineShortName(engineDesc) {
|
2012-09-09 16:44:25 -04:00
|
|
|
let symbol = engineDesc.get_symbol();
|
|
|
|
if (symbol && symbol[0])
|
|
|
|
return symbol;
|
|
|
|
|
|
|
|
let langCode = engineDesc.get_language().split('_', 1)[0];
|
|
|
|
if (langCode.length == 2 || langCode.length == 3)
|
|
|
|
return langCode.toLowerCase();
|
|
|
|
|
|
|
|
return String.fromCharCode(0x2328); // keyboard glyph
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-09 16:44:25 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ibusPropertiesRegistered(im, engineName, props) {
|
2012-12-13 14:48:13 -05:00
|
|
|
let source = this._ibusSources[engineName];
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source.properties = props;
|
|
|
|
|
|
|
|
if (source == this._currentSource)
|
2014-06-05 12:47:48 -04:00
|
|
|
this.emit('current-source-changed', null);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ibusPropertyUpdated(im, engineName, prop) {
|
2012-12-13 14:48:13 -05:00
|
|
|
let source = this._ibusSources[engineName];
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._updateSubProperty(source.properties, prop) &&
|
|
|
|
source == this._currentSource)
|
2014-06-05 12:47:48 -04:00
|
|
|
this.emit('current-source-changed', null);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSubProperty(props, prop) {
|
2012-09-01 17:57:53 -04:00
|
|
|
if (!props)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let p;
|
|
|
|
for (let i = 0; (p = props.get(i)) != null; ++i) {
|
|
|
|
if (p.get_key() == prop.get_key() && p.get_prop_type() == prop.get_prop_type()) {
|
|
|
|
p.update(prop);
|
|
|
|
return true;
|
|
|
|
} else if (p.get_prop_type() == IBus.PropType.MENU) {
|
|
|
|
if (this._updateSubProperty(p.get_sub_props(), prop))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
_ibusSetContentType(im, purpose, _hints) {
|
2022-11-11 07:13:41 -05:00
|
|
|
// Avoid purpose changes while the switcher popup is shown, likely due to
|
|
|
|
// the focus change caused by the switcher popup causing this purpose change.
|
|
|
|
if (this._switcherPopup)
|
|
|
|
return;
|
2014-11-27 03:23:01 -05:00
|
|
|
if (purpose == IBus.InputPurpose.PASSWORD) {
|
|
|
|
if (Object.keys(this._inputSources).length == Object.keys(this._ibusSources).length)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._disableIBus)
|
|
|
|
return;
|
|
|
|
this._disableIBus = true;
|
2015-03-28 14:09:34 -04:00
|
|
|
this._mruSourcesBackup = this._mruSources.slice();
|
2014-11-27 03:23:01 -05:00
|
|
|
} else {
|
|
|
|
if (!this._disableIBus)
|
|
|
|
return;
|
|
|
|
this._disableIBus = false;
|
|
|
|
}
|
|
|
|
this.reload();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-11-27 03:23:01 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getNewInputSource(current) {
|
2015-03-11 10:48:03 -04:00
|
|
|
let sourceIndexes = Object.keys(this._inputSources);
|
|
|
|
if (sourceIndexes.length == 0)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (current) {
|
|
|
|
for (let i in this._inputSources) {
|
|
|
|
let is = this._inputSources[i];
|
|
|
|
if (is.type == current.type &&
|
|
|
|
is.id == current.id)
|
|
|
|
return is;
|
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
}
|
2015-03-11 10:48:03 -04:00
|
|
|
|
|
|
|
return this._inputSources[sourceIndexes[0]];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getCurrentWindow() {
|
2014-05-29 12:42:46 -04:00
|
|
|
if (Main.overview.visible)
|
|
|
|
return Main.overview;
|
|
|
|
else
|
|
|
|
return global.display.focus_window;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setPerWindowInputSource() {
|
2014-05-29 12:42:46 -04:00
|
|
|
let window = this._getCurrentWindow();
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2020-02-20 10:03:54 -05:00
|
|
|
if (!window._inputSources ||
|
|
|
|
window._inputSources !== this._inputSources) {
|
2014-05-29 12:42:46 -04:00
|
|
|
window._inputSources = this._inputSources;
|
|
|
|
window._currentSource = this._getNewInputSource(window._currentSource);
|
|
|
|
}
|
2015-03-11 10:48:03 -04:00
|
|
|
|
|
|
|
if (window._currentSource)
|
2016-05-25 14:54:33 -04:00
|
|
|
window._currentSource.activate(false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sourcesPerWindowChanged() {
|
2015-03-16 10:10:47 -04:00
|
|
|
this._sourcesPerWindow = this._settings.perWindow;
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
if (this._sourcesPerWindow && this._focusWindowNotifyId == 0) {
|
|
|
|
this._focusWindowNotifyId = global.display.connect('notify::focus-window',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._setPerWindowInputSource.bind(this));
|
2021-08-15 18:36:59 -04:00
|
|
|
Main.overview.connectObject(
|
|
|
|
'showing', this._setPerWindowInputSource.bind(this),
|
|
|
|
'hidden', this._setPerWindowInputSource.bind(this), this);
|
2014-05-29 12:42:46 -04:00
|
|
|
} else if (!this._sourcesPerWindow && this._focusWindowNotifyId != 0) {
|
|
|
|
global.display.disconnect(this._focusWindowNotifyId);
|
|
|
|
this._focusWindowNotifyId = 0;
|
2021-08-15 18:36:59 -04:00
|
|
|
Main.overview.disconnectObject(this);
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let windows = global.get_window_actors().map(w => w.meta_window);
|
2014-05-29 12:42:46 -04:00
|
|
|
for (let i = 0; i < windows.length; ++i) {
|
|
|
|
delete windows[i]._inputSources;
|
|
|
|
delete windows[i]._currentSource;
|
|
|
|
}
|
|
|
|
delete Main.overview._inputSources;
|
|
|
|
delete Main.overview._currentSource;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_changePerWindowSource() {
|
2014-05-29 12:42:46 -04:00
|
|
|
if (!this._sourcesPerWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let window = this._getCurrentWindow();
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window._inputSources = this._inputSources;
|
|
|
|
window._currentSource = this._currentSource;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
get currentSource() {
|
|
|
|
return this._currentSource;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
get inputSources() {
|
|
|
|
return this._inputSources;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2021-03-15 02:50:31 -04:00
|
|
|
|
|
|
|
get keyboardManager() {
|
|
|
|
return this._keyboardManager;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
let _inputSourceManager = null;
|
|
|
|
|
|
|
|
function getInputSourceManager() {
|
|
|
|
if (_inputSourceManager == null)
|
|
|
|
_inputSourceManager = new InputSourceManager();
|
|
|
|
return _inputSourceManager;
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var InputSourceIndicatorContainer = GObject.registerClass(
|
|
|
|
class InputSourceIndicatorContainer extends St.Widget {
|
2018-07-12 08:36:46 -04:00
|
|
|
vfunc_get_preferred_width(forHeight) {
|
|
|
|
// Here, and in vfunc_get_preferred_height, we need to query
|
|
|
|
// for the height of all children, but we ignore the results
|
|
|
|
// for those we don't actually display.
|
|
|
|
return this.get_children().reduce((maxWidth, child) => {
|
|
|
|
let width = child.get_preferred_width(forHeight);
|
2020-03-27 09:18:34 -04:00
|
|
|
return [
|
|
|
|
Math.max(maxWidth[0], width[0]),
|
|
|
|
Math.max(maxWidth[1], width[1]),
|
|
|
|
];
|
2018-07-12 08:36:46 -04:00
|
|
|
}, [0, 0]);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2018-07-12 08:36:46 -04:00
|
|
|
|
|
|
|
vfunc_get_preferred_height(forWidth) {
|
|
|
|
return this.get_children().reduce((maxHeight, child) => {
|
|
|
|
let height = child.get_preferred_height(forWidth);
|
2020-03-27 09:18:34 -04:00
|
|
|
return [
|
|
|
|
Math.max(maxHeight[0], height[0]),
|
|
|
|
Math.max(maxHeight[1], height[1]),
|
|
|
|
];
|
2018-07-12 08:36:46 -04:00
|
|
|
}, [0, 0]);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2018-07-12 08:36:46 -04:00
|
|
|
|
2020-05-09 15:30:26 -04:00
|
|
|
vfunc_allocate(box) {
|
|
|
|
this.set_allocation(box);
|
2018-07-12 08:36:46 -04:00
|
|
|
|
|
|
|
// translate box to (0, 0)
|
|
|
|
box.x2 -= box.x1;
|
|
|
|
box.x1 = 0;
|
|
|
|
box.y2 -= box.y1;
|
|
|
|
box.y1 = 0;
|
|
|
|
|
|
|
|
this.get_children().forEach(c => {
|
2020-05-09 15:30:26 -04:00
|
|
|
c.allocate_align_fill(box, 0.5, 0.5, false, false);
|
2018-07-12 08:36:46 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var InputSourceIndicator = GObject.registerClass(
|
|
|
|
class InputSourceIndicator extends PanelMenu.Button {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2019-06-14 14:58:50 -04:00
|
|
|
super._init(0.5, _("Keyboard"));
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2019-01-18 08:23:36 -05:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
|
2014-05-30 09:29:03 -04:00
|
|
|
this._menuItems = {};
|
|
|
|
this._indicatorLabels = {};
|
|
|
|
|
2021-02-01 19:51:15 -05:00
|
|
|
this._container = new InputSourceIndicatorContainer({ style_class: 'system-status-icon' });
|
2021-01-24 15:39:43 -05:00
|
|
|
this.add_child(this._container);
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
this._propSeparator = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
this.menu.addMenuItem(this._propSeparator);
|
|
|
|
this._propSection = new PopupMenu.PopupMenuSection();
|
|
|
|
this.menu.addMenuItem(this._propSection);
|
|
|
|
this._propSection.actor.hide();
|
|
|
|
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2017-12-01 19:27:35 -05:00
|
|
|
this._showLayoutItem = this.menu.addAction(_("Show Keyboard Layout"), this._showLayout.bind(this));
|
2023-01-11 20:38:07 -05:00
|
|
|
this.menu.addSettingsAction(_('Keyboard Settings'),
|
|
|
|
'gnome-keyboard-panel.desktop');
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2014-05-29 12:42:46 -04:00
|
|
|
this._sessionUpdated();
|
|
|
|
|
|
|
|
this._inputSourceManager = getInputSourceManager();
|
2021-08-15 18:36:59 -04:00
|
|
|
this._inputSourceManager.connectObject(
|
|
|
|
'sources-changed', this._sourcesChanged.bind(this),
|
|
|
|
'current-source-changed', this._currentSourceChanged.bind(this), this);
|
2014-05-29 12:42:46 -04:00
|
|
|
this._inputSourceManager.reload();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2019-01-18 08:23:36 -05:00
|
|
|
_onDestroy() {
|
2021-08-15 18:36:59 -04:00
|
|
|
this._inputSourceManager = null;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2019-01-18 08:23:36 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2014-05-29 12:42:46 -04:00
|
|
|
// re-using "allowSettings" for the keyboard layout is a bit shady,
|
|
|
|
// but at least for now it is used as "allow popping up windows
|
|
|
|
// from shell menus"; we can always add a separate sessionMode
|
|
|
|
// option if need arises.
|
2019-04-12 17:00:49 -04:00
|
|
|
this._showLayoutItem.visible = Main.sessionMode.allowSettings;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sourcesChanged() {
|
2014-05-30 09:29:03 -04:00
|
|
|
for (let i in this._menuItems)
|
|
|
|
this._menuItems[i].destroy();
|
|
|
|
for (let i in this._indicatorLabels)
|
|
|
|
this._indicatorLabels[i].destroy();
|
|
|
|
|
2017-10-28 03:23:02 -04:00
|
|
|
this._menuItems = {};
|
|
|
|
this._indicatorLabels = {};
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
let menuIndex = 0;
|
|
|
|
for (let i in this._inputSourceManager.inputSources) {
|
|
|
|
let is = this._inputSourceManager.inputSources[i];
|
2014-05-30 09:29:03 -04:00
|
|
|
|
|
|
|
let menuItem = new LayoutMenuItem(is.displayName, is.shortName);
|
2019-01-27 19:42:00 -05:00
|
|
|
menuItem.connect('activate', () => is.activate(true));
|
2016-05-25 14:54:33 -04:00
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
const indicatorLabel = new St.Label({
|
|
|
|
text: is.shortName,
|
|
|
|
visible: false,
|
|
|
|
});
|
2014-05-30 09:29:03 -04:00
|
|
|
|
|
|
|
this._menuItems[i] = menuItem;
|
|
|
|
this._indicatorLabels[i] = indicatorLabel;
|
2017-10-30 20:38:18 -04:00
|
|
|
is.connect('changed', () => {
|
2014-05-30 09:29:03 -04:00
|
|
|
menuItem.indicator.set_text(is.shortName);
|
2017-08-10 15:03:37 -04:00
|
|
|
indicatorLabel.set_text(is.shortName);
|
2014-05-30 09:29:03 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this.menu.addMenuItem(menuItem, menuIndex++);
|
|
|
|
this._container.add_actor(indicatorLabel);
|
2014-05-29 12:42:46 -04:00
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_currentSourceChanged(manager, oldSource) {
|
2014-05-29 12:42:46 -04:00
|
|
|
let nVisibleSources = Object.keys(this._inputSourceManager.inputSources).length;
|
|
|
|
let newSource = this._inputSourceManager.currentSource;
|
|
|
|
|
2014-05-30 09:29:03 -04:00
|
|
|
if (oldSource) {
|
|
|
|
this._menuItems[oldSource.index].setOrnament(PopupMenu.Ornament.NONE);
|
|
|
|
this._indicatorLabels[oldSource.index].hide();
|
|
|
|
}
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
if (!newSource || (nVisibleSources < 2 && !newSource.properties)) {
|
|
|
|
// This source index might be invalid if we weren't able
|
|
|
|
// to build a menu item for it, so we hide ourselves since
|
|
|
|
// we can't fix it here. *shrug*
|
|
|
|
|
|
|
|
// We also hide if we have only one visible source unless
|
|
|
|
// it's an IBus source with properties.
|
|
|
|
this.menu.close();
|
2019-04-09 19:17:51 -04:00
|
|
|
this.hide();
|
2014-05-29 12:42:46 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 19:17:51 -04:00
|
|
|
this.show();
|
2014-05-29 12:42:46 -04:00
|
|
|
|
|
|
|
this._buildPropSection(newSource.properties);
|
2014-05-30 09:29:03 -04:00
|
|
|
|
|
|
|
this._menuItems[newSource.index].setOrnament(PopupMenu.Ornament.DOT);
|
|
|
|
this._indicatorLabels[newSource.index].show();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-05-29 12:42:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_buildPropSection(properties) {
|
2019-07-16 05:24:13 -04:00
|
|
|
this._propSeparator.hide();
|
2012-09-01 17:57:53 -04:00
|
|
|
this._propSection.actor.hide();
|
|
|
|
this._propSection.removeAll();
|
|
|
|
|
2012-12-13 14:48:13 -05:00
|
|
|
this._buildPropSubMenu(this._propSection, properties);
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2012-09-18 06:17:58 -04:00
|
|
|
if (!this._propSection.isEmpty()) {
|
2012-09-01 17:57:53 -04:00
|
|
|
this._propSection.actor.show();
|
2019-07-16 05:24:13 -04:00
|
|
|
this._propSeparator.show();
|
2012-09-18 06:17:58 -04:00
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_buildPropSubMenu(menu, props) {
|
2012-09-01 17:57:53 -04:00
|
|
|
if (!props)
|
|
|
|
return;
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
let ibusManager = IBusManager.getIBusManager();
|
2012-09-01 17:57:53 -04:00
|
|
|
let radioGroup = [];
|
|
|
|
let p;
|
|
|
|
for (let i = 0; (p = props.get(i)) != null; ++i) {
|
|
|
|
let prop = p;
|
|
|
|
|
2012-11-24 10:38:21 -05:00
|
|
|
if (!prop.get_visible())
|
2012-09-01 17:57:53 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (prop.get_key() == 'InputMode') {
|
|
|
|
let text;
|
|
|
|
if (prop.get_symbol)
|
|
|
|
text = prop.get_symbol().get_text();
|
|
|
|
else
|
|
|
|
text = prop.get_label().get_text();
|
|
|
|
|
2014-05-30 09:29:03 -04:00
|
|
|
let currentSource = this._inputSourceManager.currentSource;
|
|
|
|
if (currentSource) {
|
|
|
|
let indicatorLabel = this._indicatorLabels[currentSource.index];
|
|
|
|
if (text && text.length > 0 && text.length < 3)
|
|
|
|
indicatorLabel.set_text(text);
|
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let item;
|
2019-01-29 16:58:40 -05:00
|
|
|
let type = prop.get_prop_type();
|
|
|
|
switch (type) {
|
2012-11-24 09:56:06 -05:00
|
|
|
case IBus.PropType.MENU:
|
2012-09-01 17:57:53 -04:00
|
|
|
item = new PopupMenu.PopupSubMenuMenuItem(prop.get_label().get_text());
|
|
|
|
this._buildPropSubMenu(item.menu, prop.get_sub_props());
|
2012-11-24 09:56:06 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.RADIO:
|
2012-09-01 17:57:53 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(prop.get_label().get_text());
|
|
|
|
item.prop = prop;
|
|
|
|
radioGroup.push(item);
|
|
|
|
item.radioGroup = radioGroup;
|
2019-08-19 15:33:15 -04:00
|
|
|
item.setOrnament(prop.get_state() == IBus.PropState.CHECKED
|
|
|
|
? PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE);
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2012-09-01 17:57:53 -04:00
|
|
|
if (item.prop.get_state() == IBus.PropState.CHECKED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let group = item.radioGroup;
|
2019-08-19 20:20:08 -04:00
|
|
|
for (let j = 0; j < group.length; ++j) {
|
|
|
|
if (group[j] == item) {
|
2013-04-19 20:57:38 -04:00
|
|
|
item.setOrnament(PopupMenu.Ornament.DOT);
|
2012-09-01 17:57:53 -04:00
|
|
|
item.prop.set_state(IBus.PropState.CHECKED);
|
2014-05-29 12:42:46 -04:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.CHECKED);
|
2012-09-01 17:57:53 -04:00
|
|
|
} else {
|
2019-08-19 20:20:08 -04:00
|
|
|
group[j].setOrnament(PopupMenu.Ornament.NONE);
|
|
|
|
group[j].prop.set_state(IBus.PropState.UNCHECKED);
|
|
|
|
ibusManager.activateProperty(group[j].prop.get_key(),
|
2014-05-29 12:42:46 -04:00
|
|
|
IBus.PropState.UNCHECKED);
|
2012-09-01 17:57:53 -04:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2012-11-24 09:56:06 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.TOGGLE:
|
|
|
|
item = new PopupMenu.PopupSwitchMenuItem(prop.get_label().get_text(), prop.get_state() == IBus.PropState.CHECKED);
|
|
|
|
item.prop = prop;
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('toggled', () => {
|
2012-11-24 09:56:06 -05:00
|
|
|
if (item.state) {
|
|
|
|
item.prop.set_state(IBus.PropState.CHECKED);
|
2014-05-29 12:42:46 -04:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.CHECKED);
|
2012-11-24 09:56:06 -05:00
|
|
|
} else {
|
|
|
|
item.prop.set_state(IBus.PropState.UNCHECKED);
|
2014-05-29 12:42:46 -04:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.UNCHECKED);
|
2012-11-24 09:56:06 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2012-11-24 09:56:06 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.NORMAL:
|
|
|
|
item = new PopupMenu.PopupMenuItem(prop.get_label().get_text());
|
|
|
|
item.prop = prop;
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2014-05-29 12:42:46 -04:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
item.prop.get_state());
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2012-11-24 09:56:06 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.SEPARATOR:
|
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-07 09:14:06 -05:00
|
|
|
log(`IBus property ${prop.get_key()} has invalid type ${type}`);
|
2012-09-01 17:57:53 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.setSensitive(prop.get_sensitive());
|
|
|
|
menu.addMenuItem(item);
|
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-09-01 17:57:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_showLayout() {
|
2014-05-29 12:42:46 -04:00
|
|
|
Main.overview.hide();
|
2013-01-08 20:01:33 -05:00
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
let source = this._inputSourceManager.currentSource;
|
|
|
|
let xkbLayout = '';
|
|
|
|
let xkbVariant = '';
|
2013-01-08 20:01:33 -05:00
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
if (source.type == INPUT_SOURCE_TYPE_XKB) {
|
|
|
|
[, , , xkbLayout, xkbVariant] = KeyboardManager.getXkbInfo().get_layout_info(source.id);
|
|
|
|
} else if (source.type == INPUT_SOURCE_TYPE_IBUS) {
|
|
|
|
let engineDesc = IBusManager.getIBusManager().getEngineDesc(source.id);
|
|
|
|
if (engineDesc) {
|
|
|
|
xkbLayout = engineDesc.get_layout();
|
2014-08-19 13:16:08 -04:00
|
|
|
xkbVariant = engineDesc.get_layout_variant();
|
2013-01-08 20:01:33 -05:00
|
|
|
}
|
2021-03-15 02:50:31 -04:00
|
|
|
|
|
|
|
// The `default` layout from ibus engine means to
|
|
|
|
// use the current keyboard layout.
|
|
|
|
if (xkbLayout === 'default') {
|
|
|
|
const current = this._inputSourceManager.keyboardManager.currentLayout;
|
|
|
|
xkbLayout = current.layout;
|
|
|
|
xkbVariant = current.variant;
|
|
|
|
}
|
2013-01-08 20:01:33 -05:00
|
|
|
}
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
if (!xkbLayout || xkbLayout.length == 0)
|
2013-01-08 20:01:33 -05:00
|
|
|
return;
|
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
let description = xkbLayout;
|
|
|
|
if (xkbVariant.length > 0)
|
2022-02-07 09:14:06 -05:00
|
|
|
description = `${description}\t${xkbVariant}`;
|
2013-01-08 20:01:33 -05:00
|
|
|
|
2014-05-29 12:42:46 -04:00
|
|
|
Util.spawn(['gkbd-keyboard-display', '-l', description]);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|