[gnome-shell] dnd: Don't use transformed size to calculate parent scale when restoring



commit e7780623fe8f1150ce0d05601db844228c6da7b2
Author: Sebastian Keller <skeller gnome org>
Date:   Wed Mar 31 04:16:57 2021 +0200

    dnd: Don't use transformed size to calculate parent scale when restoring
    
    Some drag actor parents might change their width to 0 after the drag
    actor has been removed. If the drag is now canceled and the drag actor
    is animated to return to the current parent position and scale, this
    scale can not be determined and falls back to 1.0. This might be wrong
    and can result in the drag actor being too large/small at the end of the
    return animation.
    
    To avoid this calculate the scale of the parent by recursively
    calculating the product of its parents individual scales.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4017
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1790>

 js/ui/dnd.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/dnd.js b/js/ui/dnd.js
index 03b56915f1..4f2910da98 100644
--- a/js/ui/dnd.js
+++ b/js/ui/dnd.js
@@ -56,6 +56,15 @@ function _getEventHandlerActor() {
     return eventHandlerActor;
 }
 
+function _getRealActorScale(actor) {
+    let scale = 1.0;
+    while (actor) {
+        scale *= actor.scale_x;
+        actor = actor.get_parent();
+    }
+    return scale;
+}
+
 function addDragMonitor(monitor) {
     dragMonitors.push(monitor);
 }
@@ -659,11 +668,7 @@ var _Draggable = class _Draggable {
             // its parent, adjusting for the fact that the parent
             // may have been moved or scaled
             let [parentX, parentY] = this._dragOrigParent.get_transformed_position();
-            let [parentWidth] = this._dragOrigParent.get_size();
-            let [parentScaledWidth] = this._dragOrigParent.get_transformed_size();
-            let parentScale = 1.0;
-            if (parentWidth != 0)
-                parentScale = parentScaledWidth / parentWidth;
+            let parentScale = _getRealActorScale(this._dragOrigParent);
 
             x = parentX + parentScale * this._dragOrigX;
             y = parentY + parentScale * this._dragOrigY;


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