2023-06-12 16:20:03 -07:00
|
|
|
From 8c830f61a85e634b1fc135f6fe90a1dd5e45d158 Mon Sep 17 00:00:00 2001
|
2019-08-04 17:27:34 -07:00
|
|
|
From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= <gabrielopcode@gmail.com>
|
|
|
|
Date: Mon, 22 Jul 2019 15:29:25 +0300
|
2022-02-17 15:54:02 -08:00
|
|
|
Subject: [PATCH] user32/focus: Prevent a recursive loop with the activation
|
|
|
|
messages
|
2019-08-04 17:27:34 -07:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
When activating a window and sending activation messages to the window
|
|
|
|
procedure, Windows avoids a recursive loop by not sending more of these
|
|
|
|
messages or hooks while it's still activating the window. Some applications
|
|
|
|
actually depend on this behavior, so it is needed.
|
|
|
|
|
|
|
|
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46274
|
|
|
|
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
|
|
|
|
---
|
2023-06-12 16:20:03 -07:00
|
|
|
dlls/win32u/input.c | 42 +++++++++++++++++++++++++-----------
|
2022-03-11 16:27:46 -08:00
|
|
|
dlls/win32u/ntuser_private.h | 1 +
|
2023-06-12 16:20:03 -07:00
|
|
|
2 files changed, 30 insertions(+), 13 deletions(-)
|
2019-08-04 17:27:34 -07:00
|
|
|
|
2022-03-11 16:27:46 -08:00
|
|
|
diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c
|
2023-06-12 16:20:03 -07:00
|
|
|
index cbdd4b195d3..241d07cefd2 100644
|
2022-03-11 16:27:46 -08:00
|
|
|
--- a/dlls/win32u/input.c
|
|
|
|
+++ b/dlls/win32u/input.c
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -1810,7 +1810,7 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus )
|
2019-08-04 17:27:34 -07:00
|
|
|
{
|
2022-03-11 16:27:46 -08:00
|
|
|
HWND previous = get_active_window();
|
2019-08-04 17:27:34 -07:00
|
|
|
BOOL ret;
|
|
|
|
- DWORD old_thread, new_thread;
|
|
|
|
+ DWORD winflags, old_thread, new_thread;
|
|
|
|
CBTACTIVATESTRUCT cbt;
|
|
|
|
|
|
|
|
if (previous == hwnd)
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -1819,16 +1819,24 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus )
|
|
|
|
goto done;
|
2019-08-04 17:27:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- /* call CBT hook chain */
|
|
|
|
- cbt.fMouse = mouse;
|
|
|
|
- cbt.hWndActive = previous;
|
2022-08-16 15:24:50 -07:00
|
|
|
- if (call_hooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hwnd, (LPARAM)&cbt, sizeof(cbt) )) return FALSE;
|
2019-08-04 17:27:34 -07:00
|
|
|
-
|
2022-03-11 16:27:46 -08:00
|
|
|
- if (is_window( previous ))
|
2019-08-04 17:27:34 -07:00
|
|
|
+ /* Prevent a recursive activation loop with the activation messages */
|
|
|
|
+ winflags = win_set_flags(hwnd, WIN_IS_IN_ACTIVATION, 0);
|
|
|
|
+ if (!(winflags & WIN_IS_IN_ACTIVATION))
|
|
|
|
{
|
2022-03-11 16:27:46 -08:00
|
|
|
- send_message( previous, WM_NCACTIVATE, FALSE, (LPARAM)hwnd );
|
|
|
|
- send_message( previous, WM_ACTIVATE,
|
|
|
|
- MAKEWPARAM( WA_INACTIVE, is_iconic(previous) ), (LPARAM)hwnd );
|
2019-08-04 17:27:34 -07:00
|
|
|
+ ret = FALSE;
|
|
|
|
+
|
|
|
|
+ /* call CBT hook chain */
|
|
|
|
+ cbt.fMouse = mouse;
|
|
|
|
+ cbt.hWndActive = previous;
|
2022-08-16 15:24:50 -07:00
|
|
|
+ if (call_hooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hwnd, (LPARAM)&cbt, sizeof(cbt) ))
|
2019-08-04 17:27:34 -07:00
|
|
|
+ goto clear_flags;
|
|
|
|
+
|
2022-03-11 16:27:46 -08:00
|
|
|
+ if (is_window(previous))
|
2019-08-04 17:27:34 -07:00
|
|
|
+ {
|
2022-03-11 16:27:46 -08:00
|
|
|
+ send_message( previous, WM_NCACTIVATE, FALSE, (LPARAM)hwnd );
|
|
|
|
+ send_message( previous, WM_ACTIVATE,
|
|
|
|
+ MAKEWPARAM( WA_INACTIVE, is_iconic(previous) ), (LPARAM)hwnd );
|
2019-08-04 17:27:34 -07:00
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_active_window )
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -1848,7 +1856,11 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus )
|
2022-04-05 16:00:31 -07:00
|
|
|
if (send_message( hwnd, WM_QUERYNEWPALETTE, 0, 0 ))
|
|
|
|
send_message_timeout( HWND_BROADCAST, WM_PALETTEISCHANGING, (WPARAM)hwnd, 0,
|
2022-08-15 17:15:01 -07:00
|
|
|
SMTO_ABORTIFHUNG, 2000, FALSE );
|
2022-03-11 16:27:46 -08:00
|
|
|
- if (!is_window(hwnd)) return FALSE;
|
|
|
|
+ if (!is_window(hwnd))
|
2019-08-04 17:27:34 -07:00
|
|
|
+ {
|
|
|
|
+ ret = FALSE;
|
|
|
|
+ goto clear_flags;
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:27:46 -08:00
|
|
|
old_thread = previous ? get_window_thread( previous, NULL ) : 0;
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -1880,7 +1892,7 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus )
|
2019-08-04 17:27:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:27:46 -08:00
|
|
|
- if (is_window(hwnd))
|
|
|
|
+ if (!(winflags & WIN_IS_IN_ACTIVATION) && is_window(hwnd))
|
2019-08-04 17:27:34 -07:00
|
|
|
{
|
2022-03-11 16:27:46 -08:00
|
|
|
send_message( hwnd, WM_NCACTIVATE, hwnd == NtUserGetForegroundWindow(), (LPARAM)previous );
|
|
|
|
send_message( hwnd, WM_ACTIVATE,
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -1914,9 +1926,13 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus )
|
2019-08-04 17:27:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+clear_flags:
|
|
|
|
+ win_set_flags(hwnd, 0, WIN_IS_IN_ACTIVATION);
|
2023-06-12 16:20:03 -07:00
|
|
|
+
|
|
|
|
done:
|
|
|
|
if (hwnd) clip_fullscreen_window( hwnd, FALSE );
|
|
|
|
- return TRUE;
|
|
|
|
+
|
2019-08-04 17:27:34 -07:00
|
|
|
+ return ret;
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:27:46 -08:00
|
|
|
/**********************************************************************
|
|
|
|
diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h
|
2023-06-12 16:20:03 -07:00
|
|
|
index b39e38db5d6..4be55209265 100644
|
2022-03-11 16:27:46 -08:00
|
|
|
--- a/dlls/win32u/ntuser_private.h
|
|
|
|
+++ b/dlls/win32u/ntuser_private.h
|
2023-06-12 16:20:03 -07:00
|
|
|
@@ -100,6 +100,7 @@ typedef struct tagWND
|
2019-08-04 17:27:34 -07:00
|
|
|
#define WIN_NEEDS_SHOW_OWNEDPOPUP 0x0020 /* WM_SHOWWINDOW:SC_SHOW must be sent in the next ShowOwnedPopup call */
|
|
|
|
#define WIN_CHILDREN_MOVED 0x0040 /* children may have moved, ignore stored positions */
|
|
|
|
#define WIN_HAS_IME_WIN 0x0080 /* the window has been registered with imm32 */
|
|
|
|
+#define WIN_IS_IN_ACTIVATION 0x0100 /* the window is in an activation process */
|
|
|
|
|
2022-07-28 15:38:12 -07:00
|
|
|
#define WND_OTHER_PROCESS ((WND *)1) /* returned by get_win_ptr on unknown window handles */
|
|
|
|
#define WND_DESKTOP ((WND *)2) /* returned by get_win_ptr on the desktop window */
|
2019-08-04 17:27:34 -07:00
|
|
|
--
|
2023-06-12 16:20:03 -07:00
|
|
|
2.40.1
|
2019-08-04 17:27:34 -07:00
|
|
|
|