[gnome-maps/wip/mlundblad/touch-search-fixes: 2/2] mainWindow: Don't focus search entry by default



commit d0e070b2a1fed3c8e1fc0a5be33b57694352f6cd
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Aug 8 21:45:37 2017 +0200

    mainWindow: Don't focus search entry by default
    
    Focusing the search entry by default makes the OSK come up
    on touch devices when launching when no physical keyboard is available.
    Instead focus it in the key press handler when no other entry is focused
    (and propagate the event in there).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785369

 src/mainWindow.js |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a45f4e6..671725c 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -271,21 +271,34 @@ const MainWindow = new Lang.Class({
          * hijack the key-press to the main window and make sure that
          * they reach the entry before they can be swallowed as accelerator.
          */
-        this.connect('key-press-event', function(window, event) {
+        this.connect('key-press-event', (function(window, event) {
             let focusWidget = window.get_focus();
             let keyval = event.get_keyval()[1];
-            let keys = [Gdk.KEY_plus,
-                        Gdk.KEY_minus,
+            let keys = [Gdk.KEY_plus, Gdk.KEY_KP_Add,
+                        Gdk.KEY_minus, Gdk.KEY_KP_Subtract,
                         Gdk.KEY_equal];
+            let isPassThroughKey = keys.indexOf(keyval) !== -1;
+
+            /* if no entry is focused, and the key is not one we should treat
+             * as a zoom accelerator when no entry is focused, focus the
+             * main search entry in the headebar to propaget the keypress there
+             */
+            if (!(focusWidget instanceof Gtk.Entry) && !isPassThroughKey) {
+                /* if the search entry does not handle the event, pass it on
+                 * instead of activating the entry
+                 */
+                if (this._placeEntry.handle_event(event) === Gdk.EVENT_PROPAGATE)
+                    return false;
+
+                this._placeEntry.has_focus = true;
+                focusWidget = this._placeEntry;
+            }
 
-            if (!(focusWidget instanceof Gtk.Entry))
-                return false;
-
-            if (keys.indexOf(keyval) !== -1)
+            if (focusWidget instanceof Gtk.Entry)
                 return focusWidget.event(event);
 
             return false;
-        });
+        }).bind(this));
     },
 
     _updateLocationSensitivity: function() {
@@ -299,7 +312,6 @@ const MainWindow = new Lang.Class({
     _initHeaderbar: function() {
         this._placeEntry = this._createPlaceEntry();
         this._headerBar.custom_title = this._placeEntry;
-        this._placeEntry.has_focus = true;
 
         let favoritesPopover = this._favoritesButton.popover;
         this._favoritesButton.sensitive = favoritesPopover.rows > 0;


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