From 12032dcc50e108e984fe4d689e8d372d0eb1d5ff Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 17 Oct 2022 15:55:11 +0200 Subject: [PATCH] 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: --- js/misc/ibusManager.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js index 5ba7e636d..820ee827c 100644 --- a/js/misc/ibusManager.js +++ b/js/misc/ibusManager.js @@ -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);