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>
#endif
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject <NSApplicationDelegate> {
NSApplication *appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
@end
// Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject {
NSWindow *w;

View file

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