Restore wine access after program loses and regains focus.
This commit is contained in:
1 parent
f40e471938
commit
c3e981b4c2
12 files changed
+351
-2
No files matched your search
@@ -1,5 +1,24 @@
|
||||
# Wine control integration
|
||||
|
||||
## Virtual desktop focus recovery
|
||||
|
||||
`xvfb-run -a ctest --test-dir build -R foreground-focus --output-on-failure`
|
||||
uses a disposable Wine prefix configured for a virtual desktop and a separate
|
||||
Windows launcher fixture. It reproduces a visible launcher returned without
|
||||
activation, then checks recovery of its native foreground and button focus.
|
||||
It also checks Linux focus, mismatched window-manager/keyboard focus, disabled
|
||||
windows, multiple visible applications, hidden windows, existing foreground,
|
||||
and repeated recovery. The fixture acknowledges ICCCM window visibility on
|
||||
the private display; the runner propagates the fixture's actual exit status.
|
||||
|
||||
After installing the updated helper and restarting the reader, open AudioQuake,
|
||||
play and close a game, then Tab and Shift+Tab through the launcher. Check speech
|
||||
and braille for each control. Switch to Linux and back to workspace 3 and repeat.
|
||||
Recheck ordinary Wine menus, edits and lists, including password exclusion.
|
||||
With two visible applications in one virtual desktop, recovery intentionally
|
||||
does not choose between them; focus the intended application normally.
|
||||
Automated focus checks do not prove audible speech or physical braille.
|
||||
|
||||
## Wine flat-review capture
|
||||
|
||||
Build the helper and run `ctest --test-dir build --output-on-failure` on a
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#define UNICODE
|
||||
#define _UNICODE
|
||||
#include <windows.h>
|
||||
|
||||
static HWND button;
|
||||
static LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wp, LPARAM lp) {
|
||||
if ((message == WM_SETFOCUS || (message == WM_ACTIVATE && LOWORD(wp) != WA_INACTIVE)) && button)
|
||||
SetFocus(button);
|
||||
if (message == WM_DESTROY) { PostQuitMessage(0); return 0; }
|
||||
return DefWindowProcW(window, message, wp, lp);
|
||||
}
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) {
|
||||
(void)previous; (void)args; (void)show;
|
||||
WNDCLASSW cls = {0};
|
||||
cls.hInstance = instance;
|
||||
cls.lpfnWndProc = window_proc;
|
||||
cls.lpszClassName = L"WineAccessForegroundFixture";
|
||||
RegisterClassW(&cls);
|
||||
HWND launcher = CreateWindowW(cls.lpszClassName, L"Launcher fixture", WS_OVERLAPPEDWINDOW,
|
||||
50, 50, 300, 200, NULL, NULL, instance, NULL);
|
||||
button = CreateWindowW(L"Button", L"Play fixture", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
|
||||
10, 10, 100, 30, launcher, (HMENU)1, instance, NULL);
|
||||
ShowWindow(launcher, SW_SHOW);
|
||||
SetForegroundWindow(launcher);
|
||||
MSG message;
|
||||
while (GetMessageW(&message, NULL, 0, 0) > 0) {
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageW(&message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#include "../foreground_focus.h"
|
||||
#include "../review_x11.h"
|
||||
#pragma push_macro("_WIN32")
|
||||
#undef _WIN32
|
||||
#include <xcb/xcb.h>
|
||||
#pragma pop_macro("_WIN32")
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
void pump() {
|
||||
const auto deadline = GetTickCount64() + 100;
|
||||
do {
|
||||
MSG message{};
|
||||
while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageW(&message);
|
||||
}
|
||||
Sleep(5);
|
||||
} while (GetTickCount64() < deadline);
|
||||
}
|
||||
bool check(bool passed, const char *message) {
|
||||
if (!passed) std::fprintf(stderr, "FAIL: %s\n", message);
|
||||
return passed;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) return 2;
|
||||
const std::string command = "\"Z:" + std::string(argv[1]) + "\"";
|
||||
const int units = MultiByteToWideChar(CP_UTF8, 0, command.c_str(), -1, nullptr, 0);
|
||||
std::vector<WCHAR> wideCommand(units);
|
||||
MultiByteToWideChar(CP_UTF8, 0, command.c_str(), -1, wideCommand.data(), units);
|
||||
STARTUPINFOW startup{};
|
||||
startup.cb = sizeof(startup);
|
||||
PROCESS_INFORMATION process{};
|
||||
if (!CreateProcessW(nullptr, wideCommand.data(), nullptr, nullptr, FALSE, 0,
|
||||
nullptr, nullptr, &startup, &process)) return 2;
|
||||
HWND launcher = nullptr;
|
||||
const auto deadline = GetTickCount64() + 5000;
|
||||
while (!(launcher = FindWindowW(L"WineAccessForegroundFixture", nullptr)) &&
|
||||
GetTickCount64() < deadline) Sleep(10);
|
||||
if (!launcher) return 2;
|
||||
HWND button = GetDlgItem(launcher, 1);
|
||||
auto *connection = xcb_connect(nullptr, nullptr);
|
||||
if (xcb_connection_has_error(connection)) return 2;
|
||||
auto *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
|
||||
const auto desktop = static_cast<xcb_window_t>(reinterpret_cast<uintptr_t>(
|
||||
GetPropW(GetDesktopWindow(), L"__wine_x11_whole_window")));
|
||||
if (!desktop) return 2;
|
||||
constexpr char name[] = "_NET_ACTIVE_WINDOW";
|
||||
auto *atomReply = xcb_intern_atom_reply(connection,
|
||||
xcb_intern_atom(connection, 0, sizeof(name) - 1, name), nullptr);
|
||||
if (!atomReply) return 2;
|
||||
const auto activeAtom = atomReply->atom;
|
||||
std::free(atomReply);
|
||||
constexpr char stateName[] = "WM_STATE";
|
||||
auto *stateReply = xcb_intern_atom_reply(connection,
|
||||
xcb_intern_atom(connection, 0, sizeof(stateName) - 1, stateName), nullptr);
|
||||
if (!stateReply) return 2;
|
||||
const auto stateAtom = stateReply->atom;
|
||||
std::free(stateReply);
|
||||
auto acknowledge = [&](HWND window) {
|
||||
const auto xid = static_cast<xcb_window_t>(reinterpret_cast<uintptr_t>(
|
||||
GetPropW(window, L"__wine_x11_whole_window")));
|
||||
const uint32_t state[] = {1, XCB_WINDOW_NONE}; // ICCCM NormalState.
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xid,
|
||||
stateAtom, stateAtom, 32, 2, state);
|
||||
xcb_flush(connection);
|
||||
pump();
|
||||
};
|
||||
const auto linuxWindow = xcb_generate_id(connection);
|
||||
xcb_create_window(connection, XCB_COPY_FROM_PARENT, linuxWindow, screen->root,
|
||||
0, 0, 20, 20, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, 0, nullptr);
|
||||
xcb_map_window(connection, linuxWindow);
|
||||
auto focus = [&](xcb_window_t target, xcb_window_t active) {
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, screen->root,
|
||||
activeAtom, XCB_ATOM_WINDOW, 32, 1, &active);
|
||||
xcb_set_input_focus(connection, XCB_INPUT_FOCUS_POINTER_ROOT, target, XCB_CURRENT_TIME);
|
||||
xcb_flush(connection);
|
||||
pump();
|
||||
};
|
||||
WNDCLASSW cls{};
|
||||
cls.hInstance = GetModuleHandleW(nullptr);
|
||||
cls.lpfnWndProc = DefWindowProcW;
|
||||
cls.lpszClassName = L"WineAccessOtherFixture";
|
||||
RegisterClassW(&cls);
|
||||
HWND other = CreateWindowW(cls.lpszClassName, L"Second fixture", WS_OVERLAPPEDWINDOW,
|
||||
380, 50, 300, 200, nullptr, nullptr, cls.hInstance, nullptr);
|
||||
pump();
|
||||
bool ok = true;
|
||||
// Returning a launcher without activation leaves Wine's desktop with no
|
||||
// remembered foreground, as when an external game window has closed.
|
||||
ShowWindow(launcher, SW_HIDE);
|
||||
pump();
|
||||
ShowWindow(launcher, SW_SHOWNOACTIVATE);
|
||||
acknowledge(launcher);
|
||||
focus(linuxWindow, linuxWindow);
|
||||
ok &= check(!GetForegroundWindow(), "Linux focus clears Wine foreground");
|
||||
ok &= check(!restore_virtual_desktop_focus() && !GetForegroundWindow(), "Linux focus is never taken");
|
||||
focus(desktop, linuxWindow);
|
||||
ok &= check(!restore_virtual_desktop_focus(), "window manager must also select desktop");
|
||||
focus(linuxWindow, desktop);
|
||||
ok &= check(!restore_virtual_desktop_focus(), "X11 focus must also select desktop");
|
||||
focus(desktop, desktop);
|
||||
ok &= check(wine_x11_desktop_focused() && !GetForegroundWindow(), "reproduce orphaned virtual desktop focus");
|
||||
EnableWindow(launcher, FALSE);
|
||||
ok &= check(!restore_virtual_desktop_focus(), "disabled application is not activated");
|
||||
EnableWindow(launcher, TRUE);
|
||||
ShowWindow(other, SW_SHOWNOACTIVATE);
|
||||
acknowledge(other);
|
||||
focus(linuxWindow, linuxWindow);
|
||||
focus(desktop, desktop);
|
||||
ok &= check(!restore_virtual_desktop_focus() && !GetForegroundWindow(), "ambiguous applications are not chosen");
|
||||
ShowWindow(other, SW_HIDE);
|
||||
ok &= check(restore_virtual_desktop_focus(), "single application recovers foreground");
|
||||
pump();
|
||||
GUITHREADINFO gui{};
|
||||
gui.cbSize = sizeof(gui);
|
||||
GetGUIThreadInfo(GetWindowThreadProcessId(launcher, nullptr), &gui);
|
||||
ok &= check(GetForegroundWindow() == launcher && gui.hwndFocus == button, "launcher restores its control focus");
|
||||
ok &= check(!restore_virtual_desktop_focus() && GetForegroundWindow() == launcher, "existing Wine focus stays unchanged");
|
||||
ShowWindow(launcher, SW_HIDE);
|
||||
pump();
|
||||
ShowWindow(launcher, SW_SHOWNOACTIVATE);
|
||||
acknowledge(launcher);
|
||||
focus(linuxWindow, linuxWindow);
|
||||
focus(desktop, desktop);
|
||||
ok &= check(restore_virtual_desktop_focus(), "later workspace return recovers again");
|
||||
DestroyWindow(other);
|
||||
PostMessageW(launcher, WM_CLOSE, 0, 0);
|
||||
WaitForSingleObject(process.hProcess, 5000);
|
||||
CloseHandle(process.hProcess);
|
||||
CloseHandle(process.hThread);
|
||||
xcb_destroy_window(connection, linuxWindow);
|
||||
xcb_disconnect(connection);
|
||||
if (ok) std::puts("PASS: virtual desktop foreground recovery and focus guards");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Run the foreground fixture in its own configured Wine virtual desktop."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
buildDir = Path(sys.argv[1]).resolve()
|
||||
env = os.environ.copy()
|
||||
env.update(WINEPREFIX=str(buildDir / "focus-prefix"),
|
||||
CTHULHU_WINE_ACCESS_MANAGED="1", WINEDEBUG="-all",
|
||||
WINEDLLOVERRIDES="mscoree,mshtml=")
|
||||
try:
|
||||
for key, value, data in (
|
||||
(r"HKCU\Software\Wine\Explorer", "Desktop", "WineAccessFocusFixture"),
|
||||
(r"HKCU\Software\Wine\Explorer\Desktops", "WineAccessFocusFixture", "800x600"),
|
||||
):
|
||||
subprocess.run(["wine", "reg", "add", key, "/v", value,
|
||||
"/t", "REG_SZ", "/d", data, "/f"],
|
||||
env=env, check=True, timeout=40)
|
||||
# The next loader must create the configured desktop. Wait for this test
|
||||
# prefix's old server to stop, without touching any user application.
|
||||
subprocess.run(["wineserver", "-k"], env=env, check=True, timeout=5)
|
||||
subprocess.run(["wineserver", "-w"], env=env, check=True, timeout=5)
|
||||
result = subprocess.run([str(buildDir / "foreground-focus-test.exe"),
|
||||
str(buildDir / "foreground-fixture.exe")],
|
||||
env=env, timeout=20)
|
||||
sys.exit(result.returncode)
|
||||
finally:
|
||||
subprocess.run(["wineserver", "-k"], env=env, timeout=5)
|
||||
Reference in new issue
Block a user