homescreen: Fix binding loops caused by plasmoid changing dimensions

This commit is contained in:
Devin Lin 2022-12-10 21:40:21 -05:00
parent 389ba43b16
commit ee4ba6815a

View file

@ -49,10 +49,26 @@ Item {
/**
* Margins for the homescreen, taking panels into account.
*/
readonly property real topMargin: plasmoid.availableScreenRect.y
readonly property real bottomMargin: root.height - (plasmoid.availableScreenRect.y + plasmoid.availableScreenRect.height)
readonly property real leftMargin: plasmoid.availableScreenRect.x
readonly property real rightMargin: root.width - (plasmoid.availableScreenRect.x + plasmoid.availableScreenRect.width)
property real topMargin
property real bottomMargin
property real leftMargin
property real rightMargin
function evaluateMargins() {
topMargin = plasmoid.availableScreenRect.y
bottomMargin = root.height - (plasmoid.availableScreenRect.y + plasmoid.availableScreenRect.height)
leftMargin = plasmoid.availableScreenRect.x
rightMargin = root.width - (plasmoid.availableScreenRect.x + plasmoid.availableScreenRect.width)
}
Connections {
target: plasmoid
// avoid binding loops with root.height and root.width changing along with the availableScreenRect
function onAvailableScreenRectChanged() {
Qt.callLater(() => root.evaluateMargins());
}
}
//BEGIN API implementation
@ -105,6 +121,9 @@ Item {
//END API implementation
Component.onCompleted: {
// determine the margins used
evaluateMargins();
// set API variables
if (plasmoid.screen == 0) {
MobileShellState.HomeScreenControls.taskSwitcher = taskSwitcher;