KWin
Loading...
Searching...
No Matches
pointer_input.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2013, 2016 Martin Gräßlin <mgraesslin@kde.org>
6 SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
7 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11#pragma once
12
13#include "cursor.h"
14#include "input.h"
15#include "utils/xcursortheme.h"
16
17#include <QElapsedTimer>
18#include <QObject>
19#include <QPointF>
20#include <QPointer>
21
22class QWindow;
23
24namespace KWin
25{
26class Window;
27class CursorImage;
28class InputDevice;
29class InputRedirection;
30class CursorShape;
31class ShapeCursorSource;
32class SurfaceCursorSource;
33class PointerSurfaceCursor;
34class SurfaceInterface;
35
36namespace Decoration
37{
38class DecoratedClientImpl;
39}
40
41
43{
44 Q_OBJECT
45public:
48
49 void init() override;
50
51 void updateAfterScreenChange();
52 bool supportsWarping() const;
53 void warp(const QPointF &pos);
54
55 QPointF pos() const
56 {
57 return m_pos;
58 }
59 Qt::MouseButtons buttons() const
60 {
61 return m_qtButtons;
62 }
63 bool areButtonsPressed() const;
64
65 void setEffectsOverrideCursor(Qt::CursorShape shape);
66 void removeEffectsOverrideCursor();
67 void setWindowSelectionCursor(const QByteArray &shape);
68 void removeWindowSelectionCursor();
69
70 void updatePointerConstraints();
71
72 void setEnableConstraints(bool set);
73
74 bool isConstrained() const
75 {
76 return m_confined || m_locked;
77 }
78
79 bool focusUpdatesBlocked() override;
80
84 void processMotionAbsolute(const QPointF &pos, std::chrono::microseconds time, InputDevice *device = nullptr);
88 void processMotion(const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time, InputDevice *device);
92 void processButton(uint32_t button, InputRedirection::PointerButtonState state, std::chrono::microseconds time, InputDevice *device = nullptr);
96 void processAxis(InputRedirection::PointerAxis axis, qreal delta, qint32 deltaV120, InputRedirection::PointerAxisSource source, std::chrono::microseconds time, InputDevice *device = nullptr);
100 void processSwipeGestureBegin(int fingerCount, std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
104 void processSwipeGestureUpdate(const QPointF &delta, std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
108 void processSwipeGestureEnd(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
112 void processSwipeGestureCancelled(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
116 void processPinchGestureBegin(int fingerCount, std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
120 void processPinchGestureUpdate(qreal scale, qreal angleDelta, const QPointF &delta, std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
124 void processPinchGestureEnd(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
128 void processPinchGestureCancelled(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
132 void processHoldGestureBegin(int fingerCount, std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
136 void processHoldGestureEnd(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
140 void processHoldGestureCancelled(std::chrono::microseconds time, KWin::InputDevice *device = nullptr);
144 void processFrame(KWin::InputDevice *device = nullptr);
145
146private:
147 void processMotionInternal(const QPointF &pos, const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time, InputDevice *device);
148 void cleanupDecoration(Decoration::DecoratedClientImpl *old, Decoration::DecoratedClientImpl *now) override;
149
150 void focusUpdate(Window *focusOld, Window *focusNow) override;
151
152 QPointF position() const override;
153
154 void updateOnStartMoveResize();
155 void updateToReset();
156 void updatePosition(const QPointF &pos);
157 void updateButton(uint32_t button, InputRedirection::PointerButtonState state);
158 QPointF applyPointerConfinement(const QPointF &pos) const;
159 void disconnectConfinedPointerRegionConnection();
160 void disconnectLockedPointerAboutToBeUnboundConnection();
161 void disconnectPointerConstraintsConnection();
162 void breakPointerConstraints(SurfaceInterface *surface);
163 CursorImage *m_cursor;
164 QPointF m_pos;
165 QHash<uint32_t, InputRedirection::PointerButtonState> m_buttons;
166 Qt::MouseButtons m_qtButtons;
167 QMetaObject::Connection m_focusGeometryConnection;
168 QMetaObject::Connection m_constraintsConnection;
169 QMetaObject::Connection m_constraintsActivatedConnection;
170 QMetaObject::Connection m_confinedPointerRegionConnection;
171 QMetaObject::Connection m_lockedPointerAboutToBeUnboundConnection;
172 QMetaObject::Connection m_decorationGeometryConnection;
173 QMetaObject::Connection m_decorationDestroyedConnection;
174 QMetaObject::Connection m_decorationClosedConnection;
175 bool m_confined = false;
176 bool m_locked = false;
177 bool m_enableConstraints = true;
178 bool m_lastOutputWasPlaceholder = true;
180};
181
182class WaylandCursorImage : public QObject
183{
184 Q_OBJECT
185public:
186 explicit WaylandCursorImage(QObject *parent = nullptr);
187
188 KXcursorTheme theme() const;
189
190Q_SIGNALS:
192
193private:
194 void updateCursorTheme();
195
196 KXcursorTheme m_cursorTheme;
197};
198
199class CursorImage : public QObject
200{
201 Q_OBJECT
202public:
203 explicit CursorImage(PointerInputRedirection *parent = nullptr);
204 ~CursorImage() override;
205
206 void setEffectsOverrideCursor(Qt::CursorShape shape);
208 void setWindowSelectionCursor(const QByteArray &shape);
210
211 KXcursorTheme theme() const;
212 CursorSource *source() const;
214
215 void updateCursorOutputs(const QPointF &pos);
216 void markAsRendered(std::chrono::milliseconds timestamp);
217
218Q_SIGNALS:
219 void changed();
220
221private:
222 void reevaluteSource();
223 void updateServerCursor(const std::variant<PointerSurfaceCursor *, QByteArray> &cursor);
224 void updateDecoration();
225 void updateDecorationCursor();
226 void updateMoveResize();
227
228 void handleFocusedSurfaceChanged();
229
230 PointerInputRedirection *m_pointer;
231 CursorSource *m_currentSource = nullptr;
232 WaylandCursorImage m_waylandImage;
233
234 std::unique_ptr<ShapeCursorSource> m_effectsCursor;
235 std::unique_ptr<ShapeCursorSource> m_fallbackCursor;
236 std::unique_ptr<ShapeCursorSource> m_moveResizeCursor;
237 std::unique_ptr<ShapeCursorSource> m_windowSelectionCursor;
238
239 struct
240 {
241 std::unique_ptr<ShapeCursorSource> cursor;
242 QMetaObject::Connection connection;
243 } m_decoration;
244 struct
245 {
246 QMetaObject::Connection connection;
247 std::unique_ptr<SurfaceCursorSource> surface;
248 std::unique_ptr<ShapeCursorSource> shape;
250 } m_serverCursor;
251};
252
259{
260 Q_OBJECT
261public:
262 explicit InputRedirectionCursor();
263 ~InputRedirectionCursor() override;
264
265protected:
266 void doSetPos() override;
267
268private Q_SLOTS:
269 void slotPosChanged(const QPointF &pos);
270 void slotPointerButtonChanged();
271 void slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods);
272
273private:
274 Qt::MouseButtons m_currentButtons;
275};
276
277}
Replacement for QCursor.
Definition cursor.h:102
QPointF pos()
Definition cursor.cpp:204
std::unique_ptr< ShapeCursorSource > shape
CursorSource * source() const
void setEffectsOverrideCursor(Qt::CursorShape shape)
KXcursorTheme theme() const
CursorImage(PointerInputRedirection *parent=nullptr)
std::unique_ptr< SurfaceCursorSource > surface
void markAsRendered(std::chrono::milliseconds timestamp)
std::unique_ptr< ShapeCursorSource > cursor
void updateCursorOutputs(const QPointF &pos)
~CursorImage() override
void setWindowSelectionCursor(const QByteArray &shape)
QMetaObject::Connection connection
void setSource(CursorSource *source)
Implementation using the InputRedirection framework to get pointer positions.
This class is responsible for redirecting incoming input to the surface which currently has input or ...
Definition input.h:70
Qt::MouseButtons buttons() const
Resource representing a wl_surface.
Definition surface.h:80
KXcursorTheme theme() const
WaylandCursorImage(QObject *parent=nullptr)