From b382f61c914072732cabd9b5ae0d6e7b12fc20a9 Mon Sep 17 00:00:00 2001 From: Martin Seher Date: Mon, 21 Feb 2022 16:58:01 +0000 Subject: [PATCH] applets/panelspacer: Fix optimal size calculation Get rid of the delayed optimal size calculation caused by Qt.callLater and calculate optimal size immediately when an applet's size changes. This removes the unnecessary jumping of applets that are centered between 2 spacers. BUG: 431668 FIXED-IN: 5.24.2 (cherry picked from commit 5824e6362008988f74d07c9fce930e93294b990d) --- .../panelspacer/package/contents/ui/main.qml | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/applets/panelspacer/package/contents/ui/main.qml b/applets/panelspacer/package/contents/ui/main.qml index 86dfb0754..d0d46d55f 100644 --- a/applets/panelspacer/package/contents/ui/main.qml +++ b/applets/panelspacer/package/contents/ui/main.qml @@ -55,12 +55,9 @@ Item { plasmoid.removeAction("configure"); } - property real leftItemsSizeHint: 0 - property real rightItemsSizeHint: 0 property real middleItemsSizeHint: { - // Every time this binding gets reevaluated we want to queue a recomputation of the size hints - Qt.callLater(root.updateHints) if (!twinSpacer || !panelLayout || !leftTwin || !rightTwin) { + optimalSize = horizontal ? plasmoid.nativeInterface.containment.width : plasmoid.nativeInterface.containment.height; return 0; } @@ -105,8 +102,13 @@ Item { } } - rightItemsSizeHint = rightItemsHint; - leftItemsSizeHint = leftItemsHint; + var halfContainment = root.horizontal ?plasmoid.nativeInterface.containment.width/2 : plasmoid.nativeInterface.containment.height/2; + + if (leftTwin == plasmoid) { + optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsHint/2 - leftItemsHint) + } else { + optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsHint/2 - rightItemsHint) + } return middleItemsHint; } @@ -134,22 +136,6 @@ Item { } } - function updateHints() { - if (!twinSpacer || !panelLayout || !leftTwin || !rightTwin) { - root.optimalSize = root.horizontal ? plasmoid.nativeInterface.containment.width : plasmoid.nativeInterface.containment.height; - return; - } - - var halfContainment = root.horizontal ?plasmoid.nativeInterface.containment.width/2 : plasmoid.nativeInterface.containment.height/2; - - if (leftTwin == plasmoid) { - root.optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsSizeHint/2 - leftItemsSizeHint) - } else { - root.optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsSizeHint/2 - rightItemsSizeHint) - } - } - - Rectangle { anchors.fill: parent color: PlasmaCore.Theme.highlightColor