wayland: opengl support

This commit is contained in:
IoIxD
2025-12-30 22:26:19 -07:00
parent a03065ae52
commit 6946c1eaf3
4 changed files with 229 additions and 29 deletions

View File

@@ -8,7 +8,6 @@
#include <sys/mman.h>
#include <wayland-util.h>
#include <unistd.h>
#include <pthread.h>
/* TODO:
* - MwLLGrabPointerImpl
@@ -46,7 +45,7 @@ static void new_protocol(void* data, struct wl_registry* registry,
wayland_protocol_callback_table_t* cb = shget(wayland->wl_protocol_setup_map, interface);
if(cb != NULL) {
char* inter = malloc(strlen(interface));
char* inter = malloc(strlen(interface) + 1);
strcpy(inter, interface);
shput(wayland->wl_protocol_map, inter, cb->setup(name, data));
} else {
@@ -360,6 +359,7 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time
p.point = self->wayland.cur_mouse_pos;
MwLLDispatch(self, move, &p);
self->wayland.events_pending += 1;
/*timed_redraw(self, time, 50, &self->wayland.cooldown_timer);*/
@@ -396,8 +396,10 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri
}
}
MwLLDispatch(self, draw, NULL);
self->wayland.events_pending += 1;
if(!self->wayland.always_render) {
MwLLDispatch(self, draw, NULL);
self->wayland.events_pending += 1;
}
};
/* `wl_pointer.axis` callback */
@@ -433,8 +435,6 @@ static void keyboard_keymap(void* data,
close(fd);
struct xkb_state* xkb_state = xkb_state_new(xkb_keymap);
xkb_keymap_unref(wayland->xkb_keymap);
xkb_state_unref(wayland->xkb_state);
wayland->xkb_keymap = xkb_keymap;
wayland->xkb_state = xkb_state;
@@ -556,8 +556,11 @@ static void keyboard_key(void* data,
}
}
}
MwLLDispatch(self, draw, NULL);
self->wayland.events_pending += 1;
if(!self->wayland.always_render) {
MwLLDispatch(self, draw, NULL);
self->wayland.events_pending += 1;
}
};
/* `wl_keyboard.modifiers` callback */
@@ -783,6 +786,8 @@ static void xdg_toplevel_configure(void* data,
MwLLDispatch(self, resize, NULL);
MwLLDispatch(self, draw, NULL);
MwLLForceRender(self);
/*if(!self->wayland.egl_setup) {
self->wayland.egl_setup = egl_setup(self, self->wayland.x, self->wayland.y, width, height);
} else {
@@ -891,6 +896,7 @@ static void framebuffer_setup(struct _MwLLWayland* wayland) {
memset(wayland->framebuffer.buf, 255, wayland->framebuffer.buf_size);
update_buffer(&wayland->framebuffer);
wayland->events_pending += 1;
};
static void framebuffer_destroy(struct _MwLLWayland* wayland) {
@@ -1287,9 +1293,6 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLLForceRender(r);
pthread_mutex_init(&r->wayland.dispatch_mutex, NULL);
pthread_mutex_init(&r->wayland.pending_mutex, NULL);
return r;
}
@@ -1398,6 +1401,7 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
}
cairo_close_path(handle->wayland.cairo);
cairo_fill(handle->wayland.cairo);
handle->wayland.events_pending += 1;
}
@@ -1416,6 +1420,7 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
}
cairo_close_path(handle->wayland.cairo);
cairo_stroke(handle->wayland.cairo);
handle->wayland.events_pending += 1;
}
@@ -1424,6 +1429,7 @@ static void MwLLBeginDrawImpl(MwLL handle) {
static void MwLLEndDrawImpl(MwLL handle) {
update_buffer(&handle->wayland.framebuffer);
handle->wayland.events_pending += 1;
}
@@ -1451,20 +1457,25 @@ static int MwLLPendingImpl(MwLL handle) {
MwBool pending = MwFALSE;
struct timespec timeout;
timeout.tv_nsec = 100;
timeout.tv_sec = 0;
while(pending == 0 && !handle->wayland.break_dispatch) {
pending = wl_display_dispatch_timeout(handle->wayland.display, &timeout);
if(handle->wayland.always_render) {
return event_loop(handle);
}
return handle->wayland.force_render || handle->wayland.events_pending || pending;
timeout.tv_nsec = 10;
timeout.tv_sec = 0;
return handle->wayland.force_render || handle->wayland.events_pending || wl_display_dispatch_timeout(handle->wayland.display, &timeout);
}
static void MwLLNextEventImpl(MwLL handle) {
event_loop(handle);
if(handle->wayland.events_pending) {
handle->wayland.events_pending = 0;
if(!handle->wayland.always_render) {
event_loop(handle);
if(handle->wayland.events_pending) {
handle->wayland.events_pending = 0;
}
if(handle->wayland.force_render) {
handle->wayland.force_render = 0;
}
}
}
@@ -1575,6 +1586,8 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
static void MwLLForceRenderImpl(MwLL handle) {
wl_surface_damage(handle->wayland.framebuffer.surface, 0, 0, handle->wayland.ww, handle->wayland.wh);
handle->wayland.force_render = MwTRUE;
/*
if(handle->wayland.egl_setup) {
timed_redraw_by_epoch(handle, 25);