Skip to content

Commit b80b3ed

Browse files
authored
Merge pull request #1367 from onesounds/PositionOption
Position Setting
2 parents d646380 + 8a5895f commit b80b3ed

File tree

7 files changed

+140
-64
lines changed

7 files changed

+140
-64
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public bool HideNotifyIcon
199199
}
200200
public bool LeaveCmdOpen { get; set; }
201201
public bool HideWhenDeactive { get; set; } = true;
202-
public bool RememberLastLaunchLocation { get; set; }
202+
public SearchWindowPositions SearchWindowPosition { get; set; } = SearchWindowPositions.MouseScreenCenter;
203203
public bool IgnoreHotkeysOnFullscreen { get; set; }
204204

205205
public HttpProxy Proxy { get; set; } = new HttpProxy();
@@ -225,4 +225,12 @@ public enum ColorSchemes
225225
Light,
226226
Dark
227227
}
228+
public enum SearchWindowPositions
229+
{
230+
RememberLastLaunchLocation,
231+
MouseScreenCenter,
232+
MouseScreenCenterTop,
233+
MouseScreenLeftTop,
234+
MouseScreenRightTop
235+
}
228236
}

Flow.Launcher/Languages/en.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<system:String x:Key="textTitle">Text</system:String>
2424
<system:String x:Key="GameMode">Game Mode</system:String>
2525
<system:String x:Key="GameModeToolTip">Suspend the use of Hotkeys.</system:String>
26+
<system:String x:Key="PositionReset">Position Reset</system:String>
27+
<system:String x:Key="PositionResetToolTip">Reset search window position</system:String>
2628

2729
<!-- Setting General -->
2830
<system:String x:Key="flowlauncher_settings">Flow Launcher Settings</system:String>
@@ -33,7 +35,13 @@
3335
<system:String x:Key="setAutoStartFailed">Error setting launch on startup</system:String>
3436
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
3537
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
38+
<system:String x:Key="SearchWindowPosition">Search Window Position</system:String>
3639
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>
40+
<system:String x:Key="SearchWindowPositionRememberLastLaunchLocation">Remember Last Location</system:String>
41+
<system:String x:Key="SearchWindowPositionMouseScreenCenter">Mouse Focused Screen - Center</system:String>
42+
<system:String x:Key="SearchWindowPositionMouseScreenCenterTop">Mouse Focused Screen - Center Top</system:String>
43+
<system:String x:Key="SearchWindowPositionMouseScreenLeftTop">Mouse Focused Screen - Left Top</system:String>
44+
<system:String x:Key="SearchWindowPositionMouseScreenRightTop">Mouse Focused Screen - Right Top</system:String>
3745
<system:String x:Key="language">Language</system:String>
3846
<system:String x:Key="lastQueryMode">Last Query Style</system:String>
3947
<system:String x:Key="lastQueryModeToolTip">Show/Hide previous results when Flow Launcher is reactivated.</system:String>

Flow.Launcher/MainWindow.xaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
3333
WindowStartupLocation="Manual"
3434
WindowStyle="None"
35-
mc:Ignorable="d"
36-
Left="{Binding Left, Mode=TwoWay}"
37-
Top="{Binding Top, Mode=TwoWay}">
35+
mc:Ignorable="d">
3836
<Window.Resources>
3937
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
4038
<converters:BorderClipConverter x:Key="BorderClipConverter" />
@@ -88,20 +86,20 @@
8886
<KeyBinding Key="Left" Command="{Binding EscCommand}" />
8987
<KeyBinding
9088
Key="OemCloseBrackets"
91-
Modifiers="Control"
92-
Command="{Binding IncreaseWidthCommand}"/>
89+
Command="{Binding IncreaseWidthCommand}"
90+
Modifiers="Control" />
9391
<KeyBinding
9492
Key="OemOpenBrackets"
95-
Modifiers="Control"
96-
Command="{Binding DecreaseWidthCommand}"/>
93+
Command="{Binding DecreaseWidthCommand}"
94+
Modifiers="Control" />
9795
<KeyBinding
9896
Key="OemPlus"
99-
Modifiers="Control"
100-
Command="{Binding IncreaseMaxResultCommand}"/>
97+
Command="{Binding IncreaseMaxResultCommand}"
98+
Modifiers="Control" />
10199
<KeyBinding
102100
Key="OemMinus"
103-
Modifiers="Control"
104-
Command="{Binding DecreaseMaxResultCommand}"/>
101+
Command="{Binding DecreaseMaxResultCommand}"
102+
Modifiers="Control" />
105103
<KeyBinding
106104
Key="H"
107105
Command="{Binding LoadHistoryCommand}"
@@ -195,9 +193,9 @@
195193
AllowDrop="True"
196194
Background="Transparent"
197195
PreviewDragOver="OnPreviewDragOver"
196+
PreviewKeyUp="QueryTextBox_KeyUp"
198197
Style="{DynamicResource QueryBoxStyle}"
199198
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
200-
PreviewKeyUp="QueryTextBox_KeyUp"
201199
Visibility="Visible">
202200
<TextBox.CommandBindings>
203201
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
4646
_viewModel = mainVM;
4747
_settings = settings;
4848
InitializeComponent();
49+
InitializePosition();
4950
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
5051
}
5152

