summaryrefslogtreecommitdiff
path: root/src/common/native.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
commit76073fe5fad8799e5850805f2f090af2cb62c741 (patch)
tree9658019babe4760a3634bdab4da0731a10e42e68 /src/common/native.c
parentdd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'src/common/native.c')
-rw-r--r--src/common/native.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/common/native.c b/src/common/native.c
index 42b065c..88604c9 100644
--- a/src/common/native.c
+++ b/src/common/native.c
@@ -2,7 +2,7 @@
#include <errno.h>
-void *yasl_display_get_native_handle(struct yasl_display *d)
+void *yasl_private_display_get_native_handle(struct yasl_private_display *d)
{
if (!d) return NULL;
if (d->native_handle) return d->native_handle;
@@ -10,7 +10,7 @@ void *yasl_display_get_native_handle(struct yasl_display *d)
d->ops->display_get_native_handle(d) : NULL;
}
-void *yasl_surface_get_native_handle(struct yasl_surface *s)
+void *yasl_private_surface_get_native_handle(struct yasl_surface *s)
{
if (!s) return NULL;
if (s->native_handle) return s->native_handle;
@@ -18,18 +18,18 @@ void *yasl_surface_get_native_handle(struct yasl_surface *s)
s->display->ops->surface_get_native_handle(s) : NULL;
}
-struct yasl_surface *yasl_surface_create_native(struct yasl_display *d,
- const struct yasl_window_spec *spec, void *graphics_device)
+struct yasl_surface *yasl_private_surface_create_native(struct yasl_private_display *d,
+ const struct yasl_private_window_spec *spec, void *graphics_device)
{
if (!graphics_device) {
errno = EINVAL;
return NULL;
}
- return yasl_create_toplevel(d, spec, graphics_device);
+ return yasl_private_create_toplevel(d, spec, graphics_device);
}
-bool yasl_surface_get_native_frame(struct yasl_surface *s,
- const struct yasl_framebuffer *target, struct yasl_native_frame *out)
+bool yasl_private_surface_get_native_frame(struct yasl_surface *s,
+ const struct yasl_private_framebuffer *target, struct yasl_private_native_frame *out)
{
if (!s || !target || !out || !target->generation ||
target->generation != s->frame_generation ||
@@ -37,3 +37,39 @@ bool yasl_surface_get_native_frame(struct yasl_surface *s,
return false;
return s->display->ops->surface_get_native_frame(s, target, out);
}
+
+#include "public_internal.h"
+#include "yasl/metal.h"
+#if YASL_HAS_WAYLAND
+#include "yasl/native/wayland.h"
+struct wl_display *yasl_wayland_display(const yasl_surface *s)
+{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_WAYLAND ? yasl_private_display_get_native_handle(s->display):NULL; }
+struct wl_surface *yasl_wayland_surface(const yasl_surface *s)
+{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_WAYLAND ? yasl_private_surface_get_native_handle((yasl_surface*)s):NULL; }
+#endif
+#if YASL_HAS_X11
+#include "yasl/native/x11.h"
+Display *yasl_x11_display(const yasl_surface *s)
+{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_X11 ? yasl_private_display_get_native_handle(s->display):NULL; }
+uintptr_t yasl_x11_window(const yasl_surface *s)
+{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_X11 ? (uintptr_t)yasl_private_surface_get_native_handle((yasl_surface*)s):0; }
+#endif
+#if YASL_HAS_COCOA
+#include "yasl/native/cocoa.h"
+#include "common/private_native_cocoa.h"
+NSApplication *yasl_cocoa_application(void)
+{ struct yasl_private_display *d=yasl_public_display();return d ? yasl_private_cocoa_display_get_application(d):NULL; }
+NSWindow *yasl_cocoa_window(const yasl_surface *s)
+{ return yasl_private_cocoa_surface_get_window((yasl_surface*)s); }
+NSView *yasl_cocoa_view(const yasl_surface *s)
+{ return yasl_private_cocoa_surface_get_view((yasl_surface*)s); }
+#endif
+CAMetalLayer *yasl_metal_layer(yasl_surface *s)
+{
+ if(!yasl_public_surface(s,false))return NULL;
+ if(s->presenter!=YASL_PRIVATE_PRESENTER_NONE && s->presenter!=YASL_PRIVATE_PRESENTER_METAL) {yasl_public_fail(EBUSY);return NULL;}
+ if(!s->display->ops->surface_get_metal_layer){yasl_public_fail(ENOTSUP);return NULL;}
+ CAMetalLayer *layer=s->display->ops->surface_get_metal_layer(s);
+ if(!layer){yasl_public_fail(ENOTSUP);return NULL;}
+ s->presenter=YASL_PRIVATE_PRESENTER_METAL;return layer;
+}