mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Introduce a new PowerToys' module PowerDisplay to let user can control their monitor settings without touching monitor's button. Support feature list: Common: 1. Profiles support 2. Integration with LightSwitch (auto switch profile when theme change) 3. TrayIcon 4. Save and restore settings when startup 5. Shortcut 6. Rotation 7. GPO support 8. Auto re-discovery monitor when plugging and unplugging monitors. 9. Identify Monitors 10. Quick profile switch Especially for DDC/CI monitor: 1. Brightness 2. Contrast 3. Volume 4. Color temperature (preset profile) 5. Input source 6. Power State (poweroff) Design doc: https://github.com/microsoft/PowerToys/blob/yuleng/display/pr/3/doc/devdocs/modules/powerdisplay/design.md AOT compatibility: I designed this module for AOT from the start, so I'm pretty sure at least 95% of it is AOT compatible. But unfortunately, PowerToys still have a AOT blocker to block this module publish with AOT. Currently PowerToys will check the .net file version (file version not lib version) to avoid crash. So, all modules should reference Common.UI or add UseWPF to avoid overwrite the .net file with different version (which may cause crash). Todo: - [ ] BugBash - [ ] Icon - [ ] IdentifyWindow UI improvement Demo Main UI: <img width="546" height="671" alt="image" src="https://github.com/user-attachments/assets/b0ad9ac5-8000-4365-a192-ab8c2d66d4f1" /> Input Source: <img width="536" height="674" alt="image" src="https://github.com/user-attachments/assets/80f9ccd7-4f8c-4201-b177-cc86c5bcc9e3" /> Settings UI: <img width="1581" height="1191" alt="image" src="https://github.com/user-attachments/assets/6a82e4bb-8f96-4f28-abf9-d7c45e1c8ef7" /> <img width="1525" height="1146" alt="image" src="https://github.com/user-attachments/assets/aae81e65-08fd-453a-bf52-02a74f2fdea0" /> Closes: #42942 #42678 #41117 #38109 #35564 #34932 #28500 #1052 #18149 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #1052 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng <yuleng@microsoft.com> Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: moooyo <lengyuchn@gmail.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
592 lines
14 KiB
C#
592 lines
14 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
using Microsoft.PowerToys.Settings.Telemetry;
|
|
using Microsoft.PowerToys.Telemetry;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
{
|
|
public class EnabledModules
|
|
{
|
|
private Action notifyEnabledChangedAction;
|
|
|
|
// Default values for enabled modules should match their expected "enabled by default" values.
|
|
// Otherwise, a run of DSC on clean settings will not match the expected default result.
|
|
public EnabledModules()
|
|
{
|
|
}
|
|
|
|
private bool fancyZones = true;
|
|
|
|
[JsonPropertyName("FancyZones")]
|
|
public bool FancyZones
|
|
{
|
|
get => fancyZones;
|
|
set
|
|
{
|
|
if (fancyZones != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
fancyZones = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool imageResizer = true;
|
|
|
|
[JsonPropertyName("Image Resizer")]
|
|
public bool ImageResizer
|
|
{
|
|
get => imageResizer;
|
|
set
|
|
{
|
|
if (imageResizer != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
imageResizer = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool fileExplorerPreview = true;
|
|
|
|
[JsonPropertyName("File Explorer Preview")]
|
|
public bool PowerPreview
|
|
{
|
|
get => fileExplorerPreview;
|
|
set
|
|
{
|
|
if (fileExplorerPreview != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
fileExplorerPreview = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool shortcutGuide = true;
|
|
|
|
[JsonPropertyName("Shortcut Guide")]
|
|
public bool ShortcutGuide
|
|
{
|
|
get => shortcutGuide;
|
|
set
|
|
{
|
|
if (shortcutGuide != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
shortcutGuide = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool powerRename = true;
|
|
|
|
public bool PowerRename
|
|
{
|
|
get => powerRename;
|
|
set
|
|
{
|
|
if (powerRename != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
powerRename = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool keyboardManager; // defaulting to off
|
|
|
|
[JsonPropertyName("Keyboard Manager")]
|
|
public bool KeyboardManager
|
|
{
|
|
get => keyboardManager;
|
|
set
|
|
{
|
|
if (keyboardManager != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
keyboardManager = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool powerLauncher = true;
|
|
|
|
[JsonPropertyName("PowerToys Run")]
|
|
public bool PowerLauncher
|
|
{
|
|
get => powerLauncher;
|
|
set
|
|
{
|
|
if (powerLauncher != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
powerLauncher = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool colorPicker = true;
|
|
|
|
[JsonPropertyName("ColorPicker")]
|
|
public bool ColorPicker
|
|
{
|
|
get => colorPicker;
|
|
set
|
|
{
|
|
if (colorPicker != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
colorPicker = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool cropAndLock = true;
|
|
|
|
[JsonPropertyName("CropAndLock")]
|
|
public bool CropAndLock
|
|
{
|
|
get => cropAndLock;
|
|
set
|
|
{
|
|
if (cropAndLock != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
cropAndLock = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool awake = true;
|
|
|
|
[JsonPropertyName("Awake")]
|
|
public bool Awake
|
|
{
|
|
get => awake;
|
|
set
|
|
{
|
|
if (awake != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
awake = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool mouseWithoutBorders; // defaulting to off
|
|
|
|
[JsonPropertyName("MouseWithoutBorders")]
|
|
public bool MouseWithoutBorders
|
|
{
|
|
get => mouseWithoutBorders;
|
|
set
|
|
{
|
|
if (mouseWithoutBorders != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
mouseWithoutBorders = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool findMyMouse = true;
|
|
|
|
[JsonPropertyName("FindMyMouse")]
|
|
public bool FindMyMouse
|
|
{
|
|
get => findMyMouse;
|
|
set
|
|
{
|
|
if (findMyMouse != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
findMyMouse = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool mouseHighlighter = true;
|
|
|
|
[JsonPropertyName("MouseHighlighter")]
|
|
public bool MouseHighlighter
|
|
{
|
|
get => mouseHighlighter;
|
|
set
|
|
{
|
|
if (mouseHighlighter != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
mouseHighlighter = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool mouseJump; // defaulting to off
|
|
|
|
[JsonPropertyName("MouseJump")]
|
|
public bool MouseJump
|
|
{
|
|
get => mouseJump;
|
|
set
|
|
{
|
|
if (mouseJump != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
mouseJump = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool alwaysOnTop = true;
|
|
|
|
[JsonPropertyName("AlwaysOnTop")]
|
|
public bool AlwaysOnTop
|
|
{
|
|
get => alwaysOnTop;
|
|
set
|
|
{
|
|
if (alwaysOnTop != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
alwaysOnTop = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool mousePointerCrosshairs; // defaulting to off
|
|
|
|
[JsonPropertyName("MousePointerCrosshairs")]
|
|
public bool MousePointerCrosshairs
|
|
{
|
|
get => mousePointerCrosshairs;
|
|
set
|
|
{
|
|
if (mousePointerCrosshairs != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
mousePointerCrosshairs = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool powerAccent; // defaulting to off
|
|
|
|
[JsonPropertyName("QuickAccent")]
|
|
public bool PowerAccent
|
|
{
|
|
get => powerAccent;
|
|
set
|
|
{
|
|
if (powerAccent != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
powerAccent = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool powerOCR; // defaulting to off
|
|
|
|
[JsonPropertyName("TextExtractor")]
|
|
public bool PowerOcr
|
|
{
|
|
get => powerOCR;
|
|
set
|
|
{
|
|
if (powerOCR != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
powerOCR = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool advancedPaste = true;
|
|
|
|
[JsonPropertyName("AdvancedPaste")]
|
|
public bool AdvancedPaste
|
|
{
|
|
get => advancedPaste;
|
|
set
|
|
{
|
|
if (advancedPaste != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
advancedPaste = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool measureTool = true;
|
|
|
|
[JsonPropertyName("Measure Tool")]
|
|
public bool MeasureTool
|
|
{
|
|
get => measureTool;
|
|
set
|
|
{
|
|
if (measureTool != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
measureTool = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool hosts = true;
|
|
|
|
[JsonPropertyName("Hosts")]
|
|
public bool Hosts
|
|
{
|
|
get => hosts;
|
|
set
|
|
{
|
|
if (hosts != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
hosts = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool fileLocksmith = true;
|
|
|
|
[JsonPropertyName("File Locksmith")]
|
|
public bool FileLocksmith
|
|
{
|
|
get => fileLocksmith;
|
|
set
|
|
{
|
|
if (fileLocksmith != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
fileLocksmith = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool peek = true;
|
|
|
|
[JsonPropertyName("Peek")]
|
|
public bool Peek
|
|
{
|
|
get => peek;
|
|
set
|
|
{
|
|
if (peek != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
peek = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool registryPreview = true;
|
|
|
|
[JsonPropertyName("RegistryPreview")]
|
|
public bool RegistryPreview
|
|
{
|
|
get => registryPreview;
|
|
set
|
|
{
|
|
if (registryPreview != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
registryPreview = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool cmdNotFound = true;
|
|
|
|
[JsonPropertyName("CmdNotFound")]
|
|
public bool CmdNotFound
|
|
{
|
|
get => cmdNotFound;
|
|
set
|
|
{
|
|
if (cmdNotFound != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
cmdNotFound = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool environmentVariables = true;
|
|
|
|
[JsonPropertyName("EnvironmentVariables")]
|
|
public bool EnvironmentVariables
|
|
{
|
|
get => environmentVariables;
|
|
set
|
|
{
|
|
if (environmentVariables != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
environmentVariables = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool newPlus;
|
|
|
|
[JsonPropertyName("NewPlus")] // This key must match newplus::constants::non_localizable
|
|
public bool NewPlus
|
|
{
|
|
get => newPlus;
|
|
set
|
|
{
|
|
if (newPlus != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
newPlus = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool workspaces = true;
|
|
|
|
[JsonPropertyName("Workspaces")]
|
|
public bool Workspaces
|
|
{
|
|
get => workspaces;
|
|
set
|
|
{
|
|
if (workspaces != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
workspaces = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool cmdPal = true;
|
|
|
|
[JsonPropertyName("CmdPal")]
|
|
public bool CmdPal
|
|
{
|
|
get => cmdPal;
|
|
set
|
|
{
|
|
if (cmdPal != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
cmdPal = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool zoomIt;
|
|
|
|
[JsonPropertyName("ZoomIt")]
|
|
public bool ZoomIt
|
|
{
|
|
get => zoomIt;
|
|
set
|
|
{
|
|
if (zoomIt != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
zoomIt = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool cursorWrap; // defaulting to off
|
|
|
|
[JsonPropertyName("CursorWrap")]
|
|
public bool CursorWrap
|
|
{
|
|
get => cursorWrap;
|
|
set
|
|
{
|
|
if (cursorWrap != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
cursorWrap = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool lightSwitch;
|
|
|
|
[JsonPropertyName("LightSwitch")]
|
|
public bool LightSwitch
|
|
{
|
|
get => lightSwitch;
|
|
set
|
|
{
|
|
if (lightSwitch != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
lightSwitch = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool powerDisplay;
|
|
|
|
[JsonPropertyName("PowerDisplay")]
|
|
public bool PowerDisplay
|
|
{
|
|
get => powerDisplay;
|
|
set
|
|
{
|
|
if (powerDisplay != value)
|
|
{
|
|
LogTelemetryEvent(value);
|
|
powerDisplay = value;
|
|
NotifyChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NotifyChange()
|
|
{
|
|
notifyEnabledChangedAction?.Invoke();
|
|
}
|
|
|
|
public string ToJsonString()
|
|
{
|
|
return JsonSerializer.Serialize(this);
|
|
}
|
|
|
|
private static void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null)
|
|
{
|
|
var dataEvent = new SettingsEnabledEvent()
|
|
{
|
|
Value = value,
|
|
Name = moduleName,
|
|
};
|
|
PowerToysTelemetry.Log.WriteEvent(dataEvent);
|
|
}
|
|
|
|
internal void AddEnabledModuleChangeNotification(Action callBack)
|
|
{
|
|
notifyEnabledChangedAction = callBack;
|
|
}
|
|
}
|
|
}
|