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



commit 6e60e4583ac133b2144215a9717d4fcdabce3929
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 7f09f1ad7c..c51194f098 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 = 500;
+
 let discreteGpuAvailable = false;
 
 function _getCategories(info) {
@@ -567,6 +569,8 @@ class AppDisplay extends BaseAppView {
 
         this._lastOvershootY = -1;
         this._lastOvershootTimeoutId = 0;
+        this._delayedMoveId = 0;
+        this._targetDropPosition = null;
 
         Main.overview.connect('hidden', () => this.goToPage(0));
 
@@ -603,6 +607,8 @@ class AppDisplay extends BaseAppView {
     }
 
     _onDestroy() {
+        this._removeDelayedMove();
+
         if (this._scrollTimeoutId !== 0) {
             GLib.source_remove(this._scrollTimeoutId);
             this._scrollTimeoutId = 0;
@@ -814,6 +820,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)
@@ -888,6 +938,8 @@ class AppDisplay extends BaseAppView {
         if (this._grid.contains(appIcon))
             this._handleDragOvershoot(dragEvent);
 
+        this._maybeMoveItem(dragEvent);
+
         return DND.DragMotionResult.CONTINUE;
     }
 
@@ -916,6 +968,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]