From 39b3c035fc3ba9f36c6befe8285582aa417688f8 Mon Sep 17 00:00:00 2001 From: Nishi Date: Tue, 28 Apr 2026 16:30:01 +0000 Subject: [PATCH] at least no more segfault --- include/Mw/LowLevel/ClassicMacOS.h | 8 ++++ include/Mw/LowLevel/Cocoa.h | 10 ++++- include/Mw/LowLevel/GDI.h | 8 ++++ include/Mw/LowLevel/Wayland.h | 8 ++++ include/Mw/LowLevel/X11.h | 8 ++++ include/Mw/MachDep.h | 5 +++ pl/rules.pl | 1 + src/backend/haiku.cxx | 67 +++++++++++++++++++++++++----- 8 files changed, 104 insertions(+), 11 deletions(-) diff --git a/include/Mw/LowLevel/ClassicMacOS.h b/include/Mw/LowLevel/ClassicMacOS.h index 958b5e8..9d76e20 100644 --- a/include/Mw/LowLevel/ClassicMacOS.h +++ b/include/Mw/LowLevel/ClassicMacOS.h @@ -10,6 +10,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct _MwLLClassicMacOS { struct _MwLLCommon common; @@ -32,4 +36,8 @@ struct _MwLLClassicMacOSPixmap { MWDECL int MwLLClassicMacOSCallInit(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 9758074..1f18006 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -160,7 +160,9 @@ typedef struct { #define OBJC(x) void* #endif -MWDECL int MwLLCocoaCallInit(void); +#ifdef __cplusplus +extern "C" { +#endif struct _MwLLCocoa { struct _MwLLCommon common; @@ -178,4 +180,10 @@ struct _MwLLCocoaPixmap { real; }; +MWDECL int MwLLCocoaCallInit(void); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/Mw/LowLevel/GDI.h b/include/Mw/LowLevel/GDI.h index c695cbd..e11f8f2 100644 --- a/include/Mw/LowLevel/GDI.h +++ b/include/Mw/LowLevel/GDI.h @@ -10,6 +10,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct _MwLLGDI { struct _MwLLCommon common; @@ -43,4 +47,8 @@ struct _MwLLGDIPixmap { MWDECL int MwLLGDICallInit(void); MWDECL HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index 0d46e50..1a23f2a 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -16,8 +16,16 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + MWDECL int MwLLWaylandCallInit(void); +#ifdef __cplusplus +} +#endif + #define CSD_BORDER_FRAME_LEFT 5 #define CSD_BORDER_FRAME_RIGHT 5 #define CSD_BORDER_FRAME_TOP 24 diff --git a/include/Mw/LowLevel/X11.h b/include/Mw/LowLevel/X11.h index 3d0e125..305a24a 100644 --- a/include/Mw/LowLevel/X11.h +++ b/include/Mw/LowLevel/X11.h @@ -17,6 +17,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + struct _MwLLX11 { struct _MwLLCommon common; @@ -86,4 +90,8 @@ struct _MwLLX11Pixmap { MWDECL int MwLLX11CallInit(void); MWDECL Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index a9419a8..a9ac37c 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -62,6 +62,11 @@ #include #endif +#if defined(__HAIKU__) && defined(__cplusplus) +#include +#include +#endif + #ifdef __APPLE__ #include #include diff --git a/pl/rules.pl b/pl/rules.pl index 4741b1c..68386b4 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -96,6 +96,7 @@ if (grep(/^cocoa$/, @backends) || param_get("gnustep")) { } if (grep(/^haiku$/, @backends)) { + add_cflags("-DUSE_HAIKU"); new_object("src/backend/haiku.cxx"); } diff --git a/src/backend/haiku.cxx b/src/backend/haiku.cxx index ae07d6b..db97322 100644 --- a/src/backend/haiku.cxx +++ b/src/backend/haiku.cxx @@ -1,8 +1,21 @@ #include -MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {} +MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { + MwLL r = (MwLL)malloc(sizeof(*r)); -void MwLLDestroyImpl(MwLL handle) {} + MwLLCreateCommon(r); + + r->common.copy_buffer = 1; + r->common.type = MwLLBackendHaiku; + + return r; +} + +void MwLLDestroyImpl(MwLL handle) { + MwLLDestroyCommon(handle); + + free(handle); +} void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {} @@ -12,9 +25,17 @@ void MwLLBeginDrawImpl(MwLL handle) {} void MwLLEndDrawImpl(MwLL handle) {} -MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {} +MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { + MwLLColor c = (MwLLColor)malloc(sizeof(*c)); + MwLLColorUpdate(handle, c, r, g, b); + return c; +} -void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {} +void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) { + c->common.red = r; + c->common.green = g; + c->common.blue = b; +} void MwLLFreeColorImpl(MwLLColor color) {} @@ -26,15 +47,33 @@ void MwLLSetWHImpl(MwLL handle, int w, int h) {} void MwLLSetTitleImpl(MwLL handle, const char* title) {} -int MwLLPendingImpl(MwLL handle) {} +int MwLLPendingImpl(MwLL handle) { + return 0; +} void MwLLNextEventImpl(MwLL handle) {} -MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {} +MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) { + MwLLPixmap r = (MwLLPixmap)malloc(sizeof(*r)); + r->common.raw = (unsigned char*)malloc(4 * width * height); + memcpy(r->common.raw, data, 4 * width * height); + + r->common.width = width; + r->common.height = height; + + MwLLPixmapUpdate(r); + return r; + + return r; +} void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {} -void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {} +void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { + free(pixmap->common.raw); + + free(pixmap); +} void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {} @@ -72,11 +111,19 @@ void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {} void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {} -void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {} +void MwLLSetDarkThemeImpl(MwLL handle, int toggle) { + (void)handle; + (void)toggle; +} -MwBool MwLLDoModernImpl(MwLL handle) {} +MwBool MwLLDoModernImpl(MwLL handle) { + (void)handle; + return MwTRUE; +} -int MwLLHaikuCallInitImpl() {} +int MwLLHaikuCallInitImpl() { + return 0; +} #include "call.c" CALL(Haiku);