summaryrefslogtreecommitdiff
path: root/src/common/backend.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-14 13:56:48 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-14 13:56:48 +0300
commit87279f6903343e621c0446b20d1e7d6a495f1125 (patch)
tree999b5fb5fb76702efb02f856f082147304f0859b /src/common/backend.c
parent1ab3e5a123109704789c2768e11a4f9af515821d (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/backend.c')
-rw-r--r--src/common/backend.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/src/common/backend.c b/src/common/backend.c
index 939ec71..ad9e218 100644
--- a/src/common/backend.c
+++ b/src/common/backend.c
@@ -133,16 +133,21 @@ int yasl_private_display_double_click_ms(const struct yasl_private_display *d)
bool yasl_private_display_drag_start(struct yasl_private_display *d, struct yasl_surface *origin, const struct yasl_private_drag_image *image, const struct yasl_private_drag_listener *l, void *ud)
{
- if (!d || !d->ops->display_drag_start)
- return 0;
- if (!origin || origin->display != d)
- return false;
+ if (!d || !origin || origin->display != d) { errno = EINVAL; return false; }
+ if (!d->ops->display_drag_start) { errno = ENOTSUP; return false; }
if (image && (!image->pixels || image->size.x <= 0 || image->size.y <= 0 ||
image->size.x > 32767 || image->size.y > 32767 ||
- (int64_t)image->size.x * image->size.y * 4 > INT32_MAX))
+ (int64_t)image->size.x * image->size.y * 4 > INT32_MAX ||
+ image->hotspot.x < 0 || image->hotspot.y < 0 ||
+ image->hotspot.x >= image->size.x || image->hotspot.y >= image->size.y)) {
+ errno = EINVAL;
return false;
+ }
const struct yasl_private_drag_listener empty = {0};
- return d->ops->display_drag_start(d, origin, image, l ? l : &empty, ud);
+ errno = 0;
+ bool ok = d->ops->display_drag_start(d, origin, image, l ? l : &empty, ud);
+ if (!ok && !errno) errno = EIO;
+ return ok;
}
void yasl_private_display_drag_cancel(struct yasl_private_display *d)
@@ -326,13 +331,18 @@ bool yasl_private_surface_read_pixels(struct yasl_surface *s, uint32_t *out, siz
bool yasl_private_surface_set_pointer_mode(struct yasl_surface *s, enum yasl_private_pointer_mode mode)
{
- if (!s || (mode != YASL_PRIVATE_POINTER_NORMAL && mode != YASL_PRIVATE_POINTER_RELATIVE))
+ if (!s || (mode != YASL_PRIVATE_POINTER_NORMAL && mode != YASL_PRIVATE_POINTER_RELATIVE)) {
+ errno = EINVAL;
return false;
+ }
if (mode == s->pointer_mode)
return true;
const struct yasl_private_backend_ops *ops = s->display ? s->display->ops : NULL;
- if (!ops || !ops->surface_set_pointer_mode)
- return mode == YASL_PRIVATE_POINTER_NORMAL;
+ if (!ops || !ops->surface_set_pointer_mode) {
+ if (mode == YASL_PRIVATE_POINTER_NORMAL) return true;
+ errno = ENOTSUP;
+ return false;
+ }
if (!ops->surface_set_pointer_mode(s, mode))
return false;
s->pointer_mode = mode;
@@ -416,43 +426,48 @@ void yasl_private_surface_set_ime_caret(struct yasl_surface *s, struct yasl_priv
s->display->ops->surface_set_ime_caret(s, caret);
}
+/* Backend operations that may be missing: ENOTSUP when absent, EIO when a backend
+ * fails without saying why. */
+#define OPTIONAL_OP(s, op, ...) \
+ do { \
+ if (!(s)) { errno = EINVAL; return false; } \
+ if (!(s)->display->ops->op) { errno = ENOTSUP; return false; } \
+ errno = 0; \
+ bool ok_ = (s)->display->ops->op(__VA_ARGS__); \
+ if (!ok_ && !errno) errno = EIO; \
+ return ok_; \
+ } while (0)
+
bool yasl_private_surface_start_interactive_move(struct yasl_surface *s)
{
- if (!s || !s->display->ops->surface_start_interactive_move)
- return 0;
- return s->display->ops->surface_start_interactive_move(s);
+ OPTIONAL_OP(s, surface_start_interactive_move, s);
}
bool yasl_private_surface_start_interactive_resize(struct yasl_surface *s, enum yasl_private_resize_edge edge)
{
- if (!s || !s->display->ops->surface_start_interactive_resize ||
- (edge != YASL_PRIVATE_EDGE_TOP && edge != YASL_PRIVATE_EDGE_BOTTOM &&
- edge != YASL_PRIVATE_EDGE_LEFT && edge != YASL_PRIVATE_EDGE_RIGHT &&
- edge != YASL_PRIVATE_EDGE_TOP_LEFT && edge != YASL_PRIVATE_EDGE_TOP_RIGHT &&
- edge != YASL_PRIVATE_EDGE_BOTTOM_LEFT && edge != YASL_PRIVATE_EDGE_BOTTOM_RIGHT))
- return 0;
- return s->display->ops->surface_start_interactive_resize(s, edge);
+ if (edge != YASL_PRIVATE_EDGE_TOP && edge != YASL_PRIVATE_EDGE_BOTTOM &&
+ edge != YASL_PRIVATE_EDGE_LEFT && edge != YASL_PRIVATE_EDGE_RIGHT &&
+ edge != YASL_PRIVATE_EDGE_TOP_LEFT && edge != YASL_PRIVATE_EDGE_TOP_RIGHT &&
+ edge != YASL_PRIVATE_EDGE_BOTTOM_LEFT && edge != YASL_PRIVATE_EDGE_BOTTOM_RIGHT) {
+ errno = EINVAL;
+ return false;
+ }
+ OPTIONAL_OP(s, surface_start_interactive_resize, s, edge);
}
bool yasl_private_surface_show_window_menu(struct yasl_surface *s, struct yasl_private_vector2i pos)
{
- if (!s || !s->display->ops->surface_show_window_menu)
- return 0;
- return s->display->ops->surface_show_window_menu(s, pos);
+ OPTIONAL_OP(s, surface_show_window_menu, s, pos);
}
bool yasl_private_surface_drag_carry(struct yasl_surface *s, struct yasl_private_vector2i offset)
{
- if (!s || !s->display->ops->surface_drag_carry)
- return 0;
- return s->display->ops->surface_drag_carry(s, offset);
+ OPTIONAL_OP(s, surface_drag_carry, s, offset);
}
bool yasl_private_surface_place_under_pointer(struct yasl_surface *s, struct yasl_private_vector2i at)
{
- if (!s || !s->display->ops->surface_place_under_pointer)
- return 0;
- return s->display->ops->surface_place_under_pointer(s, at);
+ OPTIONAL_OP(s, surface_place_under_pointer, s, at);
}
void yasl_private_surface_clear_timers(struct yasl_surface *s)