diff --git a/README.md b/README.md index 34e432f..ae1c443 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,13 @@ support. A modern **.NET Desktop Runtime** (such as .NET 8) is a separate produc and does not replace the .NET Framework 4.8 dependency of older applications. Compatibility still depends on each application's Windows APIs. +Room preparation supplies missing US and German keyboard layout descriptions for +native .NET Framework clients that read `InputLanguage.LayoutName`. Existing +descriptions and the selected Mac keyboard layout are preserved. The regression +probe in `winrt/tests/keyboard_layout_names.cs` reads the current and installed +layouts through WinForms; compile it with the room's .NET Framework `csc.exe` and +`/r:System.Windows.Forms.dll`, then run it in the same room. + Native .NET Framework 4.8 and the WinRT bridge belong to the shared baseline and are supplied to every room automatically. There is no separate installation tile and no opt-in room profile. Preparation may take several minutes the first time. diff --git a/scripts/init-prefix.sh b/scripts/init-prefix.sh index f23d43c..3e29007 100755 --- a/scripts/init-prefix.sh +++ b/scripts/init-prefix.sh @@ -236,6 +236,19 @@ fi rm -f "$cursor_query" +# WinForms InputLanguage.LayoutName reads this registry tree, even when Wine +# already provides the keyboard through the Mac driver. A missing tree crashes +# native .NET clients during startup. Keep existing layout descriptions intact. +for layout in '00000409|US' '00000407|German'; do + layout_key='HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\'"${layout%%|*}" + if ! WINMAC_EXPECT_NONZERO=1 "$BIN/virtual" reg query "$layout_key" /v 'Layout Text' >/dev/null 2>&1; then + "$BIN/virtual" reg add "$layout_key" /v 'Layout Text' /t REG_SZ /d "${layout#*|}" /f >/dev/null 2>&1 \ + || fail "Tastaturlayout konnte nicht eingerichtet werden: ${layout%%|*}" + fi + "$BIN/virtual" reg query "$layout_key" /v 'Layout Text' >/dev/null 2>&1 \ + || fail "Tastaturlayout ist nicht lesbar: ${layout%%|*}" +done + # .NET: nur anbieten, wenn eine Datei bereitliegt (kein Zwang, kein Download hier). DOTNET="${WINMAC_DOTNET:-$HOME/Downloads/dotnet-desktop.exe}" DOTNET_FAILED=0 diff --git a/scripts/package-engine.sh b/scripts/package-engine.sh index 863adc1..0d42c4e 100755 --- a/scripts/package-engine.sh +++ b/scripts/package-engine.sh @@ -7,6 +7,13 @@ DEST="${1:?Destination Engine directory required}" [ "$(basename "$DEST")" = Engine ] || { echo "Destination must be named Engine." >&2; exit 1; } RUNTIME="${WINMAC_RUNTIME:-$ROOT/runtime}" [ -x "$RUNTIME/wine-build/bin/wine" ] || { echo "A source-built Wine engine is required for releases." >&2; exit 1; } +# A build-only Wine run leaves the installed runtime unchanged. Check the driver +# being packaged, since the old foreground path can shut down kiosk desktops. +MAC_DRIVER="$RUNTIME/wine-build/lib/wine/x86_64-unix/winemac.so" +nm -u "$MAC_DRIVER" | awk '$NF == "_NtUserSetForegroundWindow" { found = 1 } END { exit !found }' || { + echo "The installed Mac driver lacks the foreground-clearing API. Rebuild and install Wine before packaging (without WINMAC_BUILD_ONLY=1)." >&2 + exit 1 +} [ -f "$RUNTIME/wine-build/share/wine/mono/wine-mono-10.4.1/support/winemono-support.msi" ] || { echo "Wine Mono is missing; run scripts/setup-managed-runtime.sh first." >&2; exit 1; } diff --git a/winrt/tests/README-foreground-desktop-probe.md b/winrt/tests/README-foreground-desktop-probe.md new file mode 100644 index 0000000..bb5d1d3 --- /dev/null +++ b/winrt/tests/README-foreground-desktop-probe.md @@ -0,0 +1,66 @@ +# Foreground and input-desktop probe + +`foreground_desktop_probe.c` is a standalone Win32 probe. It creates only a +visible probe window, an intentionally hidden sentinel, and (for the custom +case) a desktop named `VirtualFocusProbe`. It does not change SEB or another +application's focus policy. + +## Build + +With Zig installed, build the PE executable without a Wine build tree: + +```sh +TEST_DIR=/path/to/Virtual/winrt/tests +ZIG_LOCAL_CACHE_DIR=/tmp/foreground-desktop-probe-zig-cache \ + zig cc -target x86_64-windows-gnu -Wall -Wextra -Werror \ + "$TEST_DIR/foreground_desktop_probe.c" \ + -o /tmp/foreground_desktop_probe.exe -Wl,/subsystem:console +``` + +## Isolated process-exit cases + +Use the `wine` and `wineboot` belonging to the engine under evaluation. Create +a new disposable prefix for each case; never point these commands at a user +room. Initialize each prefix with its engine's `wineboot -u`, then run: + +```sh +WINEPREFIX=/tmp/foreground-probe-graceful WINEARCH=win64 VIRTUAL_STAY_ACTIVE=0 \ + /path/to/engine/bin/wine /tmp/foreground_desktop_probe.exe --lifecycle graceful +WINEPREFIX=/tmp/foreground-probe-abrupt WINEARCH=win64 VIRTUAL_STAY_ACTIVE=0 \ + /path/to/engine/bin/wine /tmp/foreground_desktop_probe.exe --lifecycle abrupt +``` + +The parent must report `custom_seen=1`, `default_restored=1`, the expected child +exit code (`0` graceful, `23` abrupt), and `hidden_visible=0`. The graceful +child destroys its visible window then exits without switching desktops back; +the abrupt child is terminated while its custom desktop is still active. Both +exercise automatic input-desktop restoration. After each run, stop and wait on +only that disposable prefix's wineserver before removing the prefix. +These Win32 assertions do not establish native Mac window visibility. Also +verify that the default desktop's visible window reappears on macOS and that +the intentionally hidden window remains absent. + +## macOS app deactivation observation + +Run one focus case at a time from its own disposable prefix: + +```sh +WINEPREFIX=/tmp/foreground-probe-default WINEARCH=win64 VIRTUAL_STAY_ACTIVE=0 \ + /path/to/engine/bin/wine /tmp/foreground_desktop_probe.exe --focus default 90 +WINEPREFIX=/tmp/foreground-probe-custom WINEARCH=win64 VIRTUAL_STAY_ACTIVE=0 \ + /path/to/engine/bin/wine /tmp/foreground_desktop_probe.exe --focus custom 90 +``` + +While each visible window is active, switch normally to another macOS app once, +wait briefly, then return to the probe. The log records `WM_ACTIVATEAPP`, +`WM_ACTIVATE`, `WM_KILLFOCUS`, the input desktop name, `GetForegroundWindow()`, +and its classification (`zero`, `desktop`, `probe-window`, or +`other-window`). On macOS app deactivation the foreground must become `zero`, +never `desktop`; on return the probe window must be foreground again. +The focus run does not periodically force +foreground after startup, so the user's ordinary deactivation remains real. + +For custom mode, `VirtualFocusProbe` must remain the input desktop through the +macOS app switch and return; this distinguishes app deactivation from a Windows +desktop switch. These are manual UI acceptance cases; merely building or +starting the probe does not establish them. diff --git a/winrt/tests/foreground_desktop_probe.c b/winrt/tests/foreground_desktop_probe.c new file mode 100644 index 0000000..9203c96 --- /dev/null +++ b/winrt/tests/foreground_desktop_probe.c @@ -0,0 +1,294 @@ +/* + * Synthetic Wine foreground/input-desktop probe. + * It creates only its own windows and a uniquely named temporary desktop. + * No application-specific state or focus suppression is involved. + */ +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include + +static const char class_name[] = "VirtualForegroundDesktopProbe"; +static HWND main_window; +static BOOL quit_requested; +static BOOL saw_activateapp_off; +static BOOL saw_activateapp_on; + +static void log_foreground(const char *tag) +{ + HWND foreground = GetForegroundWindow(); + HWND desktop = GetDesktopWindow(); + char kind[16]; + + if (!foreground) strcpy(kind, "zero"); + else if (foreground == desktop) strcpy(kind, "desktop"); + else if (foreground == main_window) strcpy(kind, "probe-window"); + else strcpy(kind, "other-window"); + + printf("SAMPLE %s fg=%p kind=%s desktop=%p input=", tag, foreground, kind, desktop); + { + HDESK input = OpenInputDesktop(0, FALSE, DESKTOP_READOBJECTS); + char name[128] = "unavailable"; + if (input) + { + if (GetUserObjectInformationA(input, UOI_NAME, name, sizeof(name), NULL)) + printf("%s", name); + else printf("unreadable"); + CloseDesktop(input); + } + else printf("unavailable"); + } + printf("\n"); + fflush(stdout); +} + +static LRESULT CALLBACK window_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +{ + switch (message) + { + case WM_ACTIVATEAPP: + if (wparam) saw_activateapp_on = TRUE; + else saw_activateapp_off = TRUE; + printf("EVENT WM_ACTIVATEAPP active=%u hwnd=%p\n", (unsigned)wparam, hwnd); + log_foreground("activateapp"); + fflush(stdout); + return 0; + case WM_ACTIVATE: + printf("EVENT WM_ACTIVATE state=%u hwnd=%p\n", LOWORD(wparam), hwnd); + log_foreground("activate"); + fflush(stdout); + break; + case WM_KILLFOCUS: + printf("EVENT WM_KILLFOCUS hwnd=%p next=%p\n", hwnd, (HWND)wparam); + log_foreground("killfocus"); + fflush(stdout); + break; + case WM_CLOSE: + quit_requested = TRUE; + DestroyWindow(hwnd); + return 0; + case WM_DESTROY: + if (hwnd == main_window) PostQuitMessage(0); + return 0; + } + return DefWindowProcA(hwnd, message, wparam, lparam); +} + +static BOOL register_window_class(void) +{ + WNDCLASSA cls; + ZeroMemory(&cls, sizeof(cls)); + cls.lpfnWndProc = window_proc; + cls.hInstance = GetModuleHandleA(NULL); + cls.hCursor = LoadCursor(NULL, IDC_ARROW); + cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + cls.lpszClassName = class_name; + return RegisterClassA(&cls) != 0; +} + +static BOOL input_desktop_is(const char *expected) +{ + char name[128]; + HDESK input = OpenInputDesktop(0, FALSE, DESKTOP_READOBJECTS); + BOOL matches = FALSE; + if (!input) return FALSE; + if (GetUserObjectInformationA(input, UOI_NAME, name, sizeof(name), NULL)) + matches = lstrcmpiA(name, expected) == 0; + CloseDesktop(input); + return matches; +} + +static int run_child(const char *mode) +{ + HDESK original, temporary; + HWND window; + ULONGLONG deadline; + MSG msg; + + if (strcmp(mode, "graceful") && strcmp(mode, "abrupt")) return 2; + original = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP | DESKTOP_READOBJECTS); + temporary = CreateDesktopA("VirtualFocusProbe", NULL, NULL, 0, GENERIC_ALL, NULL); + if (!original || !temporary || !SetThreadDesktop(temporary)) return 10; + if (!register_window_class()) return 11; + window = CreateWindowA(class_name, "Temporary desktop lifecycle probe", + WS_OVERLAPPEDWINDOW, 100, 100, 460, 240, + NULL, NULL, GetModuleHandleA(NULL), NULL); + if (!window || !SwitchDesktop(temporary)) return 12; + main_window = window; + ShowWindow(window, SW_SHOW); + SetForegroundWindow(window); + UpdateWindow(window); + printf("CHILD mode=%s switched=VirtualFocusProbe window=%p\n", mode, window); + log_foreground("child-start"); + fflush(stdout); + + /* Keep a real Win32 window present while the parent observes the desktop. */ + deadline = GetTickCount64() + 2500; + while (GetTickCount64() < deadline) + { + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + Sleep(10); + } + if (!strcmp(mode, "abrupt")) TerminateProcess(GetCurrentProcess(), 23); + /* Destroy the visible window, then exit without SwitchDesktop. Desktop and + * process-handle teardown must restore Default on the server side. */ + DestroyWindow(window); + puts("CHILD graceful-window-close; exiting without SwitchDesktop"); + fflush(stdout); + return 0; +} + +static int run_lifecycle(const char *mode) +{ + char exe[MAX_PATH], command[MAX_PATH + 64]; + STARTUPINFOA startup; + PROCESS_INFORMATION process; + HWND hidden; + BOOL saw_custom = FALSE, saw_default_after = FALSE; + DWORD child_status = STILL_ACTIVE; + ULONGLONG deadline; + + if (strcmp(mode, "graceful") && strcmp(mode, "abrupt")) return 2; + if (!register_window_class()) return 20; + main_window = CreateWindowA(class_name, "Default desktop lifecycle observer", + WS_OVERLAPPEDWINDOW, 40, 40, 460, 240, + NULL, NULL, GetModuleHandleA(NULL), NULL); + hidden = CreateWindowA(class_name, "Intentionally hidden lifecycle sentinel", + WS_OVERLAPPEDWINDOW, 80, 80, 300, 140, + NULL, NULL, GetModuleHandleA(NULL), NULL); + if (!main_window || !hidden) return 21; + ShowWindow(main_window, SW_SHOW); + UpdateWindow(main_window); + if (!input_desktop_is("Default")) return 22; + printf("PHASE initial input=Default hidden_visible=%u\n", IsWindowVisible(hidden)); + log_foreground("initial"); + + GetModuleFileNameA(NULL, exe, sizeof(exe)); + snprintf(command, sizeof(command), "\"%s\" --child %s", exe, mode); + ZeroMemory(&startup, sizeof(startup)); + ZeroMemory(&process, sizeof(process)); + startup.cb = sizeof(startup); + if (!CreateProcessA(exe, command, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &process)) + return 23; + + deadline = GetTickCount64() + 15000; + while (GetTickCount64() < deadline) + { + MSG msg; + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + if (!saw_custom && input_desktop_is("VirtualFocusProbe")) + { + saw_custom = TRUE; + puts("PHASE temporary input=VirtualFocusProbe"); + log_foreground("temporary"); + } + else if (saw_custom && input_desktop_is("Default")) + { + saw_default_after = TRUE; + puts("PHASE restored input=Default"); + log_foreground("restored"); + break; + } + Sleep(20); + } + WaitForSingleObject(process.hProcess, 3000); + GetExitCodeProcess(process.hProcess, &child_status); + CloseHandle(process.hThread); + CloseHandle(process.hProcess); + + if (IsWindowVisible(hidden)) + { + puts("FAIL hidden sentinel became visible"); + return 24; + } + printf("RESULT mode=%s custom_seen=%u default_restored=%u child_exit=%lu hidden_visible=%u\n", + mode, saw_custom, saw_default_after, (unsigned long)child_status, + IsWindowVisible(hidden)); + DestroyWindow(hidden); + DestroyWindow(main_window); + if (!saw_custom || !saw_default_after || child_status != (!strcmp(mode, "abrupt") ? 23u : 0u)) + return 25; + puts("PASS lifecycle: input desktop returned to Default; hidden sentinel stayed hidden"); + return 0; +} + +static int run_focus(BOOL custom, DWORD seconds) +{ + HDESK original = NULL, temporary = NULL; + ULONGLONG deadline, next_sample; + MSG msg; + unsigned long samples = 0; + + if (custom) + { + original = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP | DESKTOP_READOBJECTS); + temporary = CreateDesktopA("VirtualFocusProbe", NULL, NULL, 0, GENERIC_ALL, NULL); + if (!original || !temporary || !SetThreadDesktop(temporary)) return 30; + if (!SwitchDesktop(temporary)) return 31; + } + if (!register_window_class()) return 32; + main_window = CreateWindowA(class_name, + custom ? "Custom desktop focus probe" : "Default desktop focus probe", + WS_OVERLAPPEDWINDOW, 50, 50, 520, 260, + NULL, NULL, GetModuleHandleA(NULL), NULL); + if (!main_window) return 33; + ShowWindow(main_window, SW_SHOW); + SetForegroundWindow(main_window); + UpdateWindow(main_window); + printf("PHASE focus-start desktop=%s hwnd=%p foreground=%p desktop-hwnd=%p\n", + custom ? "VirtualFocusProbe" : "Default", main_window, + GetForegroundWindow(), GetDesktopWindow()); + puts("Observe one ordinary macOS app switch away and back; no focus is forced after startup."); + log_foreground("focus-start"); + deadline = GetTickCount64() + (ULONGLONG)seconds * 1000; + next_sample = GetTickCount64(); + while (GetTickCount64() < deadline && !quit_requested) + { + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) goto done; + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + if (GetTickCount64() >= next_sample) + { + log_foreground("periodic"); + samples++; + next_sample = GetTickCount64() + 1000; + } + Sleep(20); + } +done: + printf("RESULT focus custom=%u samples=%lu activateapp_off=%u activateapp_on=%u\n", + custom, samples, saw_activateapp_off, saw_activateapp_on); + if (main_window && IsWindow(main_window)) DestroyWindow(main_window); + if (custom && original) SwitchDesktop(original); + if (temporary) CloseDesktop(temporary); + if (original) CloseDesktop(original); + return 0; +} + +int main(int argc, char **argv) +{ + if (argc >= 3 && !strcmp(argv[1], "--child")) return run_child(argv[2]); + if (argc >= 3 && !strcmp(argv[1], "--lifecycle")) return run_lifecycle(argv[2]); + if (argc >= 2 && !strcmp(argv[1], "--focus")) + { + BOOL custom = argc >= 3 && !strcmp(argv[2], "custom"); + DWORD seconds = argc >= 4 ? strtoul(argv[3], NULL, 10) : 60; + if (!seconds || seconds > 3600) return 2; + return run_focus(custom, seconds); + } + fprintf(stderr, "Usage: %s --focus [default|custom] [seconds]\n" + " %s --lifecycle [graceful|abrupt]\n", argv[0], argv[0]); + return 2; +} diff --git a/winrt/tests/keyboard_layout_names.cs b/winrt/tests/keyboard_layout_names.cs new file mode 100644 index 0000000..319162c --- /dev/null +++ b/winrt/tests/keyboard_layout_names.cs @@ -0,0 +1,27 @@ +using System; +using System.Windows.Forms; + +class KeyboardLayoutNames +{ + static int Main() + { + try + { + Check(InputLanguage.CurrentInputLanguage); + foreach (InputLanguage language in InputLanguage.InstalledInputLanguages) + Check(language); + return 0; + } + catch (Exception exception) + { + Console.Error.WriteLine(exception); + return 1; + } + } + + static void Check(InputLanguage language) + { + Console.WriteLine("{0:X}: {1} / {2}", language.Handle.ToInt64(), + language.Culture.Name, language.LayoutName); + } +}