diff --git a/CMakeLists.txt b/CMakeLists.txt index a6f823d31..948a83c82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,8 +309,6 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Retro") set_target_properties(Mw PROPERTIES LINK_FLAGS "-Wl,-gc-sections") endif() - list(APPEND LIBRARIES InterfaceLib WindowsLib ThreadsLib) - target_compile_definitions( Mw PRIVATE @@ -356,7 +354,7 @@ target_link_libraries( ) if(MW_BUILD_OPENGL) - target_compile_definitions( + target_compile_definitions( Mw PRIVATE MW_OPENGL diff --git a/include/Mw/LowLevel/ClassicMacOS.h b/include/Mw/LowLevel/ClassicMacOS.h index 958b5e8b1..4b32f6cd4 100644 --- a/include/Mw/LowLevel/ClassicMacOS.h +++ b/include/Mw/LowLevel/ClassicMacOS.h @@ -13,12 +13,9 @@ struct _MwLLClassicMacOS { struct _MwLLCommon common; - MwLL parent; - - WindowRef window; - ControlHandle control; - EventRecord event; - Rect winRect; + WindowRef window; + EventRecord event; + Rect winRect; }; struct _MwLLClassicMacOSColor { diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index 7f9e7625a..7debc8872 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -41,7 +41,6 @@ typedef struct wayland_call_table { MwBool has_dbus; #endif - int (*wl_display_dispatch)(struct wl_display* display); int (*wl_display_dispatch_pending)(struct wl_display* display); void (*wl_display_disconnect)(struct wl_display* display); void (*wl_display_cancel_read)(struct wl_display* display); @@ -59,7 +58,6 @@ typedef struct wayland_call_table { uint32_t flags, ...); struct wl_display* (*wl_display_connect)(const char* name); uint32_t (*wl_proxy_get_version)(struct wl_proxy* proxy); - struct wl_display* (*wl_display_connect_to_fd)(int fd); struct xkb_context* (*xkb_context_new)(enum xkb_context_flags flags); void (*xkb_context_unref)(struct xkb_context* context); @@ -158,7 +156,6 @@ MwInline int wayland_load_funcs() { return 1; \ }; - WAYLAND_FUNC(wl_display_dispatch) WAYLAND_FUNC(wl_display_dispatch_pending) WAYLAND_FUNC(wl_display_disconnect) WAYLAND_FUNC(wl_display_cancel_read) @@ -173,7 +170,6 @@ MwInline int wayland_load_funcs() { WAYLAND_FUNC(wl_proxy_marshal_flags) WAYLAND_FUNC(wl_display_connect) WAYLAND_FUNC(wl_proxy_get_version) - WAYLAND_FUNC(wl_display_connect_to_fd) #undef WAYLAND_FUNC @@ -239,7 +235,6 @@ MwInline int wayland_load_funcs() { return 0; } -#define wl_display_dispatch wl_call_tbl.wl_display_dispatch #define wl_display_dispatch_pending wl_call_tbl.wl_display_dispatch_pending #define wl_display_disconnect wl_call_tbl.wl_display_disconnect #define wl_display_cancel_read wl_call_tbl.wl_display_cancel_read @@ -254,7 +249,6 @@ MwInline int wayland_load_funcs() { #define wl_proxy_marshal_flags wl_call_tbl.wl_proxy_marshal_flags #define wl_display_connect wl_call_tbl.wl_display_connect #define wl_proxy_get_version wl_call_tbl.wl_proxy_get_version -#define wl_display_connect_to_fd wl_call_tbl.wl_display_connect_to_fd #define xkb_state_unref wl_call_tbl.xkb_state_unref #define xkb_context_new wl_call_tbl.xkb_context_new @@ -379,11 +373,11 @@ enum _MwLLWaylandType { }; typedef struct wl_clipboard_device_context { - struct { + union { struct wl_data_device* wl; struct zwp_primary_selection_device_v1* zwp; } device; - struct { + union { struct wl_data_offer* wl; struct zwp_primary_selection_offer_v1* zwp; } offer; @@ -415,13 +409,13 @@ struct _MwLLWayland { /* Map of Wayland interfaces to their relevant setup functions. */ struct { - char key[255]; + const char* key; wayland_protocol_callback_table_t* value; }* wl_protocol_setup_map; /* Map of Wayland interfaces to any information we keep about them once we've registered them. */ struct { - char key[255]; + const char* key; wayland_protocol_t* value; }* wl_protocol_map; diff --git a/include/Mw/Widget/Vulkan.h b/include/Mw/Widget/Vulkan.h index 0b7db3ac8..0565022e5 100644 --- a/include/Mw/Widget/Vulkan.h +++ b/include/Mw/Widget/Vulkan.h @@ -11,7 +11,7 @@ #ifndef __MW_WIDGET_VULKAN_H__ #define __MW_WIDGET_VULKAN_H__ -#if defined(MW_VULKAN) && !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) +#if !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) #error Vulkan is unsupported on the requested platform. #endif diff --git a/src/abstract/dynamic.c b/src/abstract/dynamic.c index ae31e82bf..d9558af6d 100644 --- a/src/abstract/dynamic.c +++ b/src/abstract/dynamic.c @@ -14,39 +14,33 @@ void MwDynamicClose(void* handle) { } #elif defined(CLASSIC_MAC_OS) void* MwDynamicOpen(const char* path) { - // CFragConnectionID connID; - // Ptr* addr; - // unsigned char err[255]; + CFragConnectionID connID; + Ptr* addr; + unsigned char err[255]; - // if(GetSharedLibrary((ConstStr63Param)path, kPowerPCCFragArch, kPrivateCFragCopy, - // &connID, addr, err)) { - // printf("Error getting %s: %s\n", path, err); - // return NULL; - // }; - // return connID; - printf("MwDynamicOpen not implemented yet.\n"); - getchar(); - return NULL; + if(GetSharedLibrary((ConstStr63Param)path, kPowerPCCFragArch, kPrivateCFragCopy, + &connID, addr, err)) { + printf("Error getting %s: %s\n", path, err); + return NULL; + }; + return connID; } void* MwDynamicSymbol(void* handle, const char* symbol) { - // CFragConnectionID connID = (CFragConnectionID)handle; - // Ptr* symAddr; - // CFragSymbolClass* symClass; - // OSErr err; - // if((err = FindSymbol(connID, (ConstStr63Param)symbol, symAddr, symClass))) { - // printf("Error getting %s: %d\n", symbol, err); - // return NULL; - // }; - // return symAddr; - printf("MwDynamicSymbol not implemented yet.\n"); - getchar(); - return NULL; + CFragConnectionID connID = (CFragConnectionID)handle; + Ptr* symAddr; + CFragSymbolClass* symClass; + OSErr err; + if((err = FindSymbol(connID, (ConstStr63Param)symbol, symAddr, symClass))) { + printf("Error getting %s: %d\n", symbol, err); + return NULL; + }; + return symAddr; } void MwDynamicClose(void* handle) { - // CFragConnectionID connID = (CFragConnectionID)handle; - // CloseConnection(&connID); + CFragConnectionID connID = (CFragConnectionID)handle; + CloseConnection(&connID); } #elif defined(__unix__) || defined(__APPLE__) void* MwDynamicOpen(const char* path) { diff --git a/src/backend/classicmacos.c b/src/backend/classicmacos.c index d7db43318..4fa7ab373 100644 --- a/src/backend/classicmacos.c +++ b/src/backend/classicmacos.c @@ -1,24 +1,12 @@ #include -#include -#include #include "../../external/stb_ds.h" static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { MwLL r; - r = malloc(sizeof(*r)); - memset(r, 0, sizeof(*r)); + MwLLCreateCommon(r); - r->cmacos.parent = parent; - - if(x == MwDEFAULT) { - x = (qd.screenBits.bounds.right / 2) - (width / 2); - } - if(y == MwDEFAULT) { - y = (qd.screenBits.bounds.bottom / 2) - (height / 2); - } - /* todo: how do we set parent windows? If we can't, what is our equivalant to MacOS's NSViews, Wayland's subsurfaces, etc.? */ SetRect(&r->cmacos.winRect, x, y, width, height); r->cmacos.window = newcwindow(nil, &r->cmacos.winRect, "", true, @@ -35,26 +23,24 @@ static void MwLLDestroyImpl(MwLL handle) { } static void MwLLBeginDrawImpl(MwLL handle) { + (void)handle; } static void MwLLEndDrawImpl(MwLL handle) { + (void)handle; } static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { int i; - PolyHandle p; + PolyHandle p = OpenPoly(); RGBColor col; - SetPort(handle->cmacos.window); - BeginUpdate(handle->cmacos.window); - - p = OpenPoly(); - col.red = color->common.red * 0x101; - col.green = color->common.green * 0x101; - col.blue = color->common.blue * 0x101; + col.red = color->common.red; + col.green = color->common.green; + col.blue = color->common.blue; + RGBBackColor(&col); RGBForeColor(&col); - PenMode(patCopy); for(i = 0; i < points_count; i++) { if(i == 0) { @@ -65,24 +51,20 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL } ClosePoly(); - FillCPoly(p, &qd.ltGray); + PaintPoly(p); KillPoly(p); - - EndUpdate(handle->cmacos.window); } static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { RGBColor col; - SetPort(handle->cmacos.window); col.red = color->common.red; col.green = color->common.green; col.blue = color->common.blue; + RGBBackColor(&col); RGBForeColor(&col); - PenMode(patCopy); - MoveTo(points[0].x, points[0].y); LineTo(points[1].x, points[1].y); } @@ -121,133 +103,10 @@ static void MwLLFreeColorImpl(MwLLColor color) { } static int MwLLPendingImpl(MwLL handle) { - YieldToAnyThread(); - return EventAvail(everyEvent, &handle->cmacos.event); + return GetNextEvent(everyEvent, &handle->cmacos.event); } static void MwLLNextEventImpl(MwLL handle) { - EventRecord event; - GetNextEvent(everyEvent, &event); - - switch(event.what) { - case updateEvt: { - } - // MwLLDispatch(handle, draw, NULL); - break; - case osEvt: - break; - case mouseUp: { - // MwLLMouse m; - // m.button = MwLLMouseLeft; - // if(___curWindow->mouseButtonCallback != NULL) { - // int mods = MacModifiersToGLFWModifiers(event.modifiers); - - // if(___curWindow->keyStateMap[MK_LCTRL] == 1) { - // ___curWindow->mouseButtonCallback( - // ___curWindow, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE, mods); - // } else { - // ___curWindow->mouseButtonCallback( - // ___curWindow, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, mods); - // } - // } - } - case mouseDown: { - // // start with callback stuff - // if(___curWindow->mouseButtonCallback != NULL) { - // int mods = MacModifiersToGLFWModifiers(event.modifiers); - - // if(___curWindow->keyStateMap[MK_LCTRL] == 1) { - // ___curWindow->mouseButtonCallback( - // ___curWindow, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods); - // } else { - // ___curWindow->mouseButtonCallback( - // ___curWindow, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, mods); - // } - // } - - // then do system stuff - switch(FindWindow(event.where, &handle->cmacos.window)) { - case inDrag: - DragWindow(handle->cmacos.window, event.where, &qd.screenBits.bounds); - // if(___curWindow->windowPosCallback != NULL) { - // ___curWindow->windowPosCallback(___curWindow, event.where.h, - // event.where.v); - // } - break; - case inGrow: { - long growResult = - GrowWindow(handle->cmacos.window, event.where, &qd.screenBits.bounds); - - int width = growResult & 0xFFFF; - int height = growResult >> 16; - - SizeWindow(handle->cmacos.window, growResult & 0xFFFF, growResult >> 16, true); - - Rect rect; - GetWindowBounds(handle->cmacos.window, kWindowStructureRgn, &rect); - rect.right = width; - rect.bottom = height; - SetWindowBounds(handle->cmacos.window, kWindowStructureRgn, &rect); - - // ___curWindow->width = width; - // ___curWindow->height = height; - - // if(___curWindow->windowSizeCallback != NULL) { - // ___curWindow->windowSizeCallback(___curWindow, width, height); - // } - // if(___curWindow->windowSetFramebufferSizeCallback != NULL) { - // ___curWindow->windowSetFramebufferSizeCallback(___curWindow, - // width, height); - // } - } break; - - case inGoAway: { - if(TrackGoAway(handle->cmacos.window, event.where)) { - MwLLDispatch(handle, close, NULL); - // if(___curWindow->windowCloseCallback != NULL) { - // ___curWindow->windowCloseCallback(___curWindow); - // } - // ___curWindow->shouldClose = true; - } - } break; - } - } - case autoKey: - case keyDown: - case keyUp: { - // // key char stuff - // unsigned char ch = (event.message & charCodeMask); - // if(*___curWindow->charCallback != NULL) { - // ___curWindow->charCallback(___curWindow, ch); - // } - - // // key state map - // unsigned char key = (event.message & keyCodeMask) >> 8; - // ___curWindow->keyStateMap[key] = 0; - // if(event.what == keyDown || event.what == autoKey) { - // ___curWindow->keyStateMap[key] &= 1; - // } - - // if(*___curWindow->keyCallback != NULL) { - // int key = MacKeyToGLFWKey(event.message); - // int scancode = (event.message & adbAddrMask) >> 16; - - // int mods = MacModifiersToGLFWModifiers(event.modifiers); - - // int action; - // if(event.what == keyUp) { - // action = GLFW_RELEASE; - // } else { - // action = GLFW_PRESS; - // } - // ___curWindow->keyCallback(___curWindow, key, scancode, action, - // mods); - // } - } - } - - FlushEvents(everyEvent, -1); - YieldToAnyThread(); } static void MwLLSetTitleImpl(MwLL handle, const char* title) { @@ -308,14 +167,14 @@ static void MwLLFocusImpl(MwLL handle) { static void MwLLGrabPointerImpl(MwLL handle, int toggle) { } -static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) { +static void MwLLSetClipboardImpl(MwLL handle, const char* text) { /* TODO */ (void)handle; (void)text; } -static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) { +static void MwLLGetClipboardImpl(MwLL handle) { } static void MwLLMakeToolWindowImpl(MwLL handle) { diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 566012582..be5a7a181 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -64,7 +64,9 @@ static void new_protocol(void* data, struct wl_registry* registry, wayland_protocol_callback_table_t* cb = shget(self->wayland.wl_protocol_setup_map, interface); if(cb != NULL) { - shput(self->wayland.wl_protocol_map, interface, cb->setup(name, data)); + char* inter = malloc(strlen(interface) + 1); + strcpy(inter, interface); + shput(self->wayland.wl_protocol_map, inter, cb->setup(name, data)); /* we don't care for adding this protocol, we just use it to know if the compositor will let us have transparent surfaces */ } else if(strcmp(interface, "wp_alpha_modifier_v1") == 0) { self->common.supports_transparency = MwTRUE; @@ -132,6 +134,34 @@ static void recursive_dispatch_move(MwLL handle, MwMouse* p) { } }; +/* Recursively dispatch a key event to a widget and its children */ +static void recursive_dispatch_key(MwLL handle, int* k) { + MwWidget h = (MwWidget)handle->common.user; + MwLLDispatch(handle, key, k); + if(h) { + int i; + for(i = 0; i < arrlen(h->children); i++) { + MwLLDispatch(h->children[i]->lowlevel, key, k); + if(arrlen(h->children[i]->children) > 0) { + recursive_dispatch_key(h->children[i]->lowlevel, k); + } + } + } +}; +/* Recursively dispatch a key released event to a widget and its children */ +static void recursive_dispatch_key_released(MwLL handle, int* k) { + MwWidget h = (MwWidget)handle->common.user; + MwLLDispatch(handle, key_released, k); + if(h) { + int i; + for(i = 0; i < arrlen(h->children); i++) { + MwLLDispatch(h->children[i]->lowlevel, key_released, k); + if(arrlen(h->children[i]->children) > 0) { + recursive_dispatch_key_released(h->children[i]->lowlevel, k); + } + } + } +}; static void wl_offer(void* data, struct wl_data_offer* wl_data_offer, const char* mime_type) { @@ -510,12 +540,6 @@ static void relative_pointer_motion(void* data, MwLL self = data; MwMouse p; - (void)pointer; - (void)timeHi; - (void)timeLo; - (void)dx; - (void)dy; - WAYLAND_EVENT_OP_START(self); p.point.x = wl_fixed_to_int(dxUnaccel); @@ -587,6 +611,8 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri inArea |= self->wayland.backbuffer.surface == curSurface; } if(inArea) { + int i; + switch(button) { case BTN_LEFT: p.button = MwMOUSE_LEFT; @@ -651,24 +677,19 @@ static void keyboard_keymap(void* data, MwLL self = data; (void)wl_keyboard; - if(!self->wayland.parent) { - char* map_shm; - struct xkb_keymap* xkb_keymap; - struct xkb_state* xkb_state; - xkb_state = NULL; - + if(self->wayland.type == MWLL_WAYLAND_TOPLEVEL) { assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1); - map_shm = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + char* map_shm = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); assert(map_shm != MAP_FAILED); - xkb_keymap = xkb_keymap_new_from_string( + struct xkb_keymap* xkb_keymap = xkb_keymap_new_from_string( self->wayland.xkb_context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(map_shm, size); close(fd); - xkb_state = xkb_state_new(xkb_keymap); + struct xkb_state* xkb_state = xkb_state_new(xkb_keymap); self->wayland.xkb_keymap = xkb_keymap; self->wayland.xkb_state = xkb_state; @@ -722,8 +743,8 @@ static void keyboard_key(void* data, MwU32 time, MwU32 key, MwU32 state) { - MwLL self = data; - MwBool inArea = 0; + MwLL self = data; + MwBool inArea; (void)wl_keyboard; (void)serial; @@ -741,7 +762,7 @@ static void keyboard_key(void* data, if(inArea) { xkb_layout_index_t layout; MwU32 levels; - xkb_level_index_t level = 0; + xkb_level_index_t level; const xkb_keysym_t* syms_out; MwU32 keycode = key + 8; MwU64 syms_num; @@ -766,8 +787,9 @@ static void keyboard_key(void* data, } for(i = 0; i < syms_num; i++) { - int sym = syms_out[i]; - int key = -1; + int sym = syms_out[i]; + int key = -1; + const char* name; switch(sym) { case XKB_KEY_BackSpace: @@ -981,7 +1003,6 @@ static wayland_protocol_t* wl_seat_setup(MwU32 name, MwLL ll) { static void wl_seat_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) { (void)wayland; free(data->listener); - free(data); } /* wl_output setup function */ @@ -1126,8 +1147,6 @@ static int event_loop(MwLL handle) { if(wl_display_dispatch_pending(wayland->display) < 0) { wl_display_cancel_read(wayland->display); } - wl_display_flush(handle->wayland.display); - return 1; } @@ -1238,46 +1257,66 @@ static void update_buffer(MwLL self, struct _MwLLWaylandShmBuffer* buffer) { } static void buffer_setup(struct _MwLLWaylandShmBuffer* buffer, MwU32 width, MwU32 height) { - int stride = width * 4; - char temp_name[] = "/tmp/milsko-wl-shm-XXXXXX"; + 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 = 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; } - - buffer->buf = mmap(NULL, buffer->buf_size, PROT_WRITE, MAP_SHARED, buffer->fd, 0); - buffer->buf_back = malloc(buffer->buf_size); - - fsync(buffer->fd); - - if(!(buffer->shm_pool = wl_shm_create_pool(buffer->shm, buffer->fd, buffer->buf_size))) { - close(buffer->fd); - printf("failure setting up wl_shm: could not create pool.\n"); + 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->shm_buffer = wl_shm_pool_create_buffer(buffer->shm_pool, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888); - buffer->setup = MwTRUE; + + 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; } static void buffer_destroy(struct _MwLLWaylandShmBuffer* buffer) { - close(buffer->fd); - if(buffer->buf) munmap(buffer->buf, buffer->buf_size); - if(buffer->buf_back) free(buffer->buf_back); + if(!buffer->setup) { + return; + } 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; } @@ -1516,12 +1555,12 @@ static void destroy_toplevel(MwLL r) { xdg_toplevel_destroy(r->wayland.toplevel->xdg_top_level); + xkb_keymap_unref(r->wayland.xkb_keymap); + xkb_state_unref(r->wayland.xkb_state); xkb_context_unref(r->wayland.xkb_context); - xkb_keymap_unref(r->wayland.xkb_keymap); - free(r->wayland.toplevel); wl_registry_destroy(r->wayland.registry); @@ -1541,6 +1580,8 @@ static void setup_sublevel(MwLL parent, MwLL r, int x, int y) { r->wayland.type = MWLL_WAYLAND_SUBLEVEL; + r->wayland.display = parent->wayland.display; + setup_callbacks(&r->wayland); r->wayland.registry = wl_display_get_registry(parent->wayland.display); @@ -1578,9 +1619,10 @@ static void setup_sublevel(MwLL parent, MwLL r, int x, int y) { /* Sublevel setup function */ static void destroy_sublevel(MwLL r) { - wl_subsurface_destroy(r->wayland.sublevel->subsurface); + backbuffer_destroy(&r->wayland); + framebuffer_destroy(&r->wayland); - wl_registry_destroy(r->wayland.registry); + wl_subsurface_destroy(r->wayland.sublevel->subsurface); free(r->wayland.sublevel); @@ -1759,9 +1801,6 @@ static void widget_setup(MwLL r, MwLL parent, int x, int y, int width, int heigh } } - framebuffer_destroy(&r->wayland); - backbuffer_destroy(&r->wayland); - framebuffer_setup(&r->wayland); backbuffer_setup(&r->wayland); @@ -1827,6 +1866,8 @@ static void MwLLDestroyImpl(MwLL handle) { int select_ret; event_loop(handle); + // wl_display_cancel_read(handle->wayland.display); + wl_flush(handle); if(pthread_mutex_timedlock(&handle->wayland.eventsMutex, &t) != 0) { @@ -1852,6 +1893,7 @@ static void MwLLDestroyImpl(MwLL handle) { } #endif + buffer_destroy(&handle->wayland.cursor); wl_region_destroy(handle->wayland.region); if(handle->wayland.supports_zwp) { @@ -1859,6 +1901,10 @@ static void MwLLDestroyImpl(MwLL handle) { } else { wl_data_source_destroy(handle->wayland.clipboard_source.wl); } + if(handle->wayland.icon != NULL) { + buffer_destroy(handle->wayland.icon); + wl_surface_destroy(handle->wayland.icon->surface); + } if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) { destroy_toplevel(handle); @@ -1868,20 +1914,6 @@ static void MwLLDestroyImpl(MwLL handle) { destroy_popup(handle); } - if(handle->wayland.framebuffer.setup) { - framebuffer_destroy(&handle->wayland); - wl_surface_destroy(handle->wayland.framebuffer.surface); - } - if(handle->wayland.backbuffer.setup) { - backbuffer_destroy(&handle->wayland); - wl_surface_destroy(handle->wayland.backbuffer.surface); - } - buffer_destroy(&handle->wayland.cursor); - if(handle->wayland.icon != NULL) { - buffer_destroy(handle->wayland.icon); - wl_surface_destroy(handle->wayland.icon->surface); - } - for(i = 0; i < shlen(handle->wayland.wl_protocol_setup_map); i++) { void* ctx = shget(handle->wayland.wl_protocol_map, handle->wayland.wl_protocol_setup_map[i].key); @@ -1889,30 +1921,17 @@ static void MwLLDestroyImpl(MwLL handle) { handle->wayland.wl_protocol_setup_map[i].value->destroy(&handle->wayland, ctx); } shdel(handle->wayland.wl_protocol_map, handle->wayland.wl_protocol_setup_map[i].value); - free(handle->wayland.wl_protocol_setup_map[i].value); - free(ctx); } shfree(handle->wayland.wl_protocol_map); shfree(handle->wayland.wl_protocol_setup_map); - // wl_keyboard_destroy(handle->wayland.keyboard); - // wl_pointer_destroy(handle->wayland.pointer); - - if(handle->wayland.supports_zwp) { - for(i = 0; i < arrlen(handle->wayland.clipboard_devices_zwp); i++) { - if(handle->wayland.clipboard_devices_zwp[i]->device.zwp) zwp_primary_selection_device_v1_destroy(handle->wayland.clipboard_devices_zwp[i]->device.zwp); - free(handle->wayland.clipboard_devices_zwp[i]); - } - } else { - printf("[WARNING] Primary clipboard requested for MwLLSetClipboard, but this Wayland compositor doesn't support it.\n"); - } - for(i = 0; i < arrlen(handle->wayland.clipboard_devices_wl); i++) { - wl_data_device_destroy(handle->wayland.clipboard_devices_wl[i]->device.wl); - free(handle->wayland.clipboard_devices_wl[i]); - } + wl_keyboard_destroy(handle->wayland.keyboard); + wl_pointer_destroy(handle->wayland.pointer); wl_flush(handle); + // free(handle); + if(currentlyHeldWidget == handle) { currentlyHeldWidget = NULL; } @@ -1965,6 +1984,7 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) { setup_popup(handle, handle->wayland.x, handle->wayland.y, handle->wayland.parent); } +refresh: region_setup(handle); framebuffer_destroy(&handle->wayland); @@ -2177,7 +2197,6 @@ static int MwLLPendingImpl(MwLL handle) { wl_display_cancel_read(handle->wayland.display); } else { wl_display_read_events(handle->wayland.display); - wl_display_flush(handle->wayland.display); if((pending = wl_display_dispatch_pending(handle->wayland.display)) < 0) { wl_display_cancel_read(handle->wayland.display); } @@ -2186,7 +2205,6 @@ static int MwLLPendingImpl(MwLL handle) { if((pending = wl_display_dispatch_pending(handle->wayland.display)) < 0) { wl_display_cancel_read(handle->wayland.display); } - wl_display_flush(handle->wayland.display); } if(MwWaylandAlwaysRender) { @@ -2337,7 +2355,7 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { if(handle->wayland.configured) update_buffer(handle, handle->wayland.icon); - xdg_toplevel_icon_v1_add_buffer(icon, handle->wayland.icon->shm_buffer, 1); + xdg_toplevel_icon_v1_add_buffer(icon, handle->wayland.icon->shm_buffer_back, 1); xdg_toplevel_icon_manager_v1_set_icon(icon_manager, handle->wayland.toplevel->xdg_top_level, icon); } diff --git a/src/backend/x11.c b/src/backend/x11.c index 704bd7bd6..cc76ed66e 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -72,7 +72,7 @@ static struct symtbl { char* (*XSetLocaleModifiers)(const char*); XIM (*XOpenIM)(Display*, struct _XrmHashBucketRec*, char*, char*); Status (*XCloseIM)(XIM); - XIC (*XCreateIC)(XIM, ...); + XIC (*XCreateIC)(XIM, ...) _X_SENTINEL(0); void (*XDestroyIC)(XIC); void (*XSetICFocus)(XIC); diff --git a/src/core.c b/src/core.c index 6476ccbb6..0c8360ef9 100644 --- a/src/core.c +++ b/src/core.c @@ -878,9 +878,6 @@ int MwLibraryInit(void) { #endif #ifdef USE_GDI MwLLGDICallInit, -#endif -#ifdef CLASSIC_MAC_OS - MwLLClassicMacOSCallInit, #endif NULL}; int i; @@ -903,9 +900,6 @@ int MwLibraryInit(void) { #endif #ifdef USE_GDI " GDI" -#endif -#ifdef CLASSIC_MAC_OS - " ClassicMacOS" #endif "\n"); diff --git a/tools/.gitignore b/tools/.gitignore deleted file mode 100644 index 0581170fb..000000000 --- a/tools/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -font -fuzzer diff --git a/tools/Makefile b/tools/Makefile index ef8636836..fbfc51a7d 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -6,10 +6,7 @@ LIBS = `freetype-config --libs` .PHONY: all clean .SUFFIXES: .c .o -all: fuzzer font - -fuzzer: fuzzer.o - $(CC) -g -L../src/ -Wl,-R../src -lMw -o $@ fuzzer.o +all: font font: font.o $(CC) $(LDFLAGS) -o $@ font.o $(LIBS) @@ -18,4 +15,4 @@ font: font.o $(CC) $(CFLAGS) -c -o $@ $< clean: - rm -f *.o font fuzzer + rm -f *.o font diff --git a/tools/fuzzer.c b/tools/fuzzer.c deleted file mode 100644 index 5b4224e93..000000000 --- a/tools/fuzzer.c +++ /dev/null @@ -1,85 +0,0 @@ -#include - -#define WIDGET_AMOUNT 1 - -int main() { - MwWidget window, widget; - - MwLibraryInit(); - - window = MwCreateWidget(MwWindowClass, "window", NULL, 0, 0, 400, 400); - - while(true) { - int r = rand() % WIDGET_AMOUNT; - MwClass cls; - switch(r) { - case 0: - cls = MwBoxClass; - break; - case 1: - cls = MwButtonClass; - break; - case 2: - cls = MwCheckBoxClass; - break; - case 3: - cls = MwComboBoxClass; - break; - case 4: - cls = MwEntryClass; - break; - case 5: - cls = MwFrameClass; - break; - case 6: - cls = MwImageClass; - break; - case 7: - cls = MwLabelClass; - break; - case 8: - cls = MwListBoxClass; - break; - case 9: - cls = MwMenuClass; - break; - case 10: - cls = MwNumberEntryClass; - break; - case 12: - cls = MwProgressBarClass; - break; - case 13: - cls = MwRadioBoxClass; - break; - case 14: - cls = MwScrollBarClass; - break; - case 15: - cls = MwSeparatorClass; - break; - // case 16: - // cls = MwSubMenuClass; - // break; - case 17: - cls = MwTreeViewClass; - break; - case 18: - cls = MwViewportClass; - break; - default: - cls = NULL; - break; - } - if(cls) { - widget = MwCreateWidget(cls, "Cls", window, 0, 0, 100, 100); - } - - if(MwPending(window)) { - MwStep(window); - } - if(cls) { - MwDestroyWidget(widget); - } - } -}