Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ IApplicationDocumentLists
ApplicationDocumentLists
IApplicationActivationManager
MENU_ITEM_TYPE
GetDpiForMonitor
MonitorFromWindow
2 changes: 2 additions & 0 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ public static partial class Win32PInvoke
public const string LOCALE_NAME_USER_DEFAULT = null;
public const string LOCALE_NAME_INVARIANT = "";
public const string LOCALE_NAME_SYSTEM_DEFAULT = "!sys-default-locale";

public const int USER_DEFAULT_SCREEN_DPI = 96;
}
}
13 changes: 13 additions & 0 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using System.Runtime.InteropServices;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
using Windows.Win32;
using Windows.Win32.Graphics.Gdi;
using Windows.Win32.UI.HiDpi;
using IO = System.IO;

namespace Files.App
Expand Down Expand Up @@ -339,5 +342,15 @@ x.tabItem.NavigationParameter.NavigationParameter is PaneNavigationArguments pan
}
}
}

public double GetDpiScale()
{
var hMonitor = PInvoke.MonitorFromWindow(
new(WinRT.Interop.WindowNative.GetWindowHandle(this)),
MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);

var res = PInvoke.GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var dpiX, out var _);
return res == 0 ? ((float)dpiX / Win32PInvoke.USER_DEFAULT_SCREEN_DPI) : 1;
}
}
}
5 changes: 3 additions & 2 deletions src/Files.App/UserControls/TabBar/TabBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition x:Name="RightPaddingColumn" Width="0" />
<ColumnDefinition x:Name="RightPaddingColumn" Width="{x:Bind TitleBarWidth, Mode=OneWay}" />
</Grid.ColumnDefinitions>

<!-- Height is not divisble by four in order to properly align the button -->
Expand Down 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
32 changes: 27 additions & 5 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 All @@ -28,6 +30,8 @@ public sealed partial class TabBar : BaseTabBar, INotifyPropertyChanged

private bool _lockDropOperation = false;

private static int _gap = 6;

// Starting position when dragging a tab
private System.Drawing.Point dragStartPoint;

Expand All @@ -51,6 +55,14 @@ public bool AllowTabsDrag
public Rectangle DragArea
=> DragAreaRectangle;

private GridLength _titleBarWidth;

public GridLength TitleBarWidth
{
get => _titleBarWidth;
set => _titleBarWidth = new((value.Value / MainWindow.Instance.GetDpiScale()) + _gap);
}

// Events

public static event EventHandler<TabBarItem?>? SelectedTabItemChanged;
Expand All @@ -66,12 +78,10 @@ public TabBar()

var appWindow = MainWindow.Instance.AppWindow;

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

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

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

private void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
=> HorizontalTabView.Measure(new(HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - TitleBarWidth.Value, HorizontalTabView.ActualHeight));

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
Loading