mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 08:56:25 +00:00
Don't change the display of a window until it is mostly on the new one
Fixes https://github.com/libsdl-org/SDL/issues/12665
This commit is contained in:
@@ -1800,6 +1800,32 @@ static void SDL_CheckWindowDisplayChanged(SDL_Window *window)
|
|||||||
|
|
||||||
SDL_DisplayID displayID = SDL_GetDisplayForWindowPosition(window);
|
SDL_DisplayID displayID = SDL_GetDisplayForWindowPosition(window);
|
||||||
|
|
||||||
|
if (displayID != window->displayID) {
|
||||||
|
// See if we are fully committed to the new display
|
||||||
|
// 80% is about the right value, tested with 350% scale on the left monitor and 100% scale on the right
|
||||||
|
SDL_Rect old_bounds, new_bounds;
|
||||||
|
SDL_Rect window_rect;
|
||||||
|
SDL_Rect old_overlap, new_overlap;
|
||||||
|
|
||||||
|
if (SDL_GetDisplayBounds(window->displayID, &old_bounds) &&
|
||||||
|
SDL_GetDisplayBounds(displayID, &new_bounds)) {
|
||||||
|
window_rect.x = window->x;
|
||||||
|
window_rect.y = window->y;
|
||||||
|
window_rect.w = window->w;
|
||||||
|
window_rect.h = window->h;
|
||||||
|
|
||||||
|
if (SDL_GetRectIntersection(&old_bounds, &window_rect, &old_overlap) &&
|
||||||
|
SDL_GetRectIntersection(&new_bounds, &window_rect, &new_overlap)) {
|
||||||
|
int old_area = old_overlap.w * old_overlap.h;
|
||||||
|
int new_area = new_overlap.w * new_overlap.h;
|
||||||
|
float new_overlap_ratio = (new_area / ((float)old_area + new_area));
|
||||||
|
if (new_overlap_ratio < 0.80) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (displayID != window->displayID) {
|
if (displayID != window->displayID) {
|
||||||
int i, display_index;
|
int i, display_index;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user