summaryrefslogtreecommitdiff
path: root/src/x11
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 00:29:34 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 00:29:34 +0300
commitf7fa0930cb46046f995fa1ab927aef62466e995e (patch)
treef5ac4e1579811b5d69498a19d0bdfbf128a1d62b /src/x11
parent624d1371304a5ae4b3429ad5e4267aac7cd03dfd (diff)
feat: add SDL3-style surface, display, and loop timer API for X11, Wayland, and Cocoa
Diffstat (limited to 'src/x11')
-rw-r--r--src/x11/window.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/x11/window.c b/src/x11/window.c
index e40db6e..2d9aff3 100644
--- a/src/x11/window.c
+++ b/src/x11/window.c
@@ -549,9 +549,13 @@ 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);
- if (!XPending(d->native) && d->loop && timeout_ms != 0) {
- yasl_loop_step(d->loop, timeout_ms);
- dispatch(base);
+ if (d->loop) {
+ if (!XPending(d->native) && timeout_ms != 0) {
+ yasl_loop_step(d->loop, timeout_ms);
+ dispatch(base);
+ } else {
+ yasl_loop_step(d->loop, 0);
+ }
}
return 0;
}
@@ -572,6 +576,7 @@ static struct yasl_display *display_open(struct yasl_loop *loop,
} else {
d->loop = loop;
}
+ d->base.loop = d->loop;
d->app_id = strdup(spec && spec->app_id ? spec->app_id : "YASL");
if (!d->loop || !d->app_id) {
if (d->owns_loop) yasl_loop_destroy(d->loop);
@@ -617,7 +622,11 @@ static void display_close(struct yasl_display *base)
assert(!d->surfaces && "destroy every surface before its display");
cancel_pastes(d, NULL);
if (d->loop && d->watch > 0) yasl_loop_del_fd(d->loop, d->watch);
- if (d->owns_loop && d->loop) yasl_loop_destroy(d->loop);
+ if (d->owns_loop && d->loop) {
+ yasl_loop_destroy(d->loop);
+ d->loop = NULL;
+ d->base.loop = NULL;
+ }
if (d->im) XCloseIM(d->im);
XDestroyWindow(d->native, d->selection_window);
XCloseDisplay(d->native);
@@ -757,12 +766,28 @@ 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 = dispatch,
+ .display_dispatch = display_dispatch,
.display_dispatch_timeout = dispatch_timeout,
.display_flush = flush,
.display_modifiers = mods,