27 #include <QtGui/QApplication>
28 #include <QtGui/QX11Info>
29 #include <QtGui/QDesktopWidget>
32 #include <X11/Xutil.h>
33 #include <X11/keysym.h>
34 #include <X11/extensions/XTest.h>
49 signed char modifiers[0x100];
50 KeyCode keycodes[0x100];
51 KeyCode leftShiftCode;
52 KeyCode rightShiftCode;
63 K_GLOBAL_STATIC(EventData, data)
65 EventData::EventData()
70 void EventData::init()
72 dpy = QX11Info::display();
77 int i, j, minkey, maxkey, syms_per_keycode;
79 memset(modifiers, -1,
sizeof(modifiers));
81 XDisplayKeycodes(dpy, &minkey, &maxkey);
82 Q_ASSERT(minkey >= 8);
83 Q_ASSERT(maxkey < 256);
84 keymap = (KeySym *) XGetKeyboardMapping(dpy, minkey,
85 (maxkey - minkey + 1),
89 for (i = minkey; i <= maxkey; i++) {
90 for (j = 0; j < syms_per_keycode; j++) {
91 key = keymap[(i-minkey)*syms_per_keycode+j];
93 if (key >=
' ' && key < 0x100 && i == XKeysymToKeycode(dpy, key)) {
100 leftShiftCode = XKeysymToKeycode(dpy,
XK_Shift_L);
101 rightShiftCode = XKeysymToKeycode(dpy,
XK_Shift_R);
104 XFree((
char *)keymap);
116 if (isShift && mod != 1) {
118 XTestFakeKeyEvent(data->dpy, data->leftShiftCode,
123 XTestFakeKeyEvent(data->dpy, data->rightShiftCode,
128 if (!isShift && mod == 1) {
129 XTestFakeKeyEvent(data->dpy, data->leftShiftCode,
133 if ((data->modifierState &
ALTGR) && mod != 2) {
134 XTestFakeKeyEvent(data->dpy, data->altGrCode,
138 if (!(data->modifierState &
ALTGR) && mod == 2) {
139 XTestFakeKeyEvent(data->dpy, data->altGrCode,
146 #define ADJUSTMOD(sym,state) \
147 if(keySym==sym) { if(down) data->modifierState|=state; else data->modifierState&=~state; }
153 if (keySym >=
' ' && keySym < 0x100) {
160 k = data->keycodes[keySym];
163 XTestFakeKeyEvent(data->dpy, k, down, CurrentTime);
170 KeyCode k = XKeysymToKeycode(data->dpy, keySym);
173 XTestFakeKeyEvent(data->dpy, k, down, CurrentTime);
180 QDesktopWidget *desktopWidget = QApplication::desktop();
182 int screen = desktopWidget->screenNumber();
188 XTestFakeMotionEvent(data->dpy, screen, x, y, CurrentTime);
190 for (
int i = 0; i < 5; i++) {
191 if ((data->buttonMask&(1 << i)) != (buttonMask&(1 << i))) {
192 XTestFakeButtonEvent(data->dpy,
194 (buttonMask&(1 << i)) ? True : False,
199 data->buttonMask = buttonMask;
static void tweakModifiers(signed char mod, bool down)
static void handleKeyboard(bool down, rfbKeySym key)
#define ADJUSTMOD(sym, state)
static void handlePointer(int buttonMask, int x, int y)