From d6cbf9efb7c42b10de5fe293589176019faf0373 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= <spaz16@wp.pl>
Date: Thu, 5 May 2016 14:03:56 +0200
Subject: [PATCH] xcb: Properly unset mousePressWindow()

In some cases the mouse release event won't arrive, i.e. when window is
minimized on button press. Check for mouse buttons state on mouse move
event and properly unset the mousePressWindow to avoid blocking
enter/leave events in this case.

Amends: c511466d747d99ee76465cfe90ce594fa1f27469

Change-Id: I543a75104f528df1bf644bace13f78a6af017455
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
---
 src/plugins/platforms/xcb/qxcbwindow.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index 226507f7a01..429ba8df717 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -2351,9 +2351,14 @@ void QXcbWindow::handleMotionNotifyEvent(int event_x, int event_y, int root_x, i
     QPoint local(event_x, event_y);
     QPoint global(root_x, root_y);
 
-    // "mousePressWindow" can be NULL i.e. if a window will be grabbed or umnapped, so set it again here
-    if (connection()->buttons() != Qt::NoButton && connection()->mousePressWindow() == Q_NULLPTR)
+    // "mousePressWindow" can be NULL i.e. if a window will be grabbed or unmapped, so set it again here.
+    // Unset "mousePressWindow" when mouse button isn't pressed - in some cases the release event won't arrive.
+    const bool isMouseButtonPressed = (connection()->buttons() != Qt::NoButton);
+    const bool hasMousePressWindow = (connection()->mousePressWindow() != Q_NULLPTR);
+    if (isMouseButtonPressed && !hasMousePressWindow)
         connection()->setMousePressWindow(this);
+    else if (hasMousePressWindow && !isMouseButtonPressed)
+        connection()->setMousePressWindow(Q_NULLPTR);
 
     handleMouseEvent(timestamp, local, global, modifiers, source);
 }
-- 
GitLab