Always On Top: The opacity should be able to configure the hotkey individually (#46410)

<!-- 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
This pull request adds support for customizing the hotkeys used to
increase and decrease the opacity of pinned windows in the Always On Top
module.
Previously, these shortcuts were hardcoded to use the same modifiers as
the main pin hotkey.

With these changes, users can now independently configure the increase
and decrease opacity shortcuts via the settings UI, and the backend has
been updated to respect and store these new settings.

Another change: If window is not Always On Topped, the opacity change
take no effect, so we should not intercept, we should pass through to
minimize the impact.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [X] Closes: #46391, #46387
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **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
<img width="1184" height="351" alt="image"
src="https://github.com/user-attachments/assets/5d20ffae-9f0c-4ce3-9d85-2ba1efea6301"
/>

<img width="336" height="244" alt="image"
src="https://github.com/user-attachments/assets/a78cc4a3-9eb3-49f1-bbb9-d6db37554e53"
/>

Verified locally that transparency hotkey will not intercept the normal
hotkey in window if Always on top not enabled

---------

Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
Kai Tao
2026-03-25 02:02:36 +08:00
committed by GitHub
parent fa78cc8ea7
commit 21f06b8bd0
11 changed files with 196 additions and 110 deletions

View File

@@ -34,13 +34,13 @@
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind Path=ViewModel.Hotkey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Description>
<StackPanel Orientation="Vertical">
<tkcontrols:MarkdownTextBlock Config="{StaticResource DescriptionTextMarkdownConfig}" Text="{x:Bind ViewModel.IncreaseOpacityShortcut, Mode=OneWay}" />
<tkcontrols:MarkdownTextBlock Config="{StaticResource DescriptionTextMarkdownConfig}" Text="{x:Bind ViewModel.DecreaseOpacityShortcut, Mode=OneWay}" />
</StackPanel>
</tkcontrols:SettingsCard.Description>
<!-- HACK: For some weird reason, a ShortcutControl does not work correctly if it's the first or last item in the expander, so we add an invisible card. -->
<tkcontrols:SettingsCard Visibility="Collapsed" />
<tkcontrols:SettingsCard x:Uid="AlwaysOnTop_IncreaseOpacityShortcut">
<controls:ShortcutControl HotkeySettings="{x:Bind Path=ViewModel.IncreaseOpacityHotkey, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard x:Uid="AlwaysOnTop_DecreaseOpacityShortcut">
<controls:ShortcutControl HotkeySettings="{x:Bind Path=ViewModel.DecreaseOpacityHotkey, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="AlwaysOnTop_GameMode" IsChecked="{x:Bind ViewModel.DoNotActivateOnGameMode, Mode=TwoWay}" />

View File

@@ -3054,11 +3054,17 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="AlwaysOnTop_ActivationShortcut.Description" xml:space="preserve">
<value>Customize the shortcut to pin or unpin an app window</value>
</data>
<data name="AlwaysOnTop_IncreaseOpacity" xml:space="preserve">
<value>Press **{0}** to increase the opacity of the window</value>
<data name="AlwaysOnTop_IncreaseOpacityShortcut.Header" xml:space="preserve">
<value>Increase opacity</value>
</data>
<data name="AlwaysOnTop_DecreaseOpacity" xml:space="preserve">
<value>Press **{0}** to decrease the opacity of the window</value>
<data name="AlwaysOnTop_IncreaseOpacityShortcut.Description" xml:space="preserve">
<value>Customize the shortcut to increase the opacity of a pinned window</value>
</data>
<data name="AlwaysOnTop_DecreaseOpacityShortcut.Header" xml:space="preserve">
<value>Decrease opacity</value>
</data>
<data name="AlwaysOnTop_DecreaseOpacityShortcut.Description" xml:space="preserve">
<value>Customize the shortcut to decrease the opacity of a pinned window</value>
</data>
<data name="Oobe_AlwaysOnTop.Title" xml:space="preserve">
<value>Always On Top</value>

View File

@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using global::PowerToys.GPOWrapper;
@@ -50,6 +49,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
Settings = moduleSettingsRepository.SettingsConfig;
_hotkey = Settings.Properties.Hotkey.Value;
_increaseOpacityHotkey = Settings.Properties.IncreaseOpacityHotkey.Value;
_decreaseOpacityHotkey = Settings.Properties.DecreaseOpacityHotkey.Value;
_showInSystemMenu = Settings.Properties.ShowInSystemMenu.Value;
_frameEnabled = Settings.Properties.FrameEnabled.Value;
_frameThickness = Settings.Properties.FrameThickness.Value;
@@ -85,7 +86,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
var hotkeysDict = new Dictionary<string, HotkeySettings[]>
{
[ModuleName] = [Hotkey],
[ModuleName] = [Hotkey, IncreaseOpacityHotkey, DecreaseOpacityHotkey],
};
return hotkeysDict;
@@ -135,10 +136,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
Settings.Properties.Hotkey.Value = _hotkey;
NotifyPropertyChanged();
// Also notify that transparency shortcut strings have changed
OnPropertyChanged(nameof(IncreaseOpacityShortcut));
OnPropertyChanged(nameof(DecreaseOpacityShortcut));
// Using InvariantCulture as this is an IPC message
SendConfigMSG(
string.Format(
@@ -150,6 +147,52 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public HotkeySettings IncreaseOpacityHotkey
{
get => _increaseOpacityHotkey;
set
{
if (value != _increaseOpacityHotkey)
{
_increaseOpacityHotkey = value ?? AlwaysOnTopProperties.DefaultIncreaseOpacityHotkeyValue;
Settings.Properties.IncreaseOpacityHotkey.Value = _increaseOpacityHotkey;
NotifyPropertyChanged();
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
AlwaysOnTopSettings.ModuleName,
JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.AlwaysOnTopSettings)));
}
}
}
public HotkeySettings DecreaseOpacityHotkey
{
get => _decreaseOpacityHotkey;
set
{
if (value != _decreaseOpacityHotkey)
{
_decreaseOpacityHotkey = value ?? AlwaysOnTopProperties.DefaultDecreaseOpacityHotkeyValue;
Settings.Properties.DecreaseOpacityHotkey.Value = _decreaseOpacityHotkey;
NotifyPropertyChanged();
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
AlwaysOnTopSettings.ModuleName,
JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.AlwaysOnTopSettings)));
}
}
}
public bool FrameEnabled
{
get => _frameEnabled;
@@ -310,32 +353,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
/// <summary>
/// Gets the formatted shortcut string for increasing window opacity (modifier keys + "+").
/// </summary>
public string IncreaseOpacityShortcut
{
get
{
var modifiers = new HotkeySettings(_hotkey.Win, _hotkey.Ctrl, _hotkey.Alt, _hotkey.Shift, 0).ToString();
var shortcut = string.IsNullOrEmpty(modifiers) ? "+" : modifiers + " + +";
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("AlwaysOnTop_IncreaseOpacity"), shortcut);
}
}
/// <summary>
/// Gets the formatted shortcut string for decreasing window opacity (modifier keys + "-").
/// </summary>
public string DecreaseOpacityShortcut
{
get
{
var modifiers = new HotkeySettings(_hotkey.Win, _hotkey.Ctrl, _hotkey.Alt, _hotkey.Shift, 0).ToString();
var shortcut = string.IsNullOrEmpty(modifiers) ? "-" : modifiers + " + -";
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("AlwaysOnTop_DecreaseOpacity"), shortcut);
}
}
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
@@ -352,6 +369,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _enabledStateIsGPOConfigured;
private bool _isEnabled;
private HotkeySettings _hotkey;
private HotkeySettings _increaseOpacityHotkey;
private HotkeySettings _decreaseOpacityHotkey;
private bool _showInSystemMenu;
private bool _frameEnabled;
private int _frameThickness;

