mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 08:22:51 -05:00
brightness: use brightness.decrement/increment/refresh APIs
This commit is contained in:
@@ -11,19 +11,6 @@ DankOSD {
|
|||||||
autoHideInterval: 3000
|
autoHideInterval: 3000
|
||||||
enableMouseInteraction: true
|
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 {
|
Connections {
|
||||||
target: DisplayService
|
target: DisplayService
|
||||||
function onBrightnessChanged() {
|
function onBrightnessChanged() {
|
||||||
@@ -89,8 +76,7 @@ DankOSD {
|
|||||||
|
|
||||||
onSliderValueChanged: newValue => {
|
onSliderValueChanged: newValue => {
|
||||||
if (DisplayService.brightnessAvailable) {
|
if (DisplayService.brightnessAvailable) {
|
||||||
root.brightnessDebounceTimer.pendingValue = newValue
|
DisplayService.setBrightness(newValue, DisplayService.lastIpcDevice, true)
|
||||||
root.brightnessDebounceTimer.restart()
|
|
||||||
resetHideTimer()
|
resetHideTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,8 +87,7 @@ DankOSD {
|
|||||||
|
|
||||||
onSliderDragFinished: finalValue => {
|
onSliderDragFinished: finalValue => {
|
||||||
if (DisplayService.brightnessAvailable) {
|
if (DisplayService.brightnessAvailable) {
|
||||||
root.brightnessDebounceTimer.stop()
|
DisplayService.setBrightness(finalValue, DisplayService.lastIpcDevice, true)
|
||||||
DisplayService.setBrightnessInternal(finalValue, DisplayService.lastIpcDevice)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,13 +95,13 @@ DankOSD {
|
|||||||
target: DisplayService
|
target: DisplayService
|
||||||
|
|
||||||
function onBrightnessChanged() {
|
function onBrightnessChanged() {
|
||||||
if (!brightnessSlider.pressed) {
|
if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) {
|
||||||
brightnessSlider.value = DisplayService.brightnessLevel
|
brightnessSlider.value = DisplayService.brightnessLevel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceSwitched() {
|
function onDeviceSwitched() {
|
||||||
if (!brightnessSlider.pressed) {
|
if (!brightnessSlider.pressed && brightnessSlider.value !== DisplayService.brightnessLevel) {
|
||||||
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 bluetoothPairingRequest(var data)
|
||||||
signal dwlStateUpdate(var data)
|
signal dwlStateUpdate(var data)
|
||||||
signal brightnessStateUpdate(var data)
|
signal brightnessStateUpdate(var data)
|
||||||
|
signal brightnessDeviceUpdate(var device)
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (socketPath && socketPath.length > 0) {
|
if (socketPath && socketPath.length > 0) {
|
||||||
@@ -271,6 +272,10 @@ Singleton {
|
|||||||
dwlStateUpdate(data)
|
dwlStateUpdate(data)
|
||||||
} else if (service === "brightness") {
|
} else if (service === "brightness") {
|
||||||
brightnessStateUpdate(data)
|
brightnessStateUpdate(data)
|
||||||
|
} else if (service === "brightness.update") {
|
||||||
|
if (data.device) {
|
||||||
|
brightnessDeviceUpdate(data.device)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,32 @@ Singleton {
|
|||||||
property bool automationAvailable: false
|
property bool automationAvailable: false
|
||||||
property bool gammaControlAvailable: 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) {
|
function updateFromBrightnessState(state) {
|
||||||
if (!state || !state.devices) {
|
if (!state || !state.devices) {
|
||||||
return
|
return
|
||||||
@@ -97,11 +123,6 @@ Singleton {
|
|||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set brightness:", response.error)
|
console.error("DisplayService: Failed to set brightness:", response.error)
|
||||||
ToastService.showError("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: {
|
Component.onCompleted: {
|
||||||
nightModeEnabled = SessionData.nightModeEnabled
|
nightModeEnabled = SessionData.nightModeEnabled
|
||||||
if (DMSService.isConnected) {
|
if (DMSService.isConnected) {
|
||||||
@@ -465,6 +498,14 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: Quickshell
|
||||||
|
|
||||||
|
function onScreensChanged() {
|
||||||
|
rescanDevices()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: DMSService
|
target: DMSService
|
||||||
|
|
||||||
@@ -485,6 +526,10 @@ Singleton {
|
|||||||
function onBrightnessStateUpdate(data) {
|
function onBrightnessStateUpdate(data) {
|
||||||
updateFromBrightnessState(data)
|
updateFromBrightnessState(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onBrightnessDeviceUpdate(device) {
|
||||||
|
updateSingleDevice(device, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session Data Connections
|
// Session Data Connections
|
||||||
@@ -554,7 +599,7 @@ Singleton {
|
|||||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||||
root.setCurrentDevice(targetDevice, false)
|
root.setCurrentDevice(targetDevice, false)
|
||||||
}
|
}
|
||||||
root.setBrightness(clampedValue, targetDevice)
|
root.setBrightness(clampedValue, targetDevice, false)
|
||||||
|
|
||||||
if (targetDevice) {
|
if (targetDevice) {
|
||||||
return "Brightness set to " + clampedValue + "% on " + targetDevice
|
return "Brightness set to " + clampedValue + "% on " + targetDevice
|
||||||
@@ -575,21 +620,31 @@ Singleton {
|
|||||||
return "Device not found: " + actualDevice
|
return "Device not found: " + actualDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
const stepValue = parseInt(step || "5")
|
||||||
const stepValue = parseInt(step || "10")
|
|
||||||
const newLevel = Math.max(1, Math.min(100, currentLevel + stepValue))
|
|
||||||
|
|
||||||
root.lastIpcDevice = targetDevice
|
root.lastIpcDevice = actualDevice
|
||||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
if (actualDevice && actualDevice !== root.currentDevice) {
|
||||||
root.setCurrentDevice(targetDevice, false)
|
root.setCurrentDevice(actualDevice, false)
|
||||||
}
|
}
|
||||||
root.setBrightness(newLevel, targetDevice)
|
|
||||||
|
|
||||||
if (targetDevice) {
|
DMSService.sendRequest("brightness.increment", {
|
||||||
return "Brightness increased to " + newLevel + "% on " + targetDevice
|
"device": actualDevice,
|
||||||
} else {
|
"step": stepValue
|
||||||
return "Brightness increased to " + newLevel + "%"
|
}, 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 {
|
function decrement(step: string, device: string): string {
|
||||||
@@ -604,21 +659,31 @@ Singleton {
|
|||||||
return "Device not found: " + actualDevice
|
return "Device not found: " + actualDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
const stepValue = parseInt(step || "5")
|
||||||
const stepValue = parseInt(step || "10")
|
|
||||||
const newLevel = Math.max(1, Math.min(100, currentLevel - stepValue))
|
|
||||||
|
|
||||||
root.lastIpcDevice = targetDevice
|
root.lastIpcDevice = actualDevice
|
||||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
if (actualDevice && actualDevice !== root.currentDevice) {
|
||||||
root.setCurrentDevice(targetDevice, false)
|
root.setCurrentDevice(actualDevice, false)
|
||||||
}
|
}
|
||||||
root.setBrightness(newLevel, targetDevice)
|
|
||||||
|
|
||||||
if (targetDevice) {
|
DMSService.sendRequest("brightness.decrement", {
|
||||||
return "Brightness decreased to " + newLevel + "% on " + targetDevice
|
"device": actualDevice,
|
||||||
} else {
|
"step": stepValue
|
||||||
return "Brightness decreased to " + newLevel + "%"
|
}, 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 {
|
function status(): string {
|
||||||
@@ -634,9 +699,9 @@ Singleton {
|
|||||||
return "No brightness devices available"
|
return "No brightness devices available"
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = "Available devices:\\n"
|
let result = "Available devices:\n"
|
||||||
for (const device of root.devices) {
|
for (const device of root.devices) {
|
||||||
result += device.id + " (" + device.class + ")\\n"
|
result += device.id + " (" + device.class + ")\n"
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user