cocoa: Return an error if GetWindowDisplayIndex() is called too early

SDL_CreateWindow() may call GetWindowDisplayIndex() to compute the position
of a new window that the caller has requested to be placed on a certain
display. Since we haven't fully constructed the window yet, our driverdata
will be nil and we will fail to get the NSScreen (which is fine). However,
we need to return an error (not 0, which is a valid display index) for
SDL_GetWindowDisplayIndex() to know to figure out the display index itself.

Fixes positioning new windows on secondary displays when using
SDL_WINDOWPOS_CENTERED_DISPLAY() and SDL_WINDOWPOS_UNDEFINED_DISPLAY().
main
Cameron Gutman 2022-08-12 22:02:26 -05:00 committed by Sam Lantinga
parent f1416ef2ba
commit 3046d55d0e
1 changed files with 1 additions and 1 deletions

View File

@ -2228,7 +2228,7 @@ Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window)
/* Not recognized via CHECK_WINDOW_MAGIC */
if (data == nil) {
return 0;
return SDL_SetError("Window data not set");
}
/* NSWindow.screen may be nil when the window is off-screen. */