#include "yasl/native.h" #include "yasl/native/cocoa.h" #import #include "yasl/yasl.h" #include #include #include int main(void) { struct yasl_display *d = yasl_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(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([window isKindOfClass:[NSWindow class]] && window.contentView); struct yasl_input_event event; while (yasl_surface_input_poll(s, &event)) {} @autoreleasepool { for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); yasl_display_copy(d, YASL_CLIPBOARD, text); yasl_display_paste(d, YASL_CLIPBOARD, s); memset(text, 'x', sizeof(text)); } } /* All NSString/UTF8String temporaries have now expired. */ for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); assert(yasl_surface_input_poll(s, &event)); assert(event.kind == YASL_INPUT_PASTE && strcmp(event.paste.text, text) == 0); } const char *last = event.paste.text; assert(!yasl_surface_input_poll(s, &event)); @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, "new selection"); } assert(strcmp(last, "paste-599") == 0); @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, ""); yasl_display_paste(d, YASL_CLIPBOARD, s); } assert(yasl_surface_input_poll(s, &event)); assert(event.kind == YASL_INPUT_PASTE && !event.paste.len && !event.paste.text[0]); yasl_surface_destroy(s); yasl_display_close(d); return 0; }