1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

brightness: optimistically update OSDs, works better

This commit is contained in:
bbedward
2025-11-05 10:00:42 -05:00
parent 1e6c80bd03
commit ae5d6c1ba4
3 changed files with 80 additions and 56 deletions

View File

@@ -148,16 +148,28 @@ Row {
enabled: DisplayService.brightnessAvailable && targetDeviceName.length > 0 enabled: DisplayService.brightnessAvailable && targetDeviceName.length > 0
minimum: { minimum: {
if (!targetDevice) return 1 if (!targetDevice) return 1
const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id)
if (isLogarithmic) {
return 1
}
return (targetDevice.class === "backlight" || targetDevice.class === "ddc") ? 1 : 0 return (targetDevice.class === "backlight" || targetDevice.class === "ddc") ? 1 : 0
} }
maximum: { maximum: {
if (!targetDevice) return 100 if (!targetDevice) return 100
const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id)
if (isLogarithmic) {
return 100
}
return targetDevice.displayMax || 100 return targetDevice.displayMax || 100
} }
value: targetBrightness value: targetBrightness
showValue: true showValue: true
unit: { unit: {
if (!targetDevice) return "%" if (!targetDevice) return "%"
const isLogarithmic = SessionData.getBrightnessLogarithmic(targetDevice.id)
if (isLogarithmic) {
return "%"
}
return targetDevice.class === "ddc" ? "" : "%" return targetDevice.class === "ddc" ? "" : "%"
} }
onSliderValueChanged: function (newValue) { onSliderValueChanged: function (newValue) {

View File

@@ -13,8 +13,10 @@ DankOSD {
Connections { Connections {
target: DisplayService target: DisplayService
function onBrightnessChanged() { function onBrightnessChanged(showOsd) {
root.show() if (showOsd) {
root.show()
}
} }
} }
@@ -63,11 +65,19 @@ DankOSD {
minimum: { minimum: {
const deviceInfo = DisplayService.getCurrentDeviceInfo() const deviceInfo = DisplayService.getCurrentDeviceInfo()
if (!deviceInfo) return 1 if (!deviceInfo) return 1
const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id)
if (isLogarithmic) {
return 1
}
return (deviceInfo.class === "backlight" || deviceInfo.class === "ddc") ? 1 : 0 return (deviceInfo.class === "backlight" || deviceInfo.class === "ddc") ? 1 : 0
} }
maximum: { maximum: {
const deviceInfo = DisplayService.getCurrentDeviceInfo() const deviceInfo = DisplayService.getCurrentDeviceInfo()
if (!deviceInfo) return 100 if (!deviceInfo) return 100
const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id)
if (isLogarithmic) {
return 100
}
return deviceInfo.displayMax || 100 return deviceInfo.displayMax || 100
} }
enabled: DisplayService.brightnessAvailable enabled: DisplayService.brightnessAvailable
@@ -75,6 +85,10 @@ DankOSD {
unit: { unit: {
const deviceInfo = DisplayService.getCurrentDeviceInfo() const deviceInfo = DisplayService.getCurrentDeviceInfo()
if (!deviceInfo) return "%" if (!deviceInfo) return "%"
const isLogarithmic = SessionData.getBrightnessLogarithmic(deviceInfo.id)
if (isLogarithmic) {
return "%"
}
return deviceInfo.class === "ddc" ? "" : "%" return deviceInfo.class === "ddc" ? "" : "%"
} }
thumbOutlineColor: Theme.surfaceContainer thumbOutlineColor: Theme.surfaceContainer
@@ -106,7 +120,7 @@ DankOSD {
Connections { Connections {
target: DisplayService target: DisplayService
function onBrightnessChanged() { function onBrightnessChanged(showOsd) {
if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) { if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) {
brightnessSlider.value = DisplayService.brightnessLevel brightnessSlider.value = DisplayService.brightnessLevel
} }

View File

@@ -29,9 +29,8 @@ Singleton {
} }
property int maxBrightness: 100 property int maxBrightness: 100
property bool brightnessInitialized: false property bool brightnessInitialized: false
property bool suppressNextOsd: false
signal brightnessChanged signal brightnessChanged(bool showOsd)
signal deviceSwitched signal deviceSwitched
property bool nightModeActive: nightModeEnabled property bool nightModeActive: nightModeEnabled
@@ -40,7 +39,7 @@ Singleton {
property bool automationAvailable: false property bool automationAvailable: false
property bool gammaControlAvailable: false property bool gammaControlAvailable: false
function updateSingleDevice(device, suppressSignal) { function updateSingleDevice(device) {
const deviceIndex = devices.findIndex(d => d.id === device.id) const deviceIndex = devices.findIndex(d => d.id === device.id)
if (deviceIndex !== -1) { if (deviceIndex !== -1) {
const newDevices = [...devices] const newDevices = [...devices]
@@ -77,20 +76,10 @@ Singleton {
} }
} }
const oldValue = deviceBrightness[device.id]
const newBrightness = Object.assign({}, deviceBrightness) const newBrightness = Object.assign({}, deviceBrightness)
newBrightness[device.id] = displayValue newBrightness[device.id] = displayValue
deviceBrightness = newBrightness deviceBrightness = newBrightness
brightnessVersion++ brightnessVersion++
const shouldSuppress = suppressSignal || suppressNextOsd
if (suppressNextOsd) {
suppressNextOsd = false
}
if (!shouldSuppress && oldValue !== displayValue) {
brightnessChanged()
}
} }
function updateFromBrightnessState(state) { function updateFromBrightnessState(state) {
@@ -166,8 +155,18 @@ Singleton {
} }
const deviceInfo = getCurrentDeviceInfoByName(actualDevice) const deviceInfo = getCurrentDeviceInfoByName(actualDevice)
const minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0 const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice)
const maxValue = deviceInfo?.displayMax || 100
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) { if (maxValue <= 0) {
console.warn("DisplayService: Invalid max value for device", actualDevice, "- skipping brightness change") console.warn("DisplayService: Invalid max value for device", actualDevice, "- skipping brightness change")
@@ -181,11 +180,10 @@ Singleton {
return return
} }
if (suppressOsd) { const newBrightness = Object.assign({}, deviceBrightness)
suppressNextOsd = true newBrightness[actualDevice] = clampedValue
} deviceBrightness = newBrightness
brightnessVersion++
const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice)
if (isLogarithmic) { if (isLogarithmic) {
const newUserSet = Object.assign({}, deviceBrightnessUserSet) const newUserSet = Object.assign({}, deviceBrightnessUserSet)
@@ -194,6 +192,10 @@ Singleton {
SessionData.setBrightnessUserSetValue(actualDevice, clampedValue) SessionData.setBrightnessUserSetValue(actualDevice, clampedValue)
} }
if (!suppressOsd) {
brightnessChanged(true)
}
const params = { const params = {
"device": actualDevice, "device": actualDevice,
"percent": clampedValue "percent": clampedValue
@@ -631,7 +633,7 @@ Singleton {
} }
function onBrightnessDeviceUpdate(device) { function onBrightnessDeviceUpdate(device) {
updateSingleDevice(device, false) updateSingleDevice(device)
} }
} }
@@ -733,22 +735,20 @@ Singleton {
root.setCurrentDevice(actualDevice, false) root.setCurrentDevice(actualDevice, false)
} }
DMSService.sendRequest("brightness.increment", { const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice)
"device": actualDevice, const currentBrightness = root.getDeviceBrightness(actualDevice)
"step": stepValue const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice)
}, response => {
if (response.error) { let maxValue = 100
console.error("DisplayService: Failed to increment brightness:", response.error) if (isLogarithmic) {
ToastService.showError("Failed to increment brightness: " + response.error) maxValue = 100
return } else {
} maxValue = deviceInfo?.displayMax || 100
if (response.result && response.result.devices) { }
const device = response.result.devices.find(d => d.id === actualDevice)
if (device) { const newBrightness = Math.min(maxValue, currentBrightness + stepValue)
updateSingleDevice(device, false)
} root.setBrightness(newBrightness, actualDevice, false)
}
})
return "Brightness increased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "") return "Brightness increased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "")
} }
@@ -772,22 +772,20 @@ Singleton {
root.setCurrentDevice(actualDevice, false) root.setCurrentDevice(actualDevice, false)
} }
DMSService.sendRequest("brightness.decrement", { const isLogarithmic = SessionData.getBrightnessLogarithmic(actualDevice)
"device": actualDevice, const currentBrightness = root.getDeviceBrightness(actualDevice)
"step": stepValue const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice)
}, response => {
if (response.error) { let minValue = 0
console.error("DisplayService: Failed to decrement brightness:", response.error) if (isLogarithmic) {
ToastService.showError("Failed to decrement brightness: " + response.error) minValue = 1
return } else {
} minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0
if (response.result && response.result.devices) { }
const device = response.result.devices.find(d => d.id === actualDevice)
if (device) { const newBrightness = Math.max(minValue, currentBrightness - stepValue)
updateSingleDevice(device, false)
} root.setBrightness(newBrightness, actualDevice, false)
}
})
return "Brightness decreased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "") return "Brightness decreased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "")
} }