Пример #1
0
XRRPropertyInfo *
XRRQueryProviderProperty (Display *dpy, RRProvider provider, Atom property)
{
    XExtDisplayInfo		*info = XRRFindDisplay(dpy);
    xRRQueryProviderPropertyReply rep;
    xRRQueryProviderPropertyReq	*req;
    unsigned int		rbytes, nbytes;
    XRRPropertyInfo		*prop_info;

    RRCheckExtension (dpy, info, NULL);

    LockDisplay (dpy);
    GetReq (RRQueryProviderProperty, req);
    req->reqType = info->codes->major_opcode;
    req->randrReqType = X_RRQueryProviderProperty;
    req->provider = provider;
    req->property = property;

    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
	UnlockDisplay (dpy);
	SyncHandle ();
	return NULL;
    }

    if (rep.length < ((INT_MAX / sizeof(long)) - sizeof (XRRPropertyInfo))) {
        rbytes = sizeof (XRRPropertyInfo) + (rep.length * sizeof (long));
        nbytes = rep.length << 2;

        prop_info = Xmalloc (rbytes);
    } else
        prop_info = NULL;

    if (prop_info == NULL) {
	_XEatDataWords (dpy, rep.length);
	UnlockDisplay (dpy);
	SyncHandle ();
	return NULL;
    }

    prop_info->pending = rep.pending;
    prop_info->range = rep.range;
    prop_info->immutable = rep.immutable;
    prop_info->num_values = rep.length;
    if (rep.length != 0) {
	prop_info->values = (long *) (prop_info + 1);
	_XRead32 (dpy, prop_info->values, nbytes);
    } else {
	prop_info->values = NULL;
    }

    UnlockDisplay (dpy);
    SyncHandle ();
    return prop_info;
}
Пример #2
0
Atom *
XRRListProviderProperties (Display *dpy, RRProvider provider, int *nprop)
{
    XExtDisplayInfo		*info = XRRFindDisplay(dpy);
    xRRListProviderPropertiesReply rep;
    xRRListProviderPropertiesReq	*req;
    int				nbytes, rbytes;
    Atom			*props = NULL;

    RRCheckExtension (dpy, info, NULL);

    LockDisplay (dpy);
    GetReq (RRListProviderProperties, req);
    req->reqType = info->codes->major_opcode;
    req->randrReqType = X_RRListProviderProperties;
    req->provider = provider;

    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
	UnlockDisplay (dpy);
	SyncHandle ();
	*nprop = 0;
	return NULL;
    }

    if (rep.nAtoms) {
	rbytes = rep.nAtoms * sizeof (Atom);
	nbytes = rep.nAtoms << 2;

	props = (Atom *) Xmalloc (rbytes);
	if (props == NULL) {
	    _XEatDataWords (dpy, rep.length);
	    UnlockDisplay (dpy);
	    SyncHandle ();
	    *nprop = 0;
	    return NULL;
	}

	_XRead32 (dpy, (long *) props, nbytes);
    }

    *nprop = rep.nAtoms;
    UnlockDisplay (dpy);
    SyncHandle ();
    return props;
}
Пример #3
0
/*
 * XmbufGetWindowAttributes -
 * 	Gets the multibuffering attributes that apply to all buffers associated
 * 	with the given window.  Returns non-zero on success and zero if an
 * 	error occurs.
 */
