2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2013, The GROMACS development team.
6 * Copyright (c) 2013, 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.
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.
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.
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.
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.
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.
50 int CheckWin(Window win, const char *file, int line)
57 { BadAlloc, "Bad Alloc" },
58 { BadColor, "Bad Color" },
59 { BadCursor, "Bad Cursor"},
60 { BadMatch, "Bad Match" },
61 { BadPixmap, "Bad Pixmap"},
62 { BadValue, "Bad Value" },
63 { BadWindow, "Bad Window"}
65 #define NERR (sizeof(winerr)/sizeof(winerr[0]))
68 for (i = 0; (i < NERR); i++)
70 if (win == winerr[i].n)
72 fprintf(stderr, "%s", winerr[i].s);
81 fprintf(stderr, " in file %s, line %d\n", file, line);
85 void LightBorder(Display *disp, Window win, unsigned long color)
87 XSetWindowAttributes attributes;
89 attributes.border_pixel = color;
90 XChangeWindowAttributes(disp, win, CWBorderPixel, &attributes);
93 void SpecialTextInRect(t_x11 *x11, XFontStruct *font, Drawable win,
94 const char *s, int x, int y, int width, int height,
102 XSetFont(x11->disp, x11->gc, font->fid);
110 fw = XTextWidth(f, s, strlen(s));
131 y0 = y+height-f->descent;
135 y0 = y+(height-fh)/2+f->ascent;
138 XDrawString(x11->disp, win, x11->gc, x0, y0, s, strlen(s));
141 XSetFont(x11->disp, x11->gc, x11->font->fid);
145 void TextInRect(t_x11 *x11, Drawable win,
146 const char *s, int x, int y, int width, int height,
149 SpecialTextInRect(x11, NULL, win, s, x, y, width, height, eX, eY);
152 void TextInWin(t_x11 *x11, t_windata *win,
153 const char *s, eXPos eX, eYPos eY)
155 TextInRect(x11, win->self, s, 0, 0, win->width, win->height, eX, eY);
158 void InitWin(t_windata *win, int x0, int y0, int w, int h, int bw, const char *text)
171 win->text = strdup(text);
178 printf("%s: %d x %d at %d, %d\n", text, w, h, x0, y0);
182 void FreeWin(Display *disp, t_windata *win)
190 XFreeCursor(disp, win->cursor);
194 void ExposeWin(Display *disp, Window win)
199 event.xexpose.send_event = True;
200 event.xexpose.window = win;
203 event.xexpose.width = 1000;
204 event.xexpose.height = 1000;
205 event.xexpose.count = 0;
206 XSendEvent(disp, win, False, ExposureMask, &event);
209 void XDrawRoundRect(Display *disp, Window win, GC gc,
210 int x, int y, int w, int h)
212 #define RAD (OFFS_X/2)
213 #define SetPoint(pn, x0, y0) pn.x = x0; pn.y = y0
215 if ((w < 10) || (h < 10))
217 XDrawRectangle(disp, win, gc, x, y, w, h);
223 SetPoint(p[0], x+RAD, y);
224 SetPoint(p[1], w-2*RAD, 0);
225 SetPoint(p[2], RAD, RAD);
226 SetPoint(p[3], 0, h-2*RAD);
227 SetPoint(p[4], -RAD, RAD);
228 SetPoint(p[5], 2*RAD-w, 0);
229 SetPoint(p[6], -RAD, -RAD);
230 SetPoint(p[7], 0, 2*RAD-h);
231 SetPoint(p[8], RAD, -RAD);
232 XDrawLines(disp, win, gc, p, 9, CoordModePrevious);
236 void RoundRectWin(Display *disp, GC gc, t_windata *win,
237 int offsx, int offsy, unsigned long color)
239 XSetLineAttributes(disp, gc, 1, LineOnOffDash, CapButt, JoinRound);
240 XSetForeground(disp, gc, color);
241 XDrawRoundRect(disp, win->self, gc, offsx, offsy,
242 win->width-2*offsx-1, win->height-2*offsy-1);
243 XSetLineAttributes(disp, gc, 1, LineSolid, CapButt, JoinRound);
246 void RectWin(Display *disp, GC gc, t_windata *win, unsigned long color)
248 int bw = 1; /*2*w.bwidth;*/
250 XSetForeground(disp, gc, color);
251 XDrawRoundRect(disp, win->self, gc, 0, 0, win->width-bw, win->height-bw);
254 typedef struct t_mpos {
259 static t_mpos *mpos = NULL;
261 void PushMouse(Display *disp, Window dest, int x, int y)
270 XQueryPointer(disp, DefaultRootWindow(disp), &root, &child, &root_x, &root_y,
271 &win_x, &win_y, &keybut);
276 XWarpPointer(disp, None, dest, 0, 0, 0, 0, x, y);
278 fprintf(stderr, "Pushmouse %d, %d\n", x, y);
282 void PopMouse(Display *disp)
292 XWarpPointer(disp, None, DefaultRootWindow(disp), 0, 0, 0, 0, old->x, old->y);
294 fprintf(stderr, "Popmouse %d, %d\n", old->x, old->y);
300 bool HelpPressed(XEvent *event)
304 XComposeStatus compose;
307 (void)XLookupString(&(event->xkey), buf, BUFSIZE, &keysym, &compose);
309 return (keysym == XK_F1);
312 bool GrabOK(FILE *out, int err)
318 case GrabNotViewable:
319 fprintf(out, "GrabNotViewable\n"); break;
321 fprintf(out, "AlreadyGrabbed\n"); break;
323 fprintf(out, "GrabFrozen\n"); break;
324 case GrabInvalidTime:
325 fprintf(out, "GrabInvalidTime\n"); break;