Unfinished Wayland PR #1
3 changed files with 58 additions and 30 deletions
recursive updating
commit
d308c83fc2
|
|
@ -84,7 +84,6 @@ struct _MwLLWayland {
|
||||||
MwBool configured;
|
MwBool configured;
|
||||||
MwBool force_redraw;
|
MwBool force_redraw;
|
||||||
MwBool egl_setup;
|
MwBool egl_setup;
|
||||||
MwBool drawn_once;
|
|
||||||
MwBool egl_do_resetup;
|
MwBool egl_do_resetup;
|
||||||
MwU32 x, y, ww, wh;
|
MwU32 x, y, ww, wh;
|
||||||
int z_index;
|
int z_index;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <wayland-client-protocol.h>
|
#include <wayland-client-protocol.h>
|
||||||
|
|
||||||
#include "../../external/stb_ds.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_display = display;
|
||||||
self->wayland.egl_surface = surface;
|
self->wayland.egl_surface = surface;
|
||||||
self->wayland.egl_context = context;
|
self->wayland.egl_context = context;
|
||||||
printf("EGL success\n");
|
|
||||||
return MwTRUE;
|
return MwTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,6 +283,26 @@ static void egl_resetup(MwLL handle) {
|
||||||
handle->wayland.egl_do_resetup = MwFALSE;
|
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,
|
static void xdg_toplevel_configure(void* data,
|
||||||
struct xdg_toplevel* xdg_toplevel,
|
struct xdg_toplevel* xdg_toplevel,
|
||||||
MwI32 width, MwI32 height,
|
MwI32 width, MwI32 height,
|
||||||
|
|
@ -304,6 +324,7 @@ static void xdg_toplevel_configure(void* data,
|
||||||
|
|
||||||
MwLLSetWH(self, width, height);
|
MwLLSetWH(self, width, height);
|
||||||
MwLLDispatch(self, resize, NULL);
|
MwLLDispatch(self, resize, NULL);
|
||||||
|
recursive_resize(self);
|
||||||
|
|
||||||
if(!self->wayland.egl_setup) {
|
if(!self->wayland.egl_setup) {
|
||||||
self->wayland.egl_setup = egl_setup(self, width, height);
|
self->wayland.egl_setup = egl_setup(self, width, height);
|
||||||
|
|
@ -405,11 +426,8 @@ static int event_loop(MwLL handle) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(wl_display_dispatch_pending(wayland->display) == 0) {
|
if(wl_display_dispatch_pending(wayland->display) == 0) {
|
||||||
int i;
|
|
||||||
MwLLDispatch(handle, draw, NULL);
|
MwLLDispatch(handle, draw, NULL);
|
||||||
for(i = 0; i < arrlen(handle->wayland.subwidgets); i++) {
|
recursive_draw(handle);
|
||||||
MwLLDispatch(handle->wayland.subwidgets[i], draw, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -463,16 +481,6 @@ static void setup_toplevel(MwLL r, int x, int y) {
|
||||||
return;
|
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
|
// Check that all globals we require are available
|
||||||
if(
|
if(
|
||||||
r->wayland.compositor == NULL ||
|
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");
|
xdg_toplevel_set_app_id(r->wayland.toplevel->xdg_top_level, "MilskoWaylandApp");
|
||||||
|
|
||||||
// Perform the initial commit and wait for the first configure event
|
// 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);
|
wl_surface_commit(r->wayland.surface);
|
||||||
event_loop(r);
|
event_loop(r);
|
||||||
wl_region_destroy(region);
|
|
||||||
|
|
||||||
// setup decorations if we can
|
// setup decorations if we can
|
||||||
if(shget(r->wayland.wl_protocol_map, zxdg_decoration_manager_v1_interface.name) != NULL) {
|
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.x = x;
|
||||||
r->wayland.y = y;
|
r->wayland.y = y;
|
||||||
|
|
||||||
printf("%d %d\n", x, y);
|
|
||||||
|
|
||||||
r->wayland.parent = parent;
|
r->wayland.parent = parent;
|
||||||
|
|
||||||
r->wayland.force_redraw = MwFALSE;
|
r->wayland.force_redraw = MwFALSE;
|
||||||
r->common.success = MwTRUE;
|
r->common.success = MwTRUE;
|
||||||
r->wayland.drawn_once = MwFALSE;
|
r->wayland.subwidgets = NULL;
|
||||||
|
|
||||||
if(parent == NULL) {
|
if(parent == NULL) {
|
||||||
printf("toplevel %d %d\n", x, y);
|
|
||||||
setup_toplevel(r, x, y);
|
setup_toplevel(r, x, y);
|
||||||
} else {
|
} else {
|
||||||
setup_subsurface(parent, r, x, y);
|
setup_subsurface(parent, r, x, y);
|
||||||
|
|
@ -678,6 +679,7 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
|
||||||
int i, n;
|
int i, n;
|
||||||
float maxX = 0, maxY = 0;
|
float maxX = 0, maxY = 0;
|
||||||
float centerX, centerY;
|
float centerX, centerY;
|
||||||
|
int doLoopback = MwFALSE;
|
||||||
|
|
||||||
if(points_count > 3) {
|
if(points_count > 3) {
|
||||||
/* To avoid having to do a real triangulation algorithim:
|
/* 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 */
|
/* 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);
|
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++) {
|
for(i = 0; i < points_count; i++) {
|
||||||
float x = round(handle->wayland.x) + round(points[i].x);
|
float x = round(handle->wayland.x) + round(points[i].x);
|
||||||
float y = round(handle->wayland.y) + round(points[i].y);
|
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);
|
glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0);
|
||||||
|
|
||||||
glVertex2f(x, y);
|
glVertex2f(x, y);
|
||||||
if(points_count > 3) {
|
if(doLoopback) {
|
||||||
glVertex2f(maxX, maxY);
|
glVertex2f(maxX, maxY);
|
||||||
glVertex2f(x, y);
|
glVertex2f(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
glColor3f(0, 0, 0);
|
||||||
|
|
||||||
framebuffer_action_end(handle);
|
framebuffer_action_end(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
|
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) {
|
static void MwLLEndDrawImpl(MwLL handle) {
|
||||||
|
|
@ -759,7 +789,6 @@ static void MwLLEndDrawImpl(MwLL handle) {
|
||||||
printf("error swapping buffers! %0X\n", eglGetError());
|
printf("error swapping buffers! %0X\n", eglGetError());
|
||||||
} else {
|
} else {
|
||||||
wl_surface_commit(handle->wayland.surface);
|
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;
|
MwBool render = handle->wayland.force_redraw;
|
||||||
|
|
||||||
if(render) {
|
if(render) {
|
||||||
MwLLDispatch(handle, draw, NULL);
|
recursive_draw(handle);
|
||||||
handle->wayland.force_redraw = MwFALSE;
|
handle->wayland.force_redraw = MwFALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -332,8 +332,8 @@ void MwLoop(MwWidget handle) {
|
||||||
long more;
|
long more;
|
||||||
while(MwPending(handle)) {
|
while(MwPending(handle)) {
|
||||||
if((v = MwStep(handle)) != 0) break;
|
if((v = MwStep(handle)) != 0) break;
|
||||||
MwLLEndDraw(handle->lowlevel);
|
|
||||||
}
|
}
|
||||||
|
MwLLEndDraw(handle->lowlevel);
|
||||||
if(v != 0) break;
|
if(v != 0) break;
|
||||||
|
|
||||||
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue