Annotation of researchv9/X11/src/X.V11R1/lib/X/XGetHints.c, revision 1.1.1.1

1.1       root        1: #include "copyright.h"
                      2: 
                      3: /* $Header: XGetHints.c,v 11.16 87/09/09 15:42:48 swick Exp $ */
                      4: 
                      5: /***********************************************************
                      6: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
                      7: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
                      8: 
                      9:                         All Rights Reserved
                     10: 
                     11: Permission to use, copy, modify, and distribute this software and its 
                     12: documentation for any purpose and without fee is hereby granted, 
                     13: provided that the above copyright notice appear in all copies and that
                     14: both that copyright notice and this permission notice appear in 
                     15: supporting documentation, and that the names of Digital or MIT not be
                     16: used in advertising or publicity pertaining to distribution of the
                     17: software without specific, written prior permission.  
                     18: 
                     19: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     20: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     21: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     22: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     23: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     24: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     25: SOFTWARE.
                     26: 
                     27: ******************************************************************/
                     28: 
                     29: #include <stdio.h>
                     30: #include "Xlibint.h"
                     31: #include "Xutil.h"
                     32: #include "Xatomtype.h"
                     33: #include "Xatom.h"
                     34: 
                     35: Status XGetSizeHints (dpy, w, hints, property)
                     36:        Display *dpy;
                     37:        Window w;
                     38:        XSizeHints *hints;
                     39:         Atom property;
                     40: {
                     41:        xPropSizeHints *prop = NULL;
                     42:         Atom actual_type;
                     43:         int actual_format;
                     44:         long leftover;
                     45:         unsigned long nitems;
                     46:        if (XGetWindowProperty(dpy, w, property, 0L, (long)NumPropSizeElements,
                     47:            False, XA_WM_SIZE_HINTS, &actual_type, &actual_format,
                     48:             &nitems, &leftover, (unsigned char **)&prop)
                     49:             != Success) return (0);
                     50: 
                     51:         if ((actual_type != XA_WM_SIZE_HINTS) ||
                     52:            (nitems < NumPropSizeElements) || (actual_format != 32)) {
                     53:                if (prop != NULL) Xfree ((char *)prop);
                     54:                 return(0);
                     55:                }
                     56:        hints->flags      = prop->flags;
                     57:        hints->x          = prop->x;
                     58:        hints->y          = prop->y;
                     59:        hints->width      = prop->width;
                     60:        hints->height     = prop->height;
                     61:        hints->min_width  = prop->minWidth;
                     62:        hints->min_height = prop->minHeight;
                     63:        hints->max_width  = prop->maxWidth;
                     64:        hints->max_height = prop->maxHeight;
                     65:        hints->width_inc  = prop->widthInc;
                     66:        hints->height_inc = prop->heightInc;
                     67:        hints->min_aspect.x = prop->minAspectX;
                     68:        hints->min_aspect.y = prop->minAspectY;
                     69:        hints->max_aspect.x = prop->maxAspectX;
                     70:        hints->max_aspect.y = prop->maxAspectY;
                     71:        Xfree((char *)prop);
                     72:        return(1);
                     73: }
                     74: 
                     75: /* 
                     76:  * must return a pointer to the hint, in malloc'd memory, or routine is not
                     77:  * extensible; any use of the caller's memory would cause things to be stepped
                     78:  * on.
                     79:  */
                     80: 
                     81: XWMHints *XGetWMHints (dpy, w)
                     82:        Display *dpy;
                     83:        Window w;
                     84: {
                     85:        xPropWMHints *prop = NULL;
                     86:        register XWMHints *hints;
                     87:         Atom actual_type;
                     88:         int actual_format;
                     89:         long leftover;
                     90:         unsigned long nitems;
                     91:        if (XGetWindowProperty(dpy, w, XA_WM_HINTS, 
                     92:            0L, (long)NumPropWMHintsElements,
                     93:            False, XA_WM_HINTS, &actual_type, &actual_format,
                     94:             &nitems, &leftover, (unsigned char **)&prop)
                     95:             != Success) return (NULL);
                     96: 
                     97:        /* If the property is undefined on the window, return null pointer. */
                     98: 
                     99:         if ((actual_type != XA_WM_HINTS) ||
                    100:            (nitems < NumPropWMHintsElements) || (actual_format != 32)) {
                    101:                if (prop != NULL) Xfree ((char *)prop);
                    102:                 return(NULL);
                    103:                }
                    104:        /* static copies not allowed in library, due to reentrancy constraint*/
                    105:        hints = (XWMHints *) Xcalloc (1, (unsigned) sizeof(XWMHints));
                    106:        hints->flags = prop->flags;
                    107:        hints->input = prop->input;
                    108:        hints->initial_state = prop->initialState;
                    109:        hints->icon_pixmap = prop->iconPixmap;
                    110:        hints->icon_window = prop->iconWindow;
                    111:        hints->icon_x = prop->iconX;
                    112:        hints->icon_y = prop->iconY;
                    113:        hints->icon_mask = prop->iconMask;
                    114:        hints->window_group = prop->windowGroup;
                    115:        Xfree ((char *)prop);
                    116:        return(hints);
                    117: }
                    118: 
                    119: Status
                    120: XGetZoomHints (dpy, w, zhints)
                    121:        Display *dpy;
                    122:        Window w;
                    123:        XSizeHints *zhints;
                    124: {
                    125:        return (XGetSizeHints(dpy, w, zhints, XA_WM_ZOOM_HINTS));
                    126: }
                    127: 
                    128: Status
                    129: XGetNormalHints (dpy, w, hints)
                    130:        Display *dpy;
                    131:        Window w;
                    132:        XSizeHints *hints;
                    133: {
                    134:        return (XGetSizeHints(dpy, w, hints, XA_WM_NORMAL_HINTS));
                    135: }
                    136: 
                    137:                                
                    138: /*
                    139:  * XGetIconSizes reads the property 
                    140:  *     ICONSIZE_ATOM   type: ICONSIZE_ATOM format: 32
                    141:  */
                    142: 
                    143: Status XGetIconSizes (dpy, w, size_list, count)
                    144:        Display *dpy;
                    145:        Window w;       /* typically, root */
                    146:        XIconSize **size_list;
                    147:        int *count; /* number of items on the list */
                    148: {
                    149:        xPropIconSize *prop = NULL;
                    150:        register xPropIconSize *pp;
                    151:        register XIconSize *hp, *hints;
                    152:         Atom actual_type;
                    153:         int actual_format;
                    154:         long leftover;
                    155:         unsigned long nitems;
                    156:        register int i;
                    157: 
                    158:        if (XGetWindowProperty(dpy, w, XA_WM_ICON_SIZE, 0L, 60L,
                    159:            False, XA_WM_ICON_SIZE, &actual_type, &actual_format,
                    160:             &nitems, &leftover, (unsigned char **)&prop)
                    161:             != Success) return (0);
                    162: 
                    163:        pp = prop;
                    164: 
                    165:         if ((actual_type != XA_WM_ICON_SIZE) ||
                    166:            (nitems < NumPropIconSizeElements) || (actual_format != 32)) {
                    167:                if (prop != NULL) Xfree ((char *)prop);
                    168:                 return(0);
                    169:                }
                    170:        /* static copies not allowed in library, due to reentrancy constraint*/
                    171:        *count = nitems / NumPropIconSizeElements;
                    172:        if (*count < 1) {
                    173:          if (prop != NULL) Xfree((char *)prop);
                    174:          return(0);
                    175:        }
                    176: 
                    177:        hp = hints =  (XIconSize *) 
                    178:          Xcalloc ((unsigned)*count, (unsigned) sizeof(XIconSize));
                    179: 
                    180:        /* march down array putting things into native form */
                    181:        for (i = 0; i < *count; i++) {
                    182:            hp->min_width  = pp->minWidth;
                    183:            hp->min_height = pp->minHeight;
                    184:            hp->max_width  = pp->maxWidth;
                    185:            hp->max_height = pp->maxHeight;
                    186:            hp->width_inc  = pp->widthInc;
                    187:            hp->height_inc = pp->heightInc;
                    188:            hp += 1;
                    189:            pp += 1;
                    190:          }
                    191:        *size_list = hints;
                    192:        if (prop != NULL) Xfree ((char *)prop);
                    193:        return(1);
                    194:        
                    195: }
                    196: 
                    197: Status
                    198: XGetTransientForHint(dpy, w, propWindow)
                    199:        Display *dpy;
                    200:        Window w;
                    201:        Window *propWindow;
                    202: {
                    203:     Atom actual_type;
                    204:     int actual_format;
                    205:     unsigned long nitems;
                    206:     long leftover;
                    207:     Window *data = NULL;
                    208:     if (XGetWindowProperty(dpy, w, XA_WM_TRANSIENT_FOR, 0L, 1L, False,
                    209:         XA_WINDOW, 
                    210:        &actual_type,
                    211:        &actual_format, &nitems, &leftover, (char **) &data) != Success) {
                    212:        *propWindow = None;
                    213:        return (0);
                    214:        }
                    215:     if ( (actual_type == XA_WINDOW) && (actual_format == 32) ) {
                    216:        *propWindow = *data;
                    217:        Xfree( (char *) data);
                    218:        return (1);
                    219:        }
                    220:     *propWindow = None;
                    221:     Xfree( (char *) data);
                    222:     return(0);
                    223: }
                    224: 
                    225: Status
                    226: XGetClassHint(dpy, w, classhint)
                    227:        Display *dpy;
                    228:        Window w;
                    229:        XClassHint *classhint;
                    230: {
                    231:     int len_name, len_class;
                    232:     Atom actual_type;
                    233:     int actual_format;
                    234:     unsigned long nitems;
                    235:     long leftover;
                    236:     unsigned char *data = NULL;
                    237:     if (XGetWindowProperty(dpy, w, XA_WM_CLASS, 0L, (long)BUFSIZ, False,
                    238:         XA_STRING, 
                    239:        &actual_type,
                    240:        &actual_format, &nitems, &leftover, &data) != Success) {
                    241:        classhint = NULL;
                    242:        return (0);
                    243:        }
                    244:        
                    245:    if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
                    246:        len_name = strlen(data);
                    247:        len_class = strlen(data+len_name+1);
                    248:        classhint->res_name = Xmalloc(len_name+1);
                    249:        strcpy(classhint->res_name, data);
                    250:        classhint->res_class = Xmalloc(len_class+1);
                    251:        strcpy(classhint->res_class, data+len_name+1);
                    252:        Xfree( (char *) data);
                    253:        return(Success);
                    254:        }
                    255:     classhint = NULL;
                    256:     Xfree( (char *) data);
                    257:     return(0);
                    258: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.