[gnome-shell/gbsneto/custom-icon-positions: 56/72] appDisplay: Nudge items on hover



commit d79db668a6438eeb2e06e1195377677769b2228f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon May 25 15:59:07 2020 -0300

    appDisplay: Nudge items on hover
    
    Nudge items when hovering over the grid, but doesn't actually
    do anything with it. Moving icons, storing and loading the grid
    layout, etc, will come next.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

 js/ui/appDisplay.js | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 5016272e7b..0999cbf75a 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -959,6 +959,7 @@ class AppDisplay extends BaseAppView {
 
         this._eventBlocker.visible = this._currentDialog !== null;
         this._resetOvershoot();
+        this.removeNudges();
     }
 
     _canAccept(source) {
@@ -972,7 +973,33 @@ class AppDisplay extends BaseAppView {
         return true;
     }
 
-    handleDragOver(source) {
+    _dropTargetIsValid(source, item, dropTarget) {
+        const [sourcePage, sourcePosition] =
+            this._grid.getItemPosition(source);
+        let [itemPage, itemPosition] = this._grid.getItemPosition(item);
+        const pageItems =
+            this._grid.getItemsAtPage(itemPage).filter(c => c.visible);
+
+        if (sourcePage === itemPage && itemPosition > sourcePosition)
+            itemPosition--;
+
+        if (source !== item && dropTarget === IconGrid.DragLocation.END_EDGE)
+            itemPosition++;
+
+        itemPosition = Math.clamp(itemPosition, 0, pageItems.length - 1);
+        const realDropTarget = this._grid.getItemAt(itemPage, itemPosition);
+
+        return source !== realDropTarget;
+    }
+
+    handleDragOver(source, _actor, x, y) {
+        const [item, dropTarget] = this.getDropTarget(x, y);
+
+        if (item && this._dropTargetIsValid(source, item, dropTarget))
+            this.nudgeItem(item, dropTarget);
+        else
+            this.removeNudges();
+
         if (!this._canAccept(source))
             return DND.DragMotionResult.NO_DROP;
 


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