Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Viewport.cxx 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2011 Pierre Ossman <ossman@cendio.se> 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. #include <assert.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <FL/fl_draw.H>
  23. #include <FL/fl_ask.H>
  24. #include <rfb/CMsgWriter.h>
  25. #include <rfb/LogWriter.h>
  26. // FLTK can pull in the X11 headers on some systems
  27. #ifndef XK_VoidSymbol
  28. #define XK_MISCELLANY
  29. #define XK_XKB_KEYS
  30. #include <rfb/keysymdef.h>
  31. #endif
  32. #ifndef XF86XK_ModeLock
  33. #include <rfb/XF86keysym.h>
  34. #endif
  35. #include "Viewport.h"
  36. #include "CConn.h"
  37. #include "OptionsDialog.h"
  38. #include "i18n.h"
  39. #include "fltk_layout.h"
  40. #include "parameters.h"
  41. #include "keysym2ucs.h"
  42. using namespace rfb;
  43. extern void exit_vncviewer();
  44. extern void about_vncviewer();
  45. static rfb::LogWriter vlog("Viewport");
  46. // Menu constants
  47. enum { ID_EXIT, ID_FULLSCREEN, ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL,
  48. ID_REFRESH, ID_OPTIONS, ID_INFO, ID_ABOUT, ID_DISMISS };
  49. Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
  50. : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL),
  51. lastPointerPos(0, 0), lastButtonMask(0)
  52. {
  53. // FLTK STR #2599 must be fixed for proper dead keys support
  54. #ifdef HAVE_FLTK_DEAD_KEYS
  55. set_simple_keyboard();
  56. #endif
  57. // FLTK STR #2636 gives us the ability to monitor clipboard changes
  58. #ifdef HAVE_FLTK_CLIPBOARD
  59. Fl::add_clipboard_notify(handleClipboardChange, this);
  60. #endif
  61. frameBuffer = new ManagedPixelBuffer(getPreferredPF(), w, h);
  62. assert(frameBuffer);
  63. setServerPF(serverPF);
  64. contextMenu = new Fl_Menu_Button(0, 0, 0, 0);
  65. // Setting box type to FL_NO_BOX prevents it from trying to draw the
  66. // button component (which we don't want)
  67. contextMenu->box(FL_NO_BOX);
  68. initContextMenu();
  69. setMenuKey();
  70. OptionsDialog::addCallback(handleOptions, this);
  71. }
  72. Viewport::~Viewport()
  73. {
  74. // Unregister all timeouts in case they get a change tro trigger
  75. // again later when this object is already gone.
  76. Fl::remove_timeout(handleUpdateTimeout, this);
  77. Fl::remove_timeout(handleColourMap, this);
  78. Fl::remove_timeout(handlePointerTimeout, this);
  79. #ifdef HAVE_FLTK_CLIPBOARD
  80. Fl::remove_clipboard_notify(handleClipboardChange);
  81. #endif
  82. OptionsDialog::removeCallback(handleOptions);
  83. delete frameBuffer;
  84. if (pixelTrans)
  85. delete pixelTrans;
  86. // FLTK automatically deletes all child widgets, so we shouldn't touch
  87. // them ourselves here
  88. }
  89. void Viewport::setServerPF(const rfb::PixelFormat& pf)
  90. {
  91. if (pixelTrans)
  92. delete pixelTrans;
  93. pixelTrans = NULL;
  94. if (pf.equal(getPreferredPF()))
  95. return;
  96. pixelTrans = new PixelTransformer();
  97. pixelTrans->init(pf, &colourMap, getPreferredPF());
  98. }
  99. const rfb::PixelFormat &Viewport::getPreferredPF()
  100. {
  101. static PixelFormat prefPF(32, 24, false, true, 255, 255, 255, 0, 8, 16);
  102. return prefPF;
  103. }
  104. // setColourMapEntries() changes some of the entries in the colourmap.
  105. // Unfortunately these messages are often sent one at a time, so we delay the
  106. // settings taking effect by 100ms. This is because recalculating the internal
  107. // translation table can be expensive.
  108. void Viewport::setColourMapEntries(int firstColour, int nColours,
  109. rdr::U16* rgbs)
  110. {
  111. for (int i = 0; i < nColours; i++)
  112. colourMap.set(firstColour+i, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
  113. if (!Fl::has_timeout(handleColourMap, this))
  114. Fl::add_timeout(0.100, handleColourMap, this);
  115. }
  116. // Copy the areas of the framebuffer that have been changed (damaged)
  117. // to the displayed window.
  118. void Viewport::updateWindow()
  119. {
  120. Rect r;
  121. Fl::remove_timeout(handleUpdateTimeout, this);
  122. r = damage.get_bounding_rect();
  123. Fl_Widget::damage(FL_DAMAGE_USER1, r.tl.x + x(), r.tl.y + y(), r.width(), r.height());
  124. damage.clear();
  125. }
  126. void Viewport::draw()
  127. {
  128. int X, Y, W, H;
  129. int pixel_bytes, stride_bytes;
  130. const uchar *buf_start;
  131. // Check what actually needs updating
  132. fl_clip_box(x(), y(), w(), h(), X, Y, W, H);
  133. if ((W == 0) || (H == 0))
  134. return;
  135. pixel_bytes = frameBuffer->getPF().bpp/8;
  136. stride_bytes = pixel_bytes * frameBuffer->getStride();
  137. buf_start = frameBuffer->data +
  138. pixel_bytes * (X - x()) +
  139. stride_bytes * (Y - y());
  140. // FIXME: Check how efficient this thing really is
  141. fl_draw_image(buf_start, X, Y, W, H, pixel_bytes, stride_bytes);
  142. }
  143. int Viewport::handle(int event)
  144. {
  145. char buffer[1024];
  146. int ret;
  147. int buttonMask, wheelMask;
  148. DownMap::const_iterator iter;
  149. switch (event) {
  150. case FL_PASTE:
  151. // This is documented as to ASCII, but actually does to 8859-1
  152. ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer, sizeof(buffer));
  153. if (ret >= sizeof(buffer)) {
  154. vlog.error(_("Clipboard buffer overflow!"));
  155. return 1;
  156. }
  157. vlog.debug("Sending clipboard data: '%s'", buffer);
  158. cc->writer()->clientCutText(buffer, ret);
  159. return 1;
  160. case FL_ENTER:
  161. // Yes, we would like some pointer events please!
  162. return 1;
  163. case FL_PUSH:
  164. case FL_RELEASE:
  165. case FL_DRAG:
  166. case FL_MOVE:
  167. case FL_MOUSEWHEEL:
  168. buttonMask = 0;
  169. if (Fl::event_button1())
  170. buttonMask |= 1;
  171. if (Fl::event_button2())
  172. buttonMask |= 2;
  173. if (Fl::event_button3())
  174. buttonMask |= 4;
  175. if (event == FL_MOUSEWHEEL) {
  176. wheelMask = 0;
  177. if (Fl::event_dy() < 0)
  178. wheelMask |= 8;
  179. if (Fl::event_dy() > 0)
  180. wheelMask |= 16;
  181. if (Fl::event_dx() < 0)
  182. wheelMask |= 32;
  183. if (Fl::event_dx() > 0)
  184. wheelMask |= 64;
  185. // A quick press of the wheel "button", followed by a immediate
  186. // release below
  187. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()),
  188. buttonMask | wheelMask);
  189. }
  190. handlePointerEvent(Point(Fl::event_x() - x(), Fl::event_y() - y()), buttonMask);
  191. return 1;
  192. case FL_FOCUS:
  193. // Yes, we would like some focus please!
  194. return 1;
  195. case FL_UNFOCUS:
  196. // Release all keys that were pressed as that generally makes most
  197. // sense (e.g. Alt+Tab where we only see the Alt press)
  198. for (iter = downKeySym.begin();iter != downKeySym.end();++iter) {
  199. vlog.debug("Key released: 0x%04x => 0x%04x", iter->first, iter->second);
  200. cc->writer()->keyEvent(iter->second, false);
  201. }
  202. downKeySym.clear();
  203. return 1;
  204. case FL_KEYDOWN:
  205. if (menuKeyCode && (Fl::event_key() == menuKeyCode)) {
  206. popupContextMenu();
  207. return 1;
  208. }
  209. handleKeyEvent(Fl::event_key(), Fl::event_original_key(),
  210. Fl::event_text(), true);
  211. return 1;
  212. case FL_KEYUP:
  213. if (menuKeyCode && (Fl::event_key() == menuKeyCode))
  214. return 1;
  215. handleKeyEvent(Fl::event_key(), Fl::event_original_key(),
  216. Fl::event_text(), false);
  217. return 1;
  218. }
  219. return Fl_Widget::handle(event);
  220. }
  221. void Viewport::handleUpdateTimeout(void *data)
  222. {
  223. Viewport *self = (Viewport *)data;
  224. assert(self);
  225. self->updateWindow();
  226. }
  227. void Viewport::handleColourMap(void *data)
  228. {
  229. Viewport *self = (Viewport *)data;
  230. assert(self);
  231. if (self->pixelTrans != NULL)
  232. self->pixelTrans->setColourMapEntries(0, 0);
  233. self->Fl_Widget::damage(FL_DAMAGE_ALL);
  234. }
  235. void Viewport::handleClipboardChange(int source, void *data)
  236. {
  237. Viewport *self = (Viewport *)data;
  238. assert(self);
  239. if (!sendPrimary && (source == 0))
  240. return;
  241. Fl::paste(*self, source);
  242. }
  243. void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask)
  244. {
  245. if (!viewOnly) {
  246. if (pointerEventInterval == 0 || buttonMask != lastButtonMask) {
  247. cc->writer()->pointerEvent(pos, buttonMask);
  248. } else {
  249. if (!Fl::has_timeout(handlePointerTimeout, this))
  250. Fl::add_timeout((double)pointerEventInterval/1000.0,
  251. handlePointerTimeout, this);
  252. }
  253. lastPointerPos = pos;
  254. lastButtonMask = buttonMask;
  255. }
  256. }
  257. void Viewport::handlePointerTimeout(void *data)
  258. {
  259. Viewport *self = (Viewport *)data;
  260. assert(self);
  261. self->cc->writer()->pointerEvent(self->lastPointerPos, self->lastButtonMask);
  262. }
  263. rdr::U32 Viewport::translateKeyEvent(int keyCode, int origKeyCode, const char *keyText)
  264. {
  265. unsigned ucs;
  266. // First check for function keys
  267. if ((keyCode > FL_F) && (keyCode <= FL_F_Last))
  268. return XK_F1 + (keyCode - FL_F - 1);
  269. // Numpad numbers
  270. if ((keyCode >= (FL_KP + '0')) && (keyCode <= (FL_KP + '9')))
  271. return XK_KP_0 + (keyCode - (FL_KP + '0'));
  272. // FLTK does some special remapping of numpad keys when numlock is off
  273. if ((origKeyCode >= FL_KP) && (origKeyCode <= FL_KP_Last)) {
  274. switch (keyCode) {
  275. case FL_F+1:
  276. return XK_KP_F1;
  277. case FL_F+2:
  278. return XK_KP_F2;
  279. case FL_F+3:
  280. return XK_KP_F3;
  281. case FL_F+4:
  282. return XK_KP_F4;
  283. case FL_Home:
  284. return XK_KP_Home;
  285. case FL_Left:
  286. return XK_KP_Left;
  287. case FL_Up:
  288. return XK_KP_Up;
  289. case FL_Right:
  290. return XK_KP_Right;
  291. case FL_Down:
  292. return XK_KP_Down;
  293. case FL_Page_Up:
  294. return XK_KP_Page_Up;
  295. case FL_Page_Down:
  296. return XK_KP_Page_Down;
  297. case FL_End:
  298. return XK_KP_End;
  299. case FL_Insert:
  300. return XK_KP_Insert;
  301. case FL_Delete:
  302. return XK_KP_Delete;
  303. }
  304. }
  305. // Then other special keys
  306. switch (keyCode) {
  307. case FL_BackSpace:
  308. return XK_BackSpace;
  309. case FL_Tab:
  310. return XK_Tab;
  311. case FL_Enter:
  312. return XK_Return;
  313. case FL_Pause:
  314. return XK_Pause;
  315. case FL_Scroll_Lock:
  316. return XK_Scroll_Lock;
  317. case FL_Escape:
  318. return XK_Escape;
  319. case FL_Home:
  320. return XK_Home;
  321. case FL_Left:
  322. return XK_Left;
  323. case FL_Up:
  324. return XK_Up;
  325. case FL_Right:
  326. return XK_Right;
  327. case FL_Down:
  328. return XK_Down;
  329. case FL_Page_Up:
  330. return XK_Page_Up;
  331. case FL_Page_Down:
  332. return XK_Page_Down;
  333. case FL_End:
  334. return XK_End;
  335. case FL_Print:
  336. return XK_Print;
  337. case FL_Insert:
  338. return XK_Insert;
  339. case FL_Menu:
  340. return XK_Menu;
  341. case FL_Help:
  342. return XK_Help;
  343. case FL_Num_Lock:
  344. return XK_Num_Lock;
  345. case FL_Shift_L:
  346. return XK_Shift_L;
  347. case FL_Shift_R:
  348. return XK_Shift_R;
  349. case FL_Control_L:
  350. return XK_Control_L;
  351. case FL_Control_R:
  352. return XK_Control_R;
  353. case FL_Caps_Lock:
  354. return XK_Caps_Lock;
  355. case FL_Meta_L:
  356. return XK_Super_L;
  357. case FL_Meta_R:
  358. return XK_Super_R;
  359. case FL_Alt_L:
  360. return XK_Alt_L;
  361. case FL_Alt_R:
  362. return XK_Alt_R;
  363. case FL_Delete:
  364. return XK_Delete;
  365. case FL_KP_Enter:
  366. return XK_KP_Enter;
  367. case FL_KP + '=':
  368. return XK_KP_Equal;
  369. case FL_KP + '*':
  370. return XK_KP_Multiply;
  371. case FL_KP + '+':
  372. return XK_KP_Add;
  373. case FL_KP + ',':
  374. return XK_KP_Separator;
  375. case FL_KP + '-':
  376. return XK_KP_Subtract;
  377. case FL_KP + '.':
  378. return XK_KP_Decimal;
  379. case FL_KP + '/':
  380. return XK_KP_Divide;
  381. #ifdef HAVE_FLTK_MEDIAKEYS
  382. case FL_Volume_Down:
  383. return XF86XK_AudioLowerVolume;
  384. case FL_Volume_Mute:
  385. return XF86XK_AudioMute;
  386. case FL_Volume_Up:
  387. return XF86XK_AudioRaiseVolume;
  388. case FL_Media_Play:
  389. return XF86XK_AudioPlay;
  390. case FL_Media_Stop:
  391. return XF86XK_AudioStop;
  392. case FL_Media_Prev:
  393. return XF86XK_AudioPrev;
  394. case FL_Media_Next:
  395. return XF86XK_AudioNext;
  396. case FL_Home_Page:
  397. return XF86XK_HomePage;
  398. case FL_Mail:
  399. return XF86XK_Mail;
  400. case FL_Search:
  401. return XF86XK_Search;
  402. case FL_Back:
  403. return XF86XK_Back;
  404. case FL_Forward:
  405. return XF86XK_Forward;
  406. case FL_Stop:
  407. return XF86XK_Stop;
  408. case FL_Refresh:
  409. return XF86XK_Refresh;
  410. case FL_Sleep:
  411. return XF86XK_Sleep;
  412. case FL_Favorites:
  413. return XF86XK_Favorites;
  414. #endif
  415. case XK_ISO_Level3_Shift:
  416. // FLTK tends to let this one leak through on X11...
  417. return XK_ISO_Level3_Shift;
  418. case XK_Multi_key:
  419. // Same for this...
  420. return XK_Multi_key;
  421. }
  422. // Unknown special key?
  423. if (keyText[0] == '\0') {
  424. vlog.error(_("Unknown FLTK key code %d (0x%04x)"), keyCode, keyCode);
  425. return XK_VoidSymbol;
  426. }
  427. // Look up the symbol the key produces and translate that from Unicode
  428. // to a X11 keysym.
  429. if (fl_utf_nb_char((const unsigned char*)keyText, strlen(keyText)) != 1) {
  430. vlog.error(_("Multiple characters given for key code %d (0x%04x): '%s'"),
  431. keyCode, keyCode, keyText);
  432. return XK_VoidSymbol;
  433. }
  434. ucs = fl_utf8decode(keyText, NULL, NULL);
  435. return ucs2keysym(ucs);
  436. }
  437. void Viewport::handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down)
  438. {
  439. rdr::U32 keySym;
  440. if (viewOnly)
  441. return;
  442. // Because of the way keyboards work, we cannot expect to have the same
  443. // symbol on release as when pressed. This breaks the VNC protocol however,
  444. // so we need to keep track of what keysym a key _code_ generated on press
  445. // and send the same on release.
  446. if (!down) {
  447. DownMap::iterator iter;
  448. iter = downKeySym.find(origKeyCode);
  449. if (iter == downKeySym.end()) {
  450. vlog.error(_("Unexpected release of FLTK key code %d (0x%04x)"),
  451. origKeyCode, origKeyCode);
  452. return;
  453. }
  454. vlog.debug("Key released: 0x%04x => 0x%04x", origKeyCode, iter->second);
  455. cc->writer()->keyEvent(iter->second, false);
  456. downKeySym.erase(iter);
  457. return;
  458. }
  459. keySym = translateKeyEvent(keyCode, origKeyCode, keyText);
  460. if (keySym == XK_VoidSymbol)
  461. return;
  462. vlog.debug("Key pressed: 0x%04x (0x%04x) '%s' => 0x%04x",
  463. origKeyCode, keyCode, keyText, keySym);
  464. downKeySym[origKeyCode] = keySym;
  465. cc->writer()->keyEvent(keySym, down);
  466. }
  467. void Viewport::initContextMenu()
  468. {
  469. contextMenu->clear();
  470. contextMenu->add(_("Exit viewer"), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER);
  471. #ifdef HAVE_FLTK_FULLSCREEN
  472. contextMenu->add(_("Full screen"), 0, NULL, (void*)ID_FULLSCREEN, FL_MENU_DIVIDER);
  473. #endif
  474. contextMenu->add(_("Ctrl"), 0, NULL, (void*)ID_CTRL, FL_MENU_TOGGLE);
  475. contextMenu->add(_("Alt"), 0, NULL, (void*)ID_ALT, FL_MENU_TOGGLE);
  476. if (menuKeyCode) {
  477. char sendMenuKey[64];
  478. snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey);
  479. contextMenu->add(sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0);
  480. contextMenu->add("Secret shortcut menu key", menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
  481. }
  482. contextMenu->add(_("Send Ctrl-Alt-Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
  483. contextMenu->add(_("Refresh screen"), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER);
  484. contextMenu->add(_("Options..."), 0, NULL, (void*)ID_OPTIONS, 0);
  485. contextMenu->add(_("Connection info..."), 0, NULL, (void*)ID_INFO, 0);
  486. contextMenu->add(_("About TigerVNC viewer..."), 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER);
  487. contextMenu->add(_("Dismiss menu"), 0, NULL, (void*)ID_DISMISS, 0);
  488. }
  489. void Viewport::popupContextMenu()
  490. {
  491. const Fl_Menu_Item *m;
  492. char buffer[1024];
  493. // FIXME: Hacky workaround for the fact that menus grab and ungrab the
  494. // keyboard. Releasing focus here triggers some events on ungrab
  495. // that DesktopWindow can catch and trigger some voodoo.
  496. // See DesktopWindow::handle().
  497. if (window()->contains(Fl::focus()))
  498. Fl::focus(NULL);
  499. contextMenu->position(Fl::event_x(), Fl::event_y());
  500. m = contextMenu->popup();
  501. if (m == NULL)
  502. return;
  503. switch (m->argument()) {
  504. case ID_EXIT:
  505. exit_vncviewer();
  506. break;
  507. #ifdef HAVE_FLTK_FULLSCREEN
  508. case ID_FULLSCREEN:
  509. if (window()->fullscreen_active())
  510. window()->fullscreen_off();
  511. else
  512. window()->fullscreen();
  513. break;
  514. #endif
  515. case ID_CTRL:
  516. if (!viewOnly)
  517. cc->writer()->keyEvent(XK_Control_L, m->value());
  518. break;
  519. case ID_ALT:
  520. if (!viewOnly)
  521. cc->writer()->keyEvent(XK_Alt_L, m->value());
  522. break;
  523. case ID_MENUKEY:
  524. if (!viewOnly) {
  525. handleKeyEvent(menuKeyCode, menuKeyCode, "", true);
  526. handleKeyEvent(menuKeyCode, menuKeyCode, "", false);
  527. }
  528. break;
  529. case ID_CTRLALTDEL:
  530. if (!viewOnly) {
  531. cc->writer()->keyEvent(XK_Control_L, true);
  532. cc->writer()->keyEvent(XK_Alt_L, true);
  533. cc->writer()->keyEvent(XK_Delete, true);
  534. cc->writer()->keyEvent(XK_Delete, false);
  535. cc->writer()->keyEvent(XK_Alt_L, false);
  536. cc->writer()->keyEvent(XK_Control_L, false);
  537. }
  538. break;
  539. case ID_REFRESH:
  540. cc->refreshFramebuffer();
  541. break;
  542. case ID_OPTIONS:
  543. OptionsDialog::showDialog();
  544. break;
  545. case ID_INFO:
  546. if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < sizeof(buffer)) {
  547. fl_message_title(_("VNC connection info"));
  548. fl_message(buffer);
  549. }
  550. break;
  551. case ID_ABOUT:
  552. about_vncviewer();
  553. break;
  554. case ID_DISMISS:
  555. // Don't need to do anything
  556. break;
  557. }
  558. }
  559. void Viewport::setMenuKey()
  560. {
  561. const char *menuKeyStr;
  562. menuKeyCode = 0;
  563. menuKeyStr = menuKey;
  564. if (menuKeyStr[0] == 'F') {
  565. int num = atoi(menuKeyStr + 1);
  566. if ((num >= 1) && (num <= 12))
  567. menuKeyCode = FL_F + num;
  568. }
  569. // Need to repopulate the context menu as it contains references to
  570. // the menu key
  571. initContextMenu();
  572. }
  573. void Viewport::handleOptions(void *data)
  574. {
  575. Viewport *self = (Viewport*)data;
  576. self->setMenuKey();
  577. }