dix: add dixPropertyCreate()
This function shall be used for creating an entirely new property structure from given data. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
07d67a07e2
commit
a46077cfc9
|
@ -325,11 +325,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
|
|||
{
|
||||
PropertyPtr pProp;
|
||||
PropertyRec savedProp;
|
||||
int sizeInBytes, totalSize, rc;
|
||||
int rc;
|
||||
Mask access_mode;
|
||||
|
||||
sizeInBytes = format >> 3;
|
||||
totalSize = len * sizeInBytes;
|
||||
access_mode = (mode == PropModeReplace) ? DixWriteAccess : DixBlendAccess;
|
||||
|
||||
/* first see if property already exists */
|
||||
|
@ -338,20 +336,11 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
|
|||
if (rc == BadMatch) { /* just add to list */
|
||||
if (!MakeWindowOptional(pWin))
|
||||
return BadAlloc;
|
||||
pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
|
||||
|
||||
pProp = dixPropertyCreate(type, property, format, len, value);
|
||||
if (!pProp)
|
||||
return BadAlloc;
|
||||
if (totalSize) {
|
||||
if (!(pProp->data = calloc(1, totalSize))) {
|
||||
dixPropertyFree(pProp);
|
||||
return BadAlloc;
|
||||
}
|
||||
memcpy(pProp->data, value, totalSize);
|
||||
}
|
||||
pProp->propertyName = property;
|
||||
pProp->type = type;
|
||||
pProp->format = format;
|
||||
pProp->size = len;
|
||||
|
||||
rc = XaceHookPropertyAccess(pClient, pWin, &pProp,
|
||||
DixCreateAccess | DixWriteAccess);
|
||||
if (rc != Success) {
|
||||
|
@ -363,6 +352,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
|
|||
pWin->properties = pProp;
|
||||
}
|
||||
else if (rc == Success) {
|
||||
const int sizeInBytes = format >> 3;
|
||||
const int totalSize = len * sizeInBytes;
|
||||
|
||||
/* To append or prepend to a property the request format and type
|
||||
must match those of the already defined property. The
|
||||
existing format and type are irrelevant when using the mode
|
||||
|
|
|
@ -15,3 +15,29 @@ void dixPropertyFree(PropertyPtr pr)
|
|||
dixFreeObjectWithPrivates(pr, PRIVATE_PROPERTY);
|
||||
}
|
||||
}
|
||||
|
||||
PropertyPtr dixPropertyCreate(Atom type, Atom name, int format, size_t len,
|
||||
const void *value)
|
||||
{
|
||||
const int totalSize = (format >> 3) * len;
|
||||
|
||||
void *data = calloc(1, totalSize);
|
||||
if (!data)
|
||||
return NULL;
|
||||
|
||||
PropertyPtr pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
|
||||
if (!pProp) {
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(data, value, totalSize);
|
||||
|
||||
pProp->data = data;
|
||||
pProp->propertyName = name;
|
||||
pProp->format = format;
|
||||
pProp->size = len;
|
||||
pProp->type = type;
|
||||
|
||||
return pProp;
|
||||
}
|
||||
|
|
|
@ -109,4 +109,18 @@ void DeleteAllWindowProperties(WindowPtr pWin);
|
|||
*/
|
||||
void dixPropertyFree(PropertyPtr pProp);
|
||||
|
||||
/*
|
||||
* Create and fill a new property structure from given data. The `value`
|
||||
* is malloc()ed and copied over.
|
||||
*
|
||||
* @param type AtomID of the property type
|
||||
* @param name AtomID of the property name
|
||||
* @param format the property format (8/16/32 bits)
|
||||
* @param len length in units defined by format
|
||||
* @param value pointer to the (raw) property data)
|
||||
* @return pointer to newly created property structure (NULL on allocation failure)
|
||||
*/
|
||||
PropertyPtr dixPropertyCreate(Atom type, Atom name, int format,
|
||||
size_t len, const void *value);
|
||||
|
||||
#endif /* _XSERVER_PROPERTY_PRIV_H */
|
||||
|
|
Loading…
Reference in New Issue