xdg-positioner: fix sliding regression

This commit fixes a regression introduced in
511f137f8f where GTK tooltips wouldn't be
unconstrained due to no gravity on x axis being set, in which case the
behavior is ambiguous, by sliding to the right/bottom.
master
Kirill Primak 3 years ago committed by Simon Ser
parent 104060fec5
commit 2d623724c3

@ -343,13 +343,10 @@ static bool xdg_positioner_rules_unconstrain_by_slide(
struct constraint_offsets *offsets) { struct constraint_offsets *offsets) {
uint32_t gravity = xdg_positioner_gravity_to_wlr_edges(rules->gravity); uint32_t gravity = xdg_positioner_gravity_to_wlr_edges(rules->gravity);
// We can only slide if there is gravity on this axis
bool slide_x = (offsets->left > 0 || offsets->right > 0) && bool slide_x = (offsets->left > 0 || offsets->right > 0) &&
(rules->constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X) && (rules->constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X);
(gravity & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT));
bool slide_y = (offsets->top > 0 || offsets->bottom > 0) && bool slide_y = (offsets->top > 0 || offsets->bottom > 0) &&
(rules->constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y) && (rules->constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y);
(gravity & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM));
if (!slide_x && !slide_y) { if (!slide_x && !slide_y) {
return false; return false;
@ -363,9 +360,13 @@ static bool xdg_positioner_rules_unconstrain_by_slide(
// the box is bigger than the anchor rect and completely includes it. // the box is bigger than the anchor rect and completely includes it.
// In this case, the second slide will fail immediately, so simply // In this case, the second slide will fail immediately, so simply
// slide towards the direction of the gravity. // slide towards the direction of the gravity.
// Note that the protocol doesn't specify the behavior when there is no
// gravity on the axis (which is what e.g. GTK tooltips use). In this
// case, fall back to sliding the box to the right/bottom, which is what
// GTK X11 popup adjustment code does.
if (gravity & WLR_EDGE_LEFT) { if (gravity & WLR_EDGE_LEFT) {
box->x -= offsets->right; box->x -= offsets->right;
} else if (gravity & WLR_EDGE_RIGHT) { } else {
box->x += offsets->left; box->x += offsets->left;
} }
} else { } else {
@ -386,7 +387,7 @@ static bool xdg_positioner_rules_unconstrain_by_slide(
if (offsets->top > 0 && offsets->bottom > 0) { if (offsets->top > 0 && offsets->bottom > 0) {
if (gravity & WLR_EDGE_TOP) { if (gravity & WLR_EDGE_TOP) {
box->y -= offsets->bottom; box->y -= offsets->bottom;
} else if (gravity & WLR_EDGE_BOTTOM) { } else {
box->y += offsets->top; box->y += offsets->top;
} }
} else { } else {

Loading…
Cancel
Save