Skip to content
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

xdg-shell: Continue transform of popup until size fits #6521

Merged
merged 4 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions src/protocols/XDGShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,30 +534,33 @@ CBox CXDGPositionerRules::getPosition(const CBox& constraint, const Vector2D& pa
if (success)
return predictedBox.translate(-parentCoord - constraint.pos());

CBox test = predictedBox;

if (state.constraintAdjustment & (XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X | XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y)) {
// attempt to flip
const bool flipX = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X;
const bool flipY = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y;

CBox test = predictedBox;
success = true;
if (flipX && test.copy().translate(Vector2D{-predictedBox.w - state.anchorRect.w, 0}).expand(-1).inside(constraint))
const bool flipX = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X;
const bool flipY = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y;
auto countEdges = [constraint](const CBox& test) -> int {
int edgeCount = 0;
edgeCount += test.x < constraint.x ? 1 : 0;
edgeCount += test.x + test.w > constraint.x + constraint.w ? 1 : 0;
edgeCount += test.y < constraint.y ? 1 : 0;
edgeCount += test.y + test.h > constraint.y + constraint.h ? 1 : 0;
return edgeCount;
};
int edgeCount = countEdges(test);

if (flipX && edgeCount > countEdges(test.copy().translate(Vector2D{-predictedBox.w - state.anchorRect.w, 0})))
test.translate(Vector2D{-predictedBox.w - state.anchorRect.w, 0});
else if (flipY && test.copy().translate(Vector2D{0, -predictedBox.h - state.anchorRect.h}).expand(-1).inside(constraint))
if (flipY && edgeCount > countEdges(test.copy().translate(Vector2D{0, -predictedBox.h - state.anchorRect.h})))
test.translate(Vector2D{0, -predictedBox.h - state.anchorRect.h});
else if (flipX && flipY && test.copy().translate(Vector2D{-predictedBox.w - state.anchorRect.w, -predictedBox.h - state.anchorRect.h}).expand(-1).inside(constraint))
test.translate(Vector2D{-predictedBox.w - state.anchorRect.w, -predictedBox.h - state.anchorRect.h});
else
success = false;

success = test.copy().expand(-1).inside(constraint);

if (success)
return test.translate(-parentCoord - constraint.pos());
}

// if flips fail, we will slide and remember.
// if the positioner is allowed to resize, then resize the slid thing.
CBox test = predictedBox;

// for slide and resize, defines the padding around the edge for the positioned
// surface.
constexpr int EDGE_PADDING = 4;
Expand All @@ -570,10 +573,10 @@ CBox CXDGPositionerRules::getPosition(const CBox& constraint, const Vector2D& pa
//const bool gravityLeft = state.gravity == XDG_POSITIONER_GRAVITY_NONE || state.gravity == XDG_POSITIONER_GRAVITY_LEFT || state.gravity == XDG_POSITIONER_GRAVITY_TOP_LEFT || state.gravity == XDG_POSITIONER_GRAVITY_BOTTOM_LEFT;
//const bool gravityTop = state.gravity == XDG_POSITIONER_GRAVITY_NONE || state.gravity == XDG_POSITIONER_GRAVITY_TOP || state.gravity == XDG_POSITIONER_GRAVITY_TOP_LEFT || state.gravity == XDG_POSITIONER_GRAVITY_TOP_RIGHT;

const bool leftEdgeOut = predictedBox.x < constraint.x;
const bool topEdgeOut = predictedBox.y < constraint.y;
const bool rightEdgeOut = predictedBox.x + predictedBox.w > constraint.x + constraint.w;
const bool bottomEdgeOut = predictedBox.y + predictedBox.h > constraint.y + constraint.h;
const bool leftEdgeOut = test.x < constraint.x;
const bool topEdgeOut = test.y < constraint.y;
const bool rightEdgeOut = test.x + test.w > constraint.x + constraint.w;
const bool bottomEdgeOut = test.y + test.h > constraint.y + constraint.h;

// TODO: this isn't truly conformant.
if (leftEdgeOut && slideX)
Expand All @@ -595,10 +598,10 @@ CBox CXDGPositionerRules::getPosition(const CBox& constraint, const Vector2D& pa
const bool resizeX = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X;
const bool resizeY = state.constraintAdjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y;

const bool leftEdgeOut = predictedBox.x < constraint.x;
const bool topEdgeOut = predictedBox.y < constraint.y;
const bool rightEdgeOut = predictedBox.x + predictedBox.w > constraint.x + constraint.w;
const bool bottomEdgeOut = predictedBox.y + predictedBox.h > constraint.y + constraint.h;
const bool leftEdgeOut = test.x < constraint.x;
const bool topEdgeOut = test.y < constraint.y;
const bool rightEdgeOut = test.x + test.w > constraint.x + constraint.w;
const bool bottomEdgeOut = test.y + test.h > constraint.y + constraint.h;

// TODO: this isn't truly conformant.
if (leftEdgeOut && resizeX) {
Expand Down
Loading