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



commit 24fb711043f1ce3ef690004e463a8b9708fd462d
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 17e2179eb..9af2a7916 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -262,6 +262,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);
     }
@@ -850,6 +865,8 @@ var AllView = class AllView extends BaseAppView {
     }
 
     handleDragOver(source, actor, x, y, time) {
+        [x, y] = this._transformToGridCoordinates(x, y);
+
         let sourceIndex = -1;
         if (source.view == this) {
             let visibleItems = this._allItems.filter(item => item.actor.visible);
@@ -873,6 +890,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)
@@ -1336,6 +1355,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);
 
@@ -1348,6 +1369,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]