mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-01 01:59:47 +00:00
OSD: another stab at a simplified approach to avoid start-up OSD notifications and separating UI from logic.
This commit is contained in:
+15
-191
@@ -1,14 +1,11 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Services.Pipewire
|
||||
import Quickshell.Wayland
|
||||
import qs.Commons
|
||||
import qs.Services.Hardware
|
||||
import qs.Services.Media
|
||||
import qs.Services.System
|
||||
import qs.Widgets
|
||||
|
||||
// Unified OSD component that displays volume, input volume, and brightness changes
|
||||
@@ -24,29 +21,14 @@ Variants {
|
||||
|
||||
// OSD State
|
||||
property string currentOSDType: "" // "volume", "inputVolume", "brightness", or ""
|
||||
|
||||
// Audio Output State
|
||||
property real lastKnownVolume: -1
|
||||
property bool volumeInitialized: false
|
||||
property bool muteInitialized: false
|
||||
property var lastKnownMuteState: null
|
||||
|
||||
// Audio Input State
|
||||
property real lastKnownInputVolume: -1
|
||||
property bool inputInitialized: false
|
||||
property bool inputMuteInitialized: false
|
||||
property var lastKnownInputMuteState: null
|
||||
|
||||
// Brightness State
|
||||
property real lastUpdatedBrightness: 0
|
||||
property bool brightnessInitialized: false
|
||||
property bool startupComplete: false
|
||||
property real currentBrightness: 0
|
||||
|
||||
// Current values (computed properties)
|
||||
readonly property real currentVolume: AudioService.volume
|
||||
readonly property bool isMuted: AudioService.muted
|
||||
readonly property real currentInputVolume: AudioService.inputVolume
|
||||
readonly property bool isInputMuted: AudioService.inputMuted
|
||||
readonly property real currentBrightness: lastUpdatedBrightness
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
@@ -105,55 +87,6 @@ Variants {
|
||||
return isMutedState ? Color.mError : Color.mOnSurface;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Audio Initialization
|
||||
// ============================================================================
|
||||
function initializeAudioValues() {
|
||||
// Initialize output volume
|
||||
if (AudioService.sink?.ready && AudioService.sink?.audio && lastKnownVolume < 0) {
|
||||
const vol = AudioService.volume;
|
||||
if (vol !== undefined && !isNaN(vol)) {
|
||||
volumeInitialized = true;
|
||||
lastKnownVolume = vol;
|
||||
const muted = AudioService.muted;
|
||||
if (muted !== undefined) {
|
||||
muteInitialized = true;
|
||||
lastKnownMuteState = muted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize input volume
|
||||
if (AudioService.hasInput && AudioService.source?.ready && AudioService.source?.audio && lastKnownInputVolume < 0) {
|
||||
const inputVol = AudioService.inputVolume;
|
||||
if (inputVol !== undefined && !isNaN(inputVol)) {
|
||||
inputInitialized = true;
|
||||
lastKnownInputVolume = inputVol;
|
||||
const inputMuted = AudioService.inputMuted;
|
||||
if (inputMuted !== undefined) {
|
||||
inputMuteInitialized = true;
|
||||
lastKnownInputMuteState = inputMuted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resetOutputInit() {
|
||||
lastKnownVolume = -1;
|
||||
volumeInitialized = false;
|
||||
lastKnownMuteState = null;
|
||||
muteInitialized = false;
|
||||
Qt.callLater(initializeAudioValues);
|
||||
}
|
||||
|
||||
function resetInputInit() {
|
||||
lastKnownInputVolume = -1;
|
||||
inputInitialized = false;
|
||||
lastKnownInputMuteState = null;
|
||||
inputMuteInitialized = false;
|
||||
Qt.callLater(initializeAudioValues);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Brightness Handling
|
||||
// ============================================================================
|
||||
@@ -166,13 +99,7 @@ Variants {
|
||||
}
|
||||
|
||||
function onBrightnessChanged(newBrightness) {
|
||||
lastUpdatedBrightness = newBrightness;
|
||||
|
||||
if (!brightnessInitialized) {
|
||||
brightnessInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
currentBrightness = newBrightness;
|
||||
showOSD("brightness");
|
||||
}
|
||||
|
||||
@@ -180,6 +107,10 @@ Variants {
|
||||
// OSD Display Control
|
||||
// ============================================================================
|
||||
function showOSD(type) {
|
||||
// Ignore all OSD requests during startup period
|
||||
if (!startupComplete)
|
||||
return;
|
||||
|
||||
currentOSDType = type;
|
||||
|
||||
if (!root.active) {
|
||||
@@ -208,106 +139,26 @@ Variants {
|
||||
// Signal Connections
|
||||
// ============================================================================
|
||||
|
||||
// Pipewire state monitoring
|
||||
Connections {
|
||||
target: Pipewire
|
||||
|
||||
function onReadyChanged() {
|
||||
if (Pipewire.ready)
|
||||
Qt.callLater(initializeAudioValues);
|
||||
}
|
||||
|
||||
function onDefaultAudioSinkChanged() {
|
||||
resetOutputInit();
|
||||
}
|
||||
|
||||
function onDefaultAudioSourceChanged() {
|
||||
resetInputInit();
|
||||
}
|
||||
}
|
||||
|
||||
// AudioService monitoring
|
||||
Connections {
|
||||
target: AudioService
|
||||
|
||||
function onSinkChanged() {
|
||||
if (AudioService.sink?.ready && AudioService.sink?.audio) {
|
||||
resetOutputInit();
|
||||
}
|
||||
}
|
||||
|
||||
function onSourceChanged() {
|
||||
if (AudioService.hasInput && AudioService.source?.ready && AudioService.source?.audio) {
|
||||
resetInputInit();
|
||||
}
|
||||
}
|
||||
|
||||
function onVolumeChanged() {
|
||||
if (lastKnownVolume < 0) {
|
||||
initializeAudioValues();
|
||||
if (lastKnownVolume < 0)
|
||||
return;
|
||||
}
|
||||
if (!volumeInitialized)
|
||||
return;
|
||||
if (Math.abs(AudioService.volume - lastKnownVolume) > 0.001) {
|
||||
lastKnownVolume = AudioService.volume;
|
||||
showOSD("volume");
|
||||
}
|
||||
showOSD("volume");
|
||||
}
|
||||
|
||||
function onMutedChanged() {
|
||||
if (lastKnownVolume < 0) {
|
||||
initializeAudioValues();
|
||||
if (lastKnownVolume < 0)
|
||||
return;
|
||||
}
|
||||
if (!muteInitialized) {
|
||||
lastKnownMuteState = AudioService.muted;
|
||||
muteInitialized = true;
|
||||
return;
|
||||
}
|
||||
if (AudioService.muted === lastKnownMuteState)
|
||||
return;
|
||||
lastKnownMuteState = AudioService.muted;
|
||||
showOSD("volume");
|
||||
}
|
||||
|
||||
function onInputVolumeChanged() {
|
||||
if (!AudioService.hasInput)
|
||||
return;
|
||||
if (lastKnownInputVolume < 0) {
|
||||
initializeAudioValues();
|
||||
if (lastKnownInputVolume < 0)
|
||||
return;
|
||||
}
|
||||
if (!inputInitialized)
|
||||
return;
|
||||
if (Math.abs(AudioService.inputVolume - lastKnownInputVolume) > 0.001) {
|
||||
lastKnownInputVolume = AudioService.inputVolume;
|
||||
if (AudioService.hasInput)
|
||||
showOSD("inputVolume");
|
||||
}
|
||||
}
|
||||
|
||||
function onInputMutedChanged() {
|
||||
if (!AudioService.hasInput)
|
||||
return;
|
||||
if (lastKnownInputVolume < 0) {
|
||||
initializeAudioValues();
|
||||
if (lastKnownInputVolume < 0)
|
||||
return;
|
||||
}
|
||||
if (!inputInitialized)
|
||||
return;
|
||||
if (!inputMuteInitialized) {
|
||||
lastKnownInputMuteState = AudioService.inputMuted;
|
||||
inputMuteInitialized = true;
|
||||
return;
|
||||
}
|
||||
if (AudioService.inputMuted === lastKnownInputMuteState)
|
||||
return;
|
||||
lastKnownInputMuteState = AudioService.inputMuted;
|
||||
showOSD("inputVolume");
|
||||
if (AudioService.hasInput)
|
||||
showOSD("inputVolume");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,41 +170,14 @@ Variants {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization timers
|
||||
// Startup timer - connect brightness monitors and enable OSD after 2 seconds
|
||||
Timer {
|
||||
id: initTimer
|
||||
interval: 500
|
||||
id: startupTimer
|
||||
interval: 2000
|
||||
running: true
|
||||
onTriggered: {
|
||||
if (Pipewire.ready)
|
||||
initializeAudioValues();
|
||||
connectBrightnessMonitors();
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: reinitTimer
|
||||
interval: 1000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (!Pipewire.ready)
|
||||
return;
|
||||
const needsOutputInit = lastKnownVolume < 0;
|
||||
const needsInputInit = AudioService.hasInput && lastKnownInputVolume < 0;
|
||||
|
||||
if (needsOutputInit || needsInputInit) {
|
||||
initializeAudioValues();
|
||||
|
||||
// Stop timer if both are initialized
|
||||
const outputDone = lastKnownVolume >= 0;
|
||||
const inputDone = !AudioService.hasInput || lastKnownInputVolume >= 0;
|
||||
if (outputDone && inputDone) {
|
||||
running = false;
|
||||
}
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
root.startupComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user