Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsmousehandler.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qwindowskeymapper.h"
6#include "qwindowscontext.h"
7#include "qwindowswindow.h"
9#include "qwindowsscreen.h"
10
11#include <qpa/qwindowsysteminterface.h>
12#include <QtGui/qguiapplication.h>
13#include <QtGui/qscreen.h>
14#include <QtGui/qpointingdevice.h>
15#include <QtGui/qwindow.h>
16#include <QtGui/qcursor.h>
17
18#include <QtCore/qdebug.h>
19
20#include <memory>
21
22#include <windowsx.h>
23
25
26static inline void compressMouseMove(MSG *msg)
27{
28 // Compress mouse move events
29 if (msg->message == WM_MOUSEMOVE) {
30 MSG mouseMsg;
31 while (PeekMessage(&mouseMsg, msg->hwnd, WM_MOUSEFIRST,
32 WM_MOUSELAST, PM_NOREMOVE)) {
33 if (mouseMsg.message == WM_MOUSEMOVE) {
34#define PEEKMESSAGE_IS_BROKEN 1
35#ifdef PEEKMESSAGE_IS_BROKEN
36 // Since the Windows PeekMessage() function doesn't
37 // correctly return the wParam for WM_MOUSEMOVE events
38 // if there is a key release event in the queue
39 // _before_ the mouse event, we have to also consider
40 // key release events (kls 2003-05-13):
41 MSG keyMsg;
42 bool done = false;
43 while (PeekMessage(&keyMsg, nullptr, WM_KEYFIRST, WM_KEYLAST,
44 PM_NOREMOVE)) {
45 if (keyMsg.time < mouseMsg.time) {
46 if ((keyMsg.lParam & 0xC0000000) == 0x40000000) {
47 PeekMessage(&keyMsg, nullptr, keyMsg.message,
48 keyMsg.message, PM_REMOVE);
49 } else {
50 done = true;
51 break;
52 }
53 } else {
54 break; // no key event before the WM_MOUSEMOVE event
55 }
56 }
57 if (done)
58 break;
59#else
60 // Actually the following 'if' should work instead of
61 // the above key event checking, but apparently
62 // PeekMessage() is broken :-(
63 if (mouseMsg.wParam != msg.wParam)
64 break; // leave the message in the queue because
65 // the key state has changed
66#endif
67 // Update the passed in MSG structure with the
68 // most recent one.
69 msg->lParam = mouseMsg.lParam;
70 msg->wParam = mouseMsg.wParam;
71 // Extract the x,y coordinates from the lParam as we do in the WndProc
72 msg->pt.x = GET_X_LPARAM(mouseMsg.lParam);
73 msg->pt.y = GET_Y_LPARAM(mouseMsg.lParam);
74 clientToScreen(msg->hwnd, &(msg->pt));
75 // Remove the mouse move message
76 PeekMessage(&mouseMsg, msg->hwnd, WM_MOUSEMOVE,
77 WM_MOUSEMOVE, PM_REMOVE);
78 } else {
79 break; // there was no more WM_MOUSEMOVE event
80 }
81 }
82 }
83}
84
95
97{
98 static QPointer<const QPointingDevice> result;
99 if (!result)
101 return result;
102}
103
105{
106 m_lastEventType = QEvent::None;
107 m_lastEventButton = Qt::NoButton;
108}
109
111{
112 Qt::MouseButtons result;
113 const bool mouseSwapped = GetSystemMetrics(SM_SWAPBUTTON);
114 if (GetAsyncKeyState(VK_LBUTTON) < 0)
115 result |= mouseSwapped ? Qt::RightButton: Qt::LeftButton;
116 if (GetAsyncKeyState(VK_RBUTTON) < 0)
117 result |= mouseSwapped ? Qt::LeftButton : Qt::RightButton;
118 if (GetAsyncKeyState(VK_MBUTTON) < 0)
120 if (GetAsyncKeyState(VK_XBUTTON1) < 0)
122 if (GetAsyncKeyState(VK_XBUTTON2) < 0)
124 return result;
125}
126
127Q_CONSTINIT static QPoint lastMouseMovePos;
128
129namespace {
130struct MouseEvent {
133};
134
135#ifndef QT_NO_DEBUG_STREAM
137{
138 QDebugStateSaver saver(d);
139 d.nospace();
140 d << "MouseEvent(" << e.type << ", " << e.button << ')';
141 return d;
142}
143#endif // QT_NO_DEBUG_STREAM
144} // namespace
145
146static inline Qt::MouseButton extraButton(WPARAM wParam) // for WM_XBUTTON...
147{
148 return GET_XBUTTON_WPARAM(wParam) == XBUTTON1 ? Qt::BackButton : Qt::ForwardButton;
149}
150
151static inline MouseEvent eventFromMsg(const MSG &msg)
152{
153 switch (msg.message) {
154 case WM_MOUSEMOVE:
156 case WM_LBUTTONDOWN:
158 case WM_LBUTTONUP:
160 case WM_LBUTTONDBLCLK: // Qt QPA does not handle double clicks, send as press
162 case WM_MBUTTONDOWN:
164 case WM_MBUTTONUP:
166 case WM_MBUTTONDBLCLK:
168 case WM_RBUTTONDOWN:
170 case WM_RBUTTONUP:
172 case WM_RBUTTONDBLCLK:
174 case WM_XBUTTONDOWN:
175 return {QEvent::MouseButtonPress, extraButton(msg.wParam)};
176 case WM_XBUTTONUP:
177 return {QEvent::MouseButtonRelease, extraButton(msg.wParam)};
178 case WM_XBUTTONDBLCLK:
179 return {QEvent::MouseButtonPress, extraButton(msg.wParam)};
180 case WM_NCMOUSEMOVE:
182 case WM_NCLBUTTONDOWN:
184 case WM_NCLBUTTONUP:
186 case WM_NCLBUTTONDBLCLK:
188 case WM_NCMBUTTONDOWN:
190 case WM_NCMBUTTONUP:
192 case WM_NCMBUTTONDBLCLK:
194 case WM_NCRBUTTONDOWN:
196 case WM_NCRBUTTONUP:
198 case WM_NCRBUTTONDBLCLK:
200 default: // WM_MOUSELEAVE
201 break;
202 }
203 return {QEvent::None, Qt::NoButton};
204}
205
208 MSG msg, LRESULT *result)
209{
210 enum : quint64 { signatureMask = 0xffffff00, miWpSignature = 0xff515700 };
211
213 return translateMouseWheelEvent(window, hwnd, msg, result);
214
215 QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
217 RECT clientArea;
218 GetClientRect(hwnd, &clientArea);
219 winEventPosition.setX(clientArea.right - winEventPosition.x());
220 }
221
222 QPoint clientPosition;
223 QPoint globalPosition;
225 globalPosition = winEventPosition;
226 clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
227 } else {
228 globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
229 auto targetHwnd = hwnd;
230 if (auto *pw = window->handle())
231 targetHwnd = HWND(pw->winId());
232 clientPosition = targetHwnd == hwnd
233 ? winEventPosition
234 : QWindowsGeometryHint::mapFromGlobal(targetHwnd, globalPosition);
235 }
236
237 // Windows sends a mouse move with no buttons pressed to signal "Enter"
238 // when a window is shown over the cursor. Discard the event and only use
239 // it for generating QEvent::Enter to be consistent with other platforms -
240 // X11 and macOS.
241 bool discardEvent = false;
242 if (msg.message == WM_MOUSEMOVE) {
243 const bool samePosition = globalPosition == lastMouseMovePos;
244 lastMouseMovePos = globalPosition;
245 if (msg.wParam == 0 && (m_windowUnderMouse.isNull() || samePosition))
246 discardEvent = true;
247 }
248
250
252
253 // Check for events synthesized from touch. Lower byte is touch index, 0 means pen.
254 static const bool passSynthesizedMouseEvents =
256 // Check for events synthesized from touch. Lower 7 bits are touch/pen index, bit 8 indicates touch.
257 // However, when tablet support is active, extraInfo is a packet serial number. This is not a problem
258 // since we do not want to ignore mouse events coming from a tablet.
259 // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320.aspx
260 const auto extraInfo = quint64(GetMessageExtraInfo());
261 if ((extraInfo & signatureMask) == miWpSignature) {
262 if (extraInfo & 0x80) { // Bit 7 indicates touch event, else tablet pen.
264 if (!m_touchDevice.isNull())
265 device = m_touchDevice.data();
266 if (!passSynthesizedMouseEvents)
267 return false;
268 }
269 }
270
271 const auto *keyMapper = QWindowsContext::instance()->keyMapper();
272 const Qt::KeyboardModifiers keyModifiers = keyMapper->queryKeyboardModifiers();
273 const MouseEvent mouseEvent = eventFromMsg(msg);
274 Qt::MouseButtons buttons;
275
277 buttons = queryMouseButtons();
278 else
279 buttons = keyStateToMouseButtons(msg.wParam);
280
281 // When the left/right mouse buttons are pressed over the window title bar
282 // WM_NCLBUTTONDOWN/WM_NCRBUTTONDOWN messages are received. But no UP
283 // messages are received on release, only WM_NCMOUSEMOVE/WM_MOUSEMOVE.
284 // We detect it and generate the missing release events here. (QTBUG-75678)
285 // The last event vars are cleared on QWindowsContext::handleExitSizeMove()
286 // to avoid generating duplicated release events.
287 if (m_lastEventType == QEvent::NonClientAreaMouseButtonPress
288 && (mouseEvent.type == QEvent::NonClientAreaMouseMove || mouseEvent.type == QEvent::MouseMove)
289 && (m_lastEventButton & buttons) == 0) {
290 auto releaseType = mouseEvent.type == QEvent::NonClientAreaMouseMove ?
292 QWindowSystemInterface::handleMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons, m_lastEventButton,
293 releaseType, keyModifiers, source);
294 }
295 m_lastEventType = mouseEvent.type;
296 m_lastEventButton = mouseEvent.button;
297
299 QWindowSystemInterface::handleMouseEvent(window, msg.time, device, clientPosition,
300 globalPosition, buttons,
301 mouseEvent.button, mouseEvent.type,
302 keyModifiers, source);
303 return false; // Allow further event processing (dragging of windows).
304 }
305
306 *result = 0;
307 if (msg.message == WM_MOUSELEAVE) {
308 qCDebug(lcQpaEvents) << mouseEvent << "for" << window << "previous window under mouse="
309 << m_windowUnderMouse << "tracked window=" << m_trackedWindow;
310
311 // When moving out of a window, WM_MOUSEMOVE within the moved-to window is received first,
312 // so if m_trackedWindow is not the window here, it means the cursor has left the
313 // application.
314 if (window == m_trackedWindow) {
315 QWindow *leaveTarget = m_windowUnderMouse ? m_windowUnderMouse : m_trackedWindow;
316 qCDebug(lcQpaEvents) << "Generating leave event for " << leaveTarget;
318 m_trackedWindow = nullptr;
319 m_windowUnderMouse = nullptr;
320 }
321 return true;
322 }
323
324 auto *platformWindow = static_cast<QWindowsWindow *>(window->handle());
325
326 // If the window was recently resized via mouse double-click on the frame or title bar,
327 // we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click,
328 // but we will get at least one WM_MOUSEMOVE with left button down and the WM_LBUTTONUP,
329 // which will result undesired mouse press and release events.
330 // To avoid those, we ignore any events with left button down if we didn't
331 // get the original WM_LBUTTONDOWN/WM_LBUTTONDBLCLK.
332 if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) {
333 m_leftButtonDown = true;
334 } else {
335 const bool actualLeftDown = buttons & Qt::LeftButton;
336 if (!m_leftButtonDown && actualLeftDown) {
337 // Autocapture the mouse for current window to and ignore further events until release.
338 // Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters.
339 // This autocapture is released normally when button is released.
340 if (!platformWindow->hasMouseCapture()) {
341 platformWindow->applyCursor();
342 platformWindow->setMouseGrabEnabled(true);
343 platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
344 qCDebug(lcQpaEvents) << "Automatic mouse capture for missing buttondown event" << window;
345 }
346 m_previousCaptureWindow = window;
347 return true;
348 }
349 if (m_leftButtonDown && !actualLeftDown)
350 m_leftButtonDown = false;
351 }
352
353 // In this context, neither an invisible nor a transparent window (transparent regarding mouse
354 // events, "click-through") can be considered as the window under mouse.
355 QWindow *currentWindowUnderMouse = platformWindow->hasMouseCapture() ?
356 QWindowsScreen::windowAt(globalPosition, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT) : window;
357 while (currentWindowUnderMouse && currentWindowUnderMouse->flags() & Qt::WindowTransparentForInput)
358 currentWindowUnderMouse = currentWindowUnderMouse->parent();
359 // QTBUG-44332: When Qt is running at low integrity level and
360 // a Qt Window is parented on a Window of a higher integrity process
361 // using QWindow::fromWinId() (for example, Qt running in a browser plugin)
362 // ChildWindowFromPointEx() may not find the Qt window (failing with ERROR_ACCESS_DENIED)
363 if (!currentWindowUnderMouse) {
364 const QRect clientRect(QPoint(0, 0), window->size());
365 if (clientRect.contains(winEventPosition))
366 currentWindowUnderMouse = window;
367 }
368
369 compressMouseMove(&msg);
370 // Qt expects the platform plugin to capture the mouse on
371 // any button press until release.
372 if (!platformWindow->hasMouseCapture()
373 && (mouseEvent.type == QEvent::MouseButtonPress || mouseEvent.type == QEvent::MouseButtonDblClick)) {
374 platformWindow->setMouseGrabEnabled(true);
375 platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
376 qCDebug(lcQpaEvents) << "Automatic mouse capture " << window;
377 // Implement "Click to focus" for native child windows (unless it is a native widget window).
378 if (!window->isTopLevel() && !window->inherits("QWidgetWindow") && QGuiApplication::focusWindow() != window)
379 window->requestActivate();
380 } else if (platformWindow->hasMouseCapture()
381 && platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)
382 && mouseEvent.type == QEvent::MouseButtonRelease
383 && !buttons) {
384 platformWindow->setMouseGrabEnabled(false);
385 qCDebug(lcQpaEvents) << "Releasing automatic mouse capture " << window;
386 }
387
388 const bool hasCapture = platformWindow->hasMouseCapture();
389 const bool currentNotCapturing = hasCapture && currentWindowUnderMouse != window;
390 // Enter new window: track to generate leave event.
391 // If there is an active capture, only track if the current window is capturing,
392 // so we don't get extra leave when cursor leaves the application.
393 if (window != m_trackedWindow && !currentNotCapturing) {
394 TRACKMOUSEEVENT tme;
395 tme.cbSize = sizeof(TRACKMOUSEEVENT);
396 tme.dwFlags = TME_LEAVE;
397 tme.hwndTrack = hwnd;
398 tme.dwHoverTime = HOVER_DEFAULT; //
399 if (!TrackMouseEvent(&tme))
400 qWarning("TrackMouseEvent failed.");
401 m_trackedWindow = window;
402 }
403
404 // No enter or leave events are sent as long as there is an autocapturing window.
405 if (!hasCapture || !platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)) {
406 // Leave is needed if:
407 // 1) There is no capture and we move from a window to another window.
408 // Note: Leaving the application entirely is handled in WM_MOUSELEAVE case.
409 // 2) There is capture and we move out of the capturing window.
410 // 3) There is a new capture and we were over another window.
411 if ((m_windowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
412 && (!hasCapture || window == m_windowUnderMouse))
413 || (hasCapture && m_previousCaptureWindow != window && m_windowUnderMouse
414 && m_windowUnderMouse != window)) {
415 qCDebug(lcQpaEvents) << "Synthetic leave for " << m_windowUnderMouse;
417 if (currentNotCapturing) {
418 // Clear tracking if capturing and current window is not the capturing window
419 // to avoid leave when mouse actually leaves the application.
420 m_trackedWindow = nullptr;
421 // We are not officially in any window, but we need to set some cursor to clear
422 // whatever cursor the left window had, so apply the cursor of the capture window.
423 platformWindow->applyCursor();
424 }
425 }
426 // Enter is needed if:
427 // 1) There is no capture and we move to a new window.
428 // 2) There is capture and we move into the capturing window.
429 // 3) The capture just ended and we are over non-capturing window.
430 if ((currentWindowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
431 && (!hasCapture || currentWindowUnderMouse == window))
432 || (m_previousCaptureWindow && window != m_previousCaptureWindow && currentWindowUnderMouse
433 && currentWindowUnderMouse != m_previousCaptureWindow)) {
434 QPoint localPosition;
435 qCDebug(lcQpaEvents) << "Entering " << currentWindowUnderMouse;
436 if (QWindowsWindow *wumPlatformWindow = QWindowsWindow::windowsWindowOf(currentWindowUnderMouse)) {
437 localPosition = wumPlatformWindow->mapFromGlobal(globalPosition);
438 wumPlatformWindow->applyCursor();
439 }
440 QWindowSystemInterface::handleEnterEvent(currentWindowUnderMouse, localPosition, globalPosition);
441 }
442 // We need to track m_windowUnderMouse separately from m_trackedWindow, as
443 // Windows mouse tracking will not trigger WM_MOUSELEAVE for leaving window when
444 // mouse capture is set.
445 m_windowUnderMouse = currentWindowUnderMouse;
446 }
447
448 if (!discardEvent && mouseEvent.type != QEvent::None) {
449 QWindowSystemInterface::handleMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons,
450 mouseEvent.button, mouseEvent.type,
451 keyModifiers, source);
452 }
453 m_previousCaptureWindow = hasCapture ? window : nullptr;
454 // QTBUG-48117, force synchronous handling for the extra buttons so that WM_APPCOMMAND
455 // is sent for unhandled WM_XBUTTONDOWN.
456 return (msg.message != WM_XBUTTONUP && msg.message != WM_XBUTTONDOWN && msg.message != WM_XBUTTONDBLCLK)
458}
459
460static bool isValidWheelReceiver(QWindow *candidate)
461{
462 if (candidate) {
463 const QWindow *toplevel = QWindowsWindow::topLevelOf(candidate);
464 if (toplevel->handle() && toplevel->handle()->isForeignWindow())
465 return true;
466 if (const QWindowsWindow *ww = QWindowsWindow::windowsWindowOf(toplevel))
467 return !ww->testFlag(QWindowsWindow::BlockedByModal);
468 }
469
470 return false;
471}
472
473static void redirectWheelEvent(QWindow *window, unsigned long timestamp, const QPoint &globalPos, int delta,
474 Qt::Orientation orientation, Qt::KeyboardModifiers mods)
475{
476 // Redirect wheel event to one of the following, in order of preference:
477 // 1) The window under mouse
478 // 2) The window receiving the event
479 // If a window is blocked by modality, it can't get the event.
480
481 QWindow *receiver = QWindowsScreen::windowAt(globalPos, CWP_SKIPINVISIBLE);
482 while (receiver && receiver->flags().testFlag(Qt::WindowTransparentForInput))
483 receiver = receiver->parent();
484 bool handleEvent = true;
485 if (!isValidWheelReceiver(receiver)) {
486 receiver = window;
487 if (!isValidWheelReceiver(receiver))
488 handleEvent = false;
489 }
490
491 if (handleEvent) {
492 const QPoint point = (orientation == Qt::Vertical) ? QPoint(0, delta) : QPoint(delta, 0);
494 timestamp,
495 QWindowsGeometryHint::mapFromGlobal(receiver, globalPos),
496 globalPos, QPoint(), point, mods);
497 }
498}
499
500bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND,
501 MSG msg, LRESULT *)
502{
503 const Qt::KeyboardModifiers mods = keyStateToModifiers(int(msg.wParam));
504
505 int delta;
506 if (msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL)
507 delta = GET_WHEEL_DELTA_WPARAM(msg.wParam);
508 else
509 delta = int(msg.wParam);
510
511 Qt::Orientation orientation = (msg.message == WM_MOUSEHWHEEL
512 || (mods & Qt::AltModifier)) ?
514
515 // according to the MSDN documentation on WM_MOUSEHWHEEL:
516 // a positive value indicates that the wheel was rotated to the right;
517 // a negative value indicates that the wheel was rotated to the left.
518 // Qt defines this value as the exact opposite, so we have to flip the value!
519 if (msg.message == WM_MOUSEHWHEEL)
520 delta = -delta;
521
522 const QPoint globalPos(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
523 redirectWheelEvent(window, msg.time, globalPos, delta, orientation, mods);
524
525 return true;
526}
527
529 MSG msg, LRESULT *)
530{
531 // This is a workaround against some touchpads that send WM_HSCROLL instead of WM_MOUSEHWHEEL.
532 // We could also handle vertical scroll here but there's no reason to, there's no bug for vertical
533 // (broken vertical scroll would have been noticed long time ago), so lets keep the change small
534 // and minimize the chance for regressions.
535
536 int delta = 0;
537 switch (LOWORD(msg.wParam)) {
538 case SB_LINELEFT:
539 delta = 120;
540 break;
541 case SB_LINERIGHT:
542 delta = -120;
543 break;
544 case SB_PAGELEFT:
545 delta = 240;
546 break;
547 case SB_PAGERIGHT:
548 delta = -240;
549 break;
550 default:
551 return false;
552 }
553
555
556 return true;
557}
558
559// from bool QApplicationPrivate::translateTouchEvent()
562 MSG msg, LRESULT *)
563{
564 using QTouchPoint = QWindowSystemInterface::TouchPoint;
565 using QTouchPointList = QList<QWindowSystemInterface::TouchPoint>;
566
567 if (!QWindowsContext::instance()->initTouch()) {
568 qWarning("Unable to initialize touch handling.");
569 return true;
570 }
571
572 const QScreen *screen = window->screen();
573 if (!screen)
575 if (!screen)
576 return true;
577 const QRect screenGeometry = screen->geometry();
578
579 const int winTouchPointCount = int(msg.wParam);
580 const auto winTouchInputs = std::make_unique<TOUCHINPUT[]>(winTouchPointCount);
581
582 QTouchPointList touchPoints;
583 touchPoints.reserve(winTouchPointCount);
584 QEventPoint::States allStates;
585
586 GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(msg.lParam),
587 UINT(msg.wParam), winTouchInputs.get(), sizeof(TOUCHINPUT));
588 for (int i = 0; i < winTouchPointCount; ++i) {
589 const TOUCHINPUT &winTouchInput = winTouchInputs[i];
590 int id = m_touchInputIDToTouchPointID.value(winTouchInput.dwID, -1);
591 if (id == -1) {
592 id = m_touchInputIDToTouchPointID.size();
593 m_touchInputIDToTouchPointID.insert(winTouchInput.dwID, id);
594 }
595 QTouchPoint touchPoint;
596 touchPoint.pressure = 1.0;
597 touchPoint.id = id;
598 if (m_lastTouchPositions.contains(id))
599 touchPoint.normalPosition = m_lastTouchPositions.value(id);
600
601 const QPointF screenPos = QPointF(winTouchInput.x, winTouchInput.y) / qreal(100.);
602 if (winTouchInput.dwMask & TOUCHINPUTMASKF_CONTACTAREA)
603 touchPoint.area.setSize(QSizeF(winTouchInput.cxContact, winTouchInput.cyContact) / qreal(100.));
604 touchPoint.area.moveCenter(screenPos);
605 QPointF normalPosition = QPointF(screenPos.x() / screenGeometry.width(),
606 screenPos.y() / screenGeometry.height());
607 const bool stationaryTouchPoint = (normalPosition == touchPoint.normalPosition);
608 touchPoint.normalPosition = normalPosition;
609
610 if (winTouchInput.dwFlags & TOUCHEVENTF_DOWN) {
611 touchPoint.state = QEventPoint::State::Pressed;
612 m_lastTouchPositions.insert(id, touchPoint.normalPosition);
613 } else if (winTouchInput.dwFlags & TOUCHEVENTF_UP) {
614 touchPoint.state = QEventPoint::State::Released;
615 m_lastTouchPositions.remove(id);
616 } else {
617 touchPoint.state = (stationaryTouchPoint
620 m_lastTouchPositions.insert(id, touchPoint.normalPosition);
621 }
622
623 allStates |= touchPoint.state;
624
625 touchPoints.append(touchPoint);
626 }
627
628 CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(msg.lParam));
629
630 // all touch points released, forget the ids we've seen, they may not be reused
631 if (allStates == QEventPoint::State::Released)
632 m_touchInputIDToTouchPointID.clear();
633
634 const auto *keyMapper = QWindowsContext::instance()->keyMapper();
636 msg.time,
637 m_touchDevice.data(),
638 touchPoints,
639 keyMapper->queryKeyboardModifiers());
640 return true;
641}
642
645 MSG msg, LRESULT *)
646{
648 Q_UNUSED(hwnd);
649 Q_UNUSED(msg);
650 return false;
651}
652
IOBluetoothDevice * device
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
\inmodule QtCore
\inmodule QtCore
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ NonClientAreaMouseButtonDblClick
Definition qcoreevent.h:215
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ NonClientAreaMouseMove
Definition qcoreevent.h:212
@ NonClientAreaMouseButtonRelease
Definition qcoreevent.h:214
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ NonClientAreaMouseButtonPress
Definition qcoreevent.h:213
@ MouseButtonRelease
Definition qcoreevent.h:61
QScreen * primaryScreen
the primary (or default) screen of the application.
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
qsizetype size() const noexcept
Returns the number of items in the hash.
Definition qhash.h:927
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
T value(const Key &key) const noexcept
Definition qhash.h:1054
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:951
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
virtual bool isForeignWindow() const
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qpoint.h:25
bool isNull() const noexcept
Definition qpointer.h:84
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
static const QPointingDevice * primaryPointingDevice(const QString &seatName=QString())
Returns the primary pointing device (the core pointer, traditionally assumed to be a mouse) on the gi...
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\inmodule QtCore
Definition qsize.h:208
static bool handleTouchEvent(QWindow *window, const QPointingDevice *device, const QList< struct TouchPoint > &points, Qt::KeyboardModifiers mods=Qt::NoModifier)
static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Make Qt Gui process all events on the event queue immediately.
static void handleLeaveEvent(QWindow *window)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
static bool isRtlLayout(HWND hwnd)
static QWindowsContext * instance()
static QWindowsIntegration * instance()
static Qt::MouseButtons queryMouseButtons()
bool translateScrollEvent(QWindow *window, HWND hwnd, MSG msg, LRESULT *result)
bool translateTouchEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, LRESULT *result)
static Qt::KeyboardModifiers keyStateToModifiers(int)
static Qt::MouseButtons keyStateToMouseButtons(WPARAM)
bool translateGestureEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType, MSG msg, LRESULT *)
static const QPointingDevice * primaryMouse()
bool translateMouseEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, LRESULT *result)
static QWindow * windowAt(const QPoint &point, unsigned flags)
Raster or OpenGL Window.
static QWindowsWindow * windowsWindowOf(const QWindow *w)
static QWindow * topLevelOf(QWindow *w)
QPushButton * button
[2]
Combined button and popup list for selecting options.
WindowsEventType
Enumerations for WM_XX events.
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ BackButton
Definition qnamespace.h:61
@ RightButton
Definition qnamespace.h:59
@ MiddleButton
Definition qnamespace.h:60
@ ForwardButton
Definition qnamespace.h:64
@ XButton2
Definition qnamespace.h:65
@ NoButton
Definition qnamespace.h:57
@ XButton1
Definition qnamespace.h:62
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
MouseEventSource
@ MouseEventSynthesizedBySystem
@ MouseEventNotSynthesized
@ NoModifier
@ AltModifier
@ WindowTransparentForInput
Definition qnamespace.h:234
#define qWarning
Definition qlogging.h:166
#define qCDebug(category,...)
GLenum GLuint id
[7]
GLsizei GLsizei GLchar * source
GLuint64EXT * result
[6]
#define WM_MOUSEHWHEEL
Definition qt_windows.h:80
#define WM_MOUSEWHEEL
Definition qt_windows.h:77
QScreen * screen
[1]
Definition main.cpp:29
#define Q_UNUSED(x)
unsigned long long quint64
Definition qtypes.h:61
double qreal
Definition qtypes.h:187
struct tagMSG MSG
static bool isValidWheelReceiver(QWindow *candidate)
static Q_CONSTINIT QPoint lastMouseMovePos
static Qt::MouseButton extraButton(WPARAM wParam)
static MouseEvent eventFromMsg(const MSG &msg)
static void redirectWheelEvent(QWindow *window, unsigned long timestamp, const QPoint &globalPos, int delta, Qt::Orientation orientation, Qt::KeyboardModifiers mods)
static QT_BEGIN_NAMESPACE void compressMouseMove(MSG *msg)
static void clientToScreen(HWND hwnd, POINT *wP)
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
aWidget window() -> setWindowTitle("New Window Title")
[2]
EventType type
Definition qwasmevent.h:136
static QPoint mapToGlobal(HWND hwnd, const QPoint &)
static QPoint mapFromGlobal(const HWND hwnd, const QPoint &)