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:
@@ -45,13 +45,5 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void BecomeForegroundWindow(IntPtr hWnd)
|
||||
{
|
||||
NativeKeyboardHelper.INPUT input = new NativeKeyboardHelper.INPUT { type = NativeKeyboardHelper.INPUTTYPE.INPUT_MOUSE, data = { } };
|
||||
NativeKeyboardHelper.INPUT[] inputs = new NativeKeyboardHelper.INPUT[] { input };
|
||||
_ = NativeMethods.SendInput(1, inputs, NativeKeyboardHelper.INPUT.Size);
|
||||
NativeMethods.SetForegroundWindow(hWnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground
|
||||
// Need to call SetForegroundWindow to actually gain focus.
|
||||
Utils.BecomeForegroundWindow(settingsWindow.GetWindowHandle());
|
||||
WindowHelpers.BringToForeground(settingsWindow.GetWindowHandle());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -33,6 +33,10 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout
|
||||
{
|
||||
FlyoutMenuButton selectedModuleBtn = sender as FlyoutMenuButton;
|
||||
bool moduleRun = true;
|
||||
|
||||
// Closing manually the flyout to workaround focus gain problems
|
||||
App.GetFlyoutWindow()?.Hide();
|
||||
|
||||
switch ((string)selectedModuleBtn.Tag)
|
||||
{
|
||||
case "ColorPicker": // Launch ColorPicker
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground
|
||||
// Need to call SetForegroundWindow to actually gain focus.
|
||||
Utils.BecomeForegroundWindow(flyout.GetWindowHandle());
|
||||
WindowHelpers.BringToForeground(flyout.GetWindowHandle());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user