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 35KB

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