Optimizations memory/cpu

- Only load bar widgets once the settings are done loading, and the
widget is actually in use.
- Only load bar on screens that request it, instead of hiding it.
This commit is contained in:
LemmyCook 2025-08-25 21:18:49 -04:00
parent 38efdc8f36
commit 9fb4aff635
4 changed files with 86 additions and 83 deletions

View file

@ -28,8 +28,7 @@ Singleton {
// Used to access via Settings.data.xxx.yyy // Used to access via Settings.data.xxx.yyy
property alias data: adapter property alias data: adapter
// Flag to prevent unnecessary wallpaper calls during reloads property bool isLoaded: false
property bool isInitialLoad: true
// Function to validate monitor configurations // Function to validate monitor configurations
function validateMonitorConfigurations() { function validateMonitorConfigurations() {
@ -91,9 +90,10 @@ Singleton {
} }
onLoaded: function () { onLoaded: function () {
Qt.callLater(function () { Qt.callLater(function () {
if (isInitialLoad) { // Some stuff like wallpaper setup and settings validation should just be executed once on startup
Logger.log("Settings", "OnLoaded") // And not on every reload
// Only set wallpaper on initial load, not on reloads if (!isLoaded) {
Logger.log("Settings", "JSON completed loading")
if (adapter.wallpaper.current !== "") { if (adapter.wallpaper.current !== "") {
Logger.log("Settings", "Set current wallpaper", adapter.wallpaper.current) Logger.log("Settings", "Set current wallpaper", adapter.wallpaper.current)
WallpaperService.setCurrentWallpaper(adapter.wallpaper.current, true) WallpaperService.setCurrentWallpaper(adapter.wallpaper.current, true)
@ -102,9 +102,9 @@ Singleton {
// Validate monitor configurations, only once // Validate monitor configurations, only once
// if none of the configured monitors exist, clear the lists // if none of the configured monitors exist, clear the lists
validateMonitorConfigurations() validateMonitorConfigurations()
}
isInitialLoad = false isLoaded = true
}
}) })
} }
onLoadFailed: function (error) { onLoadFailed: function (error) {

View file

@ -12,106 +12,108 @@ import qs.Modules.Notification
Variants { Variants {
model: Quickshell.screens model: Quickshell.screens
delegate: PanelWindow { delegate: Loader {
id: root id: root
required property ShellScreen modelData required property ShellScreen modelData
readonly property real scaling: ScalingService.scale(screen) readonly property real scaling: ScalingService.scale(modelData)
screen: modelData
WlrLayershell.namespace: "noctalia-bar" active: modelData ? (Settings.data.bar.monitors.includes(modelData.name)
|| (Settings.data.bar.monitors.length === 0)) : false
implicitHeight: Style.barHeight * scaling sourceComponent: PanelWindow {
color: Color.transparent screen: modelData
// If no bar activated in settings, then show them all WlrLayershell.namespace: "noctalia-bar"
visible: modelData ? (Settings.data.bar.monitors.includes(modelData.name)
|| (Settings.data.bar.monitors.length === 0)) : false
anchors { implicitHeight: Style.barHeight * scaling
top: Settings.data.bar.position === "top" color: Color.transparent
bottom: Settings.data.bar.position === "bottom"
left: true
right: true
}
Item { anchors {
anchors.fill: parent top: Settings.data.bar.position === "top"
clip: true bottom: Settings.data.bar.position === "bottom"
left: true
// Background fill right: true
Rectangle { }
id: bar
Item {
anchors.fill: parent anchors.fill: parent
color: Qt.rgba(Color.mSurface.r, Color.mSurface.g, Color.mSurface.b, Settings.data.bar.backgroundOpacity) clip: true
layer.enabled: true
}
// ------------------------------ // Background fill
// Left Section - Dynamic Widgets Rectangle {
Row { id: bar
id: leftSection
height: parent.height anchors.fill: parent
anchors.left: parent.left color: Qt.rgba(Color.mSurface.r, Color.mSurface.g, Color.mSurface.b, Settings.data.bar.backgroundOpacity)
anchors.leftMargin: Style.marginS * scaling layer.enabled: true
anchors.verticalCenter: parent.verticalCenter }
spacing: Style.marginS * scaling
Repeater { // ------------------------------
model: Settings.data.bar.widgets.left // Left Section - Dynamic Widgets
delegate: NWidgetLoader { Row {
widgetName: modelData id: leftSection
widgetProps: {
"screen": screen height: parent.height
anchors.left: parent.left
anchors.leftMargin: Style.marginS * scaling
anchors.verticalCenter: parent.verticalCenter
spacing: Style.marginS * scaling
Repeater {
model: Settings.data.bar.widgets.left
delegate: NWidgetLoader {
widgetName: modelData
widgetProps: {
"screen": screen
}
anchors.verticalCenter: parent.verticalCenter
} }
anchors.verticalCenter: parent.verticalCenter
} }
} }
}
// ------------------------------ // ------------------------------
// Center Section - Dynamic Widgets // Center Section - Dynamic Widgets
Row { Row {
id: centerSection id: centerSection
height: parent.height height: parent.height
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
Repeater { Repeater {
model: Settings.data.bar.widgets.center model: Settings.data.bar.widgets.center
delegate: NWidgetLoader { delegate: NWidgetLoader {
widgetName: modelData widgetName: modelData
widgetProps: { widgetProps: {
"screen": screen "screen": screen
}
anchors.verticalCenter: parent.verticalCenter
} }
anchors.verticalCenter: parent.verticalCenter
} }
} }
}
// ------------------------------ // ------------------------------
// Right Section - Dynamic Widgets // Right Section - Dynamic Widgets
Row { Row {
id: rightSection id: rightSection
height: parent.height height: parent.height
anchors.right: bar.right anchors.right: bar.right
anchors.rightMargin: Style.marginS * scaling anchors.rightMargin: Style.marginS * scaling
anchors.verticalCenter: bar.verticalCenter anchors.verticalCenter: bar.verticalCenter
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
Repeater { Repeater {
model: Settings.data.bar.widgets.right model: Settings.data.bar.widgets.right
delegate: NWidgetLoader { delegate: NWidgetLoader {
widgetName: modelData widgetName: modelData
widgetProps: { widgetProps: {
"screen": screen "screen": screen
}
anchors.verticalCenter: parent.verticalCenter
} }
anchors.verticalCenter: parent.verticalCenter
} }
} }
} }

View file

@ -13,7 +13,7 @@ Singleton {
property var items: [] // [{id, preview, mime, isImage}] property var items: [] // [{id, preview, mime, isImage}]
property bool loading: false property bool loading: false
// Active only when feature is enabled and settings have finished initial load // Active only when feature is enabled and settings have finished initial load
property bool active: Settings.data.appLauncher.enableClipboardHistory && !Settings.isInitialLoad property bool active: Settings.data.appLauncher.enableClipboardHistory && Settings.isLoaded
// Optional automatic watchers to feed cliphist DB // Optional automatic watchers to feed cliphist DB
property bool autoWatch: true property bool autoWatch: true

View file

@ -18,7 +18,7 @@ Item {
id: loader id: loader
anchors.fill: parent anchors.fill: parent
active: enabled && widgetName !== "" active: Settings.isLoaded && enabled && widgetName !== ""
sourceComponent: { sourceComponent: {
if (!active) { if (!active) {
return null return null
@ -35,6 +35,7 @@ Item {
} }
} }
} }
Logger.log("NWidgetLoader", "Loaded", widgetName, "on screen", item.screen.name)
} }
} }