Skip to content

Commit 55b247f

Browse files
committed
- Add Primary/Second/Custom Position in window position setting
- Adjust Strings - Rename WindowPosition Setting
1 parent 6869aee commit 55b247f

File tree

5 files changed

+194
-55
lines changed

5 files changed

+194
-55
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ public string QuerySearchPrecisionString
195195

196196
public double WindowLeft { get; set; }
197197
public double WindowTop { get; set; }
198+
public double CustomWindowLeft { get; set; } = 0;
199+
public double CustomWindowTop { get; set; } = 0;
198200
public int MaxResultsToShow { get; set; } = 5;
199201
public int ActivateTimes { get; set; }
200202

@@ -227,7 +229,9 @@ public bool HideNotifyIcon
227229
}
228230
public bool LeaveCmdOpen { get; set; }
229231
public bool HideWhenDeactivated { get; set; } = true;
230-
public SearchWindowPositions SearchWindowPosition { get; set; } = SearchWindowPositions.MouseScreenCenter;
232+
233+
public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.RememberLastLaunchLocation;
234+
public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center;
231235
public bool IgnoreHotkeysOnFullscreen { get; set; }
232236

233237
public HttpProxy Proxy { get; set; } = new HttpProxy();
@@ -253,12 +257,19 @@ public enum ColorSchemes
253257
Light,
254258
Dark
255259
}
256-
public enum SearchWindowPositions
260+
public enum SearchWindowScreens
257261
{
258262
RememberLastLaunchLocation,
259-
MouseScreenCenter,
260-
MouseScreenCenterTop,
261-
MouseScreenLeftTop,
262-
MouseScreenRightTop
263+
MouseScreen,
264+
PrimaryScreen,
265+
SecondaryScreen,
266+
CustomPosition
267+
}
268+
public enum SearchWindowAligns
269+
{
270+
Center,
271+
CenterTop,
272+
LeftTop,
273+
RightTop
263274
}
264275
}

Flow.Launcher/Languages/en.xaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@
3838
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
3939
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
4040
<system:String x:Key="SearchWindowPosition">Search Window Position</system:String>
41-
<system:String x:Key="SearchWindowPositionRememberLastLaunchLocation">Remember Last Position</system:String>
42-
<system:String x:Key="SearchWindowPositionMouseScreenCenter">Mouse Focused Screen - Center</system:String>
43-
<system:String x:Key="SearchWindowPositionMouseScreenCenterTop">Mouse Focused Screen - Center Top</system:String>
44-
<system:String x:Key="SearchWindowPositionMouseScreenLeftTop">Mouse Focused Screen - Left Top</system:String>
45-
<system:String x:Key="SearchWindowPositionMouseScreenRightTop">Mouse Focused Screen - Right Top</system:String>
41+
<system:String x:Key="SearchWindowScreenRememberLastLaunchLocation">Remember Last Position</system:String>
42+
<system:String x:Key="SearchWindowScreenMouseScreen">Mouse Focused Monitor</system:String>
43+
<system:String x:Key="SearchWindowScreenPrimaryScreen">Primary Monitor</system:String>
44+
<system:String x:Key="SearchWindowScreenSecondaryScreen">Secondary Monitor</system:String>
45+
<system:String x:Key="SearchWindowScreenCustomPosition">Custom Position</system:String>
46+
<system:String x:Key="SearchWindowAlignCenter">Center</system:String>
47+
<system:String x:Key="SearchWindowAlignCenterTop">Center Top</system:String>
48+
<system:String x:Key="SearchWindowAlignLeftTop">Left Top</system:String>
49+
<system:String x:Key="SearchWindowAlignRightTop">Right Top</system:String>
4650
<system:String x:Key="language">Language</system:String>
4751
<system:String x:Key="lastQueryMode">Last Query Style</system:String>
4852
<system:String x:Key="lastQueryModeToolTip">Show/Hide previous results when Flow Launcher is reactivated.</system:String>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Windows.Data;
2525
using ModernWpf.Controls;
2626
using Key = System.Windows.Input.Key;
27+
using System.Threading;
2728

