Skip to content

Commit

Permalink
video: Try to get the display for fullscreen windows via the window p…
Browse files Browse the repository at this point in the history
…osition

Attempt to retrieve the display for fullscreen windows using the window position so that the correct display ID is returned if an exclusive fullscreen window is moved to another display.
  • Loading branch information
Kontrabant authored and slouken committed Feb 7, 2023
1 parent a357021 commit d603371
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/video/SDL_video.c
Expand Up @@ -1256,9 +1256,6 @@ SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window)
* (for example if the window is off-screen), but other code may expect it
* to succeed in that situation, so we fall back to a generic position-
* based implementation in that case. */
if (!displayID && (window->flags & SDL_WINDOW_FULLSCREEN)) {
displayID = window->fullscreen_mode.displayID;
}
if (!displayID) {
displayID = SDL_GetDisplayForWindowCoordinate(window->windowed.x);
}
Expand All @@ -1267,10 +1264,14 @@ SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window)
}
if (!displayID) {
displayID = GetDisplayForRect(window->x, window->y, window->w, window->h);
if (!displayID) {
/* Use the primary display for a window if we can't find it anywhere else */
displayID = SDL_GetPrimaryDisplay();
}
}
if (!displayID && (window->flags & SDL_WINDOW_FULLSCREEN)) {
/* Use the explicit fullscreen display if retrieval via the window position fails */
displayID = window->fullscreen_mode.displayID;
}
if (!displayID) {
/* Use the primary display for a window if we can't find it anywhere else */
displayID = SDL_GetPrimaryDisplay();
}
return displayID;
}
Expand Down Expand Up @@ -1514,8 +1515,16 @@ int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode)

if (SDL_WINDOW_FULLSCREEN_VISIBLE(window)) {
SDL_UpdateFullscreenMode(window, SDL_TRUE);
} else {
SDL_CheckWindowDisplayChanged(window);
} else if (window->flags & SDL_WINDOW_FULLSCREEN) {
/* If fullscreen and not visible, just update the position so the window will be
* on the correct display when shown/restored.
*/
if (mode) {
SDL_Rect r;
if (SDL_GetDisplayBounds(mode->displayID, &r) == 0) {
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, r.x, r.y);
}
}
}
return 0;
}
Expand Down

0 comments on commit d603371

Please sign in to comment.