From b9f76db30d261421e4da58f29053181af04ceb4d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= <spaz16@wp.pl>
Date: Sat, 17 Oct 2015 17:22:16 +0200
Subject: [PATCH] xcb: Correct enter/leave event handling when mouse button is
 pressed

This patch fixes cursor shape when mouse leaves the window and enters
the window again with pressed mouse button - ignore the mouse enter
and leave event when any of mouse buttons is pressed.

Task-number: QTBUG-46576
Change-Id: Id6ce50cd0d66da51a251d4811bc42cd31606de29
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
---
 src/plugins/platforms/xcb/qxcbwindow.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index 91c5eadf345..354c29152fa 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -2198,11 +2198,14 @@ void QXcbWindow::handleEnterNotifyEvent(int event_x, int event_y, int root_x, in
     connection()->handleEnterEvent();
 #endif
 
-    if (ignoreEnterEvent(mode, detail))
+    const QPoint global = QPoint(root_x, root_y);
+
+    if (ignoreEnterEvent(mode, detail)
+            || (connection()->buttons() != Qt::NoButton
+                && QGuiApplicationPrivate::lastCursorPosition != global))
         return;
 
     const QPoint local(event_x, event_y);
-    QPoint global = QPoint(root_x, root_y);
     QWindowSystemInterface::handleEnterEvent(window(), local, global);
 }
 
@@ -2211,7 +2214,11 @@ void QXcbWindow::handleLeaveNotifyEvent(int root_x, int root_y,
 {
     connection()->setTime(timestamp);
 
-    if (ignoreLeaveEvent(mode, detail))
+    const QPoint global(root_x, root_y);
+
+    if (ignoreLeaveEvent(mode, detail)
+            || (connection()->buttons() != Qt::NoButton
+                && QGuiApplicationPrivate::lastCursorPosition != global))
         return;
 
     EnterEventChecker checker;
-- 
GitLab