forked from pyrite-dev/milsko
h
This commit is contained in:
parent
495ea93c74
commit
82319aa616
2 changed files with 45 additions and 56 deletions
|
|
@ -315,13 +315,17 @@ static void xdg_toplevel_configure(void* data,
|
|||
MwLL self = data;
|
||||
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
|
||||
|
||||
if(width == 0 && height == 0) {
|
||||
if(width == 0 || height == 0) {
|
||||
width = self->wayland.ww;
|
||||
height = self->wayland.wh;
|
||||
// if it's still 0 then bail
|
||||
if(width == 0 || height == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self->wayland.ww = width;
|
||||
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);
|
||||
MwLLDispatch(self, resize, NULL);
|
||||
|
|
@ -369,18 +373,15 @@ static void xdg_surface_configure(
|
|||
self->wayland.configured = MwTRUE;
|
||||
}
|
||||
|
||||
static int event_loop(struct _MwLLWayland* wayland) {
|
||||
static int event_loop(MwLL handle) {
|
||||
enum {
|
||||
DISPLAY_FD,
|
||||
KEYREPEAT_FD,
|
||||
CURSOR_FD
|
||||
};
|
||||
struct pollfd fd;
|
||||
int timeout = 100;
|
||||
|
||||
if(wayland->force_redraw) {
|
||||
return 1;
|
||||
}
|
||||
struct pollfd fd;
|
||||
int timeout = 100;
|
||||
struct _MwLLWayland* wayland = &handle->wayland;
|
||||
|
||||
if(wayland->display == NULL) {
|
||||
return 0;
|
||||
|
|
@ -388,12 +389,6 @@ static int event_loop(struct _MwLLWayland* wayland) {
|
|||
fd.fd = wl_display_get_fd(wayland->display);
|
||||
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 */
|
||||
while(wl_display_flush(wayland->display) == -1) {
|
||||
if(errno != EAGAIN) {
|
||||
|
|
@ -433,8 +428,11 @@ static int event_loop(struct _MwLLWayland* wayland) {
|
|||
if(wl_display_dispatch_pending(wayland->display) > 0) {
|
||||
}
|
||||
} else {
|
||||
wl_display_cancel_read(wayland->display);
|
||||
if(wl_display_dispatch_pending(wayland->display) == 0) {
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
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_surface_set_opaque_region(r->wayland.surface, region);
|
||||
wl_surface_commit(r->wayland.surface);
|
||||
event_loop(&r->wayland);
|
||||
event_loop(r);
|
||||
wl_region_destroy(region);
|
||||
|
||||
printf("%p\n", shget(r->wayland.wl_protocol_map, zxdg_decoration_manager_v1_interface.name));
|
||||
|
||||
// setup decorations if we can
|
||||
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;
|
||||
|
|
@ -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_surface_set_opaque_region(r->wayland.surface, region);
|
||||
wl_surface_commit(r->wayland.surface);
|
||||
event_loop(&r->wayland);
|
||||
event_loop(r);
|
||||
wl_region_destroy(region);
|
||||
|
||||
r->wayland.subsurface = wl_subcompositor_get_subsurface(subcompositor, r->wayland.surface, parent_surface);
|
||||
|
|
@ -628,13 +624,17 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
|||
if(width == 0) width = 1;
|
||||
if(height == 0) height = 1;
|
||||
|
||||
r->wayland.ww = width;
|
||||
r->wayland.wh = height;
|
||||
r->wayland.ww = width;
|
||||
r->wayland.wh = height;
|
||||
printf("%d %d\n", x, y);
|
||||
|
||||
r->wayland.parent = parent;
|
||||
|
||||
r->wayland.force_redraw = MwFALSE;
|
||||
r->common.success = MwTRUE;
|
||||
|
||||
r->wayland.x = x;
|
||||
r->wayland.y = y;
|
||||
if(parent == NULL) {
|
||||
setup_toplevel(r, x, y);
|
||||
} else {
|
||||
|
|
@ -668,14 +668,16 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
|||
|
||||
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
||||
/* 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;
|
||||
}
|
||||
handle->wayland.ww = w;
|
||||
handle->wayland.wh = h;
|
||||
|
||||
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 {
|
||||
}
|
||||
}
|
||||
|
|
@ -685,6 +687,8 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
|
|||
float maxX = 0, maxY = 0;
|
||||
float centerX, centerY;
|
||||
|
||||
glLineWidth(5);
|
||||
|
||||
if(points_count > 3) {
|
||||
/* To avoid having to do a real triangulation algorithim:
|
||||
1.) loop through the points once to determine the bounds of the polygon
|
||||
|
|
@ -707,46 +711,23 @@ 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 */
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
framebuffer_action_begin(handle);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glBegin(GL_TRIANGLES);
|
||||
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);
|
||||
|
||||
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) {
|
||||
if(points_count > 4) {
|
||||
glVertex2f(maxX, maxY);
|
||||
glVertex2f(x, y);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
framebuffer_action_end(handle);
|
||||
}
|
||||
|
|
@ -767,11 +748,12 @@ static void MwLLEndDrawImpl(MwLL handle) {
|
|||
h = parent->wayland.wh;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(1.0, 0, 0, 1);
|
||||
glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture);
|
||||
// glClear(GL_COLOR_BUFFER_BIT);
|
||||
// glClearColor(0, 0, 0, 1);
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 1);
|
||||
|
|
@ -814,7 +796,7 @@ static void MwLLFreeColorImpl(MwLLColor color) {
|
|||
}
|
||||
|
||||
static int MwLLPendingImpl(MwLL handle) {
|
||||
return event_loop(&handle->wayland);
|
||||
return event_loop(handle) || handle->wayland.force_redraw;
|
||||
}
|
||||
|
||||
static void MwLLNextEventImpl(MwLL handle) {
|
||||
|
|
@ -881,6 +863,8 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
|
|||
glActiveTexture(pixmap->wayland.texture);
|
||||
|
||||
framebuffer_action_begin(handle);
|
||||
// glClear(GL_COLOR_BUFFER_BIT);
|
||||
glColor3f(1, 1, 1);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0);
|
||||
glVertex2f(x, y);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
static void lldrawhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
int ind;
|
||||
|
||||
(void)data;
|
||||
|
||||
|
|
@ -14,6 +15,12 @@ static void lldrawhandler(MwLL handle, void* data) {
|
|||
MwDispatch(h, draw);
|
||||
if(h->draw_inject != NULL) h->draw_inject(h);
|
||||
MwDispatchUserHandler(h, MwNdrawHandler, NULL);
|
||||
|
||||
if(h->parent == NULL) {
|
||||
MwLLEndDraw(h->lowlevel);
|
||||
} else if(h->parent->lowlevel == NULL) {
|
||||
MwLLEndDraw(h->lowlevel);
|
||||
}
|
||||
}
|
||||
|
||||
static void lluphandler(MwLL handle, void* data) {
|
||||
|
|
@ -334,8 +341,6 @@ void MwLoop(MwWidget handle) {
|
|||
}
|
||||
if(v != 0) break;
|
||||
|
||||
MwLLEndDraw(handle->lowlevel);
|
||||
|
||||
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
||||
MwDispatch(handle->tick_list[i], tick);
|
||||
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue