@@ -748,6 +748,27 @@ public IntPtr GetWindowHandle()
748748 return WinRT . Interop . WindowNative . GetWindowHandle ( this ) ;
749749 }
750750
751+ private double GetWindowRasterizationScale ( )
752+ {
753+ uint dpi = NativeHelpers . GetDpiForWindow ( GetWindowHandle ( ) ) ;
754+ if ( dpi > 0 )
755+ {
756+ return dpi / 96.0 ;
757+ }
758+
759+ return MainContentGrid . XamlRoot ? . RasterizationScale ?? 1.0 ;
760+ }
761+
762+ private int ConvertPhysicalPixelsToDips ( int physicalPixels )
763+ {
764+ return ( int ) Math . Round ( physicalPixels / Math . Max ( GetWindowRasterizationScale ( ) , 0.01 ) ) ;
765+ }
766+
767+ private int ConvertDipsToPhysicalPixels ( int dips )
768+ {
769+ return Math . Max ( 1 , ( int ) Math . Round ( dips * GetWindowRasterizationScale ( ) ) ) ;
770+ }
771+
751772 public async Task HandleMissingDependencies ( IReadOnlyList < ManagerDependency > dependencies )
752773 {
753774 int current = 1 ;
@@ -803,7 +824,7 @@ private async Task SaveGeometry(bool Force = false)
803824 }
804825
805826 string geometry =
806- $ "{ AppWindow . Position . X } ,{ AppWindow . Position . Y } ,{ AppWindow . Size . Width } ,{ AppWindow . Size . Height } ,{ windowState } ";
827+ $ "v2, { AppWindow . Position . X } ,{ AppWindow . Position . Y } ,{ ConvertPhysicalPixelsToDips ( AppWindow . Size . Width ) } ,{ ConvertPhysicalPixelsToDips ( AppWindow . Size . Height ) } ,{ windowState } ";
807828
808829 Logger . Debug ( $ "Saving window geometry { geometry } ") ;
809830 Settings . SetValue ( Settings . K . WindowGeometry , geometry ) ;
@@ -818,10 +839,10 @@ private void RestoreGeometry()
818839 {
819840 string geometry = Settings . GetValue ( Settings . K . WindowGeometry ) ;
820841 string [ ] items = geometry . Split ( "," ) ;
821- if ( items . Length != 5 )
842+ if ( items . Length is not ( 5 or 6 ) )
822843 {
823844 Logger . Warn (
824- $ "The restored geometry did not have exactly 5 items (found length was { items . Length } )"
845+ $ "The restored geometry did not have a supported item count (found length was { items . Length } )"
825846 ) ;
826847 return ;
827848 }
@@ -833,11 +854,22 @@ private void RestoreGeometry()
833854 State ;
834855 try
835856 {
836- X = int . Parse ( items [ 0 ] ) ;
837- Y = int . Parse ( items [ 1 ] ) ;
838- Width = int . Parse ( items [ 2 ] ) ;
839- Height = int . Parse ( items [ 3 ] ) ;
840- State = int . Parse ( items [ 4 ] ) ;
857+ if ( items . Length == 6 && items [ 0 ] == "v2" )
858+ {
859+ X = int . Parse ( items [ 1 ] ) ;
860+ Y = int . Parse ( items [ 2 ] ) ;
861+ Width = ConvertDipsToPhysicalPixels ( int . Parse ( items [ 3 ] ) ) ;
862+ Height = ConvertDipsToPhysicalPixels ( int . Parse ( items [ 4 ] ) ) ;
863+ State = int . Parse ( items [ 5 ] ) ;
864+ }
865+ else
866+ {
867+ X = int . Parse ( items [ 0 ] ) ;
868+ Y = int . Parse ( items [ 1 ] ) ;
869+ Width = int . Parse ( items [ 2 ] ) ;
870+ Height = int . Parse ( items [ 3 ] ) ;
871+ State = int . Parse ( items [ 4 ] ) ;
872+ }
841873 }
842874 catch ( Exception ex )
843875 {
@@ -936,7 +968,7 @@ private void TitleBar_PaneToggleRequested(TitleBar sender, object args)
936968 if ( NavigationPage is null )
937969 return ;
938970
939- if ( this . AppWindow . Size . Width >= 1600 )
971+ if ( MainContentGrid . ActualWidth >= 1600 )
940972 {
941973 Settings . Set (
942974 Settings . K . CollapseNavMenuOnWideScreen ,
@@ -1005,6 +1037,9 @@ public static class NativeHelpers
10051037 [ return : MarshalAs ( UnmanagedType . Bool ) ]
10061038 public static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
10071039
1040+ [ DllImport ( "user32.dll" ) ]
1041+ public static extern uint GetDpiForWindow ( IntPtr hWnd ) ;
1042+
10081043 public const int MONITORINFOF_PRIMARY = 0x00000001 ;
10091044
10101045 [ StructLayout ( LayoutKind . Sequential ) ]
0 commit comments