Code: Select all
{
GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
if(argc == 1) { // called without args: OSX open-file signal might follow
static char *fakeArgv[3] = {NULL, clickedFile, NULL};
suppress = 1;
usleep(10000); // wait 10 msec (and hope this is long enough).
while(gtk_events_pending()) gtk_main_loop(); // process all events that came in upto now
suppress = 0; // future open-file signals should start new instance
if(clickedFile[0]) { // we were sent an open-file signal with filename!
fakeArgv[0] = argv[0];
argc = 2; argv = fakeArgv; // fake that we were called as "xboard filename"
}
}
}
Code: Select all
static char clickedFile[MSG_SIZ];
static int suppress;
static gboolean
StartNewXBoard(GtkosxApplication *app, gchar *path, gpointer user_data)
{
if(suppress) { // we just started XBoard without arguments
strncpy(clickedFile, path, MSG_SIZ); // remember file name
} else { // we are running something presumably useful
char buf[MSG_SIZ];
snprintf("open -n -a \"xboard\" \"%s\"", path);
system(buf); // start new instance on this file
}
return TRUE;
}
