code cleanup: make function definition confirm to GNU coding style
[xboard.git] / xengineoutput.c
1 /*
2  * Engine output (PV)
3  *
4  * Author: Alessandro Scotti (Dec 2005)
5  *
6  * Copyright 2005 Alessandro Scotti
7  *
8  * Enhancements Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
9  *
10  * ------------------------------------------------------------------------
11  *
12  * GNU XBoard is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or (at
15  * your option) any later version.
16  *
17  * GNU XBoard is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see http://www.gnu.org/licenses/.
24  *
25  * ------------------------------------------------------------------------
26  ** See the file ChangeLog for a revision history.  */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <sys/types.h>
34
35 #if STDC_HEADERS
36 # include <stdlib.h>
37 # include <string.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
40 # if HAVE_STRING_H
41 #  include <string.h>
42 # else /* not HAVE_STRING_H */
43 #  include <strings.h>
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
46
47 #if HAVE_UNISTD_H
48 # include <unistd.h>
49 #endif
50
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/Xaw/Dialog.h>
55 #include <X11/Xaw/Form.h>
56 #include <X11/Xaw/List.h>
57 #include <X11/Xaw/Label.h>
58 #include <X11/Xaw/SimpleMenu.h>
59 #include <X11/Xaw/SmeBSB.h>
60 #include <X11/Xaw/SmeLine.h>
61 #include <X11/Xaw/Box.h>
62 #include <X11/Xaw/Paned.h>
63 #include <X11/Xaw/MenuButton.h>
64 #include <X11/cursorfont.h>
65 #include <X11/Xaw/Text.h>
66 #include <X11/Xaw/AsciiText.h>
67 #include <X11/Xaw/Viewport.h>
68 #include <X11/Xatom.h>
69 #include <X11/Xmu/Atoms.h>
70
71 #include "common.h"
72 #include "frontend.h"
73 #include "backend.h"
74 #include "xboard.h"
75 #include "engineoutput.h"
76 #include "gettext.h"
77
78 #ifdef ENABLE_NLS
79 # define  _(s) gettext (s)
80 # define N_(s) gettext_noop (s)
81 #else
82 # define  _(s) (s)
83 # define N_(s)  s
84 #endif
85
86 #include <X11/xpm.h>
87
88 // [HGM] pixmaps of some ICONS used in the engine-outut window
89 #include "pixmaps/WHITE_14.xpm"
90 #include "pixmaps/BLACK_14.xpm"
91 #include "pixmaps/CLEAR_14.xpm"
92 #include "pixmaps/UNKNOWN_14.xpm"
93 #include "pixmaps/THINKING_14.xpm"
94 #include "pixmaps/PONDER_14.xpm"
95 #include "pixmaps/ANALYZING_14.xpm"
96
97 #ifdef SNAP
98 #include "wsnap.h"
99 #endif
100
101 #define _LL_ 100
102
103 Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
104 Widget outputField[2][7]; // [HGM] front-end array to translate output field to window handle
105
106 void EngineOutputPopDown();
107 void engineOutputPopUp();
108 int  EngineOutputIsUp();
109 void SetEngineColorIcon( int which );
110
111 //extern WindowPlacement wpEngineOutput;
112
113 Position engineOutputX = -1, engineOutputY = -1;
114 Dimension engineOutputW, engineOutputH;
115 Widget engineOutputShell;
116 static int engineOutputDialogUp;
117
118 /* Module variables */
119 int  windowMode = 1;
120 static int currentPV, highTextStart[2], highTextEnd[2];
121
122 typedef struct {
123     char * name;
124     int which;
125     int depth;
126     u64 nodes;
127     int score;
128     int time;
129     char * pv;
130     char * hint;
131     int an_move_index;
132     int an_move_count;
133 } EngineOutputData;
134
135 //static void UpdateControls( EngineOutputData * ed );
136
137 void
138 ReadIcon (char *pixData[], int iconNr)
139 {
140     int r;
141
142         if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(outputField[0][nColorIcon]),
143                                        pixData,
144                                        &(icons[iconNr]),
145                                        NULL, NULL /*&attr*/)) != 0) {
146           fprintf(stderr, _("Error %d loading icon image\n"), r);
147           exit(1);
148         }
149 }
150
151 static void
152 InitializeEngineOutput ()
153 {
154         ReadIcon(WHITE_14,   nColorWhite);
155         ReadIcon(BLACK_14,   nColorBlack);
156         ReadIcon(UNKNOWN_14, nColorUnknown);
157
158         ReadIcon(CLEAR_14,   nClear);
159         ReadIcon(PONDER_14,  nPondering);
160         ReadIcon(THINK_14,   nThinking);
161         ReadIcon(ANALYZE_14, nAnalyzing);
162 }
163
164 void
165 DoSetWindowText (int which, int field, char *s_label)
166 {
167         Arg arg;
168
169         XtSetArg(arg, XtNlabel, (XtArgVal) s_label);
170         XtSetValues(outputField[which][field], &arg, 1);
171 }
172
173 void
174 SetEngineOutputTitle (char *title)
175 {
176         Arg arg;
177         XtSetArg(arg, XtNtitle, (XtArgVal) title);
178         XtSetValues(engineOutputShell, &arg, 1);
179 }
180
181 void
182 InsertIntoMemo (int which, char * text, int where)
183 {
184         XawTextBlock t;
185         Widget edit;
186
187         /* the backend adds \r\n, which is needed for winboard,
188          * for xboard we delete them again over here */
189         if(t.ptr = strchr(text, '\r')) *t.ptr = ' ';
190
191         t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit;
192         edit = XtNameToWidget(engineOutputShell, which ? "*form2.text" : "*form.text");
193         XawTextReplace(edit, where, where, &t);
194         if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
195             int len = strlen(text);
196             highTextStart[which] += len; highTextEnd[which] += len;
197             XawTextSetSelection( outputField[which][nMemo], highTextStart[which], highTextEnd[which] );
198         }
199 }
200
201 void
202 SetIcon (int which, int field, int nIcon)
203 {
204     Arg arg;
205
206     if( nIcon != 0 ) {
207         XtSetArg(arg, XtNleftBitmap, (XtArgVal) icons[nIcon]);
208         XtSetValues(outputField[which][field], &arg, 1);
209     }
210 }
211
212 void
213 DoClearMemo (int which)
214 {
215     Widget edit = XtNameToWidget(engineOutputShell, which ? "*form2.text" : "*form.text");
216     Arg arg;
217 //    XtCallActionProc(edit, "select-all", NULL, NULL, 0);
218 //    XtCallActionProc(edit, "kill-selection", NULL, NULL, 0);
219     XtSetArg(arg, XtNstring, ""); // clear without disturbing selection!
220     XtSetValues(edit, &arg, 1);
221 }
222
223 // cloned from CopyPositionProc. Abuse selected_fen_position to hold selection
224
225 Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target,
226                  Atom *type_return, XtPointer *value_return,
227                  unsigned long *length_return, int *format_return); // from xboard.c
228 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b); // from xoptions.c
229
230 char memoTranslations[] =
231 ":Ctrl<Key>c: CopyMemoProc() \n \
232 <Btn3Motion>: HandlePV() \n \
233 Shift<Btn3Down>: select-start() SelectPV(1) \n \
234 Any<Btn3Down>: select-start() SelectPV(0) \n \
235 <Btn3Up>: extend-end() StopPV() \n";
236
237 void
238 SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
239 {       // [HGM] pv: translate click to PV line, and load it for display
240         String val;
241         int start, end;
242         XawTextPosition index, dummy;
243         int x, y;
244         Arg arg;
245
246         x = event->xmotion.x; y = event->xmotion.y;
247         currentPV = (w == outputField[1][nMemo]);
248         XawTextGetSelectionPos(w, &index, &dummy);
249         XtSetArg(arg, XtNstring, &val);
250         XtGetValues(w, &arg, 1);
251         shiftKey = strcmp(params[0], "0");
252         if(LoadMultiPV(x, y, val, index, &start, &end)) {
253             XawTextSetSelection( outputField[currentPV][nMemo], start, end );
254             highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
255         }
256 }
257
258 void
259 StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
260 {       // [HGM] pv: on right-button release, stop displaying PV
261         XawTextUnsetSelection( w );
262         highTextStart[currentPV] = highTextEnd[currentPV] = 0;
263         UnLoadPV();
264 }
265
266 static void
267 MemoCB (Widget w, XtPointer client_data, Atom *selection,
268         Atom *type, XtPointer value, unsigned long *len, int *format)
269 {
270   if (value==NULL || *len==0) return; /* nothing had been selected to copy */
271   selected_fen_position = value;
272   selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */
273     XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
274                    CurrentTime,
275                    SendPositionSelection,
276                    NULL/* lose_ownership_proc */ ,
277                    NULL/* transfer_done_proc */);
278 }
279
280 void
281 CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
282 {
283     if(appData.pasteSelection) return;
284     if (selected_fen_position) free(selected_fen_position);
285     XtGetSelectionValue(menuBarWidget,
286       XA_PRIMARY, XA_STRING,
287       /* (XtSelectionCallbackProc) */ MemoCB,
288       NULL, /* client_data passed to PastePositionCB */
289
290       /* better to use the time field from the event that triggered the
291        * call to this function, but that isn't trivial to get
292        */
293       CurrentTime
294     );
295 }
296
297 // The following routines are mutated clones of the commentPopUp routines
298
299 void
300 PositionControlSet (int which, Widget shell, Widget form, Dimension bw_width)
301 {
302     Arg args[16];
303     Widget edit, NameWidget, ColorWidget, ModeWidget, MoveWidget, NodesWidget;
304     int j, mutable=1;
305     j = 0;
306     XtSetArg(args[j], XtNborderWidth, (XtArgVal) 0); j++;
307     XtSetArg(args[j], XtNlabel,     (XtArgVal) ""); j++;
308     XtSetArg(args[j], XtNtop,       XtChainTop); j++;
309     XtSetArg(args[j], XtNbottom,    XtChainTop); j++;
310     XtSetArg(args[j], XtNleft,      XtChainLeft); j++;
311     XtSetArg(args[j], XtNright,     XtChainLeft); j++;
312     XtSetArg(args[j], XtNheight,    (XtArgVal) 16); j++;
313     XtSetArg(args[j], XtNwidth,     (XtArgVal) 17); j++;
314     outputField[which][nColorIcon] = ColorWidget =
315       XtCreateManagedWidget("Color", labelWidgetClass,
316                      form, args, j);
317
318     j = 0;
319     XtSetArg(args[j], XtNborderWidth, (XtArgVal) 0); j++;
320     XtSetArg(args[j], XtNjustify,   (XtArgVal) XtJustifyLeft); j++;
321     XtSetArg(args[j], XtNfromHoriz, (XtArgVal) ColorWidget); j++;
322     XtSetArg(args[j], XtNtop,       XtChainTop); j++;
323     XtSetArg(args[j], XtNbottom,    XtChainTop); j++;
324     XtSetArg(args[j], XtNleft,      XtChainLeft); j++;
325     XtSetArg(args[j], XtNheight,    (XtArgVal) 16); j++;
326     XtSetArg(args[j], XtNwidth,     (XtArgVal) bw_width/2 - 57); j++;
327     outputField[which][nLabel] = NameWidget =
328       XtCreateManagedWidget("Engine", labelWidgetClass,
329                      form, args, j);
330
331     j = 0;
332     XtSetArg(args[j], XtNborderWidth, (XtArgVal) 0); j++;
333     XtSetArg(args[j], XtNlabel,     (XtArgVal) ""); j++;
334     XtSetArg(args[j], XtNfromHoriz, (XtArgVal) NameWidget); j++;
335     XtSetArg(args[j], XtNtop,       XtChainTop); j++;
336     XtSetArg(args[j], XtNbottom,    XtChainTop); j++;
337     XtSetArg(args[j], XtNheight,    (XtArgVal) 16); j++;
338     XtSetArg(args[j], XtNwidth,     (XtArgVal) 20); j++;
339     outputField[which][nStateIcon] = ModeWidget =
340       XtCreateManagedWidget("Mode", labelWidgetClass,
341                      form, args, j);
342
343     j = 0;
344     XtSetArg(args[j], XtNborderWidth, (XtArgVal) 0); j++;
345     XtSetArg(args[j], XtNjustify,   (XtArgVal) XtJustifyLeft); j++;
346     XtSetArg(args[j], XtNlabel,     (XtArgVal) ""); j++;
347     XtSetArg(args[j], XtNfromHoriz, (XtArgVal) ModeWidget); j++;
348     XtSetArg(args[j], XtNtop,       XtChainTop); j++;
349     XtSetArg(args[j], XtNbottom,    XtChainTop); j++;
350     XtSetArg(args[j], XtNright,     XtChainRight); j++;
351     XtSetArg(args[j], XtNheight,    (XtArgVal) 16); j++;
352     XtSetArg(args[j], XtNwidth,     (XtArgVal) bw_width/2 - 102); j++;
353     outputField[which][nStateData] = MoveWidget =
354       XtCreateManagedWidget("Move", labelWidgetClass,
355                      form, args, j);
356
357     j = 0;
358     XtSetArg(args[j], XtNborderWidth, (XtArgVal) 0); j++;
359     XtSetArg(args[j], XtNjustify,   (XtArgVal) XtJustifyRight); j++;
360     XtSetArg(args[j], XtNlabel,     (XtArgVal) _("NPS")); j++;
361     XtSetArg(args[j], XtNfromHoriz, (XtArgVal) MoveWidget); j++;
362     XtSetArg(args[j], XtNtop,       XtChainTop); j++;
363     XtSetArg(args[j], XtNbottom,    XtChainTop); j++;
364     XtSetArg(args[j], XtNleft,      XtChainRight); j++;
365     XtSetArg(args[j], XtNright,     XtChainRight); j++;
366     XtSetArg(args[j], XtNheight,    (XtArgVal) 16); j++;
367     XtSetArg(args[j], XtNwidth,     (XtArgVal) 100); j++;
368     outputField[which][nLabelNPS] = NodesWidget =
369       XtCreateManagedWidget("Nodes", labelWidgetClass,
370                      form, args, j);
371
372     // create "text" within "form"
373     j = 0;
374     if (mutable) {
375         XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
376         XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
377     }
378     XtSetArg(args[j], XtNstring, "");  j++;
379     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
380     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
381     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
382     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
383     XtSetArg(args[j], XtNright, XtChainRight);  j++;
384     XtSetArg(args[j], XtNresizable, True);  j++;
385     XtSetArg(args[j], XtNwidth, bw_width);  j++; /*force wider than buttons*/
386     /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
387     XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways);  j++;
388     XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollWhenNeeded);  j++;
389 //    XtSetArg(args[j], XtNautoFill, True);  j++;
390 //    XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++;
391     outputField[which][nMemo] = edit =
392       XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
393
394     XtOverrideTranslations(edit, XtParseTranslationTable(memoTranslations));
395     XtAddEventHandler(edit, ButtonPressMask, False, SetFocus, (XtPointer) shell);
396
397     j = 0;
398     XtSetArg(args[j], XtNfromVert, ColorWidget); j++;
399 //    XtSetArg(args[j], XtNresizable, (XtArgVal) True); j++;
400     XtSetValues(edit, args, j);
401 }
402
403 Widget
404 EngineOutputCreate (char *name, char *text)
405 {
406     Arg args[16];
407     Widget shell, layout, form, form2;
408     Dimension bw_width, bw_height;
409     int j;
410
411     // get board width
412     j = 0;
413     XtSetArg(args[j], XtNwidth,  &bw_width);  j++;
414     XtSetArg(args[j], XtNheight, &bw_height);  j++;
415     XtGetValues(boardWidget, args, j);
416
417     // define form within layout within shell.
418     j = 0;
419     XtSetArg(args[j], XtNresizable, True);  j++;
420     shell =
421 #if TOPLEVEL
422      XtCreatePopupShell(name, topLevelShellWidgetClass,
423 #else
424       XtCreatePopupShell(name, transientShellWidgetClass,
425 #endif
426                          shellWidget, args, j);
427     layout =
428       XtCreateManagedWidget(layoutName, formWidgetClass, shell,
429                             layoutArgs, XtNumber(layoutArgs));
430     // divide window vertically into two equal parts, by creating two forms
431     form =
432       XtCreateManagedWidget("form", formWidgetClass, layout,
433                             formArgs, XtNumber(formArgs));
434     form2 =
435       XtCreateManagedWidget("form2", formWidgetClass, layout,
436                             formArgs, XtNumber(formArgs));
437     j = 0;
438     XtSetArg(args[j], XtNfromVert,  (XtArgVal) form); j++;
439     XtSetValues(form2, args, j);
440     // make sure width is known in advance, for better placement of child widgets
441     j = 0;
442     XtSetArg(args[j], XtNwidth,     (XtArgVal) bw_width-16); j++;
443     XtSetArg(args[j], XtNheight,    (XtArgVal) bw_height/2); j++;
444     XtSetValues(shell, args, j);
445
446     // fill up both forms with control elements
447     PositionControlSet(0, shell, form,  bw_width);
448     PositionControlSet(1, shell, form2, bw_width);
449
450     XtRealizeWidget(shell);
451
452     if(wpEngineOutput.width > 0) {
453       engineOutputW = wpEngineOutput.width;
454       engineOutputH = wpEngineOutput.height;
455       engineOutputX = wpEngineOutput.x;
456       engineOutputY = wpEngineOutput.y;
457     }
458
459     if (engineOutputX == -1) {
460         int xx, yy;
461         Window junk;
462
463         engineOutputH = bw_height/2;
464         engineOutputW = bw_width-16;
465
466         XSync(xDisplay, False);
467 #ifdef NOTDEF
468         /* This code seems to tickle an X bug if it is executed too soon
469            after xboard starts up.  The coordinates get transformed as if
470            the main window was positioned at (0, 0).
471            */
472         XtTranslateCoords(shellWidget,
473                           (bw_width - engineOutputW) / 2, 0 - engineOutputH / 2,
474                           &engineOutputX, &engineOutputY);
475 #else  /*!NOTDEF*/
476         XTranslateCoordinates(xDisplay, XtWindow(shellWidget),
477                               RootWindowOfScreen(XtScreen(shellWidget)),
478                               (bw_width - engineOutputW) / 2, 0 - engineOutputH / 2,
479                               &xx, &yy, &junk);
480         engineOutputX = xx;
481         engineOutputY = yy;
482 #endif /*!NOTDEF*/
483         if (engineOutputY < 0) engineOutputY = 0; /*avoid positioning top offscreen*/
484     }
485     j = 0;
486     XtSetArg(args[j], XtNheight, engineOutputH);  j++;
487     XtSetArg(args[j], XtNwidth, engineOutputW);  j++;
488     XtSetArg(args[j], XtNx, engineOutputX);  j++;
489     XtSetArg(args[j], XtNy, engineOutputY);  j++;
490     XtSetValues(shell, args, j);
491
492     return shell;
493 }
494
495 void
496 ResizeWindowControls (int mode)
497 {
498     Widget form1, form2;
499     Arg args[16];
500     int j;
501     Dimension ew_height, tmp;
502     Widget shell = engineOutputShell;
503
504     form1 = XtNameToWidget(shell, "*form");
505     form2 = XtNameToWidget(shell, "*form2");
506
507     j = 0;
508     XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
509     XtGetValues(form1, args, j);
510     j = 0;
511     XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
512     XtGetValues(form2, args, j);
513     ew_height += tmp; // total height
514
515     if(mode==0) {
516         j = 0;
517         XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
518         XtSetValues(form2, args, j);
519         j = 0;
520         XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
521         XtSetValues(form1, args, j);
522     } else {
523         j = 0;
524         XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
525         XtSetValues(form1, args, j);
526         j = 0;
527         XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
528         XtSetValues(form2, args, j);
529     }
530 }
531
532 void
533 EngineOutputPopUp ()
534 {
535     Arg args[16];
536     int j;
537     Widget edit;
538     static int  needInit = TRUE;
539     static char *title = N_("Engine output"), *text = N_("This feature is experimental");
540
541     if (engineOutputShell == NULL) {
542         engineOutputShell =
543           EngineOutputCreate(_(title), _(text));
544         XtRealizeWidget(engineOutputShell);
545         CatchDeleteWindow(engineOutputShell, "EngineOutputPopDown");
546         if( needInit ) {
547             InitializeEngineOutput();
548             needInit = FALSE;
549         }
550         SetEngineColorIcon( 0 );
551         SetEngineColorIcon( 1 );
552         SetEngineState( 0, STATE_IDLE, "" );
553         SetEngineState( 1, STATE_IDLE, "" );
554     } else {
555         edit = XtNameToWidget(engineOutputShell, "*form.text");
556         j = 0;
557         XtSetArg(args[j], XtNstring, text); j++;
558         XtSetValues(edit, args, j);
559         j = 0;
560         XtSetArg(args[j], XtNiconName, (XtArgVal) _(title));   j++;
561         XtSetArg(args[j], XtNtitle, (XtArgVal) _(title));      j++;
562         XtSetValues(engineOutputShell, args, j);
563     }
564
565     XtPopup(engineOutputShell, XtGrabNone);
566     XSync(xDisplay, False);
567
568     j=0;
569     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
570     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Engine Output"),
571                 args, j);
572
573     engineOutputDialogUp = True;
574     ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
575 }
576
577 void
578 EngineOutputPopDown ()
579 {
580     Arg args[16];
581     int j;
582
583     if (!engineOutputDialogUp) return;
584     DoClearMemo(1);
585     j = 0;
586     XtSetArg(args[j], XtNx, &engineOutputX); j++;
587     XtSetArg(args[j], XtNy, &engineOutputY); j++;
588     XtSetArg(args[j], XtNwidth, &engineOutputW); j++;
589     XtSetArg(args[j], XtNheight, &engineOutputH); j++;
590     XtGetValues(engineOutputShell, args, j);
591     wpEngineOutput.x = engineOutputX - 4;
592     wpEngineOutput.y = engineOutputY - 23;
593     wpEngineOutput.width = engineOutputW;
594     wpEngineOutput.height = engineOutputH;
595     XtPopdown(engineOutputShell);
596     XSync(xDisplay, False);
597     j=0;
598     XtSetArg(args[j], XtNleftBitmap, None); j++;
599     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Engine Output"),
600                 args, j);
601
602     engineOutputDialogUp = False;
603     ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output
604 }
605
606 int
607 EngineOutputIsUp ()
608 {
609     return engineOutputDialogUp;
610 }
611
612 int
613 EngineOutputDialogExists ()
614 {
615     return engineOutputShell != NULL;
616 }
617
618 void
619 EngineOutputProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
620 {
621   if (engineOutputDialogUp) {
622     EngineOutputPopDown();
623   } else {
624     EngineOutputPopUp();
625   }
626 }