mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2983 from Flow-Launcher/fix-screen-position-multiple-monitor-different-dpi
Fix Multiple Display different DPI causing weird staring position
This commit is contained in:
commit
ffb7b32304
1 changed files with 85 additions and 68 deletions
|
|
@ -58,6 +58,8 @@ namespace Flow.Launcher
|
|||
_settings = settings;
|
||||
|
||||
InitializeComponent();
|
||||
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
|
||||
InitializePosition();
|
||||
InitializePosition();
|
||||
|
||||
InitSoundEffects();
|
||||
|
|
@ -72,11 +74,7 @@ namespace Flow.Launcher
|
|||
};
|
||||
}
|
||||
|
||||
DispatcherTimer timer = new DispatcherTimer
|
||||
{
|
||||
Interval = new TimeSpan(0, 0, 0, 0, 500),
|
||||
IsEnabled = false
|
||||
};
|
||||
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
|
|
@ -87,6 +85,7 @@ namespace Flow.Launcher
|
|||
private const int WM_EXITSIZEMOVE = 0x0232;
|
||||
private int _initialWidth;
|
||||
private int _initialHeight;
|
||||
|
||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (msg == WM_ENTERSIZEMOVE)
|
||||
|
|
@ -95,18 +94,22 @@ namespace Flow.Launcher
|
|||
_initialHeight = (int)Height;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (msg == WM_EXITSIZEMOVE)
|
||||
{
|
||||
if ( _initialHeight != (int)Height)
|
||||
if (_initialHeight != (int)Height)
|
||||
{
|
||||
OnResizeEnd();
|
||||
}
|
||||
|
||||
if (_initialWidth != (int)Width)
|
||||
{
|
||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||
}
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
|
@ -131,6 +134,7 @@ namespace Flow.Launcher
|
|||
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
|
||||
}
|
||||
}
|
||||
|
||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||
_viewModel.MainWindowWidth = Width;
|
||||
}
|
||||
|
|
@ -175,6 +179,7 @@ namespace Flow.Launcher
|
|||
private void OnInitialized(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs _)
|
||||
{
|
||||
// MouseEventHandler
|
||||
|
|
@ -186,6 +191,8 @@ namespace Flow.Launcher
|
|||
InitializeColorScheme();
|
||||
WindowsInteropHelper.DisableControlBox(this);
|
||||
InitProgressbarAnimation();
|
||||
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
|
||||
InitializePosition();
|
||||
InitializePosition();
|
||||
PreviewReset();
|
||||
// since the default main window visibility is visible
|
||||
|
|
@ -206,6 +213,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
SoundPlay();
|
||||
}
|
||||
|
||||
UpdatePosition();
|
||||
PreviewReset();
|
||||
Activate();
|
||||
|
|
@ -217,7 +225,8 @@ namespace Flow.Launcher
|
|||
_viewModel.LastQuerySelected = true;
|
||||
}
|
||||
|
||||
if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
|
||||
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
|
||||
isProgressBarStoryboardPaused)
|
||||
{
|
||||
_progressBarStoryboard.Begin(ProgressBar, true);
|
||||
isProgressBarStoryboardPaused = false;
|
||||
|
|
@ -258,9 +267,12 @@ namespace Flow.Launcher
|
|||
MoveQueryTextToEnd();
|
||||
_viewModel.QueryTextCursorMovedToEnd = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case nameof(MainViewModel.GameModeStatus):
|
||||
_notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app;
|
||||
_notifyIcon.Icon = _viewModel.GameModeStatus
|
||||
? Properties.Resources.gamemode
|
||||
: Properties.Resources.app;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
@ -290,50 +302,59 @@ namespace Flow.Launcher
|
|||
|
||||
private void InitializePosition()
|
||||
{
|
||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
|
||||
InitializePositionInner();
|
||||
InitializePositionInner();
|
||||
return;
|
||||
|
||||
void InitializePositionInner()
|
||||
{
|
||||
Top = _settings.WindowTop;
|
||||
Left = _settings.WindowLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
switch (_settings.SearchWindowAlign)
|
||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||
{
|
||||
case SearchWindowAligns.Center:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = VerticalCenter(screen);
|
||||
break;
|
||||
case SearchWindowAligns.CenterTop:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.LeftTop:
|
||||
Left = HorizonLeft(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.RightTop:
|
||||
Left = HorizonRight(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.Custom:
|
||||
Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
|
||||
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
|
||||
break;
|
||||
Top = _settings.WindowTop;
|
||||
Left = _settings.WindowLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
switch (_settings.SearchWindowAlign)
|
||||
{
|
||||
case SearchWindowAligns.Center:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = VerticalCenter(screen);
|
||||
break;
|
||||
case SearchWindowAligns.CenterTop:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.LeftTop:
|
||||
Left = HorizonLeft(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.RightTop:
|
||||
Left = HorizonRight(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.Custom:
|
||||
Left = WindowsInteropHelper.TransformPixelsToDIP(this,
|
||||
screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
|
||||
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0,
|
||||
screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateNotifyIconText()
|
||||
{
|
||||
var menu = contextMenu;
|
||||
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
|
||||
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") +
|
||||
" (" + _settings.Hotkey + ")";
|
||||
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
|
||||
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
|
||||
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
||||
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
||||
|
||||
}
|
||||
|
||||
private void InitializeNotifyIcon()
|
||||
|
|
@ -345,50 +366,34 @@ namespace Flow.Launcher
|
|||
Visible = !_settings.HideNotifyIcon
|
||||
};
|
||||
|
||||
var openIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue71e"
|
||||
};
|
||||
var openIcon = new FontIcon { Glyph = "\ue71e" };
|
||||
var open = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" +
|
||||
_settings.Hotkey + ")",
|
||||
Icon = openIcon
|
||||
};
|
||||
var gamemodeIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue7fc"
|
||||
};
|
||||
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
|
||||
var gamemode = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
|
||||
Icon = gamemodeIcon
|
||||
};
|
||||
var positionresetIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue73f"
|
||||
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
|
||||
};
|
||||
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
|
||||
var positionreset = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
|
||||
Icon = positionresetIcon
|
||||
};
|
||||
var settingsIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue713"
|
||||
};
|
||||
var settingsIcon = new FontIcon { Glyph = "\ue713" };
|
||||
var settings = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
|
||||
Icon = settingsIcon
|
||||
};
|
||||
var exitIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue7e8"
|
||||
};
|
||||
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
|
||||
var exit = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
|
||||
Icon = exitIcon
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
|
||||
};
|
||||
|
||||
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
|
||||
|
|
@ -421,6 +426,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
_ = SetForegroundWindow(hwndSource.Handle);
|
||||
}
|
||||
|
||||
contextMenu.Focus();
|
||||
break;
|
||||
}
|
||||
|
|
@ -454,8 +460,10 @@ namespace Flow.Launcher
|
|||
|
||||
private void InitProgressbarAnimation()
|
||||
{
|
||||
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
|
||||
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
|
||||
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
||||
_progressBarStoryboard.Children.Add(da);
|
||||
|
|
@ -565,6 +573,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
clocksb.Begin(ClockPanel);
|
||||
}
|
||||
|
||||
iconsb.Begin(SearchIcon);
|
||||
windowsb.Begin(FlowMainWindow);
|
||||
}
|
||||
|
|
@ -641,6 +650,9 @@ namespace Flow.Launcher
|
|||
{
|
||||
if (_animating)
|
||||
return;
|
||||
|
||||
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
|
||||
InitializePosition();
|
||||
InitializePosition();
|
||||
}
|
||||
|
||||
|
|
@ -671,7 +683,7 @@ namespace Flow.Launcher
|
|||
public Screen SelectedScreen()
|
||||
{
|
||||
Screen screen = null;
|
||||
switch(_settings.SearchWindowScreen)
|
||||
switch (_settings.SearchWindowScreen)
|
||||
{
|
||||
case SearchWindowScreens.Cursor:
|
||||
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||
|
|
@ -693,6 +705,7 @@ namespace Flow.Launcher
|
|||
screen = Screen.AllScreens[0];
|
||||
break;
|
||||
}
|
||||
|
||||
return screen ?? Screen.AllScreens[0];
|
||||
}
|
||||
|
||||
|
|
@ -762,6 +775,7 @@ namespace Flow.Launcher
|
|||
_viewModel.LoadContextMenuCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case Key.Left:
|
||||
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
|
||||
|
|
@ -769,6 +783,7 @@ namespace Flow.Launcher
|
|||
_viewModel.EscCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case Key.Back:
|
||||
if (specialKeyState.CtrlPressed)
|
||||
|
|
@ -787,12 +802,13 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Up || e.Key == Key.Down)
|
||||
|
|
@ -808,6 +824,7 @@ namespace Flow.Launcher
|
|||
e.Handled = true; // Ignore Mouse Hover when press Arrowkeys
|
||||
}
|
||||
}
|
||||
|
||||
public void PreviewReset()
|
||||
{
|
||||
_viewModel.ResetPreview();
|
||||
|
|
|
|||
Loading…
Reference in a new issue