wayland: Move popupOffset() back to xdgshell.cpp
The InputPanelV1Window doesn't actually need popupOffset(). Its popup positioning is not data driven like xdg-positioner. It will be simpler and more readable to compute the desired popup geometry explicitly.
This commit is contained in:
parent
693cd16b12
commit
33e971cc09
4 changed files with 60 additions and 59 deletions
|
@ -126,9 +126,10 @@ void InputPanelV1Window::reposition()
|
|||
|
||||
m_windowGeometry = QRectF(QPointF(0, 0), surface()->size());
|
||||
|
||||
// Reuse the similar logic like xdg popup
|
||||
QRectF popupRect(popupOffset(cursorRectangle, Qt::BottomEdge | Qt::LeftEdge, Qt::RightEdge | Qt::BottomEdge, m_windowGeometry.size()), m_windowGeometry.size());
|
||||
|
||||
QRectF popupRect(cursorRectangle.left(),
|
||||
cursorRectangle.top() + cursorRectangle.height(),
|
||||
m_windowGeometry.width(),
|
||||
m_windowGeometry.height());
|
||||
if (popupRect.left() < screen.left()) {
|
||||
popupRect.moveLeft(screen.left());
|
||||
}
|
||||
|
@ -136,8 +137,10 @@ void InputPanelV1Window::reposition()
|
|||
popupRect.moveRight(screen.right());
|
||||
}
|
||||
if (popupRect.top() < screen.top() || popupRect.bottom() > screen.bottom()) {
|
||||
auto flippedPopupRect =
|
||||
QRectF(popupOffset(cursorRectangle, Qt::TopEdge | Qt::LeftEdge, Qt::RightEdge | Qt::TopEdge, m_windowGeometry.size()), m_windowGeometry.size());
|
||||
const QRectF flippedPopupRect(cursorRectangle.left(),
|
||||
cursorRectangle.top() - m_windowGeometry.height(),
|
||||
m_windowGeometry.width(),
|
||||
m_windowGeometry.height());
|
||||
|
||||
// if it still doesn't fit we should continue with the unflipped version
|
||||
if (flippedPopupRect.top() >= screen.top() && flippedPopupRect.bottom() <= screen.bottom()) {
|
||||
|
|
|
@ -191,58 +191,6 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state)
|
|||
return ret;
|
||||
}
|
||||
|
||||
QPointF popupOffset(const QRectF &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSizeF popupSize)
|
||||
{
|
||||
QPointF anchorPoint;
|
||||
switch (anchorEdge & (Qt::LeftEdge | Qt::RightEdge)) {
|
||||
case Qt::LeftEdge:
|
||||
anchorPoint.setX(anchorRect.x());
|
||||
break;
|
||||
case Qt::RightEdge:
|
||||
anchorPoint.setX(anchorRect.x() + anchorRect.width());
|
||||
break;
|
||||
default:
|
||||
anchorPoint.setX(qRound(anchorRect.x() + anchorRect.width() / 2.0));
|
||||
}
|
||||
switch (anchorEdge & (Qt::TopEdge | Qt::BottomEdge)) {
|
||||
case Qt::TopEdge:
|
||||
anchorPoint.setY(anchorRect.y());
|
||||
break;
|
||||
case Qt::BottomEdge:
|
||||
anchorPoint.setY(anchorRect.y() + anchorRect.height());
|
||||
break;
|
||||
default:
|
||||
anchorPoint.setY(qRound(anchorRect.y() + anchorRect.height() / 2.0));
|
||||
}
|
||||
|
||||
// calculate where the top left point of the popup will end up with the applied gravity
|
||||
// gravity indicates direction. i.e if gravitating towards the top the popup's bottom edge
|
||||
// will next to the anchor point
|
||||
QPointF popupPosAdjust;
|
||||
switch (gravity & (Qt::LeftEdge | Qt::RightEdge)) {
|
||||
case Qt::LeftEdge:
|
||||
popupPosAdjust.setX(-popupSize.width());
|
||||
break;
|
||||
case Qt::RightEdge:
|
||||
popupPosAdjust.setX(0);
|
||||
break;
|
||||
default:
|
||||
popupPosAdjust.setX(qRound(-popupSize.width() / 2.0));
|
||||
}
|
||||
switch (gravity & (Qt::TopEdge | Qt::BottomEdge)) {
|
||||
case Qt::TopEdge:
|
||||
popupPosAdjust.setY(-popupSize.height());
|
||||
break;
|
||||
case Qt::BottomEdge:
|
||||
popupPosAdjust.setY(0);
|
||||
break;
|
||||
default:
|
||||
popupPosAdjust.setY(qRound(-popupSize.height() / 2.0));
|
||||
}
|
||||
|
||||
return anchorPoint + popupPosAdjust;
|
||||
}
|
||||
|
||||
QRectF gravitateGeometry(const QRectF &rect, const QRectF &bounds, Gravity gravity)
|
||||
{
|
||||
QRectF geometry = rect;
|
||||
|
|
|
@ -90,7 +90,6 @@ Qt::MouseButton KWIN_EXPORT x11ToQtMouseButton(int button);
|
|||
Qt::MouseButtons KWIN_EXPORT x11ToQtMouseButtons(int state);
|
||||
Qt::KeyboardModifiers KWIN_EXPORT x11ToQtKeyboardModifiers(int state);
|
||||
|
||||
KWIN_EXPORT QPointF popupOffset(const QRectF &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSizeF popupSize);
|
||||
KWIN_EXPORT QRectF gravitateGeometry(const QRectF &rect, const QRectF &bounds, Gravity gravity);
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "display.h"
|
||||
#include "output.h"
|
||||
#include "seat.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/resource.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
@ -1049,6 +1048,58 @@ bool XdgPositioner::isReactive() const
|
|||
return d->isReactive;
|
||||
}
|
||||
|
||||
static QPointF popupOffset(const QRectF &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSizeF popupSize)
|
||||
{
|
||||
QPointF anchorPoint;
|
||||
switch (anchorEdge & (Qt::LeftEdge | Qt::RightEdge)) {
|
||||
case Qt::LeftEdge:
|
||||
anchorPoint.setX(anchorRect.x());
|
||||
break;
|
||||
case Qt::RightEdge:
|
||||
anchorPoint.setX(anchorRect.x() + anchorRect.width());
|
||||
break;
|
||||
default:
|
||||
anchorPoint.setX(qRound(anchorRect.x() + anchorRect.width() / 2.0));
|
||||
}
|
||||
switch (anchorEdge & (Qt::TopEdge | Qt::BottomEdge)) {
|
||||
case Qt::TopEdge:
|
||||
anchorPoint.setY(anchorRect.y());
|
||||
break;
|
||||
case Qt::BottomEdge:
|
||||
anchorPoint.setY(anchorRect.y() + anchorRect.height());
|
||||
break;
|
||||
default:
|
||||
anchorPoint.setY(qRound(anchorRect.y() + anchorRect.height() / 2.0));
|
||||
}
|
||||
|
||||
// calculate where the top left point of the popup will end up with the applied gravity
|
||||
// gravity indicates direction. i.e if gravitating towards the top the popup's bottom edge
|
||||
// will next to the anchor point
|
||||
QPointF popupPosAdjust;
|
||||
switch (gravity & (Qt::LeftEdge | Qt::RightEdge)) {
|
||||
case Qt::LeftEdge:
|
||||
popupPosAdjust.setX(-popupSize.width());
|
||||
break;
|
||||
case Qt::RightEdge:
|
||||
popupPosAdjust.setX(0);
|
||||
break;
|
||||
default:
|
||||
popupPosAdjust.setX(qRound(-popupSize.width() / 2.0));
|
||||
}
|
||||
switch (gravity & (Qt::TopEdge | Qt::BottomEdge)) {
|
||||
case Qt::TopEdge:
|
||||
popupPosAdjust.setY(-popupSize.height());
|
||||
break;
|
||||
case Qt::BottomEdge:
|
||||
popupPosAdjust.setY(0);
|
||||
break;
|
||||
default:
|
||||
popupPosAdjust.setY(qRound(-popupSize.height() / 2.0));
|
||||
}
|
||||
|
||||
return anchorPoint + popupPosAdjust;
|
||||
}
|
||||
|
||||
QRectF XdgPositioner::placement(const QRectF &bounds) const
|
||||
{
|
||||
// returns if a target is within the supplied bounds, optional edges argument states which side to check
|
||||
|
|
Loading…
Reference in a new issue