mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
brightness: use brightness.decrement/increment/refresh APIs
This commit is contained in:
@@ -11,19 +11,6 @@ DankOSD {
|
||||
autoHideInterval: 3000
|
||||
enableMouseInteraction: true
|
||||
|
||||
property var brightnessDebounceTimer: Timer {
|
||||
property int pendingValue: 0
|
||||
|
||||
interval: {
|
||||
const deviceInfo = DisplayService.getCurrentDeviceInfo()
|
||||
return (deviceInfo && deviceInfo.class === "ddc") ? 200 : 50
|
||||
}
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
DisplayService.setBrightnessInternal(pendingValue, DisplayService.lastIpcDevice)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: DisplayService
|
||||
function onBrightnessChanged() {
|
||||
@@ -89,8 +76,7 @@ DankOSD {
|
||||
|
||||
onSliderValueChanged: newValue => {
|
||||
if (DisplayService.brightnessAvailable) {
|
||||
root.brightnessDebounceTimer.pendingValue = newValue
|
||||
root.brightnessDebounceTimer.restart()
|
||||
DisplayService.setBrightness(newValue, DisplayService.lastIpcDevice, true)
|
||||
resetHideTimer()
|
||||
}
|
||||
}
|
||||
@@ -101,8 +87,7 @@ DankOSD {
|
||||
|
||||
onSliderDragFinished: finalValue => {
|
||||
if (DisplayService.brightnessAvailable) {
|
||||
root.brightnessDebounceTimer.stop()
|
||||
DisplayService.setBrightnessInternal(finalValue, DisplayService.lastIpcDevice)
|
||||
DisplayService.setBrightness(finalValue, DisplayService.lastIpcDevice, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,13 +95,13 @@ DankOSD {
|
||||
target: DisplayService
|
||||
|
||||
function onBrightnessChanged() {
|
||||
if (!brightnessSlider.pressed) {
|
||||
if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) {
|
||||
brightnessSlider.value = DisplayService.brightnessLevel
|
||||
}
|
||||
}
|
||||
|
||||
function onDeviceSwitched() {
|
||||
if (!brightnessSlider.pressed) {
|
||||
if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) {
|
||||
brightnessSlider.value = DisplayService.brightnessLevel
|
||||
}
|
||||
}
|
||||
@@ -124,13 +109,4 @@ DankOSD {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onOsdShown: {
|
||||
if (DisplayService.brightnessAvailable && contentLoader.item) {
|
||||
const slider = contentLoader.item.children[0].children[1]
|
||||
if (slider) {
|
||||
slider.value = DisplayService.brightnessLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ Singleton {
|
||||
signal bluetoothPairingRequest(var data)
|
||||
signal dwlStateUpdate(var data)
|
||||
signal brightnessStateUpdate(var data)
|
||||
signal brightnessDeviceUpdate(var device)
|
||||
|
||||
Component.onCompleted: {
|
||||
if (socketPath && socketPath.length > 0) {
|
||||
@@ -271,6 +272,10 @@ Singleton {
|
||||
dwlStateUpdate(data)
|
||||
} else if (service === "brightness") {
|
||||
brightnessStateUpdate(data)
|
||||
} else if (service === "brightness.update") {
|
||||
if (data.device) {
|
||||
brightnessDeviceUpdate(data.device)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,32 @@ Singleton {
|
||||
property bool automationAvailable: false
|
||||
property bool gammaControlAvailable: false
|
||||
|
||||
function updateSingleDevice(device, suppressSignal) {
|
||||
const deviceIndex = devices.findIndex(d => d.id === device.id)
|
||||
if (deviceIndex !== -1) {
|
||||
const newDevices = [...devices]
|
||||
newDevices[deviceIndex] = {
|
||||
"id": device.id,
|
||||
"name": device.id,
|
||||
"class": device.class,
|
||||
"current": device.current,
|
||||
"percentage": device.currentPercent,
|
||||
"max": device.max,
|
||||
"backend": device.backend
|
||||
}
|
||||
devices = newDevices
|
||||
}
|
||||
|
||||
const oldValue = deviceBrightness[device.id]
|
||||
const newBrightness = Object.assign({}, deviceBrightness)
|
||||
newBrightness[device.id] = device.currentPercent
|
||||
deviceBrightness = newBrightness
|
||||
|
||||
if (!suppressSignal && oldValue !== device.currentPercent) {
|
||||
brightnessChanged()
|
||||
}
|
||||
}
|
||||
|
||||
function updateFromBrightnessState(state) {
|
||||
if (!state || !state.devices) {
|
||||
return
|
||||
@@ -97,11 +123,6 @@ Singleton {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set brightness:", response.error)
|
||||
ToastService.showError("Failed to set brightness: " + response.error)
|
||||
return
|
||||
}
|
||||
|
||||
if (!suppressOsd) {
|
||||
brightnessChanged()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -458,6 +479,18 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
function rescanDevices() {
|
||||
if (!DMSService.isConnected) {
|
||||
return
|
||||
}
|
||||
|
||||
DMSService.sendRequest("brightness.rescan", null, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to rescan brightness devices:", response.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
nightModeEnabled = SessionData.nightModeEnabled
|
||||
if (DMSService.isConnected) {
|
||||
@@ -465,6 +498,14 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Quickshell
|
||||
|
||||
function onScreensChanged() {
|
||||
rescanDevices()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: DMSService
|
||||
|
||||
@@ -485,6 +526,10 @@ Singleton {
|
||||
function onBrightnessStateUpdate(data) {
|
||||
updateFromBrightnessState(data)
|
||||
}
|
||||
|
||||
function onBrightnessDeviceUpdate(device) {
|
||||
updateSingleDevice(device, false)
|
||||
}
|
||||
}
|
||||
|
||||
// Session Data Connections
|
||||
@@ -554,7 +599,7 @@ Singleton {
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
}
|
||||
root.setBrightness(clampedValue, targetDevice)
|
||||
root.setBrightness(clampedValue, targetDevice, false)
|
||||
|
||||
if (targetDevice) {
|
||||
return "Brightness set to " + clampedValue + "% on " + targetDevice
|
||||
@@ -575,21 +620,31 @@ Singleton {
|
||||
return "Device not found: " + actualDevice
|
||||
}
|
||||
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
||||
const stepValue = parseInt(step || "10")
|
||||
const newLevel = Math.max(1, Math.min(100, currentLevel + stepValue))
|
||||
const stepValue = parseInt(step || "5")
|
||||
|
||||
root.lastIpcDevice = targetDevice
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
root.lastIpcDevice = actualDevice
|
||||
if (actualDevice && actualDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(actualDevice, false)
|
||||
}
|
||||
root.setBrightness(newLevel, targetDevice)
|
||||
|
||||
if (targetDevice) {
|
||||
return "Brightness increased to " + newLevel + "% on " + targetDevice
|
||||
} else {
|
||||
return "Brightness increased to " + newLevel + "%"
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return "Brightness increased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "")
|
||||
}
|
||||
|
||||
function decrement(step: string, device: string): string {
|
||||
@@ -604,21 +659,31 @@ Singleton {
|
||||
return "Device not found: " + actualDevice
|
||||
}
|
||||
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
||||
const stepValue = parseInt(step || "10")
|
||||
const newLevel = Math.max(1, Math.min(100, currentLevel - stepValue))
|
||||
const stepValue = parseInt(step || "5")
|
||||
|
||||
root.lastIpcDevice = targetDevice
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
root.lastIpcDevice = actualDevice
|
||||
if (actualDevice && actualDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(actualDevice, false)
|
||||
}
|
||||
root.setBrightness(newLevel, targetDevice)
|
||||
|
||||
if (targetDevice) {
|
||||
return "Brightness decreased to " + newLevel + "% on " + targetDevice
|
||||
} else {
|
||||
return "Brightness decreased to " + newLevel + "%"
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return "Brightness decreased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : "")
|
||||
}
|
||||
|
||||
function status(): string {
|
||||
@@ -634,9 +699,9 @@ Singleton {
|
||||
return "No brightness devices available"
|
||||
}
|
||||
|
||||
let result = "Available devices:\\n"
|
||||
let result = "Available devices:\n"
|
||||
for (const device of root.devices) {
|
||||
result += device.id + " (" + device.class + ")\\n"
|
||||
result += device.id + " (" + device.class + ")\n"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user