Compare commits

..

1 Commits

Author SHA1 Message Date
Niels Laute
38aa3d8328 [CmdPal] Rename DockSettings.DockSize to BandSize for safe upgrade
The Compact Mode PR (#46699) replaced the DockSize enum (Small/Medium/Large)
with a new one (Default/Compact). Existing settings.json files contain a
legacy 'DockSize: Small' value which the source-generated EnumConverter
cannot parse, causing the entire settings file to fail loading.

Rename the persisted property to BandSize so the old key becomes an unknown
property (silently ignored by System.Text.Json) and the new property starts
at its default (DockSize.Default), preserving the user's existing visual
experience after upgrading.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-25 17:19:09 +02:00
30 changed files with 236 additions and 501 deletions

View File

@@ -330,9 +330,7 @@ MRUINFO
REGSTR
# Misc Win32 APIs and PInvokes
DEFAULTTONEAREST
INVOKEIDLIST
LCMAP
MEMORYSTATUSEX
ABE
Mdt
@@ -396,10 +394,3 @@ Nonpaged
# XAML
Untargeted
# Program names
SEARCHHOST
SHELLEXPERIENCEHOST
SHELLHOST
STARTMENUEXPERIENCEHOST
WIDGETBOARD

View File

@@ -365,7 +365,6 @@ defaultlib
DEFAULTONLY
DEFAULTSIZE
defaulttonearest
DEFAULTTONEAREST
DEFAULTTONULL
DEFAULTTOPRIMARY
DEFERERASE
@@ -1368,7 +1367,6 @@ POINTERUPDATE
Pokedex
Pomodoro
Popups
popups
POPUPWINDOW
POSITIONITEM
POWERBROADCAST
@@ -1884,7 +1882,6 @@ toolwindow
TOPDOWNDIB
TOUCHEVENTF
TOUCHINPUT
touchpads
TPMLEFTALIGN
TPMRETURNCMD
TRACEHANDLE

View File

@@ -50,18 +50,18 @@ But to get started quickly, choose one of the installation methods below:
Go to the [PowerToys GitHub releases](https://aka.ms/installPowerToys), select **Assets** to reveal the installation files, and choose the one that matches your architecture and install scope. For most devices, that would be _x64 per-user_.
<!-- items that need to be updated release to release -->
[github-next-release-work]: https://github.com/microsoft/PowerToys/issues?q=is%3Aissue+milestone%3A%22PowerToys+0.100%22
[ptUserX64]: https://github.com/microsoft/PowerToys/releases/download/v0.99.0/PowerToysUserSetup-0.99.0-x64.exe
[ptUserArm64]: https://github.com/microsoft/PowerToys/releases/download/v0.99.0/PowerToysUserSetup-0.99.0-arm64.exe
[ptMachineX64]: https://github.com/microsoft/PowerToys/releases/download/v0.99.0/PowerToysSetup-0.99.0-x64.exe
[ptMachineArm64]: https://github.com/microsoft/PowerToys/releases/download/v0.99.0/PowerToysSetup-0.99.0-arm64.exe
[github-next-release-work]: https://github.com/microsoft/PowerToys/issues?q=is%3Aissue+milestone%3A%22PowerToys+0.99%22
[ptUserX64]: https://github.com/microsoft/PowerToys/releases/download/v0.98.1/PowerToysUserSetup-0.98.1-x64.exe
[ptUserArm64]: https://github.com/microsoft/PowerToys/releases/download/v0.98.1/PowerToysUserSetup-0.98.1-arm64.exe
[ptMachineX64]: https://github.com/microsoft/PowerToys/releases/download/v0.98.1/PowerToysSetup-0.98.1-x64.exe
[ptMachineArm64]: https://github.com/microsoft/PowerToys/releases/download/v0.98.1/PowerToysSetup-0.98.1-arm64.exe
| Description | Filename |
| --- | --- |
| Per user - x64 | [PowerToysUserSetup-0.99.0-x64.exe][ptUserX64] |
| Per user - ARM64 | [PowerToysUserSetup-0.99.0-arm64.exe][ptUserArm64] |
| Machine wide - x64 | [PowerToysSetup-0.99.0-x64.exe][ptMachineX64] |
| Machine wide - ARM64 | [PowerToysSetup-0.99.0-arm64.exe][ptMachineArm64] |
| Per user - x64 | [PowerToysUserSetup-0.98.1-x64.exe][ptUserX64] |
| Per user - ARM64 | [PowerToysUserSetup-0.98.1-arm64.exe][ptUserArm64] |
| Machine wide - x64 | [PowerToysSetup-0.98.1-x64.exe][ptMachineX64] |
| Machine wide - ARM64 | [PowerToysSetup-0.98.1-arm64.exe][ptMachineArm64] |
</details>
@@ -106,11 +106,11 @@ There are [community driven install methods](https://learn.microsoft.com/windows
[![What's new image](doc/images/readme/Release-Banner.png)](https://github.com/microsoft/PowerToys/releases)
To see what's new, check out the [release notes](https://github.com/microsoft/PowerToys/releases/tag/v0.99.0).
To see what's new, check out the [release notes](https://github.com/microsoft/PowerToys/releases/tag/v0.98.1).
## 🛣️ Roadmap
We are planning some nice new features and improvements for the next releases a brand-new Shortcut Guide experience, ensuring it's easier to find and install Command Palette extensions and so much more! Stay tuned for [v0.100][github-next-release-work]!
We are planning some nice new features and improvements for the next releases PowerDisplay, Command Palette improvements and a brand-new Shortcut Guide experience! Stay tuned for [v0.99][github-next-release-work]!
## ❤️ PowerToys Community

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 256 KiB

View File

@@ -6,16 +6,13 @@
<?define BaseApplicationsFilesPath=$(var.BinDir)\?>
<Fragment>
<!-- winmd must be in WinUI3Apps (ExternalLocation) for WinRT COM proxy/stub resolution -->
<DirectoryRef Id="WinUI3AppsInstallFolder">
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="Microsoft_CommandPalette_Extensions_winmd" Guid="304AD25A-A986-4058-940E-61DB79EBD78C" Bitness="always64">
<RegistryKey Root="$(var.RegistryScope)" Key="Software\Classes\powertoys\components">
<RegistryValue Type="string" Name="Microsoft_CommandPalette_Extensions_winmd" Value="" KeyPath="yes" />
</RegistryKey>
<File Id="Microsoft.CommandPalette.Extensions.winmd" Source="$(var.BinDir)WinUI3Apps\Microsoft.CommandPalette.Extensions.winmd" />
</Component>
</DirectoryRef>
<DirectoryRef Id="INSTALLFOLDER">
<!-- Generated by generateFileComponents.ps1 -->
<!--BaseApplicationsFiles_Component_Def-->
</DirectoryRef>

View File

@@ -579,16 +579,14 @@ static void StopResizing()
HideOverlay();
}
static void ReplayAbsorbedModifier(bool alsoKeyUp)
static void ReplayAbsorbedAlt()
{
INPUT inputs[2] = {};
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = static_cast<WORD>(g_absorbedVk);
inputs[0].ki.wScan = static_cast<WORD>(g_absorbedScanCode);
inputs[0].ki.dwFlags = (g_absorbedFlags & LLKHF_EXTENDED) ? KEYEVENTF_EXTENDEDKEY : 0;
inputs[1] = inputs[0];
inputs[1].ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(alsoKeyUp ? 2 : 1, inputs, sizeof(INPUT));
INPUT keyboardInput = {};
keyboardInput.type = INPUT_KEYBOARD;
keyboardInput.ki.wVk = static_cast<WORD>(g_absorbedVk);
keyboardInput.ki.wScan = static_cast<WORD>(g_absorbedScanCode);
keyboardInput.ki.dwFlags = (g_absorbedFlags & LLKHF_EXTENDED) ? KEYEVENTF_EXTENDEDKEY : 0;
SendInput(1, &keyboardInput, sizeof(INPUT));
}
// ---------------------------------------------------------------------------
@@ -634,65 +632,9 @@ static void ShowTrayMenu(HWND hwnd)
static bool IsSystemClass(HWND hwnd)
{
wchar_t cls[256] = {};
GetClassNameW(hwnd, cls, ARRAYSIZE(cls));
// Desktop and primary/secondary taskbars
if (wcscmp(cls, L"Progman") == 0 ||
wcscmp(cls, L"Shell_TrayWnd") == 0 ||
wcscmp(cls, L"Shell_SecondaryTrayWnd") == 0)
return true;
// System tray / notification area popups and overflow
if (wcscmp(cls, L"NotifyIconOverflowWindow") == 0 ||
wcscmp(cls, L"TopLevelWindowForOverflowXamlIsland") == 0)
return true;
// Tooltips (e.g. "Show hidden icons" tooltip)
if (wcscmp(cls, L"tooltips_class32") == 0)
return true;
// Task View (Win+Tab)
if (wcscmp(cls, L"MultitaskingViewFrame") == 0 ||
wcscmp(cls, L"XamlExplorerHostIslandWindow") == 0)
return true;
// System tray flyouts (Quick Settings, calendar, input switcher)
if (wcscmp(cls, L"Windows.UI.Composition.DesktopWindowContentBridge") == 0 ||
wcscmp(cls, L"Shell_InputSwitchTopLevelWindow") == 0)
return true;
return false;
}
std::wstring ToUpperInvariant(std::wstring_view input)
{
int required = LCMapStringEx(
LOCALE_NAME_INVARIANT,
LCMAP_UPPERCASE,
input.data(),
static_cast<int>(input.size()),
nullptr,
0,
nullptr,
nullptr,
0);
std::wstring result(required, L'\0');
LCMapStringEx(
LOCALE_NAME_INVARIANT,
LCMAP_UPPERCASE,
input.data(),
static_cast<int>(input.size()),
result.data(),
required,
nullptr,
nullptr,
0);
return result;
wchar_t cls[64] = {};
GetClassNameW(hwnd, cls, 64);
return (wcscmp(cls, L"Progman") == 0 || wcscmp(cls, L"Shell_TrayWnd") == 0);
}
static bool IsExcluded(HWND hwnd)
@@ -700,45 +642,6 @@ static bool IsExcluded(HWND hwnd)
if (IsSystemClass(hwnd))
return true;
// To identify these for adding a new exception:
// 1. Resolve the hwnd class name.
// 2. Resolve the process path.
// 3. Add OutputDebugStringW() for the class name and process path.
// 4. Build the executable.
// 5. Check with the debugger (or with Sysinternals DebugView) the outputs.
// 6. Delete the added code.
// 7. Add the exception below, according to the pattern there.
//
// Shell experience windows: Start menu, Notifications (Win+N), Search,
// Quick Settings (volume / network / battery).
// These use the generic Windows.UI.Core.CoreWindow class, so filter by process.
{
wchar_t cls[256] = {};
GetClassNameW(hwnd, cls, ARRAYSIZE(cls));
if (wcscmp(cls, L"Windows.UI.Core.CoreWindow") == 0)
{
std::wstring processPath = ToUpperInvariant(get_process_path(hwnd));
if (processPath.find(L"STARTMENUEXPERIENCEHOST.EXE") != std::wstring::npos ||
processPath.find(L"SHELLEXPERIENCEHOST.EXE") != std::wstring::npos ||
processPath.find(L"SEARCHHOST.EXE") != std::wstring::npos)
return true;
}
else if (wcscmp(cls, L"ControlCenterWindow") == 0)
{
// The Quick Settings flyout.
std::wstring processPath = ToUpperInvariant(get_process_path(hwnd));
if (processPath.find(L"SHELLHOST.EXE") != std::wstring::npos)
return true;
}
else if (wcscmp(cls, L"WindowsDashboard") == 0)
{
// The Windows 11 Widgets flyout.
std::wstring processPath = ToUpperInvariant(get_process_path(hwnd));
if (processPath.find(L"WIDGETBOARD.EXE") != std::wstring::npos)
return true;
}
}
auto apps = g_excludedApps.load();
if (!apps || apps->empty())
return false;
@@ -832,9 +735,8 @@ static LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
g_dragConsumedAlt = false;
return 1;
}
// No drag happened; replay the keydown, THEN the keyup
ReplayAbsorbedModifier(true);
return 1; // swallow this keyup since the replay already sent one
// No drag happened; replay the keydown, then let keyup through
ReplayAbsorbedAlt();
}
}
goto forward; // let Win keyup pass through
@@ -891,7 +793,7 @@ static LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
return 1;
}
// No drag happened; replay the keydown, then let keyup through
ReplayAbsorbedModifier(false);
ReplayAbsorbedAlt();
}
}
}
@@ -901,8 +803,7 @@ static LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
if (g_altAbsorbed && !g_dragConsumedAlt)
{
g_altAbsorbed = false;
g_altPressed = false;
ReplayAbsorbedModifier(false);
ReplayAbsorbedAlt();
}
}
}
@@ -912,7 +813,7 @@ static LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
g_winAbsorbed = false;
g_winPressed = false;
ReplayAbsorbedModifier(false);
ReplayAbsorbedAlt();
}
// Track held non-modifier keys (used to suppress GrabAndMove when the modifier

