[gnome-shell/gbsneto/custom-icon-positions: 4/20] appDisplay: Move icons when hovering the grid



commit 4a50cf637e7eb59b56a2ad24e08b75604d08de3b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jun 22 18:22:13 2020 -0300

    appDisplay: Move icons when hovering the grid
    
    Implement a minimal version of the reflow-on-hover behavior,
    which gives a better sense of physicality to the grid.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

 js/ui/appDisplay.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index dc5d89d9fb..dbeac0967e 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -36,6 +36,8 @@ const FOLDER_DIALOG_ANIMATION_TIME = 200;
 const OVERSHOOT_THRESHOLD = 20;
 const OVERSHOOT_TIMEOUT = 1000;
 
+const DELAYED_MOVE_TIMEOUT = 1500;
+
 let discreteGpuAvailable = false;
 
 function _getCategories(info) {
@@ -559,6 +561,8 @@ class AppDisplay extends BaseAppView {
 
         this._lastOvershootY = -1;
         this._lastOvershootTimeoutId = 0;
+        this._delayedMoveId = 0;
+        this._targetDropPosition = null;
 
         Main.overview.connect('hidden', () => this.goToPage(0));
 
@@ -595,6 +599,8 @@ class AppDisplay extends BaseAppView {
     }
 
     _onDestroy() {
+        this._removeDelayedMove();
+
         if (this._scrollTimeoutId !== 0) {
             GLib.source_remove(this._scrollTimeoutId);
             this._scrollTimeoutId = 0;
@@ -806,6 +812,50 @@ class AppDisplay extends BaseAppView {
         });
     }
 
+    _removeDelayedMove() {
+        if (this._delayedMoveId > 0) {
+            GLib.source_remove(this._delayedMoveId);
+            this._delayedMoveId = 0;
+        }
+        this._targetDropPosition = null;
+    }
+
+    _maybeMoveItem(dragEvent) {
+        const [success, x, y] =
+            this._grid.transform_stage_point(dragEvent.x, dragEvent.y);
+
+        if (!success)
+            return;
+
+        const { source } = dragEvent;
+        const [item, dragLocation] = this.getDropTarget(x, y);
+
+        // Dragging over invalid parts of the grid cancels the timeout
+        if (!item ||
+            item === source ||
+            dragLocation === IconGrid.DragLocation.ON_ICON) {
+            this._removeDelayedMove();
+            return;
+        }
+
+        const [page, position] = this._grid.getItemPosition(item);
+
+        if (!this._targetDropPosition ||
+            this._targetDropPosition.page !== page ||
+            this._targetDropPosition.position !== position) {
+            // Update the item with a small delay
+            this._removeDelayedMove();
+            this._targetDropPosition = { page, position };
+
+            this._delayedMoveId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
+                DELAYED_MOVE_TIMEOUT, () => {
+                    this.moveItem(source, page, position);
+                    this._targetDropPosition = null;
+                    this._delayedMoveId = 0;
+                    return GLib.SOURCE_REMOVE;
+                });
+        }
+    }
 
     _resetOvershoot() {
         if (this._lastOvershootTimeoutId)
@@ -880,6 +930,8 @@ class AppDisplay extends BaseAppView {
         if (this._grid.contains(appIcon))
             this._handleDragOvershoot(dragEvent);
 
+        this._maybeMoveItem(dragEvent);
+
         return DND.DragMotionResult.CONTINUE;
     }
 
@@ -908,6 +960,14 @@ class AppDisplay extends BaseAppView {
         if (!this._canAccept(source))
             return false;
 
+        // Dropped before the icon was moved
+        if (this._targetDropPosition) {
+            const { page, position } = this._targetDropPosition;
+
+            this.moveItem(source, page, position);
+            this._removeDelayedMove();
+        }
+
         let view = _getViewFromIcon(source);
         if (view instanceof FolderView)
             view.removeApp(source.app);


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