Light Switch: add Follow Screen Brightness mode - #49625
Open
dkocich wants to merge 3 commits into
Open
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
Fixes follow-brightness UX and persistence issues in local testing: - apply schedule-mode visual state on page load and after settings file reload so the brightness threshold slider is shown consistently - include BrightnessThreshold in LightSwitchSettings.Clone() so value survives view-model/repository reload paths - avoid Windows min/max macro clash in service settings parsing by replacing std::min/std::max clamp with explicit bounds checks
Author
|
hi @jiripolasek, thanks for the info. The description and code are updated. Here is a small GIF showing how it works. Functionality looks stable during my testing in the debug build. I tested both on a laptop (HP ZBook G1A) alone and on a secondary monitor screen only, where I trigger keyboard shortcuts to lower/raise brightness levels
|
dkocich
marked this pull request as ready for review
August 4, 2026 16:26
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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 of the Pull Request
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.
PR Checklist
Detailed Description of the Pull Request / Additional comments
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. It initializes COM and the WMI connection once and keeps it open to prevent CPU/handle churn inWmiPrvSE.exe.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 only when the brightness crosses the threshold.LightSwitchService.cpp— starts/stopsBrightnessObserverwhen mode is switched to/fromFollowBrightness; linkswbemuuid.libSettings UI (C#/XAML)
BrightnessThresholdproperty inLightSwitchPropertiesandLightSwitchViewModelFollowBrightnessState)Validation Steps Performed
settings.jsonSettings.UI.UnitTests/ViewModelTests/LightSwitch.cs(for FollowBrightness clone persistence, BrightnessThreshold clamping, Setting schedule mode to FollowBrightness)