Changeset View
Changeset View
Standalone View
Standalone View
events/x11/x11events.cpp
- This file was copied from krfb/events.cpp.
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | This file is part of the KDE project | 2 | This file is part of the KDE project | ||
3 | 3 | | |||
4 | Copyright (C) 2010 Collabora Ltd. | 4 | Copyright (C) 2016 by Oleg Chernovskiy <kanedias@xaker.ru> | ||
5 | @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | | |||
6 | Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it> | | |||
7 | Copyright (C) 2001-2003 by Tim Jansen <tim@tjansen.de> | | |||
8 | 5 | | |||
9 | This program is free software; you can redistribute it and/or | 6 | This program is free software; you can redistribute it and/or | ||
10 | modify it under the terms of the GNU General Public | 7 | modify it under the terms of the GNU General Public | ||
11 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either | ||
12 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. | ||
13 | 10 | | |||
14 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | General Public License for more details. | 14 | General Public License for more details. | ||
18 | 15 | | |||
19 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; see the file COPYING. If not, write to | 17 | along with this program; see the file COPYING. If not, write to | ||
21 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
22 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. | ||
23 | */ | 20 | */ | ||
24 | 21 | | |||
25 | #include "events.h" | 22 | #include "x11events.h" | ||
26 | 23 | | |||
27 | #include <QApplication> | 24 | #include <QApplication> | ||
28 | #include <QX11Info> | 25 | #include <QX11Info> | ||
29 | #include <QDesktopWidget> | 26 | #include <QDesktopWidget> | ||
30 | #include <QGlobalStatic> | 27 | #include <QGlobalStatic> | ||
31 | 28 | | |||
32 | #include <X11/Xutil.h> | 29 | #include <X11/Xutil.h> | ||
33 | #include <X11/keysym.h> | 30 | #include <X11/keysym.h> | ||
34 | #include <X11/extensions/XTest.h> | 31 | #include <X11/extensions/XTest.h> | ||
35 | 32 | | |||
33 | #include <QX11Info> | ||||
34 | | ||||
36 | enum { | 35 | enum { | ||
37 | LEFTSHIFT = 1, | 36 | LEFTSHIFT = 1, | ||
38 | RIGHTSHIFT = 2, | 37 | RIGHTSHIFT = 2, | ||
39 | ALTGR = 4 | 38 | ALTGR = 4 | ||
40 | }; | 39 | }; | ||
41 | 40 | | |||
42 | class EventData | 41 | class EventData | ||
43 | { | 42 | { | ||
44 | public: | 43 | public: | ||
45 | EventData(); | 44 | EventData(); | ||
46 | 45 | | |||
47 | //keyboard | 46 | //keyboard | ||
48 | Display *dpy; | 47 | Display *dpy; | ||
49 | signed char modifiers[0x100]; | 48 | signed char modifiers[0x100]; | ||
50 | KeyCode keycodes[0x100]; | 49 | KeyCode keycodes[0x100]; | ||
51 | KeyCode leftShiftCode; | 50 | KeyCode leftShiftCode; | ||
52 | KeyCode rightShiftCode; | 51 | KeyCode rightShiftCode; | ||
53 | KeyCode altGrCode; | 52 | KeyCode altGrCode; | ||
54 | char modifierState; | 53 | char modifierState; | ||
55 | 54 | | |||
56 | //mouse | 55 | //mouse | ||
57 | int buttonMask; | 56 | int buttonMask; | ||
57 | int x; | ||||
58 | int y; | ||||
58 | 59 | | |||
59 | private: | 60 | private: | ||
60 | void init(); | 61 | void init(); | ||
61 | }; | 62 | }; | ||
62 | 63 | | |||
63 | Q_GLOBAL_STATIC(EventData, data) | 64 | Q_GLOBAL_STATIC(EventData, data) | ||
64 | 65 | | |||
65 | EventData::EventData() | 66 | EventData::EventData() | ||
66 | { | 67 | { | ||
67 | init(); | 68 | init(); | ||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | void EventData::init() | 71 | void EventData::init() | ||
71 | { | 72 | { | ||
72 | dpy = QX11Info::display(); | | |||
73 | buttonMask = 0; | 73 | buttonMask = 0; | ||
74 | 74 | | |||
75 | dpy = QX11Info::display(); | ||||
75 | //initialize keycodes | 76 | //initialize keycodes | ||
76 | KeySym key, *keymap; | 77 | KeySym key, *keymap; | ||
77 | int i, j, minkey, maxkey, syms_per_keycode; | 78 | int i, j, minkey, maxkey, syms_per_keycode; | ||
78 | 79 | | |||
79 | memset(modifiers, -1, sizeof(modifiers)); | 80 | memset(modifiers, -1, sizeof(modifiers)); | ||
80 | 81 | | |||
81 | XDisplayKeycodes(dpy, &minkey, &maxkey); | 82 | XDisplayKeycodes(dpy, &minkey, &maxkey); | ||
82 | Q_ASSERT(minkey >= 8); | 83 | Q_ASSERT(minkey >= 8); | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 110 | { | |||
136 | } | 137 | } | ||
137 | 138 | | |||
138 | if (!(data->modifierState & ALTGR) && mod == 2) { | 139 | if (!(data->modifierState & ALTGR) && mod == 2) { | ||
139 | XTestFakeKeyEvent(data->dpy, data->altGrCode, | 140 | XTestFakeKeyEvent(data->dpy, data->altGrCode, | ||
140 | down, CurrentTime); | 141 | down, CurrentTime); | ||
141 | } | 142 | } | ||
142 | } | 143 | } | ||
143 | 144 | | |||
144 | void EventHandler::handleKeyboard(bool down, rfbKeySym keySym) | 145 | void X11EventHandler::handleKeyboard(bool down, rfbKeySym keySym) | ||
145 | { | 146 | { | ||
146 | #define ADJUSTMOD(sym,state) \ | 147 | #define ADJUSTMOD(sym,state) \ | ||
147 | if(keySym==sym) { if(down) data->modifierState|=state; else data->modifierState&=~state; } | 148 | if(keySym==sym) { if(down) data->modifierState|=state; else data->modifierState&=~state; } | ||
148 | 149 | | |||
150 | if (QX11Info::isPlatformX11()) { | ||||
149 | ADJUSTMOD(XK_Shift_L, LEFTSHIFT); | 151 | ADJUSTMOD(XK_Shift_L, LEFTSHIFT); | ||
150 | ADJUSTMOD(XK_Shift_R, RIGHTSHIFT); | 152 | ADJUSTMOD(XK_Shift_R, RIGHTSHIFT); | ||
151 | ADJUSTMOD(XK_Mode_switch, ALTGR); | 153 | ADJUSTMOD(XK_Mode_switch, ALTGR); | ||
152 | 154 | | |||
153 | if (keySym >= ' ' && keySym < 0x100) { | 155 | if (keySym >= ' ' && keySym < 0x100) { | ||
154 | KeyCode k; | 156 | KeyCode k; | ||
155 | 157 | | |||
156 | if (down) { | 158 | if (down) { | ||
Show All 12 Lines | |||||
169 | } else { | 171 | } else { | ||
170 | KeyCode k = XKeysymToKeycode(data->dpy, keySym); | 172 | KeyCode k = XKeysymToKeycode(data->dpy, keySym); | ||
171 | 173 | | |||
172 | if (k != NoSymbol) { | 174 | if (k != NoSymbol) { | ||
173 | XTestFakeKeyEvent(data->dpy, k, down, CurrentTime); | 175 | XTestFakeKeyEvent(data->dpy, k, down, CurrentTime); | ||
174 | } | 176 | } | ||
175 | } | 177 | } | ||
176 | } | 178 | } | ||
179 | /* | ||||
180 | // Wayland platform and pipweire plugin in use | ||||
181 | if (KrfbConfig::preferredFrameBufferPlugin() == QStringLiteral("pw")) { | ||||
177 | 182 | | |||
178 | void EventHandler::handlePointer(int buttonMask, int x, int y) | 183 | }*/ | ||
184 | } | ||||
185 | | ||||
186 | void X11EventHandler::handlePointer(int buttonMask, int x, int y) | ||||
179 | { | 187 | { | ||
188 | if (QX11Info::isPlatformX11()) { | ||||
180 | QDesktopWidget *desktopWidget = QApplication::desktop(); | 189 | QDesktopWidget *desktopWidget = QApplication::desktop(); | ||
181 | 190 | | |||
182 | int screen = desktopWidget->screenNumber(); | 191 | int screen = desktopWidget->screenNumber(); | ||
183 | 192 | | |||
184 | if (screen < 0) { | 193 | if (screen < 0) { | ||
185 | screen = 0; | 194 | screen = 0; | ||
186 | } | 195 | } | ||
187 | 196 | | |||
188 | XTestFakeMotionEvent(data->dpy, screen, x, y, CurrentTime); | 197 | XTestFakeMotionEvent(data->dpy, screen, x, y, CurrentTime); | ||
189 | 198 | | |||
190 | for (int i = 0; i < 5; i++) { | 199 | for (int i = 0; i < 5; i++) { | ||
191 | if ((data->buttonMask&(1 << i)) != (buttonMask&(1 << i))) { | 200 | if ((data->buttonMask&(1 << i)) != (buttonMask&(1 << i))) { | ||
192 | XTestFakeButtonEvent(data->dpy, | 201 | XTestFakeButtonEvent(data->dpy, | ||
193 | i + 1, | 202 | i + 1, | ||
194 | (buttonMask&(1 << i)) ? True : False, | 203 | (buttonMask&(1 << i)) ? True : False, | ||
195 | CurrentTime); | 204 | CurrentTime); | ||
196 | } | 205 | } | ||
197 | } | 206 | } | ||
198 | 207 | | |||
199 | data->buttonMask = buttonMask; | 208 | data->buttonMask = buttonMask; | ||
200 | } | 209 | } | ||
210 | } | ||||
211 | | ||||
212 | #include "x11events.moc" |