forked from pyrite-dev/milsko
wayland: split wayland.c into four files
This commit is contained in:
parent
8eacf36c6a
commit
d49e50f95a
8 changed files with 1399 additions and 1366 deletions
|
|
@ -145,7 +145,7 @@ endif()
|
|||
if(MW_USE_WAYLAND)
|
||||
function(scan_wayland_protocol_core)
|
||||
execute_process(
|
||||
COMMAND wayland-scanner private-code /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
|
||||
COMMAND wayland-scanner private-code /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland/wayland-core-protocol.c
|
||||
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
|
||||
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
|
||||
ECHO_OUTPUT_VARIABLE
|
||||
|
|
@ -155,7 +155,7 @@ if(MW_USE_WAYLAND)
|
|||
target_sources(
|
||||
Mw
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland/wayland-core-protocol.c
|
||||
)
|
||||
execute_process(
|
||||
COMMAND wayland-scanner client-header /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/include/Mw/LowLevel/Wayland/wayland-core-protocol.h
|
||||
|
|
@ -169,7 +169,7 @@ if(MW_USE_WAYLAND)
|
|||
endfunction()
|
||||
|
||||
function(scan_wayland_protocol tier proto ver)
|
||||
SET(proto_c ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-${proto}-protocol.c)
|
||||
SET(proto_c ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland/wayland-${proto}-protocol.c)
|
||||
execute_process(
|
||||
COMMAND wayland-scanner private-code /usr/share/wayland-protocols/${tier}/${proto}/${proto}${ver}.xml ${proto_c}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
|
@ -217,7 +217,10 @@ if(MW_USE_WAYLAND)
|
|||
target_sources(
|
||||
Mw
|
||||
PRIVATE
|
||||
src/backend/wayland.c
|
||||
src/backend/wayland/wayland.c
|
||||
src/backend/wayland/buffer.c
|
||||
src/backend/wayland/interfaces.c
|
||||
src/backend/wayland/region.c
|
||||
)
|
||||
target_compile_definitions(
|
||||
Mw
|
||||
|
|
|
|||
|
|
@ -573,4 +573,56 @@ struct _MwLLWaylandPixmap {
|
|||
cairo_surface_t* cs;
|
||||
};
|
||||
|
||||
/* Setup the framebuffer with the saved width/height */
|
||||
void MwLLWaylandFramebufferSetup(struct _MwLLWayland* wayland);
|
||||
/* Destroy the framebuffer */
|
||||
void MwLLWaylandFramebufferDestroy(struct _MwLLWayland* handle);
|
||||
|
||||
/* Setup the framebuffer with the saved width/height */
|
||||
void MwLLWaylandBackbufferSetup(struct _MwLLWayland* wayland);
|
||||
/* Destroy the backbuffer */
|
||||
void MwLLWaylandBackbufferDestroy(struct _MwLLWayland* handle);
|
||||
|
||||
void MwLLWaylandBufferSetup(struct _MwLLWaylandShmBuffer* buffer, MwU32 width, MwU32 height);
|
||||
void MwLLWaylandBufferUpdate(MwLL self, struct _MwLLWaylandShmBuffer* buffer);
|
||||
void MwLLWaylandBufferDestroy(struct _MwLLWaylandShmBuffer* buffer);
|
||||
|
||||
void MwLLWaylandRegionSetup(MwLL handle);
|
||||
void MwLLWaylandRegionInvalidate(MwLL handle);
|
||||
|
||||
void MwLLWaylandHangUntilConfigured(MwLL handle);
|
||||
|
||||
MwBool MwLLWaylandWidgetIsDestroyed(MwLL self);
|
||||
void MwLLWaylandWidgetUndestroy(MwLL self);
|
||||
|
||||
/* Function for setting up the callbacks/structs that will be registered upon the relevant interfaces being found. */
|
||||
void MwLLWaylandSetupCallbacks(struct _MwLLWayland* wayland);
|
||||
|
||||
void MwLLWaylandClipboardRead(wl_clipboard_device_context_t* ctx, int clipboard_type);
|
||||
|
||||
/* Flush Wayland events */
|
||||
void MwLLWaylandFlush(MwLL handle);
|
||||
|
||||
/* Standard procedure before event callbacks in Wayland */
|
||||
#define WAYLAND_EVENT_OP_START(self) \
|
||||
if(MwLLWaylandWidgetIsDestroyed(self)) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
/* Footer for WAYLAND_EVENT_OP_START */
|
||||
#define WAYLAND_EVENT_OP_END(self)
|
||||
|
||||
#define WIDGET_CHECK(handle) \
|
||||
if(!handle->wayland.valid) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
/* the two decoration manager constructs */
|
||||
typedef struct zxdg_decoration_manager_v1_context {
|
||||
struct zxdg_decoration_manager_v1* manager;
|
||||
struct zxdg_toplevel_decoration_v1* decoration;
|
||||
} zxdg_decoration_manager_v1_context_t;
|
||||
|
||||
extern struct zwp_relative_pointer_v1_listener MwLLWaylandRelativePointerListener;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ if (grep(/^classicmacos$/, @backends)) {
|
|||
|
||||
if (grep(/^wayland$/, @backends)) {
|
||||
add_cflags("-DUSE_WAYLAND");
|
||||
new_object("src/backend/wayland.c");
|
||||
new_object("src/backend/wayland/wayland.c");
|
||||
new_object("src/backend/wayland/buffer.c");
|
||||
new_object("src/backend/wayland/interfaces.c");
|
||||
new_object("src/backend/wayland/region.c");
|
||||
|
||||
if (param_get("opengl")) {
|
||||
add_cflags("-DWAYLAND_LOAD_OPENGL");
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ sub use_backend {
|
|||
}
|
||||
|
||||
sub scan_wayland_protocol_core {
|
||||
my $proto_c = "src/backend/wayland-core-protocol.c";
|
||||
my $proto_c = "src/backend/wayland/wayland-core-protocol.c";
|
||||
|
||||
if (
|
||||
system(
|
||||
|
|
@ -98,7 +98,7 @@ sub scan_wayland_protocol {
|
|||
my $proto = $_[1];
|
||||
my $ver = $_[2];
|
||||
|
||||
my $proto_c = "src/backend/wayland-${proto}-protocol.c";
|
||||
my $proto_c = "src/backend/wayland/wayland-${proto}-protocol.c";
|
||||
|
||||
if (
|
||||
system(
|
||||
|
|
|
|||
116
src/backend/wayland/buffer.c
Normal file
116
src/backend/wayland/buffer.c
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
void MwLLWaylandFramebufferSetup(struct _MwLLWayland* wayland) {
|
||||
MwLLWaylandBufferSetup(&wayland->framebuffer, wayland->ww, wayland->wh);
|
||||
|
||||
wayland->front_cs = cairo_image_surface_create_for_data(wayland->framebuffer.buf_back, CAIRO_FORMAT_ARGB32, wayland->ww, wayland->wh, 4 * wayland->ww);
|
||||
wayland->front_cairo = cairo_create(wayland->front_cs);
|
||||
|
||||
memset(wayland->framebuffer.buf_back, 0, wayland->framebuffer.buf_size);
|
||||
if(wayland->configured)
|
||||
wl_surface_attach(wayland->framebuffer.surface, wayland->framebuffer.shm_buffer, 0, 0);
|
||||
wl_surface_commit(wayland->framebuffer.surface);
|
||||
|
||||
MwLLWaylandHangUntilConfigured((MwLL)wayland);
|
||||
MwLLWaylandBufferUpdate((MwLL)wayland, &wayland->framebuffer);
|
||||
};
|
||||
void MwLLWaylandFramebufferDestroy(struct _MwLLWayland* wayland) {
|
||||
MwLLWaylandBufferDestroy(&wayland->framebuffer);
|
||||
cairo_destroy(wayland->front_cairo);
|
||||
cairo_surface_destroy(wayland->front_cs);
|
||||
};
|
||||
|
||||
void MwLLWaylandBackbufferSetup(struct _MwLLWayland* wayland) {
|
||||
if(wayland->type != MwLL_WAYLAND_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
MwU32 w = wayland->ww;
|
||||
MwU32 h = wayland->wh;
|
||||
if(!wayland->has_decorations) {
|
||||
w += (CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT);
|
||||
h += (CSD_BORDER_FRAME_TOP + CSD_BORDER_FRAME_BOTTOM);
|
||||
}
|
||||
MwLLWaylandBufferSetup(&wayland->backbuffer, w, h);
|
||||
|
||||
wayland->back_cs = cairo_image_surface_create_for_data(wayland->backbuffer.buf_back, CAIRO_FORMAT_ARGB32, w, h, 4 * w);
|
||||
wayland->back_cairo = cairo_create(wayland->back_cs);
|
||||
|
||||
memset(wayland->backbuffer.buf_back, 255, wayland->backbuffer.buf_size);
|
||||
if(wayland->configured)
|
||||
wl_surface_attach(wayland->backbuffer.surface, wayland->backbuffer.shm_buffer, 0, 0);
|
||||
wl_surface_commit(wayland->backbuffer.surface);
|
||||
MwLLWaylandHangUntilConfigured((MwLL)wayland);
|
||||
MwLLWaylandBufferUpdate((MwLL)wayland, &wayland->backbuffer);
|
||||
};
|
||||
void MwLLWaylandBackbufferDestroy(struct _MwLLWayland* wayland) {
|
||||
MwLLWaylandBufferDestroy(&wayland->backbuffer);
|
||||
cairo_destroy(wayland->back_cairo);
|
||||
cairo_surface_destroy(wayland->back_cs);
|
||||
};
|
||||
|
||||
void MwLLWaylandBufferSetup(struct _MwLLWaylandShmBuffer* buffer, MwU32 width, MwU32 height) {
|
||||
int stride = width * 4;
|
||||
char temp_name[] = "/tmp/milsko-wl-shm-XXXXXX";
|
||||
char temp_name_back[] = "/tmp/milsko-wl-shm-back-XXXXXX";
|
||||
|
||||
buffer->buf_size = width * height * 4;
|
||||
|
||||
buffer->fd = mkstemp(temp_name);
|
||||
buffer->fd_back = mkstemp(temp_name_back);
|
||||
|
||||
unlink(temp_name);
|
||||
unlink(temp_name_back);
|
||||
|
||||
if(posix_fallocate(buffer->fd, 0, buffer->buf_size) != 0) {
|
||||
printf("failure setting up wl_shm: could not fallocate. %s.\n", strerror(errno));
|
||||
close(buffer->fd);
|
||||
return;
|
||||
}
|
||||
if(posix_fallocate(buffer->fd_back, 0, buffer->buf_size) != 0) {
|
||||
printf("failure setting up wl_shm: could not fallocate. %s.\n", strerror(errno));
|
||||
close(buffer->fd_back);
|
||||
return;
|
||||
}
|
||||
if(ftruncate(buffer->fd, buffer->buf_size) != 0) {
|
||||
printf("failure setting up wl_shm: could not truncate. %s.\n", strerror(errno));
|
||||
close(buffer->fd);
|
||||
return;
|
||||
}
|
||||
if(ftruncate(buffer->fd_back, buffer->buf_size) != 0) {
|
||||
printf("failure setting up wl_shm: could not truncate. %s.\n", strerror(errno));
|
||||
close(buffer->fd_back);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer->buf = mmap(NULL, buffer->buf_size, PROT_WRITE, MAP_SHARED, buffer->fd, 0);
|
||||
buffer->buf_back = mmap(NULL, buffer->buf_size, PROT_WRITE, MAP_SHARED, buffer->fd_back, 0);
|
||||
|
||||
fsync(buffer->fd);
|
||||
fsync(buffer->fd_back);
|
||||
|
||||
if(!(buffer->shm_pool = wl_shm_create_pool(buffer->shm, buffer->fd, buffer->buf_size))) {
|
||||
printf("failure setting up wl_shm: could not create pool.\n");
|
||||
}
|
||||
if(!(buffer->shm_pool_back = wl_shm_create_pool(buffer->shm, buffer->fd_back, buffer->buf_size))) {
|
||||
printf("failure setting up wl_shm: could not create pool.\n");
|
||||
}
|
||||
buffer->shm_buffer = wl_shm_pool_create_buffer(buffer->shm_pool, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888);
|
||||
buffer->shm_buffer_back = wl_shm_pool_create_buffer(buffer->shm_pool_back, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888);
|
||||
buffer->setup = MwTRUE;
|
||||
}
|
||||
|
||||
void MwLLWaylandBufferDestroy(struct _MwLLWaylandShmBuffer* buffer) {
|
||||
if(!buffer->setup) {
|
||||
return;
|
||||
}
|
||||
if(buffer->buf) munmap(buffer->buf, buffer->buf_size);
|
||||
if(buffer->buf_back) munmap(buffer->buf_back, buffer->buf_size);
|
||||
if(buffer->shm_buffer) wl_buffer_destroy(buffer->shm_buffer);
|
||||
if(buffer->shm_buffer_back) wl_buffer_destroy(buffer->shm_buffer_back);
|
||||
if(buffer->shm_pool) wl_shm_pool_destroy(buffer->shm_pool);
|
||||
if(buffer->shm_pool_back) wl_shm_pool_destroy(buffer->shm_pool_back);
|
||||
close(buffer->fd);
|
||||
close(buffer->fd_back);
|
||||
buffer->setup = MwFALSE;
|
||||
}
|
||||
1106
src/backend/wayland/interfaces.c
Normal file
1106
src/backend/wayland/interfaces.c
Normal file
File diff suppressed because it is too large
Load diff
36
src/backend/wayland/region.c
Normal file
36
src/backend/wayland/region.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
void MwLLWaylandRegionInvalidate(MwLL handle) {
|
||||
if(!handle->wayland.configured) {
|
||||
return;
|
||||
}
|
||||
wl_region_subtract(handle->wayland.region, 0, 0, handle->wayland.ww, handle->wayland.wh);
|
||||
}
|
||||
void MwLLWaylandRegionSetup(MwLL handle) {
|
||||
MwLL parent = handle->wayland.parent;
|
||||
int width = (handle->wayland.clipping_rect.width == 0) ? handle->wayland.ww : handle->wayland.clipping_rect.width;
|
||||
int height = (handle->wayland.clipping_rect.height == 0) ? handle->wayland.wh : handle->wayland.clipping_rect.height;
|
||||
|
||||
if(!handle->wayland.configured) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!handle->wayland.parent)
|
||||
wl_region_add(handle->wayland.o_region, 0, 0, width, height);
|
||||
|
||||
if(handle->wayland.type == MwLL_WAYLAND_POPUP) {
|
||||
wl_region_add(handle->wayland.region, 0, 0, width + abs(handle->wayland.x), height + abs(handle->wayland.y));
|
||||
} else {
|
||||
wl_region_subtract(handle->wayland.region, 0, 0, width + abs(handle->wayland.x), height + abs(handle->wayland.y));
|
||||
wl_region_add(handle->wayland.region, handle->wayland.clipping_rect.x, handle->wayland.clipping_rect.y, handle->wayland.clipping_rect.width, handle->wayland.clipping_rect.height);
|
||||
if(!handle->wayland.parent)
|
||||
wl_region_add(handle->wayland.region, 0, 0, width, height);
|
||||
}
|
||||
|
||||
if(handle->wayland.type == MwLL_WAYLAND_TOPLEVEL) {
|
||||
wl_surface_set_opaque_region(handle->wayland.backbuffer.surface, handle->wayland.o_region);
|
||||
wl_surface_set_input_region(handle->wayland.backbuffer.surface, handle->wayland.region);
|
||||
}
|
||||
wl_surface_set_opaque_region(handle->wayland.framebuffer.surface, handle->wayland.o_region);
|
||||
wl_surface_set_input_region(handle->wayland.framebuffer.surface, handle->wayland.region);
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue