From 39db13fa486d7cadd3d2233f523a807e5e076ef4 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Wed, 4 Mar 2026 23:06:56 -0700 Subject: [PATCH] mac: center window when MwDEFAULT is passed --- src/backend/cocoa.m | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 700ebdb..0b230eb 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -82,15 +82,12 @@ static CGPoint pointFlip(CGPoint point) { height:(int)height handle:(MwLL)r { MilskoCocoa *c = [MilskoCocoa alloc]; - bool centerX = false, centerY = false; if (x == MwDEFAULT) { - x = 0; - centerX = true; + x = ([NSScreen mainScreen].frame.size.width / 2.) - (width / 2.); } if (y == MwDEFAULT) { - y = 0; - centerY = true; + y = ([NSScreen mainScreen].frame.size.height / 2.) - (height / 2.); } c->application = [NSApplication sharedApplication]; c->rect = rectFlip(NSMakeRect(x, y, width, height)); @@ -108,6 +105,9 @@ static CGPoint pointFlip(CGPoint point) { offset = [parentWindow frameRectForContentRect:parentWindow.frame].size.height - [parentWindow contentRectForFrameRect:parentWindow.frame].size.height; + + c->rect.origin.x += parentWindow.frame.origin.x; + c->rect.origin.y -= parentWindow.frame.origin.y - offset; c->rect.origin.y -= offset; c->window = [[NSWindow alloc] initWithContentRect:c->rect @@ -204,7 +204,15 @@ static CGPoint pointFlip(CGPoint point) { offset = [parentWindow frameRectForContentRect:parentWindow.frame].size.height - [parentWindow contentRectForFrameRect:parentWindow.frame].size.height; - frame.origin.y -= offset; + + if (x < parentWindow.frame.origin.x) { + frame.origin.x += parentWindow.frame.origin.x; + } + + if (y < parentWindow.frame.origin.y) { + frame.origin.y -= parentWindow.frame.origin.y - offset; + frame.origin.y -= offset; + } } [self->view setFrameSize:frame.size];