summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Edmundson <[email protected]>2017-04-25 11:34:11 +0100
committerDavid Edmundson <[email protected]>2017-04-25 12:07:41 +0100
commitfdd3e3fc7ad2b8ed8f79f204fc8f33c2a22ee357 (patch)
treed8430f6aeaceb46d5fe7abff7b1a5566aab94f3f
parent0e797b0396ebcb40c64d61fbb4711ab060c8cb91 (diff)
Update ungrab mouse hack for Qt 5.8
-rw-r--r--applets/notifications/plugin/thumbnailer.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/applets/notifications/plugin/thumbnailer.cpp b/applets/notifications/plugin/thumbnailer.cpp
index dc079b8..ac2742f 100644
--- a/applets/notifications/plugin/thumbnailer.cpp
+++ b/applets/notifications/plugin/thumbnailer.cpp
@@ -28,6 +28,8 @@
#include <QMenu>
#include <QQuickItem>
#include <QQuickWindow>
+#include <QTimer>
+#include <QVersionNumber>
#include <KFileItemActions>
#include <KFileItemListProperties>
@@ -155,9 +157,29 @@ void Thumbnailer::showContextMenu(int x, int y, const QString &path, QQuickItem
dialog->show();
});
- if (ctx->window()->mouseGrabberItem()) {
- ctx->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 = [ctx]() {
+ if (ctx->window()->mouseGrabberItem()) {
+ ctx->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, ctx, ungrabMouseHack);
}
+ else {
+ ungrabMouseHack();
+ }
+ //end workaround
+
const QPoint pos = ctx->mapToGlobal(QPointF(x, y)).toPoint();
menu->popup(pos);