Moderators: hgm, Andres Valverde
H.G.Muller wrote:There is currently no accessible XBoard version similar to WinBoard for JAWS. A Google SOC project just started that aims to port those patches to XBoard.
Josh Pettus wrote:Gah! It has come to my attention that the dmg for the standard xboard app was unopenable.... (hate it when that happens) I uploaded another one.
Josh Pettus wrote:Do note it still has the infinite opening bug as before.
#ifdef __APPLE__
static char clickedFile[MSG_SIZ];
static int suppress;
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
if(suppress) { // we just started XBoard without arguments
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;
}
#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 __APPLE__
{ // prepare to catch OX OpenFile signal, which will tell us the clicked file
GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
char *path = gtkosx_application_get_bundle_path();
strncpy(dataDir, path, MSG_SIZ);
snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), 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);
suppress = (argc == 1 || argc > 1 && argv[1][00] != '-'); // OSX sends signal even if name was already argv[1]!
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
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"
}
}
}
#endif
case ArgFilename:
if(*(char**)ad->argLoc == NULL) break; // just in case
{ char buf[MSG_SIZ];
snprintf(buf, MSG_SIZ, "%s", *(char**)ad->argLoc);
#ifdef __APPLE__
if(strstr(buf, DATADIR) == buf)
snprintf(buf, MSG_SIZ, "~~%s", *(char**)ad->argLoc + strlen(DATADIR));
#endif
if (strchr(buf, '\"')) {
fprintf(f, OPTCHAR "%s" SEPCHAR "'%s'\n", ad->argName, buf);
} else {
fprintf(f, OPTCHAR "%s" SEPCHAR "\"%s\"\n", ad->argName, buf);
}
}
break;
case ArgBoardSize:
InfoProc ()
{
#ifdef __APPLE__
char buf[MSG_SIZ];
snprintf(buf, MSG_SIZ, "%s ./info.command", appData.sysOpen);
system(buf);
#else
char buf[MSG_SIZ];
snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
INFODIR, INFOFILE);
system(buf);
#endif
}
#define DEBUG(X, Y, Z) {FILE *f=fopen("/home/josh/debug.txt", "a"); fprintf(f, "%d: %s name=%s value=%d\n", getpid(), X, Y, Z); fclose(f); }
DEBUG("file and argc at moment X", clickedFile, argc)
#ifdef __APPLE__
static char clickedFile[MSG_SIZ];
static int suppress;
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
DEBUG("OpenFile received with name:", path, suppress)
if(suppress) { // we just started XBoard without arguments
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;
}
#endif
#ifdef __APPLE__
{ // prepare to catch OX OpenFile signal, which will tell us the clicked file
GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
char *path = gtkosx_application_get_bundle_path();
strncpy(dataDir, path, MSG_SIZ);
snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), 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);
suppress = (argc == 1 || argc > 1 && argv[1][00] != '-'); // OSX sends signal even if name was already argv[1]!
DEBUG("called with first argument", argv[1]==NULL ? "(none)" : argv[1], argc)
if(argc == 1) { // called without args: OSX open-file signal might follow
static char *fakeArgv[3] = {NULL, clickedFile, NULL};
usleep(200000); // wait 10 msec (and hope this is long enough).
while(gtk_events_pending())
gtk_main_iteration(); // 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"
}
}
DEBUG("after wait", clickedFile, suppress)
}
#endif
61338: called with first argument name=(none) value=1
61338: after wait name= value=0
61351: called with first argument name=(none) value=1
61351: OpenFile received with name: name=/Games/Chess/Xboard/herecomethej-Sjeng_11.2.pgn value=1
61351: after wait name=/Games/Chess/Xboard/herecomethej-Sjeng_11.2.pgn value=0
61351: OpenFile received with name: name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=0
61370: OpenFile received with name: name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=0
61370: called with first argument name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=2
61370: after wait name= value=1
61379: OpenFile received with name: name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=0
61379: called with first argument name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=2
61379: after wait name= value=1
61387: OpenFile received with name: name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=0
61387: called with first argument name=/Games/Chess/Xboard/Josh-Crafty-23.5.pgn value=2
61387: after wait name= value=1
...
suppress = (argc == 1 || argc > 1 && argv[1][00] != '-');
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
void
SetClockIcon (int color)
{
GdkPixbuf *pm = *clockIcons[color];
if (mainwindowIcon != pm) {
mainwindowIcon = pm;
#ifdef __APPLE__
gtkosx_application_set_dock_icon_pixbuf(theApp, mainwindowIcon);
#else
gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
#endif
}
}
}
GtkosxApplication *theApp;
#endif
char *path = gtkosx_application_get_bundle_path();
theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
// mainwindowIcon = WhiteIcon;
// gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
SetClockIcon(0);
/*
* Create an icon. (Use two icons, to indicate whther it is white's or black's turn.)
*/
WhiteIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_white.svg", NULL);
BlackIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_black.svg", NULL);
void
SetClockIcon (int color)
{
GdkPixbuf *pm = *clockIcons[color];
if (mainwindowIcon != pm) {
mainwindowIcon = pm;
#ifdef __APPLE__
gtkosx_application_set_dock_icon_pixbuf(theApp, mainwindowIcon);
#else
gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
#endif
}
}
StartNewXBoard(GtkosxApplication *app, gchar *path, gpointer user_data)
{ // handler of OSX OpenFile signal, which sends us the filename of clicked file or first argument
if(suppress) { // we just started XBoard without arguments
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
#ifdef __APPLE__
{ // prepare to catch OX OpenFile signal, which will tell us the clicked file
GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
char *path = gtkosx_application_get_bundle_path();
theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
strncpy(dataDir, path, MSG_SIZ);
snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
suppress = (argc == 1 || argc > 1 && argv[1][00] != '-'); // OSX sends signal even if name was already argv[1]!
g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), 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
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"
}
}
}
#endif
/*
* Create an icon. (Use two icons, to indicate whther it is white's or black's turn.)
*/
WhiteIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_white.svg", NULL);
BlackIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_black.svg", NULL);
// mainwindowIcon = WhiteIcon;
// gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
SetClockIcon(0);
Return to WinBoard development and bugfixing
Users browsing this forum: No registered users and 10 guests