Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsdirectmanipulation.h
Go to the documentation of this file.
1// Copyright (C) 2026 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// Qt-Security score:significant reason:default
4
5#ifndef QWINDOWSDIRECTMANIPULATION_H
6#define QWINDOWSDIRECTMANIPULATION_H
7
8#include <QtCore/qt_windows.h>
9#include <QtCore/private/qcomptr_p.h>
10
11#include <QtCore/qhash.h>
12#include <QtCore/qscopedpointer.h>
13#include <QtCore/qsharedpointer.h>
14#include <QtGui/qpointingdevice.h>
15
16#include <directmanipulation.h>
17
18QT_BEGIN_NAMESPACE
19
20class QWindow;
22
23/*!
24 \internal
25
26 Translates Windows Precision Touchpad gestures into Qt events, using the
27 Direct Manipulation API.
28
29 Windows reports touchpad gestures to legacy applications by synthesizing
30 mouse wheel messages: two-finger scrolling arrives as WM_MOUSEWHEEL and
31 WM_MOUSEHWHEEL with fine-grained deltas, and pinching arrives as
32 Ctrl+WM_MOUSEWHEEL quantized to whole WHEEL_DELTA steps. Neither carries
33 pixel deltas, gesture phases, or a real scale factor.
34
35 Direct Manipulation provides all of those: it reports a continuous content
36 transform (translation and scale) together with a state machine that
37 distinguishes an ongoing manipulation from the inertia which follows it. We
38 turn the translation into QWheelEvent with pixel deltas and scroll phases
39 (matching what the Cocoa plugin delivers for a trackpad), and the scale
40 into QNativeGestureEvent with Qt::ZoomNativeGesture, wrapped in
41 Qt::BeginNativeGesture and Qt::EndNativeGesture (matching the XCB plugin).
42
43 Handing a contact over to Direct Manipulation stops Windows from
44 synthesizing the legacy wheel messages for it, so gestures are not
45 delivered twice. A mouse wheel is unaffected and keeps arriving as
46 WM_MOUSEWHEEL, and touch screens and pens are left to
47 QWindowsPointerHandler.
48
49 Rotation is not available: DIRECTMANIPULATION_CONFIGURATION has no rotation
50 flag, and the content transform Direct Manipulation reports is always a
51 uniform scale plus a translation. Multi-finger swipes are consumed by the
52 shell (task view, virtual desktop switching) and never reach the
53 application, so Qt::SwipeNativeGesture cannot be supported either.
54*/
56{
58public:
60
62
63 // Returns nullptr if Direct Manipulation is unavailable.
65
66 // Direct Manipulation viewports are per-window: the plugin creates one for
67 // each window it creates, and destroys it along with the window.
68 void registerWindow(QWindow *window, HWND hwnd);
69 void unregisterWindow(HWND hwnd);
70
71 // Handles DM_POINTERHITTEST, which Windows sends at the start of an
72 // interaction over a window that has been activated for Direct
73 // Manipulation. Returns true if the contact was handed over to Direct
74 // Manipulation.
75 bool handlePointerHitTest(HWND hwnd, WPARAM wParam);
76
78
79private:
81
82 QWindowsDirectManipulation() = default;
83 bool init();
84
85 // In DIRECTMANIPULATION_VIEWPORT_OPTIONS_MANUALUPDATE mode Direct
86 // Manipulation only produces content transforms when asked to, so an
87 // active interaction has to be pumped. A viewport calls this when it is
88 // given a contact; the pump stops itself once nothing is interacting.
89 void startUpdates();
90 void update();
91 bool isInteracting() const;
92
93 class UpdatePump;
94
95 ComPtr<IDirectManipulationManager> m_manager;
96 ComPtr<IDirectManipulationUpdateManager> m_updateManager;
98 QScopedPointer<UpdatePump> m_pump;
99 QPointingDevicePtr m_device;
100 int m_idleUpdates = 0;
101};
102
103QT_END_NAMESPACE
104
105#endif // QWINDOWSDIRECTMANIPULATION_H
\inmodule QtCore\reentrant
Definition qpoint.h:30
Singleton container for all relevant information.
QPlatformKeyMapper * keyMapper() const
static QWindowsContext * instance()
Platform cursor implementation.
static QPoint mousePosition()
bool init(IDirectManipulationManager *manager)
void destroy(IDirectManipulationManager *manager)
~QWindowsDirectManipulationViewport() override=default
QWindowsDirectManipulationViewport(QWindowsDirectManipulation *dm, QWindow *window, HWND hwnd)
void timerEvent(QTimerEvent *) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void registerWindow(QWindow *window, HWND hwnd)
static QWindowsDirectManipulation * create()
const QPointingDevicePtr & device()
bool handlePointerHitTest(HWND hwnd, WPARAM wParam)
static const char * statusName(DIRECTMANIPULATION_STATUS status)
static Qt::KeyboardModifiers keyboardModifiers()
static constexpr int pixelsToDegrees
static constexpr int maxIdleUpdates
static constexpr int updateIntervalMs
static constexpr float maximumZoom
static constexpr float minimumZoom
static constexpr LONG viewportSize
static constexpr int pinchFingerCount
static void warnFailure(const char *what, HRESULT hr)