From e20dc19abc8c6964d7bb74a82b60f4daceb20678 Mon Sep 17 00:00:00 2001 From: "Shawn Yuan (from Dev Box)" Date: Mon, 5 Jan 2026 09:34:02 +0800 Subject: [PATCH] fix shortcut activation issue --- .../QuickAccessXAML/MainWindow.xaml.cs | 38 +------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs index 4d86dffcd4..dab53d9432 100644 --- a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs +++ b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs @@ -3,12 +3,10 @@ // See the LICENSE file in the project root for more information. using System; -using System.IO; -using System.IO.MemoryMappedFiles; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.PowerToys.QuickAccess.Flyout; +using ManagedCommon; using Microsoft.PowerToys.QuickAccess.Services; using Microsoft.PowerToys.QuickAccess.ViewModels; using Microsoft.UI.Dispatching; @@ -236,7 +234,7 @@ public sealed partial class MainWindow : WindowEx, IDisposable } SetWindowPosNative(_hwnd, HwndTopmost, targetX, targetY, 0, 0, flags); - BringToForeground(_hwnd); + WindowHelpers.BringToForeground(_hwnd); } _hasSeenInteractiveActivation = true; @@ -437,38 +435,6 @@ public sealed partial class MainWindow : WindowEx, IDisposable [DllImport("user32.dll", EntryPoint = "GetWindowRect", SetLastError = true)] private static extern bool GetWindowRectNative(IntPtr hWnd, out Rect rect); - private static void BringToForeground(IntPtr hwnd) - { - if (hwnd == IntPtr.Zero) - { - return; - } - - SetForegroundWindowNative(hwnd); - - var foreground = GetForegroundWindowNative(); - if (foreground == hwnd) - { - return; - } - - var windowThread = GetWindowThreadProcessIdNative(hwnd, IntPtr.Zero); - var foregroundThread = foreground != IntPtr.Zero ? GetWindowThreadProcessIdNative(foreground, IntPtr.Zero) : 0; - - if (windowThread != 0 && foregroundThread != 0 && windowThread != foregroundThread) - { - if (AttachThreadInputNative(windowThread, foregroundThread, true)) - { - SetForegroundWindowNative(hwnd); - AttachThreadInputNative(windowThread, foregroundThread, false); - } - } - else - { - SetForegroundWindowNative(hwnd); - } - } - private void EnsureGlobalMouseHook() { if (_mouseHook != IntPtr.Zero)