Skip to content

Commit c4a84d2

Browse files
committed
CQ: Displaying the correct gap size using different dpi
1 parent 6baa2ed commit c4a84d2

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ IApplicationDocumentLists
160160
ApplicationDocumentLists
161161
IApplicationActivationManager
162162
MENU_ITEM_TYPE
163+
GetDpiForMonitor
164+
MonitorFromWindow

src/Files.App/Helpers/Win32/Win32PInvoke.Consts.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ public static partial class Win32PInvoke
6767
public const string LOCALE_NAME_USER_DEFAULT = null;
6868
public const string LOCALE_NAME_INVARIANT = "";
6969
public const string LOCALE_NAME_SYSTEM_DEFAULT = "!sys-default-locale";
70+
71+
public const int USER_DEFAULT_SCREEN_DPI = 96;
7072
}
7173
}

src/Files.App/MainWindow.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
using System.Runtime.InteropServices;
1010
using Windows.ApplicationModel.Activation;
1111
using Windows.Storage;
12+
using Windows.Win32;
13+
using Windows.Win32.Graphics.Gdi;
14+
using Windows.Win32.UI.HiDpi;
1215
using IO = System.IO;
1316

1417
namespace Files.App
@@ -339,5 +342,15 @@ x.tabItem.NavigationParameter.NavigationParameter is PaneNavigationArguments pan
339342
}
340343
}
341344
}
345+
346+
public double GetDpiScale()
347+
{
348+
var hMonitor = PInvoke.MonitorFromWindow(
349+
new(WinRT.Interop.WindowNative.GetWindowHandle(this)),
350+
MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
351+
352+
var res = PInvoke.GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var dpiX, out var _);
353+
return res == 0 ? ((float)dpiX / Win32PInvoke.USER_DEFAULT_SCREEN_DPI) : 1;
354+
}
342355
}
343356
}

src/Files.App/UserControls/TabBar/TabBar.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Rectangle DragArea
6060
public GridLength TitleBarWidth
6161
{
6262
get => _titleBarWidth;
63-
set => _titleBarWidth = new(value.Value + _gap);
63+
set => _titleBarWidth = new((value.Value / MainWindow.Instance.GetDpiScale()) + _gap);
6464
}
6565

6666
// Events

0 commit comments

Comments
 (0)