diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
| commit | 94c5e361fbb229b0cd6853e2102a7d95f1f358b3 (patch) | |
| tree | 3c0f11af9dcb84dac8067a31a6979acd6dd56fbf /tests/common/test_backends.c | |
| parent | 08dc9047098d6d96791024ac7d8f5837633673ef (diff) | |
better public interface and doxygen
Diffstat (limited to 'tests/common/test_backends.c')
| -rw-r--r-- | tests/common/test_backends.c | 90 |
1 files changed, 86 insertions, 4 deletions
diff --git a/tests/common/test_backends.c b/tests/common/test_backends.c index 4c99646..cf5b1f9 100644 --- a/tests/common/test_backends.c +++ b/tests/common/test_backends.c @@ -194,23 +194,105 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct yasl_display_copy(d, YASL_CLIPBOARD, "clipboard text"); yasl_display_paste(d, YASL_CLIPBOARD, w->surface); pump(loop, d, NULL); - bool saw_key = false, saw_paste = false; + bool saw_key = false, saw_paste = false, saw_text = false; struct yasl_input_event event; while (yasl_surface_input_poll(w->surface, &event)) { assert(event.surface == w->surface); if (event.kind == YASL_INPUT_KEY) { assert(event.key.codepoint == 'a'); assert(event.key.shifted == 'A'); - assert(event.key.base == 30); - saw_key = event.key.key == XK_a; + assert(event.key.native_code == key.xkey.keycode); + saw_key = event.key.key == YASL_KEY_A; } if (event.kind == YASL_INPUT_PASTE) { assert(event.paste.len == strlen("clipboard text")); assert(memcmp(event.paste.text, "clipboard text", event.paste.len) == 0); saw_paste = true; } + if (event.kind == YASL_INPUT_TEXT) { + assert(event.text.len == 1 && event.text.text[0] == 'a'); + saw_text = true; + } + } + assert(saw_key && saw_paste && saw_text); + /* Physical identity survives modifier and layout changes, including a + * release whose modifiers differ from its press. */ + key.xkey.state = ShiftMask; + XSendEvent(native, window, False, KeyPressMask, &key); + key.xkey.type = KeyRelease; + key.xkey.state = 0; + XSendEvent(native, window, False, KeyReleaseMask, &key); + XFlush(native); + pump(loop, d, NULL); + int key_count = 0, text_count = 0; + while (yasl_surface_input_poll(w->surface, &event)) { + if (event.kind == YASL_INPUT_KEY) { + assert(event.key.key == YASL_KEY_A); + assert(event.key.action == (key_count ? YASL_KEY_RELEASE : YASL_KEY_PRESS)); + key_count++; + } else if (event.kind == YASL_INPUT_TEXT) { + assert(event.text.len == 1 && event.text.text[0] == 'A'); + text_count++; + } + } + assert(key_count == 2 && text_count == 1); + key.xkey.type = KeyPress; + key.xkey.state = ControlMask; + XSendEvent(native, window, False, KeyPressMask, &key); + XFlush(native); + pump(loop, d, NULL); + assert(yasl_surface_input_poll(w->surface, &event)); + assert(event.kind == YASL_INPUT_KEY && event.key.key == YASL_KEY_A); + assert(event.key.mods & YASL_MOD_CTRL); + assert(!yasl_surface_input_poll(w->surface, &event)); + + int symbols_per_key = 0; + KeySym *saved_symbols = XGetKeyboardMapping(native, key.xkey.keycode, 1, &symbols_per_key); + assert(saved_symbols && symbols_per_key >= 2); + KeySym *changed_symbols = calloc((size_t)symbols_per_key, sizeof(KeySym)); + assert(changed_symbols); + changed_symbols[0] = XK_q; + changed_symbols[1] = XK_Q; + XChangeKeyboardMapping(native, key.xkey.keycode, symbols_per_key, changed_symbols, 1); + XSync(native, False); + pump(loop, d, NULL); /* Consume MappingNotify before translating the key. */ + key.xkey.state = 0; + XSendEvent(native, window, False, KeyPressMask, &key); + XFlush(native); + pump(loop, d, NULL); + saw_key = saw_text = false; + while (yasl_surface_input_poll(w->surface, &event)) { + if (event.kind == YASL_INPUT_KEY) { + assert(event.key.key == YASL_KEY_A && event.key.codepoint == 'q'); + saw_key = true; + } else if (event.kind == YASL_INPUT_TEXT) { + assert(event.text.len == 1 && event.text.text[0] == 'q'); + saw_text = true; + } + } + assert(saw_key && saw_text); + XChangeKeyboardMapping(native, key.xkey.keycode, symbols_per_key, saved_symbols, 1); + free(changed_symbols); + XFree(saved_symbols); + XSync(native, False); + pump(loop, d, NULL); + + for (unsigned button = 4; button <= 7; button++) { + XEvent wheel = {.xbutton = {.type = ButtonPress, .display = native, + .window = window, .root = DefaultRootWindow(native), + .same_screen = True, .button = button}}; + /* Direct delivery exercises the core fallback even with XI2 enabled. */ + XSendEvent(native, window, False, NoEventMask, &wheel); + wheel.xbutton.type = ButtonRelease; + XSendEvent(native, window, False, NoEventMask, &wheel); + XFlush(native); + pump(loop, d, NULL); + assert(yasl_surface_input_poll(w->surface, &event)); + assert(event.kind == YASL_INPUT_MOUSE && event.mouse.kind == YASL_PTR_SCROLL); + assert(event.mouse.scroll.x == (button == 6 ? -1 : button == 7 ? 1 : 0)); + assert(event.mouse.scroll.y == (button == 4 ? -1 : button == 5 ? 1 : 0)); + assert(!yasl_surface_input_poll(w->surface, &event)); } - assert(saw_key && saw_paste); assert(yasl_surface_timing(w->surface).source == YASL_TIMING_SUBMISSION); assert(!(yasl_display_caps(d) & YASL_CAP_FRAME_PACING)); |
