mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
[launcher] Location and multi monitor support (#2446)
* Fixed left and top window
* Added dpi Aware launcher positioning code
* Code cleanup
* Added support to drag window
* Multi monitor support added
Remaining fix : Launcher doesn't open first time on changing monitor
* removed code handling change in DPI manually
* Code cleanup
* Fix to support multimonitor display
* Code cleanup
* Revert "Code cleanup"
This reverts commit 38f39924f0.
* Revert back to WOX helper for calculating normalized DPI
This commit is contained in:
committed by
GitHub
parent
8cb134f56b
commit
f44109abae
@@ -23,9 +23,11 @@
|
|||||||
LocationChanged="OnLocationChanged"
|
LocationChanged="OnLocationChanged"
|
||||||
Deactivated="OnDeactivated"
|
Deactivated="OnDeactivated"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
|
Width="720"
|
||||||
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||||
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
||||||
<Grid Width="720">
|
<Grid Width="720"
|
||||||
|
MouseDown="OnMouseDown">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
@@ -40,6 +42,8 @@
|
|||||||
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
||||||
</Border.Effect>
|
</Border.Effect>
|
||||||
<xaml:WindowsXamlHost
|
<xaml:WindowsXamlHost
|
||||||
|
Height="60"
|
||||||
|
x:Name="SearchBox"
|
||||||
InitialTypeName="PowerLauncher.UI.LauncherControl"
|
InitialTypeName="PowerLauncher.UI.LauncherControl"
|
||||||
ChildChanged="WindowsXamlHostTextBox_ChildChanged" />
|
ChildChanged="WindowsXamlHostTextBox_ChildChanged" />
|
||||||
</Border>
|
</Border>
|
||||||
@@ -54,6 +58,7 @@
|
|||||||
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
||||||
</Border.Effect>
|
</Border.Effect>
|
||||||
<xaml:WindowsXamlHost
|
<xaml:WindowsXamlHost
|
||||||
|
x:Name="ListBox"
|
||||||
InitialTypeName="PowerLauncher.UI.ResultList"
|
InitialTypeName="PowerLauncher.UI.ResultList"
|
||||||
ChildChanged="WindowsXamlHostListView_ChildChanged"
|
ChildChanged="WindowsXamlHostListView_ChildChanged"
|
||||||
PreviewMouseDown="WindowsXamlHost_PreviewMouseDown" />
|
PreviewMouseDown="WindowsXamlHost_PreviewMouseDown" />
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ using Windows.UI.Xaml;
|
|||||||
using Windows.UI.Core;
|
using Windows.UI.Core;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Windows.UI.Xaml.Data;
|
using Windows.UI.Xaml.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Mages.Core.Runtime.Converters;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace PowerLauncher
|
namespace PowerLauncher
|
||||||
{
|
{
|
||||||
@@ -36,6 +39,9 @@ namespace PowerLauncher
|
|||||||
private MainViewModel _viewModel;
|
private MainViewModel _viewModel;
|
||||||
private bool _isTextSetProgramatically;
|
private bool _isTextSetProgramatically;
|
||||||
const int ROW_HEIGHT = 75;
|
const int ROW_HEIGHT = 75;
|
||||||
|
const int MAX_LIST_HEIGHT = 300;
|
||||||
|
bool isDPIChanged = false;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public MainWindow(Settings settings, MainViewModel mainVM)
|
public MainWindow(Settings settings, MainViewModel mainVM)
|
||||||
@@ -68,9 +74,9 @@ namespace PowerLauncher
|
|||||||
|
|
||||||
private void InitializePosition()
|
private void InitializePosition()
|
||||||
{
|
{
|
||||||
//Top = WindowTop();
|
Top = WindowTop();
|
||||||
Left = WindowLeft();
|
Left = WindowLeft();
|
||||||
//_settings.WindowTop = Top;
|
_settings.WindowTop = Top;
|
||||||
_settings.WindowLeft = Left;
|
_settings.WindowLeft = Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +112,15 @@ namespace PowerLauncher
|
|||||||
{
|
{
|
||||||
if (_settings.HideWhenDeactive)
|
if (_settings.HideWhenDeactive)
|
||||||
{
|
{
|
||||||
Hide();
|
if (isDPIChanged)
|
||||||
|
{
|
||||||
|
isDPIChanged = false;
|
||||||
|
InitializePosition();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +133,18 @@ namespace PowerLauncher
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
double prevTop = Top;
|
||||||
|
double prevLeft = Left;
|
||||||
|
Top = WindowTop();
|
||||||
Left = WindowLeft();
|
Left = WindowLeft();
|
||||||
//Top = WindowTop();
|
if (prevTop != Top || prevLeft != Left)
|
||||||
|
{
|
||||||
|
isDPIChanged = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isDPIChanged = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,15 +157,32 @@ namespace PowerLauncher
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates X co-ordinate of main window top left corner.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>X co-ordinate of main window top left corner</returns>
|
||||||
private double WindowLeft()
|
private double WindowLeft()
|
||||||
{
|
{
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
var dpi1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
||||||
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
var dpi2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
||||||
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
|
var left = (dpi2.X - this.Width) / 2 + dpi1.X;
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates Y co-ordinate of main window top left corner
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Y co-ordinate of main window top left corner</returns>
|
||||||
|
private double WindowTop()
|
||||||
|
{
|
||||||
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
|
var dpi1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
|
||||||
|
var dpi2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
|
||||||
|
var totalHeight = this.SearchBoxBorder.Margin.Top + this.SearchBoxBorder.Margin.Bottom + this.SearchBox.Height + this.ListBoxBorder.Margin.Top + this.ListBoxBorder.Margin.Bottom + MAX_LIST_HEIGHT;
|
||||||
|
var top = (dpi2.Y - totalHeight) / 4 + dpi1.Y;
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
private PowerLauncher.UI.LauncherControl _launcher = null;
|
private PowerLauncher.UI.LauncherControl _launcher = null;
|
||||||
private void WindowsXamlHostTextBox_ChildChanged(object sender, EventArgs ev)
|
private void WindowsXamlHostTextBox_ChildChanged(object sender, EventArgs ev)
|
||||||
@@ -184,8 +225,6 @@ namespace PowerLauncher
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void UserControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
private void UserControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.PropertyName == "SolidBorderBrush")
|
if (e.PropertyName == "SolidBorderBrush")
|
||||||
|
|||||||
Reference in New Issue
Block a user