27
27
using System . Windows . Media ;
28
28
using System . Windows . Interop ;
29
29
using System . Runtime . InteropServices ;
30
+ using System . Drawing ;
30
31
31
32
namespace Flow . Launcher
32
33
{
@@ -48,6 +49,10 @@ public partial class MainWindow
48
49
49
50
private MediaPlayer animationSoundWMP ;
50
51
private SoundPlayer animationSoundWPF ;
52
+ private double _previousScreenWidth ;
53
+ private double _previousScreenHeight ;
54
+ private double _previousDpiX ;
55
+ private double _previousDpiY ;
51
56
52
57
#endregion
53
58
@@ -288,16 +293,38 @@ private void OnLoaded(object sender, RoutedEventArgs _)
288
293
} ;
289
294
}
290
295
296
+ private ( double X , double Y ) GetCurrentDpi ( Screen screen )
297
+ {
298
+ using ( Graphics g = Graphics . FromHwnd ( IntPtr . Zero ) )
299
+ {
300
+ return ( g . DpiX , g . DpiY ) ;
301
+ }
302
+ }
291
303
private void InitializePosition ( )
292
304
{
305
+ var screen = SelectedScreen ( ) ;
306
+ var currentDpi = GetCurrentDpi ( screen ) ;
307
+ double currentScreenWidth = screen . WorkingArea . Width ;
308
+ double currentScreenHeight = screen . WorkingArea . Height ;
309
+
310
+ if ( _previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0 )
311
+ {
312
+ double widthRatio = currentScreenWidth / _previousScreenWidth ;
313
+ double heightRatio = currentScreenHeight / _previousScreenHeight ;
314
+ double dpiXRatio = currentDpi . X / _previousDpiX ;
315
+ double dpiYRatio = currentDpi . Y / _previousDpiY ;
316
+
317
+ _settings . WindowLeft *= widthRatio * dpiXRatio ;
318
+ _settings . WindowTop *= heightRatio * dpiYRatio ;
319
+ }
320
+
293
321
if ( _settings . SearchWindowScreen == SearchWindowScreens . RememberLastLaunchLocation )
294
322
{
295
323
Top = _settings . WindowTop ;
296
324
Left = _settings . WindowLeft ;
297
325
}
298
326
else
299
327
{
300
- var screen = SelectedScreen ( ) ;
301
328
switch ( _settings . SearchWindowAlign )
302
329
{
303
330
case SearchWindowAligns . Center :
@@ -323,6 +350,10 @@ private void InitializePosition()
323
350
}
324
351
}
325
352
353
+ _previousScreenWidth = currentScreenWidth ;
354
+ _previousScreenHeight = currentScreenHeight ;
355
+ _previousDpiX = currentDpi . X ;
356
+ _previousDpiY = currentDpi . Y ;
326
357
}
327
358
328
359
private void UpdateNotifyIconText ( )
0 commit comments