Light Switch: add Follow Screen Brightness mode - #49625
Draft
dkocich wants to merge 2 commits into
Draft
Conversation
Adds a new FollowBrightness schedule mode to LightSwitch that monitors display brightness (via WMI WmiMonitorBrightness) and automatically switches the system theme based on a user-defined threshold. Changes: - BrightnessObserver.h: header-only polling observer that queries the WMI WmiMonitorBrightness class every 5 seconds and fires a callback when brightness changes. Works for laptop/tablet integrated displays including ALS-driven adjustments. - ScheduleMode enum: adds FollowBrightness value with ToString/FromString - LightSwitchConfig: adds brightnessThreshold field (0-100, default 90) - SettingId enum: adds BrightnessThreshold entry - LightSwitchSettings: loads brightnessThreshold from settings.json - LightSwitchStateManager: adds OnBrightnessChange(int) handler; EvaluateAndApplyIfNeeded applies light mode when brightness >= threshold - LightSwitchService: starts/stops BrightnessObserver when mode changes; adds wbemuuid.lib to linker dependencies - Settings UI: adds Follow Screen Brightness mode to the combo box with a slider control for the threshold (1-100%, default 90%) - Resources.resw: adds English strings for the new mode and slider Closes microsoft#49624 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
- Settings UI: Added the missing FollowBrightnessState to VisualStateGroups in LightSwitchPage.xaml so the slider actually appears when selecting the Follow Screen Brightness mode. - BrightnessObserver.h: Optimized the WMI polling logic. Instead of tearing down and completely rebuilding the COM/WMI connection every 5 seconds (which causes high CPU/handle churn in WmiPrvSE.exe), the connection is initialized once and kept open across the polling loop. - LightSwitchStateManager.cpp: Fixed a bug where any minor brightness fluctuation would clear the manual override state. Now it only clears the override if the brightness change actually crosses the configured threshold.
Author
|
@microsoft-github-policy-service agree |
Collaborator
|
Hi @dkocich, Some recommended reading: #28769 and https://github.com/microsoft/PowerToys/blob/main/CONTRIBUTING.md. Please add screenshots and/or a screen recording demonstrating the updated behavior. This repository also have a template for PR descriptions, please update yours to match it: https://github.com/microsoft/PowerToys/blob/main/.github/pull_request_template.md |
dkocich
marked this pull request as draft
August 2, 2026 21:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a new Follow Screen Brightness schedule mode for LightSwitch, as requested in #49624.
When selected, LightSwitch polls the display brightness (via WMI
WmiMonitorBrightness) and automatically switches the Windows theme based on a user-configurable threshold:This is especially useful for outdoor work where an ambient light sensor (ALS) automatically pushes the display to maximum brightness to compensate for glare — a time-based schedule can't handle this, but brightness-based switching does it automatically.
Changes
C++ backend
BrightnessObserver.h— new header-only observer that pollsWmiMonitorBrightnessevery 5 seconds and fires a callback on brightness changes. Works for laptop/tablet integrated displays driven by ALS or manual adjustments.ScheduleMode— newFollowBrightnessenum value withToString/FromStringround-tripLightSwitchConfig— newbrightnessThresholdfield (0–100, default 90)SettingId— newBrightnessThresholdentryLightSwitchSettings.cpp— loadsbrightnessThresholdfromsettings.jsonLightSwitchStateManager— newOnBrightnessChange(int)handler;EvaluateAndApplyIfNeededapplies light/dark based on threshold; manual override is cleared on the next brightness-change eventLightSwitchService.cpp— starts/stopsBrightnessObserverwhen mode is switched to/fromFollowBrightness; linkswbemuuid.libSettings UI (C#/XAML)
BrightnessThresholdproperty inLightSwitchPropertiesandLightSwitchViewModelTesting
settings.jsonCloses #49624