View File

@@ -9784,10 +9784,7 @@ LRESULT APIENTRY MainWndProc(
{
if (!RegisterHotKey(hWnd, ZOOM_HOTKEY, g_ToggleMod, g_ToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified zoom toggle hotkey is already in use.\nSelect a different zoom toggle hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified zoom toggle hotkey is already in use.\nSelect a different zoom toggle hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9796,10 +9793,7 @@ LRESULT APIENTRY MainWndProc(
if (!RegisterHotKey(hWnd, LIVE_HOTKEY, g_LiveZoomToggleMod, g_LiveZoomToggleKey & 0xFF) ||
!RegisterHotKey(hWnd, LIVE_DRAW_HOTKEY, g_LiveZoomToggleMod ^ MOD_SHIFT, g_LiveZoomToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified live-zoom toggle hotkey is already in use.\nSelect a different zoom toggle hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified live-zoom toggle hotkey is already in use.\nSelect a different zoom toggle hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9807,10 +9801,7 @@ LRESULT APIENTRY MainWndProc(
{
if (!RegisterHotKey(hWnd, DRAW_HOTKEY, g_DrawToggleMod, g_DrawToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified draw w/out zoom hotkey is already in use.\nSelect a different draw w/out zoom hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified draw w/out zoom hotkey is already in use.\nSelect a different draw w/out zoom hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9818,10 +9809,7 @@ LRESULT APIENTRY MainWndProc(
{
if (!RegisterHotKey(hWnd, BREAK_HOTKEY, g_BreakToggleMod, g_BreakToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified break timer hotkey is already in use.\nSelect a different break timer hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified break timer hotkey is already in use.\nSelect a different break timer hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9830,10 +9818,7 @@ LRESULT APIENTRY MainWndProc(
if (!RegisterHotKey(hWnd, DEMOTYPE_HOTKEY, g_DemoTypeToggleMod, g_DemoTypeToggleKey & 0xFF) ||
!RegisterHotKey(hWnd, DEMOTYPE_RESET_HOTKEY, (g_DemoTypeToggleMod ^ MOD_SHIFT), g_DemoTypeToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified live-type hotkey is already in use.\nSelect a different live-type hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified live-type hotkey is already in use.\nSelect a different live-type hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9842,10 +9827,7 @@ LRESULT APIENTRY MainWndProc(
if (!RegisterHotKey(hWnd, SNIP_HOTKEY, g_SnipToggleMod, g_SnipToggleKey & 0xFF) ||
!RegisterHotKey(hWnd, SNIP_SAVE_HOTKEY, (g_SnipToggleMod ^ MOD_SHIFT), g_SnipToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified snip hotkey is already in use.\nSelect a different snip hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified snip hotkey is already in use.\nSelect a different snip hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9855,10 +9837,7 @@ LRESULT APIENTRY MainWndProc(
if (!RegisterHotKey(hWnd, SNIP_PANORAMA_HOTKEY, g_SnipPanoramaToggleMod | MOD_NOREPEAT, g_SnipPanoramaToggleKey & 0xFF) ||
!RegisterHotKey(hWnd, SNIP_PANORAMA_SAVE_HOTKEY, ( g_SnipPanoramaToggleMod ^ MOD_SHIFT ) | MOD_NOREPEAT, g_SnipPanoramaToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified panorama snip hotkey is already in use.\nSelect a different panorama snip hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified panorama snip hotkey is already in use.\nSelect a different panorama snip hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9866,10 +9845,7 @@ LRESULT APIENTRY MainWndProc(
{
if (!RegisterHotKey(hWnd, SNIP_OCR_HOTKEY, g_SnipOcrToggleMod, g_SnipOcrToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified snip OCR hotkey is already in use.\nSelect a different snip OCR hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified snip OCR hotkey is already in use.\nSelect a different snip OCR hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}
@@ -9879,10 +9855,7 @@ LRESULT APIENTRY MainWndProc(
!RegisterHotKey(hWnd, RECORD_CROP_HOTKEY, (g_RecordToggleMod ^ MOD_SHIFT) | MOD_NOREPEAT, g_RecordToggleKey & 0xFF) ||
!RegisterHotKey(hWnd, RECORD_WINDOW_HOTKEY, (g_RecordToggleMod ^ MOD_ALT) | MOD_NOREPEAT, g_RecordToggleKey & 0xFF))
{
if(!g_StartedByPowerToys)
{
MessageBox(hWnd, L"The specified record hotkey is already in use.\nSelect a different record hotkey.", APPNAME, MB_ICONERROR);
}
MessageBox(hWnd, L"The specified record hotkey is already in use.\nSelect a different record hotkey.", APPNAME, MB_ICONERROR);
showOptions = TRUE;
}
}

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Text.Json.Serialization;
namespace Microsoft.CmdPal.UI.ViewModels;
@@ -12,21 +11,9 @@ public record AppStateModel
///////////////////////////////////////////////////////////////////////////
// STATE HERE
// Make sure that any new types you add are added to JsonSerializationContext!
private RecentCommandsManager? _recentCommands = new();
public RecentCommandsManager RecentCommands { get; init; } = new();
public RecentCommandsManager RecentCommands
{
get => _recentCommands ?? new();
init => _recentCommands = value;
}
private ImmutableList<string>? _runHistory = ImmutableList<string>.Empty;
public ImmutableList<string> RunHistory
{
get => _runHistory ?? ImmutableList<string>.Empty;
init => _runHistory = value;
}
public ImmutableList<string> RunHistory { get; init; } = ImmutableList<string>.Empty;
// END SETTINGS
///////////////////////////////////////////////////////////////////////////

View File

@@ -46,6 +46,45 @@ public partial class DockBandSettingsViewModel : ObservableObject
public IconInfoViewModel Icon => _adapter.IconViewModel;
private ShowLabelsOption _showLabels;
public ShowLabelsOption ShowLabels
{
get => _showLabels;
set
{
if (value != _showLabels)
{
_showLabels = value;
var newShowTitles = value switch
{
ShowLabelsOption.Default => (bool?)null,
ShowLabelsOption.ShowLabels => true,
ShowLabelsOption.HideLabels => false,
_ => null,
};
UpdateModel(_dockSettingsModel with { ShowTitles = newShowTitles });
}
}
}
private ShowLabelsOption FetchShowLabels()
{
if (_dockSettingsModel.ShowLabels == null)
{
return ShowLabelsOption.Default;
}
return _dockSettingsModel.ShowLabels.Value ? ShowLabelsOption.ShowLabels : ShowLabelsOption.HideLabels;
}
// used to map to ComboBox selection
public int ShowLabelsIndex
{
get => (int)ShowLabels;
set => ShowLabels = (ShowLabelsOption)value;
}
private DockPinSide PinSide
{
get => _pinSide;
@@ -99,6 +138,7 @@ public partial class DockBandSettingsViewModel : ObservableObject
_bandViewModel = bandViewModel;
_settingsService = settingsService;
_pinSide = FetchPinSide();
_showLabels = FetchShowLabels();
}
private DockPinSide FetchPinSide()

View File

@@ -559,7 +559,7 @@ public sealed partial class DockViewModel
}
// Create settings for the new band
var bandSettings = new DockBandSettings { ProviderId = topLevel.CommandProviderId, CommandId = bandId };
var bandSettings = new DockBandSettings { ProviderId = topLevel.CommandProviderId, CommandId = bandId, ShowLabels = null };
var dockSettings = _settings;
// Create the band view model

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// 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.
@@ -18,24 +18,12 @@ public record ProviderSettings
public bool IsEnabled { get; init; } = true;
private ImmutableDictionary<string, FallbackSettings>? _fallbackCommands
public ImmutableDictionary<string, FallbackSettings> FallbackCommands { get; init; }
= ImmutableDictionary<string, FallbackSettings>.Empty;
public ImmutableDictionary<string, FallbackSettings> FallbackCommands
{
get => _fallbackCommands ?? ImmutableDictionary<string, FallbackSettings>.Empty;
init => _fallbackCommands = value;
}
private ImmutableList<string>? _pinnedCommandIds
public ImmutableList<string> PinnedCommandIds { get; init; }
= ImmutableList<string>.Empty;
public ImmutableList<string> PinnedCommandIds
{
get => _pinnedCommandIds ?? ImmutableList<string>.Empty;
init => _pinnedCommandIds = value;
}
[JsonIgnore]
public string ProviderId { get; init; } = string.Empty;
@@ -49,6 +37,7 @@ public record ProviderSettings
{
}
[JsonConstructor]
public ProviderSettings(bool isEnabled)
{
IsEnabled = isEnabled;

View File

@@ -1,20 +1,16 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Immutable;
using System.Text.Json.Serialization;
namespace Microsoft.CmdPal.UI.ViewModels;
public record RecentCommandsManager : IRecentCommandsManager
{
private ImmutableList<HistoryItem>? _history = ImmutableList<HistoryItem>.Empty;
internal ImmutableList<HistoryItem> History
{
get => _history ?? ImmutableList<HistoryItem>.Empty;
init => _history = value;
}
[JsonInclude]
internal ImmutableList<HistoryItem> History { get; init; } = ImmutableList<HistoryItem>.Empty;
public RecentCommandsManager()
{

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Text.Json;
using System.Text.Json.Serialization;
using Windows.UI;
@@ -19,7 +18,7 @@ public record DockSettings
{
public DockSide Side { get; init; } = DockSide.Top;
public DockSize DockSize { get; init; } = DockSize.Default;
public DockSize BandSize { get; init; } = DockSize.Default;
public bool AlwaysOnTop { get; set; } = true;
@@ -45,7 +44,7 @@ public record DockSettings
public string? BackgroundImagePath { get; init; }
// </Theme settings>
private ImmutableList<DockBandSettings>? _startBands = ImmutableList.Create(
public ImmutableList<DockBandSettings> StartBands { get; init; } = ImmutableList.Create(
new DockBandSettings
{
ProviderId = "com.microsoft.cmdpal.builtin.core",
@@ -55,24 +54,12 @@ public record DockSettings
{
ProviderId = "WinGet",
CommandId = "com.microsoft.cmdpal.winget",
ShowTitles = false,
ShowLabels = false,
});
public ImmutableList<DockBandSettings> StartBands
{
get => _startBands ?? ImmutableList<DockBandSettings>.Empty;
init => _startBands = value;
}
public ImmutableList<DockBandSettings> CenterBands { get; init; } = ImmutableList<DockBandSettings>.Empty;
private ImmutableList<DockBandSettings>? _centerBands = ImmutableList<DockBandSettings>.Empty;
public ImmutableList<DockBandSettings> CenterBands
{
get => _centerBands ?? ImmutableList<DockBandSettings>.Empty;
init => _centerBands = value;
}
private ImmutableList<DockBandSettings>? _endBands = ImmutableList.Create(
public ImmutableList<DockBandSettings> EndBands { get; init; } = ImmutableList.Create(
new DockBandSettings
{
ProviderId = "PerformanceMonitor",
@@ -84,12 +71,6 @@ public record DockSettings
CommandId = "com.microsoft.cmdpal.timedate.dockBand",
});
public ImmutableList<DockBandSettings> EndBands
{
get => _endBands ?? ImmutableList<DockBandSettings>.Empty;
init => _endBands = value;
}
public bool ShowLabels { get; init; } = true;
[JsonIgnore]
@@ -121,6 +102,16 @@ public record DockBandSettings
/// </summary>
public bool? ShowSubtitles { get; init; }
/// <summary>
/// Gets a value for backward compatibility. Maps to ShowTitles.
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
public bool? ShowLabels
{
get => ShowTitles;
init => ShowTitles = value;
}
/// <summary>
/// Resolves the effective value of <see cref="ShowTitles"/> for this band.
/// If this band doesn't have a specific value set, we'll fall back to the
@@ -144,52 +135,12 @@ public enum DockSide
Bottom = 3,
}
[JsonConverter(typeof(DockSizeJsonConverter))]
public enum DockSize
{
Default,
Compact,
}
/// <summary>
/// Custom converter for <see cref="DockSize"/> that preserves backward
/// compatibility with previously-persisted values. Earlier builds shipped a
/// <c>Small</c>/<c>Medium</c>/<c>Large</c> enum; those values are migrated to
/// <see cref="DockSize.Default"/> so existing settings.json files continue to
/// load instead of failing the entire deserialization.
/// </summary>
internal sealed class DockSizeJsonConverter : JsonConverter<DockSize>
{
public override DockSize Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var value = reader.GetString();
if (Enum.TryParse<DockSize>(value, ignoreCase: true, out var parsed))
{
return parsed;
}
// Legacy values from the original Small/Medium/Large enum, or any
// other unknown string — fall back to Default so the user's
// settings file remains loadable after upgrading.
return DockSize.Default;
}
if (reader.TokenType == JsonTokenType.Number && reader.TryGetInt32(out var number))
{
return Enum.IsDefined(typeof(DockSize), number) ? (DockSize)number : DockSize.Default;
}
return DockSize.Default;
}
public override void Write(Utf8JsonWriter writer, DockSize value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
public enum DockBackdrop
{
Transparent,

View File

@@ -55,14 +55,8 @@ public record HotkeySettings// : ICmdLineRepresentable
// This is currently needed for FancyZones, we need to unify these two objects
// see src\common\settings_objects.h
private string? _key = string.Empty;
[JsonPropertyName("key")]
public string Key
{
get => _key ?? string.Empty;
init => _key = value;
}
public string Key { get; init; } = string.Empty;
public override string ToString()
{

View File

@@ -39,41 +39,17 @@ public record SettingsModel
public bool AllowExternalReload { get; init; }
private ImmutableDictionary<string, ProviderSettings>? _providerSettings
public ImmutableDictionary<string, ProviderSettings> ProviderSettings { get; init; }
= ImmutableDictionary<string, ProviderSettings>.Empty;
public ImmutableDictionary<string, ProviderSettings> ProviderSettings
{
get => _providerSettings ?? ImmutableDictionary<string, ProviderSettings>.Empty;
init => _providerSettings = value;
}
public string[] FallbackRanks { get; init; } = [];
private string[]? _fallbackRanks = [];
public string[] FallbackRanks
{
get => _fallbackRanks ?? [];
init => _fallbackRanks = value;
}
private ImmutableDictionary<string, CommandAlias>? _aliases
public ImmutableDictionary<string, CommandAlias> Aliases { get; init; }
= ImmutableDictionary<string, CommandAlias>.Empty;
public ImmutableDictionary<string, CommandAlias> Aliases
{
get => _aliases ?? ImmutableDictionary<string, CommandAlias>.Empty;
init => _aliases = value;
}
private ImmutableList<TopLevelHotkey>? _commandHotkeys
public ImmutableList<TopLevelHotkey> CommandHotkeys { get; init; }
= ImmutableList<TopLevelHotkey>.Empty;
public ImmutableList<TopLevelHotkey> CommandHotkeys
{
get => _commandHotkeys ?? ImmutableList<TopLevelHotkey>.Empty;
init => _commandHotkeys = value;
}
public MonitorBehavior SummonOn { get; init; } = MonitorBehavior.ToMouse;
public bool DisableAnimations { get; init; } = true;
@@ -86,13 +62,7 @@ public record SettingsModel
public bool EnableDock { get; init; }
private DockSettings? _dockSettings = new();
public DockSettings DockSettings
{
get => _dockSettings ?? new();
init => _dockSettings = value;
}
public DockSettings DockSettings { get; init; } = new();
// Theme settings
public UserTheme Theme { get; init; } = UserTheme.Default;

View File

@@ -201,10 +201,10 @@ public partial class SettingsViewModel : INotifyPropertyChanged
public DockSize Dock_DockSize
{
get => _settingsService.Settings.DockSettings.DockSize;
get => _settingsService.Settings.DockSettings.BandSize;
set
{
_settingsService.UpdateSettings(s => s with { DockSettings = s.DockSettings with { DockSize = value } });
_settingsService.UpdateSettings(s => s with { DockSettings = s.DockSettings with { BandSize = value } });
}
}

View File

@@ -196,7 +196,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem, IEx
{
ProviderId = this.CommandProviderId,
CommandId = this.Id,
ShowTitles = true,
ShowLabels = true,
};
}

View File

@@ -245,7 +245,7 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
// Compact mode is only supported for Top/Bottom positions
var isHorizontal = settings.Side == DockSide.Top || settings.Side == DockSide.Bottom;
var effectiveSize = isHorizontal ? settings.DockSize : DockSize.Default;
var effectiveSize = isHorizontal ? settings.BandSize : DockSize.Default;
DockSize = effectiveSize;
ItemsOrientation = isHorizontal ? Orientation.Horizontal : Orientation.Vertical;

View File

@@ -449,7 +449,7 @@ public sealed partial class DockWindow : WindowEx,
private static DockSize EffectiveDockSize(DockSettings settings)
{
var isHorizontal = settings.Side == DockSide.Top || settings.Side == DockSide.Bottom;
return isHorizontal ? settings.DockSize : DockSize.Default;
return isHorizontal ? settings.BandSize : DockSize.Default;
}
private void UpdateAppBarDataForEdge(DockSide side, DockSize size, double scaleFactor)

View File

@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using ManagedCommon;
using Windows.Win32.Foundation;
using static PowerDisplay.Common.Drivers.NativeConstants;
using static PowerDisplay.Common.Drivers.PInvoke;
@@ -28,55 +27,32 @@ namespace PowerDisplay.Common.Drivers.DDC
{
if (hPhysicalMonitor == IntPtr.Zero)
{
Logger.LogWarning("DDC: Monitor ignored - null physical monitor handle");
return DdcCiValidationResult.Invalid;
}
var handleHex = $"0x{hPhysicalMonitor:X}";
try
{
// Try to get capabilities string (slow I2C operation)
var capsString = TryGetCapabilitiesString(hPhysicalMonitor);
if (string.IsNullOrEmpty(capsString))
{
Logger.LogWarning($"DDC: Monitor ignored (handle={handleHex}) - empty capabilities string from DDC/CI");
return DdcCiValidationResult.Invalid;
}
Logger.LogInfo($"DDC: Capabilities raw (handle={handleHex}, length={capsString.Length}): {capsString}");
// Parse the capabilities string
var parseResult = Utils.MccsCapabilitiesParser.Parse(capsString);
var capabilities = parseResult.Capabilities;
if (capabilities == null || capabilities.SupportedVcpCodes.Count == 0)
{
Logger.LogWarning($"DDC: Monitor ignored (handle={handleHex}) - parsed capabilities have no VCP codes (parseErrors={parseResult.Errors.Count})");
return DdcCiValidationResult.Invalid;
}
// Check if brightness (VCP 0x10) is supported - determines DDC/CI validity
bool supportsBrightness = capabilities.SupportsVcpCode(NativeConstants.VcpCodeBrightness);
bool supportsContrast = capabilities.SupportsVcpCode(NativeConstants.VcpCodeContrast);
bool supportsColorTemperature = capabilities.SupportsVcpCode(NativeConstants.VcpCodeSelectColorPreset);
bool supportsVolume = capabilities.SupportsVcpCode(NativeConstants.VcpCodeVolume);
Logger.LogInfo(
$"DDC: Capabilities parsed (handle={handleHex}) - " +
$"Brightness={supportsBrightness} Contrast={supportsContrast} " +
$"ColorTemperature={supportsColorTemperature} Volume={supportsVolume}");
if (!supportsBrightness)
{
Logger.LogWarning($"DDC: Monitor ignored (handle={handleHex}) - brightness (VCP 0x10) not advertised in capabilities");
}
return new DdcCiValidationResult(supportsBrightness, capsString, capabilities);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Logger.LogError($"DDC: Monitor ignored (handle={handleHex}) - exception during FetchCapabilities: {ex.Message}");
return DdcCiValidationResult.Invalid;
}
}
@@ -98,7 +74,6 @@ namespace PowerDisplay.Common.Drivers.DDC
// Get capabilities string length
if (!GetCapabilitiesStringLength(hPhysicalMonitor, out uint length) || length == 0)
{
Logger.LogWarning($"DDC: GetCapabilitiesStringLength failed (handle=0x{hPhysicalMonitor:X}, length={length})");
return null;
}
@@ -108,7 +83,6 @@ namespace PowerDisplay.Common.Drivers.DDC
{
if (!CapabilitiesRequestAndCapabilitiesReply(hPhysicalMonitor, buffer, length))
{
Logger.LogWarning($"DDC: CapabilitiesRequestAndCapabilitiesReply failed (handle=0x{hPhysicalMonitor:X})");
return null;
}
@@ -121,7 +95,6 @@ namespace PowerDisplay.Common.Drivers.DDC
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Logger.LogError($"DDC: TryGetCapabilitiesString exception (handle=0x{hPhysicalMonitor:X}): {ex.Message}");
return null;
}
}

View File

@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using ManagedCommon;
using PowerDisplay.Common.Interfaces;
using PowerDisplay.Common.Models;
using PowerDisplay.Common.Utils;
using WmiLight;
using Monitor = PowerDisplay.Common.Models.Monitor;
@@ -244,9 +245,8 @@ namespace PowerDisplay.Common.Drivers.WMI
/// <summary>
/// Discover supported monitors.
/// WMI brightness control is typically only available on internal laptop displays.
/// The monitor Name is left blank here; the ViewModel layer fills in a localized
/// "Built-in Display" string so it can be translated for the user's UI language.
/// WMI brightness control is typically only available on internal laptop displays,
/// which don't have meaningful UserFriendlyName in WmiMonitorID, so we use "Built-in Display".
/// </summary>
public async Task<IEnumerable<Monitor>> DiscoverMonitorsAsync(CancellationToken cancellationToken = default)
{
@@ -294,12 +294,13 @@ namespace PowerDisplay.Common.Drivers.WMI
? $"WMI_{edidId}_{monitorNumber}"
: $"WMI_Unknown_{monitorNumber}";
// Name is left blank: MonitorViewModel injects a localized
// "Built-in Display" string for internal displays.
// Get display name from PnP manufacturer ID (e.g., "Lenovo Built-in Display")
var displayName = PnpIdHelper.GetBuiltInDisplayName(edidId);
var monitor = new Monitor
{
Id = uniqueId,
Name = string.Empty,
Name = displayName,
CurrentBrightness = currentBrightness,
MinBrightness = 0,
MaxBrightness = 100,

View File

@@ -0,0 +1,86 @@
// 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.Collections.Frozen;
using System.Collections.Generic;
namespace PowerDisplay.Common.Utils;
/// <summary>
/// Helper class for mapping PnP (Plug and Play) manufacturer IDs to display names.
/// PnP IDs are 3-character codes assigned by Microsoft to hardware manufacturers.
/// See: https://uefi.org/pnp_id_list
/// </summary>
public static class PnpIdHelper
{
/// <summary>
/// Map of common laptop/monitor manufacturer PnP IDs to display names.
/// Only includes manufacturers known to produce laptops with internal displays.
/// </summary>
private static readonly FrozenDictionary<string, string> ManufacturerNames = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
// Major laptop manufacturers
{ "ACR", "Acer" },
{ "AUO", "AU Optronics" },
{ "BOE", "BOE" },
{ "CMN", "Chi Mei Innolux" },
{ "DEL", "Dell" },
{ "HWP", "HP" },
{ "IVO", "InfoVision" },
{ "LEN", "Lenovo" },
{ "LGD", "LG Display" },
{ "NCP", "Nanjing CEC Panda" },
{ "SAM", "Samsung" },
{ "SDC", "Samsung Display" },
{ "SEC", "Samsung Electronics" },
{ "SHP", "Sharp" },
{ "AUS", "ASUS" },
{ "MSI", "MSI" },
{ "APP", "Apple" },
{ "SNY", "Sony" },
{ "PHL", "Philips" },
{ "HSD", "HannStar" },
{ "CPT", "Chunghwa Picture Tubes" },
{ "QDS", "Quanta Display" },
{ "TMX", "Tianma Microelectronics" },
{ "CSO", "CSOT" },
// Microsoft Surface
{ "MSF", "Microsoft" },
}.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Extract the 3-character PnP manufacturer ID from an EDID ID.
/// </summary>
/// <param name="edidId">EDID ID like "LEN4038" or "BOE0900".</param>
/// <returns>The 3-character PnP ID (e.g., "LEN"), or null if invalid.</returns>
public static string? ExtractPnpId(string? edidId)
{
if (string.IsNullOrEmpty(edidId) || edidId.Length < 3)
{
return null;
}
// PnP ID is the first 3 characters
return edidId.Substring(0, 3).ToUpperInvariant();
}
/// <summary>
/// Get a user-friendly display name for an internal display based on its EDID ID.
/// </summary>
/// <param name="edidId">EDID ID like "LEN4038" or "BOE0900".</param>
/// <returns>Display name like "Lenovo Built-in Display" or "Built-in Display" as fallback.</returns>
public static string GetBuiltInDisplayName(string? edidId)
{
var pnpId = ExtractPnpId(edidId);
if (pnpId != null && ManufacturerNames.TryGetValue(pnpId, out var manufacturer))
{
return $"{manufacturer} Built-in Display";
}
return "Built-in Display";
}
}

View File

@@ -135,10 +135,6 @@
<data name="BuiltInMonitorTooltip.ToolTipService.ToolTip" xml:space="preserve">
<value>Built-in display</value>
</data>
<data name="BuiltInDisplayName" xml:space="preserve">
<value>Built-in display</value>
<comment>Display name shown in the monitor list for the laptop's internal/built-in display.</comment>
</data>
<data name="BrightnessTooltip.ToolTipService.ToolTip" xml:space="preserve">
<value>Brightness</value>
</data>

View File

@@ -415,17 +415,13 @@ public partial class MainViewModel
SupportsVolume = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0x62) ?? false,
SupportsPowerState = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0xD6) ?? false,
// Default Enable* for new monitors (first-time setup):
// - Contrast / Volume: enabled if the monitor advertises the VCP code (low-risk features).
// - InputSource / ColorTemperature / PowerState: always disabled by default. These can leave
// the monitor in a state recoverable only via physical buttons; users opt-in via the
// Settings UI checkbox, which raises a confirmation dialog (HandleDangerousFeatureClickAsync).
// ApplyPreservedUserSettings will override these with saved user preferences if they exist.
// Default Enable* to match Supports* for new monitors (first-time setup)
// ApplyPreservedUserSettings will override these with saved user preferences if they exist
EnableContrast = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0x12) ?? false,
EnableVolume = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0x62) ?? false,
EnableInputSource = false,
EnableColorTemperature = false,
EnablePowerState = false,
EnableInputSource = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0x60) ?? false,
EnableColorTemperature = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0x14) ?? false,
EnablePowerState = vm.VcpCapabilitiesInfo?.SupportedVcpCodes.ContainsKey(0xD6) ?? false,
// Monitor number for display name formatting
MonitorNumber = vm.MonitorNumber,

View File

@@ -215,19 +215,13 @@ public partial class MonitorViewModel : ObservableObject, IDisposable
// Subscribe to underlying Monitor property changes (e.g., Orientation updates in mirror mode)
_monitor.PropertyChanged += OnMonitorPropertyChanged;
// Initialize Show properties for first-time detection. ApplyFeatureVisibility will
// override these whenever settings.json has a saved entry for this monitor, so these
// values only take effect for brand-new monitors (no persisted preference yet).
// Mirror CreateMonitorInfo's defaults to keep the flyout and settings.json in sync:
// - Brightness / Contrast / Volume: enabled if the hardware advertises the VCP code.
// - InputSource / ColorTemperature / PowerState: always disabled by default (dangerous
// features); the user opts in via the Settings UI confirmation dialog.
// Initialize Show properties based on hardware capabilities
ShowBrightness = monitor.SupportsBrightness;
ShowContrast = monitor.SupportsContrast;
ShowVolume = monitor.SupportsVolume;
ShowInputSource = false;
_showPowerState = false;
_showColorTemperature = false;
ShowInputSource = monitor.SupportsInputSource;
_showPowerState = monitor.SupportsPowerState;
_showColorTemperature = monitor.SupportsColorTemperature;
// Initialize basic properties from monitor
_brightness = monitor.CurrentBrightness;
@@ -238,9 +232,7 @@ public partial class MonitorViewModel : ObservableObject, IDisposable
public string Id => _monitor.Id;
public string Name => IsInternal
? ResourceLoaderInstance.ResourceLoader.GetString("BuiltInDisplayName")
: _monitor.Name;
public string Name => _monitor.Name;
/// <summary>
/// Gets the monitor number from the underlying monitor model (Windows DISPLAY number)

View File

@@ -18,14 +18,6 @@
ModuleImageSource="ms-appx:///Assets/Settings/Modules/GrabAndMove.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<InfoBar
x:Uid="GrabAndMove_TouchpadInfoBar"
Margin="0,0,0,8"
IsClosable="False"
IsOpen="True"
Severity="Informational" />
<controls:GPOInfoControl ShowWarning="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="GrabAndMoveEnableToggleControlHeaderText"

View File

@@ -211,11 +211,7 @@
<CheckBox x:Uid="PowerDisplay_Monitor_EnableVolume" IsChecked="{x:Bind EnableVolume, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Left" IsEnabled="{x:Bind SupportsInputSource, Mode=OneWay}">
<CheckBox
x:Uid="PowerDisplay_Monitor_EnableInputSource"
Click="EnableInputSource_Click"
IsChecked="{x:Bind EnableInputSource, Mode=TwoWay}"
Tag="{x:Bind}" />
<CheckBox x:Uid="PowerDisplay_Monitor_EnableInputSource" IsChecked="{x:Bind EnableInputSource, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="PowerDisplay_Monitor_EnableRotation" IsChecked="{x:Bind EnableRotation, Mode=TwoWay}" />
@@ -228,11 +224,7 @@
Tag="{x:Bind}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Left" IsEnabled="{x:Bind SupportsPowerState, Mode=OneWay}">
<CheckBox
x:Uid="PowerDisplay_Monitor_EnablePowerState"
Click="EnablePowerState_Click"
IsChecked="{x:Bind EnablePowerState, Mode=TwoWay}"
Tag="{x:Bind}" />
<CheckBox x:Uid="PowerDisplay_Monitor_EnablePowerState" IsChecked="{x:Bind EnablePowerState, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="PowerDisplay_Monitor_HideMonitor" IsChecked="{x:Bind IsHidden, Mode=TwoWay}" />

View File

@@ -209,40 +209,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views
}
}
// Flag to prevent reentrant Click handling while we programmatically restore
// a checkbox after the user cancels a dangerous-feature confirmation dialog.
private bool _isRestoringDangerousFeatureCheckbox;
// Flag to prevent reentrant handling during programmatic checkbox changes
private bool _isRestoringColorTempCheckbox;
private async void EnableColorTemperature_Click(object sender, RoutedEventArgs e)
{
await HandleDangerousFeatureClickAsync(
sender,
"PowerDisplay_ColorTemperature",
(monitor, value) => monitor.EnableColorTemperature = value);
}
private async void EnablePowerState_Click(object sender, RoutedEventArgs e)
{
await HandleDangerousFeatureClickAsync(
sender,
"PowerDisplay_PowerState",
(monitor, value) => monitor.EnablePowerState = value);
}
private async void EnableInputSource_Click(object sender, RoutedEventArgs e)
{
await HandleDangerousFeatureClickAsync(
sender,
"PowerDisplay_InputSource",
(monitor, value) => monitor.EnableInputSource = value);
}
private async Task HandleDangerousFeatureClickAsync(
object sender,
string resourceKeyPrefix,
Action<MonitorInfo, bool> setter)
{
if (_isRestoringDangerousFeatureCheckbox)
// Skip if we're programmatically restoring the checkbox state
if (_isRestoringColorTempCheckbox)
{
return;
}
@@ -252,17 +225,18 @@ namespace Microsoft.PowerToys.Settings.UI.Views
return;
}
// Only show the warning when the user is enabling the feature.
// Only show warning when enabling (checking the box)
if (checkBox.IsChecked != true)
{
return;
}
// Show confirmation dialog with color temperature warning
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
var dialog = new ContentDialog
{
XamlRoot = this.XamlRoot,
Title = resourceLoader.GetString($"{resourceKeyPrefix}_WarningTitle"),
Title = resourceLoader.GetString("PowerDisplay_ColorTemperature_WarningTitle"),
Content = new StackPanel
{
Spacing = 12,
@@ -270,31 +244,31 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{
new TextBlock
{
Text = resourceLoader.GetString($"{resourceKeyPrefix}_WarningHeader"),
Text = resourceLoader.GetString("PowerDisplay_ColorTemperature_WarningHeader"),
FontWeight = Microsoft.UI.Text.FontWeights.Bold,
Foreground = (Microsoft.UI.Xaml.Media.Brush)Application.Current.Resources["SystemFillColorCriticalBrush"],
TextWrapping = TextWrapping.Wrap,
},
new TextBlock
{
Text = resourceLoader.GetString($"{resourceKeyPrefix}_WarningDescription"),
Text = resourceLoader.GetString("PowerDisplay_ColorTemperature_WarningDescription"),
TextWrapping = TextWrapping.Wrap,
},
new TextBlock
{
Text = resourceLoader.GetString($"{resourceKeyPrefix}_WarningList"),
Text = resourceLoader.GetString("PowerDisplay_ColorTemperature_WarningList"),
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(20, 0, 0, 0),
},
new TextBlock
{
Text = resourceLoader.GetString($"{resourceKeyPrefix}_WarningConfirm"),
Text = resourceLoader.GetString("PowerDisplay_ColorTemperature_WarningConfirm"),
FontWeight = Microsoft.UI.Text.FontWeights.SemiBold,
TextWrapping = TextWrapping.Wrap,
},
},
},
PrimaryButtonText = resourceLoader.GetString("PowerDisplay_Dialog_Enable"),
PrimaryButtonText = resourceLoader.GetString("PowerDisplay_ColorTemperature_EnableButton"),
CloseButtonText = resourceLoader.GetString("PowerDisplay_Dialog_Cancel"),
DefaultButton = ContentDialogButton.Close,
};
@@ -303,16 +277,16 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (result != ContentDialogResult.Primary)
{
// User cancelled: revert checkbox to unchecked.
_isRestoringDangerousFeatureCheckbox = true;
// User cancelled: revert checkbox to unchecked
_isRestoringColorTempCheckbox = true;
try
{
checkBox.IsChecked = false;
setter(monitor, false);
monitor.EnableColorTemperature = false;
}
finally
{
_isRestoringDangerousFeatureCheckbox = false;
_isRestoringColorTempCheckbox = false;
}
}
}

View File

@@ -5501,41 +5501,7 @@ The break timer font matches the text font.</value>
<data name="PowerDisplay_ColorTemperature_WarningConfirm" xml:space="preserve">
<value>Do you want to enable color temperature control for this monitor?</value>
</data>
<data name="PowerDisplay_PowerState_WarningTitle" xml:space="preserve">
<value>Confirm power state control</value>
</data>
<data name="PowerDisplay_PowerState_WarningHeader" xml:space="preserve">
<value>⚠️ Warning: This action may be unsafe.</value>
</data>
<data name="PowerDisplay_PowerState_WarningDescription" xml:space="preserve">
<value>Enabling power state control may lead to unexpected behavior, including:</value>
</data>
<data name="PowerDisplay_PowerState_WarningList" xml:space="preserve">
<value>• Monitor may enter standby and not wake via software.
• You may need to press the monitors power button or reconnect the cable to recover.
• Some monitors may not restore the previous state correctly.</value>
</data>
<data name="PowerDisplay_PowerState_WarningConfirm" xml:space="preserve">
<value>Enable power state control for this monitor?</value>
</data>
<data name="PowerDisplay_InputSource_WarningTitle" xml:space="preserve">
<value>Confirm input source control</value>
</data>
<data name="PowerDisplay_InputSource_WarningHeader" xml:space="preserve">
<value>⚠️ Warning: This action may be unsafe.</value>
</data>
<data name="PowerDisplay_InputSource_WarningDescription" xml:space="preserve">
<value>Switching input sources may cause unintended results, including:</value>
</data>
<data name="PowerDisplay_InputSource_WarningList" xml:space="preserve">
<value>• Screen may go black if the selected input has no signal.
• Software control may be lost until you switch back using the monitors physical buttons.
• Some monitors may not reliably expose all input sources.</value>
</data>
<data name="PowerDisplay_InputSource_WarningConfirm" xml:space="preserve">
<value>Enable input source control for this monitor?</value>
</data>
<data name="PowerDisplay_Dialog_Enable" xml:space="preserve">
<data name="PowerDisplay_ColorTemperature_EnableButton" xml:space="preserve">
<value>Enable</value>
</data>
<data name="PowerDisplay_Dialog_Cancel" xml:space="preserve">
@@ -5977,13 +5943,6 @@ Text uses the current drawing color.</value>
<value>Grab And Move</value>
<comment>"Grab And Move" is the name of the utility</comment>
</data>
<data name="GrabAndMove_TouchpadInfoBar.Title" xml:space="preserve">
<value>Touchpad support</value>
</data>
<data name="GrabAndMove_TouchpadInfoBar.Message" xml:space="preserve">
<value>Grab And Move may not work reliably with some touchpads.</value>
<comment>"Grab And Move" is the name of the utility</comment>
</data>
<data name="LearnMore_GrabAndMove.Text" xml:space="preserve">
<value>Learn more about Grab And Move</value>
<comment>"Grab And Move" is the name of the utility</comment>

View File

@@ -9,7 +9,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
@@ -136,18 +135,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
var sourcePage = e.SourcePageType?.FullName ?? "<unknown>";
if (e.Exception is null)
{
Logger.LogWarning($"Navigation to '{sourcePage}' failed without an exception.");
}
else
{
Logger.LogError($"Navigation to '{sourcePage}' failed.", e.Exception);
}
e.Handled = true;
throw e.Exception;
}
private void Frame_Navigated(object sender, NavigationEventArgs e)