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.

OptionsDialog.cxx 34KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. /* Copyright 2011-2021 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <assert.h>
  22. #include <stdlib.h>
  23. #include <list>
  24. #include <rdr/types.h>
  25. #include <rfb/encodings.h>
  26. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  27. #include <rfb/Security.h>
  28. #include <rfb/SecurityClient.h>
  29. #ifdef HAVE_GNUTLS
  30. #include <rfb/CSecurityTLS.h>
  31. #endif
  32. #endif
  33. #include "OptionsDialog.h"
  34. #include "fltk_layout.h"
  35. #include "i18n.h"
  36. #include "menukey.h"
  37. #include "parameters.h"
  38. #include "MonitorArrangement.h"
  39. #include <FL/Fl.H>
  40. #include <FL/Fl_Tabs.H>
  41. #include <FL/Fl_Button.H>
  42. #include <FL/Fl_Check_Button.H>
  43. #include <FL/Fl_Return_Button.H>
  44. #include <FL/Fl_Round_Button.H>
  45. #include <FL/Fl_Int_Input.H>
  46. #include <FL/Fl_Choice.H>
  47. using namespace std;
  48. using namespace rdr;
  49. using namespace rfb;
  50. std::map<OptionsCallback*, void*> OptionsDialog::callbacks;
  51. static std::set<OptionsDialog *> instances;
  52. OptionsDialog::OptionsDialog()
  53. : Fl_Window(450, 460, _("VNC Viewer: Connection Options"))
  54. {
  55. int x, y;
  56. Fl_Button *button;
  57. Fl_Tabs *tabs = new Fl_Tabs(OUTER_MARGIN, OUTER_MARGIN,
  58. w() - OUTER_MARGIN*2,
  59. h() - OUTER_MARGIN*2 - INNER_MARGIN - BUTTON_HEIGHT);
  60. {
  61. int tx, ty, tw, th;
  62. tabs->client_area(tx, ty, tw, th, TABS_HEIGHT);
  63. createCompressionPage(tx, ty, tw, th);
  64. createSecurityPage(tx, ty, tw, th);
  65. createInputPage(tx, ty, tw, th);
  66. createDisplayPage(tx, ty, tw, th);
  67. createMiscPage(tx, ty, tw, th);
  68. }
  69. tabs->end();
  70. x = w() - BUTTON_WIDTH * 2 - INNER_MARGIN - OUTER_MARGIN;
  71. y = h() - BUTTON_HEIGHT - OUTER_MARGIN;
  72. button = new Fl_Button(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, _("Cancel"));
  73. button->callback(this->handleCancel, this);
  74. x += BUTTON_WIDTH + INNER_MARGIN;
  75. button = new Fl_Return_Button(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, _("OK"));
  76. button->callback(this->handleOK, this);
  77. callback(this->handleCancel, this);
  78. set_modal();
  79. if (instances.size() == 0)
  80. Fl::add_handler(fltk_event_handler);
  81. instances.insert(this);
  82. }
  83. OptionsDialog::~OptionsDialog()
  84. {
  85. instances.erase(this);
  86. if (instances.size() == 0)
  87. Fl::remove_handler(fltk_event_handler);
  88. }
  89. void OptionsDialog::showDialog(void)
  90. {
  91. static OptionsDialog *dialog = NULL;
  92. if (!dialog)
  93. dialog = new OptionsDialog();
  94. if (dialog->shown())
  95. return;
  96. dialog->show();
  97. }
  98. void OptionsDialog::addCallback(OptionsCallback *cb, void *data)
  99. {
  100. callbacks[cb] = data;
  101. }
  102. void OptionsDialog::removeCallback(OptionsCallback *cb)
  103. {
  104. callbacks.erase(cb);
  105. }
  106. void OptionsDialog::show(void)
  107. {
  108. /* show() gets called for raise events as well */
  109. if (!shown())
  110. loadOptions();
  111. Fl_Window::show();
  112. }
  113. void OptionsDialog::loadOptions(void)
  114. {
  115. /* Compression */
  116. autoselectCheckbox->value(autoSelect);
  117. int encNum = encodingNum(preferredEncoding);
  118. switch (encNum) {
  119. case encodingTight:
  120. tightButton->setonly();
  121. break;
  122. case encodingZRLE:
  123. zrleButton->setonly();
  124. break;
  125. case encodingHextile:
  126. hextileButton->setonly();
  127. break;
  128. #ifdef HAVE_H264
  129. case encodingH264:
  130. h264Button->setonly();
  131. break;
  132. #endif
  133. case encodingRaw:
  134. rawButton->setonly();
  135. break;
  136. }
  137. if (fullColour)
  138. fullcolorCheckbox->setonly();
  139. else {
  140. switch (lowColourLevel) {
  141. case 0:
  142. verylowcolorCheckbox->setonly();
  143. break;
  144. case 1:
  145. lowcolorCheckbox->setonly();
  146. break;
  147. case 2:
  148. mediumcolorCheckbox->setonly();
  149. break;
  150. }
  151. }
  152. char digit[2] = "0";
  153. compressionCheckbox->value(customCompressLevel);
  154. jpegCheckbox->value(!noJpeg);
  155. digit[0] = '0' + compressLevel;
  156. compressionInput->value(digit);
  157. digit[0] = '0' + qualityLevel;
  158. jpegInput->value(digit);
  159. handleAutoselect(autoselectCheckbox, this);
  160. handleCompression(compressionCheckbox, this);
  161. handleJpeg(jpegCheckbox, this);
  162. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  163. /* Security */
  164. Security security(SecurityClient::secTypes);
  165. list<U8> secTypes;
  166. list<U8>::iterator iter;
  167. list<U32> secTypesExt;
  168. list<U32>::iterator iterExt;
  169. encNoneCheckbox->value(false);
  170. #ifdef HAVE_GNUTLS
  171. encTLSCheckbox->value(false);
  172. encX509Checkbox->value(false);
  173. #endif
  174. #ifdef HAVE_NETTLE
  175. encRSAAESCheckbox->value(false);
  176. #endif
  177. authNoneCheckbox->value(false);
  178. authVncCheckbox->value(false);
  179. authPlainCheckbox->value(false);
  180. secTypes = security.GetEnabledSecTypes();
  181. for (iter = secTypes.begin(); iter != secTypes.end(); ++iter) {
  182. switch (*iter) {
  183. case secTypeNone:
  184. encNoneCheckbox->value(true);
  185. authNoneCheckbox->value(true);
  186. break;
  187. case secTypeVncAuth:
  188. encNoneCheckbox->value(true);
  189. authVncCheckbox->value(true);
  190. break;
  191. }
  192. }
  193. secTypesExt = security.GetEnabledExtSecTypes();
  194. for (iterExt = secTypesExt.begin(); iterExt != secTypesExt.end(); ++iterExt) {
  195. switch (*iterExt) {
  196. case secTypePlain:
  197. encNoneCheckbox->value(true);
  198. authPlainCheckbox->value(true);
  199. break;
  200. #ifdef HAVE_GNUTLS
  201. case secTypeTLSNone:
  202. encTLSCheckbox->value(true);
  203. authNoneCheckbox->value(true);
  204. break;
  205. case secTypeTLSVnc:
  206. encTLSCheckbox->value(true);
  207. authVncCheckbox->value(true);
  208. break;
  209. case secTypeTLSPlain:
  210. encTLSCheckbox->value(true);
  211. authPlainCheckbox->value(true);
  212. break;
  213. case secTypeX509None:
  214. encX509Checkbox->value(true);
  215. authNoneCheckbox->value(true);
  216. break;
  217. case secTypeX509Vnc:
  218. encX509Checkbox->value(true);
  219. authVncCheckbox->value(true);
  220. break;
  221. case secTypeX509Plain:
  222. encX509Checkbox->value(true);
  223. authPlainCheckbox->value(true);
  224. break;
  225. #endif
  226. #ifdef HAVE_NETTLE
  227. case secTypeRA2:
  228. case secTypeRA256:
  229. encRSAAESCheckbox->value(true);
  230. case secTypeRA2ne:
  231. case secTypeRAne256:
  232. authVncCheckbox->value(true);
  233. authPlainCheckbox->value(true);
  234. break;
  235. #endif
  236. }
  237. }
  238. #ifdef HAVE_GNUTLS
  239. caInput->value(CSecurityTLS::X509CA);
  240. crlInput->value(CSecurityTLS::X509CRL);
  241. handleX509(encX509Checkbox, this);
  242. #endif
  243. #endif
  244. /* Input */
  245. const char *menuKeyBuf;
  246. viewOnlyCheckbox->value(viewOnly);
  247. emulateMBCheckbox->value(emulateMiddleButton);
  248. acceptClipboardCheckbox->value(acceptClipboard);
  249. #if !defined(WIN32) && !defined(__APPLE__)
  250. setPrimaryCheckbox->value(setPrimary);
  251. #endif
  252. sendClipboardCheckbox->value(sendClipboard);
  253. #if !defined(WIN32) && !defined(__APPLE__)
  254. sendPrimaryCheckbox->value(sendPrimary);
  255. #endif
  256. systemKeysCheckbox->value(fullscreenSystemKeys);
  257. menuKeyChoice->value(0);
  258. menuKeyBuf = menuKey;
  259. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  260. if (!strcmp(getMenuKeySymbols()[i].name, menuKeyBuf))
  261. menuKeyChoice->value(i + 1);
  262. /* Display */
  263. if (!fullScreen) {
  264. windowedButton->setonly();
  265. } else {
  266. if (!strcasecmp(fullScreenMode, "all")) {
  267. allMonitorsButton->setonly();
  268. } else if (!strcasecmp(fullScreenMode, "selected")) {
  269. selectedMonitorsButton->setonly();
  270. } else {
  271. currentMonitorButton->setonly();
  272. }
  273. }
  274. monitorArrangement->set(fullScreenSelectedMonitors.getParam());
  275. handleFullScreenMode(selectedMonitorsButton, this);
  276. /* Misc. */
  277. sharedCheckbox->value(shared);
  278. reconnectCheckbox->value(reconnectOnError);
  279. dotCursorCheckbox->value(dotWhenNoCursor);
  280. }
  281. void OptionsDialog::storeOptions(void)
  282. {
  283. /* Compression */
  284. autoSelect.setParam(autoselectCheckbox->value());
  285. if (tightButton->value())
  286. preferredEncoding.setParam(encodingName(encodingTight));
  287. else if (zrleButton->value())
  288. preferredEncoding.setParam(encodingName(encodingZRLE));
  289. else if (hextileButton->value())
  290. preferredEncoding.setParam(encodingName(encodingHextile));
  291. #ifdef HAVE_H264
  292. else if (h264Button->value())
  293. preferredEncoding.setParam(encodingName(encodingH264));
  294. #endif
  295. else if (rawButton->value())
  296. preferredEncoding.setParam(encodingName(encodingRaw));
  297. fullColour.setParam(fullcolorCheckbox->value());
  298. if (verylowcolorCheckbox->value())
  299. lowColourLevel.setParam(0);
  300. else if (lowcolorCheckbox->value())
  301. lowColourLevel.setParam(1);
  302. else if (mediumcolorCheckbox->value())
  303. lowColourLevel.setParam(2);
  304. customCompressLevel.setParam(compressionCheckbox->value());
  305. noJpeg.setParam(!jpegCheckbox->value());
  306. compressLevel.setParam(atoi(compressionInput->value()));
  307. qualityLevel.setParam(atoi(jpegInput->value()));
  308. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  309. /* Security */
  310. Security security;
  311. /* Process security types which don't use encryption */
  312. if (encNoneCheckbox->value()) {
  313. if (authNoneCheckbox->value())
  314. security.EnableSecType(secTypeNone);
  315. if (authVncCheckbox->value()) {
  316. security.EnableSecType(secTypeVncAuth);
  317. #ifdef HAVE_NETTLE
  318. security.EnableSecType(secTypeRAne256);
  319. #endif
  320. }
  321. if (authPlainCheckbox->value()) {
  322. security.EnableSecType(secTypePlain);
  323. #ifdef HAVE_NETTLE
  324. security.EnableSecType(secTypeRA2ne);
  325. security.EnableSecType(secTypeRAne256);
  326. #endif
  327. }
  328. }
  329. #ifdef HAVE_GNUTLS
  330. /* Process security types which use TLS encryption */
  331. if (encTLSCheckbox->value()) {
  332. if (authNoneCheckbox->value())
  333. security.EnableSecType(secTypeTLSNone);
  334. if (authVncCheckbox->value())
  335. security.EnableSecType(secTypeTLSVnc);
  336. if (authPlainCheckbox->value())
  337. security.EnableSecType(secTypeTLSPlain);
  338. }
  339. /* Process security types which use X509 encryption */
  340. if (encX509Checkbox->value()) {
  341. if (authNoneCheckbox->value())
  342. security.EnableSecType(secTypeX509None);
  343. if (authVncCheckbox->value())
  344. security.EnableSecType(secTypeX509Vnc);
  345. if (authPlainCheckbox->value())
  346. security.EnableSecType(secTypeX509Plain);
  347. }
  348. CSecurityTLS::X509CA.setParam(caInput->value());
  349. CSecurityTLS::X509CRL.setParam(crlInput->value());
  350. #endif
  351. #ifdef HAVE_NETTLE
  352. if (encRSAAESCheckbox->value()) {
  353. security.EnableSecType(secTypeRA2);
  354. security.EnableSecType(secTypeRA256);
  355. }
  356. #endif
  357. SecurityClient::secTypes.setParam(security.ToString());
  358. #endif
  359. /* Input */
  360. viewOnly.setParam(viewOnlyCheckbox->value());
  361. emulateMiddleButton.setParam(emulateMBCheckbox->value());
  362. acceptClipboard.setParam(acceptClipboardCheckbox->value());
  363. #if !defined(WIN32) && !defined(__APPLE__)
  364. setPrimary.setParam(setPrimaryCheckbox->value());
  365. #endif
  366. sendClipboard.setParam(sendClipboardCheckbox->value());
  367. #if !defined(WIN32) && !defined(__APPLE__)
  368. sendPrimary.setParam(sendPrimaryCheckbox->value());
  369. #endif
  370. fullscreenSystemKeys.setParam(systemKeysCheckbox->value());
  371. if (menuKeyChoice->value() == 0)
  372. menuKey.setParam("");
  373. else {
  374. menuKey.setParam(menuKeyChoice->text());
  375. }
  376. /* Display */
  377. if (windowedButton->value()) {
  378. fullScreen.setParam(false);
  379. } else {
  380. fullScreen.setParam(true);
  381. if (allMonitorsButton->value()) {
  382. fullScreenMode.setParam("All");
  383. } else if (selectedMonitorsButton->value()) {
  384. fullScreenMode.setParam("Selected");
  385. } else {
  386. fullScreenMode.setParam("Current");
  387. }
  388. }
  389. fullScreenSelectedMonitors.setParam(monitorArrangement->get());
  390. /* Misc. */
  391. shared.setParam(sharedCheckbox->value());
  392. reconnectOnError.setParam(reconnectCheckbox->value());
  393. dotWhenNoCursor.setParam(dotCursorCheckbox->value());
  394. std::map<OptionsCallback*, void*>::const_iterator iter;
  395. for (iter = callbacks.begin();iter != callbacks.end();++iter)
  396. iter->first(iter->second);
  397. }
  398. void OptionsDialog::createCompressionPage(int tx, int ty, int tw, int th)
  399. {
  400. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Compression"));
  401. int orig_tx, orig_ty;
  402. int col1_ty, col2_ty;
  403. int half_width, full_width;
  404. int height;
  405. tx += OUTER_MARGIN;
  406. ty += OUTER_MARGIN;
  407. full_width = tw - OUTER_MARGIN * 2;
  408. half_width = (full_width - INNER_MARGIN) / 2;
  409. /* AutoSelect checkbox */
  410. autoselectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  411. CHECK_MIN_WIDTH,
  412. CHECK_HEIGHT,
  413. _("Auto select")));
  414. autoselectCheckbox->callback(handleAutoselect, this);
  415. ty += CHECK_HEIGHT + INNER_MARGIN;
  416. /* Two columns */
  417. orig_tx = tx;
  418. orig_ty = ty;
  419. /* VNC encoding box */
  420. ty += GROUP_LABEL_OFFSET;
  421. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 3 + RADIO_HEIGHT * 4;
  422. #ifdef HAVE_H264
  423. height += TIGHT_MARGIN + RADIO_HEIGHT;
  424. #endif
  425. encodingGroup = new Fl_Group(tx, ty, half_width, height,
  426. _("Preferred encoding"));
  427. encodingGroup->box(FL_ENGRAVED_BOX);
  428. encodingGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  429. {
  430. tx += GROUP_MARGIN;
  431. ty += GROUP_MARGIN;
  432. tightButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  433. RADIO_MIN_WIDTH,
  434. RADIO_HEIGHT,
  435. "Tight"));
  436. tightButton->type(FL_RADIO_BUTTON);
  437. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  438. zrleButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  439. RADIO_MIN_WIDTH,
  440. RADIO_HEIGHT,
  441. "ZRLE"));
  442. zrleButton->type(FL_RADIO_BUTTON);
  443. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  444. hextileButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  445. RADIO_MIN_WIDTH,
  446. RADIO_HEIGHT,
  447. "Hextile"));
  448. hextileButton->type(FL_RADIO_BUTTON);
  449. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  450. #ifdef HAVE_H264
  451. h264Button = new Fl_Round_Button(LBLRIGHT(tx, ty,
  452. RADIO_MIN_WIDTH,
  453. RADIO_HEIGHT,
  454. "H.264"));
  455. h264Button->type(FL_RADIO_BUTTON);
  456. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  457. #endif
  458. rawButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  459. RADIO_MIN_WIDTH,
  460. RADIO_HEIGHT,
  461. "Raw"));
  462. rawButton->type(FL_RADIO_BUTTON);
  463. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  464. }
  465. ty += GROUP_MARGIN - TIGHT_MARGIN;
  466. encodingGroup->end();
  467. col1_ty = ty;
  468. /* Second column */
  469. tx = orig_tx + half_width + INNER_MARGIN;
  470. ty = orig_ty;
  471. /* Color box */
  472. ty += GROUP_LABEL_OFFSET;
  473. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 3 + RADIO_HEIGHT * 4;
  474. colorlevelGroup = new Fl_Group(tx, ty, half_width, height, _("Color level"));
  475. colorlevelGroup->box(FL_ENGRAVED_BOX);
  476. colorlevelGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  477. {
  478. tx += GROUP_MARGIN;
  479. ty += GROUP_MARGIN;
  480. fullcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  481. RADIO_MIN_WIDTH,
  482. RADIO_HEIGHT,
  483. _("Full")));
  484. fullcolorCheckbox->type(FL_RADIO_BUTTON);
  485. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  486. mediumcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  487. RADIO_MIN_WIDTH,
  488. RADIO_HEIGHT,
  489. _("Medium")));
  490. mediumcolorCheckbox->type(FL_RADIO_BUTTON);
  491. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  492. lowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  493. RADIO_MIN_WIDTH,
  494. RADIO_HEIGHT,
  495. _("Low")));
  496. lowcolorCheckbox->type(FL_RADIO_BUTTON);
  497. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  498. verylowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  499. RADIO_MIN_WIDTH,
  500. RADIO_HEIGHT,
  501. _("Very low")));
  502. verylowcolorCheckbox->type(FL_RADIO_BUTTON);
  503. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  504. }
  505. ty += GROUP_MARGIN - TIGHT_MARGIN;
  506. colorlevelGroup->end();
  507. col2_ty = ty;
  508. /* Back to normal */
  509. tx = orig_tx;
  510. ty = (col1_ty > col2_ty ? col1_ty : col2_ty) + INNER_MARGIN;
  511. /* Checkboxes */
  512. compressionCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  513. CHECK_MIN_WIDTH,
  514. CHECK_HEIGHT,
  515. _("Custom compression level:")));
  516. compressionCheckbox->callback(handleCompression, this);
  517. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  518. compressionInput = new Fl_Int_Input(tx + INDENT, ty,
  519. INPUT_HEIGHT, INPUT_HEIGHT,
  520. _("level (0=fast, 9=best)"));
  521. compressionInput->align(FL_ALIGN_RIGHT);
  522. ty += INPUT_HEIGHT + INNER_MARGIN;
  523. jpegCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  524. CHECK_MIN_WIDTH,
  525. CHECK_HEIGHT,
  526. _("Allow JPEG compression:")));
  527. jpegCheckbox->callback(handleJpeg, this);
  528. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  529. jpegInput = new Fl_Int_Input(tx + INDENT, ty,
  530. INPUT_HEIGHT, INPUT_HEIGHT,
  531. _("quality (0=poor, 9=best)"));
  532. jpegInput->align(FL_ALIGN_RIGHT);
  533. ty += INPUT_HEIGHT + INNER_MARGIN;
  534. group->end();
  535. }
  536. void OptionsDialog::createSecurityPage(int tx, int ty, int tw, int th)
  537. {
  538. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  539. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Security"));
  540. int orig_tx;
  541. int width, height;
  542. tx += OUTER_MARGIN;
  543. ty += OUTER_MARGIN;
  544. width = tw - OUTER_MARGIN * 2;
  545. orig_tx = tx;
  546. /* Encryption */
  547. ty += GROUP_LABEL_OFFSET;
  548. #if defined(HAVE_GNUTLS) && defined(HAVE_NETTLE)
  549. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 5 + CHECK_HEIGHT * 4 + (INPUT_LABEL_OFFSET + INPUT_HEIGHT) * 2;
  550. #elif defined(HAVE_GNUTLS)
  551. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 4 + CHECK_HEIGHT * 3 + (INPUT_LABEL_OFFSET + INPUT_HEIGHT) * 2;
  552. #elif defined(HAVE_NETTLE)
  553. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 1 + CHECK_HEIGHT * 2;
  554. #endif
  555. encryptionGroup = new Fl_Group(tx, ty, width, height, _("Encryption"));
  556. encryptionGroup->box(FL_ENGRAVED_BOX);
  557. encryptionGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  558. {
  559. tx += GROUP_MARGIN;
  560. ty += GROUP_MARGIN;
  561. encNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  562. CHECK_MIN_WIDTH,
  563. CHECK_HEIGHT,
  564. _("None")));
  565. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  566. #ifdef HAVE_GNUTLS
  567. encTLSCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  568. CHECK_MIN_WIDTH,
  569. CHECK_HEIGHT,
  570. _("TLS with anonymous certificates")));
  571. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  572. encX509Checkbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  573. CHECK_MIN_WIDTH,
  574. CHECK_HEIGHT,
  575. _("TLS with X509 certificates")));
  576. encX509Checkbox->callback(handleX509, this);
  577. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  578. ty += INPUT_LABEL_OFFSET;
  579. caInput = new Fl_Input(tx + INDENT, ty,
  580. width - GROUP_MARGIN*2 - INDENT, INPUT_HEIGHT,
  581. _("Path to X509 CA certificate"));
  582. caInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  583. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  584. ty += INPUT_LABEL_OFFSET;
  585. crlInput = new Fl_Input(tx + INDENT, ty,
  586. width - GROUP_MARGIN*2 - INDENT, INPUT_HEIGHT,
  587. _("Path to X509 CRL file"));
  588. crlInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  589. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  590. #endif
  591. #ifdef HAVE_NETTLE
  592. encRSAAESCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  593. CHECK_MIN_WIDTH,
  594. CHECK_HEIGHT,
  595. _("RSA-AES")));
  596. encRSAAESCheckbox->callback(handleRSAAES, this);
  597. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  598. #endif
  599. }
  600. ty += GROUP_MARGIN - TIGHT_MARGIN;
  601. encryptionGroup->end();
  602. /* Back to normal */
  603. tx = orig_tx;
  604. ty += INNER_MARGIN;
  605. /* Authentication */
  606. ty += GROUP_LABEL_OFFSET;
  607. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 2 + CHECK_HEIGHT * 3;
  608. authenticationGroup = new Fl_Group(tx, ty, width, height, _("Authentication"));
  609. authenticationGroup->box(FL_ENGRAVED_BOX);
  610. authenticationGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  611. {
  612. tx += GROUP_MARGIN;
  613. ty += GROUP_MARGIN;
  614. authNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  615. CHECK_MIN_WIDTH,
  616. CHECK_HEIGHT,
  617. _("None")));
  618. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  619. authVncCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  620. CHECK_MIN_WIDTH,
  621. CHECK_HEIGHT,
  622. _("Standard VNC (insecure without encryption)")));
  623. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  624. authPlainCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  625. CHECK_MIN_WIDTH,
  626. CHECK_HEIGHT,
  627. _("Username and password (insecure without encryption)")));
  628. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  629. }
  630. ty += GROUP_MARGIN - TIGHT_MARGIN;
  631. authenticationGroup->end();
  632. /* Back to normal */
  633. tx = orig_tx;
  634. ty += INNER_MARGIN;
  635. group->end();
  636. #endif
  637. }
  638. void OptionsDialog::createInputPage(int tx, int ty, int tw, int th)
  639. {
  640. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Input"));
  641. int orig_tx;
  642. int width;
  643. tx += OUTER_MARGIN;
  644. ty += OUTER_MARGIN;
  645. width = tw - OUTER_MARGIN * 2;
  646. viewOnlyCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  647. CHECK_MIN_WIDTH,
  648. CHECK_HEIGHT,
  649. _("View only (ignore mouse and keyboard)")));
  650. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  651. orig_tx = tx;
  652. /* Mouse */
  653. ty += GROUP_LABEL_OFFSET;
  654. mouseGroup = new Fl_Group(tx, ty, width, 0, _("Mouse"));
  655. mouseGroup->box(FL_ENGRAVED_BOX);
  656. mouseGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  657. /* Needed for final resize to work sanely */
  658. mouseGroup->resizable(NULL);
  659. {
  660. tx += GROUP_MARGIN;
  661. ty += GROUP_MARGIN;
  662. emulateMBCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  663. CHECK_MIN_WIDTH,
  664. CHECK_HEIGHT,
  665. _("Emulate middle mouse button")));
  666. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  667. dotCursorCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  668. CHECK_MIN_WIDTH,
  669. CHECK_HEIGHT,
  670. _("Show dot when no cursor")));
  671. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  672. }
  673. ty += GROUP_MARGIN - TIGHT_MARGIN;
  674. mouseGroup->end();
  675. mouseGroup->size(mouseGroup->w(), ty - mouseGroup->y());
  676. /* Back to normal */
  677. tx = orig_tx;
  678. ty += INNER_MARGIN;
  679. /* Keyboard */
  680. ty += GROUP_LABEL_OFFSET;
  681. keyboardGroup = new Fl_Group(tx, ty, width, 0, _("Keyboard"));
  682. keyboardGroup->box(FL_ENGRAVED_BOX);
  683. keyboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  684. /* Needed for final resize to work sanely */
  685. keyboardGroup->resizable(NULL);
  686. {
  687. tx += GROUP_MARGIN;
  688. ty += GROUP_MARGIN;
  689. systemKeysCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  690. CHECK_MIN_WIDTH,
  691. CHECK_HEIGHT,
  692. _("Pass system keys directly to server (full screen)")));
  693. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  694. menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu key")));
  695. fltk_menu_add(menuKeyChoice, _("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER);
  696. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  697. fltk_menu_add(menuKeyChoice, getMenuKeySymbols()[i].name, 0, NULL, 0, 0);
  698. ty += CHOICE_HEIGHT + TIGHT_MARGIN;
  699. }
  700. ty += GROUP_MARGIN - TIGHT_MARGIN;
  701. keyboardGroup->end();
  702. keyboardGroup->size(keyboardGroup->w(), ty - keyboardGroup->y());
  703. /* Back to normal */
  704. tx = orig_tx;
  705. ty += INNER_MARGIN;
  706. /* Clipboard */
  707. ty += GROUP_LABEL_OFFSET;
  708. clipboardGroup = new Fl_Group(tx, ty, width, 0, _("Clipboard"));
  709. clipboardGroup->box(FL_ENGRAVED_BOX);
  710. clipboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  711. /* Needed for final resize to work sanely */
  712. clipboardGroup->resizable(NULL);
  713. {
  714. tx += GROUP_MARGIN;
  715. ty += GROUP_MARGIN;
  716. acceptClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  717. CHECK_MIN_WIDTH,
  718. CHECK_HEIGHT,
  719. _("Accept clipboard from server")));
  720. acceptClipboardCheckbox->callback(handleClipboard, this);
  721. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  722. #if !defined(WIN32) && !defined(__APPLE__)
  723. setPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  724. CHECK_MIN_WIDTH,
  725. CHECK_HEIGHT,
  726. _("Also set primary selection")));
  727. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  728. #endif
  729. sendClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  730. CHECK_MIN_WIDTH,
  731. CHECK_HEIGHT,
  732. _("Send clipboard to server")));
  733. sendClipboardCheckbox->callback(handleClipboard, this);
  734. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  735. #if !defined(WIN32) && !defined(__APPLE__)
  736. sendPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  737. CHECK_MIN_WIDTH,
  738. CHECK_HEIGHT,
  739. _("Send primary selection as clipboard")));
  740. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  741. #endif
  742. }
  743. ty += GROUP_MARGIN - TIGHT_MARGIN;
  744. clipboardGroup->end();
  745. clipboardGroup->size(clipboardGroup->w(), ty - clipboardGroup->y());
  746. /* Back to normal */
  747. tx = orig_tx;
  748. ty += INNER_MARGIN;
  749. group->end();
  750. }
  751. void OptionsDialog::createDisplayPage(int tx, int ty, int tw, int th)
  752. {
  753. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Display"));
  754. int orig_tx;
  755. int width;
  756. tx += OUTER_MARGIN;
  757. ty += OUTER_MARGIN;
  758. width = tw - OUTER_MARGIN * 2;
  759. orig_tx = tx;
  760. /* Display mode */
  761. ty += GROUP_LABEL_OFFSET;
  762. displayModeGroup = new Fl_Group(tx, ty, width, 0, _("Display mode"));
  763. displayModeGroup->box(FL_ENGRAVED_BOX);
  764. displayModeGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  765. /* Needed for final resize to work sanely */
  766. displayModeGroup->resizable(NULL);
  767. {
  768. tx += GROUP_MARGIN;
  769. ty += GROUP_MARGIN;
  770. width -= GROUP_MARGIN * 2;
  771. windowedButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  772. RADIO_MIN_WIDTH,
  773. RADIO_HEIGHT,
  774. _("Windowed")));
  775. windowedButton->type(FL_RADIO_BUTTON);
  776. windowedButton->callback(handleFullScreenMode, this);
  777. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  778. currentMonitorButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  779. RADIO_MIN_WIDTH,
  780. RADIO_HEIGHT,
  781. _("Full screen on current monitor")));
  782. currentMonitorButton->type(FL_RADIO_BUTTON);
  783. currentMonitorButton->callback(handleFullScreenMode, this);
  784. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  785. allMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  786. RADIO_MIN_WIDTH,
  787. RADIO_HEIGHT,
  788. _("Full screen on all monitors")));
  789. allMonitorsButton->type(FL_RADIO_BUTTON);
  790. allMonitorsButton->callback(handleFullScreenMode, this);
  791. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  792. selectedMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  793. RADIO_MIN_WIDTH,
  794. RADIO_HEIGHT,
  795. _("Full screen on selected monitor(s)")));
  796. selectedMonitorsButton->type(FL_RADIO_BUTTON);
  797. selectedMonitorsButton->callback(handleFullScreenMode, this);
  798. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  799. monitorArrangement = new MonitorArrangement(
  800. tx + INDENT, ty,
  801. width - INDENT, 150);
  802. ty += 150 + TIGHT_MARGIN;
  803. }
  804. ty += GROUP_MARGIN - TIGHT_MARGIN;
  805. displayModeGroup->end();
  806. displayModeGroup->size(displayModeGroup->w(),
  807. ty - displayModeGroup->y());
  808. /* Back to normal */
  809. tx = orig_tx;
  810. ty += INNER_MARGIN;
  811. width = tw - OUTER_MARGIN * 2;
  812. group->end();
  813. }
  814. void OptionsDialog::createMiscPage(int tx, int ty, int tw, int th)
  815. {
  816. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Misc."));
  817. tx += OUTER_MARGIN;
  818. ty += OUTER_MARGIN;
  819. sharedCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  820. CHECK_MIN_WIDTH,
  821. CHECK_HEIGHT,
  822. _("Shared (don't disconnect other viewers)")));
  823. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  824. reconnectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  825. CHECK_MIN_WIDTH,
  826. CHECK_HEIGHT,
  827. _("Ask to reconnect on connection errors")));
  828. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  829. group->end();
  830. }
  831. void OptionsDialog::handleAutoselect(Fl_Widget *widget, void *data)
  832. {
  833. OptionsDialog *dialog = (OptionsDialog*)data;
  834. if (dialog->autoselectCheckbox->value()) {
  835. dialog->encodingGroup->deactivate();
  836. dialog->colorlevelGroup->deactivate();
  837. } else {
  838. dialog->encodingGroup->activate();
  839. dialog->colorlevelGroup->activate();
  840. }
  841. // JPEG setting is also affected by autoselection
  842. dialog->handleJpeg(dialog->jpegCheckbox, dialog);
  843. }
  844. void OptionsDialog::handleCompression(Fl_Widget *widget, void *data)
  845. {
  846. OptionsDialog *dialog = (OptionsDialog*)data;
  847. if (dialog->compressionCheckbox->value())
  848. dialog->compressionInput->activate();
  849. else
  850. dialog->compressionInput->deactivate();
  851. }
  852. void OptionsDialog::handleJpeg(Fl_Widget *widget, void *data)
  853. {
  854. OptionsDialog *dialog = (OptionsDialog*)data;
  855. if (dialog->jpegCheckbox->value() &&
  856. !dialog->autoselectCheckbox->value())
  857. dialog->jpegInput->activate();
  858. else
  859. dialog->jpegInput->deactivate();
  860. }
  861. void OptionsDialog::handleX509(Fl_Widget *widget, void *data)
  862. {
  863. OptionsDialog *dialog = (OptionsDialog*)data;
  864. if (dialog->encX509Checkbox->value()) {
  865. dialog->caInput->activate();
  866. dialog->crlInput->activate();
  867. } else {
  868. dialog->caInput->deactivate();
  869. dialog->crlInput->deactivate();
  870. }
  871. }
  872. void OptionsDialog::handleRSAAES(Fl_Widget *widget, void *data)
  873. {
  874. OptionsDialog *dialog = (OptionsDialog*)data;
  875. if (dialog->encRSAAESCheckbox->value()) {
  876. dialog->authVncCheckbox->value(true);
  877. dialog->authPlainCheckbox->value(true);
  878. }
  879. }
  880. void OptionsDialog::handleClipboard(Fl_Widget *widget, void *data)
  881. {
  882. #if !defined(WIN32) && !defined(__APPLE__)
  883. OptionsDialog *dialog = (OptionsDialog*)data;
  884. if (dialog->acceptClipboardCheckbox->value())
  885. dialog->setPrimaryCheckbox->activate();
  886. else
  887. dialog->setPrimaryCheckbox->deactivate();
  888. if (dialog->sendClipboardCheckbox->value())
  889. dialog->sendPrimaryCheckbox->activate();
  890. else
  891. dialog->sendPrimaryCheckbox->deactivate();
  892. #endif
  893. }
  894. void OptionsDialog::handleFullScreenMode(Fl_Widget *widget, void *data)
  895. {
  896. OptionsDialog *dialog = (OptionsDialog*)data;
  897. if (dialog->selectedMonitorsButton->value()) {
  898. dialog->monitorArrangement->activate();
  899. } else {
  900. dialog->monitorArrangement->deactivate();
  901. }
  902. }
  903. void OptionsDialog::handleCancel(Fl_Widget *widget, void *data)
  904. {
  905. OptionsDialog *dialog = (OptionsDialog*)data;
  906. dialog->hide();
  907. }
  908. void OptionsDialog::handleOK(Fl_Widget *widget, void *data)
  909. {
  910. OptionsDialog *dialog = (OptionsDialog*)data;
  911. dialog->hide();
  912. dialog->storeOptions();
  913. }
  914. int OptionsDialog::fltk_event_handler(int event)
  915. {
  916. std::set<OptionsDialog *>::iterator iter;
  917. if (event != FL_SCREEN_CONFIGURATION_CHANGED)
  918. return 0;
  919. // Refresh monitor arrangement widget to match the parameter settings after
  920. // screen configuration has changed. The MonitorArrangement index doesn't work
  921. // the same way as the FLTK screen index.
  922. for (iter = instances.begin(); iter != instances.end(); iter++)
  923. Fl::add_timeout(0, handleScreenConfigTimeout, (*iter));
  924. return 0;
  925. }
  926. void OptionsDialog::handleScreenConfigTimeout(void *data)
  927. {
  928. OptionsDialog *self = (OptionsDialog *)data;
  929. assert(self);
  930. self->monitorArrangement->set(fullScreenSelectedMonitors.getParam());
  931. }