From cccf0e60170184d0ed1058ae7347d6e254a5b46f Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Sun, 28 Sep 2025 06:32:12 +0800 Subject: [PATCH] fix: Fix brightness synchronization in multi-monitor setups --- Services/BrightnessService.qml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Services/BrightnessService.qml b/Services/BrightnessService.qml index 794ca4ea..9e32d288 100644 --- a/Services/BrightnessService.qml +++ b/Services/BrightnessService.qml @@ -16,6 +16,9 @@ Singleton { return monitors.find(m => m.modelData === screen) } + // Signal emitted when a specific monitor's brightness changes, includes monitor context + signal monitorBrightnessChanged(var monitor, real newBrightness) + function getAvailableMethods(): list { var methods = [] if (monitors.some(m => m.isDdc)) @@ -128,17 +131,20 @@ Singleton { return } - var lines = dataText.split(" -") + var lines = dataText.split("\n") if (lines.length >= 2) { var current = parseInt(lines[0].trim()) var max = parseInt(lines[1].trim()) if (!isNaN(current) && !isNaN(max) && max > 0) { var newBrightness = current / max - // Update internal value to match system state - monitor.brightness = newBrightness - monitor.brightnessUpdated(monitor.brightness) - //Logger.log("Brightness", "Refreshed brightness from system:", monitor.modelData.name, monitor.brightness) + // Only update if it's actually different (avoid feedback loops) + if (Math.abs(newBrightness - monitor.brightness) > 0.01) { + // Update internal value to match system state + monitor.brightness = newBrightness + monitor.brightnessUpdated(monitor.brightness) + root.monitorBrightnessChanged(monitor, monitor.brightness) + //Logger.log("Brightness", "Refreshed brightness from system:", monitor.modelData.name, monitor.brightness) + } } } } @@ -149,8 +155,8 @@ Singleton { function refreshBrightnessFromSystem() { if (!monitor.isDdc && !monitor.isAppleDisplay) { // For internal displays, query the system directly - refreshProc.command = ["sh", "-c", - "cat " + monitor.brightnessPath + " && " + + refreshProc.command = ["sh", "-c", + "cat " + monitor.brightnessPath + " && " + "cat " + monitor.maxBrightnessPath] refreshProc.running = true } else if (monitor.isDdc) { @@ -226,6 +232,7 @@ Singleton { // Always update monitor.brightnessUpdated(monitor.brightness) + root.monitorBrightnessChanged(monitor, monitor.brightness) } } } @@ -269,7 +276,7 @@ Singleton { // Update internal value and trigger UI feedback monitor.brightness = value - brightnessUpdated(monitor.brightness) + root.monitorBrightnessChanged(monitor, monitor.brightness) if (isAppleDisplay) { monitor.ignoreNextChange = true