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