You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Input.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /* Copyright (C) 2009 TightVNC Team
  2. * Copyright (C) 2009, 2014 Red Hat, Inc.
  3. * Copyright 2013-2015 Pierre Ossman for Cendio AB
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #ifdef HAVE_DIX_CONFIG_H
  21. #include <dix-config.h>
  22. #endif
  23. #include "xorg-version.h"
  24. #include "Input.h"
  25. #include "vncExtInit.h"
  26. #include "RFBGlue.h"
  27. #include "inputstr.h"
  28. #include "inpututils.h"
  29. #include "mi.h"
  30. #include "mipointer.h"
  31. #include "exevents.h"
  32. #include "scrnintstr.h"
  33. #include "xkbsrv.h"
  34. #include "xkbstr.h"
  35. #include "xserver-properties.h"
  36. extern _X_EXPORT DevPrivateKey CoreDevicePrivateKey;
  37. #include <X11/keysym.h>
  38. #include <X11/Xlib.h>
  39. #include <X11/Xutil.h>
  40. extern const unsigned short code_map_qnum_to_xorgevdev[];
  41. extern const unsigned int code_map_qnum_to_xorgevdev_len;
  42. extern const unsigned short code_map_qnum_to_xorgkbd[];
  43. extern const unsigned int code_map_qnum_to_xorgkbd_len;
  44. #define BUTTONS 7
  45. DeviceIntPtr vncKeyboardDev;
  46. DeviceIntPtr vncPointerDev;
  47. static int oldButtonMask;
  48. static int cursorPosX, cursorPosY;
  49. static const unsigned short *codeMap;
  50. static unsigned int codeMapLen;
  51. static KeySym pressedKeys[256];
  52. static int vncPointerProc(DeviceIntPtr pDevice, int onoff);
  53. static void vncKeyboardBell(int percent, DeviceIntPtr device,
  54. void * ctrl, int class);
  55. static int vncKeyboardProc(DeviceIntPtr pDevice, int onoff);
  56. static void vncKeysymKeyboardEvent(KeySym keysym, int down);
  57. #define LOG_NAME "Input"
  58. #define LOG_ERROR(...) vncLogError(LOG_NAME, __VA_ARGS__)
  59. #define LOG_STATUS(...) vncLogStatus(LOG_NAME, __VA_ARGS__)
  60. #define LOG_INFO(...) vncLogInfo(LOG_NAME, __VA_ARGS__)
  61. #define LOG_DEBUG(...) vncLogDebug(LOG_NAME, __VA_ARGS__)
  62. /*
  63. * Init input device.
  64. * This has to be called after core pointer/keyboard
  65. * initialization which unfortunately is after extensions
  66. * initialization (which means we cannot call it in
  67. * vncExtensionInit(). Check InitExtensions(),
  68. * InitCoreDevices() and InitInput() calls in dix/main.c.
  69. * Instead we call it from XserverDesktop at an appropriate
  70. * time.
  71. */
  72. void vncInitInputDevice(void)
  73. {
  74. int i, ret;
  75. if ((vncPointerDev != NULL) || (vncKeyboardDev != NULL))
  76. return;
  77. /*
  78. * On Linux we try to provide the same key codes as Xorg with
  79. * the evdev driver. On other platforms we mimic the older
  80. * Xorg KBD driver.
  81. */
  82. #ifdef __linux__
  83. codeMap = code_map_qnum_to_xorgevdev;
  84. codeMapLen = code_map_qnum_to_xorgevdev_len;
  85. #else
  86. codeMap = code_map_qnum_to_xorgkbd;
  87. codeMapLen = code_map_qnum_to_xorgkbd_len;
  88. #endif
  89. for (i = 0;i < 256;i++)
  90. pressedKeys[i] = NoSymbol;
  91. ret = AllocDevicePair(serverClient, "TigerVNC",
  92. &vncPointerDev, &vncKeyboardDev,
  93. vncPointerProc, vncKeyboardProc,
  94. FALSE);
  95. if (ret != Success)
  96. FatalError("Failed to initialize TigerVNC input devices\n");
  97. if (ActivateDevice(vncPointerDev, TRUE) != Success ||
  98. ActivateDevice(vncKeyboardDev, TRUE) != Success)
  99. FatalError("Failed to activate TigerVNC devices\n");
  100. if (!EnableDevice(vncPointerDev, TRUE) ||
  101. !EnableDevice(vncKeyboardDev, TRUE))
  102. FatalError("Failed to activate TigerVNC devices\n");
  103. vncPrepareInputDevices();
  104. }
  105. void vncPointerButtonAction(int buttonMask)
  106. {
  107. int i;
  108. ValuatorMask mask;
  109. for (i = 0; i < BUTTONS; i++) {
  110. if ((buttonMask ^ oldButtonMask) & (1 << i)) {
  111. int action = (buttonMask & (1<<i)) ?
  112. ButtonPress : ButtonRelease;
  113. valuator_mask_set_range(&mask, 0, 0, NULL);
  114. QueuePointerEvents(vncPointerDev, action, i + 1,
  115. POINTER_RELATIVE, &mask);
  116. }
  117. }
  118. oldButtonMask = buttonMask;
  119. }
  120. void vncPointerMove(int x, int y)
  121. {
  122. int valuators[2];
  123. ValuatorMask mask;
  124. if (cursorPosX == x && cursorPosY == y)
  125. return;
  126. valuators[0] = x;
  127. valuators[1] = y;
  128. valuator_mask_set_range(&mask, 0, 2, valuators);
  129. QueuePointerEvents(vncPointerDev, MotionNotify, 0,
  130. POINTER_ABSOLUTE, &mask);
  131. cursorPosX = x;
  132. cursorPosY = y;
  133. }
  134. void vncGetPointerPos(int *x, int *y)
  135. {
  136. if (vncPointerDev != NULL) {
  137. ScreenPtr ptrScreen;
  138. miPointerGetPosition(vncPointerDev, &cursorPosX, &cursorPosY);
  139. /* Pointer coordinates are screen relative */
  140. ptrScreen = miPointerGetScreen(vncPointerDev);
  141. cursorPosX += ptrScreen->x;
  142. cursorPosY += ptrScreen->y;
  143. }
  144. *x = cursorPosX;
  145. *y = cursorPosY;
  146. }
  147. static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
  148. {
  149. BYTE map[BUTTONS + 1];
  150. DevicePtr pDev = (DevicePtr)pDevice;
  151. int i;
  152. /*
  153. * NOTE: map[] array is one element longer than btn_labels[] array. This
  154. * is not a bug.
  155. */
  156. Atom btn_labels[BUTTONS];
  157. Atom axes_labels[2];
  158. switch (onoff) {
  159. case DEVICE_INIT:
  160. for (i = 0; i < BUTTONS + 1; i++)
  161. map[i] = i;
  162. btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
  163. btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
  164. btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
  165. btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
  166. btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
  167. btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
  168. btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
  169. axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
  170. axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
  171. InitPointerDeviceStruct(pDev, map, BUTTONS, btn_labels,
  172. (PtrCtrlProcPtr)NoopDDA,
  173. GetMotionHistorySize(),
  174. 2, axes_labels);
  175. break;
  176. case DEVICE_ON:
  177. pDev->on = TRUE;
  178. break;
  179. case DEVICE_OFF:
  180. pDev->on = FALSE;
  181. break;
  182. case DEVICE_CLOSE:
  183. vncPointerDev = NULL;
  184. break;
  185. }
  186. return Success;
  187. }
  188. static void vncKeyboardBell(int percent, DeviceIntPtr device,
  189. void * ctrl, int class)
  190. {
  191. if (percent > 0)
  192. vncBell();
  193. }
  194. static void vncKeyboardCtrl(DeviceIntPtr pDevice, KeybdCtrl *ctrl)
  195. {
  196. vncSetLEDState(ctrl->leds);
  197. }
  198. static int vncKeyboardProc(DeviceIntPtr pDevice, int onoff)
  199. {
  200. DevicePtr pDev = (DevicePtr)pDevice;
  201. switch (onoff) {
  202. case DEVICE_INIT:
  203. InitKeyboardDeviceStruct(pDevice, NULL, vncKeyboardBell,
  204. vncKeyboardCtrl);
  205. break;
  206. case DEVICE_ON:
  207. pDev->on = TRUE;
  208. break;
  209. case DEVICE_OFF:
  210. pDev->on = FALSE;
  211. break;
  212. case DEVICE_CLOSE:
  213. vncKeyboardDev = NULL;
  214. break;
  215. }
  216. return Success;
  217. }
  218. static inline void pressKey(DeviceIntPtr dev, int kc, Bool down, const char *msg)
  219. {
  220. int action;
  221. if (msg != NULL)
  222. LOG_DEBUG("%s %d %s", msg, kc, down ? "down" : "up");
  223. action = down ? KeyPress : KeyRelease;
  224. #if XORG < 118
  225. QueueKeyboardEvents(dev, action, kc, NULL);
  226. #else
  227. QueueKeyboardEvents(dev, action, kc);
  228. #endif
  229. }
  230. /*
  231. * vncKeyboardEvent() - add X11 events for the given RFB key event
  232. */
  233. void vncKeyboardEvent(KeySym keysym, unsigned xtcode, int down)
  234. {
  235. /* Simple case: the client has specified the key */
  236. if (xtcode && xtcode < codeMapLen) {
  237. int keycode;
  238. keycode = codeMap[xtcode];
  239. if (!keycode) {
  240. /*
  241. * Figure something out based on keysym if we
  242. * cannot find a mapping.
  243. */
  244. if (keysym)
  245. vncKeysymKeyboardEvent(keysym, down);
  246. return;
  247. }
  248. /*
  249. * We update the state table in case we get a mix of
  250. * events with and without key codes.
  251. */
  252. if (down)
  253. pressedKeys[keycode] = keysym;
  254. else
  255. pressedKeys[keycode] = NoSymbol;
  256. pressKey(vncKeyboardDev, keycode, down, "raw keycode");
  257. mieqProcessInputEvents();
  258. return;
  259. }
  260. /*
  261. * Advanced case: We have to figure out a sequence of keys that
  262. * result in the given keysym
  263. */
  264. if (keysym)
  265. vncKeysymKeyboardEvent(keysym, down);
  266. }
  267. /* altKeysym is a table of alternative keysyms which have the same meaning. */
  268. static struct altKeysym_t {
  269. KeySym a, b;
  270. } altKeysym[] = {
  271. { XK_Shift_L, XK_Shift_R },
  272. { XK_Control_L, XK_Control_R },
  273. { XK_Meta_L, XK_Meta_R },
  274. { XK_Alt_L, XK_Alt_R },
  275. { XK_Super_L, XK_Super_R },
  276. { XK_Hyper_L, XK_Hyper_R },
  277. { XK_KP_Space, XK_space },
  278. { XK_KP_Tab, XK_Tab },
  279. { XK_KP_Enter, XK_Return },
  280. { XK_KP_F1, XK_F1 },
  281. { XK_KP_F2, XK_F2 },
  282. { XK_KP_F3, XK_F3 },
  283. { XK_KP_F4, XK_F4 },
  284. { XK_KP_Home, XK_Home },
  285. { XK_KP_Left, XK_Left },
  286. { XK_KP_Up, XK_Up },
  287. { XK_KP_Right, XK_Right },
  288. { XK_KP_Down, XK_Down },
  289. { XK_KP_Page_Up, XK_Page_Up },
  290. { XK_KP_Page_Down, XK_Page_Down },
  291. { XK_KP_End, XK_End },
  292. { XK_KP_Begin, XK_Begin },
  293. { XK_KP_Insert, XK_Insert },
  294. { XK_KP_Delete, XK_Delete },
  295. { XK_KP_Equal, XK_equal },
  296. { XK_KP_Multiply, XK_asterisk },
  297. { XK_KP_Add, XK_plus },
  298. { XK_KP_Separator, XK_comma },
  299. { XK_KP_Subtract, XK_minus },
  300. { XK_KP_Decimal, XK_period },
  301. { XK_KP_Divide, XK_slash },
  302. { XK_KP_0, XK_0 },
  303. { XK_KP_1, XK_1 },
  304. { XK_KP_2, XK_2 },
  305. { XK_KP_3, XK_3 },
  306. { XK_KP_4, XK_4 },
  307. { XK_KP_5, XK_5 },
  308. { XK_KP_6, XK_6 },
  309. { XK_KP_7, XK_7 },
  310. { XK_KP_8, XK_8 },
  311. { XK_KP_9, XK_9 },
  312. { XK_ISO_Level3_Shift, XK_Mode_switch },
  313. };
  314. /*
  315. * vncKeysymKeyboardEvent() - work out the best keycode corresponding
  316. * to the keysym sent by the viewer. This is basically impossible in
  317. * the general case, but we make a best effort by assuming that all
  318. * useful keysyms can be reached using just the Shift and
  319. * Level 3 (AltGr) modifiers. For core keyboards this is basically
  320. * always true, and should be true for most sane, western XKB layouts.
  321. */
  322. static void vncKeysymKeyboardEvent(KeySym keysym, int down)
  323. {
  324. int i;
  325. unsigned state, new_state;
  326. KeyCode keycode;
  327. unsigned level_three_mask;
  328. KeyCode shift_press, level_three_press;
  329. KeyCode shift_release[8], level_three_release[8];
  330. size_t shift_release_count, level_three_release_count;
  331. /*
  332. * Release events must match the press event, so look up what
  333. * keycode we sent for the press.
  334. */
  335. if (!down) {
  336. for (i = 0;i < 256;i++) {
  337. if (pressedKeys[i] == keysym) {
  338. pressedKeys[i] = NoSymbol;
  339. pressKey(vncKeyboardDev, i, FALSE, "keycode");
  340. mieqProcessInputEvents();
  341. return;
  342. }
  343. }
  344. /*
  345. * This can happen quite often as we ignore some
  346. * key presses.
  347. */
  348. LOG_DEBUG("Unexpected release of keysym 0x%x", keysym);
  349. return;
  350. }
  351. /*
  352. * Since we are checking the current state to determine if we need
  353. * to fake modifiers, we must make sure that everything put on the
  354. * input queue is processed before we start. Otherwise, shift may be
  355. * stuck down.
  356. */
  357. mieqProcessInputEvents();
  358. state = vncGetKeyboardState();
  359. keycode = vncKeysymToKeycode(keysym, state, &new_state);
  360. /*
  361. * Shift+Alt is often mapped to Meta, so try that rather than
  362. * allocating a new entry, faking shift, or using the dummy
  363. * key entries that many layouts have.
  364. */
  365. if ((state & ShiftMask) &&
  366. ((keysym == XK_Alt_L) || (keysym == XK_Alt_R))) {
  367. KeyCode alt, meta;
  368. if (keysym == XK_Alt_L) {
  369. alt = vncKeysymToKeycode(XK_Alt_L, state & ~ShiftMask, NULL);
  370. meta = vncKeysymToKeycode(XK_Meta_L, state, NULL);
  371. } else {
  372. alt = vncKeysymToKeycode(XK_Alt_R, state & ~ShiftMask, NULL);
  373. meta = vncKeysymToKeycode(XK_Meta_R, state, NULL);
  374. }
  375. if ((meta != 0) && (alt == meta)) {
  376. LOG_DEBUG("Replacing Shift+Alt with Shift+Meta");
  377. keycode = meta;
  378. new_state = state;
  379. }
  380. }
  381. /* Try some equivalent keysyms if we couldn't find a perfect match */
  382. if (keycode == 0) {
  383. for (i = 0;i < sizeof(altKeysym)/sizeof(altKeysym[0]);i++) {
  384. KeySym altsym;
  385. if (altKeysym[i].a == keysym)
  386. altsym = altKeysym[i].b;
  387. else if (altKeysym[i].b == keysym)
  388. altsym = altKeysym[i].a;
  389. else
  390. continue;
  391. keycode = vncKeysymToKeycode(altsym, state, &new_state);
  392. if (keycode != 0)
  393. break;
  394. }
  395. }
  396. /* No matches. Will have to add a new entry... */
  397. if (keycode == 0) {
  398. keycode = vncAddKeysym(keysym, state);
  399. if (keycode == 0) {
  400. LOG_ERROR("Failure adding new keysym 0x%x", keysym);
  401. return;
  402. }
  403. LOG_INFO("Added unknown keysym 0x%x to keycode %d",
  404. keysym, keycode);
  405. /*
  406. * The state given to addKeysym() is just a hint and
  407. * the actual result might still require some state
  408. * changes.
  409. */
  410. keycode = vncKeysymToKeycode(keysym, state, &new_state);
  411. if (keycode == 0) {
  412. LOG_ERROR("Newly added keysym 0x%x cannot be generated", keysym);
  413. return;
  414. }
  415. }
  416. /*
  417. * X11 generally lets shift toggle the keys on the numeric pad
  418. * the same way NumLock does. This is however not the case on
  419. * other systems like Windows. As a result, some applications
  420. * get confused when we do a fake shift to get the same effect
  421. * that having NumLock active would produce.
  422. *
  423. * Not all clients have proper NumLock synchronisation (so we
  424. * can avoid faking shift) so we try to avoid the fake shifts
  425. * if we can use an alternative keysym.
  426. */
  427. if (((state & ShiftMask) != (new_state & ShiftMask)) &&
  428. vncGetAvoidShiftNumLock() && vncIsAffectedByNumLock(keycode)) {
  429. KeyCode keycode2;
  430. unsigned new_state2;
  431. LOG_DEBUG("Finding alternative to keysym 0x%x to avoid fake shift for numpad", keysym);
  432. for (i = 0;i < sizeof(altKeysym)/sizeof(altKeysym[0]);i++) {
  433. KeySym altsym;
  434. if (altKeysym[i].a == keysym)
  435. altsym = altKeysym[i].b;
  436. else if (altKeysym[i].b == keysym)
  437. altsym = altKeysym[i].a;
  438. else
  439. continue;
  440. keycode2 = vncKeysymToKeycode(altsym, state, &new_state2);
  441. if (keycode2 == 0)
  442. continue;
  443. if (((state & ShiftMask) != (new_state2 & ShiftMask)) &&
  444. vncIsAffectedByNumLock(keycode2))
  445. continue;
  446. break;
  447. }
  448. if (i == sizeof(altKeysym)/sizeof(altKeysym[0]))
  449. LOG_DEBUG("No alternative keysym found");
  450. else {
  451. keycode = keycode2;
  452. new_state = new_state2;
  453. }
  454. }
  455. /*
  456. * "Shifted Tab" is a bit of a mess. Some systems have varying,
  457. * special keysyms for this symbol. VNC mandates that clients
  458. * should always send the plain XK_Tab keysym and the server
  459. * should deduce the meaning based on current Shift state.
  460. * To comply with this, we will find the keycode that sends
  461. * XK_Tab, and make sure that Shift isn't cleared. This can
  462. * possibly result in a different keysym than XK_Tab, but that
  463. * is the desired behaviour.
  464. *
  465. * Note: We never get ISO_Left_Tab here because it's already
  466. * been translated in VNCSConnectionST.
  467. */
  468. if (keysym == XK_Tab && (state & ShiftMask))
  469. new_state |= ShiftMask;
  470. /*
  471. * We need a bigger state change than just shift,
  472. * so we need to know what the mask is for level 3 shifts.
  473. */
  474. if ((new_state & ~ShiftMask) != (state & ~ShiftMask))
  475. level_three_mask = vncGetLevelThreeMask();
  476. else
  477. level_three_mask = 0;
  478. shift_press = level_three_press = 0;
  479. shift_release_count = level_three_release_count = 0;
  480. /* Need a fake press or release of shift? */
  481. if (!(state & ShiftMask) && (new_state & ShiftMask)) {
  482. shift_press = vncPressShift();
  483. if (shift_press == 0) {
  484. LOG_ERROR("Unable to find a modifier key for Shift");
  485. return;
  486. }
  487. pressKey(vncKeyboardDev, shift_press, TRUE, "temp shift");
  488. } else if ((state & ShiftMask) && !(new_state & ShiftMask)) {
  489. shift_release_count = vncReleaseShift(shift_release,
  490. sizeof(shift_release)/sizeof(*shift_release));
  491. if (shift_release_count == 0) {
  492. LOG_ERROR("Unable to find the modifier key(s) for releasing Shift");
  493. return;
  494. }
  495. for (i = 0;i < shift_release_count;i++)
  496. pressKey(vncKeyboardDev, shift_release[i], FALSE, "temp shift");
  497. }
  498. /* Need a fake press or release of level three shift? */
  499. if (!(state & level_three_mask) && (new_state & level_three_mask)) {
  500. level_three_press = vncPressLevelThree();
  501. if (level_three_press == 0) {
  502. LOG_ERROR("Unable to find a modifier key for ISO_Level3_Shift/Mode_Switch");
  503. return;
  504. }
  505. pressKey(vncKeyboardDev, level_three_press, TRUE, "temp level 3 shift");
  506. } else if ((state & level_three_mask) && !(new_state & level_three_mask)) {
  507. level_three_release_count = vncReleaseLevelThree(level_three_release,
  508. sizeof(level_three_release)/sizeof(*level_three_release));
  509. if (level_three_release_count == 0) {
  510. LOG_ERROR("Unable to find the modifier key(s) for releasing ISO_Level3_Shift/Mode_Switch");
  511. return;
  512. }
  513. for (i = 0;i < level_three_release_count;i++)
  514. pressKey(vncKeyboardDev, level_three_release[i], FALSE, "temp level 3 shift");
  515. }
  516. /* Now press the actual key */
  517. pressKey(vncKeyboardDev, keycode, TRUE, "keycode");
  518. /* And store the mapping so that we can do a proper release later */
  519. for (i = 0;i < 256;i++) {
  520. if (i == keycode)
  521. continue;
  522. if (pressedKeys[i] == keysym) {
  523. LOG_ERROR("Keysym 0x%x generated by both keys %d and %d", keysym, i, keycode);
  524. pressedKeys[i] = NoSymbol;
  525. }
  526. }
  527. pressedKeys[keycode] = keysym;
  528. /* Undo any fake level three shift */
  529. if (level_three_press != 0)
  530. pressKey(vncKeyboardDev, level_three_press, FALSE, "temp level 3 shift");
  531. else if (level_three_release_count != 0) {
  532. for (i = 0;i < level_three_release_count;i++)
  533. pressKey(vncKeyboardDev, level_three_release[i], TRUE, "temp level 3 shift");
  534. }
  535. /* Undo any fake shift */
  536. if (shift_press != 0)
  537. pressKey(vncKeyboardDev, shift_press, FALSE, "temp shift");
  538. else if (shift_release_count != 0) {
  539. for (i = 0;i < shift_release_count;i++)
  540. pressKey(vncKeyboardDev, shift_release[i], TRUE, "temp shift");
  541. }
  542. /*
  543. * When faking a modifier we are putting a keycode (which can
  544. * currently activate the desired modifier) on the input
  545. * queue. A future modmap change can change the mapping so
  546. * that this keycode means something else entirely. Guard
  547. * against this by processing the queue now.
  548. */
  549. mieqProcessInputEvents();
  550. }
  551. #if INPUTTHREAD
  552. /** This function is called in Xserver/os/inputthread.c when starting
  553. the input thread. */
  554. void
  555. ddxInputThreadInit(void)
  556. {
  557. }
  558. #endif