2829
namespace Flow.Launcher
2930
{
@@ -201,29 +202,39 @@ private void OnLoaded(object sender, RoutedEventArgs _)
201202

202203
private void InitializePosition()
203204
{
204-
switch (_settings.SearchWindowPosition)
205+
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
205206
{
206-
case SearchWindowPositions.RememberLastLaunchLocation:
207-
Top = _settings.WindowTop;
208-
Left = _settings.WindowLeft;
209-
break;
210-
case SearchWindowPositions.MouseScreenCenter:
211-
Left = HorizonCenter();
212-
Top = VerticalCenter();
213-
break;
214-
case SearchWindowPositions.MouseScreenCenterTop:
215-
Left = HorizonCenter();
216-
Top = 10;
217-
break;
218-
case SearchWindowPositions.MouseScreenLeftTop:
219-
Left = 10;
220-
Top = 10;
221-
break;
222-
case SearchWindowPositions.MouseScreenRightTop:
223-
Left = HorizonRight();
224-
Top = 10;
225-
break;
207+
Top = _settings.WindowTop;
208+
Left = _settings.WindowLeft;
226209
}
210+
else if (_settings.SearchWindowScreen == SearchWindowScreens.CustomPosition)
211+
{
212+
Top = _settings.CustomWindowTop;
213+
Left = _settings.CustomWindowLeft;
214+
}
215+
else
216+
{
217+
switch (_settings.SearchWindowAlign)
218+
{
219+
case SearchWindowAligns.Center:
220+
Left = HorizonCenter();
221+
Top = VerticalCenter();
222+
break;
223+
case SearchWindowAligns.CenterTop:
224+
Left = HorizonCenter();
225+
Top = 10;
226+
break;
227+
case SearchWindowAligns.LeftTop:
228+
Left = HorizonLeft();
229+
Top = 10;
230+
break;
231+
case SearchWindowAligns.RightTop:
232+
Left = HorizonRight();
233+
Top = 10;
234+
break;
235+
}
236+
}
237+
227238
}
228239

229240
private void UpdateNotifyIconText()
@@ -503,7 +514,7 @@ private void OnLocationChanged(object sender, EventArgs e)
503514
{
504515
if (_animating)
505516
return;
506-
if (_settings.SearchWindowPosition == SearchWindowPositions.RememberLastLaunchLocation)
517+
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
507518
{
508519
_settings.WindowLeft = Left;
509520
_settings.WindowTop = Top;
@@ -523,9 +534,32 @@ public void HideStartup()
523534
}
524535
}
525536

537+
public Screen SelectedScreen()
538+
{
539+
if (_settings.SearchWindowScreen == SearchWindowScreens.MouseScreen)
540+
{
541+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
542+
return screen;
543+
}
544+
else if (_settings.SearchWindowScreen == SearchWindowScreens.PrimaryScreen)
545+
{
546+
var screen = Screen.PrimaryScreen;
547+
return screen;
548+
}
549+
else if (_settings.SearchWindowScreen == SearchWindowScreens.SecondaryScreen)
550+
{
551+
var screen = Screen.AllScreens[1];
552+
return screen;
553+
}
554+
else
555+
{
556+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
557+
return screen;
558+
}
559+
}
526560
public double HorizonCenter()
527561
{
528-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
562+
var screen = SelectedScreen();
529563
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
530564
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
531565
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
@@ -534,7 +568,7 @@ public double HorizonCenter()
534568

535569
public double VerticalCenter()
536570
{
537-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
571+
var screen = SelectedScreen();
538572
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
539573
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
540574
var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y;
@@ -543,10 +577,19 @@ public double VerticalCenter()
543577

544578
public double HorizonRight()
545579
{
546-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
580+
var screen = SelectedScreen();
581+
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
582+
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
583+
var left = (dip1.X + dip2.X - ActualWidth) - 10;
584+
return left;
585+
}
586+
587+
public double HorizonLeft()
588+
{
589+
var screen = SelectedScreen();
547590
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
548591
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
549-
var left = (dip2.X - ActualWidth) - 10;
592+
var left = dip1.X + 10;
550593
return left;
551594
}
552595

Flow.Launcher/SettingWindow.xaml

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,17 +698,70 @@
698698
<StackPanel Style="{StaticResource TextPanel}">
699699
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SearchWindowPosition}" />
700700
</StackPanel>
701-
<ComboBox
702-
x:Name="SearchWindowPosition"
703-
Grid.Column="2"
704-
MinWidth="220"
705-
Margin="0,0,18,0"
706-
VerticalAlignment="Center"
707-
DisplayMemberPath="Display"
708-
FontSize="14"
709-
ItemsSource="{Binding SearchWindowPositions}"
710-
SelectedValue="{Binding Settings.SearchWindowPosition}"
711-
SelectedValuePath="Value" />
701+
<StackPanel Grid.Column="2" Orientation="Horizontal">
702+
<ComboBox
703+
x:Name="SearchWindowScreen"
704+
MinWidth="220"
705+
Margin="0,0,18,0"
706+
VerticalAlignment="Center"
707+
DisplayMemberPath="Display"
708+
FontSize="14"
709+
ItemsSource="{Binding SearchWindowScreens}"
710+
SelectedValue="{Binding Settings.SearchWindowScreen}"
711+
SelectedValuePath="Value" />
712+
<ComboBox
713+
x:Name="SearchWindowPosition"
714+
MinWidth="160"
715+
Margin="0,0,18,0"
716+
VerticalAlignment="Center"
717+
DisplayMemberPath="Display"
718+
FontSize="14"
719+
ItemsSource="{Binding SearchWindowAligns}"
720+
SelectedValue="{Binding Settings.SearchWindowAlign}"
721+
SelectedValuePath="Value">
722+
<ComboBox.Style>
723+
<Style BasedOn="{StaticResource DefaultComboBoxStyle}" TargetType="ComboBox">
724+
<Setter Property="Visibility" Value="Visible" />
725+
<Style.Triggers>
726+
<DataTrigger Binding="{Binding ElementName=SearchWindowScreen, Path=SelectedIndex}" Value="0">
727+
<Setter Property="Visibility" Value="Collapsed" />
728+
</DataTrigger>
729+
<DataTrigger Binding="{Binding ElementName=SearchWindowScreen, Path=SelectedIndex}" Value="4">
730+
<Setter Property="Visibility" Value="Collapsed" />
731+
</DataTrigger>
732+
</Style.Triggers>
733+
734+
</Style>
735+
</ComboBox.Style>
736+
</ComboBox>
737+
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
738+
<StackPanel.Style>
739+
<Style TargetType="StackPanel">
740+
<Setter Property="Visibility" Value="Collapsed" />
741+
<Style.Triggers>
742+
<DataTrigger Binding="{Binding ElementName=SearchWindowScreen, Path=SelectedIndex}" Value="4">
743+
<Setter Property="Visibility" Value="Visible" />
744+
</DataTrigger>
745+
</Style.Triggers>
746+
</Style>
747+
</StackPanel.Style>
748+
<TextBox
749+
Height="35"
750+
MinWidth="120"
751+
Text="{Binding Settings.CustomWindowLeft}"
752+
TextWrapping="NoWrap" />
753+
<TextBlock
754+
Margin="10"
755+
VerticalAlignment="Center"
756+
Foreground="{DynamicResource Color05B}"
757+
Text="x" />
758+
<TextBox
759+
Height="35"
760+
MinWidth="120"
761+
Text="{Binding Settings.CustomWindowTop}"
762+
TextWrapping="NoWrap" />
763+
</StackPanel>
764+
</StackPanel>
712765
<TextBlock Style="{StaticResource Glyph}">
713766
&#xe7f4;
714767
</TextBlock>

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Collections.ObjectModel;
2323
using CommunityToolkit.Mvvm.Input;
2424
using System.Globalization;
25+
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
2526

2627
namespace Flow.Launcher.ViewModel
2728
{
@@ -463,23 +464,50 @@ public List<ColorScheme> ColorSchemes
463464
}
464465
}
465466

466-
public class SearchWindowPosition
467+
public class SearchWindowScreen
467468
{
468469
public string Display { get; set; }
469-
public SearchWindowPositions Value { get; set; }
470+
public SearchWindowScreens Value { get; set; }
470471
}
471472

472-
public List<SearchWindowPosition> SearchWindowPositions
473+
public List<SearchWindowScreen> SearchWindowScreens
473474
{
474475
get
475476
{
476-
List<SearchWindowPosition> modes = new List<SearchWindowPosition>();
477-
var enums = (SearchWindowPositions[])Enum.GetValues(typeof(SearchWindowPositions));
477+
List<SearchWindowScreen> modes = new List<SearchWindowScreen>();
478+
var enums = (SearchWindowScreens[])Enum.GetValues(typeof(SearchWindowScreens));
478479
foreach (var e in enums)
479480
{
480-
var key = $"SearchWindowPosition{e}";
481+
var key = $"SearchWindowScreen{e}";
481482
var display = _translater.GetTranslation(key);
482-
var m = new SearchWindowPosition
483+
var m = new SearchWindowScreen
484+
{
485+
Display = display,
486+
Value = e,
487+
};
488+
modes.Add(m);
489+
}
490+
return modes;
491+
}
492+
}
493+
494+
public class SearchWindowAlign
495+
{
496+
public string Display { get; set; }
497+
public SearchWindowAligns Value { get; set; }
498+
}
499+
500+
public List<SearchWindowAlign> SearchWindowAligns
501+
{
502+
get
503+
{
504+
List<SearchWindowAlign> modes = new List<SearchWindowAlign>();
505+
var enums = (SearchWindowAligns[])Enum.GetValues(typeof(SearchWindowAligns));
506+
foreach (var e in enums)
507+
{
508+
var key = $"SearchWindowAlign{e}";
509+
var display = _translater.GetTranslation(key);
510+
var m = new SearchWindowAlign
483511
{
484512
Display = display, Value = e,
485513
};

0 commit comments

Comments
 (0)