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



commit e7272547539b3624d6ea803591e9414c8c6f32e7
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 ec1c62d9d..f96d5a2b4 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]