Blame SOURCES/backport-im-fixes.patch

c7fac9
From 99c77e85b3514e885641ebdc3dee3d4508e08fbf Mon Sep 17 00:00:00 2001
c7fac9
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
c7fac9
Date: Mon, 16 Jul 2018 23:36:38 +0000
c7fac9
Subject: [PATCH 1/6] keyboard: Handle no-window case in FocusTracker
c7fac9
c7fac9
For windows, the cursor location needs to be adjusted by the frame
c7fac9
offsets. However we cannot assume that there is a window, as the
c7fac9
shell itself can have the key focus.
c7fac9
c7fac9
https://gitlab.gnome.org/GNOME/gnome-shell/issues/414
c7fac9
c7fac9
c7fac9
(cherry picked from commit 0dee82fb9fa974ebdb4dd77fd85535a6edf207fd)
c7fac9
---
c7fac9
 js/ui/keyboard.js | 18 +++++++++++++-----
c7fac9
 1 file changed, 13 insertions(+), 5 deletions(-)
c7fac9
c7fac9
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
c7fac9
index 5fcdf988a..66653d602 100644
c7fac9
--- a/js/ui/keyboard.js
c7fac9
+++ b/js/ui/keyboard.js
c7fac9
@@ -533,17 +533,25 @@ var FocusTracker = new Lang.Class({
c7fac9
     },
c7fac9
 
c7fac9
     _setCurrentRect(rect) {
c7fac9
-        let frameRect = this._currentWindow.get_frame_rect();
c7fac9
-        rect.x -= frameRect.x;
c7fac9
-        rect.y -= frameRect.y;
c7fac9
+        if (this._currentWindow) {
c7fac9
+            let frameRect = this._currentWindow.get_frame_rect();
c7fac9
+            rect.x -= frameRect.x;
c7fac9
+            rect.y -= frameRect.y;
c7fac9
+        }
c7fac9
 
c7fac9
         this._rect = rect;
c7fac9
         this.emit('position-changed');
c7fac9
     },
c7fac9
 
c7fac9
     getCurrentRect() {
c7fac9
-        let frameRect = this._currentWindow.get_frame_rect();
c7fac9
-        let rect = { x: this._rect.x + frameRect.x, y: this._rect.y + frameRect.y, width: this._rect.width, height: this._rect.height };
c7fac9
+        let rect = { x: this._rect.x, y: this._rect.y,
c7fac9
+                     width: this._rect.width, height: this._rect.height };
c7fac9
+
c7fac9
+        if (this._currentWindow) {
c7fac9
+            let frameRect = this._currentWindow.get_frame_rect();
c7fac9
+            rect.x += frameRect.x;
c7fac9
+            rect.y += frameRect.y;
c7fac9
+        }
c7fac9
 
c7fac9
         return rect;
c7fac9
     }
c7fac9
-- 
c7fac9
2.20.1
c7fac9
c7fac9
c7fac9
From b89224c37afc9cbedbd776bfdd27c57849669fba Mon Sep 17 00:00:00 2001
c7fac9
From: Carlos Garnacho <carlosg@gnome.org>
c7fac9
Date: Fri, 29 Jun 2018 17:35:39 +0200
c7fac9
Subject: [PATCH 2/6] inputMethod: Handle IBusInputContext::forward-key-press
c7fac9
c7fac9
The input method may hint that certain keycodes should be pressed/released
c7fac9
besides the textual information in ::commit. An example is hitting space
c7fac9
in some IMs to commit text, where both ::commit happens, and an space is
c7fac9
visibly inserted. In order to handle this properly, we must honor
c7fac9
::forward-key-press.
c7fac9
c7fac9
In order to cater for the case that a keypress is forwarded while handling
c7fac9
that same keypress in a physical keyboard, check the current event being
c7fac9
handled and just forward it as-is if it matches. This is necessary to
c7fac9
prevent state from being doubly set, and the second event silenced away.
c7fac9
c7fac9
https://gitlab.gnome.org/GNOME/gnome-shell/issues/275
c7fac9
c7fac9
Closes: #275
c7fac9
---
c7fac9
 js/misc/inputMethod.js | 34 ++++++++++++++++++++++++++++++++++
c7fac9
 1 file changed, 34 insertions(+)
c7fac9
c7fac9
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
c7fac9
index 621483243..59b3d78d6 100644
c7fac9
--- a/js/misc/inputMethod.js
c7fac9
+++ b/js/misc/inputMethod.js
c7fac9
@@ -15,6 +15,8 @@ var InputMethod = new Lang.Class({
c7fac9
         this._purpose = 0;
c7fac9
         this._enabled = true;
c7fac9
         this._currentFocus = null;
c7fac9
+        this._currentEvent = null;
c7fac9
+        this._doForwardEvent = false;
c7fac9
         this._ibus = IBus.Bus.new_async();
c7fac9
         this._ibus.connect('connected', this._onConnected.bind(this));
c7fac9
         this._ibus.connect('disconnected', this._clear.bind(this));
c7fac9
@@ -25,6 +27,9 @@ var InputMethod = new Lang.Class({
c7fac9
                                                                  this._onSourceChanged.bind(this));
c7fac9
         this._currentSource = this._inputSourceManager.currentSource;
c7fac9
 
c7fac9
+        let deviceManager = Clutter.DeviceManager.get_default();
c7fac9
+        this._virtualDevice = deviceManager.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
c7fac9
+
c7fac9
         if (this._ibus.is_connected())
c7fac9
             this._onConnected();
c7fac9
     },
c7fac9
@@ -64,6 +69,7 @@ var InputMethod = new Lang.Class({
c7fac9
         this._context.connect('commit-text', this._onCommitText.bind(this));
c7fac9
         this._context.connect('delete-surrounding-text', this._onDeleteSurroundingText.bind(this));
c7fac9
         this._context.connect('update-preedit-text', this._onUpdatePreeditText.bind(this));
c7fac9
+        this._context.connect('forward-key-event', this._onForwardKeyEvent.bind(this));
c7fac9
 
c7fac9
         this._updateCapabilities();
c7fac9
     },
c7fac9
@@ -96,6 +102,24 @@ var InputMethod = new Lang.Class({
c7fac9
         this.set_preedit_text(str, pos);
c7fac9
     },
c7fac9
 
c7fac9
+    _onForwardKeyEvent(context, keyval, keycode, state) {
c7fac9
+        let press = (state & IBus.ModifierType.RELEASE_MASK) == 0;
c7fac9
+
c7fac9
+        if (this._currentEvent) {
c7fac9
+            // If we are handling this same event in filter_key_press(),
c7fac9
+            // just let it go through, sending the same event again will
c7fac9
+            // be silenced away because the key counts as pressed.
c7fac9
+            if (this._currentEvent.get_key_symbol() == keyval &&
c7fac9
+                (this._currentEvent.type() == Clutter.EventType.KEY_PRESS) == press) {
c7fac9
+                this._doForwardEvent = true;
c7fac9
+                return;
c7fac9
+            }
c7fac9
+        }
c7fac9
+
c7fac9
+        this._virtualDevice.notify_key(Clutter.get_current_event_time(), keycode,
c7fac9
+                                       press ? Clutter.KeyState.PRESSED : Clutter.KeyState.RELEASED);
c7fac9
+    },
c7fac9
+
c7fac9
     vfunc_focus_in(focus) {
c7fac9
         this._currentFocus = focus;
c7fac9
         if (this._context) {
c7fac9
@@ -197,13 +221,23 @@ var InputMethod = new Lang.Class({
c7fac9
 
c7fac9
         if (event.type() == Clutter.EventType.KEY_RELEASE)
c7fac9
             state |= IBus.ModifierType.RELEASE_MASK;
c7fac9
+
c7fac9
+        this._currentEvent = event;
c7fac9
+        this._doForwardEvent = false;
c7fac9
+
c7fac9
         this._context.process_key_event_async(event.get_key_symbol(),
c7fac9
                                               event.get_key_code() - 8, // Convert XKB keycodes to evcodes
c7fac9
                                               state, -1, null,
c7fac9
                                               (context, res) => {
c7fac9
                                                   try {
c7fac9
                                                       let retval = context.process_key_event_async_finish(res);
c7fac9
+
c7fac9
+                                                      if (this._doForwardEvent)
c7fac9
+                                                          retval = false;
c7fac9
+
c7fac9
                                                       this.notify_key_event(event, retval);
c7fac9
+                                                      this._doForwardEvent = false;
c7fac9
+                                                      this._currentEvent = null;
c7fac9
                                                   } catch (e) {
c7fac9
                                                       log('Error processing key on IM: ' + e.message);
c7fac9
                                                   }
c7fac9
-- 
c7fac9
2.20.1
c7fac9
c7fac9
c7fac9
From f8040e59811cd28d9c55d766d6f4c80cf45a226d Mon Sep 17 00:00:00 2001
c7fac9
From: Takao Fujiwara <tfujiwar@redhat.com>
c7fac9
Date: Tue, 21 Aug 2018 20:21:53 +0900
c7fac9
Subject: [PATCH 3/6] inputMethod: Fix to hide preedit text
c7fac9
c7fac9
ibus_engine_update_preedit_text() should hide the pre-edit text
c7fac9
when visible == false.
c7fac9
c7fac9
https://gitlab.gnome.org/GNOME/gnome-shell/issues/431
c7fac9
---
c7fac9
 js/misc/inputMethod.js | 25 +++++++++++++++++++++----
c7fac9
 1 file changed, 21 insertions(+), 4 deletions(-)
c7fac9
c7fac9
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
c7fac9
index 59b3d78d6..320a6cc33 100644
c7fac9
--- a/js/misc/inputMethod.js
c7fac9
+++ b/js/misc/inputMethod.js
c7fac9
@@ -17,6 +17,8 @@ var InputMethod = new Lang.Class({
c7fac9
         this._currentFocus = null;
c7fac9
         this._currentEvent = null;
c7fac9
         this._doForwardEvent = false;
c7fac9
+        this._preeditStr = '';
c7fac9
+        this._preeditPos = 0;
c7fac9
         this._ibus = IBus.Bus.new_async();
c7fac9
         this._ibus.connect('connected', this._onConnected.bind(this));
c7fac9
         this._ibus.connect('disconnected', this._clear.bind(this));
c7fac9
@@ -69,6 +71,8 @@ var InputMethod = new Lang.Class({
c7fac9
         this._context.connect('commit-text', this._onCommitText.bind(this));
c7fac9
         this._context.connect('delete-surrounding-text', this._onDeleteSurroundingText.bind(this));
c7fac9
         this._context.connect('update-preedit-text', this._onUpdatePreeditText.bind(this));
c7fac9
+        this._context.connect('show-preedit-text', this._onShowPreeditText.bind(this));
c7fac9
+        this._context.connect('hide-preedit-text', this._onHidePreeditText.bind(this));
c7fac9
         this._context.connect('forward-key-event', this._onForwardKeyEvent.bind(this));
c7fac9
 
c7fac9
         this._updateCapabilities();
c7fac9
@@ -79,6 +83,8 @@ var InputMethod = new Lang.Class({
c7fac9
         this._hints = 0;
c7fac9
         this._purpose = 0;
c7fac9
         this._enabled = false;
c7fac9
+        this._preeditStr = ''
c7fac9
+        this._preeditPos = 0;
c7fac9
     },
c7fac9
 
c7fac9
     _emitRequestSurrounding() {
c7fac9
@@ -95,11 +101,22 @@ var InputMethod = new Lang.Class({
c7fac9
     },
c7fac9
 
c7fac9
     _onUpdatePreeditText(context, text, pos, visible) {
c7fac9
-        let str = null;
c7fac9
-        if (visible && text != null)
c7fac9
-            str = text.get_text();
c7fac9
+        if (text == null)
c7fac9
+            return;
c7fac9
+        this._preeditStr = text.get_text();
c7fac9
+        this._preeditPos = pos;
c7fac9
+        if (visible)
c7fac9
+            this.set_preedit_text(this._preeditStr, pos);
c7fac9
+        else
c7fac9
+            this.set_preedit_text(null, pos);
c7fac9
+    },
c7fac9
+
c7fac9
+    _onShowPreeditText(context) {
c7fac9
+        this.set_preedit_text(this._preeditStr, this._preeditPos);
c7fac9
+    },
c7fac9
 
c7fac9
-        this.set_preedit_text(str, pos);
c7fac9
+    _onHidePreeditText(context) {
c7fac9
+        this.set_preedit_text(null, this._preeditPos);
c7fac9
     },
c7fac9
 
c7fac9
     _onForwardKeyEvent(context, keyval, keycode, state) {
c7fac9
-- 
c7fac9
2.20.1
c7fac9
c7fac9
c7fac9
From 43c841a6b9f79b136f8bfe34a28b5c9681006ae7 Mon Sep 17 00:00:00 2001
c7fac9
From: Andrea Azzarone <andrea.azzarone@canonical.com>
c7fac9
Date: Mon, 17 Sep 2018 18:00:04 +0200
c7fac9
Subject: [PATCH 4/6] inputMethod: Add a null-check for text in
c7fac9
 vfunc_set_surrounding.
c7fac9
c7fac9
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/579
c7fac9
---
c7fac9
 js/misc/inputMethod.js | 2 +-
c7fac9
 1 file changed, 1 insertion(+), 1 deletion(-)
c7fac9
c7fac9
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
c7fac9
index 320a6cc33..ec84f7277 100644
c7fac9
--- a/js/misc/inputMethod.js
c7fac9
+++ b/js/misc/inputMethod.js
c7fac9
@@ -176,7 +176,7 @@ var InputMethod = new Lang.Class({
c7fac9
     },
c7fac9
 
c7fac9
     vfunc_set_surrounding(text, cursor, anchor) {
c7fac9
-        if (this._context)
c7fac9
+        if (this._context && text)
c7fac9
             this._context.set_surrounding_text(text, cursor, anchor);
c7fac9
     },
c7fac9
 
c7fac9
-- 
c7fac9
2.20.1
c7fac9
c7fac9
c7fac9
From 5f03edcadcada801100bab027188660fb2a4c3f6 Mon Sep 17 00:00:00 2001
c7fac9
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
c7fac9
Date: Tue, 11 Sep 2018 15:36:35 +0200
c7fac9
Subject: [PATCH 5/6] inputMethod: Fix setting surrounding text
c7fac9
c7fac9
The underlying ibus method expects an object of type IBusText rather
c7fac9
than a plain string.
c7fac9
c7fac9
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/228
c7fac9
---
c7fac9
 js/misc/inputMethod.js | 7 +++++--
c7fac9
 1 file changed, 5 insertions(+), 2 deletions(-)
c7fac9
c7fac9
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
c7fac9
index ec84f7277..7fb78178a 100644
c7fac9
--- a/js/misc/inputMethod.js
c7fac9
+++ b/js/misc/inputMethod.js
c7fac9
@@ -176,8 +176,11 @@ var InputMethod = new Lang.Class({
c7fac9
     },
c7fac9
 
c7fac9
     vfunc_set_surrounding(text, cursor, anchor) {
c7fac9
-        if (this._context && text)
c7fac9
-            this._context.set_surrounding_text(text, cursor, anchor);
c7fac9
+        if (!this._context || !text)
c7fac9
+            return;
c7fac9
+
c7fac9
+        let ibusText = IBus.Text.new_from_string(text);
c7fac9
+        this._context.set_surrounding_text(ibusText, cursor, anchor);
c7fac9
     },
c7fac9
 
c7fac9
     vfunc_update_content_hints(hints) {
c7fac9
-- 
c7fac9
2.20.1
c7fac9
c7fac9
c7fac9
From 4ed4039ae031f1ed16bac2e7729c84e300f90534 Mon Sep 17 00:00:00 2001
c7fac9
From: Carlos Garnacho <carlosg@gnome.org>
c7fac9
Date: Thu, 27 Sep 2018 21:09:02 +0200
c7fac9
Subject: [PATCH 6/6] inputMethod: Use forward_key() method to forward key
c7fac9
 events
c7fac9
c7fac9
ClutterVirtualInputDevice has the limitation that event flags won't be
c7fac9
made to contain CLUTTER_EVENT_FLAG_INPUT_METHOD, possibly causing feedback
c7fac9
loops.
c7fac9
c7fac9
As the event gets injected up the platform dependent bits, we can avoid
c7fac9
care on not pressing the same key twice, we still expect coherence between
c7fac9
key presses and releases from the IM though.
c7fac9
c7fac9
https://gitlab.gnome.org/GNOME/gnome-shell/issues/531
c7fac9
---
c7fac9
 js/misc/inputMethod.js | 34 ++++++++--------------------------
c7fac9
 1 file changed, 8 insertions(+), 26 deletions(-)
c7fac9
c7fac9
diff --git a/js/misc/inputMethod.js b/js/misc/inputMethod.js
c7fac9
index 7fb78178a..4a92dc49b 100644
c7fac9
--- a/js/misc/inputMethod.js
c7fac9
+++ b/js/misc/inputMethod.js
c7fac9
@@ -15,8 +15,6 @@ var InputMethod = new Lang.Class({
c7fac9
         this._purpose = 0;
c7fac9
         this._enabled = true;
c7fac9
         this._currentFocus = null;
c7fac9
-        this._currentEvent = null;
c7fac9
-        this._doForwardEvent = false;
c7fac9
         this._preeditStr = '';
c7fac9
         this._preeditPos = 0;
c7fac9
         this._ibus = IBus.Bus.new_async();
c7fac9
@@ -29,9 +27,6 @@ var InputMethod = new Lang.Class({
c7fac9
                                                                  this._onSourceChanged.bind(this));
c7fac9
         this._currentSource = this._inputSourceManager.currentSource;
c7fac9
 
c7fac9
-        let deviceManager = Clutter.DeviceManager.get_default();
c7fac9
-        this._virtualDevice = deviceManager.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
c7fac9
-
c7fac9
         if (this._ibus.is_connected())
c7fac9
             this._onConnected();
c7fac9
     },
c7fac9
@@ -121,20 +116,16 @@ var InputMethod = new Lang.Class({
c7fac9
 
c7fac9
     _onForwardKeyEvent(context, keyval, keycode, state) {
c7fac9
         let press = (state & IBus.ModifierType.RELEASE_MASK) == 0;
c7fac9
+        state &= ~(IBus.ModifierType.RELEASE_MASK);
c7fac9
 
c7fac9
-        if (this._currentEvent) {
c7fac9
-            // If we are handling this same event in filter_key_press(),
c7fac9
-            // just let it go through, sending the same event again will
c7fac9
-            // be silenced away because the key counts as pressed.
c7fac9
-            if (this._currentEvent.get_key_symbol() == keyval &&
c7fac9
-                (this._currentEvent.type() == Clutter.EventType.KEY_PRESS) == press) {
c7fac9
-                this._doForwardEvent = true;
c7fac9
-                return;
c7fac9
-            }
c7fac9
-        }
c7fac9
+        let curEvent = Clutter.get_current_event();
c7fac9
+        let time;
c7fac9
+        if (curEvent)
c7fac9
+            time = curEvent.get_time();
c7fac9
+        else
c7fac9
+            time = global.display.get_current_time_roundtrip();
c7fac9
 
c7fac9
-        this._virtualDevice.notify_key(Clutter.get_current_event_time(), keycode,
c7fac9
-                                       press ? Clutter.KeyState.PRESSED : Clutter.KeyState.RELEASED);
c7fac9
+        this.forward_key(keyval, keycode + 8, state & Clutter.ModifierType.MODIFIER_MASK, time, press);
c7fac9
     },
c7fac9
 
c7fac9
     vfunc_focus_in(focus) {
c7fac9
@@ -242,22 +233,13 @@ var InputMethod = new Lang.Class({
c7fac9
         if (event.type() == Clutter.EventType.KEY_RELEASE)
c7fac9
             state |= IBus.ModifierType.RELEASE_MASK;
c7fac9
 
c7fac9
-        this._currentEvent = event;
c7fac9
-        this._doForwardEvent = false;
c7fac9
-
c7fac9
         this._context.process_key_event_async(event.get_key_symbol(),
c7fac9
                                               event.get_key_code() - 8, // Convert XKB keycodes to evcodes
c7fac9
                                               state, -1, null,
c7fac9
                                               (context, res) => {
c7fac9
                                                   try {
c7fac9
                                                       let retval = context.process_key_event_async_finish(res);
c7fac9
-
c7fac9
-                                                      if (this._doForwardEvent)
c7fac9
-                                                          retval = false;
c7fac9
-
c7fac9
                                                       this.notify_key_event(event, retval);
c7fac9
-                                                      this._doForwardEvent = false;
c7fac9
-                                                      this._currentEvent = null;
c7fac9
                                                   } catch (e) {
c7fac9
                                                       log('Error processing key on IM: ' + e.message);
c7fac9
                                                   }
c7fac9
-- 
c7fac9
2.20.1
c7fac9