[gnome-shell/gbsneto/icon-grid-dnd: 85/96] allView, folderView: Always operate on grid coordinates



commit 6ede454cd5d83a2067cf699bdc71c5a48c5dca55
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jul 4 14:54:20 2019 -0300

    allView, folderView: Always operate on grid coordinates
    
    Passing the actor coordinates is problematic because they do not
    match the grid coordinates at all.
    
    Transform coordinates passed by the DND handlers to the grid
    coordinates.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 53ba48094..f15231702 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -257,6 +257,21 @@ class BaseAppView {
         Tweener.addTween(this._grid, params);
     }
 
+    _transformToGridCoordinates(x, y) {
+        let point = new Clutter.Vertex();
+        point.x = x;
+        point.y = y;
+        point.z = 0.0;
+
+        point = this.actor.apply_transform_to_point(point);
+
+        let [ok, gridX, gridY] = this._grid.transform_stage_point(point.x, point.y);
+        if (!ok)
+            return [-1, -1];
+
+        return [gridX, gridY];
+    }
+
     canDropAt(x, y) {
         return this._grid.canDropAt(x, y);
     }
@@ -800,6 +815,8 @@ var AllView = class AllView extends BaseAppView {
     }
 
     handleDragOver(source, actor, x, y, time) {
+        [x, y] = this._transformToGridCoordinates(x, y);
+
         let sourceIndex = -1;
         if (source.parentView == this)
             sourceIndex = this._allItems.indexOf(source);
@@ -821,6 +838,8 @@ var AllView = class AllView extends BaseAppView {
     }
 
     acceptDrop(source, actor, x, y, time) {
+        [x, y] = this._transformToGridCoordinates(x, y);
+
         let [index, dragLocation] = this.canDropAt(x, y);
 
         if (index == -1)
@@ -1282,6 +1301,8 @@ var FolderView = class FolderView extends BaseAppView {
     }
 
     handleDragOver(source, actor, x, y, time) {
+        [x, y] = this._transformToGridCoordinates(x, y);
+
         let [index, dragLocation] = this.canDropAt(x, y);
         let sourceIndex = this._allItems.indexOf(source);
 
@@ -1294,6 +1315,8 @@ var FolderView = class FolderView extends BaseAppView {
     }
 
     acceptDrop(source, actor, x, y, time) {
+        [x, y] = this._transformToGridCoordinates(x, y);
+
         let [index, dragLocation] = this.canDropAt(x, y);
         let success = index != -1;
 


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