[gnome-shell/wip/carlosg/im-full-reset: 2/3] ibusManager: Make more resilient to completion/engine independent changes




commit 0fc4409b46743f5ece9e98a9dccf56685df2bb9e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 17 15:55:11 2022 +0200

    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).

 js/misc/ibusManager.js | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js
index 5ba7e636d0..8b12ef1466 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,23 @@ 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)
+            this.setCompletionENabled(false, callback);
+        else if (!isXkb)
+            await this._setEngine(id, callback);
+    }
+
     preloadEngines(ids) {
         if (!this._ibus || !this._ready)
             return;
@@ -339,7 +352,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 +386,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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]