XBoard for Mac: Zippy problems
Moderators: hgm, Dann Corbit, Harvey Williamson
-
hgm
- Posts: 27703
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: MacPorts and XQuartz
No hurry. I just would like to know what is written on the log file for various XBoard commands with many arguments.
-
JoshPettus
- Posts: 730
- Joined: Fri Oct 19, 2012 2:23 am
Re: MacPorts and XQuartz
Sorry it took me a little while, kept making little mistakes. Fortunately even though the build script doesn't make a full app, it makes enough for the test.
got me:
Code: Select all
-icsUp true -ics -icshost freechess.orgCode: Select all
3842: start new, suppress = 0, path='freechess.org'
3842: new instance, argc=6 argv='-icsUp'
-
hgm
- Posts: 27703
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: MacPorts and XQuartz
Is that all? This is the output from one instance (process ID 3842). But it seems to receive an OpenFile signal while suppress=0, so I think it should have launched at least a second instance. Apparently this is an instance that does not print to the log yet.JoshPettus wrote:Sorry it took me a little while, kept making little mistakes. Fortunately even though the build script doesn't make a full app, it makes enough for the test.
got me:Code: Select all
-icsUp true -ics -icshost freechess.org
Code: Select all
3842: start new, suppress = 0, path='freechess.org' 3842: new instance, argc=6 argv='-icsUp'
But this already confirms what we thought: the fact that the instance you started from the terminal gets its full command line (argc=6) is apparently no guarantee that it will not get a spurious OpenFile signal.
The new instance that is launched because of that would be invoked as "xboard freechess.org", and might or might not also receive the OpenFile signal with path=freechess.org. But because the first argument now does not start with '-' we programmed it to ignore that OpenFile signal, by setting suppress=1. So whether it gets it or not does not matter; it will just try to open freechess.org as loadGameFile (which of course will fail miserably).
Now I am curious what happens if you use -ncp as first argument?
-
JoshPettus
- Posts: 730
- Joined: Fri Oct 19, 2012 2:23 am
Re: MacPorts and XQuartz
Yah, sorry It did launch 2 instances. thought I mentioned that
really strange..
got 3 instances.
yet
only gets the one instance launching freechess.org
really strange..
Code: Select all
-ncp -icsUp true -ics -icshost freechess.orgCode: Select all
1071: start new, suppress = 0, path='true'
1071: start new, suppress = 0, path='freechess.org'
1071: new instance, argc=7 argv='-ncp'Code: Select all
-ncp -ics -icshost freechess.org icsup true Code: Select all
1160: new instance, argc=7 argv='-ncp'-
hgm
- Posts: 27703
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: MacPorts and XQuartz
This is all extremely weird OS X behavior. There really seems no way to reliably guess how many of these spurious OpenFile commands the system will send you. So I guess the solution is to just ignore them for some time, say 1 sec, in the hope that none of the spurious ones will arive later than that, and that anything arriving later is due to genuine file clicking.
The following code should do this:
The following code should do this:
Code: Select all
#ifdef OSXAPP
static char clickedFile[MSG_SIZ];
TimeMark started;
static gboolean
StartNewXBoard(GtkosxApplication *app, gchar *path, gpointer user_data)
{ // handler of OSX OpenFile signal, which sends us the filename of clicked file or first argument
TimeMark now;
GetTimeMark(&now);
if(1000*now.sec + now.ms - 1000*started.sec - started.ms < 1000) { // received during first second
strncpy(clickedFile, path, MSG_SIZ); // remember file name, but otherwise ignore
} else { // we are running something presumably useful
char buf[MSG_SIZ];
snprintf(buf, MSG_SIZ, "open -n -a \"xboard\" --args \"%s\"", path);
system(buf); // start new instance on this file
}
return TRUE;
}
GtkosxApplication *theApp;
#endif
int
main (int argc, char **argv)
{
int i, clockFontPxlSize, coordFontPxlSize, fontPxlSize;
int boardWidth, w, h; //, boardHeight;
char *p;
int forceMono = False;
srandom(time(0)); // [HGM] book: make random truly random
setbuf(stdout, NULL);
setbuf(stderr, NULL);
debugFP = stderr;
if(argc > 1 && (!strcmp(argv[1], "-v" ) || !strcmp(argv[1], "--version" ))) {
printf("%s version %s\n\n configure options: %s\n", PACKAGE_NAME, PACKAGE_VERSION, CONFIGURE_OPTIONS);
exit(0);
}
if(argc > 1 && !strcmp(argv[1], "--help" )) {
PrintOptions();
exit(0);
}
/* set up GTK */
gtk_init (&argc, &argv);
#ifdef OSXAPP
{ // prepare to catch OX OpenFile signal, which will tell us the clicked file
char *path = gtkosx_application_get_bundle_path();
#ifdef ENABLE_NLS
char *res_path = gtkosx_application_get_resource_path();
GetTimeMark(&started); // remember start time
snprintf(localeDir, MSG_SIZ, "%s/share/locale", res_path); // redefine locale dir for OSX bundle
#endif
theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
snprintf(dataDir, MSG_SIZ, "%s/Contents/Resources/share/xboard", path);
snprintf(svgDir, MSG_SIZ, "%s/themes/default", dataDir);
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
g_signal_connect(theApp, "NSApplicationWillTerminate", G_CALLBACK(ExitEvent), NULL);
// we must call application ready before we can get the signal,
// and supply a (dummy) menu bar before that, to avoid problems with dual apples in it
gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(gtk_menu_bar_new()));
gtkosx_application_ready(theApp);
if(argc == 1) { // called without args: OSX open-file signal might follow
static char *fakeArgv[3] = {NULL, clickedFile, NULL};
usleep(10000); // wait 10 msec (and hope this is long enough).
while(gtk_events_pending())
gtk_main_iteration(); // process all events that came in upto now
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"
}
}
}
#endif
-
JoshPettus
- Posts: 730
- Joined: Fri Oct 19, 2012 2:23 am
Re: MacPorts and XQuartz
I don't get it.. I copied both #ifdef osxapp sections, but after compiling, it didn't work. It looks like it should, the extra xboards start up right along side the first one as fast as the computer can open them. I thought maybe my vmmachine was slow, so I upped it to 3 seconds, still no luck.
-
hgm
- Posts: 27703
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: MacPorts and XQuartz
So we should resort to printing again to see what is going on. You can replace
by
Code: Select all
TimeMark now;
GetTimeMark(&now);
if(1000*now.sec + now.ms - 1000*started.sec - started.ms < 1000) { // received during first second
Code: Select all
TimeMark now;
int elapsedTime;
GetTimeMark(&now);
elapsedTime = 1000*now.sec + now.ms - 1000*started.sec - started.ms;
{FILE *f=fopen("FILENAME", "a"); fprintf(f, "%d: start new '%s', time=%d\n", getpid(), path, elapsedTime); fclose(f); }
if(elapsedTime < 1000) { // received during first second
-
sje
- Posts: 4675
- Joined: Mon Mar 13, 2006 7:43 pm
Re: MacPorts and XQuartz
Update:sje wrote:MacPorts: port Unix applications to Mac OS/X
Seven versions for Mac OS/X 10.4 Tiger to OS/X 10.10 Yosemite
https://www.macports.org/
https://distfiles.macports.org/MacPorts ... semite.pkg
XQuartz: X Windows server for recent versions of Mac OS/X
Single version supports OS/X 10.6 Snow Leopard to OS/X 10.10 Yosemite.
http://xquartz.macosforge.org/
http://xquartz.macosforge.org/downloads ... -2.7.7.dmg
I installed both MacPorts and XQuartz on a year 2010 iMac (3.2 GHz Core i3 dual core, 16 GiB + OS/X 10.10 Yosemite), and then installed xboard via MacPorts. Everything went smoothly.
Before using XQuartz for the first time, it's recommended to log out or reboot first so that certain XQuartz secondary information can worm its way through the system.
I note that starting XQuartz implicitly by first starting xboard can be a bit clunky as XQuartz needs some time to itself to pull its brains together. Better is to start XQuartz explicitly first and maybe wait a few seconds before invoking xboard.
Perhaps the above could be included in the xboard documentation for Mac users, and particularly for Mac users who want to connect to an ICS via xboard with their own engine.
On my 2006 Mac Pro running OS/X 10.7 Lion, I use Apple's X11.app instead of XQuartz, but I might change this as the X11.app is no longer supported.
I installed XQuartz, MacPorts, and the MacPorts' version of xboard all on an older (2010) dual core iMac. In one terminal window, in my FICS directory I have xboard+timeseal+Symbolic connected to FICS; in a second window, in my ICC directory I have xboard+timestamp+Symbolic connected to ICC. It all works. The two xboard instances share the same configuration file while each having their own net of command line parameters and their own display window.
-
JoshPettus
- Posts: 730
- Joined: Fri Oct 19, 2012 2:23 am
Re: MacPorts and XQuartz
Strange for
-ncp -icsUp true -ics -icshost freechess.org
it actually worked this time, only 1 instance.
Here were the file results
perhaps I entered in something wrong the last time?
-ncp -icsUp true -ics -icshost freechess.org
it actually worked this time, only 1 instance.
Here were the file results
Code: Select all
1482: start new 'true', time=-1550446610
1482: start new 'freechess.org', time=-1550446608-
hgm
- Posts: 27703
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: MacPorts and XQuartz
Something must go very wrong in calculating the time. It was supposed to give msec since program start. The negative values make no sense, but because they are negative this time, they are considered smaller than 1000, and cause the OpenFile signals to be ignored. Last time they probably were positive random values.
OK, I see the problem, and it is entirely my fault: the GetTimeMark(&started); ended up between #ifdef ENABLE_NLS switches, because I just put it directly behind the declarations without noticing those switches. And probably you have internationalization switched off. So it never reads the initial time, and the elapsed time becomes garbage.
Moving the GetTimeMark(&started); to just behind the following #endif should do it.
OK, I see the problem, and it is entirely my fault: the GetTimeMark(&started); ended up between #ifdef ENABLE_NLS switches, because I just put it directly behind the declarations without noticing those switches. And probably you have internationalization switched off. So it never reads the initial time, and the elapsed time becomes garbage.
Moving the GetTimeMark(&started); to just behind the following #endif should do it.