Skip to content

Commit

Permalink
CQ: Displaying the correct gap size using different dpi
Browse files Browse the repository at this point in the history
  • Loading branch information
XTorLukas committed Nov 30, 2024
1 parent 6baa2ed commit c4a84d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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;
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/TabBar/TabBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Rectangle DragArea
public GridLength TitleBarWidth
{
get => _titleBarWidth;
set => _titleBarWidth = new(value.Value + _gap);
set => _titleBarWidth = new((value.Value / MainWindow.Instance.GetDpiScale()) + _gap);
}

// Events
Expand Down

0 comments on commit c4a84d2

Please sign in to comment.