Skip to content

Feature/sync brightness wmi#49101

Open
pashza wants to merge 2 commits into
microsoft:mainfrom
pashza:feature/sync-brightness-wmi
Open

Feature/sync brightness wmi#49101
pashza wants to merge 2 commits into
microsoft:mainfrom
pashza:feature/sync-brightness-wmi

Conversation

@pashza

@pashza pashza commented Jul 3, 2026

Copy link
Copy Markdown

Summary of the Pull Request

This PR adds two highly requested features to the PowerDisplay utility:

  1. Linked Brightness Controls: A master "All Displays" slider to control all monitors simultaneously with support for per-monitor exclusions and debounced hardware writes.
  2. Laptop Screen (Internal Display) Sync: Real-time synchronization of external displays when the laptop/built-in screen's brightness is adjusted (such as via the Windows 11/10 Quick Settings slider or Fn keys).

Detailed Changes

1. Linked Brightness Controls

  • Master Slider: Added a master "All Displays" slider in the PowerDisplay flyout UI (LinkedBrightness) that broadcasts value changes to all linked monitors.
  • Per-Monitor Exclusion: Users can toggle individual monitors in and out of the linked group using a button on each card (IsExcludedFromSync / excluded_from_sync_monitor_ids). Excluded monitors keep their own independent sliders and do not follow the master level.
  • Hardware Debouncing: Propagates adjustments using a debounced queue (SliderCommitScheduler) to prevent high-frequency DDC/CI commands from locking up or lagging external monitors during drags.

2. Laptop Screen Sync (Windows Slider Integration)

  • WMI Event Monitoring: Wired up real-time listening to Windows WmiMonitorBrightnessEvent in WmiController to detect changes to the built-in display's brightness.
  • Windows Slider & Fn Key Sync: When the user adjusts their laptop screen's brightness via the Windows Quick Settings flyout or keyboard Fn keys, the utility captures the event and automatically updates all non-excluded external displays.
  • Independent Behavior: Designed the sync to work even if the internal display itself is excluded from the PowerToys linked group, allowing the native Windows slider to serve as the master control for all external screens.
  • UI Alignment: Added a settings toggle under Settings UI: "Sync external monitor brightness when laptop screen brightness changes" (sync_brightness_with_internal_display).

PR Checklist

  • Closes: power display brightness control #48120
  • Communication: Commits are atomic and cleanly document the implementation.
  • Tests: Compiled project and ran the full MSTest suite (PowerDisplay.Lib.UnitTests). All 138/138 unit tests pass successfully.

@pashza

pashza commented Jul 3, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@moooyo

moooyo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

looks good overall.

But just as I said in #47290 (comment)

we have more consider on this feature. The CLI part is ready #48632

and we have discussed about KBM.

So, we we cannot merge this PR. Sorry about that.

@pashza

pashza commented Jul 5, 2026

Copy link
Copy Markdown
Author

I see what youre saying, that you can achieve some of this with the CLI.
but the core of the issue here is syncing this to the windows (built in) brightness control, and the hardware brightness control of say Asus.

i can separate that part, so its agnostic to whenever its used by CLI or anything else, so brightness is unified across all software with WMI.

with this build its not a shortcut to adjust brightness, its the hardware keys that control brightness on all monitors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds PowerDisplay brightness synchronization capabilities by introducing a Settings UI toggle to sync external monitor brightness when the internal (laptop) display brightness changes, implemented via WMI brightness change event monitoring in the PowerDisplay module.

Changes:

  • Added sync_brightness_with_internal_display persisted setting and exposed it in Settings UI (ViewModel + XAML + localized string).
  • Added WMI brightness event subscription in WmiController and surfaced it through MonitorManager into MainViewModel to drive external monitor brightness updates.
  • Extended monitor VM surface area to expose InstanceName for matching WMI events to discovered monitors.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/settings-ui/Settings.UI/ViewModels/PowerDisplayViewModel.cs Exposes new toggle in Settings UI VM and signals settings updates.
src/settings-ui/Settings.UI/Strings/en-us/Resources.resw Adds localized string for the new toggle label.
src/settings-ui/Settings.UI/SettingsXAML/Views/PowerDisplayPage.xaml Adds the new checkbox to the PowerDisplay settings page.
src/settings-ui/Settings.UI.Library/PowerDisplayProperties.cs Adds persisted boolean property + JSON key for internal-display sync.
src/modules/powerdisplay/PowerDisplay/ViewModels/MonitorViewModel.cs Exposes InstanceName for WMI-to-monitor matching.
src/modules/powerdisplay/PowerDisplay/ViewModels/MainViewModel.Settings.cs Persists the new setting to settings.json when it changes.
src/modules/powerdisplay/PowerDisplay/ViewModels/MainViewModel.LinkedBrightness.cs Handles WMI brightness change events and propagates brightness to monitors.
src/modules/powerdisplay/PowerDisplay/ViewModels/MainViewModel.cs Hooks/unhooks WMI brightness change notifications from MonitorManager.
src/modules/powerdisplay/PowerDisplay/Helpers/WmiBrightnessChangedEventArgs.cs New event args type for WMI brightness change propagation.
src/modules/powerdisplay/PowerDisplay/Helpers/MonitorManager.cs Bridges WmiController brightness events to PowerDisplay view models.
src/modules/powerdisplay/PowerDisplay.Lib/Drivers/WMI/WmiController.cs Subscribes to WmiMonitorBrightnessEvent and raises brightness change callbacks.

Comment on lines +299 to +310
var lookupId = MonitorIdentity.FromInstanceName(instanceName);
if (string.IsNullOrEmpty(lookupId))
{
return;
}

var matchingMonitor = Monitors.FirstOrDefault(m => MonitorIdComparer.Instance.Equals(m.Id, lookupId));
if (matchingMonitor == null)
{
matchingMonitor = Monitors.FirstOrDefault(m => string.Equals(m.InstanceName, instanceName, StringComparison.OrdinalIgnoreCase));
}

Comment on lines +284 to +290
private void MonitorManager_WmiBrightnessChanged(object? sender, WmiBrightnessChangedEventArgs e)
{
_dispatcherQueue.TryEnqueue(() =>
{
HandleWmiBrightnessChanged(e.InstanceName, e.Brightness);
});
}
Comment on lines +315 to +316
Logger.LogInfo($"[WmiBrightness] Internal monitor brightness changed to {brightness}%. Syncing displays.");
matchingMonitor.UpdateBrightnessDisplay(brightness);
Comment on lines +113 to +115
[JsonPropertyName("sync_brightness_with_internal_display")]
public bool SyncBrightnessWithInternalDisplay { get; set; }

Comment on lines +103 to +113
try
{
var instanceName = eventObj.GetPropertyValue<string>("InstanceName");
var brightness = eventObj.GetPropertyValue<byte>("Brightness");
BrightnessChanged?.Invoke(instanceName, brightness);
}
catch (Exception ex)
{
Logger.LogWarning($"Error handling WMI brightness event: {ex.Message}");
}
});

@moooyo moooyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss this feature further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

power display brightness control

3 participants