mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-08 20:55:16 +00:00
AudioService + OSD: minor improvements
- Replace hardcoded value by epsilon property - Dont send volume change if delta is below epsilon
This commit is contained in:
+4
-2
@@ -12,6 +12,7 @@ import qs.Widgets
|
|||||||
// Unified OSD component that displays volume, input volume, and brightness changes
|
// Unified OSD component that displays volume, input volume, and brightness changes
|
||||||
Variants {
|
Variants {
|
||||||
id: osd
|
id: osd
|
||||||
|
|
||||||
// Do not change the order or it will break settings.
|
// Do not change the order or it will break settings.
|
||||||
enum Type {
|
enum Type {
|
||||||
Volume,
|
Volume,
|
||||||
@@ -42,6 +43,7 @@ Variants {
|
|||||||
readonly property bool isMuted: AudioService.muted
|
readonly property bool isMuted: AudioService.muted
|
||||||
readonly property real currentInputVolume: AudioService.inputVolume
|
readonly property real currentInputVolume: AudioService.inputVolume
|
||||||
readonly property bool isInputMuted: AudioService.inputMuted
|
readonly property bool isInputMuted: AudioService.inputMuted
|
||||||
|
readonly property real epsilon: 0.005
|
||||||
|
|
||||||
// Helper Functions
|
// Helper Functions
|
||||||
function getIcon() {
|
function getIcon() {
|
||||||
@@ -50,14 +52,14 @@ Variants {
|
|||||||
if (isMuted)
|
if (isMuted)
|
||||||
return "volume-mute";
|
return "volume-mute";
|
||||||
// Show volume-x icon when volume is effectively 0% (within rounding threshold)
|
// Show volume-x icon when volume is effectively 0% (within rounding threshold)
|
||||||
if (currentVolume < 0.005)
|
if (currentVolume < root.epsilon)
|
||||||
return "volume-x";
|
return "volume-x";
|
||||||
return currentVolume <= 0.5 ? "volume-low" : "volume-high";
|
return currentVolume <= 0.5 ? "volume-low" : "volume-high";
|
||||||
case OSD.Type.InputVolume:
|
case OSD.Type.InputVolume:
|
||||||
return isInputMuted ? "microphone-off" : "microphone";
|
return isInputMuted ? "microphone-off" : "microphone";
|
||||||
case OSD.Type.Brightness:
|
case OSD.Type.Brightness:
|
||||||
// Show sun-off icon when brightness is effectively 0% (within rounding threshold)
|
// Show sun-off icon when brightness is effectively 0% (within rounding threshold)
|
||||||
if (currentBrightness < 0.005)
|
if (currentBrightness < root.epsilon)
|
||||||
return "sun-off";
|
return "sun-off";
|
||||||
return currentBrightness <= 0.5 ? "brightness-low" : "brightness-high";
|
return currentBrightness <= 0.5 ? "brightness-low" : "brightness-high";
|
||||||
case OSD.Type.LockKey:
|
case OSD.Type.LockKey:
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ Singleton {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
// Devices
|
// Devices
|
||||||
|
|
||||||
readonly property PwNode sink: Pipewire.ready ? Pipewire.defaultAudioSink : null
|
readonly property PwNode sink: Pipewire.ready ? Pipewire.defaultAudioSink : null
|
||||||
readonly property PwNode source: validatedSource
|
readonly property PwNode source: validatedSource
|
||||||
readonly property bool hasInput: !!source
|
readonly property bool hasInput: !!source
|
||||||
|
|
||||||
readonly property list<PwNode> sinks: deviceNodes.sinks
|
readonly property list<PwNode> sinks: deviceNodes.sinks
|
||||||
readonly property list<PwNode> sources: deviceNodes.sources
|
readonly property list<PwNode> sources: deviceNodes.sources
|
||||||
|
|
||||||
// Output Volume - read directly from device (like friend's version)
|
readonly property real epsilon: 0.005
|
||||||
|
|
||||||
|
// Output Volume - read directly from device
|
||||||
readonly property real volume: {
|
readonly property real volume: {
|
||||||
if (!sink?.audio)
|
if (!sink?.audio)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -29,7 +29,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
readonly property bool muted: sink?.audio?.muted ?? true
|
readonly property bool muted: sink?.audio?.muted ?? true
|
||||||
|
|
||||||
// Input Volume - read directly from device (like friend's version)
|
// Input Volume - read directly from device
|
||||||
readonly property real inputVolume: {
|
readonly property real inputVolume: {
|
||||||
if (!source?.audio)
|
if (!source?.audio)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -63,14 +63,17 @@ Singleton {
|
|||||||
|
|
||||||
// Validated source (ensures it's a proper audio source, not a sink)
|
// Validated source (ensures it's a proper audio source, not a sink)
|
||||||
readonly property PwNode validatedSource: {
|
readonly property PwNode validatedSource: {
|
||||||
if (!Pipewire.ready)
|
if (!Pipewire.ready) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
const raw = Pipewire.defaultAudioSource;
|
const raw = Pipewire.defaultAudioSource;
|
||||||
if (!raw || raw.isSink || !raw.audio)
|
if (!raw || raw.isSink || !raw.audio) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
// Optional: check type if available (type reflects media.class per docs)
|
// Optional: check type if available (type reflects media.class per docs)
|
||||||
if (raw.type && typeof raw.type === "string" && !raw.type.startsWith("Audio/Source"))
|
if (raw.type && typeof raw.type === "string" && !raw.type.startsWith("Audio/Source")) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +166,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output Control
|
// Output Control
|
||||||
|
|
||||||
function increaseVolume() {
|
function increaseVolume() {
|
||||||
if (!Pipewire.ready || !sink?.audio) {
|
if (!Pipewire.ready || !sink?.audio) {
|
||||||
return;
|
return;
|
||||||
@@ -193,6 +195,10 @@ Singleton {
|
|||||||
|
|
||||||
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
||||||
const clampedVolume = Math.max(0, Math.min(maxVolume, newVolume));
|
const clampedVolume = Math.max(0, Math.min(maxVolume, newVolume));
|
||||||
|
const delta = Math.abs(clampedVolume - sink.audio.volume);
|
||||||
|
if (delta < root.epsilon) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set flag to prevent feedback loop, then set the actual volume
|
// Set flag to prevent feedback loop, then set the actual volume
|
||||||
isSettingOutputVolume = true;
|
isSettingOutputVolume = true;
|
||||||
@@ -222,15 +228,16 @@ Singleton {
|
|||||||
const clampedVolume = Math.max(0, Math.min(volume, maxVolume));
|
const clampedVolume = Math.max(0, Math.min(volume, maxVolume));
|
||||||
|
|
||||||
// Show volume-x icon when volume is effectively 0% (within rounding threshold)
|
// Show volume-x icon when volume is effectively 0% (within rounding threshold)
|
||||||
if (clampedVolume < 0.005)
|
if (clampedVolume < root.epsilon) {
|
||||||
return "volume-x";
|
return "volume-x";
|
||||||
if (clampedVolume <= 0.5)
|
}
|
||||||
|
if (clampedVolume <= 0.5) {
|
||||||
return "volume-low";
|
return "volume-low";
|
||||||
|
}
|
||||||
return "volume-high";
|
return "volume-high";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input Control
|
// Input Control
|
||||||
|
|
||||||
function increaseInputVolume() {
|
function increaseInputVolume() {
|
||||||
if (!Pipewire.ready || !source?.audio) {
|
if (!Pipewire.ready || !source?.audio) {
|
||||||
return;
|
return;
|
||||||
@@ -257,6 +264,10 @@ Singleton {
|
|||||||
|
|
||||||
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
||||||
const clampedVolume = Math.max(0, Math.min(maxVolume, newVolume));
|
const clampedVolume = Math.max(0, Math.min(maxVolume, newVolume));
|
||||||
|
const delta = Math.abs(clampedVolume - source.audio.volume);
|
||||||
|
if (delta < root.epsilon) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set flag to prevent feedback loop, then set the actual volume
|
// Set flag to prevent feedback loop, then set the actual volume
|
||||||
isSettingInputVolume = true;
|
isSettingInputVolume = true;
|
||||||
@@ -286,7 +297,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Device Selection
|
// Device Selection
|
||||||
|
|
||||||
function setAudioSink(newSink: PwNode): void {
|
function setAudioSink(newSink: PwNode): void {
|
||||||
if (!Pipewire.ready) {
|
if (!Pipewire.ready) {
|
||||||
Logger.w("AudioService", "Pipewire not ready");
|
Logger.w("AudioService", "Pipewire not ready");
|
||||||
|
|||||||
Reference in New Issue
Block a user