CmdPal: Allow mouse X1 button to navigate back (#40517)

## Summary of the Pull Request
Enables navigation to the previous page when the mouse X1 (back) button
is pressed. This improves user experience for those using multi-button
mice, making navigation more intuitive.

## PR Checklist

- [x] **Closes:** #40499
- [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:** nope
- [x] **New binaries:** nada
- [x] **Documentation updated:** nothing to add

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed
This commit is contained in:
Jiří Polášek
2025-07-10 21:56:00 +02:00
committed by GitHub
parent dbad946b6d
commit beb85e69a8
2 changed files with 25 additions and 0 deletions

View File

@@ -1932,6 +1932,7 @@ Wubi
WUX
Wwanpp
XAxis
XButton
xclip
xcopy
XDeployment

View File

@@ -14,8 +14,10 @@ using Microsoft.CommandPalette.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media.Animation;
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
@@ -79,6 +81,8 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
WeakReferenceMessenger.Default.Register<ShowToastMessage>(this);
WeakReferenceMessenger.Default.Register<NavigateToPageMessage>(this);
AddHandler(PointerPressedEvent, new PointerEventHandler(ShellPage_OnPointerPressed), true);
RootFrame.Navigate(typeof(LoadingPage), ViewModel);
}
@@ -442,4 +446,24 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(commandViewModel.Model));
}
}
private void ShellPage_OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
try
{
var ptr = e.Pointer;
if (ptr.PointerDeviceType == PointerDeviceType.Mouse)
{
var ptrPt = e.GetCurrentPoint(this);
if (ptrPt.Properties.IsXButton1Pressed)
{
WeakReferenceMessenger.Default.Send(new NavigateBackMessage());
}
}
}
catch (Exception ex)
{
Logger.LogError("Error handling mouse button press event", ex);
}
}
}