Fix context menu event handling

Konsole was using mousePressEvent with button == Qt::RightButton for
emulating a context menu event, which is wrong because there is a
dedicated event for context menu.

Due to this there were weird issues on wayland for e.g., you open the
context menu and then click somewhere else -> you get another context menu
if the target widget supports one. This happened because after
mousePressEvent, there is a mouseReleaseEvent, which konsole doesn't
handle always which then gets synthesized into a context menu event
and delivered to the widget where the click happened.

This is also a bug in Qt wayland I think and should be fixed there but
there is no reason for Konsole not to handle this properly.

To fix, move the logic for context menu event to contextMenuEvent.

BUG: 512130
This commit is contained in:
Waqar Ahmed
2025-12-18 12:47:41 +05:00
committed by Christoph Cullmann
parent 16f1288b49
commit 48ba7ea4c1

View File

@@ -1236,15 +1236,11 @@ void TerminalDisplay::mousePressEvent(QMouseEvent *ev)
} else if (ev->button() == Qt::MiddleButton) {
processMidButtonClick(ev);
} else if (ev->button() == Qt::RightButton) {
if (!usesMouseTracking() || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) {
Q_EMIT configureRequest(ev->pos());
} else {
if (!_readOnly) {
if (usesMouseTracking() && !_readOnly && !ev->modifiers().testFlag(Qt::ShiftModifier)) {
Q_EMIT mouseSignal(mouseButton(2, ev->modifiers()), charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 0);
}
}
}
}
QSharedPointer<HotSpot> TerminalDisplay::filterActions(const QPoint &position)
{
@@ -2929,8 +2925,9 @@ bool TerminalDisplay::event(QEvent *event)
void TerminalDisplay::contextMenuEvent(QContextMenuEvent *event)
{
// the logic for the mouse case is within MousePressEvent()
if (event->reason() != QContextMenuEvent::Mouse) {
if (!usesMouseTracking() || event->modifiers().testFlag(Qt::ShiftModifier)) {
Q_EMIT configureRequest(event->pos());
} else if (event->reason() != QContextMenuEvent::Mouse) {
Q_EMIT configureRequest(mapFromGlobal(QCursor::pos()));
}
}