63c8234
From 524a5401266f8b30c2210cf147530cbb815b71ed Mon Sep 17 00:00:00 2001
63c8234
From: Carlos Garnacho <carlosg@gnome.org>
63c8234
Date: Tue, 11 Oct 2022 18:23:19 +0200
63c8234
Subject: [PATCH 1/2] keyboard: Refactor code
63c8234
63c8234
Move inline anonymous function to be its own. This method
63c8234
will become asynchronous in following commits.
63c8234
---
63c8234
 js/ui/keyboard.js | 54 +++++++++++++++++++++++++----------------------
63c8234
 1 file changed, 29 insertions(+), 25 deletions(-)
63c8234
63c8234
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
63c8234
index 895691c34e..28369316e1 100644
63c8234
--- a/js/ui/keyboard.js
63c8234
+++ b/js/ui/keyboard.js
63c8234
@@ -1510,31 +1510,8 @@ var Keyboard = GObject.registerClass({
63c8234
                 button.setWidth(key.width);
63c8234
 
63c8234
             if (key.action !== 'modifier') {
63c8234
-                button.connect('commit', (actor, keyval, str) => {
63c8234
-                    if (this._modifiers.size === 0 && str !== '' &&
63c8234
-                        keyval && this._oskCompletionEnabled) {
63c8234
-                        Main.inputMethod.handleVirtualKey(keyval);
63c8234
-                        return;
63c8234
-                    }
63c8234
-
63c8234
-                    if (str === '' || !Main.inputMethod.currentFocus ||
63c8234
-                        (keyval && this._oskCompletionEnabled) ||
63c8234
-                        this._modifiers.size > 0 ||
63c8234
-                        !this._keyboardController.commitString(str, true)) {
63c8234
-                        if (keyval !== 0) {
63c8234
-                            this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
63c8234
-                            this._keyboardController.keyvalPress(keyval);
63c8234
-                            GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
63c8234
-                                this._keyboardController.keyvalRelease(keyval);
63c8234
-                                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
63c8234
-                                this._disableAllModifiers();
63c8234
-                                return GLib.SOURCE_REMOVE;
63c8234
-                            });
63c8234
-                        }
63c8234
-                    }
63c8234
-
63c8234
-                    if (!this._latched)
63c8234
-                        this._setActiveLayer(0);
63c8234
+                button.connect('commit', (_actor, keyval, str) => {
63c8234
+                    this._commitAction(keyval, str);
63c8234
                 });
63c8234
             }
63c8234
 
63c8234
@@ -1592,6 +1569,33 @@ var Keyboard = GObject.registerClass({
63c8234
         }
63c8234
     }
63c8234
 
63c8234
+    _commitAction(keyval, str) {
63c8234
+        if (this._modifiers.size === 0 && str !== '' &&
63c8234
+            keyval && this._oskCompletionEnabled) {
63c8234
+            Main.inputMethod.handleVirtualKey(keyval);
63c8234
+            return;
63c8234
+        }
63c8234
+
63c8234
+        if (str === '' || !Main.inputMethod.currentFocus ||
63c8234
+            (keyval && this._oskCompletionEnabled) ||
63c8234
+            this._modifiers.size > 0 ||
63c8234
+            !this._keyboardController.commitString(str, true)) {
63c8234
+            if (keyval !== 0) {
63c8234
+                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
63c8234
+                this._keyboardController.keyvalPress(keyval);
63c8234
+                GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
63c8234
+                    this._keyboardController.keyvalRelease(keyval);
63c8234
+                    this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
63c8234
+                    this._disableAllModifiers();
63c8234
+                    return GLib.SOURCE_REMOVE;
63c8234
+                });
63c8234
+            }
63c8234
+        }
63c8234
+
63c8234
+        if (!this._latched)
63c8234
+            this._setActiveLayer(0);
63c8234
+    }
63c8234
+
63c8234
     _previousWordPosition(text, cursor) {
63c8234
         /* Skip word prior to cursor */
63c8234
         let pos = Math.max(0, text.slice(0, cursor).search(/\s+\S+\s*$/));
63c8234
-- 
63c8234
GitLab
63c8234
63c8234
63c8234
From 6e997c993e8c392b88cb97644ad604be6dd8028a Mon Sep 17 00:00:00 2001
63c8234
From: Carlos Garnacho <carlosg@gnome.org>
63c8234
Date: Tue, 11 Oct 2022 18:24:15 +0200
63c8234
Subject: [PATCH 2/2] inputMethod: Check return value when letting IM handle
63c8234
 virtual keys
63c8234
63c8234
When propagating keys from the OSK, we usually feed these directly to
63c8234
the IBusInputContext and let the IM handle the effects of this virtual
63c8234
key event (which may also include feeding a key event back to us).
63c8234
63c8234
But these functions may also return a FALSE value if the key was "let
63c8234
through" by the IM, which means the ball is in our yard again, and
63c8234
we are responsible of letting this event get to its destination.
63c8234
63c8234
If that happens, just fall through, so the string is committed to
63c8234
the client as an UTF-8 string, or propagated through keyboard events.
63c8234
63c8234
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5930
63c8234
---
63c8234
 js/misc/inputMethod.js | 19 ++++++++++++++-----
63c8234
 js/ui/keyboard.js      |  6 +++---
63c8234
 2 files changed, 17 insertions(+), 8 deletions(-)
63c8234
63c8234
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
63c8234
index 7bf6646d80..906fe1fc93 100644
63c8234
--- a/js/misc/inputMethod.js
63c8234
+++ b/js/misc/inputMethod.js
63c8234
@@ -7,6 +7,8 @@ const Main = imports.ui.main;
63c8234
 
63c8234
 Gio._promisify(IBus.Bus.prototype,
63c8234
     'create_input_context_async', 'create_input_context_async_finish');
63c8234
+Gio._promisify(IBus.InputContext.prototype,
63c8234
+    'process_key_event_async', 'process_key_event_async_finish');
63c8234
 
63c8234
 var HIDE_PANEL_TIME = 50;
63c8234
 
63c8234
@@ -329,10 +331,17 @@ var InputMethod = GObject.registerClass({
63c8234
         return this._preeditVisible && this._preeditStr !== '' && this._preeditStr !== null;
63c8234
     }
63c8234
 
63c8234
-    handleVirtualKey(keyval) {
63c8234
-        this._context.process_key_event_async(
63c8234
-            keyval, 0, 0, -1, null, null);
63c8234
-        this._context.process_key_event_async(
63c8234
-            keyval, 0, IBus.ModifierType.RELEASE_MASK, -1, null, null);
63c8234
+    async handleVirtualKey(keyval) {
63c8234
+        try {
63c8234
+            if (!await this._context.process_key_event_async(
63c8234
+                keyval, 0, 0, -1, null))
63c8234
+                return false;
63c8234
+
63c8234
+            await this._context.process_key_event_async(
63c8234
+                keyval, 0, IBus.ModifierType.RELEASE_MASK, -1, null);
63c8234
+            return true;
63c8234
+        } catch (e) {
63c8234
+            return false;
63c8234
+        }
63c8234
     }
63c8234
 });
63c8234
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
63c8234
index 28369316e1..3241571de7 100644
63c8234
--- a/js/ui/keyboard.js
63c8234
+++ b/js/ui/keyboard.js
63c8234
@@ -1569,11 +1569,11 @@ var Keyboard = GObject.registerClass({
63c8234
         }
63c8234
     }
63c8234
 
63c8234
-    _commitAction(keyval, str) {
63c8234
+    async _commitAction(keyval, str) {
63c8234
         if (this._modifiers.size === 0 && str !== '' &&
63c8234
             keyval && this._oskCompletionEnabled) {
63c8234
-            Main.inputMethod.handleVirtualKey(keyval);
63c8234
-            return;
63c8234
+            if (await Main.inputMethod.handleVirtualKey(keyval))
63c8234
+                return;
63c8234
         }
63c8234
 
63c8234
         if (str === '' || !Main.inputMethod.currentFocus ||
63c8234
-- 
63c8234
GitLab
63c8234