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

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