blob: d980ed2c56248a009689d5a921a85cce7c994c78 [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
DRCb65bb932011-06-24 03:17:00 +00003 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossman5156d5e2011-03-09 09:42:34 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 */
20
Peter Åstrandc359f362011-08-23 12:04:46 +000021#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
Pierre Ossman5156d5e2011-03-09 09:42:34 +000025#include <string.h>
26#include <stdio.h>
Pierre Ossman2a7a8d62013-02-15 08:33:39 +000027#include <ctype.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000028#include <stdlib.h>
29#include <errno.h>
30#include <signal.h>
31#include <locale.h>
32#include <sys/stat.h>
33
34#ifdef WIN32
Peter Åstrand (astrand)11167e12015-02-05 11:10:32 +010035#include <os/winerrno.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000036#include <direct.h>
37#define mkdir(path, mode) _mkdir(path)
38#endif
39
Pierre Ossman6b9622d2014-07-21 16:42:12 +020040#if !defined(WIN32) && !defined(__APPLE__)
41#include <X11/Xlib.h>
42#include <X11/XKBlib.h>
43#endif
44
Pierre Ossman5156d5e2011-03-09 09:42:34 +000045#include <rfb/Logger_stdio.h>
46#include <rfb/SecurityClient.h>
47#include <rfb/Security.h>
48#ifdef HAVE_GNUTLS
49#include <rfb/CSecurityTLS.h>
50#endif
51#include <rfb/LogWriter.h>
52#include <rfb/Timer.h>
Peter Åstrand8a2b0812012-08-08 11:49:01 +000053#include <rfb/Exception.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000054#include <network/TcpSocket.h>
DRC4426f002011-10-12 20:02:55 +000055#include <os/os.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000056
57#include <FL/Fl.H>
58#include <FL/Fl_Widget.H>
Pierre Ossman8eb35082012-03-27 12:50:54 +000059#include <FL/Fl_PNG_Image.H>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000060#include <FL/fl_ask.H>
Pierre Ossmanb8858222011-04-29 11:51:38 +000061#include <FL/x.H>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000062
63#include "i18n.h"
64#include "parameters.h"
65#include "CConn.h"
Pierre Ossman561ff0c2011-05-13 14:04:59 +000066#include "ServerDialog.h"
Pierre Ossman5156d5e2011-03-09 09:42:34 +000067#include "UserDialog.h"
Adam Tkac8ac4b302013-01-23 13:55:46 +000068#include "vncviewer.h"
Pierre Ossman5156d5e2011-03-09 09:42:34 +000069
DRCb65bb932011-06-24 03:17:00 +000070#ifdef WIN32
Pierre Ossman8eb35082012-03-27 12:50:54 +000071#include "resource.h"
DRCb65bb932011-06-24 03:17:00 +000072#include "win32.h"
73#endif
74
Pierre Ossman5156d5e2011-03-09 09:42:34 +000075rfb::LogWriter vlog("main");
76
77using namespace network;
78using namespace rfb;
79using namespace std;
80
Pierre Ossman5945d732014-09-22 13:13:15 +020081static const char _aboutText[] = N_("TigerVNC Viewer %d-bit v%s\n"
82 "Built on: %s\n"
Pierre Ossman34e12982014-09-22 12:59:38 +020083 "Copyright (C) 1999-%d TigerVNC Team and many others (see README.txt)\n"
Pierre Ossmandc96cb42014-09-22 12:19:26 +020084 "See http://www.tigervnc.org for information on TigerVNC.");
85static char aboutText[1024];
86
Adam Tkac8ac4b302013-01-23 13:55:46 +000087char vncServerName[VNCSERVERNAMELEN] = { '\0' };
88
Pierre Ossman5156d5e2011-03-09 09:42:34 +000089static bool exitMainloop = false;
Pierre Ossmane2ef5c12011-07-12 16:56:34 +000090static const char *exitError = NULL;
Pierre Ossman5156d5e2011-03-09 09:42:34 +000091
Pierre Ossmane2ef5c12011-07-12 16:56:34 +000092void exit_vncviewer(const char *error)
Pierre Ossman5156d5e2011-03-09 09:42:34 +000093{
Pierre Ossmane2ef5c12011-07-12 16:56:34 +000094 // Prioritise the first error we get as that is probably the most
95 // relevant one.
96 if ((error != NULL) && (exitError == NULL))
97 exitError = strdup(error);
98
Pierre Ossman5156d5e2011-03-09 09:42:34 +000099 exitMainloop = true;
100}
101
Pierre Ossmanb8858222011-04-29 11:51:38 +0000102void about_vncviewer()
103{
104 fl_message_title(_("About TigerVNC Viewer"));
Pierre Ossmandc96cb42014-09-22 12:19:26 +0200105 fl_message("%s", aboutText);
Pierre Ossmanb8858222011-04-29 11:51:38 +0000106}
107
108static void about_callback(Fl_Widget *widget, void *data)
109{
110 about_vncviewer();
111}
112
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000113static void CleanupSignalHandler(int sig)
114{
115 // CleanupSignalHandler allows C++ object cleanup to happen because it calls
116 // exit() rather than the default which is to abort.
Pierre Ossmanc76bd2b2014-12-03 14:01:31 +0100117 vlog.info(_("Termination signal %d has been received. TigerVNC Viewer will now exit."), sig);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000118 exit(1);
119}
120
121static void init_fltk()
122{
123 // Basic text size (10pt @ 96 dpi => 13px)
124 FL_NORMAL_SIZE = 13;
125
126#ifndef __APPLE__
127 // Select a FLTK scheme and background color that looks somewhat
128 // close to modern Linux and Windows.
129 Fl::scheme("gtk+");
130 Fl::background(220, 220, 220);
131#else
132 // On Mac OS X there is another scheme that fits better though.
133 Fl::scheme("plastic");
134#endif
135
Henrik Andersson3b837032011-09-19 13:46:55 +0000136 // Proper Gnome Shell integration requires that we set a sensible
137 // WM_CLASS for the window.
138 Fl_Window::default_xclass("vncviewer");
139
Pierre Ossman8eb35082012-03-27 12:50:54 +0000140 // Set the default icon for all windows.
141#ifdef HAVE_FLTK_ICONS
142#ifdef WIN32
143 HICON lg, sm;
144
145 lg = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
146 IMAGE_ICON, GetSystemMetrics(SM_CXICON),
147 GetSystemMetrics(SM_CYICON),
148 LR_DEFAULTCOLOR | LR_SHARED);
149 sm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
150 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
151 GetSystemMetrics(SM_CYSMICON),
152 LR_DEFAULTCOLOR | LR_SHARED);
153
154 Fl_Window::default_icons(lg, sm);
155#elif ! defined(__APPLE__)
156 const int icon_sizes[] = {48, 32, 24, 16};
157
158 Fl_PNG_Image *icons[4];
159 int count;
160
161 count = 0;
162
163 // FIXME: Follow icon theme specification
164 for (size_t i = 0;i < sizeof(icon_sizes)/sizeof(icon_sizes[0]);i++) {
165 char icon_path[PATH_MAX];
166 bool exists;
167
Pierre Ossman6a007bd2012-09-11 10:56:21 +0000168 sprintf(icon_path, "%s/icons/hicolor/%dx%d/apps/tigervnc.png",
Pierre Ossman8eb35082012-03-27 12:50:54 +0000169 DATA_DIR, icon_sizes[i], icon_sizes[i]);
170
171#ifndef WIN32
172 struct stat st;
173 if (stat(icon_path, &st) != 0)
174#else
175 struct _stat st;
176 if (_stat(icon_path, &st) != 0)
177 return(false);
178#endif
179 exists = false;
180 else
181 exists = true;
182
183 if (exists) {
184 icons[count] = new Fl_PNG_Image(icon_path);
185 if (icons[count]->w() == 0 ||
186 icons[count]->h() == 0 ||
187 icons[count]->d() != 4) {
188 delete icons[count];
189 continue;
190 }
191
192 count++;
193 }
194 }
195
196 Fl_Window::default_icons((const Fl_RGB_Image**)icons, count);
197
198 for (int i = 0;i < count;i++)
199 delete icons[i];
200#endif
201#endif // FLTK_HAVE_ICONS
202
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000203 // This makes the "icon" in dialogs rounded, which fits better
204 // with the above schemes.
205 fl_message_icon()->box(FL_UP_BOX);
206
207 // Turn off the annoying behaviour where popups track the mouse.
208 fl_message_hotspot(false);
209
210 // Avoid empty titles for popups
211 fl_message_title_default(_("TigerVNC Viewer"));
212
213#ifdef WIN32
214 // Most "normal" Windows apps use this font for UI elements.
215 Fl::set_font(FL_HELVETICA, "Tahoma");
216#endif
217
218 // FLTK exposes these so that we can translate them.
219 fl_no = _("No");
220 fl_yes = _("Yes");
221 fl_ok = _("OK");
222 fl_cancel = _("Cancel");
223 fl_close = _("Close");
Pierre Ossmanb8858222011-04-29 11:51:38 +0000224
225#ifdef __APPLE__
Peter Åstrandb7c55242011-08-29 13:14:51 +0000226 /* Needs trailing space */
227 static char fltk_about[16];
228 snprintf(fltk_about, sizeof(fltk_about), "%s ", _("About"));
229 Fl_Mac_App_Menu::about = fltk_about;
230 static char fltk_hide[16];
231 snprintf(fltk_hide, sizeof(fltk_hide), "%s ", _("Hide"));
232 Fl_Mac_App_Menu::hide = fltk_hide;
233 static char fltk_quit[16];
234 snprintf(fltk_quit, sizeof(fltk_quit), "%s ", _("Quit"));
235 Fl_Mac_App_Menu::quit = fltk_quit;
236
Pierre Ossman41ba6032011-06-16 11:09:31 +0000237 Fl_Mac_App_Menu::print = ""; // Don't want the print item
238 Fl_Mac_App_Menu::services = _("Services");
Pierre Ossman41ba6032011-06-16 11:09:31 +0000239 Fl_Mac_App_Menu::hide_others = _("Hide Others");
240 Fl_Mac_App_Menu::show = _("Show All");
Pierre Ossman41ba6032011-06-16 11:09:31 +0000241
Pierre Ossmanb8858222011-04-29 11:51:38 +0000242 fl_mac_set_about(about_callback, NULL);
243#endif
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000244}
245
246static void mkvnchomedir()
247{
248 // Create .vnc in the user's home directory if it doesn't already exist
249 char* homeDir = NULL;
250
251 if (getvnchomedir(&homeDir) == -1) {
252 vlog.error(_("Could not create VNC home directory: can't obtain home "
253 "directory path."));
254 } else {
255 int result = mkdir(homeDir, 0755);
256 if (result == -1 && errno != EEXIST)
257 vlog.error(_("Could not create VNC home directory: %s."), strerror(errno));
258 delete [] homeDir;
259 }
260}
261
262static void usage(const char *programName)
263{
264 fprintf(stderr,
265 "\nusage: %s [parameters] [host:displayNum] [parameters]\n"
266 " %s [parameters] -listen [port] [parameters]\n",
267 programName, programName);
268 fprintf(stderr,"\n"
269 "Parameters can be turned on with -<param> or off with -<param>=0\n"
270 "Parameters which take a value can be specified as "
271 "-<param> <value>\n"
272 "Other valid forms are <param>=<value> -<param>=<value> "
273 "--<param>=<value>\n"
274 "Parameter names are case-insensitive. The parameters are:\n\n");
275 Configuration::listParams(79, 14);
276 exit(1);
277}
278
Adam Tkac8ac4b302013-01-23 13:55:46 +0000279#ifndef WIN32
280static int
281interpretViaParam(char *remoteHost, int *remotePort, int localPort)
282{
283 const int SERVER_PORT_OFFSET = 5900;
284 char *pos = strchr(vncServerName, ':');
285 if (pos == NULL)
286 *remotePort = SERVER_PORT_OFFSET;
287 else {
288 int portOffset = SERVER_PORT_OFFSET;
289 size_t len;
290 *pos++ = '\0';
291 len = strlen(pos);
292 if (*pos == ':') {
293 /* Two colons is an absolute port number, not an offset. */
294 pos++;
295 len--;
296 portOffset = 0;
297 }
298 if (!len || strspn (pos, "-0123456789") != len )
299 return 1;
300 *remotePort = atoi(pos) + portOffset;
301 }
302
303 if (*vncServerName != '\0')
304 strncpy(remoteHost, vncServerName, VNCSERVERNAMELEN);
305 else
306 strncpy(remoteHost, "localhost", VNCSERVERNAMELEN);
307
308 remoteHost[VNCSERVERNAMELEN - 1] = '\0';
309
310 snprintf(vncServerName, VNCSERVERNAMELEN, "localhost::%d", localPort);
311 vncServerName[VNCSERVERNAMELEN - 1] = '\0';
312 vlog.error(vncServerName);
313
314 return 0;
315}
316
317static void
318createTunnel(const char *gatewayHost, const char *remoteHost,
319 int remotePort, int localPort)
320{
Pierre Ossmanf8d525b2014-07-09 17:02:27 +0200321 const char *cmd = getenv("VNC_VIA_CMD");
322 char *cmd2, *percent;
Adam Tkac8ac4b302013-01-23 13:55:46 +0000323 char lport[10], rport[10];
324 sprintf(lport, "%d", localPort);
325 sprintf(rport, "%d", remotePort);
326 setenv("G", gatewayHost, 1);
327 setenv("H", remoteHost, 1);
328 setenv("R", rport, 1);
329 setenv("L", lport, 1);
Adam Tkac8ac4b302013-01-23 13:55:46 +0000330 if (!cmd)
331 cmd = "/usr/bin/ssh -f -L \"$L\":\"$H\":\"$R\" \"$G\" sleep 20";
332 /* Compatibility with TigerVNC's method. */
Pierre Ossmanf8d525b2014-07-09 17:02:27 +0200333 cmd2 = strdup(cmd);
334 while ((percent = strchr(cmd2, '%')) != NULL)
Adam Tkac8ac4b302013-01-23 13:55:46 +0000335 *percent = '$';
Pierre Ossmanf8d525b2014-07-09 17:02:27 +0200336 system(cmd2);
337 free(cmd2);
Adam Tkac8ac4b302013-01-23 13:55:46 +0000338}
339
340static int mktunnel()
341{
342 const char *gatewayHost;
343 char remoteHost[VNCSERVERNAMELEN];
344 int localPort = findFreeTcpPort();
345 int remotePort;
346
347 gatewayHost = strDup(via.getValueStr());
348 if (interpretViaParam(remoteHost, &remotePort, localPort) != 0)
349 return 1;
350 createTunnel(gatewayHost, remoteHost, remotePort, localPort);
351
352 return 0;
353}
354#endif /* !WIN32 */
355
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000356int main(int argc, char** argv)
357{
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000358 UserDialog dlg;
359
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000360 setlocale(LC_ALL, "");
Pierre Ossman0878eca2012-03-27 13:03:22 +0000361 bindtextdomain(PACKAGE_NAME, LOCALE_DIR);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000362 textdomain(PACKAGE_NAME);
363
Pierre Ossmandc96cb42014-09-22 12:19:26 +0200364 // Generate the about string now that we get the proper translation
365 snprintf(aboutText, sizeof(aboutText), _aboutText,
Pierre Ossman5945d732014-09-22 13:13:15 +0200366 (int)sizeof(size_t)*8, PACKAGE_VERSION,
367 BUILD_TIMESTAMP, 2014);
Pierre Ossmandc96cb42014-09-22 12:19:26 +0200368
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000369 rfb::SecurityClient::setDefaults();
370
371 // Write about text to console, still using normal locale codeset
Pierre Ossmandc96cb42014-09-22 12:19:26 +0200372 fprintf(stderr,"\n%s\n", aboutText);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000373
374 // Set gettext codeset to what our GUI toolkit uses. Since we are
375 // passing strings from strerror/gai_strerror to the GUI, these must
376 // be in GUI codeset as well.
377 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
378 bind_textdomain_codeset("libc", "UTF-8");
379
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000380 rfb::initStdIOLoggers();
Pierre Ossmanc8719ad2012-04-26 14:27:52 +0000381#ifdef WIN32
382 rfb::initFileLogger("C:\\temp\\vncviewer.log");
383#else
384 rfb::initFileLogger("/tmp/vncviewer.log");
385#endif
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000386 rfb::LogWriter::setLogParams("*:stderr:30");
387
388#ifdef SIGHUP
389 signal(SIGHUP, CleanupSignalHandler);
390#endif
391 signal(SIGINT, CleanupSignalHandler);
392 signal(SIGTERM, CleanupSignalHandler);
393
394 init_fltk();
395
Pierre Ossman6b9622d2014-07-21 16:42:12 +0200396#if !defined(WIN32) && !defined(__APPLE__)
397 fl_open_display();
398 XkbSetDetectableAutoRepeat(fl_display, True, NULL);
399#endif
400
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000401 Configuration::enableViewerParams();
402
Peter Åstrand8a2b0812012-08-08 11:49:01 +0000403 /* Load the default parameter settings */
404 const char* defaultServerName;
405 try {
406 defaultServerName = loadViewerParameters(NULL);
407 } catch (rfb::Exception& e) {
408 fl_alert("%s", e.str());
409 }
410
DRC5aa06502011-06-23 22:04:46 +0000411 int i = 1;
412 if (!Fl::args(argc, argv, i) || i < argc)
413 for (; i < argc; i++) {
414 if (Configuration::setParam(argv[i]))
415 continue;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000416
DRC5aa06502011-06-23 22:04:46 +0000417 if (argv[i][0] == '-') {
418 if (i+1 < argc) {
419 if (Configuration::setParam(&argv[i][1], argv[i+1])) {
420 i++;
421 continue;
422 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000423 }
DRC5aa06502011-06-23 22:04:46 +0000424 usage(argv[0]);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000425 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000426
Adam Tkac8ac4b302013-01-23 13:55:46 +0000427 strncpy(vncServerName, argv[i], VNCSERVERNAMELEN);
428 vncServerName[VNCSERVERNAMELEN - 1] = '\0';
DRC5aa06502011-06-23 22:04:46 +0000429 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000430
431 if (!::autoSelect.hasBeenSet()) {
432 // Default to AutoSelect=0 if -PreferredEncoding or -FullColor is used
Peter Åstrand8a2b0812012-08-08 11:49:01 +0000433 if (::preferredEncoding.hasBeenSet() || ::fullColour.hasBeenSet() ||
434 ::fullColourAlias.hasBeenSet()) {
435 ::autoSelect.setParam(false);
436 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000437 }
438 if (!::fullColour.hasBeenSet() && !::fullColourAlias.hasBeenSet()) {
439 // Default to FullColor=0 if AutoSelect=0 && LowColorLevel is set
440 if (!::autoSelect && (::lowColourLevel.hasBeenSet() ||
441 ::lowColourLevelAlias.hasBeenSet())) {
442 ::fullColour.setParam(false);
443 }
444 }
445 if (!::customCompressLevel.hasBeenSet()) {
446 // Default to CustomCompressLevel=1 if CompressLevel is used.
Peter Åstrand8a2b0812012-08-08 11:49:01 +0000447 if(::compressLevel.hasBeenSet()) {
448 ::customCompressLevel.setParam(true);
449 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000450 }
451
452 mkvnchomedir();
453
454 CSecurity::upg = &dlg;
455#ifdef HAVE_GNUTLS
456 CSecurityTLS::msg = &dlg;
457#endif
458
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000459 Socket *sock = NULL;
460
DRC3e7ed812013-02-26 10:34:22 +0000461#ifndef WIN32
Adam Tkac571089b2013-02-19 14:30:32 +0000462 /* Specifying -via and -listen together is nonsense */
463 if (listenMode && strlen(via.getValueStr()) > 0) {
Pierre Ossman744e55c2014-12-03 14:00:54 +0100464 // TRANSLATORS: "Parameters" are command line arguments, or settings
465 // from a file or the Windows registry.
Pierre Ossman8ca4c1d2014-09-22 12:54:26 +0200466 vlog.error(_("Parameters -listen and -via are incompatible"));
467 fl_alert(_("Parameters -listen and -via are incompatible"));
Adam Tkac571089b2013-02-19 14:30:32 +0000468 exit_vncviewer();
469 return 1;
470 }
DRC3e7ed812013-02-26 10:34:22 +0000471#endif
Adam Tkac571089b2013-02-19 14:30:32 +0000472
473 if (listenMode) {
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000474 try {
475 int port = 5500;
476 if (isdigit(vncServerName[0]))
477 port = atoi(vncServerName);
478
479 TcpListener listener(NULL, port);
480
Pierre Ossman8ca4c1d2014-09-22 12:54:26 +0200481 vlog.info(_("Listening on port %d\n"), port);
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000482 sock = listener.accept();
483 } catch (rdr::Exception& e) {
484 vlog.error("%s", e.str());
485 fl_alert("%s", e.str());
486 exit_vncviewer();
487 return 1;
488 }
489
490 } else {
491 if (vncServerName[0] == '\0') {
492 ServerDialog::run(defaultServerName, vncServerName);
493 if (vncServerName[0] == '\0')
494 return 1;
495 }
Pierre Ossman561ff0c2011-05-13 14:04:59 +0000496
Adam Tkac8ac4b302013-01-23 13:55:46 +0000497#ifndef WIN32
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000498 if (strlen (via.getValueStr()) > 0 && mktunnel() != 0)
499 usage(argv[0]);
Adam Tkac8ac4b302013-01-23 13:55:46 +0000500#endif
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000501 }
Adam Tkac8ac4b302013-01-23 13:55:46 +0000502
Pierre Ossman2a7a8d62013-02-15 08:33:39 +0000503 CConn *cc = new CConn(vncServerName, sock);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000504
505 while (!exitMainloop) {
506 int next_timer;
507
508 next_timer = Timer::checkTimeouts();
509 if (next_timer == 0)
510 next_timer = INT_MAX;
511
512 if (Fl::wait((double)next_timer / 1000.0) < 0.0) {
513 vlog.error(_("Internal FLTK error. Exiting."));
514 break;
515 }
516 }
517
Pierre Ossmane2ef5c12011-07-12 16:56:34 +0000518 delete cc;
519
520 if (exitError != NULL)
Pierre Ossmanf52740e2012-04-25 15:43:56 +0000521 fl_alert("%s", exitError);
Pierre Ossmane2ef5c12011-07-12 16:56:34 +0000522
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000523 return 0;
524}