Avoid using QMouseEvent in processDecorationButtonPress()

BUG: 480864
This commit is contained in:
Vlad Zahorodnii 2024-05-24 17:49:55 +03:00
parent fa351403ef
commit b0ccacc983
4 changed files with 23 additions and 31 deletions

View file

@ -1045,14 +1045,7 @@ bool X11Window::buttonPressEvent(xcb_window_t w, int button, int state, int x, i
if (w == inputId()) {
x = x_root - frameGeometry().x();
y = y_root - frameGeometry().y();
// New API processes core events FIRST and only passes unused ones to the decoration
QMouseEvent ev(QMouseEvent::MouseButtonPress,
QPoint(x, y),
QPoint(x_root, y_root),
x11ToQtMouseButton(button),
x11ToQtMouseButtons(state) | x11ToQtMouseButton(button),
Qt::KeyboardModifiers());
return processDecorationButtonPress(&ev, true);
return processDecorationButtonPress(QPoint(x, y), QPoint(x_root, y_root), x11ToQtMouseButton(button), true);
}
if (w == frameId() && isDecorated()) {
if (button >= 4 && button <= 7) {
@ -1089,7 +1082,7 @@ bool X11Window::buttonPressEvent(xcb_window_t w, int button, int state, int x, i
event.setAccepted(false);
QCoreApplication::sendEvent(decoration(), &event);
if (!event.isAccepted()) {
processDecorationButtonPress(&event);
processDecorationButtonPress(QPointF(x, y), QPointF(x_root, y_root), x11ToQtMouseButton(button));
}
}
return true;
@ -1114,9 +1107,6 @@ bool X11Window::buttonReleaseEvent(xcb_window_t w, int button, int state, int x,
x11ToQtKeyboardModifiers(state));
event.setAccepted(false);
QCoreApplication::sendEvent(decoration(), &event);
if (event.isAccepted() || !titlebarPositionUnderMouse()) {
invalidateDecorationDoubleClickTimer(); // click was for the deco and shall not init a doubleclick
}
}
}
if (w == wrapperId()) {

View file

@ -1392,6 +1392,7 @@ public:
if (!decoration) {
return false;
}
const QPointF globalPos = event->screenPos();
const QPointF p = event->screenPos() - decoration->window()->pos();
switch (event->type()) {
case QEvent::MouseMove: {
@ -1411,10 +1412,10 @@ public:
e.setAccepted(false);
QCoreApplication::sendEvent(decoration->decoration(), &e);
if (!e.isAccepted() && event->type() == QEvent::MouseButtonPress) {
decoration->window()->processDecorationButtonPress(&e);
decoration->window()->processDecorationButtonPress(p, globalPos, event->button());
}
if (event->type() == QEvent::MouseButtonRelease) {
decoration->window()->processDecorationButtonRelease(&e);
decoration->window()->processDecorationButtonRelease(event->button());
}
return true;
}
@ -1484,7 +1485,7 @@ public:
e.setAccepted(false);
QCoreApplication::sendEvent(decoration->decoration(), &e);
if (!e.isAccepted()) {
decoration->window()->processDecorationButtonPress(&e);
decoration->window()->processDecorationButtonPress(m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton);
}
return true;
}
@ -1534,7 +1535,7 @@ public:
QMouseEvent e(QEvent::MouseButtonRelease, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::MouseButtons(), input()->keyboardModifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(decoration->decoration(), &e);
decoration->window()->processDecorationButtonRelease(&e);
decoration->window()->processDecorationButtonRelease(Qt::LeftButton);
QHoverEvent leaveEvent(QEvent::HoverLeave, QPointF(), QPointF());
QCoreApplication::sendEvent(decoration->decoration(), &leaveEvent);
@ -1550,6 +1551,7 @@ public:
if (!decoration) {
return false;
}
const QPointF globalPos = event->globalPosF();
const QPointF p = event->globalPosF() - decoration->window()->pos();
switch (event->type()) {
case QEvent::TabletMove:
@ -1571,10 +1573,10 @@ public:
e.setAccepted(false);
QCoreApplication::sendEvent(decoration->decoration(), &e);
if (!e.isAccepted() && isPressed) {
decoration->window()->processDecorationButtonPress(&e);
decoration->window()->processDecorationButtonPress(p, globalPos, Qt::LeftButton);
}
if (event->type() == QEvent::TabletRelease) {
decoration->window()->processDecorationButtonRelease(&e);
decoration->window()->processDecorationButtonRelease(Qt::LeftButton);
}
break;
}

View file

@ -2715,7 +2715,7 @@ void Window::processDecorationMove(const QPointF &localPos, const QPointF &globa
}
}
bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
bool Window::processDecorationButtonPress(const QPointF &localPos, const QPointF &globalPos, Qt::MouseButton button, bool ignoreMenu)
{
Options::MouseCommand com = Options::MouseNothing;
bool active = isActive();
@ -2724,7 +2724,7 @@ bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
}
// check whether it is a double click
if (event->button() == Qt::LeftButton) {
if (button == Qt::LeftButton) {
if (m_decoration.doubleClickTimer.isValid()) {
const qint64 interval = m_decoration.doubleClickTimer.elapsed();
m_decoration.doubleClickTimer.invalidate();
@ -2763,21 +2763,21 @@ bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
}
}
if (event->button() == Qt::LeftButton) {
if (button == Qt::LeftButton) {
com = active ? options->commandActiveTitlebar1() : options->commandInactiveTitlebar1();
} else if (event->button() == Qt::MiddleButton) {
} else if (button == Qt::MiddleButton) {
com = active ? options->commandActiveTitlebar2() : options->commandInactiveTitlebar2();
} else if (event->button() == Qt::RightButton) {
} else if (button == Qt::RightButton) {
com = active ? options->commandActiveTitlebar3() : options->commandInactiveTitlebar3();
}
if (event->button() == Qt::LeftButton
if (button == Qt::LeftButton
&& com != Options::MouseOperationsMenu // actions where it's not possible to get the matching
&& com != Options::MouseMinimize) // mouse release event
{
setInteractiveMoveResizeGravity(mouseGravity());
setInteractiveMoveResizePointerButtonDown(true);
setInteractiveMoveResizeAnchor(event->globalPosition());
setInteractiveMoveOffset(QPointF(qreal(event->pos().x()) / width(), qreal(event->pos().y()) / height()));
setInteractiveMoveResizeAnchor(globalPos);
setInteractiveMoveOffset(QPointF(qreal(localPos.x()) / width(), qreal(localPos.y()) / height()));
setUnrestrictedInteractiveMoveResize(false);
startDelayedInteractiveMoveResize();
updateCursor();
@ -2785,15 +2785,15 @@ bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
// In the new API the decoration may process the menu action to display an inactive tab's menu.
// If the event is unhandled then the core will create one for the active window in the group.
if (!ignoreMenu || com != Options::MouseOperationsMenu) {
performMouseCommand(com, event->globalPos());
performMouseCommand(com, globalPos);
}
return !( // Return events that should be passed to the decoration in the new API
com == Options::MouseRaise || com == Options::MouseOperationsMenu || com == Options::MouseActivateAndRaise || com == Options::MouseActivate || com == Options::MouseActivateRaiseAndPassClick || com == Options::MouseActivateAndPassClick || com == Options::MouseNothing);
}
void Window::processDecorationButtonRelease(QMouseEvent *event)
void Window::processDecorationButtonRelease(Qt::MouseButton button)
{
if (event->buttons() == Qt::NoButton) {
if (button == Qt::LeftButton) {
setInteractiveMoveResizePointerButtonDown(false);
stopDelayedInteractiveMoveResize();
if (isInteractiveMoveResize()) {

View file

@ -1174,8 +1174,8 @@ public:
void triggerDecorationRepaint();
void layoutDecorationRects(QRectF &left, QRectF &top, QRectF &right, QRectF &bottom) const;
void processDecorationMove(const QPointF &localPos, const QPointF &globalPos);
bool processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu = false);
void processDecorationButtonRelease(QMouseEvent *event);
bool processDecorationButtonPress(const QPointF &localPos, const QPointF &globalPos, Qt::MouseButton button, bool ignoreMenu = false);
void processDecorationButtonRelease(Qt::MouseButton button);
virtual void invalidateDecoration();