diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -828,6 +829,29 @@ emit applet()->contextualActionsAboutToShow(); ci->addAppletActions(desktopMenu, applet(), event); + // this is a workaround where Qt will fail to realise a mouse has been released + // this happens if a window which does not accept focus spawns a new window that takes focus and X grab + // whilst the mouse is depressed + // https://bugreports.qt.io/browse/QTBUG-59044 + // this causes the next click to go missing + + // by releasing manually we avoid that situation + auto ungrabMouseHack = [this]() { + if (window() && window()->mouseGrabberItem()) { + // FIXME event forge thing enters press and hold move mode :/ + window()->mouseGrabberItem()->ungrabMouse(); + } + }; + + // pre 5.8.0 QQuickWindow code is "item->grabMouse(); sendEvent(item, mouseEvent)" + // post 5.8.0 QQuickWindow code is sendEvent(item, mouseEvent); item->grabMouse() + if (QVersionNumber::fromString(qVersion()) > QVersionNumber(5, 8, 0)) { + QTimer::singleShot(0, this, ungrabMouseHack); + } else { + ungrabMouseHack(); + } + // end workaround + if (!desktopMenu->isEmpty()) { desktopMenu->setAttribute(Qt::WA_DeleteOnClose); desktopMenu->popup(e->globalPos()); diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -995,9 +997,28 @@ desktopMenu->setAttribute(Qt::WA_TranslucentBackground); //end workaround - if (window() && window()->mouseGrabberItem()) { - window()->mouseGrabberItem()->ungrabMouse(); + // this is a workaround where Qt will fail to realise a mouse has been released + // this happens if a window which does not accept focus spawns a new window that takes focus and X grab + // whilst the mouse is depressed + // https://bugreports.qt.io/browse/QTBUG-59044 + // this causes the next click to go missing + + // by releasing manually we avoid that situation + auto ungrabMouseHack = [this]() { + if (window() && window()->mouseGrabberItem()) { + // FIXME event forge thing enters press and hold move mode :/ + window()->mouseGrabberItem()->ungrabMouse(); + } + }; + + // pre 5.8.0 QQuickWindow code is "item->grabMouse(); sendEvent(item, mouseEvent)" + // post 5.8.0 QQuickWindow code is sendEvent(item, mouseEvent); item->grabMouse() + if (QVersionNumber::fromString(qVersion()) > QVersionNumber(5, 8, 0)) { + QTimer::singleShot(0, this, ungrabMouseHack); + } else { + ungrabMouseHack(); } + // end workaround QPoint pos = event->globalPos(); if (window() && m_containment->containmentType() == Plasma::Types::PanelContainment) {