Skip to content

Commit

Permalink
Handle display brightness events from Windows
Browse files Browse the repository at this point in the history
Soon... #570
  • Loading branch information
xanderfrangos committed Oct 2, 2024
1 parent 6fa8253 commit a0dce86
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,8 @@ function updateBrightnessThrottle(id, level, useCap = true, sendUpdate = true, v




let ignoreBrightnessEvent = false
let ignoreBrightnessEventTimeout = false
function updateBrightness(index, newLevel, useCap = true, vcpValue = "brightness", clearTransition = true) {
try {
let level = newLevel
Expand Down Expand Up @@ -1970,12 +1971,18 @@ function updateBrightness(index, newLevel, useCap = true, vcpValue = "brightness
id: monitor.id
})
} else if (monitor.type == "wmi") {
ignoreBrightnessEvent = true // Don't listen for Windows brightness events
monitor.brightness = level
monitor.brightnessRaw = normalized
monitorsThread.send({
type: "brightness",
brightness: normalized
})
if(ignoreBrightnessEventTimeout) clearTimeout(ignoreBrightnessEventTimeout);
ignoreBrightnessEventTimeout = setTimeout(() => {
ignoreBrightnessEvent = false
ignoreBrightnessEventTimeout = false
}, 500)
}

setTrayPercent()
Expand Down Expand Up @@ -2467,6 +2474,19 @@ function createPanel(toggleOnLoad = false, isRefreshing = false) {
// "Turn off my screen after"
} else if(setting.name === "GUID_STANDBY_TIMEOUT") {
// "Make my device sleep after"
} else if(setting.name === "GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS") {
// Internal display brightness change
if(!ignoreBrightnessEvent) {
for(const hwid2 in monitors) {
const monitor = monitors[hwid2]
if(monitor.type === "wmi") {
const normalized = normalizeBrightness(setting.data, true, monitor.min, monitor.max)
monitor.brightness = normalized
monitor.brightnessRaw = setting.data
}
sendToAllWindows('monitors-updated', monitors)
}
}
}
})

Expand Down

0 comments on commit a0dce86

Please sign in to comment.