mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[PTRun]Reverted start position to slightly off-center(#34083)
## Summary of the Pull Request Reverted start-position to slightly off-center while still addressing multi-monitor/multi-DPI scenarios.
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace PowerLauncher.Helper
|
||||
{
|
||||
@@ -187,15 +188,18 @@ namespace PowerLauncher.Helper
|
||||
_ = NativeMethods.SetWindowLong(hwnd, GWL_EX_STYLE, NativeMethods.GetWindowLong(hwnd, GWL_EX_STYLE) | WS_EX_TOOLWINDOW);
|
||||
}
|
||||
|
||||
public static void MoveToScreenCenter(Window window, Screen screen)
|
||||
/// <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)
|
||||
{
|
||||
var workingArea = screen.WorkingArea;
|
||||
var matrix = GetCompositionTarget(window).TransformFromDevice;
|
||||
var dpiX = matrix.M11;
|
||||
var dpiY = matrix.M22;
|
||||
var matrix = GetCompositionTarget(visual).TransformFromDevice;
|
||||
|
||||
window.Left = (dpiX * workingArea.Left) + (((dpiX * workingArea.Width) - window.Width) / 2);
|
||||
window.Top = (dpiY * workingArea.Top) + (((dpiY * workingArea.Height) - window.Height) / 2);
|
||||
return new Point((int)(matrix.M11 * unitX), (int)(matrix.M22 * unitY));
|
||||
}
|
||||
|
||||
private static CompositionTarget GetCompositionTarget(Visual visual)
|
||||
|
||||
Reference in New Issue
Block a user