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

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