2014-02-14 07:35:05 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported getIBusManager */
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2022-02-10 08:08:06 -05:00
|
|
|
const { Gio, GLib, IBus, Meta, Shell } = imports.gi;
|
2022-07-04 18:30:44 -04:00
|
|
|
const Signals = imports.misc.signals;
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2018-01-17 11:01:24 -05:00
|
|
|
const IBusCandidatePopup = imports.ui.ibusCandidatePopup;
|
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
Gio._promisify(IBus.Bus.prototype,
|
|
|
|
'list_engines_async', 'list_engines_async_finish');
|
|
|
|
Gio._promisify(IBus.Bus.prototype,
|
|
|
|
'request_name_async', 'request_name_async_finish');
|
|
|
|
Gio._promisify(IBus.Bus.prototype,
|
|
|
|
'get_global_engine_async', 'get_global_engine_async_finish');
|
|
|
|
Gio._promisify(IBus.Bus.prototype,
|
|
|
|
'set_global_engine_async', 'set_global_engine_async_finish');
|
2022-02-10 08:08:06 -05:00
|
|
|
Gio._promisify(Shell, 'util_systemd_unit_exists');
|
2019-12-19 14:50:37 -05:00
|
|
|
|
2018-01-17 11:01:24 -05:00
|
|
|
// Ensure runtime version matches
|
|
|
|
_checkIBusVersion(1, 5, 2);
|
2014-02-14 07:35:05 -05:00
|
|
|
|
|
|
|
let _ibusManager = null;
|
2022-02-10 08:08:06 -05:00
|
|
|
const IBUS_SYSTEMD_SERVICE = 'org.freedesktop.IBus.session.GNOME.service';
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2014-11-27 03:23:01 -05:00
|
|
|
function _checkIBusVersion(requiredMajor, requiredMinor, requiredMicro) {
|
2014-11-10 05:09:08 -05:00
|
|
|
if ((IBus.MAJOR_VERSION > requiredMajor) ||
|
|
|
|
(IBus.MAJOR_VERSION == requiredMajor && IBus.MINOR_VERSION > requiredMinor) ||
|
|
|
|
(IBus.MAJOR_VERSION == requiredMajor && IBus.MINOR_VERSION == requiredMinor &&
|
|
|
|
IBus.MICRO_VERSION >= requiredMicro))
|
|
|
|
return;
|
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
throw new Error(`Found IBus version ${
|
|
|
|
IBus.MAJOR_VERSION}.${IBus.MINOR_VERSION}.${IBus.MINOR_VERSION} ` +
|
|
|
|
`but required is ${requiredMajor}.${requiredMinor}.${requiredMicro}`);
|
2014-11-10 05:09:08 -05:00
|
|
|
}
|
|
|
|
|
2014-02-14 07:35:05 -05:00
|
|
|
function getIBusManager() {
|
|
|
|
if (_ibusManager == null)
|
|
|
|
_ibusManager = new IBusManager();
|
|
|
|
return _ibusManager;
|
|
|
|
}
|
|
|
|
|
2022-07-04 18:30:44 -04:00
|
|
|
var IBusManager = class extends Signals.EventEmitter {
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor() {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
IBus.init();
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
// This is the longest we'll keep the keyboard frozen until an input
|
|
|
|
// source is active.
|
|
|
|
this._MAX_INPUT_SOURCE_ACTIVATION_TIME = 4000; // ms
|
|
|
|
this._PRELOAD_ENGINES_DELAY_TIME = 30; // sec
|
2014-06-05 12:47:48 -04:00
|
|
|
|
2014-02-14 07:35:05 -05:00
|
|
|
|
|
|
|
this._candidatePopup = new IBusCandidatePopup.CandidatePopup();
|
|
|
|
|
|
|
|
this._panelService = null;
|
2019-06-29 19:02:34 -04:00
|
|
|
this._engines = new Map();
|
2014-02-14 07:35:05 -05:00
|
|
|
this._ready = false;
|
|
|
|
this._registerPropertiesId = 0;
|
|
|
|
this._currentEngineName = null;
|
2014-11-10 05:09:08 -05:00
|
|
|
this._preloadEnginesId = 0;
|
2014-02-14 07:35:05 -05:00
|
|
|
|
|
|
|
this._ibus = IBus.Bus.new_async();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._ibus.connect('connected', this._onConnected.bind(this));
|
|
|
|
this._ibus.connect('disconnected', this._clear.bind(this));
|
2014-02-14 07:35:05 -05:00
|
|
|
// Need to set this to get 'global-engine-changed' emitions
|
|
|
|
this._ibus.set_watch_ibus_signal(true);
|
2017-12-01 19:27:35 -05:00
|
|
|
this._ibus.connect('global-engine-changed', this._engineChanged.bind(this));
|
2014-05-29 09:27:42 -04:00
|
|
|
|
2022-02-10 08:08:06 -05:00
|
|
|
this._queueSpawn();
|
|
|
|
}
|
|
|
|
|
|
|
|
async _ibusSystemdServiceExists() {
|
|
|
|
if (this._ibusIsSystemdService)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this._ibusIsSystemdService =
|
|
|
|
await Shell.util_systemd_unit_exists(
|
|
|
|
IBUS_SYSTEMD_SERVICE, null);
|
|
|
|
} catch (e) {
|
|
|
|
this._ibusIsSystemdService = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._ibusIsSystemdService;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _queueSpawn() {
|
|
|
|
const isSystemdService = await this._ibusSystemdServiceExists();
|
|
|
|
if (!isSystemdService)
|
|
|
|
this._spawn(Meta.is_wayland_compositor() ? [] : ['--xim']);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-05-29 09:27:42 -04:00
|
|
|
|
2022-06-26 20:56:48 -04:00
|
|
|
_tryAppendEnv(env, varname) {
|
|
|
|
const value = GLib.getenv(varname);
|
|
|
|
if (value)
|
|
|
|
env.push(`${varname}=${value}`);
|
|
|
|
}
|
|
|
|
|
2019-08-15 07:28:59 -04:00
|
|
|
_spawn(extraArgs = []) {
|
2014-05-29 09:27:42 -04:00
|
|
|
try {
|
2019-08-15 07:29:53 -04:00
|
|
|
let cmdLine = ['ibus-daemon', '--panel', 'disable', ...extraArgs];
|
2022-01-31 04:40:04 -05:00
|
|
|
let env = [];
|
|
|
|
|
2022-06-26 20:56:48 -04:00
|
|
|
this._tryAppendEnv(env, 'DBUS_SESSION_BUS_ADDRESS');
|
|
|
|
this._tryAppendEnv(env, 'WAYLAND_DISPLAY');
|
|
|
|
this._tryAppendEnv(env, 'HOME');
|
|
|
|
this._tryAppendEnv(env, 'LANG');
|
|
|
|
this._tryAppendEnv(env, 'LC_CTYPE');
|
|
|
|
this._tryAppendEnv(env, 'COMPOSE_FILE');
|
|
|
|
this._tryAppendEnv(env, 'DISPLAY');
|
|
|
|
|
2022-06-27 16:38:55 -04:00
|
|
|
// Use DO_NOT_REAP_CHILD to avoid adouble-fork internally
|
|
|
|
// since ibus-daemon refuses to start with init as its parent.
|
|
|
|
const [success_, pid] = GLib.spawn_async(
|
2022-01-31 04:40:04 -05:00
|
|
|
null, cmdLine, env,
|
2022-06-27 16:38:55 -04:00
|
|
|
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
2022-01-31 04:40:04 -05:00
|
|
|
() => {
|
|
|
|
try {
|
|
|
|
global.context.restore_rlimit_nofile();
|
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-06-27 16:38:55 -04:00
|
|
|
GLib.child_watch_add(
|
|
|
|
GLib.PRIORITY_DEFAULT,
|
|
|
|
pid,
|
|
|
|
() => GLib.spawn_close_pid(pid)
|
|
|
|
);
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2019-01-29 19:18:24 -05:00
|
|
|
log(`Failed to launch ibus-daemon: ${e.message}`);
|
2014-05-29 09:27:42 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2022-02-10 08:08:06 -05:00
|
|
|
async restartDaemon(extraArgs = []) {
|
|
|
|
const isSystemdService = await this._ibusSystemdServiceExists();
|
|
|
|
if (!isSystemdService)
|
|
|
|
this._spawn(['-r', ...extraArgs]);
|
2019-08-15 07:28:59 -04:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clear() {
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
if (this._cancellable) {
|
|
|
|
this._cancellable.cancel();
|
|
|
|
this._cancellable = null;
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:15:38 -04:00
|
|
|
if (this._preloadEnginesId) {
|
|
|
|
GLib.source_remove(this._preloadEnginesId);
|
|
|
|
this._preloadEnginesId = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-14 07:35:05 -05:00
|
|
|
if (this._panelService)
|
|
|
|
this._panelService.destroy();
|
|
|
|
|
|
|
|
this._panelService = null;
|
|
|
|
this._candidatePopup.setPanelService(null);
|
2019-06-29 19:02:34 -04:00
|
|
|
this._engines.clear();
|
2014-02-14 07:35:05 -05:00
|
|
|
this._ready = false;
|
|
|
|
this._registerPropertiesId = 0;
|
|
|
|
this._currentEngineName = null;
|
|
|
|
|
|
|
|
this.emit('ready', false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onConnected() {
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
this._cancellable = new Gio.Cancellable();
|
2019-12-19 14:50:37 -05:00
|
|
|
this._initEngines();
|
|
|
|
this._initPanelService();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
async _initEngines() {
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
try {
|
2019-12-19 14:50:37 -05:00
|
|
|
const enginesList =
|
|
|
|
await this._ibus.list_engines_async(-1, this._cancellable);
|
2014-02-14 07:35:05 -05:00
|
|
|
for (let i = 0; i < enginesList.length; ++i) {
|
|
|
|
let name = enginesList[i].get_name();
|
2019-06-29 19:02:34 -04:00
|
|
|
this._engines.set(name, enginesList[i]);
|
2014-02-14 07:35:05 -05:00
|
|
|
}
|
|
|
|
this._updateReadiness();
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
} catch (e) {
|
|
|
|
if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
logError(e);
|
2014-02-14 07:35:05 -05:00
|
|
|
this._clear();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
async _initPanelService() {
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
try {
|
2019-12-19 14:50:37 -05:00
|
|
|
await this._ibus.request_name_async(IBus.SERVICE_PANEL,
|
|
|
|
IBus.BusNameFlag.REPLACE_EXISTING, -1, this._cancellable);
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
} catch (e) {
|
2020-03-23 18:22:17 -04:00
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
|
|
|
|
logError(e);
|
|
|
|
this._clear();
|
|
|
|
}
|
|
|
|
return;
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
}
|
|
|
|
|
2020-03-23 18:22:17 -04:00
|
|
|
this._panelService = new IBus.PanelService({
|
|
|
|
connection: this._ibus.get_connection(),
|
|
|
|
object_path: IBus.PATH_PANEL,
|
|
|
|
});
|
|
|
|
this._candidatePopup.setPanelService(this._panelService);
|
|
|
|
this._panelService.connect('update-property', this._updateProperty.bind(this));
|
|
|
|
this._panelService.connect('set-cursor-location', (ps, x, y, w, h) => {
|
|
|
|
let cursorLocation = { x, y, width: w, height: h };
|
|
|
|
this.emit('set-cursor-location', cursorLocation);
|
|
|
|
});
|
|
|
|
this._panelService.connect('focus-in', (panel, path) => {
|
|
|
|
if (!GLib.str_has_suffix(path, '/InputContext_1'))
|
|
|
|
this.emit('focus-in');
|
|
|
|
});
|
|
|
|
this._panelService.connect('focus-out', () => this.emit('focus-out'));
|
2018-05-25 05:35:49 -04:00
|
|
|
|
2020-03-23 18:22:17 -04:00
|
|
|
try {
|
|
|
|
// IBus versions older than 1.5.10 have a bug which
|
|
|
|
// causes spurious set-content-type emissions when
|
|
|
|
// switching input focus that temporarily lose purpose
|
|
|
|
// and hints defeating its intended semantics and
|
|
|
|
// confusing users. We thus don't use it in that case.
|
|
|
|
_checkIBusVersion(1, 5, 10);
|
|
|
|
this._panelService.connect('set-content-type', this._setContentType.bind(this));
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2020-05-03 11:26:39 -04:00
|
|
|
this._updateReadiness();
|
2019-12-19 14:50:37 -05:00
|
|
|
|
|
|
|
try {
|
|
|
|
// If an engine is already active we need to get its properties
|
|
|
|
const engine =
|
|
|
|
await this._ibus.get_global_engine_async(-1, this._cancellable);
|
2020-03-23 18:22:17 -04:00
|
|
|
this._engineChanged(this._ibus, engine.get_name());
|
2019-12-19 14:50:37 -05:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateReadiness() {
|
2019-06-29 19:02:34 -04:00
|
|
|
this._ready = this._engines.size > 0 && this._panelService != null;
|
2014-02-14 07:35:05 -05:00
|
|
|
this.emit('ready', this._ready);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_engineChanged(bus, engineName) {
|
2014-02-14 07:35:05 -05:00
|
|
|
if (!this._ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._currentEngineName = engineName;
|
|
|
|
|
|
|
|
if (this._registerPropertiesId != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._registerPropertiesId =
|
2017-10-30 20:38:18 -04:00
|
|
|
this._panelService.connect('register-properties', (p, props) => {
|
2014-02-14 07:35:05 -05:00
|
|
|
if (!props.get(0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._panelService.disconnect(this._registerPropertiesId);
|
|
|
|
this._registerPropertiesId = 0;
|
|
|
|
|
|
|
|
this.emit('properties-registered', this._currentEngineName, props);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateProperty(panel, prop) {
|
2014-02-14 07:35:05 -05:00
|
|
|
this.emit('property-updated', this._currentEngineName, prop);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setContentType(panel, purpose, hints) {
|
2014-11-27 03:23:01 -05:00
|
|
|
this.emit('set-content-type', purpose, hints);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-11-27 03:23:01 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateProperty(key, state) {
|
2014-02-14 07:35:05 -05:00
|
|
|
this._panelService.property_activate(key, state);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-02-14 07:35:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getEngineDesc(id) {
|
2019-06-29 19:02:34 -04:00
|
|
|
if (!this._ready || !this._engines.has(id))
|
2014-02-14 07:35:05 -05:00
|
|
|
return null;
|
|
|
|
|
2019-06-29 19:02:34 -04:00
|
|
|
return this._engines.get(id);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-05 12:47:48 -04:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
async setEngine(id, callback) {
|
2014-11-27 03:23:01 -05:00
|
|
|
// Send id even if id == this._currentEngineName
|
|
|
|
// because 'properties-registered' signal can be emitted
|
|
|
|
// while this._ibusSources == null on a lock screen.
|
2018-01-17 11:01:24 -05:00
|
|
|
if (!this._ready) {
|
2014-06-05 12:47:48 -04:00
|
|
|
if (callback)
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
try {
|
|
|
|
await this._ibus.set_global_engine_async(id,
|
|
|
|
this._MAX_INPUT_SOURCE_ACTIVATION_TIME,
|
|
|
|
this._cancellable);
|
|
|
|
} catch (e) {
|
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
|
|
|
|
logError(e);
|
|
|
|
}
|
|
|
|
if (callback)
|
|
|
|
callback();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-11-10 05:09:08 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
preloadEngines(ids) {
|
2018-01-17 11:01:24 -05:00
|
|
|
if (!this._ibus || ids.length == 0)
|
2014-11-10 05:09:08 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._preloadEnginesId != 0) {
|
2019-08-19 14:50:33 -04:00
|
|
|
GLib.source_remove(this._preloadEnginesId);
|
2014-11-10 05:09:08 -05:00
|
|
|
this._preloadEnginesId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._preloadEnginesId =
|
2019-08-19 14:50:33 -04:00
|
|
|
GLib.timeout_add_seconds(
|
|
|
|
GLib.PRIORITY_DEFAULT,
|
|
|
|
this._PRELOAD_ENGINES_DELAY_TIME,
|
|
|
|
() => {
|
|
|
|
this._ibus.preload_engines_async(
|
|
|
|
ids,
|
|
|
|
-1,
|
ibusManager, inputMethod: Cancel async ibus calls chain on disconnect
The shell tries to spawn the ibus daemon on startup if unavailable, however
as per commit 8adfc5b1 we also force restarting it once the X11 server is
available.
Unfortunately this could cause a race if we disconnect while we were already
connected to an ibus daemon, but still in the process of going through the
various nested calls.
In fact the ::disconnect callback didn't stop any further async ibus call
that, even if failing, would have eventually triggered the emission of a
'ready' signal and to the Keyboard's callback, leading under X11 to a full
grab owned by ibus daemon.
In order to avoid this and keep control of the calls order, use in both
IbusManager and InputMethod a cancellable that is setup before connecting to
the bus, and that is cancelled on disconnection.
Then handle the finish() calls properly, using try/catch to validate the
returned value, taking in account the potential error and just not
proceeding in case of cancellation.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1712
2019-09-25 14:56:46 -04:00
|
|
|
this._cancellable,
|
2019-08-19 14:50:33 -04:00
|
|
|
null);
|
|
|
|
this._preloadEnginesId = 0;
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
|
|
|
};
|