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



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

 src/mainWindow.js |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index fd97733..361d4fd 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,
                         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]