3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gyas ROwers Mature At Cryogenic Speed
47 /* These colours will be mapped to black on a monochrome screen */
48 unsigned long BLACK
,BLUE
,GREEN
,CYAN
,RED
,BROWN
,GREY
,DARKGREY
;
50 /* These colours will be mapped to white on a monochrome screen */
51 unsigned long LIGHTBLUE
,LIGHTGREEN
,LIGHTGREY
,LIGHTCYAN
,LIGHTRED
,VIOLET
,YELLOW
,WHITE
;
53 static XFontStruct
*XLQF(FILE *err
, Display
*disp
, const char *name
)
55 XFontStruct
*font
=XLoadQueryFont(disp
,name
);
58 fprintf(err
, "Loaded font %s\n",name
);
63 static XFontStruct
*GetFont(FILE *err
, Display
*disp
, char *name
)
65 static const char *fontnames
[] = {
66 "sansb12","8x13bold","8x13",
69 #define MAXNAMES (sizeof(fontnames)/sizeof(fontnames[0]))
77 bFont
=(bool) ((font
=XLQF(err
,disp
,name
))!=NULL
);
81 for (i
=0; (!bFont
&& (i
<MAXNAMES
)); i
++)
82 bFont
=(bool) ((font
=XLQF(err
,disp
,fontnames
[i
]))!=NULL
);
85 fontlist
=XListFonts(disp
,"?",1,&count
);
87 bFont
=(bool) ((font
=XLQF(err
,disp
,fontlist
[0]))!=NULL
);
90 fprintf (err
, "Cannot load any suitable font\n");
94 static GC
GetGC(Display
*disp
, XFontStruct
*font
)
98 values
.font
= font
->fid
;
99 values
.foreground
= WhitePixel(disp
,DefaultScreen(disp
));
101 return XCreateGC(disp
,DefaultRootWindow(disp
),GCForeground
|GCFont
,&values
);
104 void GetNamedColor(t_x11
*x11
,const char *name
,unsigned long *col
)
106 /* If name is found than col set to that colour else col is unchanged */
109 if (XAllocNamedColor(x11
->disp
,x11
->cmap
,name
,&clr
,&exact
))
112 fprintf(x11
->console
,"No colour %s\n",name
);
115 static t_wlist
*GetWList(t_x11
*x11
, Window w
)
120 while (curs
&& (curs
->w
!= w
))
131 static Bool
TestEvent(Display
*disp
,XEvent
*event
,char *arg
)
135 fprintf(stderr
,"TestEvent\n");
137 if ((event
->xany
.window
==tp
->w
) && (event
->type
==ConfigureNotify
)) {
144 static void MainLoop(t_x11
*x11
)
151 for (bReturn
=FALSE
; (!bReturn
); ) {
153 XNextEvent(x11
->disp
,&event
);
155 curs
=GetWList(x11
,w
);
159 switch (event
.type
) {
161 /* Filter out expose events with non-zero count field */
162 if (event
.xexpose
.count
!= 0)
165 case ConfigureNotify
:
166 /* Check if more are coming...
167 if (XCheckTypedWindowEvent(x11->disp,w,ConfigureNotify,&config))
174 bReturn
=(*curs
->cb
)(x11
,&event
,w
,curs
->data
);
180 static void RegisterCallback(t_x11
*x11
,Window w
,Window Parent
,
181 CallBack cb
, void *data
)
203 static void UnRegisterCallback(t_x11
*x11
, Window w
)
210 x11
->wlist
=curs
->next
;
214 while (curs
->next
&& (curs
->next
->w
!= w
))
217 t_wlist
*tmp
=curs
->next
;
219 curs
->next
=curs
->next
->next
;
226 static void SetInputMask(t_x11
*x11
, Window w
, unsigned long mask
)
230 curs
=GetWList(x11
,w
);
233 XSelectInput(x11
->disp
,w
,(long)mask
);
236 fprintf(x11
->console
,"No such window (%d)\n",(int)w
);
239 static unsigned long GetInputMask(t_x11
*x11
, Window w
)
243 curs
=GetWList(x11
,w
);
250 static void CleanUp(t_x11
*x11
)
256 x11
->wlist
=curs
->next
;
257 XDestroyWindow(x11
->disp
,curs
->w
);
261 XCloseDisplay(x11
->disp
);
264 static void Xrm(int *argc
, char *argv
[])
267 static XrmOptionDescRec opTable[] = {
268 {"-background", "*background",
269 XrmoptionSepArg, (caddr_t) NULL},
270 {"-bd", "*borderColor",
271 XrmoptionSepArg, (caddr_t) NULL},
272 {"-bg", "*background",
273 XrmoptionSepArg, (caddr_t) NULL},
274 {"-borderwidth", "*TopLevelShell.borderwidth",
275 XrmoptionSepArg, (caddr_t) NULL},
276 {"-bordercolor", "*borderColor",
277 XrmoptionSepArg, (caddr_t) NULL},
278 {"-bw", "*TopLevelShell.borderColor",
279 XrmoptionSepArg, (caddr_t) NULL},
280 {"-display", ".display",
281 XrmoptionSepArg, (caddr_t) NULL},
282 {"-fg", "*foreground",
283 XrmoptionSepArg, (caddr_t) NULL},
285 XrmoptionSepArg, (caddr_t) NULL},
287 XrmoptionSepArg, (caddr_t) NULL},
288 {"-foreground", "*foreground",
289 XrmoptionSepArg, (caddr_t) NULL},
290 {"-geometry", ".TopLevelShell.geometry",
291 XrmoptionSepArg, (caddr_t) NULL},
292 {"-iconic", ".TopLevelShell.iconic",
293 XrmoptionNoArg, (caddr_t) "on"},
295 XrmoptionSepArg, (caddr_t) NULL},
296 {"-reverse", "*reverseVideo",
297 XrmoptionNoArg, (caddr_t) "on"},
298 {"-rv", "*reverseVideo",
299 XrmoptionNoArg, (caddr_t) "on"},
300 {"-synchronous", ".synchronous",
301 XrmoptionNoArg, (caddr_t) "on"},
302 {"-title", ".TopLevelShell.title",
303 XrmoptionSepArg, (caddr_t) NULL},
305 XrmoptionSepArg, (caddr_t) NULL},
307 #define TABLELENGTH (sizeof(opTable)/sizeof(opTable[0]))
311 static void Flush(t_x11
*x11
)
313 fflush(x11
->console
);
316 t_x11
*GetX11(int *argc
, char *argv
[])
318 static const char *v_name
[] = {
319 "DirectColor","TrueColor", "PseudoColor",
320 "StaticColor","GrayScale", "StaticGray"
322 static int v_class
[] = {
323 DirectColor
,TrueColor
, PseudoColor
,
324 StaticColor
,GrayScale
, StaticGray
326 #define NCLASS (sizeof(v_class)/sizeof(v_class[0]))
334 char *title
,*FG
=NULL
,*BG
=NULL
;
338 title
=strdup(argv
[0]);
340 /* First check environment */
341 fontname
=getenv("GMXFONT");
342 display
=getenv("DISPLAY");
346 for(i
=1; (i
< *argc
); i
++) {
347 if (argv
[i
][0]=='-') {
348 if (strlen(argv
[i
]) > 1) {
369 title
=strdup(argv
[++i
]);
375 ARGV
[ARGC
++]=argv
[i
];
381 ARGV
[ARGC
++]=argv
[i
];
383 for (i
=1; (i
<ARGC
); i
++)
389 x11
->dispname
=display
;
393 if ((x11
->console
=fopen("/dev/null","w"))== NULL
)
396 if ((x11
->disp
=XOpenDisplay(display
))==NULL
) {
398 fprintf(x11
->console
,"Display %s invalid\n",display
);
402 if ((x11
->font
=GetFont(x11
->console
,x11
->disp
,fontname
))==NULL
)
404 if ((x11
->gc
=GetGC(x11
->disp
,x11
->font
))==NULL
)
407 x11
->root
=DefaultRootWindow(x11
->disp
);
408 x11
->screen
=DefaultScreen(x11
->disp
);
409 x11
->depth
=DefaultDepth(x11
->disp
,x11
->screen
);
410 x11
->cmap
=DefaultColormap(x11
->disp
,x11
->screen
);
412 /* These colours will be mapped to black on a monochrome screen */
413 x11
->fg
=BLACK
=BLUE
=GREEN
=CYAN
=RED
=BROWN
=GREY
=DARKGREY
=
414 BlackPixel(x11
->disp
,x11
->screen
);
416 /* These colours will be mapped to white on a monochrome screen */
418 LIGHTBLUE
=LIGHTGREY
=LIGHTGREEN
=LIGHTCYAN
=LIGHTRED
=VIOLET
=YELLOW
=WHITE
=
419 WhitePixel(x11
->disp
,x11
->screen
);
421 if (x11
->depth
> 1) {
422 /* Not B & W, Look what kind of screen we've got... */
423 for (i
=0; (i
< NCLASS
); i
++)
424 if (!XMatchVisualInfo(x11
->disp
,x11
->screen
,x11
->depth
,
427 if ((i
==4) || (i
==5))
428 fprintf(x11
->console
,"Greyscale screen, using B & W only\n");
430 /* We have real color! */
431 fprintf(x11
->console
,"%s screen with depth %d.\n",
432 (i
==NCLASS
)?"Unknown":v_name
[i
],x11
->depth
);
433 GetNamedColor(x11
,"midnight blue",&BLUE
);
434 GetNamedColor(x11
,"DarkGreen",&GREEN
);
435 GetNamedColor(x11
,"SeaGreen",&CYAN
);
436 GetNamedColor(x11
,"red4",&RED
);
437 GetNamedColor(x11
,"Gray",&GREY
);
438 GetNamedColor(x11
,"Gray",&DARKGREY
);
439 GetNamedColor(x11
,"LightGray",&LIGHTGREY
);
440 GetNamedColor(x11
,"green",&LIGHTGREEN
);
441 GetNamedColor(x11
,"cyan",&LIGHTCYAN
);
442 GetNamedColor(x11
,"tomato1",&LIGHTRED
);
443 GetNamedColor(x11
,"violet",&VIOLET
);
444 GetNamedColor(x11
,"yellow",&YELLOW
);
445 GetNamedColor(x11
,"brown",&BROWN
);
446 GetNamedColor(x11
,"CornFlowerBlue",&LIGHTBLUE
);
450 fprintf(x11
->console
,"Monochrome screen.\n");
452 /* We should use Xrm here... */
454 GetNamedColor(x11
,FG
,&(x11
->fg
));
458 GetNamedColor(x11
,BG
,&(x11
->bg
));
461 x11
->title
=strdup(title
);
464 x11
->GetNamedColor
=&GetNamedColor
;
465 x11
->MainLoop
=&MainLoop
;
466 x11
->RegisterCallback
=&RegisterCallback
;
467 x11
->UnRegisterCallback
=&UnRegisterCallback
;
468 x11
->SetInputMask
=&SetInputMask
;
469 x11
->GetInputMask
=&GetInputMask
;
470 x11
->CleanUp
=&CleanUp
;