Compare commits

...

2 commits

Author SHA1 Message Date
efcc176c04 cocoa: more fixes 2026-01-12 15:31:22 -07:00
e45a1f6ad8 cocoa: more fixes 2026-01-12 15:30:05 -07:00

View file

@ -1,5 +1,7 @@
#ifndef USE_COCOA #ifndef USE_COCOA
#define USE_COCOA #define USE_COCOA
#include <Foundation/NSGeometry.h>
#include <Foundation/NSObjCRuntime.h>
#endif #endif
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
@ -41,6 +43,7 @@
@interface MilskoCocoa : NSObject { @interface MilskoCocoa : NSObject {
NSApplication *application; NSApplication *application;
NSWindow *window; NSWindow *window;
NSRect rect;
} }
+ (MilskoCocoa *)newWithParent:(MwLL)parent + (MilskoCocoa *)newWithParent:(MwLL)parent
@ -100,22 +103,20 @@
} }
c->application = [NSApplication sharedApplication]; c->application = [NSApplication sharedApplication];
NSRect rect = NSMakeRect(x, y, width, height); c->rect = NSMakeRect(x, y, width, height);
c->window = [[[NSWindow alloc] c->window = [[NSWindow alloc]
initWithContentRect:rect initWithContentRect:c->rect
styleMask:parent == NULL styleMask:parent == NULL
? (NSTitledWindowMask | NSClosableWindowMask | ? (NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSMiniaturizableWindowMask |
NSResizableWindowMask) NSResizableWindowMask)
: NSBorderlessWindowMask : NSBorderlessWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO] autorelease]; defer:NO];
[c->window makeKeyAndOrderFront:c->application]; [c->window makeKeyAndOrderFront:c->application];
if (parent != NULL) { if (parent != NULL) {
[c->window setBackgroundColor:[NSColor blueColor]];
MilskoCocoa *p = parent->cocoa.real; MilskoCocoa *p = parent->cocoa.real;
[p->window addChildWindow:c->window ordered:NSWindowAbove]; [p->window addChildWindow:c->window ordered:NSWindowAbove];
} }
@ -140,13 +141,16 @@
NSPoint p; NSPoint p;
p.x = x; p.x = x;
p.y = y; p.y = y;
[self->window setFrameTopLeftPoint:p]; NSRect frame = [self->window frame];
frame.origin.x = x;
frame.origin.y = y;
[self->window setFrame: frame display: YES animate: true];
}; };
- (void)setW:(int)w H:(int)h { - (void)setW:(int)w H:(int)h {
NSSize s; NSRect frame = [self->window frame];
s.width = w; frame.size.width = w;
s.height = h; frame.size.height = h;
[self->window setFrameSize:s]; [self->window setFrame: frame display: YES animate: true];
}; };
- (int)pending { - (int)pending {
return 1; return 1;
@ -189,7 +193,7 @@
MaxY:(int)maxy { MaxY:(int)maxy {
}; };
- (void)makeBorderless:(int)toggle { - (void)makeBorderless:(int)toggle {
NSWindowStyleMask mask = self->window.styleMask; uint32_t mask = [self->window styleMask];
if (mask & NSBorderlessWindowMask) { if (mask & NSBorderlessWindowMask) {
mask ^= NSBorderlessWindowMask; mask ^= NSBorderlessWindowMask;
mask |= NSTitledWindowMask; mask |= NSTitledWindowMask;
@ -197,7 +201,10 @@
mask |= NSBorderlessWindowMask; mask |= NSBorderlessWindowMask;
mask ^= NSTitledWindowMask; mask ^= NSTitledWindowMask;
} }
[self->window setStyleMask:mask]; [self->window initWithContentRect:self->rect
styleMask:mask
backing:NSBackingStoreBuffered
defer:NO];
}; };
- (void)focus { - (void)focus {
[self->window makeMainWindow]; [self->window makeMainWindow];
@ -217,12 +224,12 @@
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.width; _rect->width = [screen frame].size.width;
rect->height = screen.frame.size.height; _rect->height = [screen frame].size.height;
}; };
- (void)destroy { - (void)destroy {
[self->window dealloc]; [self->window dealloc];