summaryrefslogtreecommitdiff
path: root/src/x11
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 08:41:51 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 08:41:51 +0300
commit3b8af02be94a510e385f44d58c35c86bb89424a6 (patch)
tree2573fb5ac41700d458109ee1cea4bfd875ecf1a2 /src/x11
parentf7fa0930cb46046f995fa1ab927aef62466e995e (diff)
refactor: simplify public API and isolate native extensions
Separate loop/timer and native interoperability APIs from the portable surface header. Unify dispatch, geometry queries, and timer callbacks; keep framebuffer bookkeeping and frame clocks private, and hide implementation symbols. Update backends, documentation, examples, and API/integration coverage. Verify exports, strict C/C++ installed consumers, and normal plus ASan/UBSan suites.
Diffstat (limited to 'src/x11')
-rw-r--r--src/x11/window.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/src/x11/window.c b/src/x11/window.c
index 2d9aff3..67276cf 100644
--- a/src/x11/window.c
+++ b/src/x11/window.c
@@ -1,6 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#include "common/backend.h"
#include "common/input.h"
+#include "common/timing.h"
#include <X11/Xatom.h>
#include <X11/XKBlib.h>
@@ -218,8 +219,9 @@ static void net_message(struct x11_surface *s, Atom type,
}
static struct yasl_surface *create_toplevel(struct yasl_display *base,
- const struct yasl_surface_spec *spec)
+ const struct yasl_surface_spec *spec, void *graphics_device)
{
+ (void)graphics_device;
if (!spec) return NULL;
struct x11_display *d = (struct x11_display *)base;
struct x11_surface *s = calloc(1, sizeof(*s));
@@ -481,7 +483,6 @@ static bool present(struct yasl_surface *base, const struct yasl_framebuffer *fb
struct x11_surface *s = (struct x11_surface *)base;
if (s->destroyed || !s->drawing || s->presented || !fb || !damage ||
fb->pixels != s->pixels || fb->size.x != s->size.x || fb->size.y != s->size.y ||
- fb->buffer != s->frame.target.buffer || fb->native_drawable || fb->transaction ||
damage->n < -1 || damage->n > YASL_DAMAGE_MAX) return false;
struct x11_display *d = display_of(base);
XImage *im = s->image;
@@ -527,7 +528,7 @@ static void flush(struct yasl_display *base)
s->frame = (struct yasl_frame){
.surface = &s->base,
.target = {.generation = yasl_frame_begin(&s->base),
- .pixels = s->pixels, .size = s->size, .damage = &s->damage},
+ .pixels = s->pixels, .size = s->size},
};
s->cbs->draw(&s->base, &s->frame, s->ud);
s->drawing = false;
@@ -549,6 +550,12 @@ static int dispatch_timeout(struct yasl_display *base, int timeout_ms)
struct x11_display *d = (struct x11_display *)base;
if (unlikely(!d || !d->native)) return -1;
dispatch(base);
+ for (struct x11_surface *s = d->surfaces; s; s = s->next) {
+ if (s->want_draw || s->input.count || s->input.reset_pending) {
+ timeout_ms = 0;
+ break;
+ }
+ }
if (d->loop) {
if (!XPending(d->native) && timeout_ms != 0) {
yasl_loop_step(d->loop, timeout_ms);
@@ -696,8 +703,10 @@ static void schedule_redraw(struct yasl_surface *base)
}
static struct yasl_display *surface_display(const struct yasl_surface *s) { return s->display; }
-static struct yasl_vector2i size(const struct yasl_surface *s) { return ((const struct x11_surface *)s)->size; }
-static uint32_t scale(const struct yasl_surface *s) { (void)s; return YASL_SCALE_UNIT; }
+static struct yasl_geometry geometry(const struct yasl_surface *s)
+{
+ return (struct yasl_geometry){((const struct x11_surface *)s)->size, YASL_SCALE_UNIT};
+}
static uint32_t state(const struct yasl_surface *s) { return ((const struct x11_surface *)s)->state; }
static int mods(const struct yasl_display *d) { return (int)((const struct x11_display *)d)->mods; }
static void *native_display(struct yasl_display *d) { return ((struct x11_display *)d)->native; }
@@ -766,28 +775,11 @@ static bool interactive_move(struct yasl_surface *base)
return true;
}
-static void display_dispatch(struct yasl_display *base)
-{
- struct x11_display *d = (struct x11_display *)base;
- if (unlikely(!d || !d->native)) return;
- bool immediate = false;
- for (struct x11_surface *s = d->surfaces; s; s = s->next) {
- if (s->want_draw || s->input.count > 0 || s->input.reset_pending) {
- immediate = true;
- break;
- }
- }
- if (d->loop && yasl_loop_is_running(d->loop))
- immediate = true;
- dispatch_timeout(base, immediate ? 0 : -1);
-}
-
const struct yasl_backend_ops yasl_x11_backend = {
.type = YASL_BACKEND_X11,
.display_open = display_open,
.display_close = display_close,
.display_caps = caps,
- .display_dispatch = display_dispatch,
.display_dispatch_timeout = dispatch_timeout,
.display_flush = flush,
.display_modifiers = mods,
@@ -801,8 +793,7 @@ const struct yasl_backend_ops yasl_x11_backend = {
.surface_schedule_redraw = schedule_redraw,
.surface_present = present,
.surface_input_poll = input_poll,
- .surface_size = size,
- .surface_scale_120 = scale,
+ .surface_geometry = geometry,
.surface_state = state,
.surface_timing = timing,
.surface_frame_time_ns = frame_time,