1/***********************************************************
2Copyright 1988 by Wyse Technology, Inc., San Jose, Ca,
3Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
4
5                        All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the name Digital not be
12used in advertising or publicity pertaining to distribution of the
13software without specific, written prior permission.
14
15DIGITAL AND WYSE DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17EVENT SHALL DIGITAL OR WYSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25/*
26
27Copyright 1987, 1988, 1998  The Open Group
28
29Permission to use, copy, modify, distribute, and sell this software and its
30documentation for any purpose is hereby granted without fee, provided that
31the above copyright notice appear in all copies and that both that
32copyright notice and this permission notice appear in supporting
33documentation.
34
35The above copyright notice and this permission notice shall be included
36in all copies or substantial portions of the Software.
37
38THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
42OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
43ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44OTHER DEALINGS IN THE SOFTWARE.
45
46Except as contained in this notice, the name of The Open Group shall
47not be used in advertising or otherwise to promote the sale, use or
48other dealings in this Software without prior written authorization
49from The Open Group.
50
51*/
52
53
54#ifdef HAVE_CONFIG_H
55#include <config.h>
56#endif
57#include <X11/Xlibint.h>
58#include <X11/Xatom.h>
59#include "Xatomtype.h"
60#include <X11/Xutil.h>
61#include <stdio.h>
62
63Status XGetWMSizeHints (
64    Display *dpy,
65    Window w,
66    XSizeHints *hints,
67    long *supplied,
68    Atom property)
69{
70    xPropSizeHints *prop = NULL;
71    Atom actual_type;
72    int actual_format;
73    unsigned long leftover;
74    unsigned long nitems;
75
76    if (XGetWindowProperty (dpy, w, property, 0L,
77			    (long)NumPropSizeElements,
78			    False, XA_WM_SIZE_HINTS, &actual_type,
79			    &actual_format, &nitems, &leftover,
80			    (unsigned char **)&prop)
81	!= Success)
82      return False;
83
84    if ((actual_type != XA_WM_SIZE_HINTS) ||
85	(nitems < OldNumPropSizeElements) || (actual_format != 32)) {
86	Xfree (prop);
87	return False;
88    }
89
90    hints->flags	  = prop->flags;
91    /* XSizeHints misdeclares these as int instead of long */
92    hints->x = cvtINT32toInt (prop->x);
93    hints->y = cvtINT32toInt (prop->y);
94    hints->width = cvtINT32toInt (prop->width);
95    hints->height = cvtINT32toInt (prop->height);
96    hints->min_width  = cvtINT32toInt (prop->minWidth);
97    hints->min_height = cvtINT32toInt (prop->minHeight);
98    hints->max_width  = cvtINT32toInt (prop->maxWidth);
99    hints->max_height = cvtINT32toInt (prop->maxHeight);
100    hints->width_inc  = cvtINT32toInt (prop->widthInc);
101    hints->height_inc = cvtINT32toInt (prop->heightInc);
102    hints->min_aspect.x = cvtINT32toInt (prop->minAspectX);
103    hints->min_aspect.y = cvtINT32toInt (prop->minAspectY);
104    hints->max_aspect.x = cvtINT32toInt (prop->maxAspectX);
105    hints->max_aspect.y = cvtINT32toInt (prop->maxAspectY);
106
107    *supplied = (USPosition | USSize | PAllHints);
108    if (nitems >= NumPropSizeElements) {
109	hints->base_width= cvtINT32toInt (prop->baseWidth);
110	hints->base_height= cvtINT32toInt (prop->baseHeight);
111	hints->win_gravity= cvtINT32toInt (prop->winGravity);
112	*supplied |= (PBaseSize | PWinGravity);
113    }
114    hints->flags &= (*supplied);	/* get rid of unwanted bits */
115    Xfree(prop);
116    return True;
117}
118
119
120Status XGetWMNormalHints (
121    Display *dpy,
122    Window w,
123    XSizeHints *hints,
124    long *supplied)
125{
126    return (XGetWMSizeHints (dpy, w, hints, supplied, XA_WM_NORMAL_HINTS));
127}
128