window.c
// retrieve a property of any type from a window
retrieve a property of any type from a window
retrieve a property of any type from a window
int window_get_prop(Window w, Atom prop, Atom *type, int *items, void *buffer, int bytes)
{
	Atom _type; if (!type) type = &_type;
	int _items; if (!items) items = &_items;
	int format; unsigned long nitems, nbytes; unsigned char *ret = NULL;
	memset(buffer, 0, bytes);
	if (XGetWindowProperty(display, w, prop, 0, bytes/4, False, AnyPropertyType, type,
		&format, &nitems, &nbytes, &ret) == Success && ret && *type != None && format)
	{
		if (format ==  8) memmove(buffer, ret, MIN(bytes, nitems));
		if (format == 16) memmove(buffer, ret, MIN(bytes, nitems * sizeof(short)));
		if (format == 32) memmove(buffer, ret, MIN(bytes, nitems * sizeof(long)));
		*items = (int)nitems; XFree(ret);
		return 1;
	}
	return 0;
}
int window_get_prop ( Window w , Atom prop , Atom * type , int * items , void * buffer , int bytes ) { Atom _type ; if ( ! type ) type = & _type ; int _items ; if ( ! items ) items = & _items ; int format ; unsigned long nitems , nbytes ; unsigned char * ret = NULL ; memset ( buffer , 0 , bytes ) ; if ( XGetWindowProperty ( display , w , prop , 0 , bytes / 4 , False , AnyPropertyType , type , & format , & nitems , & nbytes , & ret ) == Success && ret && * type != None && format ) { if ( format == 8 ) memmove ( buffer , ret , MIN ( bytes , nitems ) ) ; if ( format == 16 ) memmove ( buffer , ret , MIN ( bytes , nitems * sizeof ( short ) ) ) ; if ( format == 32 ) memmove ( buffer , ret , MIN ( bytes , nitems * sizeof ( long ) ) ) ; * items = ( int ) nitems ; XFree ( ret ) ; return 1 ; } return 0 ; }
retrieve a property of any type from a window
retrieve a property of any type from a window