* Massachusetts.
*
* Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+ * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free
+ * Software Foundation, Inc.
*
* The following terms apply to Digital Equipment Corporation's copyright
* interest in XBoard:
#include <locale.h>
#endif
+#include <X11/keysym.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
void DisplayMove P((int moveNumber));
void update_ics_width P(());
int CopyMemoProc P(());
+static int FindLogo P((char *place, char *name, char *buf));
/*
* XBoard depends on Xt R4 or higher
if(sscanf(name, "size%d:", &size)) {
// [HGM] font: font is meant for specific boardSize (likely from settings file);
// defer processing it until we know if it matches our board size
- if(size >= 0 && size<MAX_SIZE) { // for now, fixed limit
+ if(strstr(name, "-*-") && // only pay attention to things that look like X-fonts
+ size >= 0 && size<MAX_SIZE) { // for now, fixed limit
fontTable[number][size] = strdup(strchr(name, ':')+1);
fontValid[number][size] = True;
}
void
ParseColor (int n, char *name)
{ // in XBoard, just copy the color-name string
- if(colorVariable[n]) *(char**)colorVariable[n] = strdup(name);
+ if(colorVariable[n] && *name == '#') *(char**)colorVariable[n] = strdup(name);
+}
+
+char *
+Col2Text (int n)
+{
+ return *(char**)colorVariable[n];
}
void
}
void
+GetPlacement (DialogClass dlg, WindowPlacement *wp)
+{ // wrapper to shield back-end from widget type
+ if(shellUp[dlg]) GetActualPlacement(shells[dlg], wp);
+}
+
+void
GetWindowCoords ()
{ // wrapper to shield use of window handles from back-end (make addressible by number?)
// In XBoard this will have to wait until awareness of window parameters is implemented
GenerateGlobalTranslationTable (void)
{
/* go through all menu items and extract the keyboard shortcuts, so that X11 can load them */
- char *output;
+ char *output[2];
- int i,j;
+ int i,j,n=0;
MenuItem *mi;
- output = strdup("");
+ output[0] = strdup(""); // build keystrokes with and wo mod keys separately
+ output[1] = strdup(""); // so the more specific can preceed the other
/* loop over all menu entries */
- for( i=0; menuBar[i].mi ; i++)
+ for( i=0; menuBar[i-n].mi || !n++; i++)
{
- mi = menuBar[i].mi;
+ mi = menuBar[i+n].mi; // kludge to access 'noMenu' behind sentinel
for(j=0; mi[j].proc; j++)
{
if (mi[j].accel)
mods[strlen(mods)-1]='\0';
/* get the name for the callback, we can use MenuItem() here that will call KeyBindingProc */
- size_t namesize = snprintf(NULL, 0, "%s.%s", menuBar[i].ref, mi[j].ref);
- char *name = malloc(namesize+1);
- snprintf(name, namesize+1, "%s.%s", menuBar[i].ref, mi[j].ref);
+ char *name = malloc(MSG_SIZ);
+ if(n) snprintf(name, MSG_SIZ, "%s", mi[j].ref);
+ else snprintf(name, MSG_SIZ, "%s.%s", menuBar[i].ref, mi[j].ref);
- size_t buffersize = snprintf(NULL, 0, ":%s<Key>%s: MenuItem(%s) \n ", mods, key, name);
- char *buffer = malloc(buffersize+1);
- snprintf(buffer, buffersize+1, ":%s<Key>%s: MenuItem(%s) \n ", mods, key, name);
+ char *buffer = malloc(MSG_SIZ);
+ snprintf(buffer, MSG_SIZ, ":%s<Key>%s: MenuItem(%s) \n ", mods, key, name);
/* add string to the output */
- output = realloc(output, strlen(output) + strlen(buffer)+1);
- strncat(output, buffer, strlen(buffer));
+ output[shift|alt|ctrl] = realloc(output[shift|alt|ctrl], strlen(output[shift|alt|ctrl]) + strlen(buffer)+1);
+ strncat(output[shift|alt|ctrl], buffer, strlen(buffer));
/* clean up */
free(key);
}
}
}
- return output;
+ output[1] = realloc(output[1], strlen(output[1]) + strlen(output[0])+1);
+ strncat(output[1], output[0], strlen(output[0]));
+ free(output[0]);
+ return output[1];
}
char *p;
int forceMono = False;
+ extern Option chatOptions[]; // FIXME: adapt Chat window, removing ICS pane and Hide button
+ chatOptions[6].type = chatOptions[10].type = Skip;
+
srandom(time(0)); // [HGM] book: make random truly random
setbuf(stdout, NULL);
exit(0);
}
+ if(argc > 1 && !strcmp(argv[1], "--show-config")) { // [HGM] install: called to print config info
+ typedef struct {char *name, *value; } Config;
+ static Config configList[] = {
+ { "Datadir", DATADIR },
+ { "Sysconfdir", SYSCONFDIR },
+ { NULL }
+ };
+ int i;
+
+ for(i=0; configList[i].name; i++) {
+ if(argc > 2 && strcmp(argv[2], configList[i].name)) continue;
+ if(argc > 2) printf("%s", configList[i].value);
+ else printf("%-12s: %s\n", configList[i].name, configList[i].value);
+ }
+ exit(0);
+ }
+
programName = strrchr(argv[0], '/');
if (programName == NULL)
programName = argv[0];
programName, appData.boardSize);
exit(2);
}
+ if(BOARD_WIDTH > 8)
+ squareSize = (squareSize*8 + BOARD_WIDTH/2)/BOARD_WIDTH; // scale height
if (i < 7) {
/* Find some defaults; use the nearest known size */
SizeDefaults *szd, *nearest;
} else {
SizeDefaults *szd = sizeDefaults;
if (*appData.boardSize == NULLCHAR) {
- while (DisplayWidth(xDisplay, xScreen) < szd->minScreenSize ||
- DisplayHeight(xDisplay, xScreen) < szd->minScreenSize) {
+ while (DisplayWidth(xDisplay, xScreen) < (szd->minScreenSize*BOARD_WIDTH + 4)/8 ||
+ DisplayHeight(xDisplay, xScreen) < (szd->minScreenSize*BOARD_HEIGHT + 4)/8) {
szd++;
}
if (szd->name == NULL) szd--;
boardWidget = optList[W_BOARD].handle;
menuBarWidget = optList[W_MENU].handle;
dropMenu = optList[W_DROP].handle;
- titleWidget = optList[optList[W_TITLE].type != -1 ? W_TITLE : W_SMALL].handle;
+ titleWidget = optList[optList[W_TITLE].type != Skip ? W_TITLE : W_SMALL].handle;
formWidget = XtParent(boardWidget);
XtSetArg(args[0], XtNbackground, &timerBackgroundPixel);
XtSetArg(args[1], XtNforeground, &timerForegroundPixel);
CatchDeleteWindow(shellWidget, "QuitProc");
- CreateAnyPieces();
+ CreateAnyPieces(1);
CreateGrid();
if(appData.logoSize)
{ // locate and read user logo
- char buf[MSG_SIZ];
- snprintf(buf, MSG_SIZ, "%s/%s.png", appData.logoDir, UserName());
+ char buf[MSG_SIZ], name[MSG_SIZ];
+ snprintf(name, MSG_SIZ, "/home/%s", UserName());
+ if(!FindLogo(name, ".logo", buf))
+ FindLogo(appData.logoDir, name + 6, buf);
ASSIGN(userLogo, buf);
}
EngineOutputPopUp();
}
+ gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes()
+ InitPosition(TRUE);
+
InitBackEnd2();
if (errorExitStatus == -1) {
}
}
- gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes()
- InitPosition(TRUE);
UpdateLogos(TRUE);
// XtSetKeyboardFocus(shellWidget, formWidget);
XSetInputFocus(xDisplay, XtWindow(formWidget), RevertToPointerRoot, CurrentTime);
return 0;
}
+void
+DoEvents ()
+{
+ XtInputMask m;
+ while((m = XtAppPending(appContext))) XtAppProcessEvent(appContext, m);
+}
+
RETSIGTYPE
TermSizeSigHandler (int sig)
{
if(sqy < sqx) sqx = sqy;
if(sqx != squareSize) {
squareSize = sqx; // adopt new square size
- CreatePNGPieces(); // make newly scaled pieces
+ CreatePNGPieces(appData.pieceDirectory); // make newly scaled pieces
InitDrawingSizes(0, 0); // creates grid etc.
} else ResizeBoardWindow(BOARD_WIDTH * (squareSize + lineGap) + lineGap, BOARD_HEIGHT * (squareSize + lineGap) + lineGap, 0);
w = BOARD_WIDTH * (squareSize + lineGap) + lineGap;
{
Arg args[16];
static int oldPausing = FALSE;
- static GameMode oldmode = (GameMode) -1;
+ static GameMode oldMode = (GameMode) -1;
char *wname;
if (!boardWidget || !XtIsRealized(boardWidget)) return;
}
}
- wname = ModeToWidgetName(oldmode);
+ wname = ModeToWidgetName(oldMode);
if (wname != NULL) {
MarkMenuItem(wname, False);
}
if (wname != NULL) {
MarkMenuItem(wname, True);
}
- oldmode = gameMode;
+ if(oldMode == TwoMachinesPlay) EnableNamedMenuItem("Mode.MachineMatch", True);
MarkMenuItem("Mode.MachineMatch", matchMode && matchGame < appData.matchGames);
+ oldMode = gameMode;
/* Maybe all the enables should be handled here, not just this one */
EnableNamedMenuItem("Mode.Training", gameMode == Training || gameMode == PlayFromGameFile);
Atom *type, XtPointer value, unsigned long *len, int *format)
{
FILE* f;
+ int flip = appData.flipView;
if (value == NULL || *len == 0) {
return; /* nothing had been selected to copy */
}
fwrite(value, 1, *len, f);
fclose(f);
XtFree(value);
+ if(!appData.autoFlipView) appData.flipView = flipView;
LoadGameFromFile(gamePasteFilename, 0, gamePasteFilename, TRUE);
+ appData.flipView = flip;
}
/* called when Paste Game button is pressed,
}
void
+InfoProc ()
+{
+ char buf[MSG_SIZ];
+ snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
+ INFODIR, INFOFILE);
+ system(buf);
+}
+
+void
SetWindowTitle (char *text, char *title, char *icon)
{
Arg args[16];
#endif
+static int
+FindLogo (char *place, char *name, char *buf)
+{ // check if file exists in given place
+ FILE *f;
+ if(!place) return 0;
+ snprintf(buf, MSG_SIZ, "%s/%s.png", place, name);
+ if(*place && strcmp(place, ".") && (f = fopen(buf, "r")) ) {
+ fclose(f);
+ return 1;
+ }
+ return 0;
+}
+
static void
LoadLogo (ChessProgramState *cps, int n, Boolean ics)
{
} else if(appData.autoLogo) {
if(ics) { // [HGM] logo: in ICS mode second can be used for ICS
sprintf(buf, "%s/%s.png", appData.logoDir, appData.icsHost);
- } else if(appData.directory[n] && appData.directory[n][0]) {
- sprintf(buf, "%s/%s.png", appData.logoDir, cps->tidy);
+ } else { // engine; cascade
+ if(!FindLogo(appData.logoDir, cps->tidy, buf) && // first try user log folder
+ !FindLogo(appData.directory[n], "logo", buf) && // then engine directory
+ !FindLogo("/usr/local/share/games/plugins/logos", cps->tidy, buf) ) // then system folders
+ FindLogo("/usr/share/games/plugins/logos", cps->tidy, buf);
}
}
if(logoName[0])