[PATCH 0/3] X Input 1.5 device properties (final patches)

Peter Hutterer peter.hutterer at who-t.net
Tue Sep 23 17:59:17 PDT 2008


On Tue, Sep 23, 2008 at 09:02:34PM +0200, Simon Thum wrote:
> one more thing: A Handler already consists of getter and setter, so  
> there's an incentive to abstracting 'hey thats my property' on the  
> handler side anyway. So why load deletion onto the setter as a special  
> case of modification? I think it would be cleaner to have an own  
> 'sub-handler' for deletion.
>
> Or, since 99% of in-server code will just protect its props (at least,  
> no other use case comes to my mind), we could make it a property flag  
> again. I understand you want to get rid of it, but I think this one  
> could save some code on the handlers side. Mostly code which isn't  
> exactly DRY.

Right, I can see your point. How about the patch below (untested)? It's on top
of the other patches and adds a DeleteProperty handler, and a deletable flag.

If deletable is FALSE, the prop can only be deleted by the server/a driver,
and even then only if all handlers agree.

>From aa3b6cf0bd533bc264f3acddf14222a6e04f9d44 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer at redhat.com>
Date: Wed, 24 Sep 2008 10:18:14 +0930
Subject: [PATCH] Xi: add "deletable" flag to properties, add DeleteProperty handler.

Deletable properties may be deleted, if the handlers allow it.

Non-deletable properties may be deleted by a driver/server if all handlers
allow it. A client cannot delete these properties.
---
 Xi/xiproperty.c    |   34 ++++++++++++++++++++++++++--------
 dix/devices.c      |    9 +++------
 include/exevents.h |   13 ++++++++++---
 include/inputstr.h |    6 ++++--
 4 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 94d5499..1e4ed46 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -97,10 +97,11 @@ long
 XIRegisterPropertyHandler(DeviceIntPtr         dev,
                           int (*SetProperty) (DeviceIntPtr dev,
                                               Atom property,
-                                              XIPropertyValuePtr prop,
-                                              BOOL delete),
+                                              XIPropertyValuePtr prop),
                           int (*GetProperty) (DeviceIntPtr dev,
-                                              Atom property))
+                                              Atom property),
+                          int (*DeleteProperty) (DeviceIntPtr dev,
+                                                 Atom property))
 {
     XIPropertyHandlerPtr new_handler;
 
@@ -111,6 +112,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;
 
@@ -155,6 +157,7 @@ XICreateDeviceProperty (Atom property)
     prop->value.format = 0;
     prop->value.size   = 0;
     prop->value.data   = NULL;
+    prop->deletable    = TRUE;
 
     return prop;
 }
@@ -220,20 +223,23 @@ XIDeleteDeviceProperty (DeviceIntPtr device, Atom property, Bool fromClient)
 {
     XIPropertyPtr               prop, *prev;
     devicePropertyNotify        event;
-    int                         rc;
+    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 (fromClient && device->properties.handlers)
+    if (device->properties.handlers)
     {
         XIPropertyHandlerPtr handler = device->properties.handlers;
         while(handler)
         {
-            rc = handler->SetProperty(device, prop->propertyName,
-                                      &prop->value, TRUE);
+            if (handler->DeleteProperty)
+                rc = handler->DeleteProperty(device, prop->propertyName);
             if (rc != Success)
                 return (rc);
             handler = handler->next;
@@ -346,7 +352,7 @@ XIChangeDeviceProperty (DeviceIntPtr dev, Atom property, Atom type,
                 if (handler->SetProperty)
                 {
                     rc = handler->SetProperty(dev, prop->propertyName,
-                                              &new_value, FALSE);
+                                              &new_value);
                     if (rc != Success)
                     {
                         if (new_value.data)
@@ -420,6 +426,18 @@ XIGetDeviceProperty (DeviceIntPtr dev, Atom property, XIPropertyValuePtr *value)
 }
 
 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)
 {
     Atom                        *pAtoms = NULL, *temppAtoms;
diff --git a/dix/devices.c b/dix/devices.c
index a16cd1c..f8ae6da 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -103,14 +103,10 @@ DevPrivateKey UnusedClassesPrivateKey = &UnusedClassesPrivateKeyIndex;
  * DIX property handler.
  */
 static int
-DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
-                  BOOL delete)
+DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop)
 {
     if (property == XIGetKnownProperty(XI_PROP_ENABLED))
     {
-        if (delete) /* you're not allowed to delete any server-internal prop */
-            return BadAccess;
-
         if (prop->format != 8 || prop->type != XA_INTEGER || prop->size != 1)
             return BadValue;
 
@@ -228,7 +224,8 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED),
                            XA_INTEGER, 8, PropModeReplace, 1, &dev->enabled,
                            FALSE);
-    XIRegisterPropertyHandler(dev, DeviceSetProperty, NULL);
+    XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_ENABLED), FALSE);
+    XIRegisterPropertyHandler(dev, DeviceSetProperty, NULL, NULL);
 
     return dev;
 }
diff --git a/include/exevents.h b/include/exevents.h
index b22d433..4df0aee 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -222,14 +222,21 @@ extern int XIGetDeviceProperty(
         XIPropertyValuePtr*     /* value */
 );
 
+extern int XISetDevicePropertyDeletable(
+        DeviceIntPtr            /* dev */,
+        Atom                    /* property */,
+        Bool                    /* deletable */
+);
+
 extern long XIRegisterPropertyHandler(
         DeviceIntPtr         dev,
         int (*SetProperty) (DeviceIntPtr dev,
                             Atom property,
-                            XIPropertyValuePtr prop,
-                            BOOL delete),
+                            XIPropertyValuePtr prop),
         int (*GetProperty) (DeviceIntPtr dev,
-                            Atom property)
+                            Atom property),
+        int (*DeleteProperty) (DeviceIntPtr dev,
+                               Atom property)
 );
 
 extern void XIUnRegisterPropertyHandler(
diff --git a/include/inputstr.h b/include/inputstr.h
index 0a8bf91..65cb1b9 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -353,6 +353,7 @@ typedef struct _XIProperty
 {
     struct _XIProperty   *next;
     Atom                  propertyName;
+    BOOL                  deletable;    /* clients can delete this prop? */
     XIPropertyValueRec    value;
 } XIPropertyRec;
 
@@ -366,10 +367,11 @@ typedef struct _XIPropertyHandler
     long id;
     int (*SetProperty) (DeviceIntPtr dev,
                         Atom property,
-                        XIPropertyValuePtr prop,
-                        BOOL delete);
+                        XIPropertyValuePtr prop);
     int (*GetProperty) (DeviceIntPtr dev,
                         Atom property);
+    int (*DeleteProperty) (DeviceIntPtr dev,
+                           Atom property);
 } XIPropertyHandler, *XIPropertyHandlerPtr;
 
 /* states for devices */
-- 
1.5.4.3




More information about the xorg mailing list