From ae5d6c1ba4ff62e8e0eb141820fc4e9dfb30842e Mon Sep 17 00:00:00 2001 From: bbedward Date: Wed, 5 Nov 2025 10:00:42 -0500 Subject: [PATCH] brightness: optimistically update OSDs, works better --- .../Widgets/BrightnessSliderRow.qml | 12 ++ Modules/OSD/BrightnessOSD.qml | 20 +++- Services/DisplayService.qml | 104 +++++++++--------- 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/Modules/ControlCenter/Widgets/BrightnessSliderRow.qml b/Modules/ControlCenter/Widgets/BrightnessSliderRow.qml index 046e920e..999ee779 100644 --- a/Modules/ControlCenter/Widgets/BrightnessSliderRow.qml +++ b/Modules/ControlCenter/Widgets/BrightnessSliderRow.qml @@ -148,16 +148,28 @@ Row { enabled: DisplayService.brightnessAvailable && targetDeviceName.length > 0 minimum: { if (!targetDevice) return 1 + const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id) + if (isLogarithmic) { + return 1 + } return (targetDevice.class === "backlight" || targetDevice.class === "ddc") ? 1 : 0 } maximum: { if (!targetDevice) return 100 + const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id) + if (isLogarithmic) { + return 100 + } return targetDevice.displayMax || 100 } value: targetBrightness showValue: true unit: { if (!targetDevice) return "%" + const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id) + if (isLogarithmic) { + return "%" + } return targetDevice.class === "ddc" ? "" : "%" } onSliderValueChanged: function (newValue) { diff --git a/Modules/OSD/BrightnessOSD.qml b/Modules/OSD/BrightnessOSD.qml index 99062c6a..95311aa1 100644 --- a/Modules/OSD/BrightnessOSD.qml +++ b/Modules/OSD/BrightnessOSD.qml @@ -13,8 +13,10 @@ DankOSD { Connections { target: DisplayService - function onBrightnessChanged() { - root.show() + function onBrightnessChanged(showOsd) { + if (showOsd) { + root.show() + } } } @@ -63,11 +65,19 @@ DankOSD { minimum: { const deviceInfo = DisplayService.getCurrentDeviceInfo() if (!deviceInfo) return 1 + const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id) + if (isLogarithmic) { + return 1 + } return (deviceInfo.class === "backlight" || deviceInfo.class === "ddc") ? 1 : 0 } maximum: { const deviceInfo = DisplayService.getCurrentDeviceInfo() if (!deviceInfo) return 100 + const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id) + if (isLogarithmic) { + return 100 + } return deviceInfo.displayMax || 100 } enabled: DisplayService.brightnessAvailable @@ -75,6 +85,10 @@ DankOSD { unit: { const deviceInfo = DisplayService.getCurrentDeviceInfo() if (!deviceInfo) return "%" + const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id) + if (isLogarithmic) { + return "%" + } return deviceInfo.class === "ddc" ? "" : "%" } thumbOutlineColor: Theme.surfaceContainer @@ -106,7 +120,7 @@ DankOSD { Connections { target: DisplayService - function onBrightnessChanged() { + function onBrightnessChanged(showOsd) { if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) { brightnessSlider.value = DisplayService.brightnessLevel } diff --git a/Services/DisplayService.qml b/Services/DisplayService.qml index df367e44..de68dd42 100644 --- a/Services/DisplayService.qml +++ b/Services/DisplayService.qml @@ -29,9 +29,8 @@ Singleton { } property int maxBrightness: 100 property bool brightnessInitialized: false - property bool suppressNextOsd: false - signal brightnessChanged + signal brightnessChanged(bool showOsd) signal deviceSwitched property bool nightModeActive: nightModeEnabled @@ -40,7 +39,7 @@ Singleton { property bool automationAvailable: false property bool gammaControlAvailable: false - function updateSingleDevice(device, suppressSignal) { + function updateSingleDevice(device) { const deviceIndex = devices.findIndex(d => d.id === device.id) if (deviceIndex !== -1) { const newDevices = [...devices] @@ -77,20 +76,10 @@ Singleton { } } - const oldValue = deviceBrightness[device.id] const newBrightness = Object.assign({}, deviceBrightness) newBrightness[device.id] = displayValue deviceBrightness = newBrightness brightnessVersion++ - - const shouldSuppress = suppressSignal || suppressNextOsd - if (suppressNextOsd) { - suppressNextOsd = false - } - - if (!shouldSuppress && oldValue !== displayValue) { - brightnessChanged() - } } function updateFromBrightnessState(state) { @@ -166,8 +155,18 @@ Singleton { } const deviceInfo = getCurrentDeviceInfoByName(actualDevice) - const minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0 - const maxValue = deviceInfo?.displayMax || 100 + const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice) + + let minValue = 0 + let maxValue = 100 + + if (isLogarithmic) { + minValue = 1 + maxValue = 100 + } else { + minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0 + maxValue = deviceInfo?.displayMax || 100 + } if (maxValue <= 0) { console.warn("DisplayService: Invalid max value for device", actualDevice, "- skipping brightness change") @@ -181,11 +180,10 @@ Singleton { return } - if (suppressOsd) { - suppressNextOsd = true - } - - const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice) + const newBrightness = Object.assign({}, deviceBrightness) + newBrightness[actualDevice] = clampedValue + deviceBrightness = newBrightness + brightnessVersion++ if (isLogarithmic) { const newUserSet = Object.assign({}, deviceBrightnessUserSet) @@ -194,6 +192,10 @@ Singleton { SessionData.setBrightnessUserSetValue(actualDevice, clampedValue) } + if (!suppressOsd) { + brightnessChanged(true) + } + const params = { "device": actualDevice, "percent": clampedValue @@ -631,7 +633,7 @@ Singleton { } function onBrightnessDeviceUpdate(device) { - updateSingleDevice(device, false) + updateSingleDevice(device) } } @@ -733,22 +735,20 @@ Singleton { root.setCurrentDevice(actualDevice, false) } - DMSService.sendRequest("brightness.increment", { - "device": actualDevice, - "step": stepValue - }, response => { - if (response.error) { - console.error("DisplayService: Failed to increment brightness:", response.error) - ToastService.showError("Failed to increment brightness: " + response.error) - return - } - if (response.result && response.result.devices) { - const device = response.result.devices.find(d => d.id === actualDevice) - if (device) { - updateSingleDevice(device, false) - } - } - }) + const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice) + const currentBrightness = root.getDeviceBrightness(actualDevice) + const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice) + + let maxValue = 100 + if (isLogarithmic) { + maxValue = 100 + } else { + maxValue = deviceInfo?.displayMax || 100 + } + + const newBrightness = Math.min(maxValue, currentBrightness + stepValue) + + root.setBrightness(newBrightness, actualDevice, false) return "Brightness increased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "") } @@ -772,22 +772,20 @@ Singleton { root.setCurrentDevice(actualDevice, false) } - DMSService.sendRequest("brightness.decrement", { - "device": actualDevice, - "step": stepValue - }, response => { - if (response.error) { - console.error("DisplayService: Failed to decrement brightness:", response.error) - ToastService.showError("Failed to decrement brightness: " + response.error) - return - } - if (response.result && response.result.devices) { - const device = response.result.devices.find(d => d.id === actualDevice) - if (device) { - updateSingleDevice(device, false) - } - } - }) + const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice) + const currentBrightness = root.getDeviceBrightness(actualDevice) + const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice) + + let minValue = 0 + if (isLogarithmic) { + minValue = 1 + } else { + minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0 + } + + const newBrightness = Math.max(minValue, currentBrightness - stepValue) + + root.setBrightness(newBrightness, actualDevice, false) return "Brightness decreased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "") }