From 31cc8e5a0d2660503cb1a98f6e0b0714d061f72a Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 12 Jan 2026 15:13:59 -0700 Subject: [PATCH] cocoa: fix syntax errors. Also allow cmake to compile it (untested) --- .gitignore | 1 + CMakeLists.txt | 17 +++++++++++++ src/backend/cocoa.m | 61 ++++++++++++++++++++++----------------------- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 9b18b9c..153abcc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ examples/*/*.exe /Makefile /build compile_flags.txt +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt index f695c1d..650d6d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,23 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") PRIVATE -static-libgcc ) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_sources( + Mw + PRIVATE + src/backend/cocoa.m + ) + target_compile_definitions( + Mw + PRIVATE + USE_COCOA + ) + list(APPEND LIBRARIES objc) + target_link_options( + Mw + PRIVATE + -framework Cocoa + ) else() find_package(PkgConfig) pkg_check_modules(X11 REQUIRED x11) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index bd2320b..1f098a0 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -13,34 +13,31 @@ @interface MilskoCocoaPixmap : NSObject { NSImage *image; } -+ (MilskoCocoaPixmap*)newWithWidth:(int)width - height:(int)height; -- (void)updateWithData(void *); ++ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height; +- (void)updateWithData:(void *)data; - (void)destroy; @end @implementation MilskoCocoaPixmap -+ (MilskoCocoaPixmap*)newWithWidth:(int)width - height:(int)height { - MilskoCocoaPixmap * p = [MilskoCocoaPixmap alloc]; ++ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height { + MilskoCocoaPixmap *p = [MilskoCocoaPixmap alloc]; NSSize sz; sz.width = width; sz.height = height; - p->image = [NSImage initWithSize:sz]; + p->image = [[NSImage alloc] initWithSize:sz]; return p; } -- (void)updateWithData(void *) { +- (void)updateWithData:(void *)data { } - (void)destroy { [self->image dealloc]; } @end - @interface MilskoCocoa : NSObject { NSApplication *application; NSWindow *window; @@ -132,24 +129,24 @@ - (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color { }; - (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h { - NSRect frame = self->window->frame; + NSRect frame = [self->window frame]; - *x = frame.origin.x; - *y = frame.origin.y; - *w = frame.size.x; - *h = frame.size.y; + *x = frame.origin.x; + *y = frame.origin.y; + *w = frame.size.width; + *h = frame.size.height; }; - (void)setX:(int)x Y:(int)y { - NSPoint p; - p.x = x; - p.y = y; - [self->window setFrameTopLeftPoint p]; + NSPoint p; + p.x = x; + p.y = y; + [self->window setFrameTopLeftPoint:p]; }; - (void)setW:(int)w H:(int)h { - NSSize s; - s.w = w; - s.h = h; - [self->window setFrameSize s]; + NSSize s; + s.width = w; + s.height = h; + [self->window setFrameSize:s]; }; - (int)pending { return 1; @@ -168,7 +165,8 @@ }; - (void)setTitle:(const char *)title { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [self->window setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; + [self->window + setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; [pool release]; }; - (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect { @@ -192,7 +190,7 @@ }; - (void)makeBorderless:(int)toggle { NSWindowStyleMask mask = self->window.styleMask; - if(mask & NSBorderlessWindowMask) { + if (mask & NSBorderlessWindowMask) { mask ^= NSBorderlessWindowMask; mask |= NSTitledWindowMask; } else { @@ -205,7 +203,8 @@ [self->window makeMainWindow]; }; - (void)grabPointer:(int)toggle { - /* MacOS didn't have a "pointer grab" function until 10.13.2 so I need to do this manually */ + /* MacOS didn't have a "pointer grab" function until 10.13.2 so I need to do + * this manually */ }; - (void)setClipboard:(const char *)text { }; @@ -214,16 +213,16 @@ - (void)makeToolWindow { }; - (void)getCursorCoord:(MwPoint *)point { - NSPoint p = self->window->mouseLocation; + NSPoint p = [NSEvent mouseLocation]; point->x = p.x; point->y = p.y; }; - (void)getScreenSize:(MwRect *)rect { - NSScreen * screen = self->window->screen; - rect->x = screen->frame.origin.x; - rect->y = screen->frame.origin.y; - rect->width = screen->frame.size.x; - rect->height = screen->frame.size.y; + NSScreen *screen = [self->window screen]; + rect->x = screen.frame.origin.x; + rect->y = screen.frame.origin.y; + rect->width = screen.frame.size.width; + rect->height = screen.frame.size.height; }; - (void)destroy { [self->window dealloc];