diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 13:56:48 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 13:56:48 +0300 |
| commit | 87279f6903343e621c0446b20d1e7d6a495f1125 (patch) | |
| tree | 999b5fb5fb76702efb02f856f082147304f0859b /src/common/native.c | |
| parent | 1ab3e5a123109704789c2768e11a4f9af515821d (diff) | |
Simplify the public API into one dense header
yasl.h now holds everything except Vulkan: 45 functions instead of 62,
and three installed headers instead of ten.
- One constructor: yasl_surface_create takes CPU, GL or NATIVE, with
zero-initialized GL options meaning 3.2 core, RGBA8, D24S8.
- Events carry action, mods, x, y and text at the top level; pen
positions are now logical like pointer positions.
- yasl_cpu_pixels/yasl_cpu_present draw into one persistent canvas,
cutting three full-frame copies per frame.
- yasl_surface_get_info, yasl_surface_request, YASL_CURSOR_LOCKED,
yasl_surface_set_text_input, yasl_surface_begin_move_resize and
yasl_surface_get_native replace groups of narrower calls.
- Interactive calls drop the decorative trigger event argument.
- yasl_wait_event returns 0 only on timeout or yasl_wake, the refresh
callback runs only in native modal loops, focus loss sends
INPUT_RESET, and a lost event no longer fails every later wait.
- Unsupported operations and bad arguments report ENOTSUP and EINVAL
instead of EIO; the keycodes header no longer needs C23.
- The shared library gets a versioned SONAME and version macros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/common/native.c')
| -rw-r--r-- | src/common/native.c | 106 |
1 files changed, 38 insertions, 68 deletions
diff --git a/src/common/native.c b/src/common/native.c index 1b32094..36f7010 100644 --- a/src/common/native.c +++ b/src/common/native.c @@ -45,84 +45,54 @@ bool yasl_private_surface_get_native_frame(struct yasl_surface *s, } #include "public_internal.h" -#include "yasl/metal.h" -#if YASL_HAS_WAYLAND || YASL_HAS_X11 || YASL_HAS_COCOA -static int native_validate(const yasl_surface *s, enum yasl_private_backend backend) -{ - if (!yasl_public_surface((yasl_surface *)s, false)) - return -errno; - if (s->display->ops->type != backend) - return yasl_public_error(ENOTSUP); - if (s->display->offline) - return yasl_public_error(ENOTCONN); - return 0; -} -#endif -#if YASL_HAS_WAYLAND -#include "yasl/native/wayland.h" -int yasl_wayland_get_native(const yasl_surface *s, struct yasl_wayland_handles *out) -{ - if (!out) - return yasl_public_error(EINVAL); - *out = (struct yasl_wayland_handles){0}; - int error = native_validate(s, YASL_PRIVATE_BACKEND_WAYLAND); - if (error) - return error; - out->display = yasl_private_display_get_native_handle(s->display); - out->surface = yasl_private_surface_get_native_handle((yasl_surface *)s); - return 0; -} -#endif -#if YASL_HAS_X11 -#include "yasl/native/x11.h" -int yasl_x11_get_native(const yasl_surface *s, struct yasl_x11_handles *out) -{ - if (!out) - return yasl_public_error(EINVAL); - *out = (struct yasl_x11_handles){0}; - int error = native_validate(s, YASL_PRIVATE_BACKEND_X11); - if (error) - return error; - out->display = yasl_private_display_get_native_handle(s->display); - out->window = (uintptr_t)yasl_private_surface_get_native_handle((yasl_surface *)s); - return 0; -} -#endif #if YASL_HAS_COCOA -#include "yasl/native/cocoa.h" #include "common/private_native_cocoa.h" -int yasl_cocoa_get_native(const yasl_surface *s, struct yasl_cocoa_handles *out) -{ - if (!out) - return yasl_public_error(EINVAL); - *out = (struct yasl_cocoa_handles){0}; - int error = native_validate(s, YASL_PRIVATE_BACKEND_COCOA); - if (error) - return error; - out->application = yasl_private_cocoa_display_get_application(s->display); - out->window = yasl_private_cocoa_surface_get_window((yasl_surface *)s); - out->view = yasl_private_cocoa_surface_get_view((yasl_surface *)s); - return 0; -} #endif -int yasl_metal_get_layer(yasl_surface *s, CAMetalLayer **out) +int yasl_surface_get_native(const yasl_surface *cs, struct yasl_native *out) { + yasl_surface *s = (yasl_surface *)cs; if (!out) return yasl_public_error(EINVAL); - *out = NULL; - if (!yasl_public_surface(s, false)) + *out = (struct yasl_native){0}; + if (!yasl_public_connected(s)) return -errno; - if (s->display->offline) + void *window = yasl_private_surface_get_native_handle(s); + switch (s->display->ops->type) { + case YASL_PRIVATE_BACKEND_WAYLAND: + out->wl_display = yasl_private_display_get_native_handle(s->display); + out->wl_surface = window; + break; + case YASL_PRIVATE_BACKEND_X11: + out->x11_display = yasl_private_display_get_native_handle(s->display); + out->x11_window = (unsigned long)(uintptr_t)window; + break; +#if YASL_HAS_COCOA + case YASL_PRIVATE_BACKEND_COCOA: + out->ns_window = yasl_private_cocoa_surface_get_window(s); + out->ns_view = yasl_private_cocoa_surface_get_view(s); + break; +#endif + default: + return yasl_public_error(ENOTSUP); + } + if (!window) { + *out = (struct yasl_native){0}; return yasl_public_error(ENOTCONN); + } + return 0; +} +void *yasl_metal_get_layer(yasl_surface *s) +{ + if (!yasl_public_connected(s)) + return NULL; if (s->vulkan || (s->presenter != YASL_PRIVATE_PRESENTER_NONE && s->presenter != YASL_PRIVATE_PRESENTER_METAL)) - return yasl_public_error(EBUSY); - if (!s->display->ops->surface_get_metal_layer) - return yasl_public_error(ENOTSUP); - CAMetalLayer *layer = s->display->ops->surface_get_metal_layer(s); + return yasl_public_fail(EBUSY), NULL; + void *layer = s->display->ops->surface_get_metal_layer + ? s->display->ops->surface_get_metal_layer(s) + : NULL; if (!layer) - return yasl_public_error(ENOTSUP); + return yasl_public_fail(ENOTSUP), NULL; s->presenter = YASL_PRIVATE_PRESENTER_METAL; - *out = layer; - return 0; + return layer; } |
