From 4225cbe704c00e4c34720f5bc10b2ba924909369 Mon Sep 17 00:00:00 2001 From: quadbyte Date: Sun, 17 Aug 2025 00:13:35 -0400 Subject: [PATCH] Brightness: Multi-monitor working (no external modification detected) --- Modules/Bar/Brightness.qml | 40 +++++++++---------- Services/BrightnessService.qml | 72 +++++----------------------------- 2 files changed, 29 insertions(+), 83 deletions(-) diff --git a/Modules/Bar/Brightness.qml b/Modules/Bar/Brightness.qml index a065937..7d47b53 100644 --- a/Modules/Bar/Brightness.qml +++ b/Modules/Bar/Brightness.qml @@ -14,35 +14,34 @@ Item { // Used to avoid opening the pill on Quickshell startup property bool firstBrightnessReceived: false - property real lastBrightness: -1 function getIcon() { - if (!BrightnessService.available) { - return "brightness_auto" - } - var brightness = BrightnessService.brightness - return brightness <= 0 ? "brightness_1" : brightness < 33 ? "brightness_low" : brightness < 66 ? "brightness_medium" : "brightness_high" + var brightness = BrightnessService.getMonitorForScreen(screen).brightness + return brightness <= 0 ? "brightness_1" : brightness < 0.33 ? "brightness_low" : brightness < 0.66 ? "brightness_medium" : "brightness_high" } // Connection used to open the pill when brightness changes Connections { - target: BrightnessService.focusedMonitor + target: BrightnessService.getMonitorForScreen(screen) function onBrightnessUpdated() { - var currentBrightness = BrightnessService.brightness + Logger.log("Bar-Brightness", "OnBrightnessUpdated") + + var monitor = BrightnessService.getMonitorForScreen(screen); + var currentBrightness = monitor.brightness // Ignore if this is the first time or if brightness hasn't actually changed if (!firstBrightnessReceived) { firstBrightnessReceived = true - lastBrightness = currentBrightness + monitor.lastBrightness = currentBrightness return } // Only show pill if brightness actually changed (not just loaded from settings) - if (Math.abs(currentBrightness - lastBrightness) > 0.1) { + if (Math.abs(currentBrightness - monitor.lastBrightness) > 0.1) { pill.show() } - lastBrightness = currentBrightness + monitor.lastBrightness = currentBrightness } } @@ -52,21 +51,22 @@ Item { iconCircleColor: Color.mPrimary collapsedIconColor: Color.mOnSurface autoHide: false // Important to be false so we can hover as long as we want - text: Math.round(BrightnessService.brightness) + "%" - tooltipText: "Brightness: " + Math.round( - BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod - + "\nLeft click for advanced settings.\nScroll up/down to change brightness." + text: Math.round(BrightnessService.getMonitorForScreen(screen).brightness * 100) + "%" + tooltipText: { + var monitor = BrightnessService.getMonitorForScreen(screen) + return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method + + "\nLeft click for advanced settings.\nScroll up/down to change brightness." + } onWheel: function (angle) { - if (!BrightnessService.available) - return - + var monitor = BrightnessService.getMonitorForScreen(screen) if (angle > 0) { - BrightnessService.increaseBrightness() + monitor.increaseBrightness() } else if (angle < 0) { - BrightnessService.decreaseBrightness() + monitor.decreaseBrightness() } } + onClicked: { settingsPanel.requestedTab = SettingsPanel.Tab.Brightness settingsPanel.isLoaded = true diff --git a/Services/BrightnessService.qml b/Services/BrightnessService.qml index 306bca4..edfe198 100644 --- a/Services/BrightnessService.qml +++ b/Services/BrightnessService.qml @@ -14,73 +14,10 @@ Singleton { readonly property list monitors: variants.instances property bool appleDisplayPresent: false - // Public properties for backward compatibility - readonly property real brightness: focusedMonitor ? focusedMonitor.brightness * 100 : Settings.data.brightness.lastBrightness - readonly property bool available: focusedMonitor !== null - readonly property string currentMethod: focusedMonitor ? focusedMonitor.method : Settings.data.brightness.lastMethod - readonly property var detectedDisplays: monitors.map(m => ({ - "name": m.modelData.name, - "type": m.isDdc ? "external" : "internal", - "method": m.method, - "index": m.busNum - })) - - // Get the currently focused monitor - readonly property Monitor focusedMonitor: { - if (monitors.length === 0) - return null - // For now, return the first monitor. Could be enhanced to detect focused monitor - return monitors[0] - } - function getMonitorForScreen(screen: ShellScreen): var { return monitors.find(m => m.modelData === screen) } - function increaseBrightness(step = null): void { - if (focusedMonitor) { - var stepSize = step !== null ? step : Settings.data.brightness.brightnessStep - focusedMonitor.setBrightness(focusedMonitor.brightness + (stepSize / 100)) - } - } - - function decreaseBrightness(step = null): void { - if (focusedMonitor) { - var stepSize = step !== null ? step : Settings.data.brightness.brightnessStep - focusedMonitor.setBrightness(focusedMonitor.brightness - (stepSize / 100)) - } - } - - function setBrightness(newBrightness: real): void { - if (focusedMonitor) { - focusedMonitor.setBrightness(newBrightness / 100) - } - } - - function setBrightnessDebounced(newBrightness: real): void { - if (focusedMonitor) { - focusedMonitor.setBrightnessDebounced(newBrightness / 100) - } - } - - // Backward compatibility functions - function updateBrightness(): void {// No longer needed with the new architecture - } - - function setDisplay(displayIndex: int): bool { - // No longer needed with the new architecture - return true - } - - function getDisplayInfo(): var { - return focusedMonitor ? { - "name": focusedMonitor.modelData.name, - "type": focusedMonitor.isDdc ? "external" : "internal", - "method": focusedMonitor.method, - "index": focusedMonitor.busNum - } : null - } - function getAvailableMethods(): list { var methods = [] if (monitors.some(m => m.isDdc)) @@ -147,6 +84,7 @@ Singleton { readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal") property real brightness: getStoredBrightness() + property real lastBrightness: 0 property real queuedBrightness: NaN // Signal for brightness changes @@ -207,6 +145,14 @@ Singleton { } } + function increaseBrightness(): void { + setBrightness(brightness + 0.1) + } + + function decreaseBrightness(): void { + setBrightness(monitor.brightness - 0.1) + } + function getStoredBrightness(): real { // Try to get stored brightness for this specific monitor var stored = Settings.data.brightness.monitorBrightness.find(m => {