mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 23:07:45 +08:00
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:
@@ -215,32 +215,32 @@ static void EnsurePopupPositionIsValid(SDL_Window *window, int *x, int *y)
|
|||||||
int adj_count = 0;
|
int adj_count = 0;
|
||||||
|
|
||||||
/* Per the xdg-positioner spec, child popup windows must intersect or at
|
/* 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
|
* Failure to ensure this on a compositor that enforces this restriction
|
||||||
* can result in behavior ranging from the window being spuriously closed
|
* can result in behavior ranging from the window being spuriously closed
|
||||||
* to a protocol violation.
|
* to a protocol violation.
|
||||||
*/
|
*/
|
||||||
if (*x + window->w < 0) {
|
if (*x + window->w <= 0) {
|
||||||
*x = -window->w;
|
*x = -window->w;
|
||||||
++adj_count;
|
++adj_count;
|
||||||
}
|
}
|
||||||
if (*y + window->h < 0) {
|
if (*y + window->h <= 0) {
|
||||||
*y = -window->h;
|
*y = -window->h;
|
||||||
++adj_count;
|
++adj_count;
|
||||||
}
|
}
|
||||||
if (*x > window->parent->w) {
|
if (*x >= window->parent->w) {
|
||||||
*x = window->parent->w;
|
*x = window->parent->w;
|
||||||
++adj_count;
|
++adj_count;
|
||||||
}
|
}
|
||||||
if (*y > window->parent->h) {
|
if (*y >= window->parent->h) {
|
||||||
*y = window->parent->h;
|
*y = window->parent->h;
|
||||||
++adj_count;
|
++adj_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If adjustment was required on the x and y axes, the popup is aligned with
|
/* 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
|
* the parent corner-to-corner and is neither overlapping nor adjoining, so it
|
||||||
* must be nudged by 1 to be considered adjacent.
|
* must be nudged by 1 to be considered adjoining.
|
||||||
*/
|
*/
|
||||||
if (adj_count > 1) {
|
if (adj_count > 1) {
|
||||||
*x += *x < 0 ? 1 : -1;
|
*x += *x < 0 ? 1 : -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user