some stuffs work

This commit is contained in:
NishiOwO
2025-12-15 11:05:20 +09:00
parent 4951e8995e
commit 7a81af9922
11 changed files with 96 additions and 55 deletions

View File

@@ -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");

View File

@@ -15,6 +15,7 @@
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include <cairo/cairo.h>
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 {

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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) {
@@ -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) {
}

View File

@@ -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++) {

View File

@@ -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);

View File

@@ -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;

View File

@@ -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");