cocoa: fix syntax errors. Also allow cmake to compile it (untested)

This commit is contained in:
IoIxD 2026-01-12 15:13:59 -07:00
commit 31cc8e5a0d
3 changed files with 48 additions and 31 deletions

1
.gitignore vendored
View file

@ -15,3 +15,4 @@ examples/*/*.exe
/Makefile /Makefile
/build /build
compile_flags.txt compile_flags.txt
.cache

View file

@ -158,6 +158,23 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
PRIVATE PRIVATE
-static-libgcc -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() else()
find_package(PkgConfig) find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11) pkg_check_modules(X11 REQUIRED x11)

View file

@ -13,34 +13,31 @@
@interface MilskoCocoaPixmap : NSObject { @interface MilskoCocoaPixmap : NSObject {
NSImage *image; NSImage *image;
} }
+ (MilskoCocoaPixmap*)newWithWidth:(int)width + (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height;
height:(int)height; - (void)updateWithData:(void *)data;
- (void)updateWithData(void *);
- (void)destroy; - (void)destroy;
@end @end
@implementation MilskoCocoaPixmap @implementation MilskoCocoaPixmap
+ (MilskoCocoaPixmap*)newWithWidth:(int)width + (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height {
height:(int)height { MilskoCocoaPixmap *p = [MilskoCocoaPixmap alloc];
MilskoCocoaPixmap * p = [MilskoCocoaPixmap alloc];
NSSize sz; NSSize sz;
sz.width = width; sz.width = width;
sz.height = height; sz.height = height;
p->image = [NSImage initWithSize:sz]; p->image = [[NSImage alloc] initWithSize:sz];
return p; return p;
} }
- (void)updateWithData(void *) { - (void)updateWithData:(void *)data {
} }
- (void)destroy { - (void)destroy {
[self->image dealloc]; [self->image dealloc];
} }
@end @end
@interface MilskoCocoa : NSObject { @interface MilskoCocoa : NSObject {
NSApplication *application; NSApplication *application;
NSWindow *window; NSWindow *window;
@ -132,24 +129,24 @@
- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color { - (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color {
}; };
- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h { - (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; *x = frame.origin.x;
*y = frame.origin.y; *y = frame.origin.y;
*w = frame.size.x; *w = frame.size.width;
*h = frame.size.y; *h = frame.size.height;
}; };
- (void)setX:(int)x Y:(int)y { - (void)setX:(int)x Y:(int)y {
NSPoint p; NSPoint p;
p.x = x; p.x = x;
p.y = y; p.y = y;
[self->window setFrameTopLeftPoint p]; [self->window setFrameTopLeftPoint:p];
}; };
- (void)setW:(int)w H:(int)h { - (void)setW:(int)w H:(int)h {
NSSize s; NSSize s;
s.w = w; s.width = w;
s.h = h; s.height = h;
[self->window setFrameSize s]; [self->window setFrameSize:s];
}; };
- (int)pending { - (int)pending {
return 1; return 1;
@ -168,7 +165,8 @@
}; };
- (void)setTitle:(const char *)title { - (void)setTitle:(const char *)title {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self->window setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; [self->window
setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]];
[pool release]; [pool release];
}; };
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect { - (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect {
@ -192,7 +190,7 @@
}; };
- (void)makeBorderless:(int)toggle { - (void)makeBorderless:(int)toggle {
NSWindowStyleMask mask = self->window.styleMask; NSWindowStyleMask mask = self->window.styleMask;
if(mask & NSBorderlessWindowMask) { if (mask & NSBorderlessWindowMask) {
mask ^= NSBorderlessWindowMask; mask ^= NSBorderlessWindowMask;
mask |= NSTitledWindowMask; mask |= NSTitledWindowMask;
} else { } else {
@ -205,7 +203,8 @@
[self->window makeMainWindow]; [self->window makeMainWindow];
}; };
- (void)grabPointer:(int)toggle { - (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 { - (void)setClipboard:(const char *)text {
}; };
@ -214,16 +213,16 @@
- (void)makeToolWindow { - (void)makeToolWindow {
}; };
- (void)getCursorCoord:(MwPoint *)point { - (void)getCursorCoord:(MwPoint *)point {
NSPoint p = self->window->mouseLocation; NSPoint p = [NSEvent mouseLocation];
point->x = p.x; point->x = p.x;
point->y = p.y; point->y = p.y;
}; };
- (void)getScreenSize:(MwRect *)rect { - (void)getScreenSize:(MwRect *)rect {
NSScreen * screen = self->window->screen; NSScreen *screen = [self->window screen];
rect->x = screen->frame.origin.x; rect->x = screen.frame.origin.x;
rect->y = screen->frame.origin.y; rect->y = screen.frame.origin.y;
rect->width = screen->frame.size.x; rect->width = screen.frame.size.width;
rect->height = screen->frame.size.y; rect->height = screen.frame.size.height;
}; };
- (void)destroy { - (void)destroy {
[self->window dealloc]; [self->window dealloc];