Unfinished Wayland PR #1
6 changed files with 45 additions and 32 deletions
swap buffers in draw handler instead
commit
39533b3fec
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,7 +1,6 @@
|
||||||
*.o
|
*.o
|
||||||
*.so
|
*.so
|
||||||
*.dll
|
*.dll
|
||||||
examples/*
|
|
||||||
examples/*.exe
|
examples/*.exe
|
||||||
examples/*/*
|
examples/*/*
|
||||||
!examples/*/*.c
|
!examples/*/*.c
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ int main() {
|
||||||
MwLibraryInit();
|
MwLibraryInit();
|
||||||
|
|
||||||
window = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 8 + 16 + 8 + 16 * 10 + 8, 8 + 16 + 8 + 16 + 8,
|
window = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 8 + 16 + 8 + 16 * 10 + 8, 8 + 16 + 8 + 16 + 8,
|
||||||
MwNtitle, "checkbox",
|
MwNtitle, "checkbox",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwVaCreateWidget(MwCheckBoxClass, "cb1", window, 8, 8, 16, 16,
|
MwVaCreateWidget(MwCheckBoxClass, "cb1", window, 8, 8, 16, 16,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ struct _MwLLCommon {
|
||||||
int copy_buffer;
|
int copy_buffer;
|
||||||
int type;
|
int type;
|
||||||
int success;
|
int success;
|
||||||
|
int do_redraw;
|
||||||
|
|
||||||
MwLLHandler handler;
|
MwLLHandler handler;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -315,13 +315,17 @@ static void xdg_toplevel_configure(void* data,
|
||||||
MwLL self = data;
|
MwLL self = data;
|
||||||
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
|
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
|
||||||
|
|
||||||
if(width == 0 && height == 0) {
|
if(width == 0 || height == 0) {
|
||||||
width = self->wayland.ww;
|
width = self->wayland.ww;
|
||||||
height = self->wayland.wh;
|
height = self->wayland.wh;
|
||||||
|
// if it's still 0 then bail
|
||||||
|
if(width == 0 || height == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self->wayland.ww = width;
|
self->wayland.ww = width;
|
||||||
self->wayland.wh = height;
|
self->wayland.wh = height;
|
||||||
xdg_surface_set_window_geometry(self->wayland.toplevel->xdg_surface, self->wayland.x, self->wayland.y, self->wayland.ww, self->wayland.wh);
|
xdg_surface_set_window_geometry(self->wayland.toplevel->xdg_surface, 0, 0, self->wayland.ww, self->wayland.wh);
|
||||||
|
|
||||||
MwLLSetWH(self, width, height);
|
MwLLSetWH(self, width, height);
|
||||||
MwLLDispatch(self, resize, NULL);
|
MwLLDispatch(self, resize, NULL);
|
||||||
|
|
@ -369,18 +373,15 @@ static void xdg_surface_configure(
|
||||||
self->wayland.configured = MwTRUE;
|
self->wayland.configured = MwTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int event_loop(struct _MwLLWayland* wayland) {
|
static int event_loop(MwLL handle) {
|
||||||
enum {
|
enum {
|
||||||
DISPLAY_FD,
|
DISPLAY_FD,
|
||||||
KEYREPEAT_FD,
|
KEYREPEAT_FD,
|
||||||
CURSOR_FD
|
CURSOR_FD
|
||||||
};
|
};
|
||||||
struct pollfd fd;
|
struct pollfd fd;
|
||||||
int timeout = 100;
|
int timeout = 100;
|
||||||
|
struct _MwLLWayland* wayland = &handle->wayland;
|
||||||
if(wayland->force_redraw) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(wayland->display == NULL) {
|
if(wayland->display == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -388,12 +389,6 @@ static int event_loop(struct _MwLLWayland* wayland) {
|
||||||
fd.fd = wl_display_get_fd(wayland->display);
|
fd.fd = wl_display_get_fd(wayland->display);
|
||||||
fd.events = POLLIN;
|
fd.events = POLLIN;
|
||||||
|
|
||||||
while(wl_display_prepare_read(wayland->display) != 0) {
|
|
||||||
if(wl_display_dispatch_pending(wayland->display) > 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If an error other than EAGAIN happens, we have likely been disconnected from the Wayland session */
|
/* If an error other than EAGAIN happens, we have likely been disconnected from the Wayland session */
|
||||||
while(wl_display_flush(wayland->display) == -1) {
|
while(wl_display_flush(wayland->display) == -1) {
|
||||||
if(errno != EAGAIN) {
|
if(errno != EAGAIN) {
|
||||||
|
|
@ -433,8 +428,11 @@ static int event_loop(struct _MwLLWayland* wayland) {
|
||||||
if(wl_display_dispatch_pending(wayland->display) > 0) {
|
if(wl_display_dispatch_pending(wayland->display) > 0) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wl_display_cancel_read(wayland->display);
|
if(wl_display_dispatch_pending(wayland->display) == 0) {
|
||||||
|
MwLLDispatch(handle, draw, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,11 +530,9 @@ static void setup_toplevel(MwLL r, int x, int y) {
|
||||||
wl_region_add(region, 0, 0, r->wayland.ww, r->wayland.wh);
|
wl_region_add(region, 0, 0, r->wayland.ww, r->wayland.wh);
|
||||||
wl_surface_set_opaque_region(r->wayland.surface, region);
|
wl_surface_set_opaque_region(r->wayland.surface, region);
|
||||||
wl_surface_commit(r->wayland.surface);
|
wl_surface_commit(r->wayland.surface);
|
||||||
event_loop(&r->wayland);
|
event_loop(r);
|
||||||
wl_region_destroy(region);
|
wl_region_destroy(region);
|
||||||
|
|
||||||
printf("%p\n", shget(r->wayland.wl_protocol_map, zxdg_decoration_manager_v1_interface.name));
|
|
||||||
|
|
||||||
// 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) {
|
||||||
zxdg_decoration_manager_v1_context_t* dec = WAYLAND_GET_INTERFACE(r->wayland, zxdg_decoration_manager_v1)->context;
|
zxdg_decoration_manager_v1_context_t* dec = WAYLAND_GET_INTERFACE(r->wayland, zxdg_decoration_manager_v1)->context;
|
||||||
|
|
@ -576,7 +572,7 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y) {
|
||||||
wl_region_add(region, 0, 0, r->wayland.ww, r->wayland.wh);
|
wl_region_add(region, 0, 0, r->wayland.ww, r->wayland.wh);
|
||||||
wl_surface_set_opaque_region(r->wayland.surface, region);
|
wl_surface_set_opaque_region(r->wayland.surface, region);
|
||||||
wl_surface_commit(r->wayland.surface);
|
wl_surface_commit(r->wayland.surface);
|
||||||
event_loop(&r->wayland);
|
event_loop(r);
|
||||||
wl_region_destroy(region);
|
wl_region_destroy(region);
|
||||||
|
|
||||||
r->wayland.subsurface = wl_subcompositor_get_subsurface(subcompositor, r->wayland.surface, parent_surface);
|
r->wayland.subsurface = wl_subcompositor_get_subsurface(subcompositor, r->wayland.surface, parent_surface);
|
||||||
|
|
@ -628,13 +624,18 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
if(width == 0) width = 1;
|
if(width == 0) width = 1;
|
||||||
if(height == 0) height = 1;
|
if(height == 0) height = 1;
|
||||||
|
|
||||||
r->wayland.ww = width;
|
r->wayland.ww = width;
|
||||||
r->wayland.wh = height;
|
r->wayland.wh = height;
|
||||||
|
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.x = x;
|
||||||
|
r->wayland.y = y;
|
||||||
if(parent == NULL) {
|
if(parent == NULL) {
|
||||||
setup_toplevel(r, x, y);
|
setup_toplevel(r, x, y);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -668,14 +669,16 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
||||||
|
|
||||||
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
||||||
/* Prevent an integer underflow when the w/h is too low */
|
/* Prevent an integer underflow when the w/h is too low */
|
||||||
if(w < 10 || h < 10) {
|
if((w < 10 || h < 10)) {
|
||||||
|
handle->wayland.ww = 10;
|
||||||
|
handle->wayland.wh = 10;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handle->wayland.ww = w;
|
handle->wayland.ww = w;
|
||||||
handle->wayland.wh = h;
|
handle->wayland.wh = h;
|
||||||
|
|
||||||
if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) {
|
if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) {
|
||||||
xdg_surface_set_window_geometry(handle->wayland.toplevel->xdg_surface, handle->wayland.x, handle->wayland.y, handle->wayland.ww, handle->wayland.wh);
|
xdg_surface_set_window_geometry(handle->wayland.toplevel->xdg_surface, 0, 0, handle->wayland.ww, handle->wayland.wh);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -769,7 +772,7 @@ static void MwLLEndDrawImpl(MwLL handle) {
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture);
|
glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture);
|
||||||
// glClear(GL_COLOR_BUFFER_BIT);
|
// glClear(GL_COLOR_BUFFER_BIT);
|
||||||
// glClearColor(0, 0, 0, 1);
|
// glClearColor(1.0, 0, 0, 1);
|
||||||
|
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
|
@ -790,6 +793,7 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -814,7 +818,9 @@ static void MwLLFreeColorImpl(MwLLColor color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int MwLLPendingImpl(MwLL handle) {
|
static int MwLLPendingImpl(MwLL handle) {
|
||||||
return event_loop(&handle->wayland);
|
if(wl_display_dispatch_pending(handle->wayland.display) == 0) {
|
||||||
|
}
|
||||||
|
return event_loop(handle) || handle->wayland.force_redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MwLLNextEventImpl(MwLL handle) {
|
static void MwLLNextEventImpl(MwLL handle) {
|
||||||
|
|
|
||||||
10
src/core.c
10
src/core.c
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
static void lldrawhandler(MwLL handle, void* data) {
|
static void lldrawhandler(MwLL handle, void* data) {
|
||||||
MwWidget h = (MwWidget)handle->common.user;
|
MwWidget h = (MwWidget)handle->common.user;
|
||||||
|
int ind;
|
||||||
|
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
|
|
@ -14,6 +15,13 @@ static void lldrawhandler(MwLL handle, void* data) {
|
||||||
MwDispatch(h, draw);
|
MwDispatch(h, draw);
|
||||||
if(h->draw_inject != NULL) h->draw_inject(h);
|
if(h->draw_inject != NULL) h->draw_inject(h);
|
||||||
MwDispatchUserHandler(h, MwNdrawHandler, NULL);
|
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) {
|
static void lluphandler(MwLL handle, void* data) {
|
||||||
|
|
@ -334,8 +342,6 @@ void MwLoop(MwWidget handle) {
|
||||||
}
|
}
|
||||||
if(v != 0) break;
|
if(v != 0) break;
|
||||||
|
|
||||||
MwLLEndDraw(handle->lowlevel);
|
|
||||||
|
|
||||||
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
||||||
MwDispatch(handle->tick_list[i], tick);
|
MwDispatch(handle->tick_list[i], tick);
|
||||||
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
|
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue