mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[Refactor]Use same improved BringToForeground across the solution (#28532)
* Use single BringToForeground across the solution * Close flyout manually * Try with sending input, if it fails try threads
This commit is contained in:
@@ -22,19 +22,6 @@ namespace Peek.UI.Extensions
|
||||
return hwnd.GetMonitorScale();
|
||||
}
|
||||
|
||||
public static void BringToForeground(this Window window)
|
||||
{
|
||||
// Ability to be able to set the Window to the Foreground is very limited. A current workaround is simulating mouse input before bringing to the foreground.
|
||||
var windowHandle = window.GetWindowHandle();
|
||||
Windows.Win32.UI.Input.KeyboardAndMouse.INPUT input = new Windows.Win32.UI.Input.KeyboardAndMouse.INPUT { type = Windows.Win32.UI.Input.KeyboardAndMouse.INPUT_TYPE.INPUT_MOUSE, Anonymous = { } };
|
||||
Windows.Win32.UI.Input.KeyboardAndMouse.INPUT[] inputs = new Windows.Win32.UI.Input.KeyboardAndMouse.INPUT[] { input };
|
||||
_ = PInvoke.SendInput(inputs.AsSpan<Windows.Win32.UI.Input.KeyboardAndMouse.INPUT>(), Marshal.SizeOf(typeof(Windows.Win32.UI.Input.KeyboardAndMouse.INPUT)));
|
||||
if (PInvoke.SetForegroundWindow(new HWND(windowHandle)) == 0)
|
||||
{
|
||||
Logger.LogWarning("Couldn't set the Peek window as the foreground window.");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CenterOnMonitor(this Window window, HWND hwndDesktop, double? width = null, double? height = null)
|
||||
{
|
||||
var hwndToCenter = new HWND(window.GetWindowHandle());
|
||||
|
||||
@@ -4,7 +4,6 @@ GetDpiForWindow
|
||||
GetForegroundWindow
|
||||
SetForegroundWindow
|
||||
SetActiveWindow
|
||||
SendInput
|
||||
GetWindowThreadProcessId
|
||||
GetCurrentThreadId
|
||||
AttachThreadInput
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Peek.UI
|
||||
}
|
||||
|
||||
this.Show();
|
||||
this.BringToForeground();
|
||||
WindowHelpers.BringToForeground(this.GetWindowHandle());
|
||||
}
|
||||
|
||||
private Size GetMonitorMaxContentSize(Size monitorSize, double scaling)
|
||||
|
||||
Reference in New Issue
Block a user