wayland: improve event loop

This commit is contained in:
IoI_xD 2026-03-17 22:17:05 -07:00
commit fc7896b5ce
2 changed files with 351 additions and 355 deletions

View file

@ -1046,8 +1046,12 @@ static void xdg_toplevel_icon_manager_v1_interface_destroy(struct _MwLLWayland*
/* Standard Wayland event loop. */ /* Standard Wayland event loop. */
static int event_loop(MwLL handle) { static int event_loop(MwLL handle) {
struct pollfd fd; struct pollfd fd;
int timeout = 1; struct timespec timeout;
struct _MwLLWayland* wayland = &handle->wayland; struct _MwLLWayland* wayland = &handle->wayland;
int res;
timeout.tv_nsec = 1;
timeout.tv_sec = 0;
if(wayland->display == NULL) { if(wayland->display == NULL) {
return 0; return 0;
@ -1072,19 +1076,15 @@ static int event_loop(MwLL handle) {
} }
wl_display_prepare_read(handle->wayland.display); wl_display_prepare_read(handle->wayland.display);
/* Condition where no events are being sent. */
if(!poll(&fd, 1, timeout)) {
wl_display_cancel_read(wayland->display);
/* In this case, we need to commit the surface for any animations, etc. */
wl_surface_commit(wayland->framebuffer.surface);
return 0;
}
wl_display_read_events(wayland->display); wl_display_read_events(wayland->display);
if(wl_display_dispatch_pending(wayland->display) < 0) { if((res = wl_display_dispatch_timeout(wayland->display, &timeout)) <= 0) {
if(res < 0) {
wl_display_cancel_read(handle->wayland.display); wl_display_cancel_read(handle->wayland.display);
} }
wl_surface_commit(wayland->framebuffer.surface);
return 0;
}
return 1; return 1;
} }
@ -1605,20 +1605,17 @@ static void MwLLFreeColorImpl(MwLLColor color) {
static int MwLLPendingImpl(MwLL handle) { static int MwLLPendingImpl(MwLL handle) {
MwBool pending = MwFALSE; MwBool pending = MwFALSE;
struct timespec timeout; struct timespec timeout;
int i;
timeout.tv_nsec = 1; timeout.tv_nsec = 1;
timeout.tv_sec = 0; timeout.tv_sec = 0;
int i;
pending = wl_display_dispatch_timeout(handle->wayland.display, &timeout); pending = wl_display_dispatch_timeout(handle->wayland.display, &timeout);
if(handle->wayland.always_render) { if(handle->wayland.always_render) {
event_loop(handle); event_loop(handle);
return 0; return 0;
} } else if(handle->wayland.force_render) {
if(handle->wayland.force_render) {
MwLLDispatch(handle, draw, NULL); MwLLDispatch(handle, draw, NULL);
// handle->wayland.force_render = 0;
// update_buffer(&handle->wayland.framebuffer);
return 1; return 1;
} }
if(handle->wayland.events_pending || handle->wayland.force_render) { if(handle->wayland.events_pending || handle->wayland.force_render) {

View file

@ -111,8 +111,7 @@ static int create(MwWidget handle) {
attribs[4] = None; attribs[4] = None;
while(glpath[glincr] != NULL && while(glpath[glincr] != NULL &&
(o->lib = MwDynamicOpen(glpath[glincr++])) == NULL) (o->lib = MwDynamicOpen(glpath[glincr++])) == NULL);
;
o->glXChooseVisual = o->glXChooseVisual =
(MWglXChooseVisual)MwDynamicSymbol(o->lib, "glXChooseVisual"); (MWglXChooseVisual)MwDynamicSymbol(o->lib, "glXChooseVisual");
@ -365,14 +364,14 @@ static void mwOpenGLSwapBufferImpl(MwWidget handle) {
#ifdef USE_WAYLAND #ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) { if(handle->lowlevel->common.type == MwLLBackendWayland) {
waylandopengl_t* o = handle->internal; waylandopengl_t* o = handle->internal;
eglSwapInterval(o->egl_display, 0); // eglSwapInterval(o->egl_display, 0);
if(!eglSwapBuffers(o->egl_display, o->egl_surface)) { if(!eglSwapBuffers(o->egl_display, o->egl_surface)) {
printf("ERROR: eglSwapBuffers, %0X\n", eglGetError()); printf("ERROR: eglSwapBuffers, %0X\n", eglGetError());
}; };
wl_egl_window_resize((struct wl_egl_window*)o->egl_window_native, wl_egl_window_resize((struct wl_egl_window*)o->egl_window_native,
handle->lowlevel->wayland.ww, handle->lowlevel->wayland.ww,
handle->lowlevel->wayland.wh, 0, 0); handle->lowlevel->wayland.wh, 0, 0);
MwLLForceRender(handle->lowlevel); // MwLLForceRender(handle->lowlevel);
} }
#endif #endif
} }