X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xaw%2Fxboard.c;h=1c3ffc76607715fa075e7454d7c18fca5373d65a;hb=HEAD;hp=7669269d7fbf9d2bde92cb99f32ecee3ac8c21d4;hpb=8a0368b7169965529802961fbd16fdfacf3c639d;p=xboard.git diff --git a/xaw/xboard.c b/xaw/xboard.c index 7669269..1c3ffc7 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -5,7 +5,8 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012 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: @@ -148,6 +149,7 @@ extern char *getenv(); #include #endif +#include #include #include #include @@ -183,13 +185,6 @@ extern char *getenv(); // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are. #include "common.h" -#if HAVE_LIBXPM -#include -#define IMAGE_EXT "xpm" -#else -#define IMAGE_EXT "xim" -#endif - #include "bitmaps/icon_white.bm" #include "bitmaps/icon_black.bm" #include "bitmaps/checkmark.bm" @@ -202,8 +197,6 @@ extern char *getenv(); #include "childio.h" #include "xgamelist.h" #include "xhistory.h" -#include "xevalgraph.h" -#include "xedittags.h" #include "menus.h" #include "board.h" #include "dialogs.h" @@ -212,6 +205,7 @@ extern char *getenv(); #include "gettext.h" #include "draw.h" +#define SLASH '/' #ifdef __EMX__ #ifndef HAVE_USLEEP @@ -262,9 +256,9 @@ void TempForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) Boolean TempBackwardActive = False; void ManInner P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DisplayMove P((int moveNumber)); -void ICSInitScript P((void)); 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 @@ -320,6 +314,7 @@ WindowPlacement wpEvalGraph; WindowPlacement wpEngineOutput; WindowPlacement wpGameList; WindowPlacement wpTags; +WindowPlacement wpDualBoard; /* This magic number is the number of intermediate frames used @@ -389,60 +384,17 @@ XtActionsRec boardActions[] = { }; char globalTranslations[] = - ":F9: MenuItem(Actions.Resign) \n \ - :Ctrln: MenuItem(File.NewGame) \n \ - :MetaV: MenuItem(File.NewVariant) \n \ - :Ctrlo: MenuItem(File.LoadGame) \n \ - :MetaNext: MenuItem(LoadNextGameProc) \n \ + ":MetaNext: MenuItem(LoadNextGameProc) \n \ :MetaPrior: MenuItem(LoadPrevGameProc) \n \ :CtrlDown: LoadSelectedProc(3) \n \ :CtrlUp: LoadSelectedProc(-3) \n \ - :Ctrls: MenuItem(File.SaveGame) \n \ - :Ctrlc: MenuItem(Edit.CopyGame) \n \ - :Ctrlv: MenuItem(Edit.PasteGame) \n \ - :CtrlO: MenuItem(File.LoadPosition) \n \ :ShiftNext: MenuItem(LoadNextPositionProc) \n \ :ShiftPrior: MenuItem(LoadPrevPositionProc) \n \ - :CtrlS: MenuItem(File.SavePosition) \n \ - :CtrlC: MenuItem(Edit.CopyPosition) \n \ - :CtrlV: MenuItem(Edit.PastePosition) \n \ - :Ctrlq: MenuItem(File.Quit) \n \ - :Ctrlw: MenuItem(Mode.MachineWhite) \n \ - :Ctrlb: MenuItem(Mode.MachineBlack) \n \ - :Ctrlt: MenuItem(Mode.TwoMachines) \n \ - :Ctrla: MenuItem(Mode.AnalysisMode) \n \ - :Ctrlg: MenuItem(Mode.AnalyzeFile) \n \ - :Ctrle: MenuItem(Mode.EditGame) \n \ - :CtrlE: MenuItem(Mode.EditPosition) \n \ - :MetaO: MenuItem(View.EngineOutput) \n \ - :MetaE: MenuItem(View.EvaluationGraph) \n \ - :MetaG: MenuItem(View.GameList) \n \ - :MetaH: MenuItem(View.MoveHistory) \n \ :Pause: MenuItem(Mode.Pause) \n \ - :F3: MenuItem(Action.Accept) \n \ - :F4: MenuItem(Action.Decline) \n \ - :F12: MenuItem(Action.Rematch) \n \ - :F5: MenuItem(Action.CallFlag) \n \ - :F6: MenuItem(Action.Draw) \n \ - :F7: MenuItem(Action.Adjourn) \n \ - :F8: MenuItem(Action.Abort) \n \ - :F10: MenuItem(Action.StopObserving) \n \ - :F11: MenuItem(Action.StopExamining) \n \ :Ctrld: MenuItem(DebugProc) \n \ :Meta CtrlF12: MenuItem(DebugProc) \n \ - :MetaEnd: MenuItem(Edit.ForwardtoEnd) \n \ - :MetaRight: MenuItem(Edit.Forward) \n \ - :MetaHome: MenuItem(Edit.BacktoStart) \n \ - :MetaLeft: MenuItem(Edit.Backward) \n \ :Left: MenuItem(Edit.Backward) \n \ :Right: MenuItem(Edit.Forward) \n \ - :Home: MenuItem(Edit.Revert) \n \ - :End: MenuItem(Edit.TruncateGame) \n \ - :Ctrlm: MenuItem(Engine.MoveNow) \n \ - :Ctrlx: MenuItem(Engine.RetractMove) \n \ - :MetaJ: MenuItem(Options.Adjudications) \n \ - :MetaU: MenuItem(Options.CommonEngine) \n \ - :MetaT: MenuItem(Options.TimeControl) \n \ :CtrlP: MenuItem(PonderNextMove) \n " #ifndef OPTIONSDIALOG "\ @@ -453,8 +405,6 @@ char globalTranslations[] = :CtrlH: MenuItem(HideThinkingProc) \n " #endif "\ - :F1: MenuItem(Help.ManXBoard) \n \ - :F2: MenuItem(View.FlipView) \n \ :Return: TempBackwardProc() \n \ :Return: TempForwardProc() \n"; @@ -465,7 +415,7 @@ char ICSInputTranslations[] = // [HGM] vari: another hideous kludge: call extend-end first so we can be sure select-start works, // as the widget is destroyed before the up-click can call extend-end -char commentTranslations[] = ": extend-end() select-start() CommentClick() \n"; +char commentTranslations[] = ": extend-end(PRIMARY) select-start() CommentClick() \n"; String xboardResources[] = { "*Error*translations: #override\\n Return: ErrorPopDown()", @@ -476,128 +426,6 @@ String xboardResources[] = { /* Max possible square size */ #define MAXSQSIZE 256 -static int xpm_avail[MAXSQSIZE]; - -#ifdef HAVE_DIR_STRUCT - -/* Extract piece size from filename */ -static int -xpm_getsize (char *name, int len, char *ext) -{ - char *p, *d; - char buf[10]; - - if (len < 4) - return 0; - - if ((p=strchr(name, '.')) == NULL || - StrCaseCmp(p+1, ext) != 0) - return 0; - - p = name + 3; - d = buf; - - while (*p && isdigit(*p)) - *(d++) = *(p++); - - *d = 0; - return atoi(buf); -} - -/* Setup xpm_avail */ -static int -xpm_getavail (char *dirname, char *ext) -{ - DIR *dir; - struct dirent *ent; - int i; - - for (i=0; id_name, NAMLEN(ent), ext); - if (i > 0 && i < MAXSQSIZE) - xpm_avail[i] = 1; - } - - closedir(dir); - - return 0; -} - -void -xpm_print_avail (FILE *fp, char *ext) -{ - int i; - - fprintf(fp, _("Available `%s' sizes:\n"), ext); - for (i=1; i= 0 && size= 0 && size") ) ctrl = 1; + if( strstr(mi[j].accel, "") ) shift = 1; + if( strstr(mi[j].accel, "") ) alt = 1; + + /* remove all <...> */ + test = strrchr(mi[j].accel, '>'); + if ( test==NULL ) + key = strdup(mi[j].accel); + else + key = strdup(++test); // remove ">" + + /* instead of shift X11 uses the uppercase letter directly*/ + if (shift && strlen(key)==1 ) + { + *key = toupper(*key); + shift = 0; + } + + /* handle some special cases which have different names in X11 */ + if ( strncmp(key, "Page_Down", 9) == 0 ) + { + free(key); + key=strdup("Next"); + } + else if ( strncmp(key, "Page_Up", 7) == 0 ) + { + free(key); + key=strdup("Prior"); + }; + + /* create string of mods */ + if (ctrl) + mods = strdup("Ctrl "); + else + mods = strdup(""); + + if(alt) + { + mods = realloc(mods, strlen(mods) + strlen("Meta ")+1); + strncat(mods, "Meta ", 5); + }; + + if(shift) + { + mods = realloc(mods, strlen(mods) + strlen("Shift ")+1); + strncat(mods, "Shift ", 6); + }; + + // remove trailing space + if( isspace(mods[strlen(mods)-1]) ) + mods[strlen(mods)-1]='\0'; + + /* get the name for the callback, we can use MenuItem() here that will call KeyBindingProc */ + 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); + + char *buffer = malloc(MSG_SIZ); + snprintf(buffer, MSG_SIZ, ":%s%s: MenuItem(%s) \n ", mods, key, name); + + /* add string to the output */ + 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); + free(buffer); + free(name); + free(mods); + } + } + } + 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]; +} + + void PrintOptions () { @@ -1028,6 +978,11 @@ PrintOptions () if(len) buf[len] = NULLCHAR, printf("%s\n", buf); } +void +SlaveResize (Option *opt) +{ +} + int main (int argc, char **argv) { @@ -1038,6 +993,9 @@ main (int argc, char **argv) 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); @@ -1045,7 +1003,7 @@ main (int argc, char **argv) debugFP = stderr; if(argc > 1 && (!strcmp(argv[1], "-v" ) || !strcmp(argv[1], "--version" ))) { - printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); + printf("%s version %s\n\n configure options: %s\n", PACKAGE_NAME, PACKAGE_VERSION, CONFIGURE_OPTIONS); exit(0); } @@ -1054,6 +1012,23 @@ main (int argc, char **argv) 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]; @@ -1150,6 +1125,8 @@ main (int argc, char **argv) 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; @@ -1173,8 +1150,8 @@ main (int argc, char **argv) } 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--; @@ -1257,7 +1234,7 @@ main (int argc, char **argv) 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); @@ -1267,7 +1244,6 @@ main (int argc, char **argv) XtSetArg(args[1], XtNforeground, &buttonForegroundPixel); XtGetValues(optList[W_PAUSE].handle, args, 2); } - AppendEnginesToMenu(appData.recentEngineList); xBoardWindow = XtWindow(boardWidget); @@ -1314,21 +1290,28 @@ main (int argc, char **argv) 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); } if (appData.animate || appData.animateDragging) CreateAnimVars(); + + char *TranslationsTableMenus=GenerateGlobalTranslationTable (); + XtAugmentTranslations(formWidget, XtParseTranslationTable(globalTranslations)); + XtAugmentTranslations(formWidget, + XtParseTranslationTable(TranslationsTableMenus)); XtAddEventHandler(formWidget, KeyPressMask, False, (XtEventHandler) MoveTypeInProc, NULL); @@ -1349,6 +1332,9 @@ main (int argc, char **argv) EngineOutputPopUp(); } + gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes() + InitPosition(TRUE); + InitBackEnd2(); if (errorExitStatus == -1) { @@ -1369,8 +1355,6 @@ main (int argc, char **argv) } } - gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes() - InitPosition(TRUE); UpdateLogos(TRUE); // XtSetKeyboardFocus(shellWidget, formWidget); XSetInputFocus(xDisplay, XtWindow(formWidget), RevertToPointerRoot, CurrentTime); @@ -1380,6 +1364,13 @@ main (int argc, char **argv) return 0; } +void +DoEvents () +{ + XtInputMask m; + while((m = XtAppPending(appContext))) XtAppProcessEvent(appContext, m); +} + RETSIGTYPE TermSizeSigHandler (int sig) { @@ -1563,7 +1554,7 @@ FindFont (char *pattern, int targetPxlSize) safeStrCpy(p, best, strlen(best)+1 ); } if (appData.debugMode) { - fprintf(debugFP, _("resolved %s at pixel size %d\n to %s\n"), + fprintf(debugFP, "resolved %s at pixel size %d\n to %s\n", pattern, targetPxlSize, p); } XFreeFontNames(fonts); @@ -1625,18 +1616,6 @@ KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) if(item) ((MenuProc *) item->proc) (); } -static void -MenuEngineSelect (Widget w, caddr_t addr, caddr_t index) -{ - RecentEngineEvent((int) (intptr_t) addr); -} - -void -AppendMenuItem (char *msg, int n) -{ - CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n); -} - void SetupDropMenu () { @@ -1730,7 +1709,7 @@ ReSize (WindowPlacement *wp) 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; @@ -1796,7 +1775,7 @@ HandlePV (Widget w, XEvent * event, String * params, Cardinal * nParams) MovePV(event->xmotion.x, event->xmotion.y, lineGap + BOARD_HEIGHT * (squareSize + lineGap)); } -static int savedIndex; /* gross that this is global */ +extern int savedIndex; /* gross that this is global */ void CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) @@ -1813,27 +1792,6 @@ CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) LoadVariation( index, val ); // [HGM] also does the actual moving to it, now } -void -EditCommentPopUp (int index, char *title, char *text) -{ - savedIndex = index; - if (text == NULL) text = ""; - NewCommentPopup(title, text, index); -} - -void -CommentPopUp (char *title, char *text) -{ - savedIndex = currentMove; // [HGM] vari - NewCommentPopup(title, text, currentMove); -} - -void -CommentPopDown () -{ - PopDown(CommentDlg); -} - /* Disable all user input other than deleting the window */ static int frozen = 0; @@ -1861,7 +1819,7 @@ ModeHighlight () { Arg args[16]; static int oldPausing = FALSE; - static GameMode oldmode = (GameMode) -1; + static GameMode oldMode = (GameMode) -1; char *wname; if (!boardWidget || !XtIsRealized(boardWidget)) return; @@ -1887,7 +1845,7 @@ ModeHighlight () } } - wname = ModeToWidgetName(oldmode); + wname = ModeToWidgetName(oldMode); if (wname != NULL) { MarkMenuItem(wname, False); } @@ -1895,8 +1853,9 @@ ModeHighlight () 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); @@ -2039,6 +1998,7 @@ PasteGameCB (Widget w, XtPointer client_data, Atom *selection, 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 */ } @@ -2050,7 +2010,9 @@ PasteGameCB (Widget w, XtPointer client_data, Atom *selection, 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, @@ -2167,6 +2129,15 @@ ManProc () } 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]; @@ -2403,6 +2374,19 @@ SetClockIcon (int color) } } +#define INPUT_SOURCE_BUF_SIZE 8192 + +typedef struct { + CPKind kind; + int fd; + int lineByLine; + char *unused; + InputCallback func; + XtInputId xid; + char buf[INPUT_SOURCE_BUF_SIZE]; + VOIDSTAR closure; +} InputSource; + void DoInputCallback (caddr_t closure, int *source, XtInputId *xid) { @@ -2526,6 +2510,19 @@ FrameDelay (int time) #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) { @@ -2535,8 +2532,11 @@ 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])