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



commit 0a962b951a6ddd390f078ab3dc4cdeddeea94578
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 1b44131b3..e86198823 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);
     }
@@ -799,6 +814,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);
@@ -820,6 +837,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)
@@ -1281,6 +1300,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);
 
@@ -1293,6 +1314,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]