wayland: Adjust popup adjoining check

The previous calculation could result in a window whose original position was positioned exactly corner-to-corner with the parent not being adjusted to be adjoining, and thus subject to spurious closure.

(cherry picked from commit b0cdb7143f)
This commit is contained in:
Frank Praznik
2025-07-31 12:13:07 -04:00
parent 30e3eba20a
commit 544eb2c5a9

View File

@@ -215,32 +215,32 @@ static void EnsurePopupPositionIsValid(SDL_Window *window, int *x, int *y)
int adj_count = 0;
/* Per the xdg-positioner spec, child popup windows must intersect or at
* least be partially adjacent to the parent window.
* least be partially adjoining the parent window.
*
* Failure to ensure this on a compositor that enforces this restriction
* can result in behavior ranging from the window being spuriously closed
* to a protocol violation.
*/
if (*x + window->w < 0) {
if (*x + window->w <= 0) {
*x = -window->w;
++adj_count;
}
if (*y + window->h < 0) {
if (*y + window->h <= 0) {
*y = -window->h;
++adj_count;
}
if (*x > window->parent->w) {
if (*x >= window->parent->w) {
*x = window->parent->w;
++adj_count;
}
if (*y > window->parent->h) {
if (*y >= window->parent->h) {
*y = window->parent->h;
++adj_count;
}
/* If adjustment was required on the x and y axes, the popup is aligned with
* the parent corner-to-corner and is neither overlapping nor adjacent, so it
* must be nudged by 1 to be considered adjacent.
* the parent corner-to-corner and is neither overlapping nor adjoining, so it
* must be nudged by 1 to be considered adjoining.
*/
if (adj_count > 1) {
*x += *x < 0 ? 1 : -1;