mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
When using the “remember last position” setting, if the resolution or dpi has changed, the position will be rescaled proportionally
This commit is contained in:
parent
37ccf25940
commit
63ce735169
1 changed files with 32 additions and 1 deletions
|
|
@ -27,6 +27,7 @@ using DataObject = System.Windows.DataObject;
|
|||
using System.Windows.Media;
|
||||
using System.Windows.Interop;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -48,6 +49,10 @@ namespace Flow.Launcher
|
|||
|
||||
private MediaPlayer animationSoundWMP;
|
||||
private SoundPlayer animationSoundWPF;
|
||||
private double _previousScreenWidth;
|
||||
private double _previousScreenHeight;
|
||||
private double _previousDpiX;
|
||||
private double _previousDpiY;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -288,8 +293,31 @@ namespace Flow.Launcher
|
|||
};
|
||||
}
|
||||
|
||||
private (double X, double Y) GetCurrentDpi(Screen screen)
|
||||
{
|
||||
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
||||
{
|
||||
return (g.DpiX, g.DpiY);
|
||||
}
|
||||
}
|
||||
private void InitializePosition()
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
var currentDpi = GetCurrentDpi(screen);
|
||||
double currentScreenWidth = screen.WorkingArea.Width;
|
||||
double currentScreenHeight = screen.WorkingArea.Height;
|
||||
|
||||
if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0)
|
||||
{
|
||||
double widthRatio = currentScreenWidth / _previousScreenWidth;
|
||||
double heightRatio = currentScreenHeight / _previousScreenHeight;
|
||||
double dpiXRatio = currentDpi.X / _previousDpiX;
|
||||
double dpiYRatio = currentDpi.Y / _previousDpiY;
|
||||
|
||||
_settings.WindowLeft *= widthRatio * dpiXRatio;
|
||||
_settings.WindowTop *= heightRatio * dpiYRatio;
|
||||
}
|
||||
|
||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||
{
|
||||
Top = _settings.WindowTop;
|
||||
|
|
@ -297,7 +325,6 @@ namespace Flow.Launcher
|
|||
}
|
||||
else
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
switch (_settings.SearchWindowAlign)
|
||||
{
|
||||
case SearchWindowAligns.Center:
|
||||
|
|
@ -323,6 +350,10 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
_previousScreenWidth = currentScreenWidth;
|
||||
_previousScreenHeight = currentScreenHeight;
|
||||
_previousDpiX = currentDpi.X;
|
||||
_previousDpiY = currentDpi.Y;
|
||||
}
|
||||
|
||||
private void UpdateNotifyIconText()
|
||||
|
|
|
|||
Loading…
Reference in a new issue