Better default position for window on macOS

This commit is contained in:
Ebrahim Byagowi 2017-06-27 19:15:27 +04:30
parent 5fa7ba487e
commit c7d3670472
1 changed files with 9 additions and 0 deletions

View File

@ -367,6 +367,8 @@ static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data)
// do nothing
}
static NSPoint lastTopLeftPoint;
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
{
uiWindow *w;
@ -381,6 +383,13 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
defer:YES];
[w->window setTitle:toNSString(title)];
if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
// issue "cascadeTopLeftFromPoint" twice on first time
// to have window position in a good place
lastTopLeftPoint = [w->window cascadeTopLeftFromPoint:lastTopLeftPoint];
}
lastTopLeftPoint = [w->window cascadeTopLeftFromPoint:lastTopLeftPoint];
// do NOT release when closed
// we manually do this in uiWindowDestroy() above
[w->window setReleasedWhenClosed:NO];