Skip to content

Why add display area monitoring for setting the position of a child window? #12533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pipiwoaini opened this issue Mar 13, 2025 · 0 comments · May be fixed by #12840
Open

Why add display area monitoring for setting the position of a child window? #12533

pipiwoaini opened this issue Mar 13, 2025 · 0 comments · May be fixed by #12840
Assignees
Milestone

Comments

@pipiwoaini
Copy link

When the user drags the parent window, it may extend beyond the current display boundaries. However, setting the child window’s position at this moment triggers display boundary checks, causing the child window to be positioned above the parent, which disrupts the intended behavior.
static void WIN_ConstrainPopup(SDL_Window *window, bool output_to_pending)
{
// Clamp popup windows to the output borders
if (SDL_WINDOW_IS_POPUP(window)) {
SDL_Window *w;
SDL_DisplayID displayID;
SDL_Rect rect;
int abs_x = window->last_position_pending ? window->pending.x : window->floating.x;
int abs_y = window->last_position_pending ? window->pending.y : window->floating.y;
const int width = window->last_size_pending ? window->pending.w : window->floating.w;
const int height = window->last_size_pending ? window->pending.h : window->floating.h;
int offset_x = 0, offset_y = 0;

    // Calculate the total offset from the parents
    for (w = window->parent; SDL_WINDOW_IS_POPUP(w); w = w->parent) {
        offset_x += w->x;
        offset_y += w->y;
    }

    offset_x += w->x;
    offset_y += w->y;
    abs_x += offset_x;
    abs_y += offset_y;

    //// Constrain the popup window to the display of the toplevel parent
    //displayID = SDL_GetDisplayForWindow(w);
    //SDL_GetDisplayBounds(displayID, &rect);
    //if (abs_x + width > rect.x + rect.w) {
    //    abs_x -= (abs_x + width) - (rect.x + rect.w);
    //}
    //if (abs_y + height > rect.y + rect.h) {
    //    abs_y -= (abs_y + height) - (rect.y + rect.h);
    //}
    //abs_x = SDL_max(abs_x, rect.x);
    //abs_y = SDL_max(abs_y, rect.y);

    if (output_to_pending) {
        window->pending.x = abs_x - offset_x;
        window->pending.y = abs_y - offset_y;
        window->pending.w = width;
        window->pending.h = height;
    } else {
        window->floating.x = abs_x - offset_x;
        window->floating.y = abs_y - offset_y;
        window->floating.w = width;
        window->floating.h = height;
    }
}

}
So, is there a missing condition here?

@Kontrabant Kontrabant self-assigned this Mar 13, 2025
@Kontrabant Kontrabant added this to the 3.4.0 milestone Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants