ibusManager: Make more resilient to completion/engine independent changes

Besides user interaction, there's two users of IBusManager.setEngine():

- The code that toggles all IBus engines off on entries with PASSWORD
  purpose.
- The code that toggles completion support on OSK presence.

These are currently pretty oblivious to each other. Make this
interaction more resilient by making all external IBusManager changes
more cautious about directly changing the engine, and revoke properly
the completion mode if it needs be (e.g. changing to a non-XKB engine).

But another notable change is that ibus-typing-booster is now preferred
always, over PASSWORD purpose hints. This is done to avoid possible
doubled attempts to change the current engine (and ensuing IBusInputContext
confusion).

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2512>
This commit is contained in:
Carlos Garnacho 2022-10-17 15:55:11 +02:00 committed by Marge Bot
parent b2f2266199
commit 12032dcc50

View File

@ -288,7 +288,7 @@ var IBusManager = class extends Signals.EventEmitter {
return this._engines.get(id);
}
async setEngine(id, callback) {
async _setEngine(id, callback) {
// Send id even if id == this._currentEngineName
// because 'properties-registered' signal can be emitted
// while this._ibusSources == null on a lock screen.
@ -306,10 +306,25 @@ var IBusManager = class extends Signals.EventEmitter {
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
logError(e);
}
if (callback)
callback();
}
async setEngine(id, callback) {
if (this._preOskState)
this._preOskState.engine = id;
const isXkb = id.startsWith('xkb:');
if (this._oskCompletion && isXkb)
return;
if (this._oskCompletion)
this.setCompletionEnabled(false, callback);
else
await this._setEngine(id, callback);
}
preloadEngines(ids) {
if (!this._ibus || !this._ready)
return;
@ -339,7 +354,7 @@ var IBusManager = class extends Signals.EventEmitter {
setCompletionEnabled(enabled, callback) {
/* Needs typing-booster available */
if (!this._engines.has(TYPING_BOOSTER_ENGINE))
if (enabled && !this._engines.has(TYPING_BOOSTER_ENGINE))
return false;
/* Can do only on xkb engines */
if (enabled && !this._currentEngineName.startsWith('xkb:'))
@ -373,12 +388,12 @@ var IBusManager = class extends Signals.EventEmitter {
settings.reset(KEY_INLINECOMPLETION);
settings.set_string(KEY_INPUTMETHOD, 'NoIME');
this.setEngine(TYPING_BOOSTER_ENGINE, callback);
this._setEngine(TYPING_BOOSTER_ENGINE, callback);
} else if (this._preOskState) {
const {engine, emoji, langs, completion, inputMethod} =
this._preOskState;
this._preOskState = null;
this.setEngine(engine, callback);
this._setEngine(engine, callback);
settings.set_value(KEY_EMOJIPREDICTIONS, emoji);
settings.set_value(KEY_DICTIONARY, langs);
settings.set_value(KEY_INLINECOMPLETION, completion);