From 76073fe5fad8799e5850805f2f090af2cb62c741 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 23:41:31 +0300 Subject: Simplify the public event and CPU API Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 --- tests/cocoa/test_cursor.m | 24 +++---- tests/cocoa/test_keyboard.m | 76 +++++++++++++-------- tests/cocoa/test_native.c | 70 ++++++++++---------- tests/cocoa/test_ownership.m | 154 +++++++++++++++++++++++++++---------------- tests/cocoa/test_tablet.m | 111 +++++++++++++++++++++---------- 5 files changed, 269 insertions(+), 166 deletions(-) (limited to 'tests/cocoa') diff --git a/tests/cocoa/test_cursor.m b/tests/cocoa/test_cursor.m index 4054d59..4c961df 100644 --- a/tests/cocoa/test_cursor.m +++ b/tests/cocoa/test_cursor.m @@ -1,5 +1,5 @@ #import -#include +#include #include static void assert_transparent(NSCursor *cursor) @@ -15,18 +15,18 @@ static void assert_transparent(NSCursor *cursor) int main(void) { @autoreleasepool { - struct yasl_display *display = yasl_display_open(NULL, NULL); + struct yasl_private_display *display = yasl_private_display_open(NULL, NULL); assert(display); - struct yasl_window_spec spec = {.title = "Cursor test", .size = {320, 240}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); + struct yasl_private_window_spec spec = {.title = "Cursor test", .size = {320, 240}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(display, &spec); assert(surface); - NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); + NSWindow *window = (NSWindow *)yasl_private_surface_get_native_handle(surface); NSView *view = window.contentView; NSEvent *cursor = [NSEvent enterExitEventWithType:NSEventTypeCursorUpdate location:NSMakePoint(100, 120) modifierFlags:0 timestamp:0 windowNumber:window.windowNumber context:nil eventNumber:0 trackingNumber:0 userData:NULL]; assert(cursor); - yasl_surface_set_cursor(surface, YASL_CURSOR_HIDDEN); + yasl_private_surface_set_cursor(surface, YASL_PRIVATE_CURSOR_HIDDEN); [view cursorUpdate:cursor]; NSCursor *hidden = [NSCursor currentCursor]; assert_transparent(hidden); @@ -37,21 +37,21 @@ int main(void) [view mouseMoved:motion]; [view cursorUpdate:cursor]; assert([NSCursor currentCursor] == hidden); - struct yasl_event event; + struct yasl_private_event event; bool moved = false; - while (yasl_surface_poll_event(surface, &event)) - if (event.type == YASL_EVENT_POINTER_MOTION) + while (yasl_private_surface_poll_event(surface, &event)) + if (event.type == YASL_PRIVATE_EVENT_POINTER_MOTION) moved = true; assert(moved); [[NSCursor arrowCursor] set]; /* Simulate leaving and re-entering. */ [view cursorUpdate:cursor]; assert([NSCursor currentCursor] == hidden); - yasl_surface_set_cursor(surface, YASL_CURSOR_ARROW); + yasl_private_surface_set_cursor(surface, YASL_PRIVATE_CURSOR_ARROW); [view cursorUpdate:cursor]; assert([NSCursor currentCursor] == [NSCursor arrowCursor]); - yasl_surface_destroy(surface); - yasl_display_close(display); + yasl_private_surface_destroy(surface); + yasl_private_display_close(display); } return 0; } diff --git a/tests/cocoa/test_keyboard.m b/tests/cocoa/test_keyboard.m index f93a745..a41011c 100644 --- a/tests/cocoa/test_keyboard.m +++ b/tests/cocoa/test_keyboard.m @@ -1,5 +1,6 @@ #import -#include +#include +#include #include #include #include @@ -31,32 +32,40 @@ } @end -static struct yasl_event next(struct yasl_surface *surface, enum yasl_event_type type) +static struct yasl_private_event next(struct yasl_surface *surface, enum yasl_private_event_type type) { - struct yasl_event event; - assert(yasl_surface_poll_event(surface, &event)); + struct yasl_private_event event; + assert(yasl_private_surface_poll_event(surface, &event)); assert(event.type == type && event.surface == surface); return event; } static void empty(struct yasl_surface *surface) { - struct yasl_event event; - assert(!yasl_surface_poll_event(surface, &event)); + struct yasl_private_event event; + assert(!yasl_private_surface_poll_event(surface, &event)); } int main(void) { @autoreleasepool { - struct yasl_display *display = yasl_display_open(NULL, NULL); + struct yasl_private_display *display = yasl_private_display_open(NULL, NULL); assert(display); - struct yasl_window_spec spec = {.title = "Keyboard test", .size = {320, 240}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); + struct yasl_private_window_spec spec = {.title = "Keyboard test", .size = {320, 240}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(display, &spec); assert(surface); - NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); + surface->text_input_active = true; + surface->text_surrounding = strdup("A😀B"); + surface->text_length = strlen(surface->text_surrounding); + surface->text_begin = 1; + surface->text_end = 5; + surface->text_revision = 7; + surface->text_generation = 3; + assert(display->ops->surface_update_text_input(surface)); + NSWindow *window = (NSWindow *)yasl_private_surface_get_native_handle(surface); NSView *view = (id)window.contentView; - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) {} + struct yasl_private_event event; + while (yasl_private_surface_poll_event(surface, &event)) {} InputSample *sample = [InputSample new]; NSEvent *native = (NSEvent *)sample; @@ -65,7 +74,7 @@ int main(void) sample.label = @"q"; sample.shiftedLabel = @"Q"; [view keyUp:native]; - event = next(surface, YASL_EVENT_KEY); + event = next(surface, YASL_PRIVATE_EVENT_KEY); assert(event.key.key == YASL_KEY_A && event.key.native_code == 0); assert(event.key.action == YASL_KEY_RELEASE); assert(event.key.codepoint == 'q' && event.key.shifted == 'Q'); @@ -73,29 +82,31 @@ int main(void) sample.label = @"😀"; /* One scalar, two UTF-16 units. */ sample.shiftedLabel = @"ab"; [view keyUp:native]; - event = next(surface, YASL_EVENT_KEY); + event = next(surface, YASL_PRIVATE_EVENT_KEY); assert(event.key.codepoint == 0x1f600 && event.key.shifted == 0); sample.type = NSEventTypeFlagsChanged; sample.keyCode = 56; /* Left Shift. */ sample.modifierFlags = NSEventModifierFlagShift | 0x0002; [view flagsChanged:native]; - event = next(surface, YASL_EVENT_KEY); + event = next(surface, YASL_PRIVATE_EVENT_KEY); assert(event.key.key == YASL_KEY_LEFT_SHIFT && event.key.action == YASL_KEY_PRESS); - assert(event.key.mods == YASL_MOD_SHIFT && !event.key.codepoint && !event.key.shifted); + assert(event.key.mods == YASL_PRIVATE_MOD_SHIFT && !event.key.codepoint && !event.key.shifted); sample.modifierFlags = 0; [view flagsChanged:native]; - assert(next(surface, YASL_EVENT_KEY).key.action == YASL_KEY_RELEASE); + assert(next(surface, YASL_PRIVATE_EVENT_KEY).key.action == YASL_KEY_RELEASE); /* Native text services own preedit and commits. Marked text is not an * insertion, and commits retain all UTF-8 bytes, including non-BMP. */ [view setMarkedText:@"é" selectedRange:NSMakeRange(1, 0) - replacementRange:NSMakeRange(NSNotFound, 0)]; - assert(strcmp(yasl_surface_ime_preedit(surface), "é") == 0); + replacementRange:NSMakeRange(1, 2)]; + assert(strcmp(yasl_private_surface_ime_preedit(surface), "é") == 0); empty(surface); [view insertText:@"😀é" replacementRange:NSMakeRange(NSNotFound, 0)]; - event = next(surface, YASL_EVENT_TEXT); - assert(event.text.len == strlen("😀é") && strcmp(event.text.data, "😀é") == 0); - assert(!yasl_surface_ime_preedit(surface)); + event = next(surface, YASL_PRIVATE_EVENT_TEXT_EDIT); + assert(event.text_edit.len == strlen("😀é") && strcmp(event.text_edit.data, "😀é") == 0); + assert(event.text_edit.begin == 1 && event.text_edit.end == 5); + assert(event.text_edit.revision == 7 && event.text_edit.generation == 3); + assert(!yasl_private_surface_ime_preedit(surface)); empty(surface); /* Exercise the keyDown -> interpretKeyEvents -> insertText route with @@ -104,9 +115,16 @@ int main(void) modifierFlags:0 timestamp:0 windowNumber:window.windowNumber context:nil characters:@"a" charactersIgnoringModifiers:@"a" isARepeat:NO keyCode:0]; [view keyDown:press]; - assert(next(surface, YASL_EVENT_KEY).key.key == YASL_KEY_A); - event = next(surface, YASL_EVENT_TEXT); - assert(event.text.len == 1 && event.text.data[0] == 'a'); + assert(next(surface, YASL_PRIVATE_EVENT_KEY).key.key == YASL_KEY_A); + event = next(surface, YASL_PRIVATE_EVENT_TEXT_EDIT); + assert(event.text_edit.len == 1 && event.text_edit.data[0] == 'a'); + assert(event.text_edit.begin == 1 && event.text_edit.end == 5); + empty(surface); + + surface->text_end = 1; + [view doCommandBySelector:@selector(deleteBackward)]; + event = next(surface, YASL_PRIVATE_EVENT_TEXT_EDIT); + assert(event.text_edit.len == 0 && event.text_edit.begin == 0 && event.text_edit.end == 1); empty(surface); sample.type = NSEventTypeScrollWheel; @@ -114,20 +132,20 @@ int main(void) sample.scrollingDeltaX = -2.5; sample.scrollingDeltaY = 1.25; [view scrollWheel:native]; - event = next(surface, YASL_EVENT_POINTER_SCROLL); + event = next(surface, YASL_PRIVATE_EVENT_POINTER_SCROLL); assert(event.pointer.scroll.x == 0.25 && event.pointer.scroll.y == -0.125); sample.hasPreciseScrollingDeltas = NO; sample.scrollingDeltaX = 1; sample.scrollingDeltaY = -1; [view scrollWheel:native]; - event = next(surface, YASL_EVENT_POINTER_SCROLL); + event = next(surface, YASL_PRIVATE_EVENT_POINTER_SCROLL); assert(event.pointer.scroll.x == -1 && event.pointer.scroll.y == 1); sample.scrollingDeltaX = NAN; [view scrollWheel:native]; empty(surface); [sample release]; - yasl_surface_destroy(surface); - yasl_display_close(display); + yasl_private_surface_destroy(surface); + yasl_private_display_close(display); } return 0; } diff --git a/tests/cocoa/test_native.c b/tests/cocoa/test_native.c index 674513d..9b8f8fa 100644 --- a/tests/cocoa/test_native.c +++ b/tests/cocoa/test_native.c @@ -1,77 +1,77 @@ #define _POSIX_C_SOURCE 200809L -#include "yasl/native.h" -#include "yasl/loop.h" -#include "yasl/yasl.h" +#include "common/private_native.h" +#include "common/private_loop.h" +#include "common/types.h" #include #include struct state { - struct yasl_display *display; + struct yasl_private_display *display; struct yasl_surface *surface; unsigned draws; }; -static void draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud) +static void draw(struct yasl_surface *surface, struct yasl_private_frame *frame, void *ud) { struct state *state = ud; assert(surface == state->surface && frame->surface == surface); - assert(yasl_surface_display(surface) == state->display); + assert(yasl_private_surface_display(surface) == state->display); assert(frame->target.pixels); - struct yasl_native_frame native; - assert(yasl_surface_get_native_frame(surface, &frame->target, &native)); + struct yasl_private_native_frame native; + assert(yasl_private_surface_get_native_frame(surface, &frame->target, &native)); assert(native.drawable); - struct yasl_vector2i size = yasl_surface_geometry(surface).size; + struct yasl_private_vector2i size = yasl_private_surface_geometry(surface).size; assert(size.x == frame->target.size.x && size.y == frame->target.size.y); for (int i = 0; i < size.x * size.y; i++) frame->target.pixels[i] = 0xff4080c0; - struct yasl_damage_list damage = {.n = YASL_DAMAGE_MAX + 1}; - assert(!yasl_surface_present(surface, &frame->target, &damage)); + struct yasl_private_damage_list damage = {.n = YASL_PRIVATE_DAMAGE_MAX + 1}; + assert(!yasl_private_surface_present(surface, &frame->target, &damage)); damage.n = -1; - struct yasl_framebuffer invalid = frame->target; + struct yasl_private_framebuffer invalid = frame->target; invalid.size.x++; - assert(!yasl_surface_present(surface, &invalid, &damage)); + assert(!yasl_private_surface_present(surface, &invalid, &damage)); invalid = frame->target; invalid.generation--; - assert(!yasl_surface_present(surface, &invalid, &damage)); - assert(!yasl_surface_present(surface, &frame->target, NULL)); - assert(yasl_surface_present(surface, &frame->target, &damage)); - assert(!yasl_surface_get_native_frame(surface, &frame->target, &native)); - assert(!yasl_surface_present(surface, &frame->target, &damage)); + assert(!yasl_private_surface_present(surface, &invalid, &damage)); + assert(!yasl_private_surface_present(surface, &frame->target, NULL)); + assert(yasl_private_surface_present(surface, &frame->target, &damage)); + assert(!yasl_private_surface_get_native_frame(surface, &frame->target, &native)); + assert(!yasl_private_surface_present(surface, &frame->target, &damage)); state->draws++; - yasl_surface_destroy(surface); + yasl_private_surface_destroy(surface); state->surface = NULL; } -static void test_window(enum yasl_backend request, bool null_spec) +static void test_window(enum yasl_private_backend request, bool null_spec) { - struct yasl_display_spec spec = {.backend = request}; - struct state state = {.display = yasl_display_open(NULL, null_spec ? NULL : &spec)}; + struct yasl_private_display_spec spec = {.backend = request}; + struct state state = {.display = yasl_private_display_open(NULL, null_spec ? NULL : &spec)}; assert(state.display); - assert(yasl_display_backend(state.display) == YASL_BACKEND_COCOA); - struct yasl_window_cbs callbacks = {.draw = draw}; - struct yasl_window_spec surface = { + assert(yasl_private_display_backend(state.display) == YASL_PRIVATE_BACKEND_COCOA); + struct yasl_private_window_cbs callbacks = {.draw = draw}; + struct yasl_private_window_spec surface = { .title = "Native backend test", .size = {160, 100}, .cbs = &callbacks, .ud = &state, }; - state.surface = yasl_surface_create_toplevel(state.display, &surface); + state.surface = yasl_private_surface_create_toplevel(state.display, &surface); assert(state.surface); assert(!state.draws); callbacks.draw = NULL; - yasl_surface_schedule_redraw(state.surface); - uint64_t deadline = yasl_loop_now_ns() + 3000000000ull; - while (!state.draws && yasl_loop_now_ns() < deadline) { - yasl_display_dispatch(state.display, 0); - yasl_display_flush(state.display); + yasl_private_surface_schedule_redraw(state.surface); + uint64_t deadline = yasl_private_loop_now_ns() + 3000000000ull; + while (!state.draws && yasl_private_loop_now_ns() < deadline) { + yasl_private_display_dispatch(state.display, 0); + yasl_private_display_flush(state.display); nanosleep(&(struct timespec){.tv_nsec = 1000000}, NULL); } assert(state.draws == 1 && !state.surface); - yasl_display_close(state.display); + yasl_private_display_close(state.display); } int main(void) { - test_window(YASL_BACKEND_AUTO, true); - test_window(YASL_BACKEND_AUTO, false); - test_window(YASL_BACKEND_COCOA, false); + test_window(YASL_PRIVATE_BACKEND_AUTO, true); + test_window(YASL_PRIVATE_BACKEND_AUTO, false); + test_window(YASL_PRIVATE_BACKEND_COCOA, false); return 0; } diff --git a/tests/cocoa/test_ownership.m b/tests/cocoa/test_ownership.m index 6d69907..4efd164 100644 --- a/tests/cocoa/test_ownership.m +++ b/tests/cocoa/test_ownership.m @@ -1,7 +1,9 @@ -#include "yasl/native.h" -#include "yasl/native/cocoa.h" +#include "common/private_native.h" +#include "common/private_native_cocoa.h" +#include "common/backend.h" #import -#include "yasl/yasl.h" +#import +#include "common/types.h" #include #include #include @@ -9,60 +11,98 @@ int main(void) { - struct yasl_display *d = yasl_display_open(NULL, NULL); + struct yasl_private_display *d = yasl_private_display_open(NULL, NULL); assert(d); - struct yasl_window_spec spec = {.title = "Ownership test", .size = {160, 100}}; - struct yasl_surface *s = yasl_surface_create_toplevel(d, &spec); + assert(yasl_private_display_caps(d) & YASL_PRIVATE_CAP_TEXT_INPUT); + struct yasl_private_window_spec spec = {.title = "Ownership test", .size = {160, 100}}; + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &spec); assert(s); - assert(yasl_display_get_native_handle(d) == (void *)NSApp); - assert(yasl_cocoa_display_get_application(d) == NSApp); - NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(s); - assert(yasl_cocoa_surface_get_window(s) == window); - assert(yasl_cocoa_surface_get_view(s) == window.contentView); + assert(yasl_private_display_get_native_handle(d) == (void *)NSApp); + assert(yasl_private_cocoa_display_get_application(d) == NSApp); + NSWindow *window = (NSWindow *)yasl_private_surface_get_native_handle(s); + assert(yasl_private_cocoa_surface_get_window(s) == window); + assert(yasl_private_cocoa_surface_get_view(s) == window.contentView); assert([window isKindOfClass:[NSWindow class]] && window.contentView); - struct yasl_event event; - while (yasl_display_poll_event(d, &event)) {} + struct yasl_private_event event; + while (yasl_private_display_poll_event(d, &event)) {} - assert(yasl_surface_set_size(s, (struct yasl_vector2i){180, 110})); - assert(yasl_surface_set_fullscreen(s, false)); - assert(yasl_surface_set_maximized(s, false)); - assert(!yasl_surface_set_size(s, (struct yasl_vector2i){0, 100})); + struct yasl_private_window_spec gpu_spec = { + .flags = YASL_PRIVATE_SURFACE_HIDDEN | YASL_PRIVATE_SURFACE_UNDECORATED | + YASL_PRIVATE_SURFACE_FIXED_SIZE, + .external_gpu = true, + .title = "External GPU test", + .size = {160, 100}, + }; + struct yasl_surface *gpu = yasl_private_surface_create_toplevel(d, &gpu_spec); + assert(gpu && gpu->presenter == YASL_PRIVATE_PRESENTER_NONE); + CAMetalLayer *metal = (CAMetalLayer *)d->ops->surface_get_metal_layer(gpu); + assert(metal && [metal isKindOfClass:[CAMetalLayer class]] && !metal.device); + NSWindow *hidden = (NSWindow *)yasl_private_surface_get_native_handle(gpu); + assert(!hidden.isVisible && hidden.styleMask == NSWindowStyleMaskBorderless); + yasl_private_surface_destroy(gpu); + + struct yasl_surface *gl = d->ops->surface_create_gl(d, &gpu_spec, NULL, NULL); + if (gl) { + assert(gl->presenter == YASL_PRIVATE_PRESENTER_GL); + assert(d->ops->gl_make_current(d, gl)); + assert(d->ops->gl_get_proc_address(d, "glClear") != NULL); + assert(d->ops->gl_swap_interval(d, gl, 1)); + assert(d->ops->gl_swap_buffers(d, gl)); + assert(d->ops->gl_make_current(d, NULL)); + d->ops->surface_destroy(gl); + } + + assert(yasl_private_surface_set_size(s, (struct yasl_private_vector2i){180, 110})); + assert(yasl_private_surface_set_fullscreen(s, false)); + assert(yasl_private_surface_set_maximized(s, false)); + assert(!yasl_private_surface_set_size(s, (struct yasl_private_vector2i){0, 100})); assert(errno == EINVAL); - struct yasl_popup_spec popup_spec = { + struct yasl_private_popup_spec popup_spec = { + .positioner_explicit = true, + .anchor_edges = 4, .gravity = 3, .constraints = 63, .size = {80, 40}, .anchor = {10, 10, 2, 2}, }; - struct yasl_surface *popup = yasl_surface_create_popup(s, &popup_spec); + struct yasl_surface *popup = yasl_private_surface_create_popup(s, &popup_spec); assert(popup); - assert(!yasl_surface_set_size(popup, (struct yasl_vector2i){80, 40})); + popup_spec.anchor_edges = 8; + popup_spec.gravity = 5; + assert(yasl_private_surface_popup_reposition(popup, &popup_spec)); + assert(!yasl_private_surface_set_size(popup, (struct yasl_private_vector2i){80, 40})); assert(errno == EINVAL); - assert(!yasl_surface_set_fullscreen(popup, true) && errno == EINVAL); - assert(!yasl_surface_set_maximized(popup, true) && errno == EINVAL); - assert(!yasl_surface_minimize(popup) && errno == EINVAL); - yasl_surface_destroy(popup); - while (yasl_display_poll_event(d, &event)) {} + assert(!yasl_private_surface_set_fullscreen(popup, true) && errno == EINVAL); + assert(!yasl_private_surface_set_maximized(popup, true) && errno == EINVAL); + assert(!yasl_private_surface_minimize(popup) && errno == EINVAL); + yasl_private_surface_destroy(popup); + while (yasl_private_display_poll_event(d, &event)) {} - id text_input = (id)yasl_cocoa_surface_get_view(s); + s->text_input_active = true; + s->text_surrounding = strdup("é漢"); + s->text_length = strlen(s->text_surrounding); + s->text_begin = 0; + s->text_end = s->text_length; + assert(d->ops->surface_update_text_input(s)); + id text_input = (id)yasl_private_cocoa_surface_get_view(s); [text_input setMarkedText:@"é漢" selectedRange:NSMakeRange(1, 1) replacementRange:NSMakeRange(NSNotFound, 0)]; - assert(strcmp(yasl_surface_ime_preedit(s), "é漢") == 0); + assert(strcmp(yasl_private_surface_ime_preedit(s), "é漢") == 0); [text_input unmarkText]; - assert(yasl_surface_ime_preedit(s) == NULL); - assert(yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_COMPOSITION && event.composition.active); + assert(yasl_private_surface_ime_preedit(s) == NULL); + assert(yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_COMPOSITION && event.composition.active); assert(strcmp(event.composition.data, "é漢") == 0); assert(event.composition.begin == 2 && event.composition.end == 5); - assert(yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_COMPOSITION && !event.composition.active); + assert(yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_COMPOSITION && !event.composition.active); assert(event.composition.begin == -1 && event.composition.end == -1); - while (yasl_display_poll_event(d, &event)) {} + while (yasl_private_display_poll_event(d, &event)) {} uint64_t request_ids[600]; @autoreleasepool { for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); - assert(yasl_clipboard_set(d, YASL_CLIPBOARD, text)); - request_ids[i] = yasl_clipboard_request(s, YASL_CLIPBOARD); + assert(yasl_private_clipboard_set(d, YASL_PRIVATE_CLIPBOARD, text)); + request_ids[i] = yasl_private_clipboard_request(s, YASL_PRIVATE_CLIPBOARD); assert(request_ids[i] != 0); memset(text, 'x', sizeof(text)); } @@ -71,32 +111,32 @@ int main(void) for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); - assert(yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == request_ids[i]); - assert(event.paste.status == YASL_TRANSFER_OK && strcmp(event.paste.data, text) == 0); + assert(yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == request_ids[i]); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_OK && strcmp(event.paste.data, text) == 0); } const char *last = event.paste.data; - assert(!yasl_display_poll_event(d, &event)); - @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, "new selection"); } + assert(!yasl_private_display_poll_event(d, &event)); + @autoreleasepool { yasl_private_display_copy(d, YASL_PRIVATE_CLIPBOARD, "new selection"); } assert(strcmp(last, "paste-599") == 0); - assert(!yasl_clipboard_set(d, YASL_CLIPBOARD, "\xc3")); + assert(!yasl_private_clipboard_set(d, YASL_PRIVATE_CLIPBOARD, "\xc3")); assert(errno == EILSEQ); - assert(yasl_clipboard_set(d, YASL_CLIPBOARD, "")); - uint64_t empty_id = yasl_clipboard_request(s, YASL_CLIPBOARD); - assert(empty_id && yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == empty_id); - assert(event.paste.status == YASL_TRANSFER_OK && !event.paste.len && !event.paste.data[0]); + assert(yasl_private_clipboard_set(d, YASL_PRIVATE_CLIPBOARD, "")); + uint64_t empty_id = yasl_private_clipboard_request(s, YASL_PRIVATE_CLIPBOARD); + assert(empty_id && yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == empty_id); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_OK && !event.paste.len && !event.paste.data[0]); [NSPasteboard.generalPasteboard clearContents]; - uint64_t unavailable_id = yasl_clipboard_request(s, YASL_CLIPBOARD); - assert(unavailable_id && yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == unavailable_id); - assert(event.paste.status == YASL_TRANSFER_UNAVAILABLE && !event.paste.len); - yasl_display_copy(d, YASL_CLIPBOARD, "legacy paste"); - yasl_display_paste(d, YASL_CLIPBOARD, s); - assert(yasl_display_poll_event(d, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == 0); - assert(event.paste.status == YASL_TRANSFER_OK && strcmp(event.text.data, "legacy paste") == 0); - yasl_surface_destroy(s); - yasl_display_close(d); + uint64_t unavailable_id = yasl_private_clipboard_request(s, YASL_PRIVATE_CLIPBOARD); + assert(unavailable_id && yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == unavailable_id); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_UNAVAILABLE && !event.paste.len); + yasl_private_display_copy(d, YASL_PRIVATE_CLIPBOARD, "legacy paste"); + yasl_private_display_paste(d, YASL_PRIVATE_CLIPBOARD, s); + assert(yasl_private_display_poll_event(d, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == 0); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_OK && strcmp(event.text.data, "legacy paste") == 0); + yasl_private_surface_destroy(s); + yasl_private_display_close(d); return 0; } diff --git a/tests/cocoa/test_tablet.m b/tests/cocoa/test_tablet.m index 715a66e..8eb63d5 100644 --- a/tests/cocoa/test_tablet.m +++ b/tests/cocoa/test_tablet.m @@ -1,5 +1,5 @@ #import -#include +#include #include /* A strict event double catches querying tablet-only properties on ordinary @@ -15,6 +15,10 @@ @property NSPointingDeviceType tool; @property float samplePressure; @property NSPoint sampleTilt; +@property double sampleRotation; +@property double sampleTangential; +@property NSInteger sampleDeviceID; +@property NSInteger sampleToolID; @end @implementation TabletSample @@ -33,70 +37,106 @@ assert(self.type == NSEventTypeTabletProximity || self.subtype == NSEventSubtypeTabletProximity); return self.tool; } +- (double)rotation { return self.sampleRotation; } +- (double)tangentialPressure { return self.sampleTangential; } +- (NSInteger)pointingDeviceID { return self.sampleDeviceID; } +- (NSInteger)pointingDeviceSerialNumber { return self.sampleToolID; } @end -static struct yasl_event next(struct yasl_surface *surface) +static struct yasl_private_event next(struct yasl_surface *surface, enum yasl_private_event_type type) { - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) - return event; - assert(!"Expected a pointer event"); - return (struct yasl_event){0}; + struct yasl_private_event event; + assert(yasl_private_surface_poll_event(surface, &event)); + assert(event.type == type); + return event; } int main(void) { @autoreleasepool { - struct yasl_display *display = yasl_display_open(NULL, NULL); - assert(display && (yasl_display_caps(display) & YASL_CAP_TABLET)); - struct yasl_window_spec spec = {.title = "Tablet test", .size = {320, 240}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); + struct yasl_private_display *display = yasl_private_display_open(NULL, NULL); + assert(display && (yasl_private_display_caps(display) & YASL_PRIVATE_CAP_TABLET)); + struct yasl_private_window_spec spec = {.title = "Tablet test", .size = {320, 240}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(display, &spec); assert(surface); - NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); + NSWindow *window = (NSWindow *)yasl_private_surface_get_native_handle(surface); NSView *view = window.contentView; - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) {} + struct yasl_private_event event; + while (yasl_private_surface_poll_event(surface, &event)) {} TabletSample *sample = [TabletSample new]; NSEvent *native = (NSEvent *)sample; sample.type = NSEventTypeTabletProximity; sample.enteringProximity = YES; sample.tool = NSPointingDeviceTypePen; + sample.sampleDeviceID = 17; + sample.sampleToolID = 29; [view tabletProximity:native]; sample.type = NSEventTypeMouseMoved; sample.subtype = NSEventSubtypeTabletPoint; sample.locationInWindow = NSMakePoint(100, 120); sample.sampleTilt = NSMakePoint(-0.5, 0.5); + sample.sampleRotation = 37.5; + sample.sampleTangential = -0.25; [view mouseMoved:native]; - struct yasl_event ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_MOTION && !ev.pointer.pen.pressure); + struct yasl_private_event pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_ENTER && pen.pen.device_id == 17 && pen.pen.tool_id == 29); + struct yasl_private_event ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN && ev.type == YASL_PRIVATE_EVENT_POINTER_MOTION && !ev.pointer.pen.pressure); assert(ev.pointer.pen.tilt_x == -45 && ev.pointer.pen.tilt_y == -45); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_MOVE && pen.pen.device_id == 17 && pen.pen.tool_id == 29); + assert((pen.pen.axes_valid & (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)) == + (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)); + assert(pen.pen.rotation == 37.5 && pen.pen.tangential == -0.25); + assert((pen.pen.axes_valid & (YASL_PRIVATE_PEN_ROTATION | YASL_PRIVATE_PEN_TANGENTIAL)) == + (YASL_PRIVATE_PEN_ROTATION | YASL_PRIVATE_PEN_TANGENTIAL)); sample.type = NSEventTypeLeftMouseDown; sample.samplePressure = 0.5; + sample.buttonMask = NSEventButtonMaskPenTip; [view mouseDown:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_DOWN); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN && ev.type == YASL_PRIVATE_EVENT_POINTER_DOWN && ev.pointer.button == YASL_PRIVATE_BUTTON_PRIMARY); assert(ev.pointer.pen.pressure == 32767); - struct yasl_vector2i position = ev.pointer.pos; + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_DOWN && pen.pen.in_contact && pen.pen.pressure == 0.5); + assert(pen.pen.buttons == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY)); + assert(pen.pen.changed_button == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY)); + struct yasl_private_vector2i position = ev.pointer.pos; /* Native tablet events cover stationary pressure changes. */ sample.type = NSEventTypeTabletPoint; sample.subtype = NSEventSubtypeMouseEvent; sample.buttonMask = NSEventButtonMaskPenTip; sample.samplePressure = 1.5; [view tabletPoint:native]; - ev = next(surface); - assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); assert(ev.pointer.pos.x == position.x && ev.pointer.pos.y == position.y); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_MOVE && pen.pen.pressure == 1.0); + sample.buttonMask |= NSEventButtonMaskPenLowerSide; + [view tabletPoint:native]; + next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_BUTTON); + assert(pen.pen.buttons == (YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY) | + YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY))); + assert(pen.pen.changed_button == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY)); + sample.buttonMask = NSEventButtonMaskPenTip; sample.samplePressure = 0; /* Zero does not release a held tip button. */ [view tabletPoint:native]; - assert(next(surface).type == YASL_EVENT_POINTER_MOTION); + assert(next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION).type == YASL_PRIVATE_EVENT_POINTER_MOTION); + next(surface, YASL_PRIVATE_EVENT_PEN); sample.buttonMask = 0; [view tabletPoint:native]; - ev = next(surface); - assert(ev.type == YASL_EVENT_POINTER_UP && !ev.pointer.pen.pressure && ev.pointer.device == YASL_PTR_DEV_PEN); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_UP); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_UP && !ev.pointer.pen.pressure && ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_UP && !pen.pen.in_contact && pen.pen.pressure == 0.0); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; - assert(next(surface).type == YASL_EVENT_POINTER_LEAVE); + assert(next(surface, YASL_PRIVATE_EVENT_POINTER_LEAVE).type == YASL_PRIVATE_EVENT_POINTER_LEAVE); + assert(next(surface, YASL_PRIVATE_EVENT_PEN).pen.action == YASL_PRIVATE_PEN_LEAVE); sample.enteringProximity = YES; sample.tool = NSPointingDeviceTypeEraser; [view tabletProximity:native]; @@ -104,20 +144,25 @@ int main(void) sample.samplePressure = 0.75; sample.buttonMask = NSEventButtonMaskPenTip; [view tabletPoint:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.pen.pressure > 0); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_ENTER && pen.pen.tool == 2); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_DOWN); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && ev.type == YASL_PRIVATE_EVENT_POINTER_DOWN && ev.pointer.pen.pressure > 0); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_DOWN && pen.pen.tool == 2 && pen.pen.in_contact); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_LEAVE && !ev.pointer.pen.pressure); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_LEAVE); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && ev.type == YASL_PRIVATE_EVENT_POINTER_LEAVE && !ev.pointer.pen.pressure); + assert(next(surface, YASL_PRIVATE_EVENT_PEN).pen.action == YASL_PRIVATE_PEN_LEAVE); sample.type = NSEventTypeMouseMoved; [view mouseMoved:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); [sample release]; - yasl_surface_destroy(surface); - yasl_display_close(display); + yasl_private_surface_destroy(surface); + yasl_private_display_close(display); } return 0; } -- cgit v1.2.3