[gnome-shell/wip/focus-management: 8/8] messageTray: Remove pointer tracking to keep notifications on screen



commit deb3736849154be91f6f6affc4fe4bce636bb4b7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed May 22 13:13:26 2013 -0400

    messageTray: Remove pointer tracking to keep notifications on screen
    
    There's a lot of code dedicated to keeping track of the pointer position
    so we can be smarter about keeping notifications on screen, but the code
    is error-prone and made more sense in the 3.4 days when getting to the
    tray was more of an arduous task.

 js/ui/messageTray.js |  117 ++------------------------------------------------
 1 files changed, 4 insertions(+), 113 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 999fe6d..f9b3fdb 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -31,15 +31,6 @@ const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
 
 const ANIMATION_TIME = 0.2;
 const NOTIFICATION_TIMEOUT = 4;
-const SUMMARY_TIMEOUT = 1;
-const LONGER_SUMMARY_TIMEOUT = 4;
-
-const HIDE_TIMEOUT = 0.2;
-const LONGER_HIDE_TIMEOUT = 0.6;
-
-// We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
-// range from the point where it left the tray.
-const MOUSE_LEFT_ACTOR_THRESHOLD = 20;
 
 // Time the user needs to leave the mouse on the bottom pixel row to open the tray
 const TRAY_DWELL_TIME = 1000; // ms
