Skip to content

Light Switch: add Follow Screen Brightness mode - #49625

Draft
dkocich wants to merge 2 commits into
microsoft:mainfrom
dkocich:dkocich-lightswitch-brightness-mode
Draft

Light Switch: add Follow Screen Brightness mode#49625
dkocich wants to merge 2 commits into
microsoft:mainfrom
dkocich:dkocich-lightswitch-brightness-mode

Conversation

@dkocich

@dkocich dkocich commented Aug 2, 2026

Copy link
Copy Markdown

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:

  • Brightness ≥ threshold → Light mode
  • Brightness < threshold → Dark mode

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 polls WmiMonitorBrightness every 5 seconds and fires a callback on brightness changes. Works for laptop/tablet integrated displays driven by ALS or manual adjustments.
  • ScheduleMode — new FollowBrightness enum value with ToString/FromString round-trip
  • LightSwitchConfig — new brightnessThreshold field (0–100, default 90)
  • SettingId — new BrightnessThreshold entry
  • LightSwitchSettings.cpp — loads brightnessThreshold from settings.json
  • LightSwitchStateManager — new OnBrightnessChange(int) handler; EvaluateAndApplyIfNeeded applies light/dark based on threshold; manual override is cleared on the next brightness-change event
  • LightSwitchService.cpp — starts/stops BrightnessObserver when mode is switched to/from FollowBrightness; links wbemuuid.lib

Settings UI (C#/XAML)

  • New Follow Screen Brightness entry in the schedule mode combo box
  • New BrightnessThreshold property in LightSwitchProperties and LightSwitchViewModel
  • Slider control (1–100%, default 90%) shown only when the mode is active
  • English string resources for the mode name and slider label/description

Testing

  • Selecting "Follow Screen Brightness" in Settings UI shows the threshold slider and saves the value to settings.json
  • Adjusting brightness above/below the threshold on a laptop with an ALS (or via manual brightness keys) triggers the theme switch within ~5 seconds
  • Switching to another schedule mode stops the brightness watcher and hides the slider
  • Existing modes (Off, FixedHours, SunsetToSunrise, FollowNightLight) are unaffected

Closes #49624

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

Copy link
Copy Markdown
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.
@dkocich

dkocich commented Aug 2, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@jiripolasek

jiripolasek commented Aug 2, 2026

Copy link
Copy Markdown
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
dkocich marked this pull request as draft August 2, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

powertoys light switch - add new mode based on screen brightness

2 participants