Compare commits

...

3 commits

Author SHA1 Message Date
ba6466a642 everything gets drawn 2025-12-05 19:18:11 -07:00
31e419a134 context doesn't need to be recreated on resize 2025-12-05 18:53:49 -07:00
c1c969859c undo the ugly clear color hack thing 2025-12-05 18:53:15 -07:00
3 changed files with 28 additions and 76 deletions

View file

@ -79,6 +79,8 @@ struct _MwLLWayland {
struct wl_shm* shm;
struct wl_registry_listener registry_listener;
MwLL* subwidgets;
MwBool configured;
MwBool force_redraw;
MwBool egl_setup;

View file

@ -251,31 +251,6 @@ static MwBool egl_setup(MwLL self, int width, int height) {
static void egl_resetup(MwLL handle) {
int err;
if(!handle->wayland.egl_do_resetup) {
return;
}
if(!eglMakeCurrent(handle->wayland.egl_display, 0, 0, handle->wayland.egl_context)) {
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
return;
}
if(!eglDestroySurface(handle->wayland.egl_display, handle->wayland.egl_surface)) {
printf("ERROR: eglDestroySurface, %0X\n", eglGetError());
return;
};
handle->wayland.egl_surface = eglCreateWindowSurface(handle->wayland.egl_display, handle->wayland.egl_config, handle->wayland.egl_window_native, NULL);
if(handle->wayland.egl_surface == EGL_NO_SURFACE) {
printf("ERROR: eglCreateWindowSurface, %0X\n", eglGetError());
return;
}
if(!eglMakeCurrent(handle->wayland.egl_display, handle->wayland.egl_surface, handle->wayland.egl_surface, handle->wayland.egl_context)) {
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
return;
}
glDeleteTextures(1, &handle->wayland.fbo_texture);
glGenTextures(1, &handle->wayland.fbo_texture);
glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture);
@ -333,12 +308,12 @@ static void xdg_toplevel_configure(void* data,
if(!self->wayland.egl_setup) {
self->wayland.egl_setup = egl_setup(self, width, height);
MwLLForceRender(self);
} else {
wl_egl_window_resize(self->wayland.egl_window_native, width, height, 0, 0);
self->wayland.egl_do_resetup = MwTRUE;
egl_resetup(self);
}
wl_egl_window_resize(self->wayland.egl_window_native, width, height, 0, 0);
self->wayland.egl_do_resetup = MwTRUE;
egl_resetup(self);
return;
};
@ -380,8 +355,9 @@ static int event_loop(MwLL handle) {
CURSOR_FD
};
struct pollfd fd;
int timeout = 100;
struct _MwLLWayland* wayland = &handle->wayland;
int timeout = 100;
struct _MwLLWayland* wayland = &handle->wayland;
MwLL topmost_parent = handle->wayland.parent;
if(wayland->display == NULL) {
return 0;
@ -429,7 +405,11 @@ static int event_loop(MwLL handle) {
}
} else {
if(wl_display_dispatch_pending(wayland->display) == 0) {
int i;
MwLLDispatch(handle, draw, NULL);
for(i = 0; i < arrlen(handle->wayland.subwidgets); i++) {
MwLLDispatch(handle->wayland.subwidgets[i], draw, NULL);
}
}
}
@ -602,6 +582,8 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y) {
r->wayland.egl_surface = topmost_parent->wayland.egl_surface;
r->wayland.fbo = topmost_parent->wayland.fbo;
r->wayland.fbo_texture = topmost_parent->wayland.fbo_texture;
arrpush(parent->wayland.subwidgets, r);
}
static void framebuffer_action_begin(MwLL handle) {
@ -624,8 +606,18 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
if(width == 0) width = 1;
if(height == 0) height = 1;
if(x == MwDEFAULT) {
x = 0;
}
if(y == MwDEFAULT) {
y = 0;
}
r->wayland.ww = width;
r->wayland.wh = height;
r->wayland.x = x;
r->wayland.y = y;
printf("%d %d\n", x, y);
r->wayland.parent = parent;
@ -634,9 +626,8 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->common.success = MwTRUE;
r->wayland.drawn_once = MwFALSE;
r->wayland.x = x;
r->wayland.y = y;
if(parent == NULL) {
printf("toplevel %d %d\n", x, y);
setup_toplevel(r, x, y);
} else {
setup_subsurface(parent, r, x, y);
@ -718,31 +709,6 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0);
/* If we have a polygon that's covering the whole screen, we want to do glClear
*/
if(x == 0 && y == 0) {
/*
We determine this by checking if all of the points are at the edge of the screen (and if there's more then 6 points).
Not a pretty solution, but unless the user does something weird like draw a triangle over itself twice, I'm pretty sure this is effective.
*/
if(points_count >= 6) {
MwBool doClear = MwTRUE;
for(n = 0; n < points_count; n++) {
if((points[n].x >= (handle->wayland.ww) - 1 || points[n].x <= 1) && (points[n].y >= (handle->wayland.wh) - 1 || points[n].y <= 1)) {
} else {
doClear = MwFALSE;
break;
}
}
if(doClear) {
glEnd();
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0, 1);
glBegin(GL_TRIANGLE_FAN);
}
}
}
glVertex2f(x, y);
if(points_count > 3) {
glVertex2f(maxX, maxY);
@ -824,17 +790,7 @@ static int MwLLPendingImpl(MwLL handle) {
}
static void MwLLNextEventImpl(MwLL handle) {
MwBool render = handle->wayland.force_redraw;
if(render) {
int x, y;
unsigned int w, h;
MwLLGetXYWH(handle, &x, &y, &w, &h);
MwLLDispatch(handle, draw, NULL);
handle->wayland.force_redraw = MwFALSE;
}
// MwBool render = handle->wayland.force_redraw;
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {

View file

@ -15,13 +15,6 @@ static void lldrawhandler(MwLL handle, void* data) {
MwDispatch(h, draw);
if(h->draw_inject != NULL) h->draw_inject(h);
MwDispatchUserHandler(h, MwNdrawHandler, NULL);
handle->common.do_redraw = MwTRUE;
if(h->parent == NULL) {
MwLLEndDraw(h->lowlevel);
} else if(h->parent->lowlevel == NULL) {
MwLLEndDraw(h->lowlevel);
}
}
static void lluphandler(MwLL handle, void* data) {
@ -339,6 +332,7 @@ void MwLoop(MwWidget handle) {
long more;
while(MwPending(handle)) {
if((v = MwStep(handle)) != 0) break;
MwLLEndDraw(handle->lowlevel);
}
if(v != 0) break;