mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
Merge pull request #423 from lances101/bugfix-271-positioning
Bugfix #271 positioning
This commit is contained in:
commit
8ade52c8d9
@ -4,6 +4,8 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using Point = System.Windows.Point;
|
||||||
|
|
||||||
namespace Wox.Helper
|
namespace Wox.Helper
|
||||||
{
|
{
|
||||||
@ -80,6 +82,32 @@ namespace Wox.Helper
|
|||||||
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
|
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transforms pixels to Device Independent Pixels used by WPF
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="visual">current window, required to get presentation source</param>
|
||||||
|
/// <param name="unitX">horizontal position in pixels</param>
|
||||||
|
/// <param name="unitY">vertical position in pixels</param>
|
||||||
|
/// <returns>point containing device independent pixels</returns>
|
||||||
|
public static Point TransformPixelsToDIP(Visual visual, double unitX, double unitY)
|
||||||
|
{
|
||||||
|
Matrix matrix;
|
||||||
|
var source = PresentationSource.FromVisual(visual);
|
||||||
|
if (source != null)
|
||||||
|
{
|
||||||
|
matrix = source.CompositionTarget.TransformFromDevice;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using (var src = new HwndSource(new HwndSourceParameters()))
|
||||||
|
{
|
||||||
|
matrix = src.CompositionTarget.TransformFromDevice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Point((int) (matrix.M11*unitX), (int) (matrix.M22*unitY));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct RECT
|
public struct RECT
|
||||||
{
|
{
|
||||||
|
@ -260,34 +260,21 @@ namespace Wox
|
|||||||
|
|
||||||
private double GetWindowsLeft()
|
private double GetWindowsLeft()
|
||||||
{
|
{
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowLeft;
|
||||||
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
|
|
||||||
{
|
|
||||||
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
|
||||||
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
|
||||||
UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) / 2 + screen.WorkingArea.Left;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
|
var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
||||||
|
UserSettingStorage.Instance.WindowLeft = (dipPoint.X - ActualWidth)/2;
|
||||||
return UserSettingStorage.Instance.WindowLeft;
|
return UserSettingStorage.Instance.WindowLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double GetWindowsTop()
|
private double GetWindowsTop()
|
||||||
{
|
{
|
||||||
|
if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowTop;
|
||||||
|
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
|
var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
|
||||||
{
|
UserSettingStorage.Instance.WindowTop = (dipPoint.Y - tbQuery.ActualHeight)/4;
|
||||||
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
|
||||||
var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
|
|
||||||
UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - tbQuery.ActualHeight) / 4 + screen.WorkingArea.Top;
|
|
||||||
}
|
|
||||||
return UserSettingStorage.Instance.WindowTop;
|
return UserSettingStorage.Instance.WindowTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,6 +521,8 @@ namespace Wox
|
|||||||
|
|
||||||
private void HideWox()
|
private void HideWox()
|
||||||
{
|
{
|
||||||
|
UserSettingStorage.Instance.WindowLeft = Left;
|
||||||
|
UserSettingStorage.Instance.WindowTop = Top;
|
||||||
if (IsInContextMenuMode)
|
if (IsInContextMenuMode)
|
||||||
{
|
{
|
||||||
BackToResultMode();
|
BackToResultMode();
|
||||||
|
@ -5,6 +5,7 @@ using System.Windows.Forms;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using Wox.Helper;
|
||||||
|
|
||||||
namespace Wox {
|
namespace Wox {
|
||||||
public partial class Msg : Window {
|
public partial class Msg : Window {
|
||||||
@ -13,15 +14,18 @@ namespace Wox {
|
|||||||
|
|
||||||
public Msg() {
|
public Msg() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
|
var dipWorkingArea = WindowIntelopHelper.TransformPixelsToDIP(this,
|
||||||
Top = Screen.PrimaryScreen.Bounds.Bottom;
|
screen.WorkingArea.Width,
|
||||||
showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom;
|
screen.WorkingArea.Height);
|
||||||
showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height;
|
Left = dipWorkingArea.X - this.Width;
|
||||||
|
Top = dipWorkingArea.Y;
|
||||||
|
showAnimation.From = dipWorkingArea.Y;
|
||||||
|
showAnimation.To = dipWorkingArea.Y - Height;
|
||||||
|
|
||||||
// Create the fade out storyboard
|
// Create the fade out storyboard
|
||||||
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
|
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
|
||||||
DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3))) {
|
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(0.3))) {
|
||||||
AccelerationRatio = 0.2
|
AccelerationRatio = 0.2
|
||||||
};
|
};
|
||||||
Storyboard.SetTarget(fadeOutAnimation, this);
|
Storyboard.SetTarget(fadeOutAnimation, this);
|
||||||
|
Loading…
Reference in New Issue
Block a user