mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(media): gate spectrum pipeline on playback to cut idle CPU
Issue: #2393
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user