From a2d83b9dc8387ec7e70689db1371cf6500b2f68e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 18 Sep 2008 18:21:03 +0930 Subject: Xi: add "deletable" flag to properties, add DeleteProperty handler. A property can only be deleted if any of the following is true: - if a property is deletable and all handlers return Success. - if a property is non-deleteable and the all handlers return Success AND the delete request does not come from a client (i.e. driver or the server). A client can never delete a non-deletable property. --- Xi/xiproperty.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'Xi') diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c index bd130d1f9..72efb67b1 100644 --- a/Xi/xiproperty.c +++ b/Xi/xiproperty.c @@ -98,7 +98,9 @@ XIRegisterPropertyHandler(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop), int (*GetProperty) (DeviceIntPtr dev, - Atom property)) + Atom property), + int (*DeleteProperty) (DeviceIntPtr dev, + Atom property)) { XIPropertyHandlerPtr new_handler; @@ -109,6 +111,7 @@ XIRegisterPropertyHandler(DeviceIntPtr dev, new_handler->id = XIPropHandlerID++; new_handler->SetProperty = SetProperty; new_handler->GetProperty = GetProperty; + new_handler->DeleteProperty = DeleteProperty; new_handler->next = dev->properties.handlers; dev->properties.handlers = new_handler; @@ -153,6 +156,7 @@ XICreateDeviceProperty (Atom property) prop->value.format = 0; prop->value.size = 0; prop->value.data = NULL; + prop->deletable = TRUE; return prop; } @@ -218,11 +222,29 @@ XIDeleteDeviceProperty (DeviceIntPtr device, Atom property, Bool fromClient) { XIPropertyPtr prop, *prev; devicePropertyNotify event; + int rc = Success; for (prev = &device->properties.properties; (prop = *prev); prev = &(prop->next)) if (prop->propertyName == property) break; + if (fromClient && !prop->deletable) + return BadAccess; + + /* Ask handlers if we may delete the property */ + if (device->properties.handlers) + { + XIPropertyHandlerPtr handler = device->properties.handlers; + while(handler) + { + if (handler->DeleteProperty) + rc = handler->DeleteProperty(device, prop->propertyName); + if (rc != Success) + return (rc); + handler = handler->next; + } + } + if (prop) { *prev = prop->next; @@ -402,6 +424,18 @@ XIGetDeviceProperty (DeviceIntPtr dev, Atom property, XIPropertyValuePtr *value) return Success; } +int +XISetDevicePropertyDeletable(DeviceIntPtr dev, Atom property, Bool deletable) +{ + XIPropertyPtr prop = XIFetchDeviceProperty(dev, property); + + if (!prop) + return BadAtom; + + prop->deletable = deletable; + return Success; +} + int ProcXListDeviceProperties (ClientPtr client) { -- cgit v1.2.3