diff --git a/Makefile.pl b/Makefile.pl index 2d42299..4f5d5d5 100755 --- a/Makefile.pl +++ b/Makefile.pl @@ -173,8 +173,11 @@ print(OUT "\n"); print(OUT "all: lib examples\n"); print(OUT "\n"); print(OUT "install: lib\n"); -print(OUT " mkdir -p \$(DESTDIR)\$(PREFIX)/lib \$(DESTDIR)\$(PREFIX)/include\n"); -print(OUT " -cp src/${library_prefix}Mw${library_suffix} \$(DESTDIR)\$(PREFIX)/lib/\n"); +print(OUT + " mkdir -p \$(DESTDIR)\$(PREFIX)/lib \$(DESTDIR)\$(PREFIX)/include\n"); +print(OUT +" -cp src/${library_prefix}Mw${library_suffix} \$(DESTDIR)\$(PREFIX)/lib/\n" +); print(OUT " -cp src/libMw.a \$(DESTDIR)\$(PREFIX)/lib/\n"); print(OUT " cp -rf include \$(DESTDIR)\$(PREFIX)/\n"); print(OUT "\n"); diff --git a/include/Mw/BaseTypes.h b/include/Mw/BaseTypes.h index ca718ea..1014869 100644 --- a/include/Mw/BaseTypes.h +++ b/include/Mw/BaseTypes.h @@ -58,8 +58,8 @@ typedef unsigned long MwU64; #ifdef MW_OTHER_TYPES_DEFINED #undef MW_OTHER_TYPES_DEFINED #else -typedef int MwI32; -typedef unsigned int MwU32; +typedef int MwI32; +typedef unsigned int MwU32; typedef short MwI16; typedef unsigned short MwU16; diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index cc334e0..b37bd45 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -15,6 +15,7 @@ #include #include +#include MWDECL int MwLLWaylandCallInit(void); @@ -103,6 +104,9 @@ struct _MwLLWayland { void* mapped_shm_buf; MwU64 mapped_shm_buf_size; int shm_fd; + + cairo_surface_t* cs; + cairo_t* cairo; }; struct _MwLLWaylandColor { diff --git a/pl/ostype/Linux.pl b/pl/ostype/Linux.pl index d87b738..155cd4a 100644 --- a/pl/ostype/Linux.pl +++ b/pl/ostype/Linux.pl @@ -1,6 +1,7 @@ -if(param_get("experimental-wayland")) { - use_backend("wayland","x11"); -} else { +if (param_get("experimental-wayland")) { + use_backend("wayland", "x11"); +} +else { use_backend("x11"); } diff --git a/pl/rules.pl b/pl/rules.pl index 96d7a8e..fc88c10 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -29,8 +29,8 @@ if (grep(/^gdi$/, @backends)) { if (grep(/^wayland$/, @backends)) { add_cflags("-DUSE_WAYLAND"); new_object("src/backend/wayland.c"); - add_cflags(`pkg-config --cflags wayland-client xkbcommon`); - add_libs(`pkg-config --libs wayland-client xkbcommon`); + add_cflags(`pkg-config --cflags cairo wayland-client xkbcommon`); + add_libs(`pkg-config --libs cairo wayland-client xkbcommon`); scan_wayland_protocol("stable", "xdg-shell", ""); scan_wayland_protocol("stable", "tablet", "-v2"); diff --git a/src/backend/wayland.c b/src/backend/wayland.c index be24dbc..b034ab4 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -38,20 +38,18 @@ static void new_protocol(void* data, struct wl_registry* registry, /* `wl_registry.global_remove` callback */ static void protocol_removed(void* data, struct wl_registry* registry, - MwU32 name) { + MwU32 name){ }; /* `wl_pointer.enter` callback */ static void pointer_enter(void* data, struct wl_pointer* wl_pointer, MwU32 serial, struct wl_surface* surface, wl_fixed_t surface_x, - wl_fixed_t surface_y) { -}; + wl_fixed_t surface_y){}; /* `wl_pointer.leave` callback */ static void pointer_leave(void* data, struct wl_pointer* wl_pointer, MwU32 serial, - struct wl_surface* surface) { -}; + struct wl_surface* surface){}; /* `wl_pointer.motion` callback */ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time, @@ -93,12 +91,13 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri break; } } + MwLLDispatch(self, draw, NULL); }; /* `wl_pointer.axis` callback */ static void pointer_axis(void* data, struct wl_pointer* wl_pointer, MwU32 time, - MwU32 axis, wl_fixed_t value) {}; + MwU32 axis, wl_fixed_t value){}; struct wl_pointer_listener pointer_listener = { .enter = pointer_enter, @@ -267,7 +266,7 @@ static void keyboard_modifiers(void* data, MwU32 mods_depressed, MwU32 mods_latched, MwU32 mods_locked, - MwU32 group) {}; + MwU32 group){}; struct wl_keyboard_listener keyboard_listener = { .keymap = keyboard_keymap, @@ -279,7 +278,7 @@ struct wl_keyboard_listener keyboard_listener = { /* `wl_seat.name` callback */ static void -wl_seat_name(void* data, struct wl_seat* wl_seat, const char* name) {}; +wl_seat_name(void* data, struct wl_seat* wl_seat, const char* name){}; /* `wl_seat.capabilities` callback */ static void wl_seat_capabilities(void* data, struct wl_seat* wl_seat, @@ -393,7 +392,13 @@ static void xdg_toplevel_configure(void* data, self->wayland.wh = height; xdg_surface_set_window_geometry(self->wayland.toplevel->xdg_surface, 0, 0, self->wayland.ww, self->wayland.wh); + cairo_destroy(self->wayland.cairo); + cairo_surface_destroy(self->wayland.cs); + self->wayland.cs = cairo_image_surface_create_for_data(self->wayland.mapped_shm_buf, CAIRO_FORMAT_ARGB32, width, height, 4 * width); + self->wayland.cairo = cairo_create(self->wayland.cs); + MwLLDispatch(self, resize, NULL); + MwLLDispatch(self, draw, NULL); /*if(!self->wayland.egl_setup) { self->wayland.egl_setup = egl_setup(self, self->wayland.x, self->wayland.y, width, height); @@ -544,7 +549,6 @@ static int event_loop(MwLL handle) { /* Function for setting up the callbacks/structs that will be registered upon the relevant interfaces being found. */ static void setup_callbacks(struct _MwLLWayland* wayland) { - /* Convience macro for adding the interface functions to the setup map */ #define WL_INTERFACE(interface) \ shput(wayland->wl_protocol_setup_map, interface##_interface.name, (wl_setup_func*)interface##_setup); @@ -677,8 +681,8 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { r->common.type = MwLLBackendWayland; - if(width == 0) width = 1; - if(height == 0) height = 1; + if(width < 2) width = 2; + if(height < 2) height = 2; if(x == MwDEFAULT) { x = 0; @@ -701,15 +705,23 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { } /* example of writing to the buffer */ - memset(r->wayland.mapped_shm_buf, 127, r->wayland.mapped_shm_buf_size); + memset(r->wayland.mapped_shm_buf, 255, r->wayland.mapped_shm_buf_size); update_buffer(r); + r->wayland.cs = cairo_image_surface_create_for_data(r->wayland.mapped_shm_buf, CAIRO_FORMAT_ARGB32, width, height, 4 * width); + r->wayland.cairo = cairo_create(r->wayland.cs); + + MwLLForceRender(r); + return r; } static void MwLLDestroyImpl(MwLL handle) { MwLLDestroyCommon(handle); + cairo_destroy(handle->wayland.cairo); + cairo_surface_destroy(handle->wayland.cs); + munmap(handle->wayland.mapped_shm_buf, handle->wayland.mapped_shm_buf_size); wl_buffer_destroy(handle->wayland.mapped_shm_buf); wl_shm_pool_destroy(handle->wayland.shm_pool); @@ -734,7 +746,10 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) { } else if(x != 0 && y != 0) { handle->wayland.has_set_xy = MwTRUE; }*/ + + wl_subsurface_set_position(handle->wayland.sublevel->subsurface, x, y); } + MwLLDispatch(handle, draw, NULL); } static void MwLLSetWHImpl(MwLL handle, int w, int h) { @@ -753,40 +768,47 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) { /* timed_redraw_by_epoch(handle->wayland.topmost_parent, 25); recursive_draw(handle->wayland.topmost_parent); */ } + MwLLDispatch(handle, draw, NULL); } static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { - /* todo */ + int i; + + cairo_set_source_rgb(handle->wayland.cairo, color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0); + cairo_new_path(handle->wayland.cairo); + for(i = 0; i < points_count; i++) { + if(i == 0) { + cairo_move_to(handle->wayland.cairo, points[i].x, points[i].y); + } else { + cairo_line_to(handle->wayland.cairo, points[i].x, points[i].y); + } + } + cairo_close_path(handle->wayland.cairo); + cairo_fill(handle->wayland.cairo); } static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { - /* todo */ + int i; + + cairo_set_line_cap(handle->wayland.cairo, CAIRO_LINE_CAP_SQUARE); + cairo_set_source_rgb(handle->wayland.cairo, color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0); + cairo_new_path(handle->wayland.cairo); + for(i = 0; i < 2; i++) { + if(i == 0) { + cairo_move_to(handle->wayland.cairo, points[i].x, points[i].y); + } else { + cairo_line_to(handle->wayland.cairo, points[i].x, points[i].y); + } + } + cairo_close_path(handle->wayland.cairo); + cairo_stroke(handle->wayland.cairo); } static void MwLLBeginDrawImpl(MwLL handle) { - /* if(handle->wayland.parent == NULL) { - 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; - } - }*/ } static void MwLLEndDrawImpl(MwLL handle) { - int w, h; - - /*recursive_draw(handle);*/ - - /* glClear(GL_COLOR_BUFFER_BIT); */ - /* glClearColor(1.0, 0, 0, 1); */ - - /* if(handle->wayland.parent == NULL) { - if(!eglSwapBuffers(handle->wayland.egl_display, handle->wayland.egl_surface)) { - printf("error swapping buffers! %0X\n", eglGetError()); - } else { - wl_surface_commit(handle->wayland.surface); - } -}*/ + update_buffer(handle); } static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { @@ -825,9 +847,9 @@ static void MwLLSetTitleImpl(MwLL handle, const char* title) { static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) { MwLLPixmap r = malloc(sizeof(*r)); - r->common.width = width; - r->common.height = height; - r->common.raw = malloc(4 * width * height); + r->common.width = width; + r->common.height = height; + r->common.raw = malloc(4 * width * height); memcpy(r->common.raw, data, 4 * width * height); MwLLPixmapUpdate(r); @@ -840,11 +862,21 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap r) { } static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { + free(pixmap->common.raw); free(pixmap); } static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { - /* todo */ + int y, x; + for(y = rect->y; y < rect->y + rect->height; y++) { + if(y < 0 || y >= handle->wayland.wh) continue; + for(x = rect->x; x < rect->x + rect->width; x++) { + if(x < 0 || x >= handle->wayland.ww) continue; + + /* TODO */ + //((unsigned char*)handle->wayland.mapped_shm_buf)[(x + y * handle->wayland.ww) * 4 + 0] = 0x80; + } + } } static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { } diff --git a/src/draw.c b/src/draw.c index 636dc78..f8489dc 100644 --- a/src/draw.c +++ b/src/draw.c @@ -109,7 +109,9 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { int ColorDiff = get_color_diff(handle); double darkenStep = (ColorDiff / 2.) / rect->height; unsigned long sz = rect->width * rect->height * 4; - unsigned char* data = malloc(sz); + unsigned char* data; + + data = malloc(sz); memset(data, 0, sz); for(y = 0; y < rect->height; y++) { diff --git a/src/widget/frame.c b/src/widget/frame.c index 38ff990..294f110 100644 --- a/src/widget/frame.c +++ b/src/widget/frame.c @@ -29,7 +29,6 @@ static void draw(MwWidget handle) { rr.width = MwGetInteger(handle, MwNwidth) - (MwDefaultBorderWidth(handle) * 2); rr.height = MwGetInteger(handle, MwNheight) - (MwDefaultBorderWidth(handle) * 2); } else { - rr.x = 0; rr.y = 0; rr.width = MwGetInteger(handle, MwNwidth); diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 784594b..1841594 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -258,7 +258,6 @@ static void frame_draw(MwWidget handle) { if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle); if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) { - p.x += 4; MwDrawText(handle, &p, str, 0, MwALIGNMENT_BEGINNING, selected ? base2 : text2); p.x -= 4; diff --git a/src/widget/opengl.c b/src/widget/opengl.c index 9552ae4..8c3b1ac 100644 --- a/src/widget/opengl.c +++ b/src/widget/opengl.c @@ -89,7 +89,8 @@ static int create(MwWidget handle) { attribs[3] = 24; attribs[4] = None; - while(glpath[glincr] != NULL && (o->lib = MwDynamicOpen(glpath[glincr++])) == NULL); + while(glpath[glincr] != NULL && (o->lib = MwDynamicOpen(glpath[glincr++])) == NULL) + ; o->glXChooseVisual = (MWglXChooseVisual)MwDynamicSymbol(o->lib, "glXChooseVisual"); o->glXCreateContext = (MWglXCreateContext)MwDynamicSymbol(o->lib, "glXCreateContext"); diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index e00d0b5..4058c81 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -144,7 +144,7 @@ static void draw(MwWidget handle) { } static void mouse_move(MwWidget handle) { - int or = MwGetInteger(handle, MwNorientation); + int or = MwGetInteger(handle, MwNorientation); scrollbar_t* scr = handle->internal; if(!handle->pressed) return; @@ -172,9 +172,9 @@ static void mouse_move(MwWidget handle) { } static void mouse_down(MwWidget handle, void* ptr) { - int ww = MwGetInteger(handle, MwNwidth); - int wh = MwGetInteger(handle, MwNheight); - int or = MwGetInteger(handle, MwNorientation); + int ww = MwGetInteger(handle, MwNwidth); + int wh = MwGetInteger(handle, MwNheight); + int or = MwGetInteger(handle, MwNorientation); scrollbar_t* scr = handle->internal; MwLLMouse* m = ptr;