diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 155f33ed4..00745ee7d 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -41,6 +41,7 @@ var APP_ICON_SCALE_IN_TIME = 500; var APP_ICON_SCALE_IN_DELAY = 700; const OVERSHOOT_THRESHOLD = 20; +const OVERSHOOT_TIMEOUT = 1000; const SWITCHEROO_BUS_NAME = 'net.hadess.SwitcherooControl'; const SWITCHEROO_OBJECT_PATH = '/net/hadess/SwitcherooControl'; @@ -379,6 +380,7 @@ var AllView = GObject.registerClass({ this._availHeight = 0; this._lastOvershootY = -1; + this._lastOvershootTimeoutId = 0; Main.overview.connect('hidden', () => this.goToPage(0)); this._grid.connect('space-opened', () => { @@ -774,6 +776,13 @@ var AllView = GObject.registerClass({ this.folderIcons[i].adaptToSize(availWidth, availHeight); } + _resetOvershoot() { + if (this._lastOvershootTimeoutId) + GLib.source_remove(this._lastOvershootTimeoutId); + this._lastOvershootTimeoutId = 0; + this._lastOvershootY = -1; + } + _handleDragOvershoot(dragEvent) { let [, gridY] = this.get_transformed_position(); let [, gridHeight] = this.get_transformed_size(); @@ -787,7 +796,8 @@ var AllView = GObject.registerClass({ if (dragEvent.y > gridY && dragEvent.y < gridBottom) { // Check whether we moved out the area of the last switch if (Math.abs(this._lastOvershootY - dragEvent.y) > OVERSHOOT_THRESHOLD) - this._lastOvershootY = -1; + this._resetOvershoot(); + return; } @@ -795,19 +805,29 @@ var AllView = GObject.registerClass({ if (this._lastOvershootY >= 0) return; + let currentY = this._adjustment.value; + let maxY = this._adjustment.upper - this._adjustment.page_size; + + if (dragEvent.y <= gridY && currentY > 0) + this.goToPage(this._grid.currentPage - 1); + else if (dragEvent.y >= gridBottom && currentY < maxY) + this.goToPage(this._grid.currentPage + 1); + else + return; // don't go beyond first/last page + this._lastOvershootY = dragEvent.y; - // Moving above the grid - let currentY = this._adjustment.value; - if (dragEvent.y <= gridY && currentY > 0) { - this.goToPage(this._grid.currentPage - 1); - return; - } + if (this._lastOvershootTimeoutId > 0) + GLib.source_remove(this._lastOvershootTimeoutId); - // Moving below the grid - let maxY = this._adjustment.upper - this._adjustment.page_size; - if (dragEvent.y >= gridBottom && currentY < maxY) - this.goToPage(this._grid.currentPage + 1); + this._lastOvershootTimeoutId = + GLib.timeout_add(GLib.PRIORITY_DEFAULT, OVERSHOOT_TIMEOUT, () => { + this._resetOvershoot(); + this._handleDragOvershoot(dragEvent); + return GLib.SOURCE_REMOVE; + }); + GLib.Source.set_name_by_id(this._lastOvershootTimeoutId, + '[gnome-shell] this._lastOvershootTimeoutId'); } _onDragBegin() { @@ -841,7 +861,7 @@ var AllView = GObject.registerClass({ } this._eventBlocker.visible = this._currentPopup !== null; - this._lastOvershootY = -1; + this._resetOvershoot(); } _canAccept(source) {