mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
Enable "Space" only to activate Peek (#41867)
<!-- 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 Closes: #26143 This pull request introduces a new "single Space key activation" mode for the Peek PowerToy, allowing users to open Peek with just the Space key when File Explorer or the Desktop is focused. The implementation includes settings UI changes, backend logic to enforce and manage this mode, eligibility checks for activation, and telemetry. It also enhances the user experience by disabling the activation shortcut control when space mode is enabled and providing appropriate tooltips and localization. **Key changes:** ### Feature: Single Space Key Activation Mode * Added a new setting (`EnableSpaceToActivate`) to allow users to enable Peek activation using only the Space key, restricted to File Explorer or Desktop focus. When enabled, the activation shortcut is forced to bare Space and the previous shortcut is stashed (not restored on toggle-off for simplicity). (`src/modules/peek/peek/dllmain.cpp`, `src/settings-ui/Settings.UI.Library/PeekProperties.cs`, `src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs`, `src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml`, `src/settings-ui/Settings.UI/Strings/en-us/Resources.resw`) [[1]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R132-R169) [[2]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R79-R80) [[3]](diffhunk://#diff-d482fce7c2d0abbe2b307351ef7588378ddf34d47b31ebf71411f264dcce07faR22) [[4]](diffhunk://#diff-d482fce7c2d0abbe2b307351ef7588378ddf34d47b31ebf71411f264dcce07faR33-R35) [[5]](diffhunk://#diff-3fb87fad8b86d17fa39d2319425f78d3029e3de89e88f4040d449d6a16d9d240R228-R257) [[6]](diffhunk://#diff-f474be48688a195b3cce5b395ea6c0cbc93d7a76d228dcb5dc4fc33f36f2ce83L17-R51) [[7]](diffhunk://#diff-dada9baae540a067141b033257982d33df5a6a504e1a1d492fa2961bd04b6a03R3155-R3165) <img width="1018" height="197" alt="image" src="https://github.com/user-attachments/assets/6f9eec4a-2583-41e5-92e9-9dfbc186728a" /> * UI will hide the activation shortcut control. Attempts to change the shortcut programmatically are ignored while in this mode. (`src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml`, `src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs`, `src/settings-ui/Settings.UI/Strings/en-us/Resources.resw`) [[1]](diffhunk://#diff-f474be48688a195b3cce5b395ea6c0cbc93d7a76d228dcb5dc4fc33f36f2ce83L17-R51) [[2]](diffhunk://#diff-3fb87fad8b86d17fa39d2319425f78d3029e3de89e88f4040d449d6a16d9d240R173-R178) [[3]](diffhunk://#diff-3fb87fad8b86d17fa39d2319425f78d3029e3de89e88f4040d449d6a16d9d240R228-R257) [[4]](diffhunk://#diff-dada9baae540a067141b033257982d33df5a6a504e1a1d492fa2961bd04b6a03R3155-R3165) <img width="1014" height="116" alt="image" src="https://github.com/user-attachments/assets/d1513101-a859-4b06-9252-2e707bce6689" /> ### Activation Logic & Eligibility * Implemented a foreground window hook and debounce logic to determine if Peek can be activated by Space (only when File Explorer, Desktop, or Peek itself is focused). This minimizes CPU overhead when user repeatedly presses Space but not for Peek . (`src/modules/peek/peek/dllmain.cpp`) [[1]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R50-R60) [[2]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R188-R292) [[3]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039L457-R637) * Managed hook installation and cleanup based on Peek's enabled state and the space mode toggle. (`src/modules/peek/peek/dllmain.cpp`) [[1]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R188-R292) [[2]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R562) [[3]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R593) [[4]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R496) ### Settings & Telemetry * Added the new toggle to the settings serialization and XAML UI, with localization and descriptions. (`src/modules/peek/peek/dllmain.cpp`, `src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml`, `src/settings-ui/Settings.UI/Strings/en-us/Resources.resw`) [[1]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R530) [[2]](diffhunk://#diff-f474be48688a195b3cce5b395ea6c0cbc93d7a76d228dcb5dc4fc33f36f2ce83L17-R51) [[3]](diffhunk://#diff-dada9baae540a067141b033257982d33df5a6a504e1a1d492fa2961bd04b6a03R3155-R3165) * Added telemetry event for enabling/disabling space mode. (`src/modules/peek/peek/trace.cpp`, `src/modules/peek/peek/trace.h`) [[1]](diffhunk://#diff-db76a3e6fa1cc19889492b72d0c063835bdc8f67909cb9d91c9e7e47e248a87aR51-R60) [[2]](diffhunk://#diff-8f824b0a7dd76f7fcd4a15b7885233b5b3212403a56c4efd67b83c4c2d02e486R18-R20) ### Code Quality * Refactored includes and initialization logic for clarity and maintainability. (`src/modules/peek/peek/dllmain.cpp`) [[1]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039L2-R14) [[2]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R37-R39) [[3]](diffhunk://#diff-ac3987a14b7c287a047f57613d97a78265f0dcef56084fb5361021953328b039R483) These changes collectively provide a safer, more accessible, and user-friendly way to activate Peek with a single key, while ensuring users are clearly informed and accidental activations are minimized. <!-- Please review the items on the PR checklist before submitting--> --------- Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
@@ -19,6 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
AlwaysRunNotElevated = new BoolProperty(true);
|
||||
CloseAfterLosingFocus = new BoolProperty(false);
|
||||
ConfirmFileDelete = new BoolProperty(true);
|
||||
EnableSpaceToActivate = new BoolProperty(true); // Toggle is ON by default for new users. No impact on existing users.
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut { get; set; }
|
||||
@@ -29,6 +30,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public BoolProperty ConfirmFileDelete { get; set; }
|
||||
|
||||
public BoolProperty EnableSpaceToActivate { get; set; }
|
||||
|
||||
public override string ToString() => JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public class PeekSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig
|
||||
{
|
||||
public const string ModuleName = "Peek";
|
||||
public const string ModuleVersion = "0.0.1";
|
||||
public const string InitialModuleVersion = "0.0.1";
|
||||
public const string SpaceActivationIntroducedVersion = "0.0.2";
|
||||
public const string CurrentModuleVersion = SpaceActivationIntroducedVersion;
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
@@ -28,7 +30,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public PeekSettings()
|
||||
{
|
||||
Name = ModuleName;
|
||||
Version = ModuleVersion;
|
||||
Version = CurrentModuleVersion;
|
||||
Properties = new PeekProperties();
|
||||
}
|
||||
|
||||
@@ -54,6 +56,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Version) ||
|
||||
Version.Equals(InitialModuleVersion, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Version = CurrentModuleVersion;
|
||||
Properties.EnableSpaceToActivate.Value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,19 @@
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
|
||||
</tkcontrols:SettingsCard>
|
||||
</controls:GPOInfoControl>
|
||||
|
||||
<controls:SettingsGroup x:Uid="Peek_Activation_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
||||
<tkcontrols:SettingsCard x:Uid="Peek_ActivationMethod">
|
||||
<ComboBox SelectedIndex="{x:Bind ViewModel.EnableSpaceToActivate, Mode=TwoWay, Converter={StaticResource BoolToComboBoxIndexConverter}}">
|
||||
<ComboBoxItem x:Uid="Peek_ActivationMethod_CustomizedShortcut" />
|
||||
<ComboBoxItem x:Uid="Peek_ActivationMethod_SpaceBar" />
|
||||
</ComboBox>
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard
|
||||
Name="ActivationShortcut"
|
||||
x:Uid="Activation_Shortcut"
|
||||
HeaderIcon="{ui:FontIcon Glyph=}">
|
||||
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||
Visibility="{x:Bind ViewModel.EnableSpaceToActivate, Mode=OneWay, Converter={StaticResource ReverseBoolToVisibilityConverter}}">
|
||||
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.ActivationShortcut, Mode=TwoWay}" />
|
||||
</tkcontrols:SettingsCard>
|
||||
</controls:SettingsGroup>
|
||||
|
||||
@@ -3152,6 +3152,19 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<data name="Peek_ConfirmFileDelete.Description" xml:space="preserve">
|
||||
<value>You'll be asked to confirm before files are moved to the Recycle Bin</value>
|
||||
</data>
|
||||
<data name="Peek_ActivationMethod.Header" xml:space="preserve">
|
||||
<value>Activation method</value>
|
||||
</data>
|
||||
<data name="Peek_ActivationMethod.Description" xml:space="preserve">
|
||||
<value>Use a shortcut or press the Spacebar when a file is selected</value>
|
||||
<comment>Spacebar is a physical keyboard key</comment>
|
||||
</data>
|
||||
<data name="Peek_ActivationMethod_CustomizedShortcut.Content" xml:space="preserve">
|
||||
<value>Custom shortcut</value>
|
||||
</data>
|
||||
<data name="Peek_ActivationMethod_SpaceBar.Content" xml:space="preserve">
|
||||
<value>Spacebar</value>
|
||||
</data>
|
||||
<data name="FancyZones_DisableRoundCornersOnWindowSnap.Content" xml:space="preserve">
|
||||
<value>Disable rounded corners when a window is snapped</value>
|
||||
</data>
|
||||
|
||||
@@ -170,6 +170,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
if (_peekSettings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
// If space mode toggle is on, ignore external attempts to change (UI will be disabled, but defensive).
|
||||
if (EnableSpaceToActivate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_peekSettings.Properties.ActivationShortcut = value ?? _peekSettings.Properties.DefaultActivationShortcut;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
NotifySettingsChanged();
|
||||
@@ -219,6 +225,33 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnableSpaceToActivate
|
||||
{
|
||||
get => _peekSettings.Properties.EnableSpaceToActivate.Value;
|
||||
set
|
||||
{
|
||||
if (_peekSettings.Properties.EnableSpaceToActivate.Value != value)
|
||||
{
|
||||
_peekSettings.Properties.EnableSpaceToActivate.Value = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
// Force single space (0x20) without modifiers.
|
||||
_peekSettings.Properties.ActivationShortcut = new HotkeySettings(false, false, false, false, 0x20);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Revert to default (design simplification, not restoring previous custom combo).
|
||||
_peekSettings.Properties.ActivationShortcut = _peekSettings.Properties.DefaultActivationShortcut;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(EnableSpaceToActivate));
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SourceCodeWrapText
|
||||
{
|
||||
get => _peekPreviewSettings.SourceCodeWrapText.Value;
|
||||
|
||||
Reference in New Issue
Block a user