Windows: Implement automatic mouse capture in QPA.
Qt expects the mouse to be captured on any button press
until release.
Remove flags to store capture, use WinAPI GetCapture() instead.
Remove setMouseGrabEnabled_sys(), streamline code.
Replacement for the reverted change
6b5bbc531b
for QTBUG-25977.
Task-number: QTBUG-27132
Task-number: QTBUG-27039
Task-number: QTBUG-25977
Task-number: QTBUG-26962
Change-Id: If86428eabfadcafd16da10f134a419f833185272
Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
parent
b625ff4c7b
commit
1ea00124f7
@ -175,9 +175,26 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
compressMouseMove(&msg);
|
compressMouseMove(&msg);
|
||||||
|
QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
|
||||||
|
// Qt expects the platform plugin to capture the mouse on
|
||||||
|
// any button press until release.
|
||||||
|
if (!platformWindow->hasMouseCapture()
|
||||||
|
&& (msg.message == WM_LBUTTONDOWN || msg.message == WM_MBUTTONDOWN
|
||||||
|
|| msg.message == WM_RBUTTONDOWN)) {
|
||||||
|
platformWindow->setMouseGrabEnabled(true);
|
||||||
|
platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
|
||||||
|
if (QWindowsContext::verboseEvents)
|
||||||
|
qDebug() << "Automatic mouse capture " << window;
|
||||||
|
} else if (platformWindow->hasMouseCapture()
|
||||||
|
&& platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)
|
||||||
|
&& (msg.message == WM_LBUTTONUP || msg.message == WM_MBUTTONUP
|
||||||
|
|| msg.message == WM_RBUTTONUP)) {
|
||||||
|
platformWindow->setMouseGrabEnabled(false);
|
||||||
|
if (QWindowsContext::verboseEvents)
|
||||||
|
qDebug() << "Releasing automatic mouse capture " << window;
|
||||||
|
}
|
||||||
// Eat mouse move after size grip drag.
|
// Eat mouse move after size grip drag.
|
||||||
if (msg.message == WM_MOUSEMOVE) {
|
if (msg.message == WM_MOUSEMOVE) {
|
||||||
QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
|
|
||||||
if (platformWindow->testFlag(QWindowsWindow::SizeGripOperation)) {
|
if (platformWindow->testFlag(QWindowsWindow::SizeGripOperation)) {
|
||||||
MSG mouseMsg;
|
MSG mouseMsg;
|
||||||
while (PeekMessage(&mouseMsg, platformWindow->handle(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) ;
|
while (PeekMessage(&mouseMsg, platformWindow->handle(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) ;
|
||||||
|
@ -696,7 +696,6 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) :
|
|||||||
m_hdc(0),
|
m_hdc(0),
|
||||||
m_windowState(Qt::WindowNoState),
|
m_windowState(Qt::WindowNoState),
|
||||||
m_opacity(1.0),
|
m_opacity(1.0),
|
||||||
m_mouseGrab(false),
|
|
||||||
m_cursor(QWindowsScreen::screenOf(aWindow)->windowsCursor()->standardWindowCursor()),
|
m_cursor(QWindowsScreen::screenOf(aWindow)->windowsCursor()->standardWindowCursor()),
|
||||||
m_dropTarget(0),
|
m_dropTarget(0),
|
||||||
m_savedStyle(0),
|
m_savedStyle(0),
|
||||||
@ -738,6 +737,8 @@ void QWindowsWindow::destroyWindow()
|
|||||||
if (QWindowsContext::verboseIntegration || QWindowsContext::verboseWindows)
|
if (QWindowsContext::verboseIntegration || QWindowsContext::verboseWindows)
|
||||||
qDebug() << __FUNCTION__ << this << window() << m_data.hwnd;
|
qDebug() << __FUNCTION__ << this << window() << m_data.hwnd;
|
||||||
if (m_data.hwnd) { // Stop event dispatching before Window is destroyed.
|
if (m_data.hwnd) { // Stop event dispatching before Window is destroyed.
|
||||||
|
if (hasMouseCapture())
|
||||||
|
setMouseGrabEnabled(false);
|
||||||
unregisterDropSite();
|
unregisterDropSite();
|
||||||
QWindowsContext::instance()->removeWindow(m_data.hwnd);
|
QWindowsContext::instance()->removeWindow(m_data.hwnd);
|
||||||
#ifdef QT_OPENGL_ES_2
|
#ifdef QT_OPENGL_ES_2
|
||||||
@ -811,6 +812,8 @@ void QWindowsWindow::setVisible(bool visible)
|
|||||||
QWindowSystemInterface::handleExposeEvent(window(),
|
QWindowSystemInterface::handleExposeEvent(window(),
|
||||||
QRect(QPoint(), geometry().size()));
|
QRect(QPoint(), geometry().size()));
|
||||||
} else {
|
} else {
|
||||||
|
if (hasMouseCapture())
|
||||||
|
setMouseGrabEnabled(false);
|
||||||
hide_sys();
|
hide_sys();
|
||||||
QWindowSystemInterface::handleExposeEvent(window(), QRegion());
|
QWindowSystemInterface::handleExposeEvent(window(), QRegion());
|
||||||
}
|
}
|
||||||
@ -1495,29 +1498,27 @@ bool QWindowsWindow::setKeyboardGrabEnabled(bool grab)
|
|||||||
|
|
||||||
bool QWindowsWindow::setMouseGrabEnabled(bool grab)
|
bool QWindowsWindow::setMouseGrabEnabled(bool grab)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
if (!m_data.hwnd) {
|
|
||||||
qWarning("%s: No handle", __FUNCTION__);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (QWindowsContext::verboseWindows)
|
if (QWindowsContext::verboseWindows)
|
||||||
qDebug() << __FUNCTION__ << window() << grab;
|
qDebug() << __FUNCTION__ << window() << grab;
|
||||||
|
if (!m_data.hwnd) {
|
||||||
if (m_mouseGrab != grab) {
|
qWarning("%s: No handle", __FUNCTION__);
|
||||||
m_mouseGrab = grab;
|
return false;
|
||||||
if (isVisible())
|
|
||||||
setMouseGrabEnabled_sys(grab);
|
|
||||||
}
|
}
|
||||||
return grab;
|
if (!isVisible() && grab) {
|
||||||
}
|
qWarning("%s: Not setting mouse grab for invisible window %s",
|
||||||
|
__FUNCTION__, qPrintable(window()->objectName()));
|
||||||
void QWindowsWindow::setMouseGrabEnabled_sys(bool grab)
|
return false;
|
||||||
{
|
}
|
||||||
|
// release grab or an explicit grab overriding autocapture: Clear flag.
|
||||||
|
clearFlag(QWindowsWindow::AutoMouseCapture);
|
||||||
|
if (hasMouseCapture() != grab) {
|
||||||
if (grab) {
|
if (grab) {
|
||||||
SetCapture(m_data.hwnd);
|
SetCapture(m_data.hwnd);
|
||||||
} else {
|
} else {
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return grab;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline DWORD cornerToWinOrientation(Qt::Corner corner)
|
static inline DWORD cornerToWinOrientation(Qt::Corner corner)
|
||||||
|
@ -126,7 +126,8 @@ public:
|
|||||||
SizeGripOperation = 0x100,
|
SizeGripOperation = 0x100,
|
||||||
FrameStrutEventsEnabled = 0x200,
|
FrameStrutEventsEnabled = 0x200,
|
||||||
SynchronousGeometryChangeEvent = 0x400,
|
SynchronousGeometryChangeEvent = 0x400,
|
||||||
WithinSetStyle = 0x800
|
WithinSetStyle = 0x800,
|
||||||
|
AutoMouseCapture = 0x1000 //! Automatic mouse capture on button press.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WindowData
|
struct WindowData
|
||||||
@ -179,6 +180,7 @@ public:
|
|||||||
|
|
||||||
virtual bool setKeyboardGrabEnabled(bool grab);
|
virtual bool setKeyboardGrabEnabled(bool grab);
|
||||||
virtual bool setMouseGrabEnabled(bool grab);
|
virtual bool setMouseGrabEnabled(bool grab);
|
||||||
|
inline bool hasMouseCapture() const { return GetCapture() == m_data.hwnd; }
|
||||||
|
|
||||||
virtual bool startSystemResize(const QPoint &pos, Qt::Corner corner);
|
virtual bool startSystemResize(const QPoint &pos, Qt::Corner corner);
|
||||||
|
|
||||||
@ -249,7 +251,6 @@ private:
|
|||||||
inline bool isFullScreen_sys() const;
|
inline bool isFullScreen_sys() const;
|
||||||
inline void setWindowState_sys(Qt::WindowState newState);
|
inline void setWindowState_sys(Qt::WindowState newState);
|
||||||
inline void setParent_sys(const QPlatformWindow *parent) const;
|
inline void setParent_sys(const QPlatformWindow *parent) const;
|
||||||
inline void setMouseGrabEnabled_sys(bool grab);
|
|
||||||
void destroyWindow();
|
void destroyWindow();
|
||||||
void registerDropSite();
|
void registerDropSite();
|
||||||
void unregisterDropSite();
|
void unregisterDropSite();
|
||||||
@ -261,7 +262,6 @@ private:
|
|||||||
HDC m_hdc;
|
HDC m_hdc;
|
||||||
Qt::WindowState m_windowState;
|
Qt::WindowState m_windowState;
|
||||||
qreal m_opacity;
|
qreal m_opacity;
|
||||||
bool m_mouseGrab;
|
|
||||||
QWindowsWindowCursor m_cursor;
|
QWindowsWindowCursor m_cursor;
|
||||||
QWindowsOleDropTarget *m_dropTarget;
|
QWindowsOleDropTarget *m_dropTarget;
|
||||||
unsigned m_savedStyle;
|
unsigned m_savedStyle;
|
||||||
|
Loading…
Reference in New Issue
Block a user