Skip to content

Fix: Fixed an issue where the title bar drag region was sometimes missing #16549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Files.App/UserControls/TabBar/TabBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="Transparent" />
Fill="Transparent"
Loaded="DragAreaRectangle_Loaded" />

</Grid>
</TabView.TabStripFooter>
Expand Down
45 changes: 36 additions & 9 deletions src/Files.App/UserControls/TabBar/TabBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.WinUI.UI;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Shapes;
using Windows.ApplicationModel.DataTransfer;
using Windows.Graphics;
using Windows.Storage;
using Windows.Win32;

Expand Down Expand Up @@ -64,15 +66,6 @@ public TabBar()
tabHoverTimer.Interval = TimeSpan.FromMilliseconds(Constants.DragAndDrop.HoverToOpenTimespan);
tabHoverTimer.Tick += TabHoverSelected;

var appWindow = MainWindow.Instance.AppWindow;

double rightPaddingColumnWidth =
FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft
? appWindow.TitleBar.LeftInset
: appWindow.TitleBar.RightInset;

RightPaddingColumn.Width = new(rightPaddingColumnWidth >= 0 ? rightPaddingColumnWidth : 0);

AppearanceSettingsService.PropertyChanged += (s, e) =>
{
switch (e.PropertyName)
Expand Down Expand Up @@ -366,5 +359,39 @@ private void TabViewItem_Loaded(object sender, RoutedEventArgs e)
});
}
}

private void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
{
if (HorizontalTabView.ActualWidth > 0 && TabBarAddNewTabButton.Width > 0)
{
var appWindow = MainWindow.Instance.AppWindow;
var titleBarInset = (FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft
? appWindow.TitleBar.LeftInset
: appWindow.TitleBar.RightInset) / DragAreaRectangle.XamlRoot.RasterizationScale;

if (titleBarInset > 0)
{
titleBarInset += 40; // Add 40px gap
RightPaddingColumn.Width = new(titleBarInset);

HorizontalTabView.Measure(new(
HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - titleBarInset,
HorizontalTabView.ActualHeight));

return;
}
}

DispatcherQueue.TryEnqueue(() => DragAreaRectangle_Loaded(sender, e));
}

public int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
{
var height = (int)ActualHeight;
var width = (int)(ActualWidth - DragArea.ActualWidth);

source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, width, height))]);
return height;
}
}
}
13 changes: 4 additions & 9 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh

private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs e)
{
TabControl.DragArea.SizeChanged += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
TabControl.DragArea.SizeChanged += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(TabControl.SetTitleBarDragRegion);
TabControl.SizeChanged += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(TabControl.SetTitleBarDragRegion);

if (ViewModel.MultitaskingControl is not TabBar)
{
ViewModel.MultitaskingControl = TabControl;
Expand All @@ -135,13 +137,6 @@ private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs
}
}

private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
{
var height = (int)TabControl.ActualHeight;
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, (int)(TabControl.ActualWidth + TabControl.Margin.Left - TabControl.DragArea.ActualWidth), height))]);
return height;
}

public async void TabItemContent_ContentChanged(object? sender, TabBarItemParameter e)
{
if (SidebarAdaptiveViewModel.PaneHolder is null)
Expand Down Expand Up @@ -279,7 +274,7 @@ protected override void OnLostFocus(RoutedEventArgs e)

private void Page_Loaded(object sender, RoutedEventArgs e)
{
MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(TabControl.SetTitleBarDragRegion);

// Defers the status bar loading until after the page has loaded to improve startup perf
FindName(nameof(StatusBar));
Expand Down