Expose visible Wine window text to the matching Go reader's independent keypad review commands, and extend standard Edit feedback to 32-bit programs such as MUSHclient without requiring 32-bit Linux GLib/Winelib libraries. Add lifetime-aware instance/window/control identities and bounded capture of standard Edit text, button/static captions, native ListBox/ListView items, and usable MSAA text. Preserve focus, caret, selection, scrolling, and the clipboard. Exclude hidden/password content before retrieval, retain both rune and UTF-16 offsets, clip visible ranges, and reject changing or oversized sources rather than returning incomplete text as a full snapshot. Export CaptureWindow on the version-1 WineReview D-Bus interface. Register with the current reader service owner and publish copied focus metadata. Authorize capture only for the current same-user owner. Use a dedicated GLib dispatcher and separate COM worker with a 500 ms deadline, one active job and one pending job, bounded payloads, and explicit stale/busy/limited/ unavailable replies. Keep menu and focus forwarding responsive when an MSAA provider stalls; retain ordinary feedback with older readers. Read the actual X11 geometry associated with Wine HWNDs using bounded XCB queries and __wine_x11_whole_window. Translate virtual-desktop coordinates and recheck physical geometry before returning captured text. Link XCB in the helper/tests and declare libxcb in the Arch package dependencies. Build edit_hook.c into the 32-bit DLL and attach both menu and input hooks to the foreground 32-bit UI thread. Release both hooks on transitions or attachment failure. Keep Scintilla-specific hooks confined to 64-bit builds. Expand Edit integration checks with read-only multiline navigation and unsuccessful deletion, plus 32-bit editor/Windows Forms lifecycle support. Add 32-bit/64-bit native capture fixtures, wire-protocol integration checks, and design/implementation documents. Document exact schema, capture limits, installation dependencies, compatibility, and live acceptance procedures. Validation during commit preparation: - git diff --check passed. - cmake --build build --parallel passed. - CTest could not start because xvfb-run is unavailable in this environment. - Further tests were skipped at the user's request; capture, protocol, and menu/editor integration tests were not run during commit preparation. Live speech and physical braille checks remain necessary, including review without moving the native caret, incoming output, plugin dialogs, and return to Linux/Fenrir. Custom painted output requires an accessible provider; RichEdit/Scintilla capture, semantic object review, Say All, typing echo, and native Wine braille routing remain unsupported by this protocol.
81 lines
3.3 KiB
C
81 lines
3.3 KiB
C
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#include "menu_bridge.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
static DWORD foreground_thread32(void) {
|
|
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);
|
|
return known && wow64 ? thread : 0;
|
|
}
|
|
|
|
// Hook DLLs must match the application's architecture. This small PE host
|
|
// supplies 32-bit menu/editor hooks without requiring 32-bit Linux GLib/Winelib.
|
|
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) {
|
|
(void)instance; (void)previous; (void)show;
|
|
char *end;
|
|
DWORD parentId = strtoul(args, &end, 10);
|
|
HWND bridge = (HWND)(UINT_PTR)strtoul(end, &end, 10);
|
|
DWORD bridgeProcess = 0;
|
|
GetWindowThreadProcessId(bridge, &bridgeProcess);
|
|
if (!parentId || bridgeProcess != parentId) return 1;
|
|
HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, parentId);
|
|
if (!parent) return 1;
|
|
|
|
WCHAR path[4096] = {0};
|
|
DWORD length = GetModuleFileNameW(NULL, path, 4096);
|
|
WCHAR *name = NULL;
|
|
for (DWORD i = 0; i < length && i < 4096; ++i)
|
|
if (path[i] == L'\\' || path[i] == L'/') name = path + i + 1;
|
|
if (!length || length >= 4096 || !name ||
|
|
name - path + lstrlenW(L"wine-access-menu32.dll") >= 4096) {
|
|
CloseHandle(parent);
|
|
return 1;
|
|
}
|
|
lstrcpyW(name, L"wine-access-menu32.dll");
|
|
HMODULE module = LoadLibraryW(path);
|
|
HOOKPROC callback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessMenuHook") : NULL;
|
|
HOOKPROC inputCallback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessInputHook") : NULL;
|
|
HHOOK hook = NULL;
|
|
HHOOK inputHook = NULL;
|
|
DWORD hookedThread = 0;
|
|
if (!callback || !inputCallback)
|
|
fprintf(stderr, "wine-access: 32-bit menu/editor hooks unavailable (error %lu)\n", GetLastError());
|
|
if (callback && inputCallback) {
|
|
while (IsWindow(bridge)) {
|
|
// Wine's mixed-architecture global hook chain can suppress the 64-bit
|
|
// hook. Attach only to the foreground 32-bit UI thread, and release it
|
|
// when focus moves elsewhere. The 64-bit helper keeps its global hook.
|
|
DWORD thread = foreground_thread32();
|
|
if (thread != hookedThread) {
|
|
if (hook) UnhookWindowsHookEx(hook);
|
|
if (inputHook) UnhookWindowsHookEx(inputHook);
|
|
hook = thread ? SetWindowsHookExW(WH_CALLWNDPROC, callback, module, thread) : NULL;
|
|
inputHook = thread ? SetWindowsHookExW(WH_GETMESSAGE, inputCallback, module, thread) : NULL;
|
|
hookedThread = hook && inputHook ? thread : 0;
|
|
if (!hookedThread) {
|
|
if (hook) UnhookWindowsHookEx(hook);
|
|
if (inputHook) UnhookWindowsHookEx(inputHook);
|
|
hook = inputHook = NULL;
|
|
}
|
|
}
|
|
DWORD result = MsgWaitForMultipleObjects(1, &parent, FALSE, 100, QS_ALLINPUT);
|
|
if (result == WAIT_OBJECT_0 || result == WAIT_FAILED) break;
|
|
MSG message;
|
|
while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) {
|
|
TranslateMessage(&message);
|
|
DispatchMessageW(&message);
|
|
}
|
|
}
|
|
if (hook) UnhookWindowsHookEx(hook);
|
|
if (inputHook) UnhookWindowsHookEx(inputHook);
|
|
}
|
|
if (module) FreeLibrary(module);
|
|
CloseHandle(parent);
|
|
return callback && inputCallback ? 0 : 1;
|
|
}
|