Status XmbufGetWindowAttributes (
    Display *dpy,
    Window w,
    XmbufWindowAttributes *attr)
{
    XExtDisplayInfo *info = find_display (dpy);
    register xMbufGetMBufferAttributesReq *req;
    xMbufGetMBufferAttributesReply rep;

    MbufCheckExtension (dpy, info, 0);

    LockDisplay (dpy);
    MbufGetReq (MbufGetMBufferAttributes, req, info);
    req->window = w;
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
	UnlockDisplay (dpy);
	SyncHandle ();
	return 0;
    }
    attr->buffers = (Multibuffer *) NULL;
    if ((attr->nbuffers = rep.length)) {
	int nbytes = rep.length * sizeof(Multibuffer);
	attr->buffers = (Multibuffer *) Xmalloc((unsigned) nbytes);
	nbytes = rep.length << 2;
	if (! attr->buffers) {
	    _XEatDataWords(dpy, rep.length);
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return (0);
	}
	_XRead32 (dpy, (long *) attr->buffers, nbytes);
    }
    attr->displayed_index = rep.displayedBuffer;
    attr->update_action = rep.updateAction;
    attr->update_hint = rep.updateHint;
    attr->window_mode = rep.windowMode;

    UnlockDisplay (dpy);
    SyncHandle();
    return 1;
}
Пример #4
0
Colormap *XListInstalledColormaps(
    register Display *dpy,
    Window win,
    int *n)  /* RETURN */
{
    long nbytes;
    Colormap *cmaps;
    xListInstalledColormapsReply rep;
    register xResourceReq *req;

    LockDisplay(dpy);
    GetResReq(ListInstalledColormaps, win, req);

    if(_XReply(dpy, (xReply *) &rep, 0, xFalse) == 0) {
	    UnlockDisplay(dpy);
	    SyncHandle();
	    *n = 0;
	    return((Colormap *) NULL);
	}

    if (rep.nColormaps) {
	nbytes = rep.nColormaps * sizeof(Colormap);
	cmaps = (Colormap *) Xmalloc((unsigned) nbytes);
	nbytes = rep.nColormaps << 2;
	if (! cmaps) {
	    _XEatData(dpy, (unsigned long) nbytes);
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return((Colormap *) NULL);
	}
	_XRead32 (dpy, (long *) cmaps, nbytes);
    }
    else cmaps = (Colormap *) NULL;

    *n = rep.nColormaps;
    UnlockDisplay(dpy);
    SyncHandle();
    return(cmaps);
}
Пример #5
0
Atom *XListProperties(
    register Display *dpy,
    Window window,
    int *n_props)  /* RETURN */
{
    unsigned long nbytes;
    xListPropertiesReply rep;
    Atom *properties;
    register xResourceReq *req;

    LockDisplay(dpy);
    GetResReq(ListProperties, window, req);
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	*n_props = 0;
	UnlockDisplay(dpy);
        SyncHandle();
	return ((Atom *) NULL);
    }

    if (rep.nProperties) {
	nbytes = rep.nProperties * sizeof(Atom);
	properties = Xmalloc (nbytes);
	if (! properties) {
	    _XEatDataWords(dpy, rep.length);
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return (Atom *) NULL;
	}
	nbytes = rep.nProperties << 2;
	_XRead32 (dpy, (long *) properties, nbytes);
    }
    else properties = (Atom *) NULL;

    *n_props = rep.nProperties;
    UnlockDisplay(dpy);
    SyncHandle();
    return (properties);
}
Пример #6
0
Файл: Xdbe.c Проект: aosm/X11
/*
 * XdbeGetVisualInfo -
 *	This function returns information about which visuals support
 *	double buffering.  The argument num_screens specifies how many
 *	elements there are in the screen_specifiers list.  Each drawable
 *	in screen_specifiers designates a screen for which the supported
 *	visuals are being requested.  If num_screens is zero, information
 *	for all screens is requested.  In this case, upon return from this
 *	function, num_screens will be set to the number of screens that were
 *	found.  If an error occurs, this function returns NULL, else it returns
 *	a pointer to a list of XdbeScreenVisualInfo structures of length
 *	num_screens.  The nth element in the returned list corresponds to the
 *	nth drawable in the screen_specifiers list, unless num_screens was
 *	passed in with the value zero, in which case the nth element in the
 *	returned list corresponds to the nth screen of the server, starting
 *	with screen zero.
 */