@@ -1686,8 +1677,6 @@ const MessageTray = new Lang.Class({
 
         this._trayState = State.HIDDEN;
         this._traySummoned = false;
-        this._useLongerNotificationLeftTimeout = false;
-        this._trayLeftTimeoutId = 0;
 
         // pointerInNotification is sort of a misnomer -- it tracks whether
         // a message tray notification should expand. The value is
@@ -2158,47 +2147,11 @@ const MessageTray = new Lang.Class({
         if (this._notificationHovered) {
             // No dwell inside notifications at the bottom of the screen
             this._cancelTrayDwell();
-
-            this._useLongerNotificationLeftTimeout = false;
-            if (this._notificationLeftTimeoutId) {
-                Mainloop.source_remove(this._notificationLeftTimeoutId);
-                this._notificationLeftTimeoutId = 0;
-                this._notificationLeftMouseX = -1;
-                this._notificationLeftMouseY = -1;
-                return;
-            }
-
-            if (this._showNotificationMouseX >= 0) {
-                let actorAtShowNotificationPosition =
-                    global.stage.get_actor_at_pos(Clutter.PickMode.ALL, this._showNotificationMouseX, 
this._showNotificationMouseY);
-                this._showNotificationMouseX = -1;
-                this._showNotificationMouseY = -1;
-                // Don't set this._pointerInNotification to true if the pointer was initially in the area 
where the notification
-                // popped up. That way we will not be expanding notifications that happen to pop up over the 
pointer
-                // automatically. Instead, the user is able to expand the notification by mousing away from 
it and then
-                // mousing back in. Because this is an expected action, we set the boolean flag that 
indicates that a longer
-                // timeout should be used before popping down the notification.
-                if (this.actor.contains(actorAtShowNotificationPosition)) {
-                    this._useLongerNotificationLeftTimeout = true;
-                    return;
-                }
-            }
             this._pointerInNotification = true;
             this._updateState();
         } else {
-            // We record the position of the mouse the moment it leaves the tray. These coordinates are used 
in
-            // this._onNotificationLeftTimeout() to determine if the mouse has moved far enough during the 
initial timeout for us
-            // to consider that the user intended to leave the tray and therefore hide the tray. If the 
mouse is still
-            // close to its previous position, we extend the timeout once.
-            let [x, y, mods] = global.get_pointer();
-            this._notificationLeftMouseX = x;
-            this._notificationLeftMouseY = y;
-
-            // We wait just a little before hiding the message tray in case the user quickly moves the mouse 
back into it.
-            // We wait for a longer period if the notification popped up where the mouse pointer was already 
positioned.
-            // That gives the user more time to mouse away from the notification and mouse back in in order 
to expand it.
-            let timeout = this._useLongerNotificationLeftTimeout ? LONGER_HIDE_TIMEOUT * 1000 : HIDE_TIMEOUT 
* 1000;
-            this._notificationLeftTimeoutId = Mainloop.timeout_add(timeout, Lang.bind(this, 
this._onNotificationLeftTimeout));
+            this._pointerInNotification = false;
+            this._updateNotificationTimeout(600);
         }
     },
 
@@ -2222,28 +2175,6 @@ const MessageTray = new Lang.Class({
         this._updateState();
     },
 
-    _onNotificationLeftTimeout: function() {
-        let [x, y, mods] = global.get_pointer();
-        // We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to 
either side or up.
-        // We don't check how far down the mouse moved because any point above the tray, but below the exit 
coordinate,
-        // is close to the tray.
-        if (this._notificationLeftMouseX > -1 &&
-            y > this._notificationLeftMouseY - MOUSE_LEFT_ACTOR_THRESHOLD &&
-            x < this._notificationLeftMouseX + MOUSE_LEFT_ACTOR_THRESHOLD &&
-            x > this._notificationLeftMouseX - MOUSE_LEFT_ACTOR_THRESHOLD) {
-            this._notificationLeftMouseX = -1;
-            this._notificationLeftTimeoutId = Mainloop.timeout_add(LONGER_HIDE_TIMEOUT * 1000,
-                                                             Lang.bind(this, 
this._onNotificationLeftTimeout));
-        } else {
-            this._notificationLeftTimeoutId = 0;
-            this._useLongerNotificationLeftTimeout = false;
-            this._pointerInNotification = false;
-            this._updateNotificationTimeout(0);
-            this._updateState();
-        }
-        return false;
-    },
-
     _escapeTray: function() {
         this._pointerInNotification = false;
         this._traySummoned = false;
@@ -2486,20 +2417,6 @@ const MessageTray = new Lang.Class({
         this._notificationWidget.show();
 
         this._updateShowingNotification();
-
-        let [x, y, mods] = global.get_pointer();
-        // We save the position of the mouse at the time when we started showing the notification
-        // in order to determine if the notification popped up under it. We make that check if
-        // the user starts moving the mouse and _onNotificationHoverChanged() gets called. We don't
-        // expand the notification if it just happened to pop up under the mouse unless the user
-        // explicitly mouses away from it and then mouses back in.
-        this._showNotificationMouseX = x;
-        this._showNotificationMouseY = y;
-        // We save the coordinates of the mouse at the time when we started showing the notification
-        // and then we update it in _notificationTimeout(). We don't pop down the notification if
-        // the mouse is moving towards it or within it.
-        this._lastSeenMouseX = x;
-        this._lastSeenMouseY = y;
     },
 
     _updateShowingNotification: function() {
@@ -2551,26 +2468,8 @@ const MessageTray = new Lang.Class({
     },
 
     _notificationTimeout: function() {
-        let [x, y, mods] = global.get_pointer();
-        if (y > this._lastSeenMouseY + 10 && !this._notificationHovered) {
-            // The mouse is moving towards the notification, so don't
-            // hide it yet. (We just create a new timeout (and destroy
-            // the old one) each time because the bookkeeping is
-            // simpler.)
-            this._updateNotificationTimeout(1000);
-        } else if (this._useLongerNotificationLeftTimeout && !this._notificationLeftTimeoutId &&
-                  (x != this._lastSeenMouseX || y != this._lastSeenMouseY)) {
-            // Refresh the timeout if the notification originally
-            // popped up under the pointer, and the pointer is hovering
-            // inside it.
-            this._updateNotificationTimeout(1000);
-        } else {
-            this._notificationTimeoutId = 0;
-            this._updateState();
-        }
-
-        this._lastSeenMouseX = x;
-        this._lastSeenMouseY = y;
+        this._notificationTimeoutId = 0;
+        this._updateState();
         return false;
     },
 
@@ -2590,14 +2489,6 @@ const MessageTray = new Lang.Class({
             this._notificationUnfocusedId = 0;
         }
 
-        this._useLongerNotificationLeftTimeout = false;
-        if (this._notificationLeftTimeoutId) {
-            Mainloop.source_remove(this._notificationLeftTimeoutId);
-            this._notificationLeftTimeoutId = 0;
-            this._notificationLeftMouseX = -1;
-            this._notificationLeftMouseY = -1;
-        }
-
         if (this._notificationRemoved) {
             Tweener.removeTweens(this._notificationWidget);
             this._notificationWidget.y = this.actor.height;


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