Sort includes outside src/gromacs
[alexxy/gromacs.git] / src / programs / view / x11.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 #ifndef _x11_h
39 #define _x11_h
40
41 #include <stdio.h>
42
43 #include "gromacs/legacyheaders/typedefs.h"
44
45 #include "Xstuff.h"
46
47 /* These colours will be mapped to black on a monochrome screen */
48 extern unsigned long BLACK, BLUE, GREEN, CYAN, RED, BROWN, GREY, DARKGREY;
49
50 /* These colours will be mapped to white on a monochrome screen */
51 extern unsigned long LIGHTBLUE, LIGHTGREY, LIGHTGREEN, LIGHTCYAN,
52                      LIGHTRED, VIOLET, YELLOW, WHITE;
53
54 #define CBARGS (struct t_x11 *x11, XEvent *event, Window w, void *data)
55 /* Callback function. Return false to continue, true to exit */
56
57 typedef struct t_x11 {
58     Display            *disp;
59     XFontStruct        *font;
60     GC                  gc;
61     Window              root;
62     char               *dispname;
63     FILE               *console;
64     int                 screen, depth;
65     Colormap            cmap;
66     unsigned long       fg, bg;
67     char               *title;
68     struct t_wlist     *wlist;
69     void        (*GetNamedColor)(struct t_x11 *x11, const char *name, unsigned long *col);
70     void        (*MainLoop)(struct t_x11 *x11);
71     void        (*RegisterCallback)(struct t_x11 *x11, Window w, Window Parent,
72                                     bool cb CBARGS, void *data);
73     void        (*UnRegisterCallback)(struct t_x11 *x11, Window w);
74     void        (*SetInputMask)(struct t_x11 *x11, Window w, unsigned long mask);
75     unsigned long       (*GetInputMask)(struct t_x11 *x11, Window w);
76     void        (*CleanUp)(struct t_x11 *x11);
77     void        (*Flush)(struct t_x11 *x11);
78 } t_x11;
79
80 typedef bool CallBack CBARGS;
81
82 typedef struct t_wlist {
83     Window                 w;      /* The window itself                 */
84     Window                 Parent; /* It's parent window                        */
85     CallBack              *cb;     /* Call back function                        */
86     unsigned long          mask;   /* Input mask                                */
87     void                  *data;   /* User data struct                  */
88     struct t_wlist        *next;
89 } t_wlist;
90
91 t_x11 *GetX11(int *argc, char *argv[]);
92 /* x11 is a struct / function-set that manages a number of windows.
93  * more or (presumably) less like Xt does, but since x11 uses only
94  * Xlib calls, it is *PORTABLE* software.
95  *
96  * The x11 struct is in principle Object Oriented, in that the functions
97  * are member of the struct. This makes the software a little more
98  * managable. Because of portability I decided not to use C++, even
99  * though it would be much nicer to work with in the X-Bizz.
100  *
101  * Here's the description of how to use the x11 struct
102  * 1. Call the GetX11 routine, with the argc and argv from your main.
103  *    This will sort out the X-arguments on the command line and remove
104  *    them from the command line. When the routine returns, only the
105  *    application specific arguments should be left. Thi opens the
106  *    display, selects a font, creates a Graphics Context and also sets
107  *    the colours listed above in the global variables.
108  * 2. Call x11->RegisterCallback for each window you want to have
109  *    managed by x11. You have to create a Callback routine for your
110  *    application that handles *ONE* event at a time. The idea is that
111  *    each window has it's own Callback which is not polluted by code
112  *    for other windows, but it is of course entirely possible to have
113  *    one Callback routine for a number of windows (eg. when you need
114  *    to know something about your children).
115  * 3. Call x11->SetInputMask. This comes in place of the normal
116  *    XSelectInput, because it enables x11 to manually decide which
117  *    events are passed to the windows. With the x11->GetInputMask,
118  *    x11->SetInputMask combination, a child window can temporarily
119  *    disable mouse and keyboard input for it's parent, while allowing
120  *    redraw events to pass through for instance. Hereby a simple way
121  *    for creating application modal child windows is implemented.
122  * 4. Call x11->MainLoop. This will call every callback function as
123  *    appropriate. When a window receives a message, that makes it decide
124  *    to terminate it should call x11->UnRegisterCallback, in order to
125  *    tell the x11 Manager that it does not want to receive any more
126  *    events. It is up to the window to destroy itself. The MainLoop
127  *    routine exits when there are no more windows to manage, i.e. when
128  *    all routines have called UnRegisterCallback, OR when one Callback
129  *    routine returns non-zero (true).
130  * 5. Call x11->CleanUp. This closes the display, and frees all
131  *    memory allocated by x11 before.
132  */
133
134 extern void GetNamedColor(t_x11 *x11, const char *name, unsigned long *col);
135
136 #endif  /* _x11_h */