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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. /* fall through */
  247. case secTypeDH:
  248. case secTypeMSLogonII:
  249. encNoneCheckbox->value(true);
  250. authPlainCheckbox->value(true);
  251. break;
  252. #endif
  253. }
  254. }
  255. #ifdef HAVE_GNUTLS
  256. caInput->value(CSecurityTLS::X509CA);
  257. crlInput->value(CSecurityTLS::X509CRL);
  258. handleX509(encX509Checkbox, this);
  259. #endif
  260. #endif
  261. /* Input */
  262. const char *menuKeyBuf;
  263. viewOnlyCheckbox->value(viewOnly);
  264. emulateMBCheckbox->value(emulateMiddleButton);
  265. acceptClipboardCheckbox->value(acceptClipboard);
  266. #if !defined(WIN32) && !defined(__APPLE__)
  267. setPrimaryCheckbox->value(setPrimary);
  268. #endif
  269. sendClipboardCheckbox->value(sendClipboard);
  270. #if !defined(WIN32) && !defined(__APPLE__)
  271. sendPrimaryCheckbox->value(sendPrimary);
  272. #endif
  273. systemKeysCheckbox->value(fullscreenSystemKeys);
  274. menuKeyChoice->value(0);
  275. menuKeyBuf = menuKey;
  276. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  277. if (!strcmp(getMenuKeySymbols()[i].name, menuKeyBuf))
  278. menuKeyChoice->value(i + 1);
  279. /* Display */
  280. if (!fullScreen) {
  281. windowedButton->setonly();
  282. } else {
  283. if (!strcasecmp(fullScreenMode, "all")) {
  284. allMonitorsButton->setonly();
  285. } else if (!strcasecmp(fullScreenMode, "selected")) {
  286. selectedMonitorsButton->setonly();
  287. } else {
  288. currentMonitorButton->setonly();
  289. }
  290. }
  291. monitorArrangement->value(fullScreenSelectedMonitors.getParam());
  292. handleFullScreenMode(selectedMonitorsButton, this);
  293. /* Misc. */
  294. sharedCheckbox->value(shared);
  295. reconnectCheckbox->value(reconnectOnError);
  296. dotCursorCheckbox->value(dotWhenNoCursor);
  297. }
  298. void OptionsDialog::storeOptions(void)
  299. {
  300. /* Compression */
  301. autoSelect.setParam(autoselectCheckbox->value());
  302. if (tightButton->value())
  303. preferredEncoding.setParam(encodingName(encodingTight));
  304. else if (zrleButton->value())
  305. preferredEncoding.setParam(encodingName(encodingZRLE));
  306. else if (hextileButton->value())
  307. preferredEncoding.setParam(encodingName(encodingHextile));
  308. #ifdef HAVE_H264
  309. else if (h264Button->value())
  310. preferredEncoding.setParam(encodingName(encodingH264));
  311. #endif
  312. else if (rawButton->value())
  313. preferredEncoding.setParam(encodingName(encodingRaw));
  314. fullColour.setParam(fullcolorCheckbox->value());
  315. if (verylowcolorCheckbox->value())
  316. lowColourLevel.setParam(0);
  317. else if (lowcolorCheckbox->value())
  318. lowColourLevel.setParam(1);
  319. else if (mediumcolorCheckbox->value())
  320. lowColourLevel.setParam(2);
  321. customCompressLevel.setParam(compressionCheckbox->value());
  322. noJpeg.setParam(!jpegCheckbox->value());
  323. compressLevel.setParam(atoi(compressionInput->value()));
  324. qualityLevel.setParam(atoi(jpegInput->value()));
  325. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  326. /* Security */
  327. Security security;
  328. /* Process security types which don't use encryption */
  329. if (encNoneCheckbox->value()) {
  330. if (authNoneCheckbox->value())
  331. security.EnableSecType(secTypeNone);
  332. if (authVncCheckbox->value()) {
  333. security.EnableSecType(secTypeVncAuth);
  334. #ifdef HAVE_NETTLE
  335. security.EnableSecType(secTypeRA2ne);
  336. security.EnableSecType(secTypeRAne256);
  337. #endif
  338. }
  339. if (authPlainCheckbox->value()) {
  340. security.EnableSecType(secTypePlain);
  341. #ifdef HAVE_NETTLE
  342. security.EnableSecType(secTypeRA2ne);
  343. security.EnableSecType(secTypeRAne256);
  344. security.EnableSecType(secTypeDH);
  345. security.EnableSecType(secTypeMSLogonII);
  346. #endif
  347. }
  348. }
  349. #ifdef HAVE_GNUTLS
  350. /* Process security types which use TLS encryption */
  351. if (encTLSCheckbox->value()) {
  352. if (authNoneCheckbox->value())
  353. security.EnableSecType(secTypeTLSNone);
  354. if (authVncCheckbox->value())
  355. security.EnableSecType(secTypeTLSVnc);
  356. if (authPlainCheckbox->value())
  357. security.EnableSecType(secTypeTLSPlain);
  358. }
  359. /* Process security types which use X509 encryption */
  360. if (encX509Checkbox->value()) {
  361. if (authNoneCheckbox->value())
  362. security.EnableSecType(secTypeX509None);
  363. if (authVncCheckbox->value())
  364. security.EnableSecType(secTypeX509Vnc);
  365. if (authPlainCheckbox->value())
  366. security.EnableSecType(secTypeX509Plain);
  367. }
  368. CSecurityTLS::X509CA.setParam(caInput->value());
  369. CSecurityTLS::X509CRL.setParam(crlInput->value());
  370. #endif
  371. #ifdef HAVE_NETTLE
  372. if (encRSAAESCheckbox->value()) {
  373. security.EnableSecType(secTypeRA2);
  374. security.EnableSecType(secTypeRA256);
  375. }
  376. #endif
  377. SecurityClient::secTypes.setParam(security.ToString());
  378. #endif
  379. /* Input */
  380. viewOnly.setParam(viewOnlyCheckbox->value());
  381. emulateMiddleButton.setParam(emulateMBCheckbox->value());
  382. acceptClipboard.setParam(acceptClipboardCheckbox->value());
  383. #if !defined(WIN32) && !defined(__APPLE__)
  384. setPrimary.setParam(setPrimaryCheckbox->value());
  385. #endif
  386. sendClipboard.setParam(sendClipboardCheckbox->value());
  387. #if !defined(WIN32) && !defined(__APPLE__)
  388. sendPrimary.setParam(sendPrimaryCheckbox->value());
  389. #endif
  390. fullscreenSystemKeys.setParam(systemKeysCheckbox->value());
  391. if (menuKeyChoice->value() == 0)
  392. menuKey.setParam("");
  393. else {
  394. menuKey.setParam(menuKeyChoice->text());
  395. }
  396. /* Display */
  397. if (windowedButton->value()) {
  398. fullScreen.setParam(false);
  399. } else {
  400. fullScreen.setParam(true);
  401. if (allMonitorsButton->value()) {
  402. fullScreenMode.setParam("All");
  403. } else if (selectedMonitorsButton->value()) {
  404. fullScreenMode.setParam("Selected");
  405. } else {
  406. fullScreenMode.setParam("Current");
  407. }
  408. }
  409. fullScreenSelectedMonitors.setParam(monitorArrangement->value());
  410. /* Misc. */
  411. shared.setParam(sharedCheckbox->value());
  412. reconnectOnError.setParam(reconnectCheckbox->value());
  413. dotWhenNoCursor.setParam(dotCursorCheckbox->value());
  414. std::map<OptionsCallback*, void*>::const_iterator iter;
  415. for (iter = callbacks.begin();iter != callbacks.end();++iter)
  416. iter->first(iter->second);
  417. }
  418. void OptionsDialog::createCompressionPage(int tx, int ty, int tw, int th)
  419. {
  420. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Compression"));
  421. int orig_tx, orig_ty;
  422. int col1_ty, col2_ty;
  423. int half_width, full_width;
  424. tx += OUTER_MARGIN;
  425. ty += OUTER_MARGIN;
  426. full_width = tw - OUTER_MARGIN * 2;
  427. half_width = (full_width - INNER_MARGIN) / 2;
  428. /* AutoSelect checkbox */
  429. autoselectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  430. CHECK_MIN_WIDTH,
  431. CHECK_HEIGHT,
  432. _("Auto select")));
  433. autoselectCheckbox->callback(handleAutoselect, this);
  434. ty += CHECK_HEIGHT + INNER_MARGIN;
  435. /* Two columns */
  436. orig_tx = tx;
  437. orig_ty = ty;
  438. /* VNC encoding box */
  439. ty += GROUP_LABEL_OFFSET;
  440. encodingGroup = new Fl_Group(tx, ty, half_width, 0,
  441. _("Preferred encoding"));
  442. encodingGroup->box(FL_FLAT_BOX);
  443. encodingGroup->labelfont(FL_BOLD);
  444. encodingGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  445. {
  446. tx += INDENT;
  447. ty += TIGHT_MARGIN;
  448. tightButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  449. RADIO_MIN_WIDTH,
  450. RADIO_HEIGHT,
  451. "Tight"));
  452. tightButton->type(FL_RADIO_BUTTON);
  453. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  454. zrleButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  455. RADIO_MIN_WIDTH,
  456. RADIO_HEIGHT,
  457. "ZRLE"));
  458. zrleButton->type(FL_RADIO_BUTTON);
  459. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  460. hextileButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  461. RADIO_MIN_WIDTH,
  462. RADIO_HEIGHT,
  463. "Hextile"));
  464. hextileButton->type(FL_RADIO_BUTTON);
  465. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  466. #ifdef HAVE_H264
  467. h264Button = new Fl_Round_Button(LBLRIGHT(tx, ty,
  468. RADIO_MIN_WIDTH,
  469. RADIO_HEIGHT,
  470. "H.264"));
  471. h264Button->type(FL_RADIO_BUTTON);
  472. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  473. #endif
  474. rawButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  475. RADIO_MIN_WIDTH,
  476. RADIO_HEIGHT,
  477. "Raw"));
  478. rawButton->type(FL_RADIO_BUTTON);
  479. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  480. }
  481. ty -= TIGHT_MARGIN;
  482. encodingGroup->end();
  483. /* Needed for resize to work sanely */
  484. encodingGroup->resizable(NULL);
  485. encodingGroup->size(encodingGroup->w(), ty - encodingGroup->y());
  486. col1_ty = ty;
  487. /* Second column */
  488. tx = orig_tx + half_width + INNER_MARGIN;
  489. ty = orig_ty;
  490. /* Color box */
  491. ty += GROUP_LABEL_OFFSET;
  492. colorlevelGroup = new Fl_Group(tx, ty, half_width, 0, _("Color level"));
  493. colorlevelGroup->labelfont(FL_BOLD);
  494. colorlevelGroup->box(FL_FLAT_BOX);
  495. colorlevelGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  496. {
  497. tx += INDENT;
  498. ty += TIGHT_MARGIN;
  499. fullcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  500. RADIO_MIN_WIDTH,
  501. RADIO_HEIGHT,
  502. _("Full")));
  503. fullcolorCheckbox->type(FL_RADIO_BUTTON);
  504. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  505. mediumcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  506. RADIO_MIN_WIDTH,
  507. RADIO_HEIGHT,
  508. _("Medium")));
  509. mediumcolorCheckbox->type(FL_RADIO_BUTTON);
  510. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  511. lowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  512. RADIO_MIN_WIDTH,
  513. RADIO_HEIGHT,
  514. _("Low")));
  515. lowcolorCheckbox->type(FL_RADIO_BUTTON);
  516. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  517. verylowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  518. RADIO_MIN_WIDTH,
  519. RADIO_HEIGHT,
  520. _("Very low")));
  521. verylowcolorCheckbox->type(FL_RADIO_BUTTON);
  522. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  523. }
  524. ty -= TIGHT_MARGIN;
  525. colorlevelGroup->end();
  526. /* Needed for resize to work sanely */
  527. colorlevelGroup->resizable(NULL);
  528. colorlevelGroup->size(colorlevelGroup->w(),
  529. ty - colorlevelGroup->y());
  530. col2_ty = ty;
  531. /* Back to normal */
  532. tx = orig_tx;
  533. ty = (col1_ty > col2_ty ? col1_ty : col2_ty) + INNER_MARGIN;
  534. /* Checkboxes */
  535. compressionCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  536. CHECK_MIN_WIDTH,
  537. CHECK_HEIGHT,
  538. _("Custom compression level:")));
  539. compressionCheckbox->labelfont(FL_BOLD);
  540. compressionCheckbox->callback(handleCompression, this);
  541. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  542. compressionInput = new Fl_Int_Input(tx + INDENT, ty,
  543. INPUT_HEIGHT, INPUT_HEIGHT,
  544. _("level (0=fast, 9=best)"));
  545. compressionInput->align(FL_ALIGN_RIGHT);
  546. ty += INPUT_HEIGHT + INNER_MARGIN;
  547. jpegCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  548. CHECK_MIN_WIDTH,
  549. CHECK_HEIGHT,
  550. _("Allow JPEG compression:")));
  551. jpegCheckbox->labelfont(FL_BOLD);
  552. jpegCheckbox->callback(handleJpeg, this);
  553. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  554. jpegInput = new Fl_Int_Input(tx + INDENT, ty,
  555. INPUT_HEIGHT, INPUT_HEIGHT,
  556. _("quality (0=poor, 9=best)"));
  557. jpegInput->align(FL_ALIGN_RIGHT);
  558. ty += INPUT_HEIGHT + INNER_MARGIN;
  559. group->end();
  560. }
  561. void OptionsDialog::createSecurityPage(int tx, int ty, int tw, int th)
  562. {
  563. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  564. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Security"));
  565. int orig_tx;
  566. int width;
  567. tx += OUTER_MARGIN;
  568. ty += OUTER_MARGIN;
  569. width = tw - OUTER_MARGIN * 2;
  570. orig_tx = tx;
  571. /* Encryption */
  572. ty += GROUP_LABEL_OFFSET;
  573. encryptionGroup = new Fl_Group(tx, ty, width, 0, _("Encryption"));
  574. encryptionGroup->labelfont(FL_BOLD);
  575. encryptionGroup->box(FL_FLAT_BOX);
  576. encryptionGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  577. {
  578. tx += INDENT;
  579. ty += TIGHT_MARGIN;
  580. encNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  581. CHECK_MIN_WIDTH,
  582. CHECK_HEIGHT,
  583. _("None")));
  584. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  585. #ifdef HAVE_GNUTLS
  586. encTLSCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  587. CHECK_MIN_WIDTH,
  588. CHECK_HEIGHT,
  589. _("TLS with anonymous certificates")));
  590. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  591. encX509Checkbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  592. CHECK_MIN_WIDTH,
  593. CHECK_HEIGHT,
  594. _("TLS with X509 certificates")));
  595. encX509Checkbox->callback(handleX509, this);
  596. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  597. ty += INPUT_LABEL_OFFSET;
  598. caInput = new Fl_Input(tx + INDENT, ty,
  599. width - INDENT * 2, INPUT_HEIGHT,
  600. _("Path to X509 CA certificate"));
  601. caInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  602. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  603. ty += INPUT_LABEL_OFFSET;
  604. crlInput = new Fl_Input(tx + INDENT, ty,
  605. width - INDENT * 2, INPUT_HEIGHT,
  606. _("Path to X509 CRL file"));
  607. crlInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  608. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  609. #endif
  610. #ifdef HAVE_NETTLE
  611. encRSAAESCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  612. CHECK_MIN_WIDTH,
  613. CHECK_HEIGHT,
  614. "RSA-AES"));
  615. encRSAAESCheckbox->callback(handleRSAAES, this);
  616. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  617. #endif
  618. }
  619. ty -= TIGHT_MARGIN;
  620. encryptionGroup->end();
  621. /* Needed for resize to work sanely */
  622. encryptionGroup->resizable(NULL);
  623. encryptionGroup->size(encryptionGroup->w(),
  624. ty - encryptionGroup->y());
  625. /* Back to normal */
  626. tx = orig_tx;
  627. ty += INNER_MARGIN;
  628. /* Authentication */
  629. ty += GROUP_LABEL_OFFSET;
  630. authenticationGroup = new Fl_Group(tx, ty, width, 0, _("Authentication"));
  631. authenticationGroup->labelfont(FL_BOLD);
  632. authenticationGroup->box(FL_FLAT_BOX);
  633. authenticationGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  634. {
  635. tx += INDENT;
  636. ty += TIGHT_MARGIN;
  637. authNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  638. CHECK_MIN_WIDTH,
  639. CHECK_HEIGHT,
  640. _("None")));
  641. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  642. authVncCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  643. CHECK_MIN_WIDTH,
  644. CHECK_HEIGHT,
  645. _("Standard VNC (insecure without encryption)")));
  646. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  647. authPlainCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  648. CHECK_MIN_WIDTH,
  649. CHECK_HEIGHT,
  650. _("Username and password (insecure without encryption)")));
  651. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  652. }
  653. ty -= TIGHT_MARGIN;
  654. authenticationGroup->end();
  655. /* Needed for resize to work sanely */
  656. authenticationGroup->resizable(NULL);
  657. authenticationGroup->size(authenticationGroup->w(),
  658. ty - authenticationGroup->y());
  659. /* Back to normal */
  660. tx = orig_tx;
  661. ty += INNER_MARGIN;
  662. group->end();
  663. #endif
  664. }
  665. void OptionsDialog::createInputPage(int tx, int ty, int tw, int th)
  666. {
  667. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Input"));
  668. int orig_tx;
  669. int width;
  670. tx += OUTER_MARGIN;
  671. ty += OUTER_MARGIN;
  672. width = tw - OUTER_MARGIN * 2;
  673. viewOnlyCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  674. CHECK_MIN_WIDTH,
  675. CHECK_HEIGHT,
  676. _("View only (ignore mouse and keyboard)")));
  677. ty += CHECK_HEIGHT + INNER_MARGIN;
  678. orig_tx = tx;
  679. /* Mouse */
  680. ty += GROUP_LABEL_OFFSET;
  681. mouseGroup = new Fl_Group(tx, ty, width, 0, _("Mouse"));
  682. mouseGroup->labelfont(FL_BOLD);
  683. mouseGroup->box(FL_FLAT_BOX);
  684. mouseGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  685. {
  686. tx += INDENT;
  687. ty += TIGHT_MARGIN;
  688. emulateMBCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  689. CHECK_MIN_WIDTH,
  690. CHECK_HEIGHT,
  691. _("Emulate middle mouse button")));
  692. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  693. dotCursorCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  694. CHECK_MIN_WIDTH,
  695. CHECK_HEIGHT,
  696. _("Show dot when no cursor")));
  697. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  698. }
  699. ty -= TIGHT_MARGIN;
  700. mouseGroup->end();
  701. /* Needed for resize to work sanely */
  702. mouseGroup->resizable(NULL);
  703. mouseGroup->size(mouseGroup->w(), ty - mouseGroup->y());
  704. /* Back to normal */
  705. tx = orig_tx;
  706. ty += INNER_MARGIN;
  707. /* Keyboard */
  708. ty += GROUP_LABEL_OFFSET;
  709. keyboardGroup = new Fl_Group(tx, ty, width, 0, _("Keyboard"));
  710. keyboardGroup->labelfont(FL_BOLD);
  711. keyboardGroup->box(FL_FLAT_BOX);
  712. keyboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  713. {
  714. tx += INDENT;
  715. ty += TIGHT_MARGIN;
  716. systemKeysCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  717. CHECK_MIN_WIDTH,
  718. CHECK_HEIGHT,
  719. _("Pass system keys directly to server (full screen)")));
  720. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  721. menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu key")));
  722. fltk_menu_add(menuKeyChoice, _("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER);
  723. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  724. fltk_menu_add(menuKeyChoice, getMenuKeySymbols()[i].name, 0, NULL, 0, 0);
  725. ty += CHOICE_HEIGHT + TIGHT_MARGIN;
  726. }
  727. ty -= TIGHT_MARGIN;
  728. keyboardGroup->end();
  729. /* Needed for resize to work sanely */
  730. keyboardGroup->resizable(NULL);
  731. keyboardGroup->size(keyboardGroup->w(), ty - keyboardGroup->y());
  732. /* Back to normal */
  733. tx = orig_tx;
  734. ty += INNER_MARGIN;
  735. /* Clipboard */
  736. ty += GROUP_LABEL_OFFSET;
  737. clipboardGroup = new Fl_Group(tx, ty, width, 0, _("Clipboard"));
  738. clipboardGroup->labelfont(FL_BOLD);
  739. clipboardGroup->box(FL_FLAT_BOX);
  740. clipboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  741. {
  742. tx += INDENT;
  743. ty += TIGHT_MARGIN;
  744. acceptClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  745. CHECK_MIN_WIDTH,
  746. CHECK_HEIGHT,
  747. _("Accept clipboard from server")));
  748. acceptClipboardCheckbox->callback(handleClipboard, this);
  749. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  750. #if !defined(WIN32) && !defined(__APPLE__)
  751. setPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  752. CHECK_MIN_WIDTH,
  753. CHECK_HEIGHT,
  754. _("Also set primary selection")));
  755. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  756. #endif
  757. sendClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  758. CHECK_MIN_WIDTH,
  759. CHECK_HEIGHT,
  760. _("Send clipboard to server")));
  761. sendClipboardCheckbox->callback(handleClipboard, this);
  762. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  763. #if !defined(WIN32) && !defined(__APPLE__)
  764. sendPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  765. CHECK_MIN_WIDTH,
  766. CHECK_HEIGHT,
  767. _("Send primary selection as clipboard")));
  768. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  769. #endif
  770. }
  771. ty -= TIGHT_MARGIN;
  772. clipboardGroup->end();
  773. /* Needed for resize to work sanely */
  774. clipboardGroup->resizable(NULL);
  775. clipboardGroup->size(clipboardGroup->w(), ty - clipboardGroup->y());
  776. /* Back to normal */
  777. tx = orig_tx;
  778. ty += INNER_MARGIN;
  779. group->end();
  780. }
  781. void OptionsDialog::createDisplayPage(int tx, int ty, int tw, int th)
  782. {
  783. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Display"));
  784. int orig_tx;
  785. int width;
  786. tx += OUTER_MARGIN;
  787. ty += OUTER_MARGIN;
  788. width = tw - OUTER_MARGIN * 2;
  789. orig_tx = tx;
  790. /* Display mode */
  791. ty += GROUP_LABEL_OFFSET;
  792. displayModeGroup = new Fl_Group(tx, ty, width, 0, _("Display mode"));
  793. displayModeGroup->labelfont(FL_BOLD);
  794. displayModeGroup->box(FL_FLAT_BOX);
  795. displayModeGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  796. {
  797. tx += INDENT;
  798. ty += TIGHT_MARGIN;
  799. width -= INDENT;
  800. windowedButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  801. RADIO_MIN_WIDTH,
  802. RADIO_HEIGHT,
  803. _("Windowed")));
  804. windowedButton->type(FL_RADIO_BUTTON);
  805. windowedButton->callback(handleFullScreenMode, this);
  806. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  807. currentMonitorButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  808. RADIO_MIN_WIDTH,
  809. RADIO_HEIGHT,
  810. _("Full screen on current monitor")));
  811. currentMonitorButton->type(FL_RADIO_BUTTON);
  812. currentMonitorButton->callback(handleFullScreenMode, this);
  813. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  814. allMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  815. RADIO_MIN_WIDTH,
  816. RADIO_HEIGHT,
  817. _("Full screen on all monitors")));
  818. allMonitorsButton->type(FL_RADIO_BUTTON);
  819. allMonitorsButton->callback(handleFullScreenMode, this);
  820. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  821. selectedMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  822. RADIO_MIN_WIDTH,
  823. RADIO_HEIGHT,
  824. _("Full screen on selected monitor(s)")));
  825. selectedMonitorsButton->type(FL_RADIO_BUTTON);
  826. selectedMonitorsButton->callback(handleFullScreenMode, this);
  827. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  828. monitorArrangement = new Fl_Monitor_Arrangement(
  829. tx + INDENT, ty,
  830. width - INDENT, 150);
  831. ty += 150 + TIGHT_MARGIN;
  832. }
  833. ty -= TIGHT_MARGIN;
  834. displayModeGroup->end();
  835. /* Needed for resize to work sanely */
  836. displayModeGroup->resizable(NULL);
  837. displayModeGroup->size(displayModeGroup->w(),
  838. ty - displayModeGroup->y());
  839. /* Back to normal */
  840. tx = orig_tx;
  841. ty += INNER_MARGIN;
  842. width = tw - OUTER_MARGIN * 2;
  843. group->end();
  844. }
  845. void OptionsDialog::createMiscPage(int tx, int ty, int tw, int th)
  846. {
  847. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Miscellaneous"));
  848. tx += OUTER_MARGIN;
  849. ty += OUTER_MARGIN;
  850. sharedCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  851. CHECK_MIN_WIDTH,
  852. CHECK_HEIGHT,
  853. _("Shared (don't disconnect other viewers)")));
  854. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  855. reconnectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  856. CHECK_MIN_WIDTH,
  857. CHECK_HEIGHT,
  858. _("Ask to reconnect on connection errors")));
  859. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  860. group->end();
  861. }
  862. void OptionsDialog::handleAutoselect(Fl_Widget* /*widget*/, void *data)
  863. {
  864. OptionsDialog *dialog = (OptionsDialog*)data;
  865. if (dialog->autoselectCheckbox->value()) {
  866. dialog->encodingGroup->deactivate();
  867. dialog->colorlevelGroup->deactivate();
  868. } else {
  869. dialog->encodingGroup->activate();
  870. dialog->colorlevelGroup->activate();
  871. }
  872. // JPEG setting is also affected by autoselection
  873. dialog->handleJpeg(dialog->jpegCheckbox, dialog);
  874. }
  875. void OptionsDialog::handleCompression(Fl_Widget* /*widget*/, void *data)
  876. {
  877. OptionsDialog *dialog = (OptionsDialog*)data;
  878. if (dialog->compressionCheckbox->value())
  879. dialog->compressionInput->activate();
  880. else
  881. dialog->compressionInput->deactivate();
  882. }
  883. void OptionsDialog::handleJpeg(Fl_Widget* /*widget*/, void *data)
  884. {
  885. OptionsDialog *dialog = (OptionsDialog*)data;
  886. if (dialog->jpegCheckbox->value() &&
  887. !dialog->autoselectCheckbox->value())
  888. dialog->jpegInput->activate();
  889. else
  890. dialog->jpegInput->deactivate();
  891. }
  892. void OptionsDialog::handleX509(Fl_Widget* /*widget*/, void *data)
  893. {
  894. OptionsDialog *dialog = (OptionsDialog*)data;
  895. if (dialog->encX509Checkbox->value()) {
  896. dialog->caInput->activate();
  897. dialog->crlInput->activate();
  898. } else {
  899. dialog->caInput->deactivate();
  900. dialog->crlInput->deactivate();
  901. }
  902. }
  903. void OptionsDialog::handleRSAAES(Fl_Widget* /*widget*/, void *data)
  904. {
  905. OptionsDialog *dialog = (OptionsDialog*)data;
  906. if (dialog->encRSAAESCheckbox->value()) {
  907. dialog->authVncCheckbox->value(true);
  908. dialog->authPlainCheckbox->value(true);
  909. }
  910. }
  911. void OptionsDialog::handleClipboard(Fl_Widget* /*widget*/, void *data)
  912. {
  913. (void)data;
  914. #if !defined(WIN32) && !defined(__APPLE__)
  915. OptionsDialog *dialog = (OptionsDialog*)data;
  916. if (dialog->acceptClipboardCheckbox->value())
  917. dialog->setPrimaryCheckbox->activate();
  918. else
  919. dialog->setPrimaryCheckbox->deactivate();
  920. if (dialog->sendClipboardCheckbox->value())
  921. dialog->sendPrimaryCheckbox->activate();
  922. else
  923. dialog->sendPrimaryCheckbox->deactivate();
  924. #endif
  925. }
  926. void OptionsDialog::handleFullScreenMode(Fl_Widget* /*widget*/, void *data)
  927. {
  928. OptionsDialog *dialog = (OptionsDialog*)data;
  929. if (dialog->selectedMonitorsButton->value()) {
  930. dialog->monitorArrangement->activate();
  931. } else {
  932. dialog->monitorArrangement->deactivate();
  933. }
  934. }
  935. void OptionsDialog::handleCancel(Fl_Widget* /*widget*/, void *data)
  936. {
  937. OptionsDialog *dialog = (OptionsDialog*)data;
  938. dialog->hide();
  939. }
  940. void OptionsDialog::handleOK(Fl_Widget* /*widget*/, void *data)
  941. {
  942. OptionsDialog *dialog = (OptionsDialog*)data;
  943. dialog->hide();
  944. dialog->storeOptions();
  945. }
  946. int OptionsDialog::fltk_event_handler(int event)
  947. {
  948. std::set<OptionsDialog *>::iterator iter;
  949. if (event != FL_SCREEN_CONFIGURATION_CHANGED)
  950. return 0;
  951. // Refresh monitor arrangement widget to match the parameter settings after
  952. // screen configuration has changed. The MonitorArrangement index doesn't work
  953. // the same way as the FLTK screen index.
  954. for (iter = instances.begin(); iter != instances.end(); iter++)
  955. Fl::add_timeout(0, handleScreenConfigTimeout, (*iter));
  956. return 0;
  957. }
  958. void OptionsDialog::handleScreenConfigTimeout(void *data)
  959. {
  960. OptionsDialog *self = (OptionsDialog *)data;
  961. assert(self);
  962. self->monitorArrangement->value(fullScreenSelectedMonitors.getParam());
  963. }