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.

Viewport.cxx 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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 !defined(WIN32) && !defined(__APPLE__)
  206. if (setPrimary)
  207. Fl::copy(buffer, ret, 0);
  208. #endif
  209. Fl::copy(buffer, ret, 1);
  210. delete [] buffer;
  211. }
  212. static const char * dotcursor_xpm[] = {
  213. "5 5 2 1",
  214. ". c #000000",
  215. " c #FFFFFF",
  216. " ",
  217. " ... ",
  218. " ... ",
  219. " ... ",
  220. " "};
  221. void Viewport::setCursor(int width, int height, const Point& hotspot,
  222. const rdr::U8* data)
  223. {
  224. int i;
  225. if (cursor) {
  226. if (!cursor->alloc_array)
  227. delete [] cursor->array;
  228. delete cursor;
  229. }
  230. for (i = 0; i < width*height; i++)
  231. if (data[i*4 + 3] != 0) break;
  232. if ((i == width*height) && dotWhenNoCursor) {
  233. vlog.debug("cursor is empty - using dot");
  234. Fl_Pixmap pxm(dotcursor_xpm);
  235. cursor = new Fl_RGB_Image(&pxm);
  236. cursorHotspot.x = cursorHotspot.y = 2;
  237. } else {
  238. if ((width == 0) || (height == 0)) {
  239. U8 *buffer = new U8[4];
  240. memset(buffer, 0, 4);
  241. cursor = new Fl_RGB_Image(buffer, 1, 1, 4);
  242. cursorHotspot.x = cursorHotspot.y = 0;
  243. } else {
  244. U8 *buffer = new U8[width * height * 4];
  245. memcpy(buffer, data, width * height * 4);
  246. cursor = new Fl_RGB_Image(buffer, width, height, 4);
  247. cursorHotspot = hotspot;
  248. }
  249. }
  250. if (Fl::belowmouse() == this)
  251. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  252. }
  253. void Viewport::setLEDState(unsigned int state)
  254. {
  255. vlog.debug("Got server LED state: 0x%08x", state);
  256. // The first message is just considered to be the server announcing
  257. // support for this extension. We will push our state to sync up the
  258. // server when we get focus. If we already have focus we need to push
  259. // it here though.
  260. if (firstLEDState) {
  261. firstLEDState = false;
  262. if (hasFocus())
  263. pushLEDState();
  264. return;
  265. }
  266. if (!hasFocus())
  267. return;
  268. #if defined(WIN32)
  269. INPUT input[6];
  270. UINT count;
  271. UINT ret;
  272. memset(input, 0, sizeof(input));
  273. count = 0;
  274. if (!!(state & ledCapsLock) != !!(GetKeyState(VK_CAPITAL) & 0x1)) {
  275. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  276. input[count].ki.wVk = input[count+1].ki.wVk = VK_CAPITAL;
  277. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  278. input[count].ki.dwFlags = 0;
  279. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP;
  280. count += 2;
  281. }
  282. if (!!(state & ledNumLock) != !!(GetKeyState(VK_NUMLOCK) & 0x1)) {
  283. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  284. input[count].ki.wVk = input[count+1].ki.wVk = VK_NUMLOCK;
  285. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  286. input[count].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
  287. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY;
  288. count += 2;
  289. }
  290. if (!!(state & ledScrollLock) != !!(GetKeyState(VK_SCROLL) & 0x1)) {
  291. input[count].type = input[count+1].type = INPUT_KEYBOARD;
  292. input[count].ki.wVk = input[count+1].ki.wVk = VK_SCROLL;
  293. input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE;
  294. input[count].ki.dwFlags = 0;
  295. input[count+1].ki.dwFlags = KEYEVENTF_KEYUP;
  296. count += 2;
  297. }
  298. if (count == 0)
  299. return;
  300. ret = SendInput(count, input, sizeof(*input));
  301. if (ret < count)
  302. vlog.error(_("Failed to update keyboard LED state: %lu"), GetLastError());
  303. #elif defined(__APPLE__)
  304. int ret;
  305. ret = cocoa_set_caps_lock_state(state & ledCapsLock);
  306. if (ret != 0) {
  307. vlog.error(_("Failed to update keyboard LED state: %d"), ret);
  308. return;
  309. }
  310. ret = cocoa_set_num_lock_state(state & ledNumLock);
  311. if (ret != 0) {
  312. vlog.error(_("Failed to update keyboard LED state: %d"), ret);
  313. return;
  314. }
  315. // No support for Scroll Lock //
  316. #else
  317. unsigned int affect, values;
  318. unsigned int mask;
  319. Bool ret;
  320. affect = values = 0;
  321. affect |= LockMask;
  322. if (state & ledCapsLock)
  323. values |= LockMask;
  324. mask = getModifierMask(XK_Num_Lock);
  325. affect |= mask;
  326. if (state & ledNumLock)
  327. values |= mask;
  328. mask = getModifierMask(XK_Scroll_Lock);
  329. affect |= mask;
  330. if (state & ledScrollLock)
  331. values |= mask;
  332. ret = XkbLockModifiers(fl_display, XkbUseCoreKbd, affect, values);
  333. if (!ret)
  334. vlog.error(_("Failed to update keyboard LED state"));
  335. #endif
  336. }
  337. void Viewport::pushLEDState()
  338. {
  339. unsigned int state;
  340. // Server support?
  341. if (cc->server.ledState() == ledUnknown)
  342. return;
  343. state = 0;
  344. #if defined(WIN32)
  345. if (GetKeyState(VK_CAPITAL) & 0x1)
  346. state |= ledCapsLock;
  347. if (GetKeyState(VK_NUMLOCK) & 0x1)
  348. state |= ledNumLock;
  349. if (GetKeyState(VK_SCROLL) & 0x1)
  350. state |= ledScrollLock;
  351. #elif defined(__APPLE__)
  352. int ret;
  353. bool on;
  354. ret = cocoa_get_caps_lock_state(&on);
  355. if (ret != 0) {
  356. vlog.error(_("Failed to get keyboard LED state: %d"), ret);
  357. return;
  358. }
  359. if (on)
  360. state |= ledCapsLock;
  361. ret = cocoa_get_num_lock_state(&on);
  362. if (ret != 0) {
  363. vlog.error(_("Failed to get keyboard LED state: %d"), ret);
  364. return;
  365. }
  366. if (on)
  367. state |= ledNumLock;
  368. // No support for Scroll Lock //
  369. state |= (cc->server.ledState() & ledScrollLock);
  370. #else
  371. unsigned int mask;
  372. Status status;
  373. XkbStateRec xkbState;
  374. status = XkbGetState(fl_display, XkbUseCoreKbd, &xkbState);
  375. if (status != Success) {
  376. vlog.error(_("Failed to get keyboard LED state: %d"), status);
  377. return;
  378. }
  379. if (xkbState.locked_mods & LockMask)
  380. state |= ledCapsLock;
  381. mask = getModifierMask(XK_Num_Lock);
  382. if (xkbState.locked_mods & mask)
  383. state |= ledNumLock;
  384. mask = getModifierMask(XK_Scroll_Lock);
  385. if (xkbState.locked_mods & mask)
  386. state |= ledScrollLock;
  387. #endif
  388. if ((state & ledCapsLock) != (cc->server.ledState() & ledCapsLock)) {
  389. vlog.debug("Inserting fake CapsLock to get in sync with server");
  390. handleKeyPress(0x3a, XK_Caps_Lock);
  391. handleKeyRelease(0x3a);
  392. }
  393. if ((state & ledNumLock) != (cc->server.ledState() & ledNumLock)) {
  394. vlog.debug("Inserting fake NumLock to get in sync with server");
  395. handleKeyPress(0x45, XK_Num_Lock);
  396. handleKeyRelease(0x45);
  397. }
  398. if ((state & ledScrollLock) != (cc->server.ledState() & ledScrollLock)) {
  399. vlog.debug("Inserting fake ScrollLock to get in sync with server");
  400. handleKeyPress(0x46, XK_Scroll_Lock);
  401. handleKeyRelease(0x46);
  402. }
  403. }
  404. void Viewport::draw(Surface* dst)
  405. {
  406. int X, Y, W, H;
  407. // Check what actually needs updating
  408. fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
  409. if ((W == 0) || (H == 0))
  410. return;
  411. frameBuffer->draw(dst, X - x(), Y - y(), X, Y, W, H);
  412. }
  413. void Viewport::draw()
  414. {
  415. int X, Y, W, H;
  416. // Check what actually needs updating
  417. fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
  418. if ((W == 0) || (H == 0))
  419. return;
  420. frameBuffer->draw(X - x(), Y - y(), X, Y, W, H);
  421. }
  422. void Viewport::resize(int x, int y, int w, int h)
  423. {
  424. if ((w != frameBuffer->width()) || (h != frameBuffer->height())) {
  425. vlog.debug("Resizing framebuffer from %dx%d to %dx%d",
  426. frameBuffer->width(), frameBuffer->height(), w, h);
  427. frameBuffer = new PlatformPixelBuffer(w, h);
  428. assert(frameBuffer);
  429. cc->setFramebuffer(frameBuffer);
  430. }
  431. Fl_Widget::resize(x, y, w, h);
  432. }
  433. int Viewport::handle(int event)
  434. {
  435. char *buffer;
  436. int ret;
  437. int buttonMask, wheelMask;
  438. DownMap::const_iterator iter;
  439. switch (event) {
  440. case FL_PASTE:
  441. buffer = new char[Fl::event_length() + 1];
  442. clearPendingClipboard();
  443. // This is documented as to ASCII, but actually does to 8859-1
  444. ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer,
  445. Fl::event_length() + 1);
  446. assert(ret < (Fl::event_length() + 1));
  447. if (!hasFocus()) {
  448. pendingClientCutText = buffer;
  449. return 1;
  450. }
  451. vlog.debug("Sending clipboard data (%d bytes)", (int)strlen(buffer));
  452. try {
  453. cc->writer()->writeClientCutText(buffer, ret);
  454. } catch (rdr::Exception& e) {
  455. vlog.error("%s", e.str());
  456. exit_vncviewer(e.str());
  457. }
  458. delete [] buffer;
  459. return 1;
  460. case FL_ENTER:
  461. if (cursor)
  462. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  463. // Yes, we would like some pointer events please!
  464. return 1;
  465. case FL_LEAVE:
  466. window()->cursor(FL_CURSOR_DEFAULT);
  467. // We want a last move event to help trigger edge stuff
  468. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), 0);
  469. return 1;
  470. case FL_PUSH:
  471. case FL_RELEASE:
  472. case FL_DRAG:
  473. case FL_MOVE:
  474. case FL_MOUSEWHEEL:
  475. buttonMask = 0;
  476. if (Fl::event_button1())
  477. buttonMask |= 1;
  478. if (Fl::event_button2())
  479. buttonMask |= 2;
  480. if (Fl::event_button3())
  481. buttonMask |= 4;
  482. if (event == FL_MOUSEWHEEL) {
  483. wheelMask = 0;
  484. if (Fl::event_dy() < 0)
  485. wheelMask |= 8;
  486. if (Fl::event_dy() > 0)
  487. wheelMask |= 16;
  488. if (Fl::event_dx() < 0)
  489. wheelMask |= 32;
  490. if (Fl::event_dx() > 0)
  491. wheelMask |= 64;
  492. // A quick press of the wheel "button", followed by a immediate
  493. // release below
  494. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()),
  495. buttonMask | wheelMask);
  496. }
  497. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), buttonMask);
  498. return 1;
  499. case FL_FOCUS:
  500. Fl::disable_im();
  501. flushPendingClipboard();
  502. // We may have gotten our lock keys out of sync with the server
  503. // whilst we didn't have focus. Try to sort this out.
  504. pushLEDState();
  505. // Resend Ctrl/Alt if needed
  506. if (menuCtrlKey)
  507. handleKeyPress(0x1d, XK_Control_L);
  508. if (menuAltKey)
  509. handleKeyPress(0x38, XK_Alt_L);
  510. // Yes, we would like some focus please!
  511. return 1;
  512. case FL_UNFOCUS:
  513. // Release all keys that were pressed as that generally makes most
  514. // sense (e.g. Alt+Tab where we only see the Alt press)
  515. while (!downKeySym.empty())
  516. handleKeyRelease(downKeySym.begin()->first);
  517. Fl::enable_im();
  518. return 1;
  519. case FL_KEYDOWN:
  520. case FL_KEYUP:
  521. // Just ignore these as keys were handled in the event handler
  522. return 1;
  523. }
  524. return Fl_Widget::handle(event);
  525. }
  526. bool Viewport::hasFocus()
  527. {
  528. Fl_Widget* focus;
  529. focus = Fl::grab();
  530. if (!focus)
  531. focus = Fl::focus();
  532. return focus == this;
  533. }
  534. #if ! (defined(WIN32) || defined(__APPLE__))
  535. unsigned int Viewport::getModifierMask(unsigned int keysym)
  536. {
  537. XkbDescPtr xkb;
  538. unsigned int mask, keycode;
  539. XkbAction *act;
  540. mask = 0;
  541. xkb = XkbGetMap(fl_display, XkbAllComponentsMask, XkbUseCoreKbd);
  542. if (xkb == NULL)
  543. return 0;
  544. for (keycode = xkb->min_key_code; keycode <= xkb->max_key_code; keycode++) {
  545. unsigned int state_out;
  546. KeySym ks;
  547. XkbTranslateKeyCode(xkb, keycode, 0, &state_out, &ks);
  548. if (ks == NoSymbol)
  549. continue;
  550. if (ks == keysym)
  551. break;
  552. }
  553. // KeySym not mapped?
  554. if (keycode > xkb->max_key_code)
  555. goto out;
  556. act = XkbKeyAction(xkb, keycode, 0);
  557. if (act == NULL)
  558. goto out;
  559. if (act->type != XkbSA_LockMods)
  560. goto out;
  561. if (act->mods.flags & XkbSA_UseModMapMods)
  562. mask = xkb->map->modmap[keycode];
  563. else
  564. mask = act->mods.mask;
  565. out:
  566. XkbFreeKeyboard(xkb, XkbAllComponentsMask, True);
  567. return mask;
  568. }
  569. #endif
  570. void Viewport::handleClipboardChange(int source, void *data)
  571. {
  572. Viewport *self = (Viewport *)data;
  573. assert(self);
  574. if (!sendClipboard)
  575. return;
  576. #if !defined(WIN32) && !defined(__APPLE__)
  577. if (!sendPrimary && (source == 0))
  578. return;
  579. #endif
  580. Fl::paste(*self, source);
  581. }
  582. void Viewport::clearPendingClipboard()
  583. {
  584. delete [] pendingServerCutText;
  585. pendingServerCutText = NULL;
  586. delete [] pendingClientCutText;
  587. pendingClientCutText = NULL;
  588. }
  589. void Viewport::flushPendingClipboard()
  590. {
  591. if (pendingServerCutText) {
  592. size_t len = strlen(pendingServerCutText);
  593. #if !defined(WIN32) && !defined(__APPLE__)
  594. if (setPrimary)
  595. Fl::copy(pendingServerCutText, len, 0);
  596. #endif
  597. Fl::copy(pendingServerCutText, len, 1);
  598. }
  599. if (pendingClientCutText) {
  600. size_t len = strlen(pendingClientCutText);
  601. vlog.debug("Sending pending clipboard data (%d bytes)", (int)len);
  602. try {
  603. cc->writer()->writeClientCutText(pendingClientCutText, len);
  604. } catch (rdr::Exception& e) {
  605. vlog.error("%s", e.str());
  606. exit_vncviewer(e.str());
  607. }
  608. }
  609. clearPendingClipboard();
  610. }
  611. void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask)
  612. {
  613. if (!viewOnly) {
  614. if (pointerEventInterval == 0 || buttonMask != lastButtonMask) {
  615. try {
  616. cc->writer()->writePointerEvent(pos, buttonMask);
  617. } catch (rdr::Exception& e) {
  618. vlog.error("%s", e.str());
  619. exit_vncviewer(e.str());
  620. }
  621. } else {
  622. if (!Fl::has_timeout(handlePointerTimeout, this))
  623. Fl::add_timeout((double)pointerEventInterval/1000.0,
  624. handlePointerTimeout, this);
  625. }
  626. lastPointerPos = pos;
  627. lastButtonMask = buttonMask;
  628. }
  629. }
  630. void Viewport::handlePointerTimeout(void *data)
  631. {
  632. Viewport *self = (Viewport *)data;
  633. assert(self);
  634. try {
  635. self->cc->writer()->writePointerEvent(self->lastPointerPos,
  636. self->lastButtonMask);
  637. } catch (rdr::Exception& e) {
  638. vlog.error("%s", e.str());
  639. exit_vncviewer(e.str());
  640. }
  641. }
  642. void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym)
  643. {
  644. static bool menuRecursion = false;
  645. // Prevent recursion if the menu wants to send its own
  646. // activation key.
  647. if (menuKeySym && (keySym == menuKeySym) && !menuRecursion) {
  648. menuRecursion = true;
  649. popupContextMenu();
  650. menuRecursion = false;
  651. return;
  652. }
  653. if (viewOnly)
  654. return;
  655. if (keyCode == 0) {
  656. vlog.error(_("No key code specified on key press"));
  657. return;
  658. }
  659. #ifdef __APPLE__
  660. // Alt on OS X behaves more like AltGr on other systems, and to get
  661. // sane behaviour we should translate things in that manner for the
  662. // remote VNC server. However that means we lose the ability to use
  663. // Alt as a shortcut modifier. Do what RealVNC does and hijack the
  664. // left command key as an Alt replacement.
  665. switch (keySym) {
  666. case XK_Super_L:
  667. keySym = XK_Alt_L;
  668. break;
  669. case XK_Super_R:
  670. keySym = XK_Super_L;
  671. break;
  672. case XK_Alt_L:
  673. keySym = XK_Mode_switch;
  674. break;
  675. case XK_Alt_R:
  676. keySym = XK_ISO_Level3_Shift;
  677. break;
  678. }
  679. #endif
  680. // Because of the way keyboards work, we cannot expect to have the same
  681. // symbol on release as when pressed. This breaks the VNC protocol however,
  682. // so we need to keep track of what keysym a key _code_ generated on press
  683. // and send the same on release.
  684. downKeySym[keyCode] = keySym;
  685. #if defined(WIN32) || defined(__APPLE__)
  686. vlog.debug("Key pressed: 0x%04x => 0x%04x", keyCode, keySym);
  687. #else
  688. vlog.debug("Key pressed: 0x%04x => XK_%s (0x%04x)",
  689. keyCode, XKeysymToString(keySym), keySym);
  690. #endif
  691. try {
  692. // Fake keycode?
  693. if (keyCode > 0xff)
  694. cc->writer()->writeKeyEvent(keySym, 0, true);
  695. else
  696. cc->writer()->writeKeyEvent(keySym, keyCode, true);
  697. } catch (rdr::Exception& e) {
  698. vlog.error("%s", e.str());
  699. exit_vncviewer(e.str());
  700. }
  701. }
  702. void Viewport::handleKeyRelease(int keyCode)
  703. {
  704. DownMap::iterator iter;
  705. if (viewOnly)
  706. return;
  707. iter = downKeySym.find(keyCode);
  708. if (iter == downKeySym.end()) {
  709. // These occur somewhat frequently so let's not spam them unless
  710. // logging is turned up.
  711. vlog.debug("Unexpected release of key code %d", keyCode);
  712. return;
  713. }
  714. #if defined(WIN32) || defined(__APPLE__)
  715. vlog.debug("Key released: 0x%04x => 0x%04x", keyCode, iter->second);
  716. #else
  717. vlog.debug("Key released: 0x%04x => XK_%s (0x%04x)",
  718. keyCode, XKeysymToString(iter->second), iter->second);
  719. #endif
  720. try {
  721. if (keyCode > 0xff)
  722. cc->writer()->writeKeyEvent(iter->second, 0, false);
  723. else
  724. cc->writer()->writeKeyEvent(iter->second, keyCode, false);
  725. } catch (rdr::Exception& e) {
  726. vlog.error("%s", e.str());
  727. exit_vncviewer(e.str());
  728. }
  729. downKeySym.erase(iter);
  730. }
  731. int Viewport::handleSystemEvent(void *event, void *data)
  732. {
  733. Viewport *self = (Viewport *)data;
  734. assert(self);
  735. if (!self->hasFocus())
  736. return 0;
  737. assert(event);
  738. #if defined(WIN32)
  739. MSG *msg = (MSG*)event;
  740. if ((msg->message == WM_KEYDOWN) || (msg->message == WM_SYSKEYDOWN)) {
  741. UINT vKey;
  742. bool isExtended;
  743. int keyCode;
  744. rdr::U32 keySym;
  745. vKey = msg->wParam;
  746. isExtended = (msg->lParam & (1 << 24)) != 0;
  747. keyCode = ((msg->lParam >> 16) & 0xff);
  748. // Windows' touch keyboard doesn't set a scan code for the Alt
  749. // portion of the AltGr sequence, so we need to help it out
  750. if (!isExtended && (keyCode == 0x00) && (vKey == VK_MENU)) {
  751. isExtended = true;
  752. keyCode = 0x38;
  753. }
  754. // Windows doesn't have a proper AltGr, but handles it using fake
  755. // Ctrl+Alt. However the remote end might not be Windows, so we need
  756. // to merge those in to a single AltGr event. We detect this case
  757. // by seeing the two key events directly after each other with a very
  758. // short time between them (<50ms) and supress the Ctrl event.
  759. if (self->altGrArmed) {
  760. self->altGrArmed = false;
  761. Fl::remove_timeout(handleAltGrTimeout);
  762. if (isExtended && (keyCode == 0x38) && (vKey == VK_MENU) &&
  763. ((msg->time - self->altGrCtrlTime) < 50)) {
  764. // Alt seen, so this is an AltGr sequence
  765. } else {
  766. // Not Alt, so fire the queued up Ctrl event
  767. self->handleKeyPress(0x1d, XK_Control_L);
  768. }
  769. }
  770. if (keyCode == SCAN_FAKE) {
  771. vlog.debug("Ignoring fake key press (virtual key 0x%02x)", vKey);
  772. return 1;
  773. }
  774. // Windows sets the scan code to 0x00 for multimedia keys, so we
  775. // have to do a reverse lookup based on the vKey.
  776. if (keyCode == 0x00) {
  777. keyCode = MapVirtualKey(vKey, MAPVK_VK_TO_VSC);
  778. if (keyCode == 0x00) {
  779. if (isExtended)
  780. vlog.error(_("No scan code for extended virtual key 0x%02x"), (int)vKey);
  781. else
  782. vlog.error(_("No scan code for virtual key 0x%02x"), (int)vKey);
  783. return 1;
  784. }
  785. }
  786. if (keyCode & ~0x7f) {
  787. vlog.error(_("Invalid scan code 0x%02x"), (int)keyCode);
  788. return 1;
  789. }
  790. if (isExtended)
  791. keyCode |= 0x80;
  792. // Fortunately RFB and Windows use the same scan code set (mostly),
  793. // so there is no conversion needed
  794. // (as long as we encode the extended keys with the high bit)
  795. // However Pause sends a code that conflicts with NumLock, so use
  796. // the code most RFB implementations use (part of the sequence for
  797. // Ctrl+Pause, i.e. Break)
  798. if (keyCode == 0x45)
  799. keyCode = 0xc6;
  800. // And NumLock incorrectly has the extended bit set
  801. if (keyCode == 0xc5)
  802. keyCode = 0x45;
  803. // And Alt+PrintScreen (i.e. SysRq) sends a different code than
  804. // PrintScreen
  805. if (keyCode == 0xb7)
  806. keyCode = 0x54;
  807. keySym = win32_vkey_to_keysym(vKey, isExtended);
  808. if (keySym == NoSymbol) {
  809. if (isExtended)
  810. vlog.error(_("No symbol for extended virtual key 0x%02x"), (int)vKey);
  811. else
  812. vlog.error(_("No symbol for virtual key 0x%02x"), (int)vKey);
  813. }
  814. // Windows sends the same vKey for both shifts, so we need to look
  815. // at the scan code to tell them apart
  816. if ((keySym == XK_Shift_L) && (keyCode == 0x36))
  817. keySym = XK_Shift_R;
  818. // AltGr handling (see above)
  819. if (win32_has_altgr()) {
  820. if ((keyCode == 0xb8) && (keySym == XK_Alt_R))
  821. keySym = XK_ISO_Level3_Shift;
  822. // Possible start of AltGr sequence?
  823. if ((keyCode == 0x1d) && (keySym == XK_Control_L)) {
  824. self->altGrArmed = true;
  825. self->altGrCtrlTime = msg->time;
  826. Fl::add_timeout(0.1, handleAltGrTimeout, self);
  827. return 1;
  828. }
  829. }
  830. self->handleKeyPress(keyCode, keySym);
  831. return 1;
  832. } else if ((msg->message == WM_KEYUP) || (msg->message == WM_SYSKEYUP)) {
  833. UINT vKey;
  834. bool isExtended;
  835. int keyCode;
  836. vKey = msg->wParam;
  837. isExtended = (msg->lParam & (1 << 24)) != 0;
  838. keyCode = ((msg->lParam >> 16) & 0xff);
  839. // Touch keyboard AltGr (see above)
  840. if (!isExtended && (keyCode == 0x00) && (vKey == VK_MENU)) {
  841. isExtended = true;
  842. keyCode = 0x38;
  843. }
  844. // We can't get a release in the middle of an AltGr sequence, so
  845. // abort that detection
  846. if (self->altGrArmed) {
  847. self->altGrArmed = false;
  848. Fl::remove_timeout(handleAltGrTimeout);
  849. self->handleKeyPress(0x1d, XK_Control_L);
  850. }
  851. if (keyCode == SCAN_FAKE) {
  852. vlog.debug("Ignoring fake key release (virtual key 0x%02x)", vKey);
  853. return 1;
  854. }
  855. if (keyCode == 0x00)
  856. keyCode = MapVirtualKey(vKey, MAPVK_VK_TO_VSC);
  857. if (isExtended)
  858. keyCode |= 0x80;
  859. if (keyCode == 0x45)
  860. keyCode = 0xc6;
  861. if (keyCode == 0xc5)
  862. keyCode = 0x45;
  863. if (keyCode == 0xb7)
  864. keyCode = 0x54;
  865. self->handleKeyRelease(keyCode);
  866. // Windows has a rather nasty bug where it won't send key release
  867. // events for a Shift button if the other Shift is still pressed
  868. if ((keyCode == 0x2a) || (keyCode == 0x36)) {
  869. if (self->downKeySym.count(0x2a))
  870. self->handleKeyRelease(0x2a);
  871. if (self->downKeySym.count(0x36))
  872. self->handleKeyRelease(0x36);
  873. }
  874. return 1;
  875. }
  876. #elif defined(__APPLE__)
  877. if (cocoa_is_keyboard_event(event)) {
  878. int keyCode;
  879. keyCode = cocoa_event_keycode(event);
  880. if ((unsigned)keyCode >= code_map_osx_to_qnum_len)
  881. keyCode = 0;
  882. else
  883. keyCode = code_map_osx_to_qnum[keyCode];
  884. if (cocoa_is_key_press(event)) {
  885. rdr::U32 keySym;
  886. keySym = cocoa_event_keysym(event);
  887. if (keySym == NoSymbol) {
  888. vlog.error(_("No symbol for key code 0x%02x (in the current state)"),
  889. (int)keyCode);
  890. }
  891. self->handleKeyPress(keyCode, keySym);
  892. // We don't get any release events for CapsLock, so we have to
  893. // send the release right away.
  894. if (keySym == XK_Caps_Lock)
  895. self->handleKeyRelease(keyCode);
  896. } else {
  897. self->handleKeyRelease(keyCode);
  898. }
  899. return 1;
  900. }
  901. #else
  902. XEvent *xevent = (XEvent*)event;
  903. if (xevent->type == KeyPress) {
  904. int keycode;
  905. char str;
  906. KeySym keysym;
  907. keycode = code_map_keycode_to_qnum[xevent->xkey.keycode];
  908. // Generate a fake keycode just for tracking if we can't figure
  909. // out the proper one
  910. if (keycode == 0)
  911. keycode = 0x100 | xevent->xkey.keycode;
  912. XLookupString(&xevent->xkey, &str, 1, &keysym, NULL);
  913. if (keysym == NoSymbol) {
  914. vlog.error(_("No symbol for key code %d (in the current state)"),
  915. (int)xevent->xkey.keycode);
  916. }
  917. switch (keysym) {
  918. // For the first few years, there wasn't a good consensus on what the
  919. // Windows keys should be mapped to for X11. So we need to help out a
  920. // bit and map all variants to the same key...
  921. case XK_Hyper_L:
  922. keysym = XK_Super_L;
  923. break;
  924. case XK_Hyper_R:
  925. keysym = XK_Super_R;
  926. break;
  927. // There has been several variants for Shift-Tab over the years.
  928. // RFB states that we should always send a normal tab.
  929. case XK_ISO_Left_Tab:
  930. keysym = XK_Tab;
  931. break;
  932. }
  933. self->handleKeyPress(keycode, keysym);
  934. return 1;
  935. } else if (xevent->type == KeyRelease) {
  936. int keycode = code_map_keycode_to_qnum[xevent->xkey.keycode];
  937. if (keycode == 0)
  938. keycode = 0x100 | xevent->xkey.keycode;
  939. self->handleKeyRelease(keycode);
  940. return 1;
  941. }
  942. #endif
  943. return 0;
  944. }
  945. #ifdef WIN32
  946. void Viewport::handleAltGrTimeout(void *data)
  947. {
  948. Viewport *self = (Viewport *)data;
  949. assert(self);
  950. self->altGrArmed = false;
  951. self->handleKeyPress(0x1d, XK_Control_L);
  952. }
  953. #endif
  954. void Viewport::initContextMenu()
  955. {
  956. contextMenu->clear();
  957. fltk_menu_add(contextMenu, p_("ContextMenu|", "E&xit viewer"),
  958. 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER);
  959. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Full screen"),
  960. 0, NULL, (void*)ID_FULLSCREEN,
  961. FL_MENU_TOGGLE | (window()->fullscreen_active()?FL_MENU_VALUE:0));
  962. fltk_menu_add(contextMenu, p_("ContextMenu|", "Minimi&ze"),
  963. 0, NULL, (void*)ID_MINIMIZE, 0);
  964. fltk_menu_add(contextMenu, p_("ContextMenu|", "Resize &window to session"),
  965. 0, NULL, (void*)ID_RESIZE,
  966. (window()->fullscreen_active()?FL_MENU_INACTIVE:0) |
  967. FL_MENU_DIVIDER);
  968. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Ctrl"),
  969. 0, NULL, (void*)ID_CTRL,
  970. FL_MENU_TOGGLE | (menuCtrlKey?FL_MENU_VALUE:0));
  971. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Alt"),
  972. 0, NULL, (void*)ID_ALT,
  973. FL_MENU_TOGGLE | (menuAltKey?FL_MENU_VALUE:0));
  974. if (menuKeySym) {
  975. char sendMenuKey[64];
  976. snprintf(sendMenuKey, 64, p_("ContextMenu|", "Send %s"), (const char *)menuKey);
  977. fltk_menu_add(contextMenu, sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0);
  978. fltk_menu_add(contextMenu, "Secret shortcut menu key", menuKeyFLTK, NULL,
  979. (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
  980. }
  981. fltk_menu_add(contextMenu, p_("ContextMenu|", "Send Ctrl-Alt-&Del"),
  982. 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
  983. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Refresh screen"),
  984. 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER);
  985. fltk_menu_add(contextMenu, p_("ContextMenu|", "&Options..."),
  986. 0, NULL, (void*)ID_OPTIONS, 0);
  987. fltk_menu_add(contextMenu, p_("ContextMenu|", "Connection &info..."),
  988. 0, NULL, (void*)ID_INFO, 0);
  989. fltk_menu_add(contextMenu, p_("ContextMenu|", "About &TigerVNC viewer..."),
  990. 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER);
  991. fltk_menu_add(contextMenu, p_("ContextMenu|", "Dismiss &menu"),
  992. 0, NULL, (void*)ID_DISMISS, 0);
  993. }
  994. void Viewport::popupContextMenu()
  995. {
  996. const Fl_Menu_Item *m;
  997. char buffer[1024];
  998. // Make sure the menu is reset to its initial state between goes or
  999. // it will start up highlighting the previously selected entry.
  1000. contextMenu->value(-1);
  1001. // initialize context menu before display
  1002. initContextMenu();
  1003. // Unfortunately FLTK doesn't reliably restore the mouse pointer for
  1004. // menus, so we have to help it out.
  1005. if (Fl::belowmouse() == this)
  1006. window()->cursor(FL_CURSOR_DEFAULT);
  1007. // FLTK also doesn't switch focus properly for menus
  1008. handle(FL_UNFOCUS);
  1009. m = contextMenu->popup();
  1010. handle(FL_FOCUS);
  1011. // Back to our proper mouse pointer.
  1012. if ((Fl::belowmouse() == this) && cursor)
  1013. window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
  1014. if (m == NULL)
  1015. return;
  1016. switch (m->argument()) {
  1017. case ID_EXIT:
  1018. exit_vncviewer();
  1019. break;
  1020. case ID_FULLSCREEN:
  1021. if (window()->fullscreen_active())
  1022. window()->fullscreen_off();
  1023. else
  1024. ((DesktopWindow*)window())->fullscreen_on();
  1025. break;
  1026. case ID_MINIMIZE:
  1027. window()->iconize();
  1028. break;
  1029. case ID_RESIZE:
  1030. if (window()->fullscreen_active())
  1031. break;
  1032. window()->size(w(), h());
  1033. break;
  1034. case ID_CTRL:
  1035. if (m->value())
  1036. handleKeyPress(0x1d, XK_Control_L);
  1037. else
  1038. handleKeyRelease(0x1d);
  1039. menuCtrlKey = !menuCtrlKey;
  1040. break;
  1041. case ID_ALT:
  1042. if (m->value())
  1043. handleKeyPress(0x38, XK_Alt_L);
  1044. else
  1045. handleKeyRelease(0x38);
  1046. menuAltKey = !menuAltKey;
  1047. break;
  1048. case ID_MENUKEY:
  1049. handleKeyPress(menuKeyCode, menuKeySym);
  1050. handleKeyRelease(menuKeyCode);
  1051. break;
  1052. case ID_CTRLALTDEL:
  1053. handleKeyPress(0x1d, XK_Control_L);
  1054. handleKeyPress(0x38, XK_Alt_L);
  1055. handleKeyPress(0xd3, XK_Delete);
  1056. handleKeyRelease(0xd3);
  1057. handleKeyRelease(0x38);
  1058. handleKeyRelease(0x1d);
  1059. break;
  1060. case ID_REFRESH:
  1061. cc->refreshFramebuffer();
  1062. break;
  1063. case ID_OPTIONS:
  1064. OptionsDialog::showDialog();
  1065. break;
  1066. case ID_INFO:
  1067. if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < sizeof(buffer)) {
  1068. fl_message_title(_("VNC connection info"));
  1069. fl_message("%s", buffer);
  1070. }
  1071. break;
  1072. case ID_ABOUT:
  1073. about_vncviewer();
  1074. break;
  1075. case ID_DISMISS:
  1076. // Don't need to do anything
  1077. break;
  1078. }
  1079. }
  1080. void Viewport::setMenuKey()
  1081. {
  1082. getMenuKey(&menuKeyFLTK, &menuKeyCode, &menuKeySym);
  1083. }
  1084. void Viewport::handleOptions(void *data)
  1085. {
  1086. Viewport *self = (Viewport*)data;
  1087. self->setMenuKey();
  1088. }