@@ -108,7 +109,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
108109
animationSound.Position = TimeSpan.Zero;
109110
animationSound.Play();
110111
}
111-
112112
UpdatePosition();
113113
Activate();
114114
QueryTextBox.Focus();
@@ -161,6 +161,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
161161
_viewModel.QueryTextCursorMovedToEnd = false;
162162
}
163163
break;
164+
164165
}
165166
};
166167
_settings.PropertyChanged += (o, e) =>
@@ -176,17 +177,51 @@ private void OnLoaded(object sender, RoutedEventArgs _)
176177
case nameof(Settings.Hotkey):
177178
UpdateNotifyIconText();
178179
break;
180+
case nameof(Settings.WindowLeft):
181+
Left = _settings.WindowLeft;
182+
break;
183+
case nameof(Settings.WindowTop):
184+
Top = _settings.WindowTop;
185+
break;
179186
}
180187
};
181188
}
182189

190+
private void InitializePosition()
191+
{
192+
switch (_settings.SearchWindowPosition)
193+
{
194+
case SearchWindowPositions.RememberLastLaunchLocation:
195+
Top = _settings.WindowTop;
196+
Left = _settings.WindowLeft;
197+
break;
198+
case SearchWindowPositions.MouseScreenCenter:
199+
Left = HorizonCenter();
200+
Top = VerticalCenter();
201+
break;
202+
case SearchWindowPositions.MouseScreenCenterTop:
203+
Left = HorizonCenter();
204+
Top = 10;
205+
break;
206+
case SearchWindowPositions.MouseScreenLeftTop:
207+
Left = 10;
208+
Top = 10;
209+
break;
210+
case SearchWindowPositions.MouseScreenRightTop:
211+
Left = HorizonRight();
212+
Top = 10;
213+
break;
214+
}
215+
}
216+
183217
private void UpdateNotifyIconText()
184218
{
185219
var menu = contextMenu;
186220
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
187221
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
188-
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
189-
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
222+
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
223+
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
224+
((MenuItem)menu.Items[5]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
190225
}
191226

192227
private void InitializeNotifyIcon()
@@ -212,6 +247,10 @@ private void InitializeNotifyIcon()
212247
{
213248
Header = InternationalizationManager.Instance.GetTranslation("GameMode")
214249
};
250+
var positionreset = new MenuItem
251+
{
252+
Header = InternationalizationManager.Instance.GetTranslation("PositionReset")
253+
};
215254
var settings = new MenuItem
216255
{
217256
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings")
@@ -223,12 +262,15 @@ private void InitializeNotifyIcon()
223262

224263
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
225264
gamemode.Click += (o, e) => ToggleGameMode();
265+
positionreset.Click += (o, e) => PositionReset();
226266
settings.Click += (o, e) => App.API.OpenSettingDialog();
227267
exit.Click += (o, e) => Close();
228268
contextMenu.Items.Add(header);
229269
contextMenu.Items.Add(open);
230270
gamemode.ToolTip = InternationalizationManager.Instance.GetTranslation("GameModeToolTip");
271+
positionreset.ToolTip = InternationalizationManager.Instance.GetTranslation("PositionResetToolTip");
231272
contextMenu.Items.Add(gamemode);
273+
contextMenu.Items.Add(positionreset);
232274
contextMenu.Items.Add(settings);
233275
contextMenu.Items.Add(exit);
234276

@@ -275,10 +317,17 @@ private void ToggleGameMode()
275317
_viewModel.GameModeStatus = true;
276318
}
277319
}
320+
private async void PositionReset()
321+
{
322+
_viewModel.Show();
323+
await Task.Delay(300); // If don't give a time, Positioning will be weird.
324+
Left = HorizonCenter();
325+
Top = VerticalCenter();
326+
}
278327
private void InitProgressbarAnimation()
279328
{
280329
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150,
281-
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
330+
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
282331
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 50, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
283332
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
284333
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
@@ -382,6 +431,8 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
382431

383432
private async void OnDeactivated(object sender, EventArgs e)
384433
{
434+
_settings.WindowLeft = Left;
435+
_settings.WindowTop = Top;
385436
//This condition stops extra hide call when animator is on,
386437
// which causes the toggling to occasional hide instead of show.
387438
if (_viewModel.MainWindowVisibilityStatus)
@@ -403,24 +454,14 @@ private void UpdatePosition()
403454
{
404455
if (_animating)
405456
return;
406-
407-
if (_settings.RememberLastLaunchLocation)
408-
{
409-
Left = _settings.WindowLeft;
410-
Top = _settings.WindowTop;
411-
}
412-
else
413-
{
414-
Left = WindowLeft();
415-
Top = WindowTop();
416-
}
457+
InitializePosition();
417458
}
418459

419460
private void OnLocationChanged(object sender, EventArgs e)
420461
{
421462
if (_animating)
422463
return;
423-
if (_settings.RememberLastLaunchLocation)
464+
if (_settings.SearchWindowPosition == SearchWindowPositions.RememberLastLaunchLocation)
424465
{
425466
_settings.WindowLeft = Left;
426467
_settings.WindowTop = Top;
@@ -439,17 +480,8 @@ public void HideStartup()
439480
_viewModel.Show();
440481
}
441482
}
442-
443-
private void InitializePosition()
444-
{
445-
if (!_settings.RememberLastLaunchLocation)
446-
{
447-
Left = WindowLeft();
448-
Top = WindowTop();
449-
}
450-
}
451483

452-
public double WindowLeft()
484+
public double HorizonCenter()
453485
{
454486
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
455487
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
@@ -458,7 +490,7 @@ public double WindowLeft()
458490
return left;
459491
}
460492

461-
public double WindowTop()
493+
public double VerticalCenter()
462494
{
463495
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
464496
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
@@ -467,6 +499,15 @@ public double WindowTop()
467499
return top;
468500
}
469501

502+
public double HorizonRight()
503+
{
504+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
505+
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
506+
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
507+
var left = (dip2.X - ActualWidth) - 10;
508+
return left;
509+
}
510+
470511
/// <summary>
471512
/// Register up and down key
472513
/// todo: any way to put this in xaml ?

Flow.Launcher/SettingWindow.xaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,25 @@
685685
</ItemsControl>
686686
</Border>
687687

688-
<Border Style="{DynamicResource SettingGroupBox}">
688+
<Border Margin="0,30,0,0" Style="{DynamicResource SettingGroupBox}">
689689
<ItemsControl Style="{StaticResource SettingGrid}">
690690
<StackPanel Style="{StaticResource TextPanel}">
691-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource rememberLastLocation}" />
691+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SearchWindowPosition}" />
692692
</StackPanel>
693-
<CheckBox IsChecked="{Binding Settings.RememberLastLaunchLocation}" Style="{DynamicResource SideControlCheckBox}" />
693+
<ComboBox
694+
x:Name="SearchWindowPosition"
695+
Grid.Column="2"
696+
MinWidth="220"
697+
Margin="0,0,18,0"
698+
VerticalAlignment="Center"
699+
DisplayMemberPath="Display"
700+
FontSize="14"
701+
ItemsSource="{Binding SearchWindowPositions}"
702+
SelectedValue="{Binding Settings.SearchWindowPosition}"
703+
SelectedValuePath="Value" />
704+
<TextBlock Style="{StaticResource Glyph}">
705+
&#xe7f4;
706+
</TextBlock>
694707
</ItemsControl>
695708
</Border>
696709

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -341,25 +341,6 @@ public string QueryText
341341
}
342342

343343

344-
public double Top
345-
{
346-
get => _settings.WindowTop;
347-
set
348-
{
349-
_settings.WindowTop = value;
350-
OnPropertyChanged();
351-
}
352-
}
353-
public double Left
354-
{
355-
get => _settings.WindowLeft;
356-
set
357-
{
358-
_settings.WindowLeft = value;
359-
OnPropertyChanged();
360-
}
361-
}
362-
363344
[RelayCommand]
364345
private void IncreaseWidth()
365346
{
@@ -370,7 +351,7 @@ private void IncreaseWidth()
370351
else
371352
{
372353
_settings.WindowSize += 100;
373-
Left -= 50;
354+
_settings.WindowLeft -= 50;
374355
}
375356
OnPropertyChanged();
376357
}
@@ -384,7 +365,7 @@ private void DecreaseWidth()
384365
}
385366
else
386367
{
387-
Left += 50;
368+
_settings.WindowLeft += 50;
388369
_settings.WindowSize -= 100;
389370
}
390371
OnPropertyChanged();

0 commit comments

Comments
 (0)