GetNrmHint.c revision 61b2299d
11ab64890Smrg/* $Xorg: GetNrmHint.c,v 1.4 2001/02/09 02:03:33 xorgcvs Exp $ */
21ab64890Smrg/***********************************************************
31ab64890SmrgCopyright 1988 by Wyse Technology, Inc., San Jose, Ca,
41ab64890SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
51ab64890Smrg
61ab64890Smrg                        All Rights Reserved
71ab64890Smrg
861b2299dSmrgPermission to use, copy, modify, and distribute this software and its
961b2299dSmrgdocumentation for any purpose and without fee is hereby granted,
101ab64890Smrgprovided that the above copyright notice appear in all copies and that
1161b2299dSmrgboth that copyright notice and this permission notice appear in
121ab64890Smrgsupporting documentation, and that the name Digital not be
131ab64890Smrgused in advertising or publicity pertaining to distribution of the
1461b2299dSmrgsoftware without specific, written prior permission.
1561b2299dSmrg
1661b2299dSmrgDIGITAL AND WYSE DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1761b2299dSmrgINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1861b2299dSmrgEVENT SHALL DIGITAL OR WYSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1961b2299dSmrgCONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
2061b2299dSmrgUSE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2161b2299dSmrgOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
221ab64890SmrgPERFORMANCE OF THIS SOFTWARE.
231ab64890Smrg
241ab64890Smrg******************************************************************/
251ab64890Smrg
261ab64890Smrg/*
271ab64890Smrg
281ab64890SmrgCopyright 1987, 1988, 1998  The Open Group
291ab64890Smrg
301ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its
311ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that
321ab64890Smrgthe above copyright notice appear in all copies and that both that
331ab64890Smrgcopyright notice and this permission notice appear in supporting
341ab64890Smrgdocumentation.
351ab64890Smrg
361ab64890SmrgThe above copyright notice and this permission notice shall be included
371ab64890Smrgin all copies or substantial portions of the Software.
381ab64890Smrg
391ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
401ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
411ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
421ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
431ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
441ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
451ab64890SmrgOTHER DEALINGS IN THE SOFTWARE.
461ab64890Smrg
471ab64890SmrgExcept as contained in this notice, the name of The Open Group shall
481ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or
491ab64890Smrgother dealings in this Software without prior written authorization
501ab64890Smrgfrom The Open Group.
511ab64890Smrg
521ab64890Smrg*/
531ab64890Smrg
541ab64890Smrg
551ab64890Smrg#ifdef HAVE_CONFIG_H
561ab64890Smrg#include <config.h>
571ab64890Smrg#endif
581ab64890Smrg#include <X11/Xlibint.h>
591ab64890Smrg#include <X11/Xatom.h>
601ab64890Smrg#include "Xatomtype.h"
611ab64890Smrg#include <X11/Xutil.h>
621ab64890Smrg#include <stdio.h>
631ab64890Smrg
641ab64890SmrgStatus XGetWMSizeHints (
651ab64890Smrg    Display *dpy,
661ab64890Smrg    Window w,
671ab64890Smrg    XSizeHints *hints,
681ab64890Smrg    long *supplied,
691ab64890Smrg    Atom property)
701ab64890Smrg{
711ab64890Smrg    xPropSizeHints *prop = NULL;
721ab64890Smrg    Atom actual_type;
731ab64890Smrg    int actual_format;
741ab64890Smrg    unsigned long leftover;
751ab64890Smrg    unsigned long nitems;
761ab64890Smrg
7761b2299dSmrg    if (XGetWindowProperty (dpy, w, property, 0L,
781ab64890Smrg			    (long)NumPropSizeElements,
791ab64890Smrg			    False, XA_WM_SIZE_HINTS, &actual_type,
8061b2299dSmrg			    &actual_format, &nitems, &leftover,
811ab64890Smrg			    (unsigned char **)&prop)
821ab64890Smrg	!= Success)
831ab64890Smrg      return False;
841ab64890Smrg
851ab64890Smrg    if ((actual_type != XA_WM_SIZE_HINTS) ||
861ab64890Smrg	(nitems < OldNumPropSizeElements) || (actual_format != 32)) {
871ab64890Smrg	if (prop != NULL) Xfree ((char *)prop);
881ab64890Smrg	return False;
891ab64890Smrg    }
901ab64890Smrg
911ab64890Smrg    hints->flags	  = prop->flags;
921ab64890Smrg    /* XSizeHints misdeclares these as int instead of long */
931ab64890Smrg    hints->x = cvtINT32toInt (prop->x);
941ab64890Smrg    hints->y = cvtINT32toInt (prop->y);
951ab64890Smrg    hints->width = cvtINT32toInt (prop->width);
961ab64890Smrg    hints->height = cvtINT32toInt (prop->height);
971ab64890Smrg    hints->min_width  = cvtINT32toInt (prop->minWidth);
981ab64890Smrg    hints->min_height = cvtINT32toInt (prop->minHeight);
991ab64890Smrg    hints->max_width  = cvtINT32toInt (prop->maxWidth);
1001ab64890Smrg    hints->max_height = cvtINT32toInt (prop->maxHeight);
1011ab64890Smrg    hints->width_inc  = cvtINT32toInt (prop->widthInc);
1021ab64890Smrg    hints->height_inc = cvtINT32toInt (prop->heightInc);
1031ab64890Smrg    hints->min_aspect.x = cvtINT32toInt (prop->minAspectX);
1041ab64890Smrg    hints->min_aspect.y = cvtINT32toInt (prop->minAspectY);
1051ab64890Smrg    hints->max_aspect.x = cvtINT32toInt (prop->maxAspectX);
1061ab64890Smrg    hints->max_aspect.y = cvtINT32toInt (prop->maxAspectY);
1071ab64890Smrg
1081ab64890Smrg    *supplied = (USPosition | USSize | PAllHints);
1091ab64890Smrg    if (nitems >= NumPropSizeElements) {
1101ab64890Smrg	hints->base_width= cvtINT32toInt (prop->baseWidth);
1111ab64890Smrg	hints->base_height= cvtINT32toInt (prop->baseHeight);
1121ab64890Smrg	hints->win_gravity= cvtINT32toInt (prop->winGravity);
1131ab64890Smrg	*supplied |= (PBaseSize | PWinGravity);
1141ab64890Smrg    }
1151ab64890Smrg    hints->flags &= (*supplied);	/* get rid of unwanted bits */
1161ab64890Smrg    Xfree((char *)prop);
1171ab64890Smrg    return True;
1181ab64890Smrg}
1191ab64890Smrg
1201ab64890Smrg
1211ab64890SmrgStatus XGetWMNormalHints (
1221ab64890Smrg    Display *dpy,
1231ab64890Smrg    Window w,
1241ab64890Smrg    XSizeHints *hints,
1251ab64890Smrg    long *supplied)
1261ab64890Smrg{
1271ab64890Smrg    return (XGetWMSizeHints (dpy, w, hints, supplied, XA_WM_NORMAL_HINTS));
1281ab64890Smrg}
129