[gnome-shell] dnd: Set dnd actor size instead of scaling it when reparenting



commit 629b7394f7cabb2c8ee1c8700c7a9d4050673a13
Author: Sebastian Keller <skeller gnome org>
Date:   Tue Feb 16 00:54:37 2021 +0100

    dnd: Set dnd actor size instead of scaling it when reparenting
    
    Previously the actor could end up using its natural size and then get
    scaled down to its allocation before reparenting. This however could
    affect the layout of the widget due to the larger size. To ensure the
    widget looks the same after reparenting set the size to its original
    size.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3717
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1680>

 js/ui/dnd.js | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
---
diff --git a/js/ui/dnd.js b/js/ui/dnd.js
index ad92d7ee77..6b4a983823 100644
--- a/js/ui/dnd.js
+++ b/js/ui/dnd.js
@@ -382,24 +382,18 @@ var _Draggable = class _Draggable {
             this._dragActorHadFixedPos = this._dragActor.fixed_position_set;
             this._dragOrigX = this._dragActor.allocation.x1;
             this._dragOrigY = this._dragActor.allocation.y1;
+            this._dragActorHadNatWidth = this._dragActor.natural_width_set;
+            this._dragActorHadNatHeight = this._dragActor.natural_height_set;
             this._dragOrigWidth = this._dragActor.allocation.get_width();
             this._dragOrigHeight = this._dragActor.allocation.get_height();
             this._dragOrigScale = this._dragActor.scale_x;
 
-            // When the actor gets reparented to the uiGroup, it will be
-            // allocated its preferred size, so use that size instead of the
-            // current allocation size.
-            const [, newAllocatedWidth] = this._dragActor.get_preferred_width(-1);
-            const [, newAllocatedHeight] = this._dragActor.get_preferred_height(-1);
+            // Ensure actors with an allocation smaller than their natural size
+            // retain their size
+            this._dragActor.set_size(...this._dragActor.allocation.get_size());
 
             const transformedExtents = this._dragActor.get_transformed_extents();
 
-            // Set the actor's scale such that it will keep the same
-            // transformed size when it's reparented to the uiGroup
-            this._dragActor.set_scale(
-                transformedExtents.get_width() / newAllocatedWidth,
-                transformedExtents.get_height() / newAllocatedHeight);
-
             this._dragOffsetX = transformedExtents.origin.x - this._dragStartX;
             this._dragOffsetY = transformedExtents.origin.y - this._dragStartY;
 
@@ -757,6 +751,10 @@ var _Draggable = class _Draggable {
                 dragActor.set_position(this._dragOrigX, this._dragOrigY);
             else
                 dragActor.fixed_position_set = false;
+            if (this._dragActorHadNatWidth)
+                this._dragActor.set_width(-1);
+            if (this._dragActorHadNatHeight)
+                this._dragActor.set_height(-1);
         } else {
             dragActor.destroy();
         }


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