Skip to content

Commit

Permalink
Update: Get dpi from AppModel
Browse files Browse the repository at this point in the history
  • Loading branch information
XTorLukas committed Dec 2, 2024
1 parent c4a84d2 commit 57b8edc
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 18 deletions.
2 changes: 0 additions & 2 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,3 @@ IApplicationDocumentLists
ApplicationDocumentLists
IApplicationActivationManager
MENU_ITEM_TYPE
GetDpiForMonitor
MonitorFromWindow
2 changes: 0 additions & 2 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,5 @@ 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: 0 additions & 13 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
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 @@ -342,15 +339,5 @@ 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 / MainWindow.Instance.GetDpiScale()) + _gap);
set => _titleBarWidth = new((value.Value / App.AppModel.AppWindowDPI) + _gap);
}

// Events
Expand Down

0 comments on commit 57b8edc

Please sign in to comment.