[polari] chatView: Compress scroll events



commit 61e126415a59917ceadb8bec7c1d91f14706c28b
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Nov 29 12:12:41 2013 +0000

    chatView: Compress scroll events
    
    In order to mark messages read as we scroll by, we do not have to
    process every single scroll event; save some CPU time by only
    checking at most every 100ms.
    (If we do miss an unread message this way, it is safe to assume that
    it scrolled by too fast to be actually read anyway)

 src/chatView.js |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index d1d2a3c..b8e154e 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -15,6 +15,8 @@ const MAX_NICK_CHARS = 8;
 const IGNORE_STATUS_TIME = 5;
 const TP_CURRENT_TIME = GLib.MAXUINT32;
 
+const SCROLL_TIMEOUT = 100; // ms
+
 const TIMESTAMP_INTERVAL = 300; // seconds of inactivity after which to
                                 // insert a timestamp
 
@@ -232,7 +234,7 @@ const ChatView = new Lang.Class({
                             Lang.bind(this, this._updateToplevel));
         this.widget.connect('scroll-event', Lang.bind(this ,this._onScroll));
         this.widget.vadjustment.connect('value-changed',
-                                 Lang.bind(this, this._checkMessages));
+                                        Lang.bind(this, this._onValueChanged));
         this.widget.vadjustment.connect('changed',
                                  Lang.bind(this, this._updateScroll));
         this._view.connect('button-release-event',
@@ -365,6 +367,18 @@ const ChatView = new Lang.Class({
         return false;
     },
 
+    _onValueChanged: function() {
+        if (this._valueChangedId)
+            return;
+
+        this._valueChangedId = Mainloop.timeout_add(SCROLL_TIMEOUT, Lang.bind(this,
+            function() {
+                this._checkMessages();
+                this._valueChangedId = 0;
+                return false;
+            }));
+    },
+
     _pendingMessageRemoved: function(channel, message) {
         let [id,] = message.get_pending_message_id();
         if (this._pending[id])


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