Skip to content

Commit

Permalink
Add handling for SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED and SDL_HINT_WI…
Browse files Browse the repository at this point in the history
…NDOW_ACTIVATE_WHEN_SHOWN on macOS

- Cocoa_ShowWindow will order a window that is not being activated below the key window (if one exists) then set visible

- Cocoa_RaiseWindow calls -[NSWindow orderFront:] without changing the key window
  • Loading branch information
slouken committed Jun 18, 2023
1 parent f168f9c commit 9351bf6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/video/cocoa/SDL_cocoawindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -2139,14 +2139,23 @@ void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
@autoreleasepool {
SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow;
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE);

if (![nswindow isMiniaturized]) {
[windowData.listener pauseVisibleObservation];
if (SDL_WINDOW_IS_POPUP(window)) {
NSWindow *nsparent = ((__bridge SDL_CocoaWindowData *)window->parent->driverdata).nswindow;
[nsparent addChildWindow:nswindow ordered:NSWindowAbove];
}
[nswindow makeKeyAndOrderFront:nil];
if (bActivate) {
[nswindow makeKeyAndOrderFront:nil];
} else {
/* Order this window below the key window if we're not activating it */
if ([NSApp keyWindow]) {
[nswindow orderWindow:NSWindowBelow relativeTo:[[NSApp keyWindow] windowNumber]];
}
[nswindow setIsVisible:YES];
}
[windowData.listener resumeVisibleObservation];
}
}
Expand Down Expand Up @@ -2180,9 +2189,10 @@ void Cocoa_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
@autoreleasepool {
SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow;
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, SDL_TRUE);

/* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
a minimized or hidden window, so check for that before showing it.
a minimized or hidden window, so check for that before showing it.
*/
[windowData.listener pauseVisibleObservation];
if (![nswindow isMiniaturized] && [nswindow isVisible]) {
Expand All @@ -2191,7 +2201,12 @@ void Cocoa_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
NSWindow *nsparent = ((__bridge SDL_CocoaWindowData *)window->parent->driverdata).nswindow;
[nsparent addChildWindow:nswindow ordered:NSWindowAbove];
}
[nswindow makeKeyAndOrderFront:nil];

if (bActivate) {
[nswindow makeKeyAndOrderFront:nil];
} else {
[nswindow orderFront:nil];
}
}
[windowData.listener resumeVisibleObservation];
}
Expand Down

0 comments on commit 9351bf6

Please sign in to comment.