mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
bar: avoid recreating model on every setting change.
This commit is contained in:
+53
-12
@@ -77,6 +77,47 @@ Item {
|
||||
// Bar widgets (per-screen)
|
||||
readonly property var barWidgets: Settings.getBarWidgetsForScreen(screen?.name)
|
||||
|
||||
// Cached widget arrays - only update when widget IDs change, not when widget settings change
|
||||
// This prevents Repeater from recreating delegates on every settings save
|
||||
property var _cachedLeftWidgets: []
|
||||
property var _cachedCenterWidgets: []
|
||||
property var _cachedRightWidgets: []
|
||||
|
||||
// Helper to check if widget ID list changed
|
||||
function _widgetIdsEqual(a, b) {
|
||||
if (!a || !b || a.length !== b.length)
|
||||
return false;
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (a[i]?.id !== b[i]?.id)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update caches when barWidgets changes, but only if widget IDs actually changed
|
||||
onBarWidgetsChanged: {
|
||||
var newLeft = filterValidWidgets(barWidgets?.left);
|
||||
var newCenter = filterValidWidgets(barWidgets?.center);
|
||||
var newRight = filterValidWidgets(barWidgets?.right);
|
||||
|
||||
if (!_widgetIdsEqual(_cachedLeftWidgets, newLeft)) {
|
||||
_cachedLeftWidgets = newLeft;
|
||||
}
|
||||
if (!_widgetIdsEqual(_cachedCenterWidgets, newCenter)) {
|
||||
_cachedCenterWidgets = newCenter;
|
||||
}
|
||||
if (!_widgetIdsEqual(_cachedRightWidgets, newRight)) {
|
||||
_cachedRightWidgets = newRight;
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// Initialize caches
|
||||
_cachedLeftWidgets = filterValidWidgets(barWidgets?.left);
|
||||
_cachedCenterWidgets = filterValidWidgets(barWidgets?.center);
|
||||
_cachedRightWidgets = filterValidWidgets(barWidgets?.right);
|
||||
}
|
||||
|
||||
// Fill the parent (the Loader)
|
||||
anchors.fill: parent
|
||||
|
||||
@@ -274,7 +315,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.left)
|
||||
model: root._cachedLeftWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -285,7 +326,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "left",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.left.length
|
||||
"sectionWidgetsCount": root._cachedLeftWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
@@ -299,7 +340,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.center)
|
||||
model: root._cachedCenterWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -310,7 +351,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "center",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.center.length
|
||||
"sectionWidgetsCount": root._cachedCenterWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
@@ -325,7 +366,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.right)
|
||||
model: root._cachedRightWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -336,7 +377,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "right",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.right.length
|
||||
"sectionWidgetsCount": root._cachedRightWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
@@ -380,7 +421,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.left)
|
||||
model: root._cachedLeftWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -391,7 +432,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "left",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.left.length
|
||||
"sectionWidgetsCount": root._cachedLeftWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
@@ -407,7 +448,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.center)
|
||||
model: root._cachedCenterWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -418,7 +459,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "center",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.center.length
|
||||
"sectionWidgetsCount": root._cachedCenterWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
@@ -435,7 +476,7 @@ Item {
|
||||
spacing: Style.marginS
|
||||
|
||||
Repeater {
|
||||
model: root.filterValidWidgets(root.barWidgets.right)
|
||||
model: root._cachedRightWidgets
|
||||
delegate: BarWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
@@ -446,7 +487,7 @@ Item {
|
||||
"widgetId": modelData.id,
|
||||
"section": "right",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": root.barWidgets.right.length
|
||||
"sectionWidgetsCount": root._cachedRightWidgets.length
|
||||
})
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user