View File

@@ -521,7 +521,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
ISettingsRepository<AlwaysOnTopSettings> moduleSettingsRepository = SettingsRepository<AlwaysOnTopSettings>.GetInstance(SettingsUtils.Default);
var list = new List<DashboardModuleItem>
{
new DashboardModuleShortcutItem() { Label = resourceLoader.GetString("AlwaysOnTop_ShortDescription"), Shortcut = moduleSettingsRepository.SettingsConfig.Properties.Hotkey.Value.GetKeysList() },
new DashboardModuleShortcutItem() { Label = resourceLoader.GetString("AlwaysOnTop_ActivationShortcut/Header"), Shortcut = moduleSettingsRepository.SettingsConfig.Properties.Hotkey.Value.GetKeysList() },
new DashboardModuleShortcutItem() { Label = resourceLoader.GetString("AlwaysOnTop_IncreaseOpacityShortcut/Header"), Shortcut = moduleSettingsRepository.SettingsConfig.Properties.IncreaseOpacityHotkey.Value.GetKeysList() },
new DashboardModuleShortcutItem() { Label = resourceLoader.GetString("AlwaysOnTop_DecreaseOpacityShortcut/Header"), Shortcut = moduleSettingsRepository.SettingsConfig.Properties.DecreaseOpacityHotkey.Value.GetKeysList() },
};
return new ObservableCollection<DashboardModuleItem>(list);
}