Geom.c revision 1ab64890
1/* $Xorg: Geom.c,v 1.4 2001/02/09 02:03:33 xorgcvs Exp $ */
2
3/*
4
5Copyright 1985, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included
14in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the name of The Open Group shall
25not be used in advertising or otherwise to promote the sale, use or
26other dealings in this Software without prior written authorization
27from The Open Group.
28
29*/
30/* $XFree86$ */
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35#include "Xlibint.h"
36#include "Xutil.h"
37
38/*
39 * This routine given a user supplied positional argument and a default
40 * argument (fully qualified) will return the position the window should take
41 * returns 0 if there was some problem, else the position bitmask.
42 */
43
44int
45XGeometry (
46     Display *dpy,			/* user's display connection */
47     int screen,			/* screen on which to do computation */
48     _Xconst char *pos,			/* user provided geometry spec */
49     _Xconst char *def,			/* default geometry spec for window */
50     unsigned int bwidth,		/* border width */
51     unsigned int fwidth,		/* size of position units */
52     unsigned int fheight,
53     int xadd,				/* any additional interior space */
54     int yadd,
55     register int *x,			/* always set on successful RETURN */
56     register int *y,			/* always set on successful RETURN */
57     register int *width,		/* always set on successful RETURN */
58     register int *height)		/* always set on successful RETURN */
59{
60	int px, py;			/* returned values from parse */
61	unsigned int pwidth, pheight;	/* returned values from parse */
62	int dx, dy;			/* default values from parse */
63	unsigned int dwidth, dheight;	/* default values from parse */
64	int pmask, dmask;		/* values back from parse */
65
66	pmask = XParseGeometry(pos, &px, &py, &pwidth, &pheight);
67	dmask = XParseGeometry(def, &dx, &dy, &dwidth, &dheight);
68
69	/* set default values */
70	*x = (dmask & XNegative) ?
71	    DisplayWidth(dpy, screen)  + dx - dwidth * fwidth -
72	        2 * bwidth - xadd : dx;
73	*y = (dmask & YNegative) ?
74	    DisplayHeight(dpy, screen) + dy - dheight * fheight -
75	        2 * bwidth - yadd : dy;
76	*width  = dwidth;
77	*height = dheight;
78
79	if (pmask & WidthValue)  *width  = pwidth;
80	if (pmask & HeightValue) *height = pheight;
81
82	if (pmask & XValue)
83	    *x = (pmask & XNegative) ?
84	      DisplayWidth(dpy, screen) + px - *width * fwidth -
85		  2 * bwidth - xadd : px;
86	if (pmask & YValue)
87	    *y = (pmask & YNegative) ?
88	      DisplayHeight(dpy, screen) + py - *height * fheight -
89		  2 * bwidth - yadd : py;
90	return (pmask);
91}
92