6f328e8fdec689e7489bd202bbafd0b23975bb09
[platform/upstream/libX11.git] / src / GetNrmHint.c
1 /***********************************************************
2 Copyright 1988 by Wyse Technology, Inc., San Jose, Ca,
3 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
4
5                         All Rights Reserved
6
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name Digital not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
14
15 DIGITAL AND WYSE DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 EVENT SHALL DIGITAL OR WYSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 PERFORMANCE OF THIS SOFTWARE.
22
23 ******************************************************************/
24
25 /*
26
27 Copyright 1987, 1988, 1998  The Open Group
28
29 Permission to use, copy, modify, distribute, and sell this software and its
30 documentation for any purpose is hereby granted without fee, provided that
31 the above copyright notice appear in all copies and that both that
32 copyright notice and this permission notice appear in supporting
33 documentation.
34
35 The above copyright notice and this permission notice shall be included
36 in all copies or substantial portions of the Software.
37
38 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
42 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
43 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44 OTHER DEALINGS IN THE SOFTWARE.
45
46 Except as contained in this notice, the name of The Open Group shall
47 not be used in advertising or otherwise to promote the sale, use or
48 other dealings in this Software without prior written authorization
49 from 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
63 Status 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         if (prop != NULL) Xfree ((char *)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((char *)prop);
116     return True;
117 }
118
119
120 Status 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 }