/*
* xboard.c -- X front end for XBoard
- * $Id: xboard.c,v 2.2 2003/11/06 07:22:14 mann Exp $
*
* Copyright 1991 by Digital Equipment Corporation, Maynard,
- * Massachusetts. Enhancements Copyright
- * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software
- * Foundation, Inc.
+ * Massachusetts.
+ *
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
+ * 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
*
* The following terms apply to Digital Equipment Corporation's copyright
* interest in XBoard:
#include <X11/Shell.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
+#include <X11/Xmu/Atoms.h>
#if USE_XAW3D
#include <X11/Xaw3d/Dialog.h>
#include <X11/Xaw3d/Form.h>
int main P((int argc, char **argv));
RETSIGTYPE CmailSigHandler P((int sig));
RETSIGTYPE IntSigHandler P((int sig));
+RETSIGTYPE TermSizeSigHandler P((int sig));
void CreateGCs P((void));
void CreateXIMPieces P((void));
void CreateXPMPieces P((void));
void AskQuestionProc P((Widget w, XEvent *event,
String *prms, Cardinal *nprms));
void AskQuestionPopDown P((void));
-void PromotionPopUp P((void));
void PromotionPopDown P((void));
void PromotionCallback P((Widget w, XtPointer client_data,
XtPointer call_data));
void ErrorPopDown P((void));
static char *ExpandPathName P((char *path));
static void CreateAnimVars P((void));
-static void DragPieceBegin P((int x, int y));
static void DragPieceMove P((int x, int y));
-static void DragPieceEnd P((int x, int y));
static void DrawDragPiece P((void));
char *ModeToWidgetName P((GameMode mode));
void EngineOutputUpdate( FrontEndProgramStats * stats );
void TimeControlPopDown P(());
void NewVariantPopDown P(());
void SettingsPopDown P(());
+void update_ics_width P(());
+int get_term_width P(());
/*
* XBoard depends on Xt R4 or higher
*/
Window xBoardWindow;
Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor,
jailSquareColor, highlightSquareColor, premoveHighlightColor;
+Pixel lowTimeWarningColor;
GC lightSquareGC, darkSquareGC, jailSquareGC, lineGC, wdPieceGC, wlPieceGC,
bdPieceGC, blPieceGC, wbPieceGC, bwPieceGC, coordGC, highlineGC,
wjPieceGC, bjPieceGC, prelineGC, countGC;
#define SOLID 0
#define OUTLINE 1
Pixmap pieceBitmap[2][(int)BlackPawn];
-Pixmap xpmPieceBitmap[4][(int)BlackPawn]; /* LL, LD, DL, DD */
+Pixmap pieceBitmap2[2][(int)BlackPawn+4]; /* [HGM] pieces */
+Pixmap xpmPieceBitmap[4][(int)BlackPawn]; /* LL, LD, DL, DD actually used*/
+Pixmap xpmPieceBitmap2[4][(int)BlackPawn+4]; /* LL, LD, DL, DD set to select from */
Pixmap xpmLightSquare, xpmDarkSquare, xpmJailSquare;
int useImages, useImageSqs;
-XImage *ximPieceBitmap[4][(int)BlackPawn]; /* LL, LD, DL, DD */
-Pixmap ximMaskPm[(int)BlackPawn]; /* clipmasks, used for XIM pieces */
+XImage *ximPieceBitmap[4][(int)BlackPawn+4]; /* LL, LD, DL, DD */
+Pixmap ximMaskPm[(int)BlackPawn]; /* clipmasks, used for XIM pieces */
+Pixmap ximMaskPm2[(int)BlackPawn+4]; /* clipmasks, used for XIM pieces */
XImage *ximLightSquare, *ximDarkSquare;
XImage *xim_Cross;
-#define pieceToSolid(piece) &pieceBitmap[SOLID][((int)(piece)) % (int)BlackPawn]
-#define pieceToOutline(piece) &pieceBitmap[OUTLINE][((int)(piece)) % (int)BlackPawn]
+#define pieceToSolid(piece) &pieceBitmap[SOLID][(piece) % (int)BlackPawn]
+#define pieceToOutline(piece) &pieceBitmap[OUTLINE][(piece) % (int)BlackPawn]
#define White(piece) ((int)(piece) < (int)BlackPawn)
{NULL, NULL}
};
-#define PIECE_MENU_SIZE 11
+#define PIECE_MENU_SIZE 18
String pieceMenuStrings[2][PIECE_MENU_SIZE] = {
{ N_("White"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
- N_("Queen"), N_("King"), "----", N_("Empty square"), N_("Clear board") },
+ N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
+ N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
+ N_("Empty square"), N_("Clear board") },
{ N_("Black"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
- N_("Queen"), N_("King"), "----", N_("Empty square"), N_("Clear board") },
+ N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
+ N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
+ N_("Empty square"), N_("Clear board") }
};
/* must be in same order as PieceMenuStrings! */
ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = {
{ WhitePlay, (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
- WhiteRook, WhiteQueen, WhiteKing,
- (ChessSquare) 0, EmptySquare, ClearBoard },
+ WhiteRook, WhiteQueen, WhiteKing, (ChessSquare) 0, WhiteAlfil,
+ WhiteCannon, WhiteAngel, WhiteMarshall, (ChessSquare) 0,
+ PromotePiece, DemotePiece, EmptySquare, ClearBoard },
{ BlackPlay, (ChessSquare) 0, BlackPawn, BlackKnight, BlackBishop,
- BlackRook, BlackQueen, BlackKing,
- (ChessSquare) 0, EmptySquare, ClearBoard },
+ BlackRook, BlackQueen, BlackKing, (ChessSquare) 0, BlackAlfil,
+ BlackCannon, BlackAngel, BlackMarshall, (ChessSquare) 0,
+ PromotePiece, DemotePiece, EmptySquare, ClearBoard },
};
#define DROP_MENU_SIZE 6
{ "localLineEditing", "localLineEditing", XtRBoolean,
sizeof(Boolean), XtOffset(AppDataPtr, localLineEditing),
XtRImmediate, (XtPointer) True }, /* not implemented, must be True */
-#ifdef ZIPPY
+#if ZIPPY
{ "zippyTalk", "zippyTalk", XtRBoolean,
sizeof(Boolean), XtOffset(AppDataPtr, zippyTalk),
XtRImmediate, (XtPointer) ZIPPY_TALK },
{ "showButtonBar", "showButtonBar", XtRBoolean,
sizeof(Boolean), XtOffset(AppDataPtr, showButtonBar),
XtRImmediate, (XtPointer) True },
+ { "lowTimeWarningColor", "lowTimeWarningColor", XtRString,
+ sizeof(String), XtOffset(AppDataPtr, lowTimeWarningColor),
+ XtRString, COLOR_LOWTIMEWARNING },
+ { "lowTimeWarning", "lowTimeWarning", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, lowTimeWarning),
+ XtRImmediate, (XtPointer) False },
{"icsEngineAnalyze", "icsEngineAnalyze", XtRBoolean, /* [DM] icsEngineAnalyze */
sizeof(Boolean), XtOffset(AppDataPtr, icsEngineAnalyze),
XtRImmediate, (XtPointer) False },
{ "adjudicateLossThreshold", "adjudicateLossThreshold", XtRInt,
sizeof(int), XtOffset(AppDataPtr, adjudicateLossThreshold),
XtRImmediate, (XtPointer) 0},
+ { "adjudicateDrawMoves", "adjudicateDrawMoves", XtRInt,
+ sizeof(int), XtOffset(AppDataPtr, adjudicateDrawMoves),
+ XtRImmediate, (XtPointer) 0},
{ "pgnEventHeader", "pgnEventHeader", XtRString,
sizeof(String), XtOffset(AppDataPtr, pgnEventHeader),
XtRImmediate, (XtPointer) "Computer Chess Game" },
XtRImmediate, (XtPointer) "xboard.debug"},
{ "engineDebugOutput", "engineDebugOutput", XtRInt,
sizeof(int), XtOffset(AppDataPtr, engineComments),
- XtRImmediate, (XtPointer) 0},
+ XtRImmediate, (XtPointer) 1},
{ "noGUI", "noGUI", XtRBoolean,
sizeof(Boolean), XtOffset(AppDataPtr, noGUI),
XtRImmediate, (XtPointer) 0},
{ "delayAfterQuit", "delayAfterQuit", XtRInt,
sizeof(int), XtOffset(AppDataPtr, delayAfterQuit),
XtRImmediate, (XtPointer) 0},
+ { "keepAlive", "keepAlive", XtRInt,
+ sizeof(int), XtOffset(AppDataPtr, keepAlive),
+ XtRImmediate, (XtPointer) 0},
+ { "forceIllegalMoves", "forceIllegalMoves", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, forceIllegal),
+ XtRImmediate, (XtPointer) False},
+ { "keepLineBreaksICS", "keepLineBreaksICS", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, noJoin),
+ XtRImmediate, (XtPointer) False},
+ { "wrapContinuationSequence", "wrapContinuationSequence", XtRString,
+ sizeof(String), XtOffset(AppDataPtr, wrapContSeq),
+ XtRString, ""},
+ { "useInternalWrap", "useInternalWrap", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, useInternalWrap),
+ XtRImmediate, (XtPointer) True},
+ { "autoDisplayTags", "autoDisplayTags", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, autoDisplayTags),
+ XtRImmediate, (XtPointer) True},
+ { "autoDisplayComment", "autoDisplayComment", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, autoDisplayComment),
+ XtRImmediate, (XtPointer) True},
+ { "pasteSelection", "pasteSelection", XtRBoolean,
+ sizeof(Boolean), XtOffset(AppDataPtr, pasteSelection),
+ XtRImmediate, (XtPointer) False},
};
XrmOptionDescRec shellOptions[] = {
{ "-showButtonBar", "showButtonBar", XrmoptionSepArg, NULL },
{ "-buttons", "showButtonBar", XrmoptionNoArg, "True" },
{ "-xbuttons", "showButtonBar", XrmoptionNoArg, "False" },
+ { "-lowTimeWarningColor", "lowTimeWarningColor", XrmoptionSepArg, NULL },
+ { "-lowTimeWarning", "lowTimeWarning", XrmoptionSepArg, NULL },
/* [AS,HR] New features */
{ "-firstScoreAbs", "firstScoreAbs", XrmoptionSepArg, NULL },
{ "-secondScoreAbs", "secondScoreAbs", XrmoptionSepArg, NULL },
{ "-pgnExtendedInfo", "pgnExtendedInfo", XrmoptionSepArg, NULL },
{ "-hideThinkingFromHuman", "hideThinkingFromHuman", XrmoptionSepArg, NULL },
{ "-adjudicateLossThreshold", "adjudicateLossThreshold", XrmoptionSepArg, NULL },
+ { "-adjudicateDrawMoves", "adjudicateDrawMoves", XrmoptionSepArg, NULL },
{ "-pgnEventHeader", "pgnEventHeader", XrmoptionSepArg, NULL },
{ "-firstIsUCI", "firstIsUCI", XrmoptionSepArg, NULL },
{ "-secondIsUCI", "secondIsUCI", XrmoptionSepArg, NULL },
{ "-secondOptions", "secondOptions", XrmoptionSepArg, NULL },
{ "-firstNeedsNoncompliantFEN", "firstNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
{ "-secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
+ { "-keepAlive", "keepAlive", XrmoptionSepArg, NULL },
+ { "-forceIllegalMoves", "forceIllegalMoves", XrmoptionNoArg, "True" },
+ { "-keepLineBreaksICS", "keepLineBreaksICS", XrmoptionSepArg, NULL },
+ { "-wrapContinuationSequence", "wrapContinuationSequence", XrmoptionSepArg, NULL },
+ { "-useInternalWrap", "useInternalWrap", XrmoptionSepArg, NULL },
+ { "-autoDisplayTags", "autoDisplayTags", XrmoptionSepArg, NULL },
+ { "-autoDisplayComment", "autoDisplayComment", XrmoptionSepArg, NULL },
+ { "-pasteSelection", "pasteSelection", XrmoptionSepArg, NULL },
};
-
XtActionsRec boardActions[] = {
{ "DrawPosition", DrawPositionProc },
{ "HandleUserMove", HandleUserMove },
{ "TagsPopDown", (XtActionProc) TagsPopDown },
{ "ErrorPopDown", (XtActionProc) ErrorPopDown },
{ "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown },
- { "AnalysisPopDown", (XtActionProc) AnalysisPopDown },
{ "FileNamePopDown", (XtActionProc) FileNamePopDown },
{ "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown },
{ "GameListPopDown", (XtActionProc) GameListPopDown },
{
char buf[MSG_SIZ];
XSetWMProtocols(xDisplay, XtWindow(w), &wm_delete_window, 1);
- sprintf(buf, "<Message>WM_PROTOCOLS: %s() \n", procname);
+ snprintf(buf, sizeof(buf), "<Message>WM_PROTOCOLS: %s() \n", procname);
XtAugmentTranslations(w, XtParseTranslationTable(buf));
}
shellArgs[4].value = shellArgs[2].value = w;
shellArgs[5].value = shellArgs[3].value = h;
XtSetValues(shellWidget, &shellArgs[0], 6);
+
+ // [HGM] pieces: tailor piece bitmaps to needs of specific variant
+ // (only for xpm)
+ if(useImages) {
+ for(i=0; i<4; i++) {
+ int p;
+ for(p=0; p<=(int)WhiteKing; p++)
+ xpmPieceBitmap[i][p] = xpmPieceBitmap2[i][p]; // defaults
+ if(gameInfo.variant == VariantShogi) {
+ xpmPieceBitmap[i][(int)WhiteCannon] = xpmPieceBitmap2[i][(int)WhiteKing+1];
+ xpmPieceBitmap[i][(int)WhiteNightrider] = xpmPieceBitmap2[i][(int)WhiteKing+2];
+ xpmPieceBitmap[i][(int)WhiteSilver] = xpmPieceBitmap2[i][(int)WhiteKing+3];
+ xpmPieceBitmap[i][(int)WhiteGrasshopper] = xpmPieceBitmap2[i][(int)WhiteKing+4];
+ xpmPieceBitmap[i][(int)WhiteQueen] = xpmPieceBitmap2[i][(int)WhiteLance];
+ }
+#ifdef GOTHIC
+ if(gameInfo.variant == VariantGothic) {
+ xpmPieceBitmap[i][(int)WhiteMarshall] = xpmPieceBitmap2[i][(int)WhiteSilver];
+ }
+#endif
+#if !HAVE_LIBXPM
+ // [HGM] why are thee ximMasks used at all? the ximPieceBitmaps seem to be never used!
+ for(p=0; p<=(int)WhiteKing; p++)
+ ximMaskPm[p] = ximMaskPm2[p]; // defaults
+ if(gameInfo.variant == VariantShogi) {
+ ximMaskPm[(int)WhiteCannon] = ximMaskPm2[(int)WhiteKing+1];
+ ximMaskPm[(int)WhiteNightrider] = ximMaskPm2[(int)WhiteKing+2];
+ ximMaskPm[(int)WhiteSilver] = ximMaskPm2[(int)WhiteKing+3];
+ ximMaskPm[(int)WhiteGrasshopper] = ximMaskPm2[(int)WhiteKing+4];
+ ximMaskPm[(int)WhiteQueen] = ximMaskPm2[(int)WhiteLance];
+ }
+#ifdef GOTHIC
+ if(gameInfo.variant == VariantGothic) {
+ ximMaskPm[(int)WhiteMarshall] = ximMaskPm2[(int)WhiteSilver];
+ }
+#endif
+#endif
+ }
+ } else {
+ for(i=0; i<2; i++) {
+ int p;
+ for(p=0; p<=(int)WhiteKing; p++)
+ pieceBitmap[i][p] = pieceBitmap2[i][p]; // defaults
+ if(gameInfo.variant == VariantShogi) {
+ pieceBitmap[i][(int)WhiteCannon] = pieceBitmap2[i][(int)WhiteKing+1];
+ pieceBitmap[i][(int)WhiteNightrider] = pieceBitmap2[i][(int)WhiteKing+2];
+ pieceBitmap[i][(int)WhiteSilver] = pieceBitmap2[i][(int)WhiteKing+3];
+ pieceBitmap[i][(int)WhiteGrasshopper] = pieceBitmap2[i][(int)WhiteKing+4];
+ pieceBitmap[i][(int)WhiteQueen] = pieceBitmap2[i][(int)WhiteLance];
+ }
+#ifdef GOTHIC
+ if(gameInfo.variant == VariantGothic) {
+ pieceBitmap[i][(int)WhiteMarshall] = pieceBitmap2[i][(int)WhiteSilver];
+ }
+#endif
+ }
+ }
+#if HAVE_LIBXPM
+ CreateAnimVars();
+#endif
}
#endif
+void EscapeExpand(char *p, char *q)
+{ // [HGM] initstring: routine to shape up string arguments
+ while(*p++ = *q++) if(p[-1] == '\\')
+ switch(*q++) {
+ case 'n': p[-1] = '\n'; break;
+ case 'r': p[-1] = '\r'; break;
+ case 't': p[-1] = '\t'; break;
+ case '\\': p[-1] = '\\'; break;
+ case 0: *p = 0; return;
+ default: p[-1] = q[-1]; break;
+ }
+}
+
int
main(argc, argv)
int argc;
argvCopy[j] = NULL;
argv = argvCopy;
argc = j;
-#if 0
- if(appData.debugMode,1) { // OK, appData is not initialized here yet...
- for(i=0; i<argc; i++) fprintf(stderr, "argv[%2d] = '%s'\n", i, argv[i]);
- }
-#endif
#endif
-
setbuf(stdout, NULL);
setbuf(stderr, NULL);
debugFP = stderr;
#ifdef ENABLE_NLS
XtSetLanguageProc(NULL, NULL, NULL);
- bindtextdomain(PRODUCT, LOCALEDIR);
- textdomain(PRODUCT);
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
#endif
shellWidget =
XtAppInitialize(&appContext, "XBoard", shellOptions,
XtNumber(shellOptions),
&argc, argv, xboardResources, NULL, 0);
- if (argc > 1) {
+ if (argc > 1)
+ { /* left over command line arguments, print out help and exit.
+ * Use two columns to print help
+ */
fprintf(stderr, _("%s: unrecognized argument %s\n"),
programName, argv[1]);
+
+ fprintf(stderr, "Recognized options:\n");
+ for(i = 0; i < XtNumber(shellOptions); i++)
+ {
+ /* print first column */
+ j = fprintf(stderr, " %s%s", shellOptions[i].option,
+ (shellOptions[i].argKind == XrmoptionSepArg
+ ? " ARG" : ""));
+ /* print second column and end line */
+ if (++i < XtNumber(shellOptions))
+ {
+ fprintf(stderr, "%*c%s%s\n", 40 - j, ' ',
+ shellOptions[i].option,
+ (shellOptions[i].argKind == XrmoptionSepArg
+ ? " ARG" : ""));
+ }
+ else
+ {
+ fprintf(stderr, "\n");
+ };
+ };
exit(2);
+ };
+
+ p = getenv("HOME");
+ if (p == NULL) p = "/tmp";
+ i = strlen(p) + strlen("/.xboardXXXXXx.pgn") + 1;
+ gameCopyFilename = (char*) malloc(i);
+ gamePasteFilename = (char*) malloc(i);
+ snprintf(gameCopyFilename,i, "%s/.xboard%05uc.pgn", p, getpid());
+ snprintf(gamePasteFilename,i, "%s/.xboard%05up.pgn", p, getpid());
+
+ XtGetApplicationResources(shellWidget, (XtPointer) &appData,
+ clientResources, XtNumber(clientResources),
+ NULL, 0);
+
+ { // [HGM] initstring: kludge to fix bad bug. expand '\n' characters in init string and computer string.
+ static char buf[MSG_SIZ];
+ EscapeExpand(buf, appData.initString);
+ appData.initString = strdup(buf);
+ EscapeExpand(buf, appData.secondInitString);
+ appData.secondInitString = strdup(buf);
+ EscapeExpand(buf, appData.firstComputerString);
+ appData.firstComputerString = strdup(buf);
+ EscapeExpand(buf, appData.secondComputerString);
+ appData.secondComputerString = strdup(buf);
}
if ((chessDir = (char *) getenv("CHESSDIR")) == NULL) {
}
}
- p = getenv("HOME");
- if (p == NULL) p = "/tmp";
- i = strlen(p) + strlen("/.xboardXXXXXx.pgn") + 1;
- gameCopyFilename = (char*) malloc(i);
- gamePasteFilename = (char*) malloc(i);
- sprintf(gameCopyFilename, "%s/.xboard%05uc.pgn", p, getpid());
- sprintf(gamePasteFilename, "%s/.xboard%05up.pgn", p, getpid());
-
- XtGetApplicationResources(shellWidget, (XtPointer) &appData,
- clientResources, XtNumber(clientResources),
- NULL, 0);
-
if (appData.debugMode && appData.nameOfDebugFile && strcmp(appData.nameOfDebugFile, "stderr")) {
/* [DM] debug info to file [HGM] make the filename a command-line option, and allow it to remain stderr */
if ((debugFP = fopen(appData.nameOfDebugFile, "w")) == NULL) {
gameInfo.variant = StringToVariant(appData.variant);
InitPosition(FALSE);
-#if 0
- /*
- * Determine boardSize
- */
- gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] boardsize: make sure we start as 8x8
-
-//#ifndef IDSIZE
- // [HGM] as long as we have not created the possibility to change size while running, start with requested size
- gameInfo.boardWidth = appData.NrFiles > 0 ? appData.NrFiles : 8;
- gameInfo.boardHeight = appData.NrRanks > 0 ? appData.NrRanks : 8;
- gameInfo.holdingsWidth = appData.holdingsSize > 0 ? 2 : 0;
-#endif
-
#ifdef IDSIZE
InitDrawingSizes(-1, 0); // [HGM] initsize: make this into a subroutine
if (forceMono) {
fprintf(stderr, _("%s: too few colors available; trying monochrome mode\n"),
programName);
+
+ if (appData.bitmapDirectory == NULL ||
+ appData.bitmapDirectory[0] == NULLCHAR)
+ appData.bitmapDirectory = DEF_BITMAP_DIR;
+ }
+
+ if (appData.lowTimeWarning && !appData.monoMode) {
+ vFrom.addr = (caddr_t) appData.lowTimeWarningColor;
+ vFrom.size = strlen(appData.lowTimeWarningColor);
+ XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
+ if (vTo.addr == NULL)
+ appData.monoMode = True;
+ else
+ lowTimeWarningColor = *(Pixel *) vTo.addr;
}
if (appData.monoMode && appData.debugMode) {
widgetList[j++] = menuBarWidget = CreateMenuBar(menuBar);
XtSetArg(args[0], XtNtop, XtChainTop);
XtSetArg(args[1], XtNbottom, XtChainTop);
- XtSetValues(menuBarWidget, args, 2);
+ XtSetArg(args[2], XtNright, XtChainLeft);
+ XtSetValues(menuBarWidget, args, 3);
widgetList[j++] = whiteTimerWidget =
XtCreateWidget("whiteTime", labelWidgetClass,
if (appData.icsInputBox) ICSInputBoxPopUp();
}
+ #ifdef SIGWINCH
+ signal(SIGWINCH, TermSizeSigHandler);
+ #endif
signal(SIGINT, IntSigHandler);
signal(SIGTERM, IntSigHandler);
if (*appData.cmailGameName != NULLCHAR) {
signal(SIGUSR1, CmailSigHandler);
}
}
- InitPosition(TRUE);
+ gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes()
+ InitPosition(TRUE);
XtAppMainLoop(appContext);
if (appData.debugMode) fclose(debugFP); // [DM] debug
unlink(gamePasteFilename);
}
+RETSIGTYPE TermSizeSigHandler(int sig)
+{
+ update_ics_width();
+}
+
RETSIGTYPE
IntSigHandler(sig)
int sig;
}
}
+
+char pieceBitmapNames[] = "pnbrqfeacwmohijgdvlsukpnsl";
+
void CreateXIMPieces()
{
int piece, kind;
}
fprintf(stderr, _("\nLoading XIMs...\n"));
/* Load pieces */
- for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
+ for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) {
fprintf(stderr, "%d", piece+1);
for (kind=0; kind<4; kind++) {
fprintf(stderr, ".");
- sprintf(buf, "%s/%c%s%u.xim",
+ snprintf(buf, sizeof(buf), "%s/%s%c%s%u.xim",
ExpandPathName(appData.pixmapDirectory),
- ToLower(PieceToChar((ChessSquare)piece)),
+ piece <= (int) WhiteKing ? "" : "w",
+ pieceBitmapNames[piece],
ximkind[kind], ss);
ximPieceBitmap[kind][piece] =
XGetImage(xDisplay, DefaultRootWindow(xDisplay),
fprintf(stderr, _("(File:%s:) "), buf);
loadXIM(ximPieceBitmap[kind][piece],
ximtemp, buf,
- &(xpmPieceBitmap[kind][piece]),
- &(ximMaskPm[piece%(int)BlackPawn]));
+ &(xpmPieceBitmap2[kind][piece]),
+ &(ximMaskPm2[piece]));
+ if(piece <= (int)WhiteKing)
+ xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece];
}
fprintf(stderr," ");
}
/* Load light and dark squares */
/* If the LSQ and DSQ pieces don't exist, we will
draw them with solid squares. */
- sprintf(buf, "%s/lsq%u.xim", ExpandPathName(appData.pixmapDirectory), ss);
+ snprintf(buf,sizeof(buf), "%s/lsq%u.xim", ExpandPathName(appData.pixmapDirectory), ss);
if (access(buf, 0) != 0) {
useImageSqs = 0;
} else {
loadXIM(ximLightSquare, NULL, buf, &xpmLightSquare, NULL);
fprintf(stderr, _("dark square "));
- sprintf(buf, "%s/dsq%u.xim",
+ snprintf(buf,sizeof(buf), "%s/dsq%u.xim",
ExpandPathName(appData.pixmapDirectory), ss);
if (appData.debugMode)
fprintf(stderr, _("(File:%s:) "), buf);
static char *xpmkind[] = { "ll", "ld", "dl", "dd" };
XpmColorSymbol symbols[4];
-#if 0
- /* Apparently some versions of Xpm don't define XpmFormat at all --tpm */
- if (appData.debugMode) {
- fprintf(stderr, "XPM Library Version: %d.%d%c\n",
- XpmFormat, XpmVersion, (char)('a' + XpmRevision - 1));
- }
-#endif
-
/* The XSynchronize calls were copied from CreatePieces.
Not sure if needed, but can't hurt */
XSynchronize(xDisplay, True); /* Work-around for xlib/xt buffering bug */
fprintf(stderr, _("No builtin XPM pieces of size %d\n"), squareSize);
exit(1);
}
- for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
+ for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) {
for (kind=0; kind<4; kind++) {
if ((r=XpmCreatePixmapFromData(xDisplay, xBoardWindow,
pieces->xpm[piece][kind],
- &(xpmPieceBitmap[kind][piece]),
+ &(xpmPieceBitmap2[kind][piece]),
NULL, &attr)) != 0) {
fprintf(stderr, _("Error %d loading XPM image \"%s\"\n"),
r, buf);
exit(1);
}
+ if(piece <= (int) WhiteKing)
+ xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece];
}
}
useImageSqs = 0;
fprintf(stderr, _("\nLoading XPMs...\n"));
/* Load pieces */
- for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
+ for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) {
fprintf(stderr, "%d ", piece+1);
for (kind=0; kind<4; kind++) {
- sprintf(buf, "%s/%c%s%u.xpm",
+ snprintf(buf, sizeof(buf), "%s/%s%c%s%u.xpm",
ExpandPathName(appData.pixmapDirectory),
- ToLower(PieceToChar((ChessSquare)piece)),
+ piece > (int) WhiteKing ? "w" : "",
+ pieceBitmapNames[piece],
xpmkind[kind], ss);
if (appData.debugMode) {
fprintf(stderr, _("(File:%s:) "), buf);
}
if ((r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf,
- &(xpmPieceBitmap[kind][piece]),
+ &(xpmPieceBitmap2[kind][piece]),
NULL, &attr)) != 0) {
- fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"),
- r, buf);
- exit(1);
+ if(piece != (int)WhiteKing && piece > (int)WhiteQueen) {
+ // [HGM] missing: read of unorthodox piece failed; substitute King.
+ snprintf(buf, sizeof(buf), "%s/k%s%u.xpm",
+ ExpandPathName(appData.pixmapDirectory),
+ xpmkind[kind], ss);
+ if (appData.debugMode) {
+ fprintf(stderr, _("(Replace by File:%s:) "), buf);
+ }
+ r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf,
+ &(xpmPieceBitmap2[kind][piece]),
+ NULL, &attr);
+ }
+ if (r != 0) {
+ fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"),
+ r, buf);
+ exit(1);
+ }
}
+ if(piece <= (int) WhiteKing)
+ xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece];
}
}
/* Load light and dark squares */
/* If the LSQ and DSQ pieces don't exist, we will
draw them with solid squares. */
fprintf(stderr, _("light square "));
- sprintf(buf, "%s/lsq%u.xpm", ExpandPathName(appData.pixmapDirectory), ss);
+ snprintf(buf, sizeof(buf), "%s/lsq%u.xpm", ExpandPathName(appData.pixmapDirectory), ss);
if (access(buf, 0) != 0) {
useImageSqs = 0;
} else {
exit(1);
}
fprintf(stderr, _("dark square "));
- sprintf(buf, "%s/dsq%u.xpm",
+ snprintf(buf, sizeof(buf), "%s/dsq%u.xpm",
ExpandPathName(appData.pixmapDirectory), ss);
if (appData.debugMode) {
fprintf(stderr, _("(File:%s:) "), buf);
buffering bug */
for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) {
- for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
- sprintf(buf, "%c%u%c.bm", ToLower(PieceToChar((ChessSquare)piece)),
+ for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) {
+ sprintf(buf, "%s%c%u%c.bm", piece > (int)WhiteKing ? "w" : "",
+ pieceBitmapNames[piece],
ss, kind == SOLID ? 's' : 'o');
- ReadBitmap(&pieceBitmap[kind][piece], buf, NULL, ss, ss);
+ ReadBitmap(&pieceBitmap2[kind][piece], buf, NULL, ss, ss);
+ if(piece <= (int)WhiteKing)
+ pieceBitmap[kind][piece] = pieceBitmap2[kind][piece];
}
}
while (bib->squareSize != ss && bib->squareSize != 0) bib++;
for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) {
- for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
- sprintf(buf, "%c%u%c.bm", ToLower(PieceToChar((ChessSquare)piece)),
+ for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) {
+ sprintf(buf, "%s%c%u%c.bm", piece > (int)WhiteKing ? "w" : "",
+ pieceBitmapNames[piece],
ss, kind == SOLID ? 's' : 'o');
- ReadBitmap(&pieceBitmap[kind][piece], buf,
+ ReadBitmap(&pieceBitmap2[kind][piece], buf,
bib->bits[kind][piece], ss, ss);
+ if(piece <= (int)WhiteKing)
+ pieceBitmap[kind][piece] = pieceBitmap2[kind][piece];
}
}
strcat(fullname, name);
errcode = XReadBitmapFile(xDisplay, xBoardWindow, fullname,
&w, &h, pm, &x_hot, &y_hot);
+ fprintf(stderr, "load %s\n", name);
if (errcode != BitmapSuccess) {
switch (errcode) {
case BitmapOpenFailed:
- sprintf(msg, _("Can't open bitmap file %s"), fullname);
+ snprintf(msg, sizeof(msg), _("Can't open bitmap file %s"), fullname);
break;
case BitmapFileInvalid:
- sprintf(msg, _("Invalid bitmap in file %s"), fullname);
+ snprintf(msg, sizeof(msg), _("Invalid bitmap in file %s"), fullname);
break;
case BitmapNoMemory:
- sprintf(msg, _("Ran out of memory reading bitmap file %s"),
+ snprintf(msg, sizeof(msg), _("Ran out of memory reading bitmap file %s"),
fullname);
break;
default:
- sprintf(msg, _("Unknown XReadBitmapFile error %d on file %s"),
+ snprintf(msg, sizeof(msg), _("Unknown XReadBitmapFile error %d on file %s"),
errcode, fullname);
break;
}
return;
}
}
- if (bits == NULL) {
-#if 0
- fprintf(stderr, _("%s: No built-in bitmap for %s; giving up\n"),
- programName, name);
- exit(1);
-#endif
- ; // [HGM] bitmaps: make it non-fatal if we have no bitmap;
- } else {
+ if (bits != NULL) {
*pm = XCreateBitmapFromData(xDisplay, xBoardWindow, (char *) bits,
wreq, hreq);
}
&& !appData.icsActive));
count = 0;
while (p && *p++ == dmEnables[i].piece) count++;
- sprintf(label, "%s %d", dmEnables[i].widget, count);
+ snprintf(label, sizeof(label), "%s %d", dmEnables[i].widget, count);
j = 0;
XtSetArg(args[j], XtNlabel, label); j++;
XtSetValues(entry, args, j);
if (hi1X >= 0 && hi1Y >= 0) {
drawHighlight(hi1X, hi1Y, lineGC);
}
+ } // [HGM] first erase both, then draw new!
+ if (hi2X != toX || hi2Y != toY) {
+ if (hi2X >= 0 && hi2Y >= 0) {
+ drawHighlight(hi2X, hi2Y, lineGC);
+ }
+ }
+ if (hi1X != fromX || hi1Y != fromY) {
if (fromX >= 0 && fromY >= 0) {
drawHighlight(fromX, fromY, highlineGC);
}
}
if (hi2X != toX || hi2Y != toY) {
- if (hi2X >= 0 && hi2Y >= 0) {
- drawHighlight(hi2X, hi2Y, lineGC);
- }
if (toX >= 0 && toY >= 0) {
drawHighlight(toX, toY, highlineGC);
}
DrawFunc drawfunc;
int flash_delay;
- if(gameInfo.variant == VariantShogi) { // [HGM] shogi: in shogi Q is used for Lance
- if(piece == WhiteQueen) piece = WhiteLance; else
- if(piece == BlackQueen) piece = BlackLance;
- }
-#ifdef GOTHIC
- else if(gameInfo.variant == VariantGothic) { // [HGM] shogi: in Gothic Chancelor has alternative look
- if(piece == WhiteMarshall) piece = WhiteSilver; else
- if(piece == BlackMarshall) piece = BlackSilver;
- }
-#endif
-
/* Calculate delay in milliseconds (2-delays per complete flash) */
flash_delay = 500 / appData.flashRate;
String *prms;
Cardinal *nprms;
{
- int x, y;
- Boolean saveAnimate;
- static int second = 0;
-
if (w != boardWidget || errorExitStatus != -1) return;
- if (event->type == ButtonPress) ErrorPopDown();
-
if (promotionUp) {
if (event->type == ButtonPress) {
XtPopdown(promotionShell);
}
}
- x = EventToSquare(event->xbutton.x, BOARD_WIDTH);
- y = EventToSquare(event->xbutton.y, BOARD_HEIGHT);
- if (!flipView && y >= 0) {
- y = BOARD_HEIGHT - 1 - y;
- }
- if (flipView && x >= 0) {
- x = BOARD_WIDTH - 1 - x;
- }
-
- /* [HGM] holdings: next 5 lines: ignore all clicks between board and holdings */
- if(event->type == ButtonPress
- && ( x == BOARD_LEFT-1 || x == BOARD_RGHT
- || x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize
- || x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize) )
- return;
-
- if (fromX == -1) {
- if (event->type == ButtonPress) {
- /* First square */
- if (OKToStartUserMove(x, y)) {
- fromX = x;
- fromY = y;
- second = 0;
- DragPieceBegin(event->xbutton.x, event->xbutton.y);
- if (appData.highlightDragging) {
- SetHighlights(x, y, -1, -1);
- }
- }
- }
- return;
- }
-
- /* fromX != -1 */
- if (event->type == ButtonPress && gameMode != EditPosition &&
- x >= 0 && y >= 0) {
- ChessSquare fromP;
- ChessSquare toP;
-
- /* Check if clicking again on the same color piece */
- fromP = boards[currentMove][fromY][fromX];
- toP = boards[currentMove][y][x];
- if ((WhitePawn <= fromP && fromP < WhiteKing && // [HGM] this test should go, as UserMoveTest now does it.
- WhitePawn <= toP && toP <= WhiteKing) || // For now I made it less critical by exempting King
- (BlackPawn <= fromP && fromP < BlackKing && // moves, to not interfere with FRC castlings.
- BlackPawn <= toP && toP <= BlackKing)) {
- /* Clicked again on same color piece -- changed his mind */
- second = (x == fromX && y == fromY);
- if (appData.highlightDragging) {
- SetHighlights(x, y, -1, -1);
- } else {
- ClearHighlights();
- }
- if (OKToStartUserMove(x, y)) {
- fromX = x;
- fromY = y;
- DragPieceBegin(event->xbutton.x, event->xbutton.y);
- }
- return;
- }
- }
-
- if (event->type == ButtonRelease && x == fromX && y == fromY) {
- DragPieceEnd(event->xbutton.x, event->xbutton.y);
- if (appData.animateDragging) {
- /* Undo animation damage if any */
- DrawPosition(FALSE, NULL);
- }
- if (second) {
- /* Second up/down in same square; just abort move */
- second = 0;
- fromX = fromY = -1;
- ClearHighlights();
- gotPremove = 0;
- ClearPremoveHighlights();
- } else {
- /* First upclick in same square; start click-click mode */
- SetHighlights(x, y, -1, -1);
- }
- return;
- }
-
- /* Completed move */
- toX = x;
- toY = y;
- saveAnimate = appData.animate;
- if (event->type == ButtonPress) {
- /* Finish clickclick move */
- if (appData.animate || appData.highlightLastMove) {
- SetHighlights(fromX, fromY, toX, toY);
- } else {
- ClearHighlights();
- }
- } else {
- /* Finish drag move */
- if (appData.highlightLastMove) {
- SetHighlights(fromX, fromY, toX, toY);
- } else {
- ClearHighlights();
- }
- DragPieceEnd(event->xbutton.x, event->xbutton.y);
- /* Don't animate move and drag both */
- appData.animate = FALSE;
- }
- if (IsPromotion(fromX, fromY, toX, toY)) {
- if (appData.alwaysPromoteToQueen) {
- UserMoveEvent(fromX, fromY, toX, toY, 'q');
- if (!appData.highlightLastMove || gotPremove) ClearHighlights();
- if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
- fromX = fromY = -1;
- } else {
- SetHighlights(fromX, fromY, toX, toY);
- PromotionPopUp();
- }
- } else {
- UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR);
- if (!appData.highlightLastMove || gotPremove) ClearHighlights();
- if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
- fromX = fromY = -1;
- }
- appData.animate = saveAnimate;
- if (appData.animate || appData.animateDragging) {
- /* Undo animation damage if needed */
- DrawPosition(FALSE, NULL);
- }
+ // [HGM] mouse: the rest of the mouse handler is moved to the backend, and called here
+ if(event->type == ButtonPress) LeftClick(Press, event->xbutton.x, event->xbutton.y);
+ if(event->type == ButtonRelease) LeftClick(Release, event->xbutton.x, event->xbutton.y);
}
void AnimateUserMove (Widget w, XEvent * event,
XtSetArg(args[j], XtNright, XtChainRight); j++;
XtSetArg(args[j], XtNresizable, True); j++;
XtSetArg(args[j], XtNwidth, bw_width); j++; /*force wider than buttons*/
-#if 0
- XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
-#else
/* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
-#endif
XtSetArg(args[j], XtNautoFill, True); j++;
XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++;
edit =
XtSetArg(args[j], XtNleft, XtChainLeft); j++;
XtSetArg(args[j], XtNright, XtChainRight); j++;
XtSetArg(args[j], XtNresizable, True); j++;
-#if 0
- XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
-#else
/* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
-#endif
XtSetArg(args[j], XtNautoFill, True); j++;
XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++;
edit =
commentUp = True;
}
-void AnalysisPopUp(title, text)
- char *title, *text;
-{
- Arg args[16];
- int j;
- Widget edit;
-
- if (analysisShell == NULL) {
- analysisShell = MiscCreate(title, text, False, NULL, 4);
- XtRealizeWidget(analysisShell);
- CatchDeleteWindow(analysisShell, "AnalysisPopDown");
-
- } else {
- edit = XtNameToWidget(analysisShell, "*form.text");
- j = 0;
- XtSetArg(args[j], XtNstring, text); j++;
- XtSetValues(edit, args, j);
- j = 0;
- XtSetArg(args[j], XtNiconName, (XtArgVal) title); j++;
- XtSetArg(args[j], XtNtitle, (XtArgVal) title); j++;
- XtSetValues(analysisShell, args, j);
- }
-
- if (!analysisUp) {
- XtPopup(analysisShell, XtGrabNone);
- }
- XSync(xDisplay, False);
-
- analysisUp = True;
-}
-
void CommentCallback(w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
commentUp = False;
}
-void AnalysisPopDown()
-{
- if (!analysisUp) return;
- XtPopdown(analysisShell);
- XSync(xDisplay, False);
- analysisUp = False;
- if (appData.icsEngineAnalyze) ExitAnalyzeMode(); /* [DM] icsEngineAnalyze */
-}
-
-
void FileNamePopUp(label, def, proc, openMode)
char *label;
char *def;
layoutArgs, XtNumber(layoutArgs));
j = 0;
- XtSetArg(args[j], XtNlabel, _("Promote pawn to what?")); j++;
+ XtSetArg(args[j], XtNlabel, _("Promote to what?")); j++;
XtSetArg(args[j], XtNborderWidth, 0); j++;
dialog = XtCreateManagedWidget("promotion", dialogWidgetClass,
layout, args, j);
+ if(gameInfo.variant != VariantShogi) {
XawDialogAddButton(dialog, _("Queen"), PromotionCallback,
(XtPointer) dialog);
XawDialogAddButton(dialog, _("Rook"), PromotionCallback,
XawDialogAddButton(dialog, _("King"), PromotionCallback,
(XtPointer) dialog);
}
+ if(gameInfo.variant == VariantCapablanca ||
+ gameInfo.variant == VariantGothic ||
+ gameInfo.variant == VariantCapaRandom) {
+ XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback,
+ (XtPointer) dialog);
+ XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback,
+ (XtPointer) dialog);
+ }
+ } else // [HGM] shogi
+ {
+ XawDialogAddButton(dialog, _("Promote"), PromotionCallback,
+ (XtPointer) dialog);
+ XawDialogAddButton(dialog, _("Defer"), PromotionCallback,
+ (XtPointer) dialog);
+ }
XawDialogAddButton(dialog, _("cancel"), PromotionCallback,
(XtPointer) dialog);
return;
} else if (strcmp(name, _("Knight")) == 0) {
promoChar = 'n';
+ } else if (strcmp(name, _("Promote")) == 0) {
+ promoChar = '+';
+ } else if (strcmp(name, _("Defer")) == 0) {
+ promoChar = '=';
} else {
promoChar = ToLower(name[0]);
}
args, 1);
if (appData.showButtonBar) {
-#if 0
- if (pausing) {
- XtSetArg(args[0], XtNbackground, buttonForegroundPixel);
- XtSetArg(args[1], XtNforeground, buttonBackgroundPixel);
- } else {
- XtSetArg(args[0], XtNbackground, buttonBackgroundPixel);
- XtSetArg(args[1], XtNforeground, buttonForegroundPixel);
- }
-#else
/* Always toggle, don't set. Previous code messes up when
invoked while the button is pressed, as releasing it
toggles the state again. */
XtSetArg(args[0], XtNbackground, oldfg);
XtSetArg(args[1], XtNforeground, oldbg);
}
-#endif
XtSetValues(XtNameToWidget(buttonBarWidget, PAUSE_BUTTON), args, 2);
}
}
Cardinal *nprms;
{
ResetGameEvent();
- AnalysisPopDown();
}
int LoadGamePopUp(f, gameNumber, title)
char *selection_tmp;
if (!selected_fen_position) return False; /* should never happen */
- if (*target == XA_STRING){
+ if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){
/* note: since no XtSelectionDoneProc was registered, Xt will
* automatically call XtFree on the value returned. So have to
* make a copy of it allocated with XtMalloc */
*value_return=selection_tmp;
*length_return=strlen(selection_tmp);
- *type_return=XA_STRING;
+ *type_return=*target;
*format_return = 8; /* bits per byte */
return True;
+ } else if (*target == XA_TARGETS(xDisplay)) {
+ Atom *targets_tmp = (Atom *) XtMalloc(2 * sizeof(Atom));
+ targets_tmp[0] = XA_UTF8_STRING(xDisplay);
+ targets_tmp[1] = XA_STRING;
+ *value_return = targets_tmp;
+ *type_return = XA_ATOM;
+ *length_return = 2;
+ *format_return = 8 * sizeof(Atom);
+ if (*format_return > 32) {
+ *length_return *= *format_return / 32;
+ *format_return = 32;
+ }
+ return True;
} else {
return False;
}
String *prms;
Cardinal *nprms;
{
- int ret;
-
+ /*
+ * Set both PRIMARY (the selection) and CLIPBOARD, since we don't
+ * have a notion of a position that is selected but not copied.
+ * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki
+ */
+ if(gameMode == EditPosition) EditPositionDone(TRUE);
if (selected_fen_position) free(selected_fen_position);
selected_fen_position = (char *)PositionToFEN(currentMove, NULL);
if (!selected_fen_position) return;
- ret = XtOwnSelection(menuBarWidget, XA_PRIMARY,
- CurrentTime,
- SendPositionSelection,
- NULL/* lose_ownership_proc */ ,
- NULL/* transfer_done_proc */);
- if (!ret) {
- free(selected_fen_position);
- selected_fen_position=NULL;
- }
+ XtOwnSelection(menuBarWidget, XA_PRIMARY,
+ CurrentTime,
+ SendPositionSelection,
+ NULL/* lose_ownership_proc */ ,
+ NULL/* transfer_done_proc */);
+ XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
+ CurrentTime,
+ SendPositionSelection,
+ NULL/* lose_ownership_proc */ ,
+ NULL/* transfer_done_proc */);
}
/* function called when the data to Paste is ready */
String *prms;
Cardinal *nprms;
{
- XtGetSelectionValue(menuBarWidget, XA_PRIMARY, XA_STRING,
+ XtGetSelectionValue(menuBarWidget,
+ appData.pasteSelection ? XA_PRIMARY: XA_CLIPBOARD(xDisplay), XA_STRING,
/* (XtSelectionCallbackProc) */ PastePositionCB,
NULL, /* client_data passed to PastePositionCB */
{
char *selection_tmp;
- if (*target == XA_STRING){
+ if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){
FILE* f = fopen(gameCopyFilename, "r");
long len;
size_t count;
selection_tmp[len] = NULLCHAR;
*value_return = selection_tmp;
*length_return = len;
- *type_return = XA_STRING;
+ *type_return = *target;
*format_return = 8; /* bits per byte */
return True;
+ } else if (*target == XA_TARGETS(xDisplay)) {
+ Atom *targets_tmp = (Atom *) XtMalloc(2 * sizeof(Atom));
+ targets_tmp[0] = XA_UTF8_STRING(xDisplay);
+ targets_tmp[1] = XA_STRING;
+ *value_return = targets_tmp;
+ *type_return = XA_ATOM;
+ *length_return = 2;
+ *format_return = 8 * sizeof(Atom);
+ if (*format_return > 32) {
+ *length_return *= *format_return / 32;
+ *format_return = 32;
+ }
+ return True;
} else {
return False;
}
ret = SaveGameToFile(gameCopyFilename, FALSE);
if (!ret) return;
- ret = XtOwnSelection(menuBarWidget, XA_PRIMARY,
- CurrentTime,
- SendGameSelection,
- NULL/* lose_ownership_proc */ ,
- NULL/* transfer_done_proc */);
+ /*
+ * Set both PRIMARY (the selection) and CLIPBOARD, since we don't
+ * have a notion of a game that is selected but not copied.
+ * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki
+ */
+ XtOwnSelection(menuBarWidget, XA_PRIMARY,
+ CurrentTime,
+ SendGameSelection,
+ NULL/* lose_ownership_proc */ ,
+ NULL/* transfer_done_proc */);
+ XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
+ CurrentTime,
+ SendGameSelection,
+ NULL/* lose_ownership_proc */ ,
+ NULL/* transfer_done_proc */);
}
/* function called when the data to Paste is ready */
String *prms;
Cardinal *nprms;
{
- XtGetSelectionValue(menuBarWidget, XA_PRIMARY, XA_STRING,
+ XtGetSelectionValue(menuBarWidget,
+ appData.pasteSelection ? XA_PRIMARY: XA_CLIPBOARD(xDisplay), XA_STRING,
/* (XtSelectionCallbackProc) */ PasteGameCB,
NULL, /* client_data passed to PasteGameCB */
char buf[MSG_SIZ];
if (!first.analysisSupport) {
- sprintf(buf, _("%s does not support analysis"), first.tidy);
+ snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
DisplayError(buf, 0);
return;
}
{
if (!first.analysisSupport) {
char buf[MSG_SIZ];
- sprintf(buf, _("%s does not support analysis"), first.tidy);
+ snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
DisplayError(buf, 0);
return;
}
String *prms;
Cardinal *nprms;
{
- Arg args[16];
-
appData.showThinking = !appData.showThinking; // [HGM] thinking: tken out of ShowThinkingEvent
ShowThinkingEvent();
-#if 0
- // [HGM] thinking: currently no suc menu item; replaced by Hide Thinking (From Human)
- if (appData.showThinking) {
- XtSetArg(args[0], XtNleftBitmap, xMarkPixmap);
- } else {
- XtSetArg(args[0], XtNleftBitmap, None);
- }
- XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Show Thinking"),
- args, 1);
-#endif
}
void HideThinkingProc(w, event, prms, nprms)
Cardinal *nprms;
{
char buf[MSG_SIZ];
- sprintf(buf, "xterm -e info --directory %s --directory . -f %s &",
+ snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
INFODIR, INFOFILE);
system(buf);
}
name = prms[0];
else
name = "xboard";
- sprintf(buf, "xterm -e man %s &", name);
+ snprintf(buf, sizeof(buf), "xterm -e man %s &", name);
system(buf);
}
#else
char *zippy = "";
#endif
- sprintf(buf, "%s%s\n\n%s\n%s\n%s\n\n%s%s\n%s",
+ snprintf(buf, sizeof(buf), "%s%s\n\n%s\n%s\n%s\n\n%s%s\n%s",
programVersion, zippy,
"Copyright 1991 Digital Equipment Corporation",
"Enhancements Copyright 1992-2009 Free Software Foundation",
"Enhancements Copyright 2005 Alessandro Scotti",
- PRODUCT, " is free software and carries NO WARRANTY;",
+ PACKAGE, " is free software and carries NO WARRANTY;",
"see the file COPYING for more information.");
ErrorPopUp(_("About XBoard"), buf, FALSE);
}
void DisplayMessage(message, extMessage)
char *message, *extMessage;
{
- char buf[MSG_SIZ];
- Arg arg;
-
- if (extMessage) {
- if (*message) {
- sprintf(buf, "%s %s", message, extMessage);
- message = buf;
- } else {
- message = extMessage;
- }
- }
- XtSetArg(arg, XtNlabel, message);
- XtSetValues(messageWidget, &arg, 1);
+ /* display a message in the message widget */
+
+ char buf[MSG_SIZ];
+ Arg arg;
+
+ if (extMessage)
+ {
+ if (*message)
+ {
+ snprintf(buf, sizeof(buf), "%s %s", message, extMessage);
+ message = buf;
+ }
+ else
+ {
+ message = extMessage;
+ };
+ };
+
+ /* need to test if messageWidget already exists, since this function
+ can also be called during the startup, if for example a Xresource
+ is not set up correctly */
+ if(messageWidget)
+ {
+ XtSetArg(arg, XtNlabel, message);
+ XtSetValues(messageWidget, &arg, 1);
+ };
+
+ return;
}
void DisplayTitle(text)
strcpy(icon, text);
strcpy(title, text);
} else if (appData.icsActive) {
- sprintf(icon, "%s", appData.icsHost);
- sprintf(title, "%s: %s", programName, appData.icsHost);
+ snprintf(icon, sizeof(icon), "%s", appData.icsHost);
+ snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost);
} else if (appData.cmailGameName[0] != NULLCHAR) {
- sprintf(icon, "%s", "CMail");
- sprintf(title, "%s: %s", programName, "CMail");
+ snprintf(icon, sizeof(icon), "%s", "CMail");
+ snprintf(title,sizeof(title), "%s: %s", programName, "CMail");
#ifdef GOTHIC
// [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it
} else if (gameInfo.variant == VariantGothic) {
strcpy(title, programName);
} else {
strcpy(icon, first.tidy);
- sprintf(title, "%s: %s", programName, first.tidy);
+ snprintf(title,sizeof(title), "%s: %s", programName, first.tidy);
}
i = 0;
XtSetArg(args[i], XtNiconName, (XtArgVal) icon); i++;
fprintf(stderr, "%s: %s: %s\n",
programName, message, strerror(error));
}
- sprintf(buf, "%s: %s", message, strerror(error));
+ snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
message = buf;
}
ErrorPopUp(_("Error"), message, FALSE);
} else {
fprintf(stderr, "%s: %s: %s\n",
programName, message, strerror(error));
- sprintf(buf, "%s: %s", message, strerror(error));
+ snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
message = buf;
}
if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) {
putc(BELLCHAR, stderr);
} else {
char buf[2048];
- sprintf(buf, "%s '%s' &", appData.soundProgram, name);
+ snprintf(buf, sizeof(buf), "%s '%s' &", appData.soundProgram, name);
system(buf);
}
}
ScheduleDelayedEvent(cb, millisec)
DelayedEventCallback cb; long millisec;
{
+ if(delayedEventTimerXID && delayedEventCallback == cb)
+ // [HGM] alive: replace, rather than add or flush identical event
+ XtRemoveTimeOut(delayedEventTimerXID);
delayedEventCallback = cb;
delayedEventTimerXID =
XtAppAddTimeOut(appContext, millisec,
char buf[MSG_SIZ];
Arg args[16];
+ /* check for low time warning */
+ Pixel foregroundOrWarningColor = timerForegroundPixel;
+
+ if (timer > 0 &&
+ appData.lowTimeWarning &&
+ (timer / 1000) < appData.icsAlarmTime)
+ foregroundOrWarningColor = lowTimeWarningColor;
+
if (appData.clockMode) {
sprintf(buf, "%s: %s", color, TimeString(timer));
XtSetArg(args[0], XtNlabel, buf);
}
if (highlight) {
- XtSetArg(args[1], XtNbackground, timerForegroundPixel);
+
+ XtSetArg(args[1], XtNbackground, foregroundOrWarningColor);
XtSetArg(args[2], XtNforeground, timerBackgroundPixel);
} else {
XtSetArg(args[1], XtNbackground, timerBackgroundPixel);
- XtSetArg(args[2], XtNforeground, timerForegroundPixel);
+ XtSetArg(args[2], XtNforeground, foregroundOrWarningColor);
}
XtSetValues(w, args, 3);
char cmdLine[MSG_SIZ];
if (port[0] == NULLCHAR) {
- sprintf(cmdLine, "%s %s", appData.telnetProgram, host);
+ snprintf(cmdLine, sizeof(cmdLine), "%s %s", appData.telnetProgram, host);
} else {
- sprintf(cmdLine, "%s %s %s", appData.telnetProgram, host, port);
+ snprintf(cmdLine, sizeof(cmdLine), "%s %s %s", appData.telnetProgram, host, port);
}
return StartChildProcess(cmdLine, "", pr);
}
int count;
int *outError;
{
+ static int line = 0;
ChildProc *cp = (ChildProc *) pr;
int outCount;
if (pr == NoProc)
- outCount = fwrite(message, 1, count, stdout);
+ {
+ if (appData.noJoin || !appData.useInternalWrap)
+ outCount = fwrite(message, 1, count, stdout);
+ else
+ {
+ int width = get_term_width();
+ int len = wrap(NULL, message, count, width, &line);
+ char *msg = malloc(len);
+ int dbgchk;
+
+ if (!msg)
+ outCount = fwrite(message, 1, count, stdout);
+ else
+ {
+ dbgchk = wrap(msg, message, count, width, &line);
+ if (dbgchk != len && appData.debugMode)
+ fprintf(debugFP, "wrap(): dbgchk(%d) != len(%d)\n", dbgchk, len);
+ outCount = fwrite(msg, 1, dbgchk, stdout);
+ free(msg);
+ }
+ }
+ }
else
outCount = write(cp->fdTo, message, count);
and dark squares, and all pieces must use the same
background square colors/images. */
+static int xpmDone = 0;
+
static void
CreateAnimMasks (pieceDepth)
int pieceDepth;
for (piece = WhitePawn; piece <= BlackKing; piece++) {
/* Begin with empty mask */
+ if(!xpmDone) // [HGM] pieces: keep using existing
xpmMask[piece] = XCreatePixmap(xDisplay, xBoardWindow,
squareSize, squareSize, 1);
XSetFunction(xDisplay, maskGC, GXclear);
static void
CreateAnimVars ()
{
- static int done = 0;
+ static VariantClass old = (VariantClass) -1; // [HGM] pieces: redo every time variant changes
XWindowAttributes info;
- if (done) return;
- done = 1;
+ if (xpmDone && gameInfo.variant == old) return;
+ if(xpmDone) old = gameInfo.variant; // first time pieces might not be created yet
XGetWindowAttributes(xDisplay, xBoardWindow, &info);
InitAnimState(&game, &info);
/* For XPM pieces, we need bitmaps to use as masks. */
if (useImages)
CreateAnimMasks(info.depth);
+ xpmDone = 1;
}
#ifndef HAVE_USLEEP
delay.it_interval.tv_usec =
delay.it_value.tv_usec = (time % 1000) * 1000;
setitimer(ITIMER_REAL, &delay, NULL);
-#if 0
- /* Ugh -- busy-wait! --tpm */
- while (frameWaiting);
-#else
while (frameWaiting) pause();
-#endif
delay.it_interval.tv_sec = delay.it_value.tv_sec = 0;
delay.it_interval.tv_usec = delay.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &delay, NULL);
#if HAVE_LIBXPM
*mask = xpmMask[piece];
#else
- *mask = ximMaskPm[piece%(int)BlackPawn];
+ *mask = ximMaskPm[piece];
#endif
} else {
*mask = *pieceToSolid(piece);
kind = 0;
else
kind = 2;
- XCopyArea(xDisplay, xpmPieceBitmap[kind][((int)piece) % (int)BlackPawn],
+ XCopyArea(xDisplay, xpmPieceBitmap[kind][piece],
dest, clip,
0, 0, squareSize, squareSize,
0, 0);
if (!appData.animate || appData.blindfold)
return;
+ if(board[toY][toX] == WhiteRook && board[fromY][fromX] == WhiteKing ||
+ board[toY][toX] == BlackRook && board[fromY][fromX] == BlackKing)
+ return; // [HGM] FRC: no animtion of FRC castlings, as to-square is not true to-square
+
if (fromY < 0 || fromX < 0 || toX < 0 || toY < 0) return;
piece = board[fromY][fromX];
if (piece >= EmptySquare) return;
damage[toY][toX] = True;
}
-static void
+void
DragPieceBegin(x, y)
int x; int y;
{
ScreenSquare(boardX, boardY, &corner, &color);
player.startSquare = corner;
player.startColor = color;
-#if 0
- /* Start from exactly where the piece is. This can be confusing
- if you start dragging far from the center of the square; most
- or all of the piece can be over a different square from the one
- the mouse pointer is in. */
- player.mouseDelta.x = x - corner.x;
- player.mouseDelta.y = y - corner.y;
-#else
/* As soon as we start dragging, the piece will jump slightly to
be centered over the mouse pointer. */
player.mouseDelta.x = squareSize/2;
player.mouseDelta.y = squareSize/2;
-#endif
/* Initialise animation */
player.dragPiece = PieceForSquare(boardX, boardY);
/* Sanity check */
#endif
}
-static void
+void
DragPieceEnd(x, y)
int x; int y;
{
// [HGM] done, but perhaps backend should call this directly?
EngineOutputUpdate( stats );
}
+
+#include <sys/ioctl.h>
+int get_term_width()
+{
+ int fd, default_width;
+
+ fd = STDIN_FILENO;
+ default_width = 79; // this is FICS default anyway...
+
+#if !defined(TIOCGWINSZ) && defined(TIOCGSIZE)
+ struct ttysize win;
+ if (!ioctl(fd, TIOCGSIZE, &win))
+ default_width = win.ts_cols;
+#elif defined(TIOCGWINSZ)
+ struct winsize win;
+ if (!ioctl(fd, TIOCGWINSZ, &win))
+ default_width = win.ws_col;
+#endif
+ return default_width;
+}
+
+void update_ics_width()
+{
+ static int old_width = 0;
+ int new_width = get_term_width();
+
+ if (old_width != new_width)
+ ics_printf("set width %d\n", new_width);
+ old_width = new_width;
+}
+
+void NotifyFrontendLogin()
+{
+ update_ics_width();
+}