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



commit b18da58e6a1804c070543ff27273c8c4909f5245
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 1ae75fbdc4..88de5cc4a4 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -963,6 +963,7 @@ class AppDisplay extends BaseAppView {
 
         this._eventBlocker.visible = this._currentDialog !== null;
         this._resetOvershoot();
+        this.removeNudges();
     }
 
     _canAccept(source) {
@@ -976,7 +977,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 = 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]