Changeset View
Changeset View
Standalone View
Standalone View
events/xdp/xdpevents.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This file is part of the KDE project | ||||
3 | | ||||
4 | Copyright (C) 2018-2019 Jan Grulich <jgrulich@redhat.com> | ||||
5 | | ||||
6 | This program is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU General Public | ||||
8 | License as published by the Free Software Foundation; either | ||||
9 | version 2 of the License, or (at your option) any later version. | ||||
10 | | ||||
11 | This program is distributed in the hope that it will be useful, | ||||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
14 | General Public License for more details. | ||||
15 | | ||||
16 | You should have received a copy of the GNU General Public License | ||||
17 | along with this program; see the file COPYING. If not, write to | ||||
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
19 | Boston, MA 02110-1301, USA. | ||||
20 | */ | ||||
21 | | ||||
22 | #include "xdpevents.h" | ||||
23 | | ||||
24 | #include "rfbservermanager.h" | ||||
25 | #include "xdp_dbus_remotedesktop_interface.h" | ||||
26 | | ||||
27 | #include <linux/input.h> | ||||
28 | | ||||
29 | #include <QApplication> | ||||
30 | #include <QDesktopWidget> | ||||
31 | #include <QGlobalStatic> | ||||
32 | | ||||
33 | class EventData | ||||
34 | { | ||||
35 | public: | ||||
36 | EventData(); | ||||
37 | | ||||
38 | //mouse | ||||
39 | int buttonMask; | ||||
40 | int x; | ||||
41 | int y; | ||||
42 | | ||||
43 | QScopedPointer<OrgFreedesktopPortalRemoteDesktopInterface> dbusXdpRemoteDesktopService; | ||||
44 | | ||||
45 | private: | ||||
46 | void init(); | ||||
47 | }; | ||||
48 | | ||||
49 | Q_GLOBAL_STATIC(EventData, data) | ||||
50 | | ||||
51 | EventData::EventData() | ||||
52 | { | ||||
53 | init(); | ||||
54 | } | ||||
55 | | ||||
56 | void EventData::init() | ||||
57 | { | ||||
58 | buttonMask = 0; | ||||
59 | | ||||
60 | dbusXdpRemoteDesktopService.reset(new OrgFreedesktopPortalRemoteDesktopInterface(QLatin1String("org.freedesktop.portal.Desktop"), | ||||
61 | QLatin1String("/org/freedesktop/portal/desktop"), QDBusConnection::sessionBus())); | ||||
62 | } | ||||
63 | | ||||
64 | void XdpEventHandler::handleKeyboard(bool down, rfbKeySym keySym) | ||||
65 | { | ||||
66 | // TODO: implement button handling | ||||
67 | // both in FakeInput interface and here | ||||
68 | Q_UNUSED(down) | ||||
69 | Q_UNUSED(keySym) | ||||
70 | } | ||||
71 | | ||||
72 | void XdpEventHandler::handlePointer(int buttonMask, int x, int y) | ||||
73 | { | ||||
74 | const uint streamNodeId = frameBuffer()->customProperty(QLatin1String("stream_node_id")).toUInt(); | ||||
75 | const QDBusObjectPath sessionHandle = frameBuffer()->customProperty(QLatin1String("session_handle")).value<QDBusObjectPath>(); | ||||
76 | | ||||
77 | if (streamNodeId == 0 || sessionHandle.path().isEmpty()) { | ||||
78 | return; | ||||
79 | } | ||||
80 | | ||||
81 | if (x != data->x || y != data->y) { | ||||
82 | data->dbusXdpRemoteDesktopService->NotifyPointerMotionAbsolute(sessionHandle, QVariantMap(), streamNodeId, x, y); | ||||
83 | data->x = x; | ||||
84 | data->y = y; | ||||
85 | } | ||||
86 | | ||||
87 | if (buttonMask != data->buttonMask) { | ||||
88 | int i = 0; | ||||
89 | QVector<int> buttons = { BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, 0, 0, 0, 0, BTN_SIDE, BTN_EXTRA }; | ||||
90 | for (auto it = buttons.constBegin(); it != buttons.constEnd(); ++it) { | ||||
91 | int prevButtonState = (data->buttonMask >> i) & 0x01; | ||||
92 | int currentButtonState = (buttonMask >> i) & 0x01; | ||||
93 | | ||||
94 | if (prevButtonState != currentButtonState) { | ||||
95 | if (*it) { | ||||
96 | data->dbusXdpRemoteDesktopService->NotifyPointerButton(sessionHandle, QVariantMap(), *it, buttonMask); | ||||
97 | } else { | ||||
98 | int axis = 0; | ||||
99 | int steps = 0; | ||||
100 | switch (i) { | ||||
101 | case 3: | ||||
102 | axis = 0; // Vertical | ||||
103 | steps = -1; | ||||
104 | break; | ||||
105 | case 4: | ||||
106 | axis = 0; // Vertical | ||||
107 | steps = 1; | ||||
108 | break; | ||||
109 | case 5: | ||||
110 | axis = 1; // Horizontal | ||||
111 | steps = -1; | ||||
112 | break; | ||||
113 | case 6: | ||||
114 | axis = 1; // Horizontal | ||||
115 | steps = 1; | ||||
116 | break; | ||||
117 | } | ||||
118 | | ||||
119 | data->dbusXdpRemoteDesktopService->NotifyPointerAxisDiscrete(sessionHandle, QVariantMap(), axis, steps); | ||||
120 | } | ||||
121 | } | ||||
122 | ++i; | ||||
123 | } | ||||
124 | data->buttonMask = buttonMask; | ||||
125 | } | ||||
126 | } | ||||
127 | | ||||
128 | #include "xdpevents.moc" |