Changeset View
Changeset View
Standalone View
Standalone View
xdgshellclient.cpp
Show First 20 Lines • Show All 1636 Lines • ▼ Show 20 Line(s) | 1634 | { | |||
---|---|---|---|---|---|
1637 | QRect anchorRect; | 1637 | QRect anchorRect; | ||
1638 | Qt::Edges anchorEdge; | 1638 | Qt::Edges anchorEdge; | ||
1639 | Qt::Edges gravity; | 1639 | Qt::Edges gravity; | ||
1640 | QPoint offset; | 1640 | QPoint offset; | ||
1641 | PositionerConstraints constraintAdjustments; | 1641 | PositionerConstraints constraintAdjustments; | ||
1642 | QSize size = frameGeometry().size(); | 1642 | QSize size = frameGeometry().size(); | ||
1643 | 1643 | | |||
1644 | const QPoint parentClientPos = transientFor()->pos() + transientFor()->clientPos(); | 1644 | const QPoint parentClientPos = transientFor()->pos() + transientFor()->clientPos(); | ||
1645 | QRect popupPosition; | | |||
1646 | 1645 | | |||
1647 | // returns if a target is within the supplied bounds, optional edges argument states which side to check | 1646 | // returns if a target is within the supplied bounds, optional edges argument states which side to check | ||
1648 | auto inBounds = [bounds](const QRect &target, Qt::Edges edges = Qt::LeftEdge | Qt::RightEdge | Qt::TopEdge | Qt::BottomEdge) -> bool { | 1647 | auto inBounds = [bounds](const QRect &target, Qt::Edges edges = Qt::LeftEdge | Qt::RightEdge | Qt::TopEdge | Qt::BottomEdge) -> bool { | ||
1649 | if (edges & Qt::LeftEdge && target.left() < bounds.left()) { | 1648 | if (edges & Qt::LeftEdge && target.left() < bounds.left()) { | ||
1650 | return false; | 1649 | return false; | ||
1651 | } | 1650 | } | ||
1652 | if (edges & Qt::TopEdge && target.top() < bounds.top()) { | 1651 | if (edges & Qt::TopEdge && target.top() < bounds.top()) { | ||
1653 | return false; | 1652 | return false; | ||
Show All 12 Lines | |||||
1666 | anchorEdge = m_xdgShellPopup->anchorEdge(); | 1665 | anchorEdge = m_xdgShellPopup->anchorEdge(); | ||
1667 | gravity = m_xdgShellPopup->gravity(); | 1666 | gravity = m_xdgShellPopup->gravity(); | ||
1668 | offset = m_xdgShellPopup->anchorOffset(); | 1667 | offset = m_xdgShellPopup->anchorOffset(); | ||
1669 | constraintAdjustments = m_xdgShellPopup->constraintAdjustments(); | 1668 | constraintAdjustments = m_xdgShellPopup->constraintAdjustments(); | ||
1670 | if (!size.isValid()) { | 1669 | if (!size.isValid()) { | ||
1671 | size = m_xdgShellPopup->initialSize(); | 1670 | size = m_xdgShellPopup->initialSize(); | ||
1672 | } | 1671 | } | ||
1673 | 1672 | | |||
1674 | //initial position | 1673 | QRect popupRect(popupOffset(anchorRect, anchorEdge, gravity, size) + offset + parentClientPos, size); | ||
1675 | popupPosition = QRect(popupOffset(anchorRect, anchorEdge, gravity, size) + offset + parentClientPos, size); | | |||
1676 | 1674 | | |||
1677 | //if that fits, we don't need to do anything | 1675 | //if that fits, we don't need to do anything | ||
1678 | if (inBounds(popupPosition)) { | 1676 | if (inBounds(popupRect)) { | ||
1679 | return popupPosition; | 1677 | return popupRect; | ||
1680 | } | 1678 | } | ||
1681 | //otherwise apply constraint adjustment per axis in order XDG Shell Popup states | 1679 | //otherwise apply constraint adjustment per axis in order XDG Shell Popup states | ||
1682 | 1680 | | |||
1683 | if (constraintAdjustments & PositionerConstraint::FlipX) { | 1681 | if (constraintAdjustments & PositionerConstraint::FlipX) { | ||
1684 | if (!inBounds(popupPosition, Qt::LeftEdge | Qt::RightEdge)) { | 1682 | if (!inBounds(popupRect, Qt::LeftEdge | Qt::RightEdge)) { | ||
1685 | //flip both edges (if either bit is set, XOR both) | 1683 | //flip both edges (if either bit is set, XOR both) | ||
1686 | auto flippedAnchorEdge = anchorEdge; | 1684 | auto flippedAnchorEdge = anchorEdge; | ||
1687 | if (flippedAnchorEdge & (Qt::LeftEdge | Qt::RightEdge)) { | 1685 | if (flippedAnchorEdge & (Qt::LeftEdge | Qt::RightEdge)) { | ||
1688 | flippedAnchorEdge ^= (Qt::LeftEdge | Qt::RightEdge); | 1686 | flippedAnchorEdge ^= (Qt::LeftEdge | Qt::RightEdge); | ||
1689 | } | 1687 | } | ||
1690 | auto flippedGravity = gravity; | 1688 | auto flippedGravity = gravity; | ||
1691 | if (flippedGravity & (Qt::LeftEdge | Qt::RightEdge)) { | 1689 | if (flippedGravity & (Qt::LeftEdge | Qt::RightEdge)) { | ||
1692 | flippedGravity ^= (Qt::LeftEdge | Qt::RightEdge); | 1690 | flippedGravity ^= (Qt::LeftEdge | Qt::RightEdge); | ||
1693 | } | 1691 | } | ||
1694 | auto flippedPopupPosition = QRect(popupOffset(anchorRect, flippedAnchorEdge, flippedGravity, size) + offset + parentClientPos, size); | 1692 | auto flippedPopupRect = QRect(popupOffset(anchorRect, flippedAnchorEdge, flippedGravity, size) + offset + parentClientPos, size); | ||
1695 | 1693 | | |||
1696 | //if it still doesn't fit we should continue with the unflipped version | 1694 | //if it still doesn't fit we should continue with the unflipped version | ||
1697 | if (inBounds(flippedPopupPosition, Qt::LeftEdge | Qt::RightEdge)) { | 1695 | if (inBounds(flippedPopupRect, Qt::LeftEdge | Qt::RightEdge)) { | ||
1698 | popupPosition.moveLeft(flippedPopupPosition.x()); | 1696 | popupRect.moveLeft(flippedPopupRect.left()); | ||
1699 | } | 1697 | } | ||
1700 | } | 1698 | } | ||
1701 | } | 1699 | } | ||
1702 | if (constraintAdjustments & PositionerConstraint::SlideX) { | 1700 | if (constraintAdjustments & PositionerConstraint::SlideX) { | ||
1703 | if (!inBounds(popupPosition, Qt::LeftEdge)) { | 1701 | if (!inBounds(popupRect, Qt::LeftEdge)) { | ||
1704 | popupPosition.moveLeft(bounds.x()); | 1702 | popupRect.moveLeft(bounds.left()); | ||
1705 | } | 1703 | } | ||
1706 | if (!inBounds(popupPosition, Qt::RightEdge)) { | 1704 | if (!inBounds(popupRect, Qt::RightEdge)) { | ||
1707 | popupPosition.moveRight(bounds.right()); | 1705 | popupRect.moveRight(bounds.right()); | ||
1708 | } | 1706 | } | ||
1709 | } | 1707 | } | ||
1710 | if (constraintAdjustments & PositionerConstraint::ResizeX) { | 1708 | if (constraintAdjustments & PositionerConstraint::ResizeX) { | ||
1711 | QRect unconstrainedRect = popupPosition; | 1709 | QRect unconstrainedRect = popupRect; | ||
1712 | 1710 | | |||
1713 | if (!inBounds(unconstrainedRect, Qt::LeftEdge)) { | 1711 | if (!inBounds(unconstrainedRect, Qt::LeftEdge)) { | ||
1714 | unconstrainedRect.setLeft(bounds.left()); | 1712 | unconstrainedRect.setLeft(bounds.left()); | ||
1715 | } | 1713 | } | ||
1716 | if (!inBounds(unconstrainedRect, Qt::RightEdge)) { | 1714 | if (!inBounds(unconstrainedRect, Qt::RightEdge)) { | ||
1717 | unconstrainedRect.setRight(bounds.right()); | 1715 | unconstrainedRect.setRight(bounds.right()); | ||
1718 | } | 1716 | } | ||
1719 | 1717 | | |||
1720 | if (unconstrainedRect.isValid()) { | 1718 | if (unconstrainedRect.isValid()) { | ||
1721 | popupPosition = unconstrainedRect; | 1719 | popupRect = unconstrainedRect; | ||
1722 | } | 1720 | } | ||
1723 | } | 1721 | } | ||
1724 | 1722 | | |||
1725 | if (constraintAdjustments & PositionerConstraint::FlipY) { | 1723 | if (constraintAdjustments & PositionerConstraint::FlipY) { | ||
1726 | if (!inBounds(popupPosition, Qt::TopEdge | Qt::BottomEdge)) { | 1724 | if (!inBounds(popupRect, Qt::TopEdge | Qt::BottomEdge)) { | ||
1727 | //flip both edges (if either bit is set, XOR both) | 1725 | //flip both edges (if either bit is set, XOR both) | ||
1728 | auto flippedAnchorEdge = anchorEdge; | 1726 | auto flippedAnchorEdge = anchorEdge; | ||
1729 | if (flippedAnchorEdge & (Qt::TopEdge | Qt::BottomEdge)) { | 1727 | if (flippedAnchorEdge & (Qt::TopEdge | Qt::BottomEdge)) { | ||
1730 | flippedAnchorEdge ^= (Qt::TopEdge | Qt::BottomEdge); | 1728 | flippedAnchorEdge ^= (Qt::TopEdge | Qt::BottomEdge); | ||
1731 | } | 1729 | } | ||
1732 | auto flippedGravity = gravity; | 1730 | auto flippedGravity = gravity; | ||
1733 | if (flippedGravity & (Qt::TopEdge | Qt::BottomEdge)) { | 1731 | if (flippedGravity & (Qt::TopEdge | Qt::BottomEdge)) { | ||
1734 | flippedGravity ^= (Qt::TopEdge | Qt::BottomEdge); | 1732 | flippedGravity ^= (Qt::TopEdge | Qt::BottomEdge); | ||
1735 | } | 1733 | } | ||
1736 | auto flippedPopupPosition = QRect(popupOffset(anchorRect, flippedAnchorEdge, flippedGravity, size) + offset + parentClientPos, size); | 1734 | auto flippedPopupRect = QRect(popupOffset(anchorRect, flippedAnchorEdge, flippedGravity, size) + offset + parentClientPos, size); | ||
1737 | 1735 | | |||
1738 | //if it still doesn't fit we should continue with the unflipped version | 1736 | //if it still doesn't fit we should continue with the unflipped version | ||
1739 | if (inBounds(flippedPopupPosition, Qt::TopEdge | Qt::BottomEdge)) { | 1737 | if (inBounds(flippedPopupRect, Qt::TopEdge | Qt::BottomEdge)) { | ||
1740 | popupPosition.moveTop(flippedPopupPosition.y()); | 1738 | popupRect.moveTop(flippedPopupRect.top()); | ||
1741 | } | 1739 | } | ||
1742 | } | 1740 | } | ||
1743 | } | 1741 | } | ||
1744 | if (constraintAdjustments & PositionerConstraint::SlideY) { | 1742 | if (constraintAdjustments & PositionerConstraint::SlideY) { | ||
1745 | if (!inBounds(popupPosition, Qt::TopEdge)) { | 1743 | if (!inBounds(popupRect, Qt::TopEdge)) { | ||
1746 | popupPosition.moveTop(bounds.y()); | 1744 | popupRect.moveTop(bounds.top()); | ||
1747 | } | 1745 | } | ||
1748 | if (!inBounds(popupPosition, Qt::BottomEdge)) { | 1746 | if (!inBounds(popupRect, Qt::BottomEdge)) { | ||
1749 | popupPosition.moveBottom(bounds.bottom()); | 1747 | popupRect.moveBottom(bounds.bottom()); | ||
1750 | } | 1748 | } | ||
1751 | } | 1749 | } | ||
1752 | if (constraintAdjustments & PositionerConstraint::ResizeY) { | 1750 | if (constraintAdjustments & PositionerConstraint::ResizeY) { | ||
1753 | QRect unconstrainedRect = popupPosition; | 1751 | QRect unconstrainedRect = popupRect; | ||
1754 | 1752 | | |||
1755 | if (!inBounds(unconstrainedRect, Qt::TopEdge)) { | 1753 | if (!inBounds(unconstrainedRect, Qt::TopEdge)) { | ||
1756 | unconstrainedRect.setTop(bounds.top()); | 1754 | unconstrainedRect.setTop(bounds.top()); | ||
1757 | } | 1755 | } | ||
1758 | if (!inBounds(unconstrainedRect, Qt::BottomEdge)) { | 1756 | if (!inBounds(unconstrainedRect, Qt::BottomEdge)) { | ||
1759 | unconstrainedRect.setBottom(bounds.bottom()); | 1757 | unconstrainedRect.setBottom(bounds.bottom()); | ||
1760 | } | 1758 | } | ||
1761 | 1759 | | |||
1762 | if (unconstrainedRect.isValid()) { | 1760 | if (unconstrainedRect.isValid()) { | ||
1763 | popupPosition = unconstrainedRect; | 1761 | popupRect = unconstrainedRect; | ||
1764 | } | 1762 | } | ||
1765 | } | 1763 | } | ||
1766 | 1764 | | |||
1767 | return popupPosition; | 1765 | return popupRect; | ||
1768 | } | 1766 | } | ||
1769 | 1767 | | |||
1770 | QPoint XdgShellClient::popupOffset(const QRect &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSize popupSize) const | 1768 | QPoint XdgShellClient::popupOffset(const QRect &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSize popupSize) const | ||
1771 | { | 1769 | { | ||
1772 | QPoint anchorPoint; | 1770 | QPoint anchorPoint; | ||
1773 | switch (anchorEdge & (Qt::LeftEdge | Qt::RightEdge)) { | 1771 | switch (anchorEdge & (Qt::LeftEdge | Qt::RightEdge)) { | ||
1774 | case Qt::LeftEdge: | 1772 | case Qt::LeftEdge: | ||
1775 | anchorPoint.setX(anchorRect.x()); | 1773 | anchorPoint.setX(anchorRect.x()); | ||
▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines |