Unfinished Wayland PR #1

Merged
IoI_xD merged 55 commits from IoI_xD/milsko:wayland into master 2025-12-10 11:11:02 +09:00
3 changed files with 58 additions and 30 deletions
Showing only changes of commit d308c83fc2 - Show all commits

recursive updating

IoIxD 2025-12-05 20:25:23 -07:00

View file

@ -84,7 +84,6 @@ struct _MwLLWayland {
MwBool configured;
MwBool force_redraw;
MwBool egl_setup;
MwBool drawn_once;
MwBool egl_do_resetup;
MwU32 x, y, ww, wh;
int z_index;

View file

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <wayland-client-protocol.h>
#include "../../external/stb_ds.h"
@ -244,7 +245,6 @@ static MwBool egl_setup(MwLL self, int width, int height) {
self->wayland.egl_display = display;
self->wayland.egl_surface = surface;
self->wayland.egl_context = context;
printf("EGL success\n");
return MwTRUE;
}
@ -283,6 +283,26 @@ static void egl_resetup(MwLL handle) {
handle->wayland.egl_do_resetup = MwFALSE;
}
static void recursive_draw(MwLL handle) {
int i;
if(handle->wayland.subwidgets != NULL) {
for(i = 0; i < arrlen(handle->wayland.subwidgets); i++) {
MwLLDispatch(handle->wayland.subwidgets[i], draw, NULL);
recursive_draw(handle->wayland.subwidgets[i]);
}
}
}
static void recursive_resize(MwLL handle) {
int i;
if(handle->wayland.subwidgets != NULL) {
for(i = 0; i < arrlen(handle->wayland.subwidgets); i++) {
MwLLDispatch(handle->wayland.subwidgets[i], resize, NULL);
recursive_resize(handle->wayland.subwidgets[i]);
}
}
}
static void xdg_toplevel_configure(void* data,
struct xdg_toplevel* xdg_toplevel,
MwI32 width, MwI32 height,
@ -304,6 +324,7 @@ static void xdg_toplevel_configure(void* data,
MwLLSetWH(self, width, height);
MwLLDispatch(self, resize, NULL);
recursive_resize(self);
if(!self->wayland.egl_setup) {
self->wayland.egl_setup = egl_setup(self, width, height);
@ -405,11 +426,8 @@ 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);
}
recursive_draw(handle);
}
}
@ -463,16 +481,6 @@ static void setup_toplevel(MwLL r, int x, int y) {
return;
}
printf("Found globals: \n");
for(i = 0; i < shlen(r->wayland.wl_protocol_map); i++) {
wayland_protocol_t* proto = shget(r->wayland.wl_protocol_map, r->wayland.wl_protocol_map[i].key);
if(proto != NULL) {
printf("%s (%p)\n", r->wayland.wl_protocol_map[i].key, r->wayland.wl_protocol_map[i].value);
} else {
printf("%s (proto is null)\n", r->wayland.wl_protocol_map[i].key, r->wayland.wl_protocol_map[i].value);
}
}
// Check that all globals we require are available
if(
r->wayland.compositor == NULL ||
@ -506,12 +514,8 @@ static void setup_toplevel(MwLL r, int x, int y) {
xdg_toplevel_set_app_id(r->wayland.toplevel->xdg_top_level, "MilskoWaylandApp");
// Perform the initial commit and wait for the first configure event
region = wl_compositor_create_region(r->wayland.compositor);
wl_region_add(region, 0, 0, r->wayland.ww, r->wayland.wh);
wl_surface_set_opaque_region(r->wayland.surface, region);
wl_surface_commit(r->wayland.surface);
event_loop(r);
wl_region_destroy(region);
// setup decorations if we can
if(shget(r->wayland.wl_protocol_map, zxdg_decoration_manager_v1_interface.name) != NULL) {
@ -618,16 +622,13 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->wayland.x = x;
r->wayland.y = y;
printf("%d %d\n", x, y);
r->wayland.parent = parent;
r->wayland.force_redraw = MwFALSE;
r->common.success = MwTRUE;
r->wayland.drawn_once = MwFALSE;
r->wayland.subwidgets = NULL;
if(parent == NULL) {
printf("toplevel %d %d\n", x, y);
setup_toplevel(r, x, y);
} else {
setup_subsurface(parent, r, x, y);
@ -678,6 +679,7 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
int i, n;
float maxX = 0, maxY = 0;
float centerX, centerY;
int doLoopback = MwFALSE;
if(points_count > 3) {
/* To avoid having to do a real triangulation algorithim:
@ -702,7 +704,16 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
/* Efficient? No. But at the end of the day it's still not that many polygons, and if a computer can't handle 12 polygons over 6 then it should not be using Wayland anyways */
framebuffer_action_begin(handle);
glBegin(GL_TRIANGLE_FAN);
if(points_count == 3) {
glBegin(GL_TRIANGLES);
} else if((points_count % 3) == 0) {
glBegin(GL_POLYGON);
} else {
glBegin(GL_TRIANGLE_FAN);
doLoopback = MwTRUE;
}
for(i = 0; i < points_count; i++) {
float x = round(handle->wayland.x) + round(points[i].x);
float y = round(handle->wayland.y) + round(points[i].y);
@ -710,18 +721,37 @@ 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);
glVertex2f(x, y);
if(points_count > 3) {
if(doLoopback) {
glVertex2f(maxX, maxY);
glVertex2f(x, y);
}
}
glEnd();
glColor3f(0, 0, 0);
framebuffer_action_end(handle);
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
//
int i;
glLineWidth(1);
framebuffer_action_begin(handle);
glBegin(GL_LINES);
for(i = 0; i < 2; i++) {
float x = round(handle->wayland.x) + round(points[i].x);
float y = round(handle->wayland.y) + round(points[i].y);
glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0);
glVertex2f(x, y);
}
glEnd();
glColor3f(0, 0, 0);
framebuffer_action_end(handle);
}
static void MwLLEndDrawImpl(MwLL handle) {
@ -759,7 +789,6 @@ static void MwLLEndDrawImpl(MwLL handle) {
printf("error swapping buffers! %0X\n", eglGetError());
} else {
wl_surface_commit(handle->wayland.surface);
handle->wayland.drawn_once = MwTRUE;
}
}
@ -793,7 +822,7 @@ static void MwLLNextEventImpl(MwLL handle) {
MwBool render = handle->wayland.force_redraw;
if(render) {
MwLLDispatch(handle, draw, NULL);
recursive_draw(handle);
handle->wayland.force_redraw = MwFALSE;
}
}

View file

@ -332,8 +332,8 @@ void MwLoop(MwWidget handle) {
long more;
while(MwPending(handle)) {
if((v = MwStep(handle)) != 0) break;
MwLLEndDraw(handle->lowlevel);
}
MwLLEndDraw(handle->lowlevel);
if(v != 0) break;
for(i = 0; i < arrlen(handle->tick_list); i++) {