[polari] chatView: Simplify tracking of toplevel focus



commit cb11ac9a2f43a3e8c9ab73f1a36ad7ed9414ce69
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Oct 15 18:19:48 2013 +0200

    chatView: Simplify tracking of toplevel focus
    
    Rather than tracking the toplevel hierarchy, we can just watch the
    chat widget's state flags for BACKDROP.

 src/chatView.js |   24 +++++++-----------------
 1 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index b710952..749ebae 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -162,8 +162,8 @@ const ChatView = new Lang.Class({
         this.widget.connect('screen-changed',
                             Lang.bind(this, this._updateIndent));
         this.widget.connect('parent-set', Lang.bind(this, this._onParentSet));
-        this.widget.connect('hierarchy-changed',
-                            Lang.bind(this, this._onHierarchyChanged));
+        this.widget.connect('state-flags-changed',
+                            Lang.bind(this, this._updateToplevel));
         this.widget.vadjustment.connect('value-changed',
                                  Lang.bind(this, this._checkMessages));
         this.widget.vadjustment.connect('changed',
@@ -212,27 +212,17 @@ const ChatView = new Lang.Class({
         this._updateActive();
     },
 
-    _onHierarchyChanged: function(w, oldToplevel) {
-        if (oldToplevel)
-            oldToplevel.disconnect(this._toplevelFocusNotifyId);
-
-        let newToplevel = this.widget.get_toplevel();
-        if (!newToplevel)
-            return;
-
-        this._toplevelFocusNotifyId =
-            newToplevel.connect('notify::has-toplevel-focus',
-                                Lang.bind(this, this._updateToplevel));
-        this._updateToplevel();
-    },
-
     _updateActive: function() {
         this._active = this.widget.get_parent().get_visible_child() == this.widget;
         this._checkMessages();
     },
 
     _updateToplevel: function() {
-        this._toplevelFocus = this.widget.get_toplevel().has_toplevel_focus;
+        let flags = this.widget.get_state_flags();
+        let toplevelFocus = !(flags & Gtk.StateFlags.BACKDROP);
+        if (this._toplevelFocus == toplevelFocus)
+            return;
+        this._toplevelFocus = toplevelFocus;
         this._checkMessages();
     },
 


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