KWin
Loading...
Searching...
No Matches
tablet_input.cpp
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: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "tablet_input.h"
11#include "input_event.h"
12#include "input_event_spy.h"
13#include "pointer_input.h"
14#include "wayland/seat.h"
15#include "wayland/surface.h"
16#include "wayland_server.h"
17#include "window.h"
18#include "workspace.h"
19// KDecoration
20#include <KDecoration2/Decoration>
21// Qt
22#include <QHoverEvent>
23#include <QWindow>
24
25namespace KWin
26{
31
33
35{
36 Q_ASSERT(!inited());
37 setInited(true);
39
40 connect(workspace(), &QObject::destroyed, this, [this] {
41 setInited(false);
42 });
43 connect(waylandServer(), &QObject::destroyed, this, [this] {
44 setInited(false);
45 });
46}
47
49 qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
50 bool tipNear, const TabletToolId &tabletToolId,
51 std::chrono::microseconds time)
52{
53 if (!inited()) {
54 return;
55 }
57 m_lastPosition = pos;
58
59 QEvent::Type t;
60 switch (type) {
62 t = QEvent::TabletMove;
63 break;
65 t = tipDown ? QEvent::TabletPress : QEvent::TabletRelease;
66 break;
68 t = tipNear ? QEvent::TabletEnterProximity : QEvent::TabletLeaveProximity;
69 break;
70 }
71
72 update();
74
75 const auto button = m_tipDown ? Qt::LeftButton : Qt::NoButton;
76
77 // TODO: Not correct, but it should work fine. In long term, we need to stop using QTabletEvent.
78 const QPointingDevice *dev = QPointingDevice::primaryPointingDevice();
79 TabletEvent ev(t, dev, pos, pos, pressure,
80 xTilt, yTilt,
81 0, // tangentialPressure
82 rotation,
83 0, // z
84 Qt::NoModifier, button, button, tabletToolId);
85
86 ev.setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(time).count());
87 input()->processSpies(std::bind(&InputEventSpy::tabletToolEvent, std::placeholders::_1, &ev));
89 std::bind(&InputEventFilter::tabletToolEvent, std::placeholders::_1, &ev));
90
91 m_tipDown = tipDown;
92 m_tipNear = tipNear;
93}
94
96 const TabletToolId &tabletToolId, std::chrono::microseconds time)
97{
99 std::placeholders::_1, button, isPressed, tabletToolId, time));
101 std::placeholders::_1, button, isPressed, tabletToolId, time));
102 input()->setLastInputHandler(this);
103}
104
106 const TabletPadId &tabletPadId, std::chrono::microseconds time)
107{
109 std::placeholders::_1, button, isPressed, tabletPadId, time));
111 std::placeholders::_1, button, isPressed, tabletPadId, time));
112 input()->setLastInputHandler(this);
113}
114
115void KWin::TabletInputRedirection::tabletPadStripEvent(int number, int position, bool isFinger,
116 const TabletPadId &tabletPadId, std::chrono::microseconds time)
117{
119 std::placeholders::_1, number, position, isFinger, tabletPadId, time));
121 std::placeholders::_1, number, position, isFinger, tabletPadId, time));
122 input()->setLastInputHandler(this);
123}
124
125void KWin::TabletInputRedirection::tabletPadRingEvent(int number, int position, bool isFinger,
126 const TabletPadId &tabletPadId, std::chrono::microseconds time)
127{
129 std::placeholders::_1, number, position, isFinger, tabletPadId, time));
131 std::placeholders::_1, number, position, isFinger, tabletPadId, time));
132 input()->setLastInputHandler(this);
133}
134
139
140void TabletInputRedirection::cleanupDecoration(Decoration::DecoratedClientImpl *old,
142{
143 disconnect(m_decorationGeometryConnection);
144 m_decorationGeometryConnection = QMetaObject::Connection();
145
146 disconnect(m_decorationDestroyedConnection);
147 m_decorationDestroyedConnection = QMetaObject::Connection();
148
149 if (old) {
150 // send leave event to old decoration
151 QHoverEvent event(QEvent::HoverLeave, QPointF(), QPointF());
152 QCoreApplication::instance()->sendEvent(old->decoration(), &event);
153 }
154 if (!now) {
155 // left decoration
156 return;
157 }
158
159 const auto pos = m_lastPosition - now->window()->pos();
160 QHoverEvent event(QEvent::HoverEnter, pos, pos);
161 QCoreApplication::instance()->sendEvent(now->decoration(), &event);
162 now->window()->processDecorationMove(pos, m_lastPosition);
163
164 m_decorationGeometryConnection = connect(
165 decoration()->window(), &Window::frameGeometryChanged, this, [this]() {
166 // ensure maximize button gets the leave event when maximizing/restore a window, see BUG 385140
167 const auto oldDeco = decoration();
168 update();
169 if (oldDeco && oldDeco == decoration() && !decoration()->window()->isInteractiveMove() && !decoration()->window()->isInteractiveResize()) {
170 // position of window did not change, we need to send HoverMotion manually
171 const QPointF p = m_lastPosition - decoration()->window()->pos();
172 QHoverEvent event(QEvent::HoverMove, p, p);
173 QCoreApplication::instance()->sendEvent(decoration()->decoration(), &event);
174 }
175 },
176 Qt::QueuedConnection);
177
178 // if our decoration gets destroyed whilst it has focus, we pass focus on to the same client
179 m_decorationDestroyedConnection = connect(now, &QObject::destroyed, this, &TabletInputRedirection::update, Qt::QueuedConnection);
180}
181
182void TabletInputRedirection::focusUpdate(Window *focusOld, Window *focusNow)
183{
184 // This method is left blank intentionally.
185}
186
187}
188
189#include "moc_tablet_input.cpp"
QPointer< Window > window
Definition input.h:536
bool inited() const
Definition input.h:520
void setInited(bool set)
Definition input.h:524
virtual void init()
Definition input.cpp:3410
QPointer< Decoration::DecoratedClientImpl > decoration
Definition input.h:543
virtual bool tabletToolButtonEvent(uint button, bool pressed, const TabletToolId &tabletToolId, std::chrono::microseconds time)
Definition input.cpp:220
virtual bool tabletPadButtonEvent(uint button, bool pressed, const TabletPadId &tabletPadId, std::chrono::microseconds time)
Definition input.cpp:225
virtual bool tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
Definition input.cpp:235
virtual bool tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
Definition input.cpp:230
virtual bool tabletToolEvent(TabletEvent *event)
Definition input.cpp:215
virtual void tabletToolButtonEvent(uint button, bool pressed, const TabletToolId &tabletToolId, std::chrono::microseconds time)
virtual void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
virtual void tabletToolEvent(TabletEvent *event)
virtual void tabletPadButtonEvent(uint button, bool pressed, const TabletPadId &tabletPadId, std::chrono::microseconds time)
virtual void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
This class is responsible for redirecting incoming input to the surface which currently has input or ...
Definition input.h:70
void processSpies(UnaryFunction function)
Definition input.h:211
void processFilters(UnaryPredicate function)
Definition input.h:192
void setLastInputHandler(QObject *device)
Definition input.cpp:2739
bool isSelectingWindow() const
Definition input.cpp:3398
void tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time)
void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
void tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time)
void tabletToolEvent(KWin::InputRedirection::TabletEventType type, const QPointF &pos, qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown, bool tipNear, const TabletToolId &tabletToolId, std::chrono::microseconds time)
TabletInputRedirection(InputRedirection *parent)
void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time)
bool focusUpdatesBlocked() override
QPointF pos
Definition window.h:79
void processDecorationMove(const QPointF &localPos, const QPointF &globalPos)
Definition window.cpp:2706
void frameGeometryChanged(const QRectF &oldGeometry)
void setActiveCursorOutput(Output *output)
Session::Type type
Definition session.cpp:17
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
InputRedirection * input()
Definition input.h:549