Merged from branch deedra after conflict fixes.
This commit is contained in:
commit
2dfd5b200a
15 files changed
+494
-152
No files matched your search
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include "bootstrapper_hook.h"
|
||||
|
||||
typedef struct WineAccessForegroundHooks {
|
||||
HMODULE module;
|
||||
HOOKPROC menu_callback, input_callback;
|
||||
HHOOK menu, input;
|
||||
DWORD thread;
|
||||
} WineAccessForegroundHooks;
|
||||
|
||||
static inline void wine_access_release_hooks(WineAccessForegroundHooks *hooks) {
|
||||
if (hooks->menu) UnhookWindowsHookEx(hooks->menu);
|
||||
if (hooks->input) UnhookWindowsHookEx(hooks->input);
|
||||
hooks->menu = hooks->input = NULL;
|
||||
hooks->thread = 0;
|
||||
}
|
||||
|
||||
// Global hooks cross the 32/64-bit boundary through the installing thread.
|
||||
// Avoid that synchronous traffic and hook only the matching foreground UI
|
||||
// thread. Both hosts use the same detach/retry rules.
|
||||
static inline void wine_access_update_hooks(WineAccessForegroundHooks *hooks, BOOL target_wow64) {
|
||||
DWORD pid = 0;
|
||||
DWORD thread = GetWindowThreadProcessId(GetForegroundWindow(), &pid);
|
||||
HANDLE process = pid ? OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid) : NULL;
|
||||
BOOL wow64 = FALSE;
|
||||
BOOL known = process && IsWow64Process(process, &wow64);
|
||||
if (process) CloseHandle(process);
|
||||
if (!known || wow64 != target_wow64) thread = 0;
|
||||
if (thread == hooks->thread) return;
|
||||
wine_access_release_hooks(hooks);
|
||||
if (!thread || !hooks->menu_callback || !hooks->input_callback) return;
|
||||
hooks->menu = SetWindowsHookExW(WH_CALLWNDPROC, hooks->menu_callback, hooks->module, thread);
|
||||
hooks->input = SetWindowsHookExW(WH_GETMESSAGE, hooks->input_callback, hooks->module, thread);
|
||||
if (hooks->menu && hooks->input) {
|
||||
hooks->thread = thread;
|
||||
HWND foreground = GetForegroundWindow();
|
||||
WCHAR className[128];
|
||||
if (GetWindowThreadProcessId(foreground, NULL) == thread &&
|
||||
GetClassNameW(foreground, className, ARRAYSIZE(className)) &&
|
||||
!lstrcmpW(className, L"Blizzard Bootstrapper")) {
|
||||
// A query may have arrived while detached. Reestablish readiness on
|
||||
// every attachment, including return from another application.
|
||||
RemovePropW(foreground, BOOTSTRAPPER_STATE_READY);
|
||||
RemovePropW(foreground, BOOTSTRAPPER_STATE_PENDING);
|
||||
PostMessageW(foreground, WM_NULL, 0, 0);
|
||||
}
|
||||
} else wine_access_release_hooks(hooks); // Retry both on the next foreground poll.
|
||||
}
|
||||
Reference in new issue
Block a user