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