mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 17:42:45 +08: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:
parent
8cb134f56b
commit
f44109abae
@ -23,9 +23,11 @@
|
||||
LocationChanged="OnLocationChanged"
|
||||
Deactivated="OnDeactivated"
|
||||
Background="Transparent"
|
||||
Width="720"
|
||||
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
||||
<Grid Width="720">
|
||||
<Grid Width="720"
|
||||
MouseDown="OnMouseDown">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@ -39,7 +41,9 @@
|
||||
<Border.Effect>
|
||||
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
||||
</Border.Effect>
|
||||
<xaml:WindowsXamlHost
|
||||
<xaml:WindowsXamlHost
|
||||
Height="60"
|
||||
x:Name="SearchBox"
|
||||
InitialTypeName="PowerLauncher.UI.LauncherControl"
|
||||
ChildChanged="WindowsXamlHostTextBox_ChildChanged" />
|
||||
</Border>
|
||||
@ -53,7 +57,8 @@
|
||||
<Border.Effect>
|
||||
<DropShadowEffect BlurRadius="16" Opacity="0.8" ShadowDepth="0" />
|
||||
</Border.Effect>
|
||||
<xaml:WindowsXamlHost
|
||||
<xaml:WindowsXamlHost
|
||||
x:Name="ListBox"
|
||||
InitialTypeName="PowerLauncher.UI.ResultList"
|
||||
ChildChanged="WindowsXamlHostListView_ChildChanged"
|
||||
PreviewMouseDown="WindowsXamlHost_PreviewMouseDown" />
|
||||
|
@ -23,6 +23,9 @@ using Windows.UI.Xaml;
|
||||
using Windows.UI.Core;
|
||||
using System.Windows.Media;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using System.Diagnostics;
|
||||
using Mages.Core.Runtime.Converters;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PowerLauncher
|
||||
{
|
||||
@ -36,6 +39,9 @@ namespace PowerLauncher
|
||||
private MainViewModel _viewModel;
|
||||
private bool _isTextSetProgramatically;
|
||||
const int ROW_HEIGHT = 75;
|
||||
const int MAX_LIST_HEIGHT = 300;
|
||||
bool isDPIChanged = false;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainWindow(Settings settings, MainViewModel mainVM)
|
||||
@ -68,9 +74,9 @@ namespace PowerLauncher
|
||||
|
||||
private void InitializePosition()
|
||||
{
|
||||
//Top = WindowTop();
|
||||
Top = WindowTop();
|
||||
Left = WindowLeft();
|
||||
//_settings.WindowTop = Top;
|
||||
_settings.WindowTop = Top;
|
||||
_settings.WindowLeft = Left;
|
||||
}
|
||||
|
||||
@ -106,8 +112,16 @@ namespace PowerLauncher
|
||||
{
|
||||
if (_settings.HideWhenDeactive)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
if (isDPIChanged)
|
||||
{
|
||||
isDPIChanged = false;
|
||||
InitializePosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePosition()
|
||||
@ -119,8 +133,18 @@ namespace PowerLauncher
|
||||
}
|
||||
else
|
||||
{
|
||||
double prevTop = Top;
|
||||
double prevLeft = Left;
|
||||
Top = WindowTop();
|
||||
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()
|
||||
{
|
||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
||||
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
||||
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
|
||||
var dpi1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
||||
var dpi2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
||||
var left = (dpi2.X - this.Width) / 2 + dpi1.X;
|
||||
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 void WindowsXamlHostTextBox_ChildChanged(object sender, EventArgs ev)
|
||||
@ -184,8 +225,6 @@ namespace PowerLauncher
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UserControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "SolidBorderBrush")
|
||||
|
Loading…
Reference in New Issue
Block a user