Work started on editor support.

This commit is contained in:
Storm Dragon committed 2026-10-09 15:57:45 -04:00
1 parent 0992ffee0d
commit 6f6d4040c4
9 files changed
+401 -5

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include <windows.h>
static HWND editor, password;
static int step;
static void key(UINT key, BOOL control, BOOL shift) {
BYTE saved[256], state[256];
GetKeyboardState(saved);
CopyMemory(state, saved, sizeof(state));
state[VK_CONTROL] = control ? 0x80 : 0;
state[VK_SHIFT] = shift ? 0x80 : 0;
SetKeyboardState(state);
SendMessageW(editor, WM_KEYDOWN, key, 1);
SetKeyboardState(saved);
}
static LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wp, LPARAM lp) {
if (message == WM_TIMER) {
switch (++step) {
case 1: key(VK_RIGHT, FALSE, FALSE); break;
case 2: key(VK_RIGHT, TRUE, FALSE); break;
case 3: key(VK_DOWN, FALSE, FALSE); break;
case 4: key(VK_HOME, FALSE, FALSE); break;
case 5: key(VK_RIGHT, FALSE, TRUE); break;
case 6: key(VK_RIGHT, FALSE, TRUE); break;
case 7: key(VK_LEFT, FALSE, TRUE); break;
case 8: key(VK_LEFT, FALSE, FALSE); break;
case 9: key(VK_DELETE, FALSE, FALSE); break;
case 10:
key(VK_RIGHT, FALSE, FALSE);
SendMessageW(editor, WM_CHAR, VK_BACK, 1);
break;
case 11: SendMessageW(editor, EM_SETSEL, 0, 5); break;
case 12: SendMessageW(editor, WM_CLEAR, 0, 0); break;
case 13: SetFocus(password); break;
case 14: SendMessageW(password, WM_KEYDOWN, VK_LEFT, 1); break;
case 15: SendMessageW(password, WM_CHAR, VK_BACK, 1); break;
case 16:
SetFocus(editor);
SetWindowTextW(editor, L"\U0001f600 cafe");
SendMessageW(editor, EM_SETSEL, 2, 2);
break;
case 17: key(VK_HOME, FALSE, FALSE); break;
case 18:
SendMessageW(editor, EM_SETREADONLY, TRUE, 0);
SetFocus(password); SetFocus(editor);
break;
case 19: key(VK_DELETE, FALSE, FALSE); break;
default:
if (GetWindowTextLengthW(editor) != 7) ExitProcess(2);
DestroyWindow(window); break;
}
return 0;
}
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.lpszClassName = L"WineAccessEditFixture";
cls.lpfnWndProc = window_proc; RegisterClassW(&cls);
HWND window = CreateWindowW(cls.lpszClassName, L"Wine editor fixture", WS_OVERLAPPEDWINDOW,
120, 120, 500, 300, NULL, NULL, instance, NULL);
editor = CreateWindowW(L"Edit", L"alpha beta\r\nsecond line",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_MULTILINE | ES_AUTOVSCROLL,
10, 10, 450, 150, window, NULL, instance, NULL);
password = CreateWindowW(L"Edit", L"private-password-fixture",
WS_CHILD | WS_VISIBLE | ES_PASSWORD, 10, 180, 300, 30,
window, NULL, instance, NULL);
ShowWindow(window, SW_SHOW); SetForegroundWindow(window); SetFocus(editor);
SendMessageW(editor, EM_SETSEL, 0, 0);
SetTimer(window, 1, 350, NULL);
MSG message;
while (GetMessageW(&message, NULL, 0, 0) > 0) {
TranslateMessage(&message); DispatchMessageW(&message);
}
return 0;
}
+20 -2
View File
@@ -16,11 +16,13 @@ from gi.repository import Gio, GLib
parser = argparse.ArgumentParser()
parser.add_argument("--build-dir", default="build")
parser.add_argument("--session", action="store_true")
parser.add_argument("--fixture", choices=("menu", "edit"), default="menu")
args = parser.parse_args()
build = Path(args.build_dir).resolve()
if not args.session:
sys.exit(subprocess.call(["dbus-run-session", "--", sys.executable,
__file__, "--session", "--build-dir", str(build)]))
__file__, "--session", "--build-dir", str(build),
"--fixture", args.fixture]))
interface = "org.stormux.Cthulhu1.Service"
object_path = "/org/stormux/Cthulhu1/Service"
@@ -47,7 +49,7 @@ with tempfile.TemporaryDirectory(prefix="wine-access-menus-") as temporary:
WINEDLLOVERRIDES="mscoree,mshtml=", CTHULHU_WINE_ACCESS_MANAGED="1")
fixture = Path(temporary) / "menu-fixture.exe"
subprocess.run(["x86_64-w64-mingw32-gcc", "-Wall", "-Wextra", "-mwindows",
"-o", str(fixture), str(Path(__file__).with_name("menu_fixture.c")),
"-o", str(fixture), str(Path(__file__).with_name(args.fixture + "_fixture.c")),
"-luser32"], check=True)
helper = None
app = None
@@ -72,6 +74,22 @@ with tempfile.TemporaryDirectory(prefix="wine-access-menus-") as temporary:
while GLib.MainContext.default().iteration(False):
pass
time.sleep(0.01)
if args.fixture == "edit":
text_events = [e for e in events if e[0].endswith(":text")]
for event in text_events:
print(event[2:7])
spoken = [e[2] for e in text_events]
for expected in ("l", "beta", "second line", "s selected", "e selected",
"e unselected", "s unselected", "s deleted", "e deleted",
"alpha selected", "alpha deleted", "😀"):
assert expected in spoken, f"missing editor feedback: {expected!r}"
assert any(e[3] == "edit" and e[4] == "alpha beta" for e in text_events), "initial line missing"
assert any(e[3] == "read only edit" for e in text_events), "read-only focus missing"
assert any(e[6] == "password" for e in text_events), "password role missing"
assert not any("private-password-fixture" in str(e) for e in events), "password leaked"
assert "😀 deleted" not in spoken, "read-only control reported deletion"
print("PASS: editor focus, characters, words, lines, selection, deletion, Unicode, passwords, and read-only controls")
sys.exit(0)
menus = [event for event in events if ":menu:" in event[0]]
for event in menus:
print(event[2:7])