Skip to content

Commit 085baeb

Browse files
committed
feat: add back nav on side button #90
1 parent 481d2d2 commit 085baeb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Nagi.WinUI/MainPage.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ private async void OnMainPageLoaded(object sender, RoutedEventArgs e)
299299

300300
_ = ApplyDynamicThemeForCurrentTrackAsync();
301301
UpdatePlayerVisualState(false);
302+
303+
AddHandler(PointerPressedEvent, new PointerEventHandler(OnGlobalPointerPressed), true);
302304
}
303305
catch (Exception ex)
304306
{
@@ -319,6 +321,8 @@ private void OnMainPageUnloaded(object sender, RoutedEventArgs e)
319321

320322
// Dispose the tray icon control to prevent "Exception Processing Message 0xc0000005" errors on exit.
321323
AppTrayIconHost?.Dispose();
324+
325+
RemoveHandler(PointerPressedEvent, (PointerEventHandler)OnGlobalPointerPressed);
322326
}
323327

324328
/// <summary>
@@ -545,4 +549,20 @@ private async Task RestorePaneStateAsync()
545549
}
546550
}
547551

552+
/// <summary>
553+
/// Handles global pointer pressed events to enable back navigation using the mouse side button.
554+
/// This is registered with handledEventsToo: true to catch events even if child controls swallow them.
555+
/// </summary>
556+
private void OnGlobalPointerPressed(object sender, PointerRoutedEventArgs e)
557+
{
558+
var point = e.GetCurrentPoint(sender as UIElement);
559+
var properties = point.Properties;
560+
561+
if (properties.PointerUpdateKind == Microsoft.UI.Input.PointerUpdateKind.XButton1Pressed)
562+
{
563+
TryGoBack();
564+
e.Handled = true;
565+
}
566+
}
567+
548568
}

0 commit comments

Comments
 (0)