Changeset View
Changeset View
Standalone View
Standalone View
pointer_input.h
Show All 17 Lines | |||||
18 | 18 | | |||
19 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | *********************************************************************/ | 21 | *********************************************************************/ | ||
22 | #ifndef KWIN_POINTER_INPUT_H | 22 | #ifndef KWIN_POINTER_INPUT_H | ||
23 | #define KWIN_POINTER_INPUT_H | 23 | #define KWIN_POINTER_INPUT_H | ||
24 | 24 | | |||
25 | #include "input.h" | 25 | #include "input.h" | ||
26 | #include "cursor.h" | ||||
26 | 27 | | |||
27 | #include <QElapsedTimer> | 28 | #include <QElapsedTimer> | ||
28 | #include <QObject> | 29 | #include <QObject> | ||
29 | #include <QPointer> | 30 | #include <QPointer> | ||
30 | #include <QPointF> | 31 | #include <QPointF> | ||
31 | 32 | | |||
32 | class QWindow; | 33 | class QWindow; | ||
33 | 34 | | |||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 66 | public: | |||
75 | QPointF pos() const { | 76 | QPointF pos() const { | ||
76 | return m_pos; | 77 | return m_pos; | ||
77 | } | 78 | } | ||
78 | Qt::MouseButtons buttons() const { | 79 | Qt::MouseButtons buttons() const { | ||
79 | return m_qtButtons; | 80 | return m_qtButtons; | ||
80 | } | 81 | } | ||
81 | bool areButtonsPressed() const; | 82 | bool areButtonsPressed() const; | ||
82 | 83 | | |||
83 | QImage cursorImage() const; | | |||
84 | QPoint cursorHotSpot() const; | | |||
85 | void markCursorAsRendered(); | | |||
86 | void setEffectsOverrideCursor(Qt::CursorShape shape); | 84 | void setEffectsOverrideCursor(Qt::CursorShape shape); | ||
87 | void removeEffectsOverrideCursor(); | 85 | void removeEffectsOverrideCursor(); | ||
88 | void setWindowSelectionCursor(const QByteArray &shape); | 86 | void setWindowSelectionCursor(const QByteArray &shape); | ||
89 | void removeWindowSelectionCursor(); | 87 | void removeWindowSelectionCursor(); | ||
90 | 88 | | |||
91 | void updatePointerConstraints(); | 89 | void updatePointerConstraints(); | ||
92 | 90 | | |||
93 | void setEnableConstraints(bool set); | 91 | void setEnableConstraints(bool set); | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 148 | private: | |||
177 | QMetaObject::Connection m_confinedPointerRegionConnection; | 175 | QMetaObject::Connection m_confinedPointerRegionConnection; | ||
178 | QMetaObject::Connection m_lockedPointerAboutToBeUnboundConnection; | 176 | QMetaObject::Connection m_lockedPointerAboutToBeUnboundConnection; | ||
179 | QMetaObject::Connection m_decorationGeometryConnection; | 177 | QMetaObject::Connection m_decorationGeometryConnection; | ||
180 | bool m_confined = false; | 178 | bool m_confined = false; | ||
181 | bool m_locked = false; | 179 | bool m_locked = false; | ||
182 | bool m_enableConstraints = true; | 180 | bool m_enableConstraints = true; | ||
183 | }; | 181 | }; | ||
184 | 182 | | |||
183 | class WaylandCursorImage : public QObject | ||||
184 | { | ||||
185 | Q_OBJECT | ||||
186 | public: | ||||
187 | void loadTheme(); | ||||
188 | struct Image { | ||||
189 | QImage image; | ||||
190 | QPoint hotspot; | ||||
191 | }; | ||||
192 | template <typename T> | ||||
193 | void loadThemeCursor(const T &shape, Image *image); | ||||
194 | | ||||
195 | template <typename T> | ||||
196 | void loadThemeCursor(const T &shape, QHash<T, Image> &cursors, Image *image); | ||||
197 | | ||||
198 | Q_SIGNALS: | ||||
199 | void themeChanged(); | ||||
200 | | ||||
201 | private: | ||||
202 | WaylandCursorTheme *m_cursorTheme = nullptr; | ||||
203 | }; | ||||
204 | | ||||
185 | class CursorImage : public QObject | 205 | class CursorImage : public QObject | ||
186 | { | 206 | { | ||
187 | Q_OBJECT | 207 | Q_OBJECT | ||
188 | public: | 208 | public: | ||
189 | explicit CursorImage(PointerInputRedirection *parent = nullptr); | 209 | explicit CursorImage(PointerInputRedirection *parent = nullptr); | ||
190 | ~CursorImage() override; | 210 | ~CursorImage() override; | ||
191 | 211 | | |||
192 | void setEffectsOverrideCursor(Qt::CursorShape shape); | 212 | void setEffectsOverrideCursor(Qt::CursorShape shape); | ||
Show All 12 Lines | 224 | private: | |||
205 | void reevaluteSource(); | 225 | void reevaluteSource(); | ||
206 | void update(); | 226 | void update(); | ||
207 | void updateServerCursor(); | 227 | void updateServerCursor(); | ||
208 | void updateDecoration(); | 228 | void updateDecoration(); | ||
209 | void updateDecorationCursor(); | 229 | void updateDecorationCursor(); | ||
210 | void updateMoveResize(); | 230 | void updateMoveResize(); | ||
211 | void updateDrag(); | 231 | void updateDrag(); | ||
212 | void updateDragCursor(); | 232 | void updateDragCursor(); | ||
213 | void loadTheme(); | 233 | | ||
214 | struct Image { | 234 | void loadThemeCursor(CursorShape shape, WaylandCursorImage::Image *image); | ||
215 | QImage image; | 235 | void loadThemeCursor(const QByteArray &shape, WaylandCursorImage::Image *image); | ||
216 | QPoint hotSpot; | | |||
217 | }; | | |||
218 | void loadThemeCursor(CursorShape shape, Image *image); | | |||
219 | void loadThemeCursor(const QByteArray &shape, Image *image); | | |||
220 | template <typename T> | | |||
221 | void loadThemeCursor(const T &shape, QHash<T, Image> &cursors, Image *image); | | |||
222 | 236 | | |||
223 | enum class CursorSource { | 237 | enum class CursorSource { | ||
224 | LockScreen, | 238 | LockScreen, | ||
225 | EffectsOverride, | 239 | EffectsOverride, | ||
226 | MoveResize, | 240 | MoveResize, | ||
227 | PointerSurface, | 241 | PointerSurface, | ||
228 | Decoration, | 242 | Decoration, | ||
229 | DragAndDrop, | 243 | DragAndDrop, | ||
230 | Fallback, | 244 | Fallback, | ||
231 | WindowSelector | 245 | WindowSelector | ||
232 | }; | 246 | }; | ||
233 | void setSource(CursorSource source); | 247 | void setSource(CursorSource source); | ||
234 | 248 | | |||
235 | PointerInputRedirection *m_pointer; | 249 | PointerInputRedirection *m_pointer; | ||
236 | CursorSource m_currentSource = CursorSource::Fallback; | 250 | CursorSource m_currentSource = CursorSource::Fallback; | ||
237 | WaylandCursorTheme *m_cursorTheme = nullptr; | 251 | WaylandCursorImage m_waylandImage; | ||
238 | struct { | | |||
239 | QMetaObject::Connection connection; | | |||
240 | QImage image; | | |||
241 | QPoint hotSpot; | | |||
242 | } m_serverCursor; | | |||
243 | 252 | | |||
244 | Image m_effectsCursor; | 253 | WaylandCursorImage::Image m_effectsCursor; | ||
245 | Image m_decorationCursor; | 254 | WaylandCursorImage::Image m_decorationCursor; | ||
246 | QMetaObject::Connection m_decorationConnection; | 255 | QMetaObject::Connection m_decorationConnection; | ||
247 | Image m_fallbackCursor; | 256 | WaylandCursorImage::Image m_fallbackCursor; | ||
248 | Image m_moveResizeCursor; | 257 | WaylandCursorImage::Image m_moveResizeCursor; | ||
249 | Image m_windowSelectionCursor; | 258 | WaylandCursorImage::Image m_windowSelectionCursor; | ||
250 | QHash<CursorShape, Image> m_cursors; | 259 | QHash<CursorShape, WaylandCursorImage::Image> m_cursors; | ||
251 | QHash<QByteArray, Image> m_cursorsByName; | 260 | QHash<QByteArray, WaylandCursorImage::Image> m_cursorsByName; | ||
252 | QElapsedTimer m_surfaceRenderedTimer; | 261 | QElapsedTimer m_surfaceRenderedTimer; | ||
253 | struct { | 262 | struct { | ||
254 | Image cursor; | 263 | WaylandCursorImage::Image cursor; | ||
255 | QMetaObject::Connection connection; | 264 | QMetaObject::Connection connection; | ||
256 | } m_drag; | 265 | } m_drag; | ||
266 | struct { | ||||
267 | QMetaObject::Connection connection; | ||||
268 | WaylandCursorImage::Image cursor; | ||||
269 | } m_serverCursor; | ||||
270 | }; | ||||
271 | | ||||
272 | /** | ||||
273 | * @brief Implementation using the InputRedirection framework to get pointer positions. | ||||
274 | * | ||||
275 | * Does not support warping of cursor. | ||||
276 | */ | ||||
277 | class InputRedirectionCursor : public KWin::Cursor | ||||
278 | { | ||||
279 | Q_OBJECT | ||||
280 | public: | ||||
281 | explicit InputRedirectionCursor(QObject *parent); | ||||
282 | ~InputRedirectionCursor() override; | ||||
283 | protected: | ||||
284 | void doSetPos() override; | ||||
285 | void doStartCursorTracking() override; | ||||
286 | void doStopCursorTracking() override; | ||||
287 | private Q_SLOTS: | ||||
288 | void slotPosChanged(const QPointF &pos); | ||||
289 | void slotPointerButtonChanged(); | ||||
290 | void slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods); | ||||
291 | private: | ||||
292 | Qt::MouseButtons m_currentButtons; | ||||
257 | }; | 293 | }; | ||
258 | 294 | | |||
259 | } | 295 | } | ||
260 | 296 | | |||
261 | #endif | 297 | #endif |