XdbeScreenVisualInfo *XdbeGetVisualInfo (
    Display        *dpy,
    Drawable       *screen_specifiers,
    int            *num_screens)  /* SEND and RETURN */
{
    XExtDisplayInfo *info = find_display(dpy);
    register xDbeGetVisualInfoReq *req;
    xDbeGetVisualInfoReply rep;
    XdbeScreenVisualInfo *scrVisInfo;
    int i;

    DbeCheckExtension (dpy, info, (XdbeScreenVisualInfo *)NULL);

    LockDisplay (dpy);

    DbeGetReq(DbeGetVisualInfo, req, info);
    req->length = 2 + *num_screens;
    req->n      = *num_screens;
    Data32 (dpy, screen_specifiers, (*num_screens * sizeof (CARD32)));

    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay (dpy);
        SyncHandle ();
        return NULL;
    }

    /* return the number of screens actually found if we
     * requested information about all screens (*num_screens == 0)
     */
    if (*num_screens == 0)
       *num_screens = rep.m;

    /* allocate list of visual information to be returned */
    if (!(scrVisInfo =
        (XdbeScreenVisualInfo *)Xmalloc(
        (unsigned)(*num_screens * sizeof(XdbeScreenVisualInfo))))) {
        UnlockDisplay (dpy);
        SyncHandle ();
        return NULL;
    }

    for (i = 0; i < *num_screens; i++)
    {
        int nbytes;
        int j;
        long c;

        _XRead32 (dpy, &c, sizeof(CARD32));
        scrVisInfo[i].count = c;

        nbytes = scrVisInfo[i].count * sizeof(XdbeVisualInfo);

        /* if we can not allocate the list of visual/depth info
         * then free the lists that we already allocate as well
         * as the visual info list itself
         */
        if (!(scrVisInfo[i].visinfo = (XdbeVisualInfo *)Xmalloc(
            (unsigned)nbytes))) {
            for (j = 0; j < i; j++) {
                Xfree ((char *)scrVisInfo[j].visinfo);
            }
            Xfree ((char *)scrVisInfo);
            UnlockDisplay (dpy);
            SyncHandle ();
            return NULL;
        }
    
        /* Read the visual info item into the wire structure.  Then copy each
         * element into the library structure.  The element sizes and/or
         * padding may be different in the two structures.
         */
        for (j = 0; j < scrVisInfo[i].count; j++) {
            xDbeVisInfo xvi;

            _XRead (dpy, (char *)&xvi, sizeof(xDbeVisInfo));
            scrVisInfo[i].visinfo[j].visual    = xvi.visualID;
            scrVisInfo[i].visinfo[j].depth     = xvi.depth;
            scrVisInfo[i].visinfo[j].perflevel = xvi.perfLevel;
        }

    }

    UnlockDisplay (dpy);
    SyncHandle ();
    return scrVisInfo;

} /* XdbeGetVisualInfo() */
Пример #7
0
XPPrinterList
XpGetPrinterList (
    Display     *dpy,
    char        *printer_name,
    int         *list_count             /* return value */
)
{
    xPrintGetPrinterListReq     *req;
    xPrintGetPrinterListReply   rep;

    int		printer_name_len, locale_len;
    char        *locale;

    /* For decoding the variable portion of Reply */
    long	dataLenVR;
    CARD8	*dataVR;	/* aka STRING8 */

    XPPrinterList ptr_list;

    XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);

    /* For converting root winID to corresponding ScreenPtr */
    int    i;


    if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
        return ( (XPPrinterList) NULL ); /* No such extension */

    /*
     * Fetch locale information. Note: XpGetLocaleNetString has
     * a thread-safe mutex on _Xglobal_lock.
     */
    locale = XpGetLocaleNetString();

    LockDisplay (dpy);

    GetReq(PrintGetPrinterList,req);
    req->reqType = info->codes->major_opcode;
    req->printReqType = X_PrintGetPrinterList;

    /*
     * Compute lengths of variable portions.
     */
    if ( printer_name == (char *) NULL )
	req->printerNameLen = 0;
    else if ( *printer_name == (char) NULL )
	req->printerNameLen = 0;
    else {
	printer_name_len    = strlen( printer_name );
	req->length        += _XpPadOut(printer_name_len) >> 2;
	req->printerNameLen = (unsigned long) printer_name_len;
    }

    if ( locale == (char *) NULL )
	req->localeLen = 0;
    else if ( *locale == (char) NULL )
	req->localeLen = 0;
    else {
	locale_len     = strlen( locale );
	req->length   += _XpPadOut(locale_len) >> 2;
	req->localeLen = (unsigned long) locale_len;
    }

    /*
     * Attach variable data.
     */
    if (req->printerNameLen)
	Data( dpy, (char *) printer_name, (long) req->printerNameLen );

    if (req->localeLen)
	Data( dpy, (char *) locale, (long) req->localeLen );

    if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return ( (XPPrinterList) NULL ); /* error */
    }

    XFree(locale);

    *list_count = rep.listCount;

    if (*list_count) {
	ptr_list = (XPPrinterList)
		Xmalloc( (unsigned) (sizeof(XPPrinterRec) * (*list_count + 1)));

	if (!ptr_list) {
            UnlockDisplay(dpy);
            SyncHandle();
            return ( (XPPrinterList) NULL ); /* malloc error */
	}

	/*
	 * NULL last entry so XpFreePrinterList can work without a list_count
	 */
	ptr_list[*list_count].name = (char *) NULL;
	ptr_list[*list_count].desc = (char *) NULL;

	for ( i = 0; i < *list_count; i++ ) {
	    /*
	     * Pull printer length and then name.
	     */
	    _XRead32 (dpy, &dataLenVR, (long) sizeof(CARD32) );

	    if (dataLenVR) {
		dataVR = (CARD8 *) Xmalloc( (unsigned) dataLenVR + 1 );

		if (!dataVR) {
		    UnlockDisplay(dpy);
		    SyncHandle();
		    return ( (XPPrinterList) NULL ); /* malloc error */
		}

		_XReadPad (dpy, (char *) dataVR, (long) dataLenVR);
		dataVR[dataLenVR] = 0;
		ptr_list[i].name = (char *) dataVR;
	    }
	    else {
		ptr_list[i].name = (char *) NULL;
	    }

	    /*
	     * Pull localized description length and then description.
	     */
	    _XRead32 (dpy, &dataLenVR, (long) sizeof(CARD32) );

	    if (dataLenVR) {
		dataVR = (CARD8 *) Xmalloc( (unsigned) dataLenVR + 1 );

		if (!dataVR) {
		    UnlockDisplay(dpy);
		    SyncHandle();
		    return ( (XPPrinterList) NULL ); /* malloc error */
		}

		_XReadPad (dpy, (char *) dataVR, (long) dataLenVR);
		dataVR[dataLenVR] = 0;
		ptr_list[i].desc = (char *) dataVR;
	    }
	    else {
		ptr_list[i].desc = (char *) NULL;
	    }
	}
    }
    else {
	ptr_list = (XPPrinterList) NULL;
    }

    UnlockDisplay(dpy);
    SyncHandle();

    return ( ptr_list );
}
Пример #8
0
XFixesCursorImage *
XFixesGetCursorImage (Display *dpy)
{
    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
    xXFixesGetCursorImageAndNameReq	*req;
    xXFixesGetCursorImageAndNameReply	rep;
    int					npixels;
    int					nbytes_name;
    int					nbytes, nread, rlength;
    XFixesCursorImage			*image;
    char				*name;

    XFixesCheckExtension (dpy, info, NULL);
    LockDisplay (dpy);
    GetReq (XFixesGetCursorImageAndName, req);
    req->reqType = info->codes->major_opcode;
    if (info->major_version >= 2)
	req->xfixesReqType = X_XFixesGetCursorImageAndName;
    else
	req->xfixesReqType = X_XFixesGetCursorImage;
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
    {
	UnlockDisplay (dpy);
	SyncHandle ();
	return NULL;
    }
    if (info->major_version < 2)
    {
	rep.cursorName = None;
	rep.nbytes = 0;
    }
    npixels = rep.width * rep.height;
    nbytes_name = rep.nbytes;
    /* reply data length */
    nbytes = (long) rep.length << 2;
    /* bytes of actual data in the reply */
    nread = (npixels << 2) + nbytes_name;
    /* size of data returned to application */
    rlength = (sizeof (XFixesCursorImage) + 
	       npixels * sizeof (unsigned long) +
	       nbytes_name + 1);

    image = (XFixesCursorImage *) Xmalloc (rlength);
    if (!image)
    {
	_XEatData (dpy, nbytes);
	UnlockDisplay (dpy);
	SyncHandle ();
	return NULL;
    }
    image->x = rep.x;
    image->y = rep.y;
    image->width = rep.width;
    image->height = rep.height;
    image->xhot = rep.xhot;
    image->yhot = rep.yhot;
    image->cursor_serial = rep.cursorSerial;
    image->pixels = (unsigned long *) (image + 1);
    image->atom = rep.cursorName;
    name = (char *) (image->pixels + npixels);
    image->name = name;
    _XRead32 (dpy, (long *) image->pixels, npixels << 2);
    _XRead (dpy, name, nbytes_name);
    name[nbytes_name] = '\0';	/* null-terminate */
    /* skip any padding */
    if(nbytes > nread)
    {
	_XEatData (dpy, (unsigned long) (nbytes - nread));
    }
    UnlockDisplay (dpy);
    SyncHandle ();
    return image;
}