fix(media): gate spectrum pipeline on playback to cut idle CPU

Issue: #2393
This commit is contained in:
Lysec
2026-04-04 15:31:11 +02:00
parent 4b9a607151
commit a0093e509b
8 changed files with 25 additions and 19 deletions
+12 -6
View File
@@ -45,23 +45,29 @@ Item {
readonly property bool shouldShow: (currentVisualizerType !== "" && currentVisualizerType !== "none") && (!hideWhenIdle || MediaService.isPlaying)
readonly property bool needsSpectrum: root.shouldShow && MediaService.isPlaying
// Register/unregister with SpectrumService based on visibility (use screenName — screen can be null after DPMS/output changes)
readonly property string spectrumComponentId: "bar:audiovisualizer:" + screenName + ":" + root.section + ":" + root.sectionWidgetIndex
onShouldShowChanged: {
if (root.shouldShow) {
onNeedsSpectrumChanged: {
if (root.needsSpectrum) {
SpectrumService.registerComponent(root.spectrumComponentId);
} else {
SpectrumService.unregisterComponent(root.spectrumComponentId);
}
}
Component.onDestruction: {
if (root.shouldShow) {
SpectrumService.unregisterComponent(root.spectrumComponentId);
Component.onCompleted: {
if (root.needsSpectrum) {
SpectrumService.registerComponent(root.spectrumComponentId);
}
}
Component.onDestruction: {
SpectrumService.unregisterComponent(root.spectrumComponentId);
}
// Content dimensions for implicit sizing
readonly property real contentWidth: !shouldShow ? 0 : isVerticalBar ? capsuleHeight : visualizerWidth
readonly property real contentHeight: !shouldShow ? 0 : isVerticalBar ? visualizerWidth : capsuleHeight
@@ -104,7 +110,7 @@ Item {
id: visualizerLoader
anchors.fill: parent
anchors.margins: Style.marginS
active: shouldShow
active: root.needsSpectrum
asynchronous: true
sourceComponent: {
+3 -3
View File
@@ -75,7 +75,7 @@ Item {
// SpectrumService registration for visualizer
readonly property string spectrumComponentId: "bar:mediamini:" + root.screen?.name + ":" + root.section + ":" + root.sectionWidgetIndex
readonly property bool needsSpectrum: root.showVisualizer && root.visualizerType !== "" && root.visualizerType !== "none" && !root.isHidden
readonly property bool needsSpectrum: root.showVisualizer && root.visualizerType !== "" && root.visualizerType !== "none" && !root.isHidden && MediaService.isPlaying
Layout.preferredHeight: isVertical ? -1 : Style.getBarHeightForScreen(screenName)
Layout.preferredWidth: isVertical ? Style.getBarHeightForScreen(screenName) : -1
@@ -265,10 +265,10 @@ Item {
y: Style.pixelAlignCenter(parent.height, height)
width: Style.toOdd(parent.width)
height: Style.toOdd(parent.height)
active: showVisualizer
active: root.needsSpectrum
z: 0
sourceComponent: {
if (!showVisualizer)
if (!root.needsSpectrum)
return null;
if (visualizerType === "linear")
return linearSpectrum;
+2 -2
View File
@@ -16,7 +16,7 @@ NBox {
readonly property bool hasActivePlayer: MediaService.currentPlayer && MediaService.canPlay
// SpectrumService registration for visualizer
readonly property bool needsSpectrum: Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none"
readonly property bool needsSpectrum: Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none" && MediaService.isPlaying
onNeedsSpectrumChanged: {
if (root.needsSpectrum) {
@@ -138,7 +138,7 @@ NBox {
// Background visualizer on top of the artwork
Loader {
anchors.fill: parent
active: Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none"
active: root.needsSpectrum
sourceComponent: {
switch (Settings.data.audio.visualizerType) {
@@ -25,7 +25,7 @@ DraggableDesktopWidget {
readonly property bool shouldShow: visualizerType !== "" && visualizerType !== "none" && (!hideWhenIdle || MediaService.isPlaying)
readonly property bool isHidden: !shouldShow
readonly property bool shouldRegisterSpectrum: shouldShow
readonly property bool shouldRegisterSpectrum: shouldShow && MediaService.isPlaying
// Keep widget visible in edit mode so users can move/configure it
visible: !root.isHidden || DesktopWidgetRegistry.editMode
@@ -66,7 +66,7 @@ DraggableDesktopWidget {
id: visualizerLoader
anchors.fill: parent
anchors.margins: root.showBackground ? Math.round(Style.marginXS * root.widgetScale) : 0
active: root.shouldShow
active: root.shouldRegisterSpectrum
asynchronous: true
sourceComponent: {
@@ -34,7 +34,7 @@ DraggableDesktopWidget {
// SpectrumService registration for visualizer
readonly property string spectrumComponentId: "desktopmediaplayer:" + (root.screen ? root.screen.name : "unknown")
readonly property bool needsSpectrum: root.shouldShowVisualizer && !root.isHidden
readonly property bool needsSpectrum: root.shouldShowVisualizer && !root.isHidden && root.isPlaying
onNeedsSpectrumChanged: {
if (root.needsSpectrum) {
+1 -1
View File
@@ -17,7 +17,7 @@ Loader {
active: false
// Track if the visualizer should be shown (lockscreen active + media playing + non-compact mode)
readonly property bool needsSpectrum: root.active && !Settings.data.general.compactLockScreen && Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none"
readonly property bool needsSpectrum: root.active && !Settings.data.general.compactLockScreen && Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none" && MediaService.isPlaying
onActiveChanged: {
if (root.active && root.needsSpectrum) {
+3 -3
View File
@@ -264,7 +264,7 @@ Item {
Loader {
anchors.fill: parent
anchors.margins: 4
active: Settings.data.audio.visualizerType === "linear"
active: Settings.data.audio.visualizerType === "linear" && MediaService.isPlaying
z: 0
sourceComponent: NLinearSpectrum {
anchors.fill: parent
@@ -278,7 +278,7 @@ Item {
Loader {
anchors.fill: parent
anchors.margins: 4
active: Settings.data.audio.visualizerType === "mirrored"
active: Settings.data.audio.visualizerType === "mirrored" && MediaService.isPlaying
z: 0
sourceComponent: NMirroredSpectrum {
anchors.fill: parent
@@ -292,7 +292,7 @@ Item {
Loader {
anchors.fill: parent
anchors.margins: 4
active: Settings.data.audio.visualizerType === "wave"
active: Settings.data.audio.visualizerType === "wave" && MediaService.isPlaying
z: 0
sourceComponent: NWaveSpectrum {
anchors.fill: parent
+1 -1
View File
@@ -50,7 +50,7 @@ SmartPanel {
readonly property bool isSideBySide: root.compactMode && root.showAlbumArt
readonly property bool needsSpectrum: root.showVisualizer && root.visualizerType !== "" && root.visualizerType !== "none" && root.isPanelOpen
readonly property bool needsSpectrum: root.showVisualizer && root.visualizerType !== "" && root.visualizerType !== "none" && root.isPanelOpen && MediaService.isPlaying
onNeedsSpectrumChanged: {
if (root.needsSpectrum) {