From d4259fa8aa272727096ab66748d0d8e3287ce7f8 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 1 Mar 2013 15:21:25 -0500 Subject: [PATCH] layout: Prevent going into negatives with the pressure We capped each event to 15px of travel, but we didn't do the same cap when subtracting events that were too old. --- js/ui/layout.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/js/ui/layout.js b/js/ui/layout.js index b178b53c8..bcc0dda6e 100644 --- a/js/ui/layout.js +++ b/js/ui/layout.js @@ -1296,19 +1296,16 @@ const PressureBarrier = new Lang.Class({ return Math.abs(event.dy); }, - _isBarrierEventTooOld: function(event) { - // Ignore all events older than this time - let threshold = this._lastTime - this._timeout; - return event.time < threshold; - }, - _trimBarrierEvents: function() { // Events are guaranteed to be sorted in time order from // oldest to newest, so just look for the first old event, // and then chop events after that off. let i = 0; + let threshold = this._lastTime - this._timeout; + while (i < this._barrierEvents.length) { - if (!this._isBarrierEventTooOld(this._barrierEvents[i])) + let [time, distance] = this._barrierEvents[i]; + if (time >= threshold) break; i++; } @@ -1316,7 +1313,8 @@ const PressureBarrier = new Lang.Class({ let firstNewEvent = i; for (i = 0; i < firstNewEvent; i++) { - this._currentPressure -= this._getDistanceAcrossBarrier(this._barrierEvents[i]); + let [time, distance] = this._barrierEvents[i]; + this._currentPressure -= distance; } this._barrierEvents = this._barrierEvents.slice(firstNewEvent); @@ -1362,8 +1360,10 @@ const PressureBarrier = new Lang.Class({ this._lastTime = event.time; this._trimBarrierEvents(); - this._barrierEvents.push(event); - this._currentPressure += Math.min(15, distance); + distance = Math.min(15, distance); + + this._barrierEvents.push([event.time, distance]); + this._currentPressure += distance; if (this._currentPressure >= this._threshold) this._trigger();