Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Viewport.cxx 33KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2011-2014 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <assert.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <rfb/CMsgWriter.h>
  26. #include <rfb/LogWriter.h>
  27. #include <rfb/Exception.h>
  28. #include <rfb/ledStates.h>
  29. // FLTK can pull in the X11 headers on some systems
  30. #ifndef XK_VoidSymbol
  31. #define XK_LATIN1
  32. #define XK_MISCELLANY
  33. #define XK_XKB_KEYS
  34. #include <rfb/keysymdef.h>
  35. #endif
  36. #ifndef XF86XK_ModeLock
  37. #include <rfb/XF86keysym.h>
  38. #endif
  39. #if ! (defined(WIN32) || defined(__APPLE__))
  40. #include <X11/XKBlib.h>
  41. #endif
  42. #ifndef NoSymbol
  43. #define NoSymbol 0
  44. #endif
  45. // Missing in at least some versions of MinGW
  46. #ifndef MAPVK_VK_TO_VSC
  47. #define MAPVK_VK_TO_VSC 0
  48. #endif
  49. #include "Viewport.h"
  50. #include "CConn.h"
  51. #include "OptionsDialog.h"
  52. #include "DesktopWindow.h"
  53. #include "i18n.h"
  54. #include "fltk_layout.h"
  55. #include "parameters.h"
  56. #include "keysym2ucs.h"
  57. #include "menukey.h"
  58. #include "vncviewer.h"
  59. #include "PlatformPixelBuffer.h"
  60. #include <FL/fl_draw.H>
  61. #include <FL/fl_ask.H>
  62. #include <FL/Fl_Menu.H>
  63. #include <FL/Fl_Menu_Button.H>
  64. #if !defined(WIN32) && !defined(__APPLE__)
  65. #include <X11/XKBlib.h>
  66. extern const struct _code_map_xkb_to_qnum {
  67. const char * from;
  68. const unsigned short to;
  69. } code_map_xkb_to_qnum[];
  70. extern const unsigned int code_map_xkb_to_qnum_len;
  71. static int code_map_keycode_to_qnum[256];
  72. #endif
  73. #ifdef __APPLE__
  74. #include "cocoa.h"
  75. extern const unsigned short code_map_osx_to_qnum[];
  76. extern const unsigned int code_map_osx_to_qnum_len;
  77. #endif
  78. #ifdef WIN32
  79. #include "win32.h"
  80. #endif
  81. using namespace rfb;
  82. using namespace rdr;
  83. static rfb::LogWriter vlog("Viewport");
  84. // Menu constants
  85. enum { ID_EXIT, ID_FULLSCREEN, ID_MINIMIZE, ID_RESIZE,
  86. ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL,
  87. ID_REFRESH, ID_OPTIONS, ID_INFO, ID_ABOUT, ID_DISMISS };
  88. // Used to detect fake input (0xaa is not a real key)
  89. #ifdef WIN32
  90. static const WORD SCAN_FAKE = 0xaa;
  91. #endif
  92. Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
  93. : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL),
  94. lastPointerPos(0, 0), lastButtonMask(0),
  95. #ifdef WIN32
  96. altGrArmed(false),
  97. #endif
  98. firstLEDState(true),
  99. pendingServerCutText(NULL), pendingClientCutText(NULL),
  100. menuCtrlKey(false), menuAltKey(false), cursor(NULL)
  101. {
  102. #if !defined(WIN32) && !defined(__APPLE__)
  103. XkbDescPtr xkb;
  104. Status status;
  105. xkb = XkbGetMap(fl_display, 0, XkbUseCoreKbd);
  106. if (!xkb)
  107. throw rfb::Exception("XkbGetMap");
  108. status = XkbGetNames(fl_display, XkbKeyNamesMask, xkb);
  109. if (status != Success)
  110. throw rfb::Exception("XkbGetNames");
  111. memset(code_map_keycode_to_qnum, 0, sizeof(code_map_keycode_to_qnum));
  112. for (KeyCode keycode = xkb->min_key_code;
  113. keycode < xkb->max_key_code;
  114. keycode++) {
  115. const char *keyname = xkb->names->keys[keycode].name;
  116. unsigned short rfbcode;
  117. if (keyname[0] == '\0')
  118. continue;
  119. rfbcode = 0;
  120. for (unsigned i = 0;i < code_map_xkb_to_qnum_len;i++) {
  121. if (strncmp(code_map_xkb_to_qnum[i].from,
  122. keyname, XkbKeyNameLength) == 0) {
  123. rfbcode = code_map_xkb_to_qnum[i].to;
  124. break;
  125. }
  126. }
  127. if (rfbcode != 0)
  128. code_map_keycode_to_qnum[keycode] = rfbcode;
  129. else
  130. vlog.debug("No key mapping for key %.4s", keyname);
  131. }
  132. XkbFreeKeyboard(xkb, 0, True);
  133. #endif
  134. Fl::add_clipboard_notify(handleClipboardChange, this);
  135. // We need to intercept keyboard events early
  136. Fl::add_system_handler(handleSystemEvent, this);
  137. frameBuffer = new PlatformPixelBuffer(w, h);
  138. assert(frameBuffer);
  139. cc->setFramebuffer(frameBuffer);
  140. contextMenu = new Fl_Menu_Button(0, 0, 0, 0);
  141. // Setting box type to FL_NO_BOX prevents it from trying to draw the
  142. // button component (which we don't want)
  143. contextMenu->box(FL_NO_BOX);
  144. // The (invisible) button associated with this widget can mess with
  145. // things like Fl_Scroll so we need to get rid of any parents.
  146. // Unfortunately that's not possible because of STR #2654, but
  147. // reparenting to the current window works for most cases.
  148. window()->add(contextMenu);
  149. setMenuKey();
  150. OptionsDialog::addCallback(handleOptions, this);
  151. }
  152. Viewport::~Viewport()
  153. {
  154. // Unregister all timeouts in case they get a change tro trigger
  155. // again later when this object is already gone.
  156. Fl::remove_timeout(handlePointerTimeout, this);
  157. #ifdef WIN32
  158. Fl::remove_timeout(handleAltGrTimeout, this);
  159. #endif
  160. Fl::remove_system_handler(handleSystemEvent);
  161. Fl::remove_clipboard_notify(handleClipboardChange);
  162. OptionsDialog::removeCallback(handleOptions);
  163. if (cursor) {
  164. if (!cursor->alloc_array)
  165. delete [] cursor->array;
  166. delete cursor;
  167. }
  168. clearPendingClipboard();
  169. // FLTK automatically deletes all child widgets, so we shouldn't touch
  170. // them ourselves here
  171. }
  172. const rfb::PixelFormat &Viewport::getPreferredPF()
  173. {
  174. return frameBuffer->getPF();
  175. }
  176. // Copy the areas of the framebuffer that have been changed (damaged)
  177. // to the displayed window.
  178. void Viewport::updateWindow()
  179. {
  180. Rect r;
  181. r = frameBuffer->getDamage();
  182. damage(FL_DAMAGE_USER1, r.tl.x + x(), r.tl.y + y(), r.width(), r.height());
  183. }
  184. void Viewport::serverCutText(const char* str, rdr::U32 len)
  185. {
  186. char *buffer;
  187. int size, ret;
  188. clearPendingClipboard();
  189. if (!acceptClipboard)
  190. return;
  191. size = fl_utf8froma(NULL, 0, str, len);
  192. if (size <= 0)
  193. return;
  194. size++;
  195. buffer = new char[size];
  196. ret = fl_utf8froma(buffer, size, str, len);
  197. assert(ret < size);
  198. vlog.debug("Got clipboard data (%d bytes)", (int)strlen(buffer));
  199. if (!hasFocus()) {
  200. pendingServerCutText = buffer;
  201. return;
  202. }
  203. // RFB doesn't have separate selection and clipboard concepts, so we
  204. // dump the data into both variants.
  205. if (setPrimary)
  206. Fl::copy(buffer, ret, 0);
  207. Fl::copy(buffer, ret, 1);
  208. delete [] buffer;
  209. }
  210. static const char * dotcursor_xpm[] = {
  211. "5 5 2 1",
  212. ". c #000000",
  213. " c #FFFFFF",
  214. " ",
  215. " ... ",
  216. " ... ",
  217. " ... ",
  218. " "};
  219. void Viewport::setCursor(int width, int height, const Point& hotspot,
  220. const rdr::U8* data)
  221. {
  222. int i;
  223. if (cursor) {
  224. if (!cursor->alloc_array)
  225. delete [] cursor->array;
  226. delete cursor;
  227. }
  228. for (i = 0; i < width*height; i++)
  229. if (data[i*4 + 3] != 0) break;
  230. if ((i == width*height) && dotWhenNoCursor) {
  231. vlog.debug("cursor is empty - using dot");
  232. Fl_Pixmap pxm(dotcursor_xpm);
  233. cursor = new Fl_RGB_Image(&pxm);
  234. cursorHotspot.x = cursorHotspot.y = 2;
  235. } else {
  236. if ((width == 0) || (height == 0)) {
  237. U8 *buffer = new U8[4];
  238. memset(buffer, 0, 4);
  239. cursor = new Fl_RGB_Image(buffer, 1, 1, 4);
  240. cursorHotspot.x = cursorHotspot.y = 0;
  241. } else {
  242. U8 *buffer = new U8[width * height * 4];
  243. memcpy(buffer, data, width * height * 4);
  244. cursor = new Fl_RGB_Image(buffer, width, height, 4);
  245. cursorHotspot = hotspot;
  246. }
  247. }
  248. if (Fl::belowmouse() == this)
  249. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  250. }
  251. void Viewport::setLEDState(unsigned int state)
  252. {
  253. vlog.debug("Got server LED state: 0x%08x", state);
  254. // The first message is just considered to be the server announcing
  255. // support for this extension, so start by pushing our state to the
  256. // remote end to get things in sync
  257. if (firstLEDState) {
  258. firstLEDState = false;
  259. pushLEDState();
  260. return;
  261. }
  262. if (!hasFocus())
  263. return;
  264. #if defined(WIN32)
  265. INPUT input[6];
  266. UINT count;
  267. UINT ret;
  268. memset(input, 0, sizeof(input));
  269. count = 0;
  270. if (!!(state & ledCapsLock) != !!(GetKeyState(VK_CAPITAL) & 0x1)) {
  271. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  272. input[count].ki.wVk = input[count+1].ki.wVk = VK_CAPITAL;
  273. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  274. input[count].ki.dwFlags = 0;
  275. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP;
  276. count += 2;
  277. }
  278. if (!!(state & ledNumLock) != !!(GetKeyState(VK_NUMLOCK) & 0x1)) {
  279. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  280. input[count].ki.wVk = input[count+1].ki.wVk = VK_NUMLOCK;
  281. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  282. input[count].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
  283. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY;
  284. count += 2;
  285. }
  286. if (!!(state & ledScrollLock) != !!(GetKeyState(VK_SCROLL) & 0x1)) {
  287. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  288. input[count].ki.wVk = input[count+1].ki.wVk = VK_SCROLL;
  289. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  290. input[count].ki.dwFlags = 0;
  291. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP;
  292. count += 2;
  293. }
  294. if (count == 0)
  295. return;
  296. ret = SendInput(count, input, sizeof(*input));
  297. if (ret < count)
  298. vlog.error(_("Failed to update keyboard LED state: %lu"), GetLastError());
  299. #elif defined(__APPLE__)
  300. int ret;
  301. ret = cocoa_set_caps_lock_state(state & ledCapsLock);
  302. if (ret != 0) {
  303. vlog.error(_("Failed to update keyboard LED state: %d"), ret);
  304. return;
  305. }
  306. ret = cocoa_set_num_lock_state(state & ledNumLock);
  307. if (ret != 0) {
  308. vlog.error(_("Failed to update keyboard LED state: %d"), ret);
  309. return;
  310. }
  311. // No support for Scroll Lock //
  312. #else
  313. unsigned int affect, values;
  314. unsigned int mask;
  315. Bool ret;
  316. affect = values = 0;
  317. affect |= LockMask;
  318. if (state & ledCapsLock)
  319. values |= LockMask;
  320. mask = getModifierMask(XK_Num_Lock);
  321. affect |= mask;
  322. if (state & ledNumLock)
  323. values |= mask;
  324. mask = getModifierMask(XK_Scroll_Lock);
  325. affect |= mask;
  326. if (state & ledScrollLock)
  327. values |= mask;
  328. ret = XkbLockModifiers(fl_display, XkbUseCoreKbd, affect, values);
  329. if (!ret)
  330. vlog.error(_("Failed to update keyboard LED state"));
  331. #endif
  332. }
  333. void Viewport::pushLEDState()
  334. {
  335. unsigned int state;
  336. // Server support?
  337. if (cc->cp.ledState() == ledUnknown)
  338. return;
  339. state = 0;
  340. #if defined(WIN32)
  341. if (GetKeyState(VK_CAPITAL) & 0x1)
  342. state |= ledCapsLock;
  343. if (GetKeyState(VK_NUMLOCK) & 0x1)
  344. state |= ledNumLock;
  345. if (GetKeyState(VK_SCROLL) & 0x1)
  346. state |= ledScrollLock;
  347. #elif defined(__APPLE__)
  348. int ret;
  349. bool on;
  350. ret = cocoa_get_caps_lock_state(&on);
  351. if (ret != 0) {
  352. vlog.error(_("Failed to get keyboard LED state: %d"), ret);
  353. return;
  354. }
  355. if (on)
  356. state |= ledCapsLock;
  357. ret = cocoa_get_num_lock_state(&on);
  358. if (ret != 0) {
  359. vlog.error(_("Failed to get keyboard LED state: %d"), ret);
  360. return;
  361. }
  362. if (on)
  363. state |= ledNumLock;
  364. // No support for Scroll Lock //
  365. state |= (cc->cp.ledState() & ledScrollLock);
  366. #else
  367. unsigned int mask;
  368. Status status;
  369. XkbStateRec xkbState;
  370. status = XkbGetState(fl_display, XkbUseCoreKbd, &xkbState);
  371. if (status != Success) {
  372. vlog.error(_("Failed to get keyboard LED state: %d"), status);
  373. return;
  374. }
  375. if (xkbState.locked_mods & LockMask)
  376. state |= ledCapsLock;
  377. mask = getModifierMask(XK_Num_Lock);
  378. if (xkbState.locked_mods & mask)
  379. state |= ledNumLock;
  380. mask = getModifierMask(XK_Scroll_Lock);
  381. if (xkbState.locked_mods & mask)
  382. state |= ledScrollLock;
  383. #endif
  384. if ((state & ledCapsLock) != (cc->cp.ledState() & ledCapsLock)) {
  385. vlog.debug("Inserting fake CapsLock to get in sync with server");
  386. handleKeyPress(0x3a, XK_Caps_Lock);
  387. handleKeyRelease(0x3a);
  388. }
  389. if ((state & ledNumLock) != (cc->cp.ledState() & ledNumLock)) {
  390. vlog.debug("Inserting fake NumLock to get in sync with server");
  391. handleKeyPress(0x45, XK_Num_Lock);
  392. handleKeyRelease(0x45);
  393. }
  394. if ((state & ledScrollLock) != (cc->cp.ledState() & ledScrollLock)) {
  395. vlog.debug("Inserting fake ScrollLock to get in sync with server");
  396. handleKeyPress(0x46, XK_Scroll_Lock);
  397. handleKeyRelease(0x46);
  398. }
  399. }
  400. void Viewport::draw(Surface* dst)
  401. {
  402. int X, Y, W, H;
  403. // Check what actually needs updating
  404. fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
  405. if ((W == 0) || (H == 0))
  406. return;
  407. frameBuffer->draw(dst, X - x(), Y - y(), X, Y, W, H);
  408. }
  409. void Viewport::draw()
  410. {
  411. int X, Y, W, H;
  412. // Check what actually needs updating
  413. fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
  414. if ((W == 0) || (H == 0))
  415. return;
  416. frameBuffer->draw(X - x(), Y - y(), X, Y, W, H);
  417. }
  418. void Viewport::resize(int x, int y, int w, int h)
  419. {
  420. if ((w != frameBuffer->width()) || (h != frameBuffer->height())) {
  421. vlog.debug("Resizing framebuffer from %dx%d to %dx%d",
  422. frameBuffer->width(), frameBuffer->height(), w, h);
  423. frameBuffer = new PlatformPixelBuffer(w, h);
  424. assert(frameBuffer);
  425. cc->setFramebuffer(frameBuffer);
  426. }
  427. Fl_Widget::resize(x, y, w, h);
  428. }
  429. int Viewport::handle(int event)
  430. {
  431. char *buffer;
  432. int ret;
  433. int buttonMask, wheelMask;
  434. DownMap::const_iterator iter;
  435. switch (event) {
  436. case FL_PASTE:
  437. buffer = new char[Fl::event_length() + 1];
  438. clearPendingClipboard();
  439. // This is documented as to ASCII, but actually does to 8859-1
  440. ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer,
  441. Fl::event_length() + 1);
  442. assert(ret < (Fl::event_length() + 1));
  443. if (!hasFocus()) {
  444. pendingClientCutText = buffer;
  445. return 1;
  446. }
  447. vlog.debug("Sending clipboard data (%d bytes)", (int)strlen(buffer));
  448. try {
  449. cc->writer()->writeClientCutText(buffer, ret);
  450. } catch (rdr::Exception& e) {
  451. vlog.error("%s", e.str());
  452. exit_vncviewer(e.str());
  453. }
  454. delete [] buffer;
  455. return 1;
  456. case FL_ENTER:
  457. if (cursor)
  458. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  459. // Yes, we would like some pointer events please!
  460. return 1;
  461. case FL_LEAVE:
  462. window()->cursor(FL_CURSOR_DEFAULT);
  463. // We want a last move event to help trigger edge stuff
  464. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), 0);
  465. return 1;
  466. case FL_PUSH:
  467. case FL_RELEASE:
  468. case FL_DRAG:
  469. case FL_MOVE:
  470. case FL_MOUSEWHEEL:
  471. buttonMask = 0;
  472. if (Fl::event_button1())
  473. buttonMask |= 1;
  474. if (Fl::event_button2())
  475. buttonMask |= 2;
  476. if (Fl::event_button3())
  477. buttonMask |= 4;
  478. if (event == FL_MOUSEWHEEL) {
  479. wheelMask = 0;
  480. if (Fl::event_dy() < 0)
  481. wheelMask |= 8;
  482. if (Fl::event_dy() > 0)
  483. wheelMask |= 16;
  484. if (Fl::event_dx() < 0)
  485. wheelMask |= 32;
  486. if (Fl::event_dx() > 0)
  487. wheelMask |= 64;
  488. // A quick press of the wheel "button", followed by a immediate
  489. // release below
  490. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()),
  491. buttonMask | wheelMask);
  492. }
  493. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), buttonMask);
  494. return 1;
  495. case FL_FOCUS:
  496. Fl::disable_im();
  497. flushPendingClipboard();
  498. // We may have gotten our lock keys out of sync with the server
  499. // whilst we didn't have focus. Try to sort this out.
  500. pushLEDState();
  501. // Resend Ctrl/Alt if needed
  502. if (menuCtrlKey)
  503. handleKeyPress(0x1d, XK_Control_L);
  504. if (menuAltKey)
  505. handleKeyPress(0x38, XK_Alt_L);
  506. // Yes, we would like some focus please!
  507. return 1;
  508. case FL_UNFOCUS:
  509. // Release all keys that were pressed as that generally makes most
  510. // sense (e.g. Alt+Tab where we only see the Alt press)
  511. while (!downKeySym.empty())
  512. handleKeyRelease(downKeySym.begin()->first);
  513. Fl::enable_im();
  514. return 1;
  515. case FL_KEYDOWN:
  516. case FL_KEYUP:
  517. // Just ignore these as keys were handled in the event handler
  518. return 1;
  519. }
  520. return Fl_Widget::handle(event);
  521. }
  522. bool Viewport::hasFocus()
  523. {
  524. Fl_Widget* focus;
  525. focus = Fl::grab();
  526. if (!focus)
  527. focus = Fl::focus();
  528. return focus == this;
  529. }
  530. #if ! (defined(WIN32) || defined(__APPLE__))
  531. unsigned int Viewport::getModifierMask(unsigned int keysym)
  532. {
  533. XkbDescPtr xkb;
  534. unsigned int mask, keycode;
  535. XkbAction *act;
  536. mask = 0;
  537. xkb = XkbGetMap(fl_display, XkbAllComponentsMask, XkbUseCoreKbd);
  538. if (xkb == NULL)
  539. return 0;
  540. for (keycode = xkb->min_key_code; keycode <= xkb->max_key_code; keycode++) {
  541. unsigned int state_out;
  542. KeySym ks;
  543. XkbTranslateKeyCode(xkb, keycode, 0, &state_out, &ks);
  544. if (ks == NoSymbol)
  545. continue;
  546. if (ks == keysym)
  547. break;
  548. }
  549. // KeySym not mapped?
  550. if (keycode > xkb->max_key_code)
  551. goto out;
  552. act = XkbKeyAction(xkb, keycode, 0);
  553. if (act == NULL)
  554. goto out;
  555. if (act->type != XkbSA_LockMods)
  556. goto out;
  557. if (act->mods.flags & XkbSA_UseModMapMods)
  558. mask = xkb->map->modmap[keycode];
  559. else
  560. mask = act->mods.mask;
  561. out:
  562. XkbFreeKeyboard(xkb, XkbAllComponentsMask, True);
  563. return mask;
  564. }
  565. #endif
  566. void Viewport::handleClipboardChange(int source, void *data)
  567. {
  568. Viewport *self = (Viewport *)data;
  569. assert(self);
  570. if (!sendClipboard)
  571. return;
  572. #if !defined(WIN32) && !defined(__APPLE__)
  573. if (!sendPrimary && (source == 0))
  574. return;
  575. #endif
  576. Fl::paste(*self, source);
  577. }
  578. void Viewport::clearPendingClipboard()
  579. {
  580. delete [] pendingServerCutText;
  581. pendingServerCutText = NULL;
  582. delete [] pendingClientCutText;
  583. pendingClientCutText = NULL;
  584. }
  585. void Viewport::flushPendingClipboard()
  586. {
  587. if (pendingServerCutText) {
  588. size_t len = strlen(pendingServerCutText);
  589. if (setPrimary)
  590. Fl::copy(pendingServerCutText, len, 0);
  591. Fl::copy(pendingServerCutText, len, 1);
  592. }
  593. if (pendingClientCutText) {
  594. size_t len = strlen(pendingClientCutText);
  595. vlog.debug("Sending pending clipboard data (%d bytes)", (int)len);
  596. try {
  597. cc->writer()->writeClientCutText(pendingClientCutText, len);
  598. } catch (rdr::Exception& e) {
  599. vlog.error("%s", e.str());
  600. exit_vncviewer(e.str());
  601. }
  602. }
  603. clearPendingClipboard();
  604. }
  605. void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask)
  606. {
  607. if (!viewOnly) {
  608. if (pointerEventInterval == 0 || buttonMask != lastButtonMask) {
  609. try {
  610. cc->writer()->writePointerEvent(pos, buttonMask);
  611. } catch (rdr::Exception& e) {
  612. vlog.error("%s", e.str());
  613. exit_vncviewer(e.str());
  614. }
  615. } else {
  616. if (!Fl::has_timeout(handlePointerTimeout, this))
  617. Fl::add_timeout((double)pointerEventInterval/1000.0,
  618. handlePointerTimeout, this);
  619. }
  620. lastPointerPos = pos;
  621. lastButtonMask = buttonMask;
  622. }
  623. }
  624. void Viewport::handlePointerTimeout(void *data)
  625. {
  626. Viewport *self = (Viewport *)data;
  627. assert(self);
  628. try {
  629. self->cc->writer()->writePointerEvent(self->lastPointerPos,
  630. self->lastButtonMask);
  631. } catch (rdr::Exception& e) {
  632. vlog.error("%s", e.str());
  633. exit_vncviewer(e.str());
  634. }
  635. }
  636. void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym)
  637. {
  638. static bool menuRecursion = false;
  639. // Prevent recursion if the menu wants to send its own
  640. // activation key.
  641. if (menuKeySym && (keySym == menuKeySym) && !menuRecursion) {
  642. menuRecursion = true;
  643. popupContextMenu();
  644. menuRecursion = false;
  645. return;
  646. }
  647. if (viewOnly)
  648. return;
  649. if (keyCode == 0) {
  650. vlog.error(_("No key code specified on key press"));
  651. return;
  652. }
  653. #ifdef __APPLE__
  654. // Alt on OS X behaves more like AltGr on other systems, and to get
  655. // sane behaviour we should translate things in that manner for the
  656. // remote VNC server. However that means we lose the ability to use
  657. // Alt as a shortcut modifier. Do what RealVNC does and hijack the
  658. // left command key as an Alt replacement.
  659. switch (keySym) {
  660. case XK_Super_L:
  661. keySym = XK_Alt_L;
  662. break;
  663. case XK_Super_R:
  664. keySym = XK_Super_L;
  665. break;
  666. case XK_Alt_L:
  667. keySym = XK_Mode_switch;
  668. break;
  669. case XK_Alt_R:
  670. keySym = XK_ISO_Level3_Shift;
  671. break;
  672. }
  673. #endif
  674. // Because of the way keyboards work, we cannot expect to have the same
  675. // symbol on release as when pressed. This breaks the VNC protocol however,
  676. // so we need to keep track of what keysym a key _code_ generated on press
  677. // and send the same on release.
  678. downKeySym[keyCode] = keySym;
  679. #if defined(WIN32) || defined(__APPLE__)
  680. vlog.debug("Key pressed: 0x%04x => 0x%04x", keyCode, keySym);
  681. #else
  682. vlog.debug("Key pressed: 0x%04x => XK_%s (0x%04x)",
  683. keyCode, XKeysymToString(keySym), keySym);
  684. #endif
  685. try {
  686. // Fake keycode?
  687. if (keyCode > 0xff)
  688. cc->writer()->writeKeyEvent(keySym, 0, true);
  689. else
  690. cc->writer()->writeKeyEvent(keySym, keyCode, true);
  691. } catch (rdr::Exception& e) {
  692. vlog.error("%s", e.str());
  693. exit_vncviewer(e.str());
  694. }
  695. }
  696. void Viewport::handleKeyRelease(int keyCode)
  697. {
  698. DownMap::iterator iter;
  699. if (viewOnly)
  700. return;
  701. iter = downKeySym.find(keyCode);
  702. if (iter == downKeySym.end()) {
  703. // These occur somewhat frequently so let's not spam them unless
  704. // logging is turned up.
  705. vlog.debug("Unexpected release of key code %d", keyCode);
  706. return;
  707. }
  708. #if defined(WIN32) || defined(__APPLE__)
  709. vlog.debug("Key released: 0x%04x => 0x%04x", keyCode, iter->second);
  710. #else
  711. vlog.debug("Key released: 0x%04x => XK_%s (0x%04x)",
  712. keyCode, XKeysymToString(iter->second), iter->second);
  713. #endif
  714. try {
  715. if (keyCode > 0xff)
  716. cc->writer()->writeKeyEvent(iter->second, 0, false);
  717. else
  718. cc->writer()->writeKeyEvent(iter->second, keyCode, false);
  719. } catch (rdr::Exception& e) {
  720. vlog.error("%s", e.str());
  721. exit_vncviewer(e.str());
  722. }
  723. downKeySym.erase(iter);
  724. }
  725. int Viewport::handleSystemEvent(void *event, void *data)
  726. {
  727. Viewport *self = (Viewport *)data;
  728. assert(self);
  729. if (!self->hasFocus())
  730. return 0;
  731. assert(event);
  732. #if defined(WIN32)
  733. MSG *msg = (MSG*)event;
  734. if ((msg->message == WM_KEYDOWN) || (msg->message == WM_SYSKEYDOWN)) {
  735. UINT vKey;
  736. bool isExtended;
  737. int keyCode;
  738. rdr::U32 keySym;
  739. vKey = msg->wParam;
  740. isExtended = (msg->lParam & (1 << 24)) != 0;
  741. keyCode = ((msg->lParam >> 16) & 0xff);
  742. // Windows doesn't have a proper AltGr, but handles it using fake
  743. // Ctrl+Alt. However the remote end might not be Windows, so we need
  744. // to merge those in to a single AltGr event. We detect this case
  745. // by seeing the two key events directly after each other with a very
  746. // short time between them (<50ms) and supress the Ctrl event.
  747. if (self->altGrArmed) {
  748. self->altGrArmed = false;
  749. Fl::remove_timeout(handleAltGrTimeout);
  750. if (isExtended && (keyCode == 0x38) && (vKey == VK_MENU) &&
  751. ((msg->time - self->altGrCtrlTime) < 50)) {
  752. // Alt seen, so this is an AltGr sequence
  753. } else {
  754. // Not Alt, so fire the queued up Ctrl event
  755. self->handleKeyPress(0x1d, XK_Control_L);
  756. }
  757. }
  758. if (keyCode == SCAN_FAKE) {
  759. vlog.debug("Ignoring fake key press (virtual key 0x%02x)", vKey);
  760. return 1;
  761. }
  762. // Windows sets the scan code to 0x00 for multimedia keys, so we
  763. // have to do a reverse lookup based on the vKey.
  764. if (keyCode == 0x00) {
  765. keyCode = MapVirtualKey(vKey, MAPVK_VK_TO_VSC);
  766. if (keyCode == 0x00) {
  767. if (isExtended)
  768. vlog.error(_("No scan code for extended virtual key 0x%02x"), (int)vKey);
  769. else
  770. vlog.error(_("No scan code for virtual key 0x%02x"), (int)vKey);
  771. return 1;
  772. }
  773. }
  774. if (keyCode & ~0x7f) {
  775. vlog.error(_("Invalid scan code 0x%02x"), (int)keyCode);
  776. return 1;
  777. }
  778. if (isExtended)
  779. keyCode |= 0x80;
  780. // Fortunately RFB and Windows use the same scan code set (mostly),
  781. // so there is no conversion needed
  782. // (as long as we encode the extended keys with the high bit)
  783. // However Pause sends a code that conflicts with NumLock, so use
  784. // the code most RFB implementations use (part of the sequence for
  785. // Ctrl+Pause, i.e. Break)
  786. if (keyCode == 0x45)
  787. keyCode = 0xc6;
  788. // And NumLock incorrectly has the extended bit set
  789. if (keyCode == 0xc5)
  790. keyCode = 0x45;
  791. // And Alt+PrintScreen (i.e. SysRq) sends a different code than
  792. // PrintScreen
  793. if (keyCode == 0xb7)
  794. keyCode = 0x54;
  795. keySym = win32_vkey_to_keysym(vKey, isExtended);
  796. if (keySym == NoSymbol) {
  797. if (isExtended)
  798. vlog.error(_("No symbol for extended virtual key 0x%02x"), (int)vKey);
  799. else
  800. vlog.error(_("No symbol for virtual key 0x%02x"), (int)vKey);
  801. }
  802. // Windows sends the same vKey for both shifts, so we need to look
  803. // at the scan code to tell them apart
  804. if ((keySym == XK_Shift_L) && (keyCode == 0x36))
  805. keySym = XK_Shift_R;
  806. // AltGr handling (see above)
  807. if (win32_has_altgr()) {
  808. if ((keyCode == 0xb8) && (keySym == XK_Alt_R))
  809. keySym = XK_ISO_Level3_Shift;
  810. // Possible start of AltGr sequence?
  811. if ((keyCode == 0x1d) && (keySym == XK_Control_L)) {
  812. self->altGrArmed = true;
  813. self->altGrCtrlTime = msg->time;
  814. Fl::add_timeout(0.1, handleAltGrTimeout, self);
  815. return 1;
  816. }
  817. }
  818. self->handleKeyPress(keyCode, keySym);
  819. return 1;
  820. } else if ((msg->message == WM_KEYUP) || (msg->message == WM_SYSKEYUP)) {
  821. UINT vKey;
  822. bool isExtended;
  823. int keyCode;
  824. vKey = msg->wParam;
  825. isExtended = (msg->lParam & (1 << 24)) != 0;
  826. keyCode = ((msg->lParam >> 16) & 0xff);
  827. // We can't get a release in the middle of an AltGr sequence, so
  828. // abort that detection
  829. if (self->altGrArmed) {
  830. self->altGrArmed = false;
  831. Fl::remove_timeout(handleAltGrTimeout);
  832. self->handleKeyPress(0x1d, XK_Control_L);
  833. }
  834. if (keyCode == SCAN_FAKE) {
  835. vlog.debug("Ignoring fake key release (virtual key 0x%02x)", vKey);
  836. return 1;
  837. }
  838. if (keyCode == 0x00)
  839. keyCode = MapVirtualKey(vKey, MAPVK_VK_TO_VSC);
  840. if (isExtended)
  841. keyCode |= 0x80;
  842. if (keyCode == 0x45)
  843. keyCode = 0xc6;
  844. if (keyCode == 0xc5)
  845. keyCode = 0x45;
  846. if (keyCode == 0xb7)
  847. keyCode = 0x54;
  848. self->handleKeyRelease(keyCode);
  849. // Windows has a rather nasty bug where it won't send key release
  850. // events for a Shift button if the other Shift is still pressed
  851. if ((keyCode == 0x2a) || (keyCode == 0x36)) {
  852. if (self->downKeySym.count(0x2a))
  853. self->handleKeyRelease(0x2a);
  854. if (self->downKeySym.count(0x36))
  855. self->handleKeyRelease(0x36);
  856. }
  857. return 1;
  858. }
  859. #elif defined(__APPLE__)
  860. if (cocoa_is_keyboard_event(event)) {
  861. int keyCode;
  862. keyCode = cocoa_event_keycode(event);
  863. if ((unsigned)keyCode >= code_map_osx_to_qnum_len)
  864. keyCode = 0;
  865. else
  866. keyCode = code_map_osx_to_qnum[keyCode];
  867. if (cocoa_is_key_press(event)) {
  868. rdr::U32 keySym;
  869. keySym = cocoa_event_keysym(event);
  870. if (keySym == NoSymbol) {
  871. vlog.error(_("No symbol for key code 0x%02x (in the current state)"),
  872. (int)keyCode);
  873. }
  874. self->handleKeyPress(keyCode, keySym);
  875. // We don't get any release events for CapsLock, so we have to
  876. // send the release right away.
  877. if (keySym == XK_Caps_Lock)
  878. self->handleKeyRelease(keyCode);
  879. } else {
  880. self->handleKeyRelease(keyCode);
  881. }
  882. return 1;
  883. }
  884. #else
  885. XEvent *xevent = (XEvent*)event;
  886. if (xevent->type == KeyPress) {
  887. int keycode;
  888. char str;
  889. KeySym keysym;
  890. keycode = code_map_keycode_to_qnum[xevent->xkey.keycode];
  891. // Generate a fake keycode just for tracking if we can't figure
  892. // out the proper one
  893. if (keycode == 0)
  894. keycode = 0x100 | xevent->xkey.keycode;
  895. XLookupString(&xevent->xkey, &str, 1, &keysym, NULL);
  896. if (keysym == NoSymbol) {
  897. vlog.error(_("No symbol for key code %d (in the current state)"),
  898. (int)xevent->xkey.keycode);
  899. }
  900. switch (keysym) {
  901. // For the first few years, there wasn't a good consensus on what the
  902. // Windows keys should be mapped to for X11. So we need to help out a
  903. // bit and map all variants to the same key...
  904. case XK_Hyper_L:
  905. keysym = XK_Super_L;
  906. break;
  907. case XK_Hyper_R:
  908. keysym = XK_Super_R;
  909. break;
  910. // There has been several variants for Shift-Tab over the years.
  911. // RFB states that we should always send a normal tab.
  912. case XK_ISO_Left_Tab:
  913. keysym = XK_Tab;
  914. break;
  915. }
  916. self->handleKeyPress(keycode, keysym);
  917. return 1;
  918. } else if (xevent->type == KeyRelease) {
  919. int keycode = code_map_keycode_to_qnum[xevent->xkey.keycode];
  920. if (keycode == 0)
  921. keycode = 0x100 | xevent->xkey.keycode;
  922. self->handleKeyRelease(keycode);
  923. return 1;
  924. }
  925. #endif
  926. return 0;
  927. }
  928. #ifdef WIN32
  929. void Viewport::handleAltGrTimeout(void *data)
  930. {
  931. Viewport *self = (Viewport *)data;
  932. assert(self);
  933. self->altGrArmed = false;
  934. self->handleKeyPress(0x1d, XK_Control_L);
  935. }
  936. #endif
  937. void Viewport::initContextMenu()
  938. {
  939. contextMenu->clear();
  940. fltk_menu_add(contextMenu, p_("ContextMenu|", "E&xit viewer"),
  941. 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER);
  942. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Full screen"),
  943. 0, NULL, (void*)ID_FULLSCREEN,
  944. FL_MENU_TOGGLE | (window()->fullscreen_active()?FL_MENU_VALUE:0));
  945. fltk_menu_add(contextMenu, p_("ContextMenu|", "Minimi&ze"),
  946. 0, NULL, (void*)ID_MINIMIZE, 0);
  947. fltk_menu_add(contextMenu, p_("ContextMenu|", "Resize &window to session"),
  948. 0, NULL, (void*)ID_RESIZE,
  949. (window()->fullscreen_active()?FL_MENU_INACTIVE:0) |
  950. FL_MENU_DIVIDER);
  951. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Ctrl"),
  952. 0, NULL, (void*)ID_CTRL,
  953. FL_MENU_TOGGLE | (menuCtrlKey?FL_MENU_VALUE:0));
  954. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Alt"),
  955. 0, NULL, (void*)ID_ALT,
  956. FL_MENU_TOGGLE | (menuAltKey?FL_MENU_VALUE:0));
  957. if (menuKeySym) {
  958. char sendMenuKey[64];
  959. snprintf(sendMenuKey, 64, p_("ContextMenu|", "Send %s"), (const char *)menuKey);
  960. fltk_menu_add(contextMenu, sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0);
  961. fltk_menu_add(contextMenu, "Secret shortcut menu key", menuKeyFLTK, NULL,
  962. (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
  963. }
  964. fltk_menu_add(contextMenu, p_("ContextMenu|", "Send Ctrl-Alt-&Del"),
  965. 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
  966. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Refresh screen"),
  967. 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER);
  968. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Options..."),
  969. 0, NULL, (void*)ID_OPTIONS, 0);
  970. fltk_menu_add(contextMenu, p_("ContextMenu|", "Connection &info..."),
  971. 0, NULL, (void*)ID_INFO, 0);
  972. fltk_menu_add(contextMenu, p_("ContextMenu|", "About &TigerVNC viewer..."),
  973. 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER);
  974. fltk_menu_add(contextMenu, p_("ContextMenu|", "Dismiss &menu"),
  975. 0, NULL, (void*)ID_DISMISS, 0);
  976. }
  977. void Viewport::popupContextMenu()
  978. {
  979. const Fl_Menu_Item *m;
  980. char buffer[1024];
  981. // Make sure the menu is reset to its initial state between goes or
  982. // it will start up highlighting the previously selected entry.
  983. contextMenu->value(-1);
  984. // initialize context menu before display
  985. initContextMenu();
  986. // Unfortunately FLTK doesn't reliably restore the mouse pointer for
  987. // menus, so we have to help it out.
  988. if (Fl::belowmouse() == this)
  989. window()->cursor(FL_CURSOR_DEFAULT);
  990. // FLTK also doesn't switch focus properly for menus
  991. handle(FL_UNFOCUS);
  992. m = contextMenu->popup();
  993. handle(FL_FOCUS);
  994. // Back to our proper mouse pointer.
  995. if ((Fl::belowmouse() == this) && cursor)
  996. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  997. if (m == NULL)
  998. return;
  999. switch (m->argument()) {
  1000. case ID_EXIT:
  1001. exit_vncviewer();
  1002. break;
  1003. case ID_FULLSCREEN:
  1004. if (window()->fullscreen_active())
  1005. window()->fullscreen_off();
  1006. else
  1007. ((DesktopWindow*)window())->fullscreen_on();
  1008. break;
  1009. case ID_MINIMIZE:
  1010. window()->iconize();
  1011. break;
  1012. case ID_RESIZE:
  1013. if (window()->fullscreen_active())
  1014. break;
  1015. window()->size(w(), h());
  1016. break;
  1017. case ID_CTRL:
  1018. if (m->value())
  1019. handleKeyPress(0x1d, XK_Control_L);
  1020. else
  1021. handleKeyRelease(0x1d);
  1022. menuCtrlKey = !menuCtrlKey;
  1023. break;
  1024. case ID_ALT:
  1025. if (m->value())
  1026. handleKeyPress(0x38, XK_Alt_L);
  1027. else
  1028. handleKeyRelease(0x38);
  1029. menuAltKey = !menuAltKey;
  1030. break;
  1031. case ID_MENUKEY:
  1032. handleKeyPress(menuKeyCode, menuKeySym);
  1033. handleKeyRelease(menuKeyCode);
  1034. break;
  1035. case ID_CTRLALTDEL:
  1036. handleKeyPress(0x1d, XK_Control_L);
  1037. handleKeyPress(0x38, XK_Alt_L);
  1038. handleKeyPress(0xd3, XK_Delete);
  1039. handleKeyRelease(0xd3);
  1040. handleKeyRelease(0x38);
  1041. handleKeyRelease(0x1d);
  1042. break;
  1043. case ID_REFRESH:
  1044. cc->refreshFramebuffer();
  1045. break;
  1046. case ID_OPTIONS:
  1047. OptionsDialog::showDialog();
  1048. break;
  1049. case ID_INFO:
  1050. if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < sizeof(buffer)) {
  1051. fl_message_title(_("VNC connection info"));
  1052. fl_message("%s", buffer);
  1053. }
  1054. break;
  1055. case ID_ABOUT:
  1056. about_vncviewer();
  1057. break;
  1058. case ID_DISMISS:
  1059. // Don't need to do anything
  1060. break;
  1061. }
  1062. }
  1063. void Viewport::setMenuKey()
  1064. {
  1065. getMenuKey(&menuKeyFLTK, &menuKeyCode, &menuKeySym);
  1066. }
  1067. void Viewport::handleOptions(void *data)
  1068. {
  1069. Viewport *self = (Viewport*)data;
  1070. self->setMenuKey();
  1071. }