From 51b5033d5048e9e9ec478d93d0a66aa6061d95ae Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:31:33 +0900 Subject: [PATCH] Update MainPage.xaml.cs --- src/Files.App/Views/MainPage.xaml.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 6930515eda5d..f4c5c2b8f2c0 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -15,6 +15,7 @@ using Windows.Foundation.Metadata; using Windows.Graphics; using Windows.UI.Input; +using Windows.Win32; using WinUIEx; using GridSplitter = Files.App.Controls.GridSplitter; using VirtualKey = Windows.System.VirtualKey; @@ -32,8 +33,10 @@ public sealed partial class MainPage : Page public MainPageViewModel ViewModel { get; } private bool keyReleased = true; + private const int KEY_DOWN_MASK = 0x8000; private DispatcherQueueTimer _updateDateDisplayTimer; + private InputNonClientPointerSource? _nonClientPointerSource; private readonly Dictionary _sidebarScrollByTab = new(); private TabBarItem? _previousSidebarTab; @@ -122,6 +125,15 @@ private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 return height; } + private async void NonClientPointerSource_PointerPressed(InputNonClientPointerSource sender, NonClientPointerEventArgs args) + { + if (args.RegionKind is not NonClientRegionKind.Caption || + (PInvoke.GetKeyState((int)VirtualKey.MiddleButton) & KEY_DOWN_MASK) == 0) + return; + + await NavigationHelpers.AddNewTabAsync(); + } + public async void TabItemContent_ContentChanged(object? sender, TabBarItemParameter e) { if (SidebarAdaptiveViewModel.PaneHolder is null) @@ -297,6 +309,12 @@ private void Page_Loaded(object sender, RoutedEventArgs e) FindName(nameof(TabControl)); FindName(nameof(NavToolbar)); + if (_nonClientPointerSource is null) + { + _nonClientPointerSource = InputNonClientPointerSource.GetForWindowId(MainWindow.Instance.AppWindow.Id); + _nonClientPointerSource.PointerPressed += NonClientPointerSource_PointerPressed; + } + // Notify user that drag and drop is disabled // Prompt is disabled in the dev environment to prevent issues with the automation testing // ToDo put this in a StartupPromptService