try and fail to have the app be activated without setting the activation policy
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
IoI_xD 2026-03-08 18:30:37 -07:00
commit c20da369e8
2 changed files with 889 additions and 865 deletions

View file

@ -21,6 +21,13 @@
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
#endif #endif
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject <NSApplicationDelegate> {
NSApplication *appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
@end
// Note: implements NSWindowDelegate // Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject { @interface MilskoCocoaWindowDelegate : NSObject {
NSWindow *w; NSWindow *w;

View file

@ -1,3 +1,4 @@
#include "Mw/BaseTypes.h"
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include <stdlib.h> #include <stdlib.h>
@ -104,7 +105,8 @@ static NSPoint pointFlip(NSPoint point) {
double offset = 0; double offset = 0;
NSWindow *parentWindow = parent->cocoa.real->window; NSWindow *parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height - [parentWindow frameRectForContentRect:[parentWindow frame]]
.size.height -
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height; [parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
c->rect.origin.x += [parentWindow frame].origin.x; c->rect.origin.x += [parentWindow frame].origin.x;
@ -116,7 +118,8 @@ static NSPoint pointFlip(NSPoint point) {
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
} }
[c->window setDelegate:[[MilskoCocoaWindowDelegate alloc] [c->window
setDelegate:(id<NSWindowDelegate>)[[MilskoCocoaWindowDelegate alloc]
initWithWin:c->window]]; initWithWin:c->window]];
[c->window makeKeyAndOrderFront:c->application]; [c->window makeKeyAndOrderFront:c->application];
@ -131,6 +134,9 @@ static NSPoint pointFlip(NSPoint point) {
[c->window makeFirstResponder:c->view]; [c->window makeFirstResponder:c->view];
} }
[c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc]
initWithAppl:c->application]];
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect]; c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
[c->view retain]; [c->view retain];
c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)]; c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
@ -145,6 +151,8 @@ static NSPoint pointFlip(NSPoint point) {
c->_forceRender = MwTRUE; c->_forceRender = MwTRUE;
c->strHash = 0; c->strHash = 0;
[c->application finishLaunching];
return c; return c;
} }
- (void)polygonWithPoints:(MwPoint *)points - (void)polygonWithPoints:(MwPoint *)points
@ -155,7 +163,8 @@ static NSPoint pointFlip(NSPoint point) {
if (ctx) { if (ctx) {
int i; int i;
NSBezierPath *path = [NSBezierPath bezierPath]; NSBezierPath *path = [NSBezierPath bezierPath];
NSColor* nscolor = [NSColor colorWithCalibratedRed:color->common.red / 255. NSColor *nscolor =
[NSColor colorWithCalibratedRed:color->common.red / 255.
green:color->common.green / 255. green:color->common.green / 255.
blue:color->common.blue / 255. blue:color->common.blue / 255.
alpha:1.0]; alpha:1.0];
@ -211,7 +220,8 @@ static NSPoint pointFlip(NSPoint point) {
double offset = 0; double offset = 0;
NSWindow *parentWindow = parent->cocoa.real->window; NSWindow *parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height - [parentWindow frameRectForContentRect:[parentWindow frame]]
.size.height -
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height; [parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
if (x < [parentWindow frame].origin.x) { if (x < [parentWindow frame].origin.x) {
@ -224,6 +234,8 @@ static NSPoint pointFlip(NSPoint point) {
[self->view setFrameSize:frame.size]; [self->view setFrameSize:frame.size];
[self->window setFrame:frame display:YES animate:false]; [self->window setFrame:frame display:YES animate:false];
[self forceRender];
}; };
- (void)setW:(int)w H:(int)h { - (void)setW:(int)w H:(int)h {
NSRect frame = [self->window frame]; NSRect frame = [self->window frame];
@ -234,6 +246,7 @@ static NSPoint pointFlip(NSPoint point) {
[self->view setFrameSize:frame.size]; [self->view setFrameSize:frame.size];
[self->window setFrame:frame display:YES animate:false]; [self->window setFrame:frame display:YES animate:false];
[self forceRender];
}; };
- (int)pending { - (int)pending {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@ -288,7 +301,8 @@ static NSPoint pointFlip(NSPoint point) {
[pool release]; [pool release];
return; return;
} else { } else {
h = [((MilskoFakePointer*)[[[win contentView] subviews] objectAtIndex:0]) pointer]; h = [((MilskoFakePointer *)[[[win contentView] subviews]
objectAtIndex:0]) pointer];
} }
switch ([ev type]) { switch ([ev type]) {
@ -523,14 +537,12 @@ static NSPoint pointFlip(NSPoint point) {
size_t size = 0; size_t size = 0;
for(NSPasteboardItem* item in [pasteboard pasteboardItems]) { for(NSPasteboardItem* item in [pasteboard pasteboardItems]) {
for(NSString* it in items) { for(NSString* it in items) {
NSString* itemData = [item stringForType:(NSString*)it]; NSString* itemData = [item
if(itemData != NULL) { stringForType:(NSString*)it]; if(itemData != NULL) { if(strHash != 0 &&
if(strHash != 0 && strHash != [itemData hash]) { strHash != [itemData hash]) { char* text = malloc([itemData length]);
char* text = malloc([itemData length]); strncpy(text, [itemData UTF8String],
strncpy(text, [itemData UTF8String], [itemData length]); [itemData length]); MwLLDispatch(this, clipboard, text); printf("%s -> %p\n",
MwLLDispatch(this, clipboard, text); text, this); free(text);
printf("%s -> %p\n", text, this);
free(text);
} }
strHash = [itemData hash]; strHash = [itemData hash];
} }
@ -555,8 +567,8 @@ static NSPoint pointFlip(NSPoint point) {
[NSGraphicsContext saveGraphicsState]; [NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:ctx]; [NSGraphicsContext setCurrentContext:ctx];
[[p image] drawInRect:NSMakeRect(_rect->x, _rect->y, _rect->width, [[p image]
_rect->height) drawInRect:NSMakeRect(_rect->x, _rect->y, _rect->width, _rect->height)
fromRect:NSZeroRect fromRect:NSZeroRect
operation:NSCompositeSourceOver operation:NSCompositeSourceOver
fraction:1.0]; fraction:1.0];
@ -571,7 +583,16 @@ static NSPoint pointFlip(NSPoint point) {
(void)pixmap; (void)pixmap;
}; };
- (void)forceRender { - (void)forceRender {
_forceRender = MwTRUE; NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
}; };
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask { - (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
(void)image; (void)image;
@ -622,9 +643,9 @@ static NSPoint pointFlip(NSPoint point) {
// TODO: find out how to do this while supporting 10.4 // TODO: find out how to do this while supporting 10.4
// NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; // NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
// [pasteboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString] owner:nil]; // [pasteboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString]
// [pasteboard setString:[NSString stringWithUTF8String:text] forType:NSPasteboardTypeString]; // owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text]
// [pool release]; // forType:NSPasteboardTypeString]; [pool release];
}; };
- (void)getClipboard { - (void)getClipboard {
}; };
@ -749,6 +770,16 @@ static NSPoint pointFlip(NSPoint point) {
@end @end
@implementation MilskoCocoaApplicationDelegate
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)_appl {
self->appl = _appl;
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self->appl activateIgnoringOtherApps:MwTRUE];
}
@end
@implementation MilskoCocoaWindowDelegate @implementation MilskoCocoaWindowDelegate
- (NSSize)windowWillResize:(NSWindow *)win toSize:(NSSize)frameSize; - (NSSize)windowWillResize:(NSWindow *)win toSize:(NSSize)frameSize;
@ -833,13 +864,9 @@ static void MwLLDestroyImpl(MwLL handle) {
free(handle); free(handle);
} }
static void MwLLBeginDrawImpl(MwLL handle) { static void MwLLBeginDrawImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLEndDrawImpl(MwLL handle) { static void MwLLEndDrawImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLPolygonImpl(MwLL handle, MwPoint *points, int points_count, static void MwLLPolygonImpl(MwLL handle, MwPoint *points, int points_count,
MwLLColor color) { MwLLColor color) {
@ -882,9 +909,7 @@ static void MwLLSetWHImpl(MwLL handle, int w, int height) {
[h setW:w H:height]; [h setW:w H:height];
} }
static void MwLLFreeColorImpl(MwLLColor color) { static void MwLLFreeColorImpl(MwLLColor color) { free(color); }
free(color);
}
static int MwLLPendingImpl(MwLL handle) { static int MwLLPendingImpl(MwLL handle) {
MilskoCocoa *h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
@ -998,9 +1023,7 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
[h setClipboard:text]; [h setClipboard:text];
} }
static void MwLLGetClipboardImpl(MwLL handle) { static void MwLLGetClipboardImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLMakeToolWindowImpl(MwLL handle) { static void MwLLMakeToolWindowImpl(MwLL handle) {
@ -1018,17 +1041,11 @@ static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
[h getScreenSize:rect]; [h getScreenSize:rect];
} }
static void MwLLBeginStateChangeImpl(MwLL handle) { static void MwLLBeginStateChangeImpl(MwLL handle) { MwLLShow(handle, 0); }
MwLLShow(handle, 0);
}
static void MwLLEndStateChangeImpl(MwLL handle) { static void MwLLEndStateChangeImpl(MwLL handle) { MwLLShow(handle, 1); }
MwLLShow(handle, 1);
}
static int MwLLCocoaCallInitImpl(void) { static int MwLLCocoaCallInitImpl(void) { return 0; }
return 0;
}
#include "call.c" #include "call.c"
CALL(Cocoa); CALL(Cocoa);