2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-12-10 19:35:29 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2011-01-04 22:04:56 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
2012-12-10 19:35:29 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-01-04 22:04:56 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2012-09-01 21:57:53 +00:00
|
|
|
const Signals = imports.signals;
|
2011-01-04 22:04:56 +00:00
|
|
|
const St = imports.gi.St;
|
2013-03-12 03:06:32 +00:00
|
|
|
const Gettext = imports.gettext;
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2014-02-14 15:11:28 +00:00
|
|
|
const IBus = imports.misc.ibusManager.IBus;
|
|
|
|
const IBusManager = imports.misc.ibusManager;
|
|
|
|
const KeyboardManager = imports.misc.keyboardManager;
|
2011-06-21 22:26:57 +00:00
|
|
|
const Main = imports.ui.main;
|
2011-01-04 22:04:56 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2012-12-10 19:35:29 +00:00
|
|
|
const SwitcherPopup = imports.ui.switcherPopup;
|
2011-02-05 18:30:16 +00:00
|
|
|
const Util = imports.misc.util;
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-04-19 02:01:29 +00:00
|
|
|
const DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
|
|
|
|
const KEY_INPUT_SOURCES = 'sources';
|
2014-06-05 16:47:48 +00:00
|
|
|
const KEY_KEYBOARD_OPTIONS = 'xkb-options';
|
2012-04-19 02:01:29 +00:00
|
|
|
|
|
|
|
const INPUT_SOURCE_TYPE_XKB = 'xkb';
|
2012-05-29 17:30:14 +00:00
|
|
|
const INPUT_SOURCE_TYPE_IBUS = 'ibus';
|
|
|
|
|
2011-11-20 13:10:48 +00:00
|
|
|
const LayoutMenuItem = new Lang.Class({
|
|
|
|
Name: 'LayoutMenuItem',
|
|
|
|
Extends: PopupMenu.PopupBaseMenuItem,
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-04-19 02:01:29 +00:00
|
|
|
_init: function(displayName, shortName) {
|
2011-11-20 13:10:48 +00:00
|
|
|
this.parent();
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-04-19 02:01:29 +00:00
|
|
|
this.label = new St.Label({ text: displayName });
|
|
|
|
this.indicator = new St.Label({ text: shortName });
|
2013-07-16 00:00:41 +00:00
|
|
|
this.actor.add(this.label, { expand: true });
|
|
|
|
this.actor.add(this.indicator);
|
2012-09-20 13:02:49 +00:00
|
|
|
this.actor.label_actor = this.label;
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
2011-11-20 13:10:48 +00:00
|
|
|
});
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-12-13 15:31:03 +00:00
|
|
|
const InputSource = new Lang.Class({
|
|
|
|
Name: 'InputSource',
|
|
|
|
|
|
|
|
_init: function(type, id, displayName, shortName, index) {
|
|
|
|
this.type = type;
|
|
|
|
this.id = id;
|
|
|
|
this.displayName = displayName;
|
|
|
|
this._shortName = shortName;
|
|
|
|
this.index = index;
|
|
|
|
|
2012-12-13 19:48:13 +00:00
|
|
|
this.properties = null;
|
2014-06-05 16:47:48 +00:00
|
|
|
|
|
|
|
this.xkbId = this._getXkbId();
|
2012-12-13 15:31:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get shortName() {
|
|
|
|
return this._shortName;
|
|
|
|
},
|
|
|
|
|
|
|
|
set shortName(v) {
|
|
|
|
this._shortName = v;
|
2014-05-30 13:29:03 +00:00
|
|
|
this.emit('changed');
|
2012-12-13 15:31:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
this.emit('activate');
|
|
|
|
},
|
2014-06-05 16:47:48 +00:00
|
|
|
|
|
|
|
_getXkbId: function() {
|
|
|
|
let engineDesc = IBusManager.getIBusManager().getEngineDesc(this.id);
|
|
|
|
if (!engineDesc)
|
|
|
|
return this.id;
|
|
|
|
|
|
|
|
if (engineDesc.variant && engineDesc.variant.length > 0)
|
|
|
|
return engineDesc.layout + '+' + engineDesc.variant;
|
|
|
|
else
|
|
|
|
return engineDesc.layout;
|
|
|
|
}
|
2012-12-13 15:31:03 +00:00
|
|
|
});
|
|
|
|
Signals.addSignalMethods(InputSource.prototype);
|
|
|
|
|
2012-12-10 19:35:29 +00:00
|
|
|
const InputSourcePopup = new Lang.Class({
|
|
|
|
Name: 'InputSourcePopup',
|
|
|
|
Extends: SwitcherPopup.SwitcherPopup,
|
|
|
|
|
|
|
|
_init: function(items, action, actionBackward) {
|
|
|
|
this.parent(items);
|
|
|
|
|
|
|
|
this._action = action;
|
|
|
|
this._actionBackward = actionBackward;
|
|
|
|
|
|
|
|
this._switcherList = new InputSourceSwitcher(this._items);
|
|
|
|
},
|
|
|
|
|
2014-08-12 15:55:22 +00:00
|
|
|
_keyPressHandler: function(keysym, action) {
|
2012-12-10 19:35:29 +00:00
|
|
|
if (action == this._action)
|
2014-08-12 15:55:22 +00:00
|
|
|
this._select(this._next());
|
2012-12-10 19:35:29 +00:00
|
|
|
else if (action == this._actionBackward)
|
2014-08-12 15:55:22 +00:00
|
|
|
this._select(this._previous());
|
2012-12-10 19:35:29 +00:00
|
|
|
else if (keysym == Clutter.Left)
|
|
|
|
this._select(this._previous());
|
|
|
|
else if (keysym == Clutter.Right)
|
|
|
|
this._select(this._next());
|
2014-05-26 13:27:16 +00:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2012-12-10 19:35:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_finish : function() {
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
this._items[this._selectedIndex].activate();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const InputSourceSwitcher = new Lang.Class({
|
|
|
|
Name: 'InputSourceSwitcher',
|
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
|
|
|
|
|
|
|
_init: function(items) {
|
|
|
|
this.parent(true);
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
this._addIcon(items[i]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_addIcon: function(item) {
|
|
|
|
let box = new St.BoxLayout({ vertical: true });
|
|
|
|
|
|
|
|
let bin = new St.Bin({ style_class: 'input-source-switcher-symbol' });
|
|
|
|
let symbol = new St.Label({ text: item.shortName });
|
|
|
|
bin.set_child(symbol);
|
|
|
|
box.add(bin, { x_fill: false, y_fill: false } );
|
|
|
|
|
|
|
|
let text = new St.Label({ text: item.displayName });
|
|
|
|
box.add(text, { x_fill: false });
|
|
|
|
|
|
|
|
this.addItem(box, text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
const InputSourceManager = new Lang.Class({
|
|
|
|
Name: 'InputSourceManager',
|
2011-01-04 22:04:56 +00:00
|
|
|
|
|
|
|
_init: function() {
|
2012-12-13 15:31:03 +00:00
|
|
|
// All valid input sources currently in the gsettings
|
|
|
|
// KEY_INPUT_SOURCES list indexed by their index there
|
|
|
|
this._inputSources = {};
|
2012-12-13 19:48:13 +00: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 15:31:03 +00:00
|
|
|
|
|
|
|
this._currentSource = null;
|
2014-11-27 08:23:01 +00:00
|
|
|
this._backupSource = null;
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2012-12-10 19:34:43 +00:00
|
|
|
// All valid input sources currently in the gsettings
|
|
|
|
// KEY_INPUT_SOURCES list ordered by most recently used
|
|
|
|
this._mruSources = [];
|
2012-12-10 19:35:29 +00:00
|
|
|
this._keybindingAction =
|
|
|
|
Main.wm.addKeybinding('switch-input-source',
|
2014-06-24 19:17:09 +00:00
|
|
|
new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings" }),
|
2014-05-29 21:28:44 +00:00
|
|
|
Meta.KeyBindingFlags.NONE,
|
2014-12-11 14:35:40 +00:00
|
|
|
Shell.ActionMode.ALL,
|
2012-12-10 19:35:29 +00:00
|
|
|
Lang.bind(this, this._switchInputSource));
|
|
|
|
this._keybindingActionBackward =
|
|
|
|
Main.wm.addKeybinding('switch-input-source-backward',
|
2014-06-24 19:17:09 +00:00
|
|
|
new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings" }),
|
2014-05-29 21:23:32 +00:00
|
|
|
Meta.KeyBindingFlags.IS_REVERSED,
|
2014-12-11 14:35:40 +00:00
|
|
|
Shell.ActionMode.ALL,
|
2012-12-10 19:35:29 +00:00
|
|
|
Lang.bind(this, this._switchInputSource));
|
2014-06-24 19:17:09 +00:00
|
|
|
this._settings = new Gio.Settings({ schema_id: DESKTOP_INPUT_SOURCES_SCHEMA });
|
2012-04-19 02:01:29 +00:00
|
|
|
this._settings.connect('changed::' + KEY_INPUT_SOURCES, Lang.bind(this, this._inputSourcesChanged));
|
2014-06-05 16:47:48 +00:00
|
|
|
this._settings.connect('changed::' + KEY_KEYBOARD_OPTIONS, Lang.bind(this, this._keyboardOptionsChanged));
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2014-02-14 15:11:28 +00:00
|
|
|
this._xkbInfo = KeyboardManager.getXkbInfo();
|
2014-06-05 16:47:48 +00:00
|
|
|
this._keyboardManager = KeyboardManager.getKeyboardManager();
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2012-12-10 19:34:43 +00:00
|
|
|
this._ibusReady = false;
|
2014-02-14 12:35:05 +00:00
|
|
|
this._ibusManager = IBusManager.getIBusManager();
|
|
|
|
this._ibusManager.connect('ready', Lang.bind(this, this._ibusReadyCallback));
|
2012-09-01 21:57:53 +00:00
|
|
|
this._ibusManager.connect('properties-registered', Lang.bind(this, this._ibusPropertiesRegistered));
|
|
|
|
this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated));
|
2014-11-27 08:23:01 +00:00
|
|
|
this._ibusManager.connect('set-content-type', Lang.bind(this, this._ibusSetContentType));
|
2011-01-04 22:04:56 +00:00
|
|
|
|
2013-03-29 01:35:32 +00:00
|
|
|
global.display.connect('modifiers-accelerator-activated', Lang.bind(this, this._modifiersSwitcher));
|
|
|
|
|
2013-01-09 01:01:33 +00:00
|
|
|
this._sourcesPerWindow = false;
|
|
|
|
this._focusWindowNotifyId = 0;
|
|
|
|
this._overviewShowingId = 0;
|
|
|
|
this._overviewHiddenId = 0;
|
|
|
|
this._settings.connect('changed::per-window', Lang.bind(this, this._sourcesPerWindowChanged));
|
|
|
|
this._sourcesPerWindowChanged();
|
2014-11-27 08:23:01 +00:00
|
|
|
this._disableIBus = false;
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
reload: function() {
|
2014-06-05 16:47:48 +00:00
|
|
|
this._keyboardManager.setKeyboardOptions(this._settings.get_strv(KEY_KEYBOARD_OPTIONS));
|
2014-05-29 16:42:46 +00:00
|
|
|
this._inputSourcesChanged();
|
2012-05-22 22:27:06 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 12:35:05 +00:00
|
|
|
_ibusReadyCallback: function(im, ready) {
|
2012-12-10 19:34:43 +00:00
|
|
|
if (this._ibusReady == ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._ibusReady = ready;
|
|
|
|
this._mruSources = [];
|
|
|
|
this._inputSourcesChanged();
|
|
|
|
},
|
|
|
|
|
2013-03-29 01:35:32 +00:00
|
|
|
_modifiersSwitcher: function() {
|
|
|
|
let sourceIndexes = Object.keys(this._inputSources);
|
|
|
|
if (sourceIndexes.length == 0) {
|
2014-02-14 15:11:28 +00:00
|
|
|
KeyboardManager.releaseKeyboard();
|
2013-03-29 01:35:32 +00: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;
|
|
|
|
|
|
|
|
is.activate();
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-12-10 19:35:29 +00:00
|
|
|
_switchInputSource: function(display, screen, window, binding) {
|
2013-03-02 15:51:00 +00:00
|
|
|
if (this._mruSources.length < 2)
|
|
|
|
return;
|
|
|
|
|
2013-03-29 22:19:02 +00: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-26 00:05:29 +00:00
|
|
|
if (Main.actionMode == Shell.ActionMode.POPUP) {
|
2013-03-29 22:19:02 +00:00
|
|
|
this._modifiersSwitcher();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-10 19:35:29 +00:00
|
|
|
let popup = new InputSourcePopup(this._mruSources, this._keybindingAction, this._keybindingActionBackward);
|
2014-05-29 21:26:25 +00:00
|
|
|
if (!popup.show(binding.is_reversed(), binding.get_name(), binding.get_mask()))
|
2012-12-10 19:35:29 +00:00
|
|
|
popup.destroy();
|
|
|
|
},
|
|
|
|
|
2014-06-05 16:47:48 +00:00
|
|
|
_keyboardOptionsChanged: function() {
|
|
|
|
this._keyboardManager.setKeyboardOptions(this._settings.get_strv(KEY_KEYBOARD_OPTIONS));
|
|
|
|
this._keyboardManager.reapply();
|
|
|
|
},
|
2012-09-01 21:57:53 +00:00
|
|
|
|
2014-06-05 16:47:48 +00:00
|
|
|
_currentInputSourceChanged: function(newSource) {
|
2013-02-07 08:27:55 +00:00
|
|
|
let oldSource;
|
|
|
|
[oldSource, this._currentSource] = [this._currentSource, newSource];
|
|
|
|
|
2014-05-30 13:29:03 +00:00
|
|
|
this.emit('current-source-changed', oldSource);
|
2012-12-13 19:48:13 +00:00
|
|
|
|
2012-12-10 19:34:43 +00:00
|
|
|
for (let i = 1; i < this._mruSources.length; ++i)
|
|
|
|
if (this._mruSources[i] == newSource) {
|
|
|
|
let currentSource = this._mruSources.splice(i, 1);
|
|
|
|
this._mruSources = currentSource.concat(this._mruSources);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-09 01:01:33 +00:00
|
|
|
|
|
|
|
this._changePerWindowSource();
|
2011-05-15 17:31:02 +00:00
|
|
|
},
|
|
|
|
|
2014-06-05 16:47:48 +00:00
|
|
|
_activateInputSource: function(is) {
|
|
|
|
KeyboardManager.holdKeyboard();
|
|
|
|
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';
|
|
|
|
|
|
|
|
this._ibusManager.setEngine(engine, KeyboardManager.releaseKeyboard);
|
|
|
|
this._currentInputSourceChanged(is);
|
|
|
|
},
|
|
|
|
|
2012-04-19 02:01:29 +00:00
|
|
|
_inputSourcesChanged: function() {
|
|
|
|
let sources = this._settings.get_value(KEY_INPUT_SOURCES);
|
|
|
|
let nSources = sources.n_children();
|
|
|
|
|
2012-12-13 15:31:03 +00:00
|
|
|
this._inputSources = {};
|
2012-12-13 19:48:13 +00:00
|
|
|
this._ibusSources = {};
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2014-10-10 13:54:30 +00:00
|
|
|
let infosList = [];
|
2012-04-19 02:01:29 +00:00
|
|
|
for (let i = 0; i < nSources; i++) {
|
2012-12-13 15:31:03 +00:00
|
|
|
let displayName;
|
|
|
|
let shortName;
|
2012-04-19 02:01:29 +00:00
|
|
|
let [type, id] = sources.get_child_value(i).deep_unpack();
|
2012-12-13 15:31:03 +00:00
|
|
|
let exists = false;
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2012-05-29 17:30:14 +00:00
|
|
|
if (type == INPUT_SOURCE_TYPE_XKB) {
|
2012-12-13 15:31:03 +00:00
|
|
|
[exists, displayName, shortName, , ] =
|
2012-05-29 17:30:14 +00:00
|
|
|
this._xkbInfo.get_layout_info(id);
|
|
|
|
} else if (type == INPUT_SOURCE_TYPE_IBUS) {
|
2014-11-27 08:23:01 +00:00
|
|
|
if (this._disableIBus)
|
|
|
|
continue;
|
2012-05-29 17:30:14 +00:00
|
|
|
let engineDesc = this._ibusManager.getEngineDesc(id);
|
|
|
|
if (engineDesc) {
|
2012-08-31 16:14:48 +00:00
|
|
|
let language = IBus.get_language_name(engineDesc.get_language());
|
2013-03-12 03:06:32 +00:00
|
|
|
let longName = engineDesc.get_longname();
|
|
|
|
let textdomain = engineDesc.get_textdomain();
|
|
|
|
if (textdomain != '')
|
|
|
|
longName = Gettext.dgettext(textdomain, longName);
|
2012-12-13 15:31:03 +00:00
|
|
|
exists = true;
|
2013-03-12 03:06:32 +00:00
|
|
|
displayName = '%s (%s)'.format(language, longName);
|
2012-12-13 15:31:03 +00:00
|
|
|
shortName = this._makeEngineShortName(engineDesc);
|
2012-05-29 17:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2014-10-10 13:54:30 +00:00
|
|
|
if (exists)
|
|
|
|
infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
|
|
|
|
}
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2014-10-10 13:54:30 +00:00
|
|
|
if (infosList.length == 0) {
|
|
|
|
let type = INPUT_SOURCE_TYPE_XKB;
|
|
|
|
let id = KeyboardManager.DEFAULT_LAYOUT;
|
|
|
|
let [ , displayName, shortName, , ] = this._xkbInfo.get_layout_info(id);
|
|
|
|
infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
|
|
|
|
}
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2014-10-10 13:54:30 +00: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);
|
2014-06-05 16:47:48 +00:00
|
|
|
is.connect('activate', Lang.bind(this, this._activateInputSource));
|
2012-12-13 15:31:03 +00:00
|
|
|
|
|
|
|
if (!(is.shortName in inputSourcesByShortName))
|
|
|
|
inputSourcesByShortName[is.shortName] = [];
|
|
|
|
inputSourcesByShortName[is.shortName].push(is);
|
|
|
|
|
|
|
|
this._inputSources[is.index] = is;
|
2012-12-13 19:48:13 +00:00
|
|
|
|
|
|
|
if (is.type == INPUT_SOURCE_TYPE_IBUS)
|
|
|
|
this._ibusSources[is.id] = is;
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 15:31:03 +00: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-19 02:01:29 +00:00
|
|
|
}
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
this.emit('sources-changed');
|
|
|
|
|
2012-12-10 19:34:43 +00:00
|
|
|
let sourcesList = [];
|
|
|
|
for (let i in this._inputSources)
|
|
|
|
sourcesList.push(this._inputSources[i]);
|
|
|
|
|
2014-06-05 16:47:48 +00:00
|
|
|
this._keyboardManager.setUserLayouts(sourcesList.map(function(x) { return x.xkbId; }));
|
|
|
|
|
2012-12-10 19:34:43 +00:00
|
|
|
let mruSources = [];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._mruSources = mruSources.concat(sourcesList);
|
|
|
|
|
2014-11-27 08:23:01 +00:00
|
|
|
if (this._mruSources.length > 0) {
|
|
|
|
if (!this._disableIBus && this._backupSource) {
|
|
|
|
for (let i = 0; i < this._mruSources.length; i++) {
|
|
|
|
if (this._mruSources[i].type == this._backupSource.type &&
|
|
|
|
this._mruSources[i].id == this._backupSource.id) {
|
|
|
|
let currentSource = this._mruSources.splice(i, 1);
|
|
|
|
this._mruSources = currentSource.concat(this._mruSources);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._backupSource = null;
|
|
|
|
}
|
2014-06-05 16:47:48 +00:00
|
|
|
this._mruSources[0].activate();
|
2014-11-27 08:23:01 +00:00
|
|
|
}
|
2014-11-10 10:09:08 +00: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));
|
2011-01-04 22:04:56 +00:00
|
|
|
},
|
|
|
|
|
2012-09-09 20:44:25 +00:00
|
|
|
_makeEngineShortName: function(engineDesc) {
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
2012-12-13 19:48:13 +00:00
|
|
|
_ibusPropertiesRegistered: function(im, engineName, props) {
|
|
|
|
let source = this._ibusSources[engineName];
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source.properties = props;
|
|
|
|
|
|
|
|
if (source == this._currentSource)
|
2014-06-05 16:47:48 +00:00
|
|
|
this.emit('current-source-changed', null);
|
2012-09-01 21:57:53 +00:00
|
|
|
},
|
|
|
|
|
2012-12-13 19:48:13 +00:00
|
|
|
_ibusPropertyUpdated: function(im, engineName, prop) {
|
|
|
|
let source = this._ibusSources[engineName];
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._updateSubProperty(source.properties, prop) &&
|
|
|
|
source == this._currentSource)
|
2014-06-05 16:47:48 +00:00
|
|
|
this.emit('current-source-changed', null);
|
2012-09-01 21:57:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateSubProperty: function(props, prop) {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2014-11-27 08:23:01 +00:00
|
|
|
_ibusSetContentType: function(im, purpose, hints) {
|
|
|
|
if (purpose == IBus.InputPurpose.PASSWORD) {
|
|
|
|
if (Object.keys(this._inputSources).length == Object.keys(this._ibusSources).length)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._disableIBus)
|
|
|
|
return;
|
|
|
|
this._disableIBus = true;
|
|
|
|
this._backupSource = this._currentSource;
|
|
|
|
} else {
|
|
|
|
if (!this._disableIBus)
|
|
|
|
return;
|
|
|
|
this._disableIBus = false;
|
|
|
|
}
|
|
|
|
// If this._mruSources is not cleared before this.reload() is called,
|
|
|
|
// the order is different from the original one as IM sources will
|
|
|
|
// be appended to XKB sources.
|
|
|
|
this._mruSources = [];
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
_getNewInputSource: function(current) {
|
2015-03-11 14:48:03 +00: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 16:42:46 +00:00
|
|
|
}
|
2015-03-11 14:48:03 +00:00
|
|
|
|
|
|
|
return this._inputSources[sourceIndexes[0]];
|
2014-05-29 16:42:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getCurrentWindow: function() {
|
|
|
|
if (Main.overview.visible)
|
|
|
|
return Main.overview;
|
|
|
|
else
|
|
|
|
return global.display.focus_window;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setPerWindowInputSource: function() {
|
|
|
|
let window = this._getCurrentWindow();
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2015-03-11 14:48:03 +00:00
|
|
|
if (window._inputSources != this._inputSources) {
|
2014-05-29 16:42:46 +00:00
|
|
|
window._inputSources = this._inputSources;
|
|
|
|
window._currentSource = this._getNewInputSource(window._currentSource);
|
|
|
|
}
|
2015-03-11 14:48:03 +00:00
|
|
|
|
|
|
|
if (window._currentSource)
|
|
|
|
window._currentSource.activate();
|
2014-05-29 16:42:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_sourcesPerWindowChanged: function() {
|
|
|
|
this._sourcesPerWindow = this._settings.get_boolean('per-window');
|
|
|
|
|
|
|
|
if (this._sourcesPerWindow && this._focusWindowNotifyId == 0) {
|
|
|
|
this._focusWindowNotifyId = global.display.connect('notify::focus-window',
|
|
|
|
Lang.bind(this, this._setPerWindowInputSource));
|
|
|
|
this._overviewShowingId = Main.overview.connect('showing',
|
|
|
|
Lang.bind(this, this._setPerWindowInputSource));
|
|
|
|
this._overviewHiddenId = Main.overview.connect('hidden',
|
|
|
|
Lang.bind(this, this._setPerWindowInputSource));
|
|
|
|
} else if (!this._sourcesPerWindow && this._focusWindowNotifyId != 0) {
|
|
|
|
global.display.disconnect(this._focusWindowNotifyId);
|
|
|
|
this._focusWindowNotifyId = 0;
|
|
|
|
Main.overview.disconnect(this._overviewShowingId);
|
|
|
|
this._overviewShowingId = 0;
|
|
|
|
Main.overview.disconnect(this._overviewHiddenId);
|
|
|
|
this._overviewHiddenId = 0;
|
|
|
|
|
|
|
|
let windows = global.get_window_actors().map(function(w) {
|
|
|
|
return w.meta_window;
|
|
|
|
});
|
|
|
|
for (let i = 0; i < windows.length; ++i) {
|
|
|
|
delete windows[i]._inputSources;
|
|
|
|
delete windows[i]._currentSource;
|
|
|
|
}
|
|
|
|
delete Main.overview._inputSources;
|
|
|
|
delete Main.overview._currentSource;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_changePerWindowSource: function() {
|
|
|
|
if (!this._sourcesPerWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let window = this._getCurrentWindow();
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window._inputSources = this._inputSources;
|
|
|
|
window._currentSource = this._currentSource;
|
|
|
|
},
|
|
|
|
|
|
|
|
get currentSource() {
|
|
|
|
return this._currentSource;
|
|
|
|
},
|
|
|
|
|
|
|
|
get inputSources() {
|
|
|
|
return this._inputSources;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(InputSourceManager.prototype);
|
|
|
|
|
|
|
|
let _inputSourceManager = null;
|
|
|
|
|
|
|
|
function getInputSourceManager() {
|
|
|
|
if (_inputSourceManager == null)
|
|
|
|
_inputSourceManager = new InputSourceManager();
|
|
|
|
return _inputSourceManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
const InputSourceIndicator = new Lang.Class({
|
|
|
|
Name: 'InputSourceIndicator',
|
|
|
|
Extends: PanelMenu.Button,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.parent(0.0, _("Keyboard"));
|
|
|
|
|
2014-05-30 13:29:03 +00:00
|
|
|
this._menuItems = {};
|
|
|
|
this._indicatorLabels = {};
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
this._container = new Shell.GenericContainer();
|
|
|
|
this._container.connect('get-preferred-width', Lang.bind(this, this._containerGetPreferredWidth));
|
|
|
|
this._container.connect('get-preferred-height', Lang.bind(this, this._containerGetPreferredHeight));
|
|
|
|
this._container.connect('allocate', Lang.bind(this, this._containerAllocate));
|
|
|
|
|
|
|
|
this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
|
|
|
|
this._hbox.add_child(this._container);
|
|
|
|
this._hbox.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
|
|
|
|
|
|
|
this.actor.add_child(this._hbox);
|
|
|
|
|
|
|
|
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());
|
|
|
|
this._showLayoutItem = this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this, this._showLayout));
|
|
|
|
|
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
|
|
|
this._sessionUpdated();
|
|
|
|
|
|
|
|
this._inputSourceManager = getInputSourceManager();
|
|
|
|
this._inputSourceManager.connect('sources-changed', Lang.bind(this, this._sourcesChanged));
|
|
|
|
this._inputSourceManager.connect('current-source-changed', Lang.bind(this, this._currentSourceChanged));
|
|
|
|
this._inputSourceManager.reload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_sessionUpdated: function() {
|
|
|
|
// 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.
|
|
|
|
this._showLayoutItem.actor.visible = Main.sessionMode.allowSettings;
|
|
|
|
},
|
|
|
|
|
|
|
|
_sourcesChanged: function() {
|
2014-05-30 13:29:03 +00:00
|
|
|
for (let i in this._menuItems)
|
|
|
|
this._menuItems[i].destroy();
|
|
|
|
for (let i in this._indicatorLabels)
|
|
|
|
this._indicatorLabels[i].destroy();
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
let menuIndex = 0;
|
|
|
|
for (let i in this._inputSourceManager.inputSources) {
|
|
|
|
let is = this._inputSourceManager.inputSources[i];
|
2014-05-30 13:29:03 +00:00
|
|
|
|
|
|
|
let menuItem = new LayoutMenuItem(is.displayName, is.shortName);
|
|
|
|
menuItem.connect('activate', Lang.bind(is, is.activate));
|
|
|
|
let indicatorLabel = new St.Label({ text: is.shortName,
|
|
|
|
visible: false });
|
|
|
|
|
|
|
|
this._menuItems[i] = menuItem;
|
|
|
|
this._indicatorLabels[i] = indicatorLabel;
|
|
|
|
is.connect('changed', function() {
|
|
|
|
menuItem.indicator.set_text(is.shortName);
|
|
|
|
indicatorLabel.set_text(is.shorName);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.menu.addMenuItem(menuItem, menuIndex++);
|
|
|
|
this._container.add_actor(indicatorLabel);
|
2014-05-29 16:42:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-30 13:29:03 +00:00
|
|
|
_currentSourceChanged: function(manager, oldSource) {
|
2014-05-29 16:42:46 +00:00
|
|
|
let nVisibleSources = Object.keys(this._inputSourceManager.inputSources).length;
|
|
|
|
let newSource = this._inputSourceManager.currentSource;
|
|
|
|
|
2014-05-30 13:29:03 +00:00
|
|
|
if (oldSource) {
|
|
|
|
this._menuItems[oldSource.index].setOrnament(PopupMenu.Ornament.NONE);
|
|
|
|
this._indicatorLabels[oldSource.index].hide();
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:42:46 +00: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();
|
|
|
|
this.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.show();
|
|
|
|
|
|
|
|
this._buildPropSection(newSource.properties);
|
2014-05-30 13:29:03 +00:00
|
|
|
|
|
|
|
this._menuItems[newSource.index].setOrnament(PopupMenu.Ornament.DOT);
|
|
|
|
this._indicatorLabels[newSource.index].show();
|
2014-05-29 16:42:46 +00:00
|
|
|
},
|
|
|
|
|
2012-12-13 19:48:13 +00:00
|
|
|
_buildPropSection: function(properties) {
|
2012-09-18 10:17:58 +00:00
|
|
|
this._propSeparator.actor.hide();
|
2012-09-01 21:57:53 +00:00
|
|
|
this._propSection.actor.hide();
|
|
|
|
this._propSection.removeAll();
|
|
|
|
|
2012-12-13 19:48:13 +00:00
|
|
|
this._buildPropSubMenu(this._propSection, properties);
|
2012-09-01 21:57:53 +00:00
|
|
|
|
2012-09-18 10:17:58 +00:00
|
|
|
if (!this._propSection.isEmpty()) {
|
2012-09-01 21:57:53 +00:00
|
|
|
this._propSection.actor.show();
|
2012-09-18 10:17:58 +00:00
|
|
|
this._propSeparator.actor.show();
|
|
|
|
}
|
2012-09-01 21:57:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildPropSubMenu: function(menu, props) {
|
|
|
|
if (!props)
|
|
|
|
return;
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
let ibusManager = IBusManager.getIBusManager();
|
2012-09-01 21:57:53 +00:00
|
|
|
let radioGroup = [];
|
|
|
|
let p;
|
|
|
|
for (let i = 0; (p = props.get(i)) != null; ++i) {
|
|
|
|
let prop = p;
|
|
|
|
|
2012-11-24 15:38:21 +00:00
|
|
|
if (!prop.get_visible())
|
2012-09-01 21:57:53 +00: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 13:29:03 +00: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 21:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let item;
|
2012-11-24 14:56:06 +00:00
|
|
|
switch (prop.get_prop_type()) {
|
|
|
|
case IBus.PropType.MENU:
|
2012-09-01 21:57:53 +00:00
|
|
|
item = new PopupMenu.PopupSubMenuMenuItem(prop.get_label().get_text());
|
|
|
|
this._buildPropSubMenu(item.menu, prop.get_sub_props());
|
2012-11-24 14:56:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.RADIO:
|
2012-09-01 21:57:53 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(prop.get_label().get_text());
|
|
|
|
item.prop = prop;
|
|
|
|
radioGroup.push(item);
|
|
|
|
item.radioGroup = radioGroup;
|
2013-04-20 00:57:38 +00:00
|
|
|
item.setOrnament(prop.get_state() == IBus.PropState.CHECKED ?
|
|
|
|
PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE);
|
2012-09-01 21:57:53 +00:00
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
|
|
|
if (item.prop.get_state() == IBus.PropState.CHECKED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let group = item.radioGroup;
|
|
|
|
for (let i = 0; i < group.length; ++i) {
|
|
|
|
if (group[i] == item) {
|
2013-04-20 00:57:38 +00:00
|
|
|
item.setOrnament(PopupMenu.Ornament.DOT);
|
2012-09-01 21:57:53 +00:00
|
|
|
item.prop.set_state(IBus.PropState.CHECKED);
|
2014-05-29 16:42:46 +00:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.CHECKED);
|
2012-09-01 21:57:53 +00:00
|
|
|
} else {
|
2013-04-20 00:57:38 +00:00
|
|
|
group[i].setOrnament(PopupMenu.Ornament.NONE);
|
2012-09-01 21:57:53 +00:00
|
|
|
group[i].prop.set_state(IBus.PropState.UNCHECKED);
|
2014-05-29 16:42:46 +00:00
|
|
|
ibusManager.activateProperty(group[i].prop.get_key(),
|
|
|
|
IBus.PropState.UNCHECKED);
|
2012-09-01 21:57:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2012-11-24 14:56:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.TOGGLE:
|
|
|
|
item = new PopupMenu.PopupSwitchMenuItem(prop.get_label().get_text(), prop.get_state() == IBus.PropState.CHECKED);
|
|
|
|
item.prop = prop;
|
|
|
|
item.connect('toggled', Lang.bind(this, function() {
|
|
|
|
if (item.state) {
|
|
|
|
item.prop.set_state(IBus.PropState.CHECKED);
|
2014-05-29 16:42:46 +00:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.CHECKED);
|
2012-11-24 14:56:06 +00:00
|
|
|
} else {
|
|
|
|
item.prop.set_state(IBus.PropState.UNCHECKED);
|
2014-05-29 16:42:46 +00:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
IBus.PropState.UNCHECKED);
|
2012-11-24 14:56:06 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.NORMAL:
|
|
|
|
item = new PopupMenu.PopupMenuItem(prop.get_label().get_text());
|
|
|
|
item.prop = prop;
|
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
2014-05-29 16:42:46 +00:00
|
|
|
ibusManager.activateProperty(item.prop.get_key(),
|
|
|
|
item.prop.get_state());
|
2012-11-24 14:56:06 +00:00
|
|
|
}));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBus.PropType.SEPARATOR:
|
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log ('IBus property %s has invalid type %d'.format(prop.get_key(), type));
|
2012-09-01 21:57:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.setSensitive(prop.get_sensitive());
|
|
|
|
menu.addMenuItem(item);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
_showLayout: function() {
|
|
|
|
Main.overview.hide();
|
2013-01-09 01:01:33 +00:00
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
let source = this._inputSourceManager.currentSource;
|
|
|
|
let xkbLayout = '';
|
|
|
|
let xkbVariant = '';
|
2013-01-09 01:01:33 +00:00
|
|
|
|
2014-05-29 16:42:46 +00: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 17:16:08 +00:00
|
|
|
xkbVariant = engineDesc.get_layout_variant();
|
2013-01-09 01:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
if (!xkbLayout || xkbLayout.length == 0)
|
2013-01-09 01:01:33 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
let description = xkbLayout;
|
|
|
|
if (xkbVariant.length > 0)
|
|
|
|
description = description + '\t' + xkbVariant;
|
2013-01-09 01:01:33 +00:00
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
Util.spawn(['gkbd-keyboard-display', '-l', description]);
|
2013-01-09 01:01:33 +00:00
|
|
|
},
|
|
|
|
|
2011-09-19 12:07:40 +00:00
|
|
|
_containerGetPreferredWidth: function(container, for_height, alloc) {
|
|
|
|
// Here, and in _containerGetPreferredHeight, we need to query
|
|
|
|
// for the height of all children, but we ignore the results
|
|
|
|
// for those we don't actually display.
|
2011-01-04 22:04:56 +00:00
|
|
|
let max_min_width = 0, max_natural_width = 0;
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
for (let i in this._inputSourceManager.inputSources) {
|
2014-05-30 13:29:03 +00:00
|
|
|
let label = this._indicatorLabels[i];
|
|
|
|
let [min_width, natural_width] = label.get_preferred_width(for_height);
|
2012-04-19 02:01:29 +00:00
|
|
|
max_min_width = Math.max(max_min_width, min_width);
|
|
|
|
max_natural_width = Math.max(max_natural_width, natural_width);
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alloc.min_size = max_min_width;
|
|
|
|
alloc.natural_size = max_natural_width;
|
|
|
|
},
|
|
|
|
|
2011-09-19 12:07:40 +00:00
|
|
|
_containerGetPreferredHeight: function(container, for_width, alloc) {
|
2011-01-04 22:04:56 +00:00
|
|
|
let max_min_height = 0, max_natural_height = 0;
|
2012-04-19 02:01:29 +00:00
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
for (let i in this._inputSourceManager.inputSources) {
|
2014-05-30 13:29:03 +00:00
|
|
|
let label = this._indicatorLabels[i];
|
|
|
|
let [min_height, natural_height] = label.get_preferred_height(for_width);
|
2012-04-19 02:01:29 +00:00
|
|
|
max_min_height = Math.max(max_min_height, min_height);
|
|
|
|
max_natural_height = Math.max(max_natural_height, natural_height);
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alloc.min_size = max_min_height;
|
|
|
|
alloc.natural_size = max_natural_height;
|
|
|
|
},
|
|
|
|
|
2011-09-19 12:07:40 +00:00
|
|
|
_containerAllocate: function(container, box, flags) {
|
2011-01-04 22:04:56 +00:00
|
|
|
// translate box to (0, 0)
|
|
|
|
box.x2 -= box.x1;
|
|
|
|
box.x1 = 0;
|
|
|
|
box.y2 -= box.y1;
|
|
|
|
box.y1 = 0;
|
|
|
|
|
2014-05-29 16:42:46 +00:00
|
|
|
for (let i in this._inputSourceManager.inputSources) {
|
2014-05-30 13:29:03 +00:00
|
|
|
let label = this._indicatorLabels[i];
|
|
|
|
label.allocate_align_fill(box, 0.5, 0.5, false, false, flags);
|
2012-12-13 15:31:03 +00:00
|
|
|
}
|
2011-01-04 22:04:56 +00:00
|
|
|
}
|
2011-11-20 14:38:48 +00:00
|
|
|
});
|