[polari] entryArea: Don't grab focus unconditionally when becoming sensitive



commit 8eb6f943b62113aaa279ca64d2905b2990237774
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Feb 2 22:05:15 2016 +0100

    entryArea: Don't grab focus unconditionally when becoming sensitive
    
    Our current idea for supporting server passwords is to allow users to
    enter a password on authentication errors using the header popovers in
    the room list. As this may happen while the active room is connecting,
    we should make sure to not steal the focus while the user is typing
    her password.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709824

 src/entryArea.js |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index 416671f..a4047d4 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -164,17 +164,16 @@ const EntryArea = new Lang.Class({
         this._completion.setCompletions(nicks);
     },
 
-    _onKeyPressEvent: function(w, event) {
-        if (!this._chatEntry.get_mapped())
-            return Gdk.EVENT_PROPAGATE;
-
-        if (!this.sensitive)
-            return Gdk.EVENT_PROPAGATE;
-
-        if (this._chatEntry.has_focus)
-            return Gdk.EVENT_PROPAGATE;
+    _canFocusChatEntry: function() {
+        let toplevelFocus = this._chatEntry.get_toplevel().get_focus();
+        return this.sensitive &&
+               this._chatEntry.get_mapped() &&
+               !this._chatEntry.has_focus &&
+               !(toplevelFocus instanceof Gtk.Entry);
+    },
 
-        if (this._chatEntry.get_toplevel().get_focus() instanceof Gtk.Entry)
+    _onKeyPressEvent: function(w, event) {
+        if (!this._canFocusChatEntry())
             return Gdk.EVENT_PROPAGATE;
 
         let [, keyval] = event.get_keyval();
@@ -219,14 +218,8 @@ const EntryArea = new Lang.Class({
     },
 
     _onSensitiveChanged: function() {
-        if (!this.sensitive)
-            return;
-
-        Mainloop.idle_add(Lang.bind(this,
-            function() {
-                this._chatEntry.grab_focus();
-                return GLib.SOURCE_REMOVE;
-            }));
+        if (this._canFocusChatEntry())
+            this._chatEntry.grab_focus();
     },
 
     _onChannelChanged: function(room) {


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