Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Viewport.cxx 35KB

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