]> git.street.me.uk Git - andy/viking.git/blobdiff - src/main.c
Add options to start making a new track and finishing it from the TrackWaypoint layer...
[andy/viking.git] / src / main.c
index e22b43aa2b28f9c03c9d7d0a85f9fe80377e6b43..5028dc79837641b0730b96c2588f23348509d3f3 100644 (file)
@@ -58,6 +58,10 @@ void a_datasource_gc_init();
 #define LOCALEDIR "locale"
 #endif
 
+#ifdef HAVE_X11_XLIB_H
+#include "X11/Xlib.h"
+#endif
+
 #if GLIB_CHECK_VERSION (2, 32, 0)
 /* Callback to log message */
 static void log_debug(const gchar *log_domain,
@@ -78,6 +82,20 @@ static void mute_log(const gchar *log_domain,
 }
 #endif
 
+#if HAVE_X11_XLIB_H
+static int myXErrorHandler(Display *display, XErrorEvent *theEvent)
+{
+  g_fprintf (stderr,
+             _("Ignoring Xlib error: error code %d request code %d\n"),
+             theEvent->error_code,
+             theEvent->request_code);
+  // No exit on X errors!
+  //  mainly to handle out of memory error when requesting large pixbuf from user request
+  //  see vikwindow.c::save_image_file ()
+  return 0;
+}
+#endif
+
 /* Options */
 static GOptionEntry entries[] = 
 {
@@ -137,6 +155,10 @@ int main( int argc, char *argv[] )
     g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
 #endif
 
+#if HAVE_X11_XLIB_H
+  XSetErrorHandler(myXErrorHandler);
+#endif
+
   a_preferences_init ();
 
   a_vik_preferences_init ();
@@ -168,8 +190,18 @@ int main( int argc, char *argv[] )
   while ( ++i < argc ) {
     if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
       dashdash_already = TRUE; /* hack to open '-' */
-    else
-      vik_window_open_file ( first_window, argv[i], argc == 2 );
+    else {
+      VikWindow *newvw = first_window;
+      gboolean change_filename = (i == 1);
+
+      // Open any subsequent .vik files in their own window
+      if ( i > 1 && check_file_magic_vik ( argv[i] ) ) {
+        newvw = vik_window_new_window ();
+        change_filename = TRUE;
+      }
+
+      vik_window_open_file ( newvw, argv[i], change_filename );
+    }
   }
 
   gtk_main ();