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

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