mac: try and fix positioning for child windows

This commit is contained in:
IoIxD 2026-03-08 19:15:17 -07:00
commit 75c9af91d1
2 changed files with 45 additions and 31 deletions

View file

@ -22,7 +22,7 @@
#endif #endif
// Note: implements NSApplicationDelegate // Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject <NSApplicationDelegate> { @interface MilskoCocoaApplicationDelegate : NSObject {
NSApplication *appl; NSApplication *appl;
} }
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl; - (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;

View file

@ -1,5 +1,7 @@
#include "Mw/BaseTypes.h" #include "Mw/BaseTypes.h"
#include <AppKit/NSGraphicsContext.h>
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef __clang__ #ifdef __clang__
@ -102,24 +104,23 @@ static NSPoint pointFlip(NSPoint point) {
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
} else { } else {
double offset = 0; double offset = 0;
NSWindow *parentWindow = parent->cocoa.real->window; NSWindow* parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]] [parentWindow frameRectForContentRect:[parentWindow frame]].size.height -
.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;
c->rect.origin.y -= [parentWindow frame].origin.y - offset; c->rect.origin.y -= [parentWindow frame].origin.y - offset;
c->rect.origin.y -= offset; c->rect.origin.y -= offset;
c->window = [[NSWindow alloc] initWithContentRect:c->rect c->window = [[NSWindow alloc] initWithContentRect:c->rect
styleMask:NSBorderlessWindowMask styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
} }
[c->window [c->window
setDelegate:(id<NSWindowDelegate>)[[MilskoCocoaWindowDelegate alloc] setDelegate:[[MilskoCocoaWindowDelegate alloc]
initWithWin:c->window]]; initWithWin:c->window]];
[c->window makeKeyAndOrderFront:c->application]; [c->window makeKeyAndOrderFront:c->application];
@ -127,8 +128,17 @@ static NSPoint pointFlip(NSPoint point) {
if (parent != NULL) { if (parent != NULL) {
MilskoCocoa *p = parent->cocoa.real; MilskoCocoa *p = parent->cocoa.real;
double offset = 0;
offset =
[p->window frameRectForContentRect:[p->window frame]].size.height -
[p->window contentRectForFrameRect:[p->window frame]].size.height;
[p->window addChildWindow:c->window ordered:NSWindowAbove]; [p->window addChildWindow:c->window ordered:NSWindowAbove];
[c->window setHasShadow:MwFALSE]; [c->window setHasShadow:MwFALSE];
[c->window setParentWindow:p->window];
c->rect.origin.x += [p->window frame].origin.x;
c->rect.origin.y -= [p->window frame].origin.y - offset;
c->rect.origin.y -= offset;
} else { } else {
[c->application activateIgnoringOtherApps:true]; [c->application activateIgnoringOtherApps:true];
[c->window makeFirstResponder:c->view]; [c->window makeFirstResponder:c->view];
@ -202,6 +212,11 @@ static NSPoint pointFlip(NSPoint point) {
NSRect frame = rectFlip([self->window frame]); NSRect frame = rectFlip([self->window frame]);
frame = rectFlip(frame); frame = rectFlip(frame);
if(parent) {
frame.origin.x -= [parent->cocoa.real->window frame].origin.x;
frame.origin.y += [parent->cocoa.real->window frame].origin.y;
}
*x = frame.origin.x; *x = frame.origin.x;
*y = frame.origin.y; *y = frame.origin.y;
@ -216,24 +231,21 @@ static NSPoint pointFlip(NSPoint point) {
frame = rectFlip(frame); frame = rectFlip(frame);
if (parent) { if(parent) {
double offset = 0; double offset = 0;
NSWindow *parentWindow = parent->cocoa.real->window; NSWindow* parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]] [parentWindow frameRectForContentRect:[parentWindow frame]].size.height -
.size.height - [parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
if (x < [parentWindow frame].origin.x) {
frame.origin.x += [parentWindow frame].origin.x;
}
frame.origin.x += [parentWindow frame].origin.x;
frame.origin.y -= [parentWindow frame].origin.y - offset; frame.origin.y -= [parentWindow frame].origin.y - offset;
frame.origin.y -= offset; frame.origin.y -= offset;
} }
[self->view setFrameSize:frame.size]; [self->view setFrameSize:frame.size];
[self->window setFrame:frame display:YES animate:false]; [self->window setFrameOrigin:frame.origin];
[self forceRender]; [self forceRender];
}; };
@ -583,7 +595,8 @@ static NSPoint pointFlip(NSPoint point) {
(void)pixmap; (void)pixmap;
}; };
- (void)forceRender { - (void)forceRender {
NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0, 0) location:NSMakePoint(0, 0)
modifierFlags:0 modifierFlags:0
timestamp:0 timestamp:0
@ -593,6 +606,7 @@ static NSPoint pointFlip(NSPoint point) {
data1:0 data1:0
data2:0]; data2:0];
[NSApp postEvent:event atStart:YES]; [NSApp postEvent:event atStart:YES];
[pool release];
}; };
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask { - (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
(void)image; (void)image;