Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 85 additions & 68 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public MainWindow(Settings settings, MainViewModel mainVM)
_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();
Expand All @@ -72,11 +74,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
};
}

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()
{
Expand All @@ -87,6 +85,7 @@ public MainWindow()
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)
Expand All @@ -95,18 +94,22 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
_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;
}

Expand All @@ -131,6 +134,7 @@ private void OnResizeEnd()
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
}
}

FlowMainWindow.SizeToContent = SizeToContent.Height;
_viewModel.MainWindowWidth = Width;
}
Expand Down Expand Up @@ -175,6 +179,7 @@ private async void OnClosing(object sender, CancelEventArgs e)
private void OnInitialized(object sender, EventArgs e)
{
}

private void OnLoaded(object sender, RoutedEventArgs _)
{
// MouseEventHandler
Expand All @@ -186,6 +191,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
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
Expand All @@ -206,6 +213,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
{
SoundPlay();
}

UpdatePosition();
PreviewReset();
Activate();
Expand All @@ -217,7 +225,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
_viewModel.LastQuerySelected = true;
}

if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
Expand Down Expand Up @@ -258,9 +267,12 @@ private void OnLoaded(object sender, RoutedEventArgs _)
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;
}
};
Expand Down Expand Up @@ -290,50 +302,59 @@ private void OnLoaded(object sender, RoutedEventArgs _)

private void InitializePosition()
{
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
{
Top = _settings.WindowTop;
Left = _settings.WindowLeft;
}
else
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
InitializePositionInner();
InitializePositionInner();
return;

void InitializePositionInner()
{
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()
Expand All @@ -345,50 +366,34 @@ private void InitializeNotifyIcon()
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();
Expand Down Expand Up @@ -421,6 +426,7 @@ private void InitializeNotifyIcon()
{
_ = SetForegroundWindow(hwndSource.Handle);
}

contextMenu.Focus();
break;
}
Expand Down Expand Up @@ -454,8 +460,10 @@ private async void PositionReset()

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);
Expand Down Expand Up @@ -565,6 +573,7 @@ public void WindowAnimator()
{
clocksb.Begin(ClockPanel);
}

iconsb.Begin(SearchIcon);
windowsb.Begin(FlowMainWindow);
}
Expand Down Expand Up @@ -641,6 +650,9 @@ private void UpdatePosition()
{
if (_animating)
return;

// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
InitializePosition();
InitializePosition();
}

Expand Down Expand Up @@ -671,7 +683,7 @@ public void HideStartup()
public Screen SelectedScreen()
{
Screen screen = null;
switch(_settings.SearchWindowScreen)
switch (_settings.SearchWindowScreen)
{
case SearchWindowScreens.Cursor:
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
Expand All @@ -693,6 +705,7 @@ public Screen SelectedScreen()
screen = Screen.AllScreens[0];
break;
}

return screen ?? Screen.AllScreens[0];
}

Expand Down Expand Up @@ -762,13 +775,15 @@ private void OnKeyDown(object sender, KeyEventArgs e)
_viewModel.LoadContextMenuCommand.Execute(null);
e.Handled = true;
}

break;
case Key.Left:
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
{
_viewModel.EscCommand.Execute(null);
e.Handled = true;
}

break;
case Key.Back:
if (specialKeyState.CtrlPressed)
Expand All @@ -787,12 +802,13 @@ private void OnKeyDown(object sender, KeyEventArgs e)
}
}
}

break;
default:
break;

}
}

private void OnKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up || e.Key == Key.Down)
Expand All @@ -808,6 +824,7 @@ private void MainPreviewMouseMove(object sender, System.Windows.Input.MouseEvent
e.Handled = true; // Ignore Mouse Hover when press Arrowkeys
}
}

public void PreviewReset()
{
_viewModel.ResetPreview();
Expand Down
Loading