xserver: Branch 'master' - 4 commits

Peter Hutterer whot at kemper.freedesktop.org
Tue Jun 30 16:00:15 PDT 2009


 Xext/xtest.c                 |   10 ----
 Xi/xichangehierarchy.c       |  106 ++++++++++---------------------------------
 Xi/xiproperty.c              |    1 
 dix/devices.c                |   76 ++++++++++++++++++++++++++++--
 dix/inpututils.c             |    6 ++
 include/input.h              |    6 ++
 include/xserver-properties.h |    2 
 7 files changed, 112 insertions(+), 95 deletions(-)

New commits:
commit e13605ea40cfc671314a0086c75b917564298b55
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 23 14:09:22 2009 +1000

    dix: introduce "Xtst Device" label property.
    
    Xtst devices get this property assigned automatically so they can be
    detected easily by a client.
    The property is read-only.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 396061f..55f20c4 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -51,6 +51,7 @@ static struct dev_properties
     char *name;
 } dev_properties[] = {
     {0, XI_PROP_ENABLED},
+    {0, XI_PROP_XTST_DEVICE},
     {0, XATOM_FLOAT},
     {0, ACCEL_PROP_PROFILE_NUMBER},
     {0, ACCEL_PROP_CONSTANT_DECELERATION},
diff --git a/dix/devices.c b/dix/devices.c
index b7f2192..a99d046 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2563,6 +2563,19 @@ AllocDevicePair (ClientPtr client, char* name,
 }
 
 /**
+ * Don't allow changing the Xtst property.
+ */
+static int
+DeviceSetXtstProperty(DeviceIntPtr dev, Atom property,
+                      XIPropertyValuePtr prop, BOOL checkonly)
+{
+    if (property == XIGetKnownProperty(XI_PROP_XTST_DEVICE))
+        return BadAccess;
+
+    return Success;
+}
+
+/**
  * Allocate a device pair that is initialised as a slave
  * device with properties that identify the devices as belonging
  * to XTest subsystem.
@@ -2576,6 +2589,7 @@ int AllocXtstDevice (ClientPtr client, char* name,
     int retval;
     int len = strlen(name);
     char *xtstname = xcalloc(len + 6, 1 );
+    char dummy = 1;
 
     strncpy( xtstname, name, len);
     strncat( xtstname, " Xtst", 5 );
@@ -2588,6 +2602,17 @@ int AllocXtstDevice (ClientPtr client, char* name,
 
     xfree( xtstname );
 
+    XIChangeDeviceProperty(*ptr, XIGetKnownProperty(XI_PROP_XTST_DEVICE),
+                           XA_INTEGER, 8, PropModeReplace, 1, &dummy,
+                           FALSE);
+    XISetDevicePropertyDeletable(*ptr, XIGetKnownProperty(XI_PROP_XTST_DEVICE), FALSE);
+    XIRegisterPropertyHandler(*ptr, DeviceSetXtstProperty, NULL, NULL);
+    XIChangeDeviceProperty(*keybd, XIGetKnownProperty(XI_PROP_XTST_DEVICE),
+                           XA_INTEGER, 8, PropModeReplace, 1, &dummy,
+                           FALSE);
+    XISetDevicePropertyDeletable(*keybd, XIGetKnownProperty(XI_PROP_XTST_DEVICE), FALSE);
+    XIRegisterPropertyHandler(*keybd, DeviceSetXtstProperty, NULL, NULL);
+
     return retval;
 }
 
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
index 9b3b7bf..0f18dbc 100644
--- a/include/xserver-properties.h
+++ b/include/xserver-properties.h
@@ -32,6 +32,8 @@
 
 /* BOOL. 0 - device disabled, 1 - device enabled */
 #define XI_PROP_ENABLED      "Device Enabled"
+/* BOOL. If present, device is a virtual Xtst device */
+#define XI_PROP_XTST_DEVICE  "Xtst Device"
 
 /* Pointer acceleration properties */
 /* INTEGER of any format */
commit 0814f511d56a89c7b1868b17eba7a89f990b9ab1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 23 10:50:52 2009 +1000

    input: store the master device's ID in the devPrivate for XTest devices.
    
    Rather than storing a simple boolean in the devPrivate for XTest devices,
    store the actual master device's id (since it is constant for the life of
    the device anyway).
    
    Callers should use GetXtstDevice now instead of digging around in the
    devPrivates themselves.
    
    This patch allows for a cleanup in the creation of new master devices since
    GetMaster and GetXtstDevice spare the need for loops, IsPointer checks and
    similar.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Benjamin Close <Benjamin.Close at clearchain.com>

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 32abe2a..4f5c527 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -56,7 +56,6 @@
 
 extern int DeviceValuator;
 extern int DeviceMotionNotify;
-extern DevPrivateKey XTstDevicePrivateKey;
 
 #ifdef PANORAMIX
 #include "panoramiX.h"
@@ -299,14 +298,7 @@ ProcXTestFakeInput(ClientPtr client)
                 return BadValue;
         }
 
-        /* When faking core events through XTest, we always fake through the
-         * virtual test device.
-         */
-        for(it = inputInfo.devices; it ; it = it->next )
-            if( !IsMaster(it) && it->u.master == dev &&
-                    dixLookupPrivate(&it->devPrivates, XTstDevicePrivateKey ))
-                break;
-        dev= it;
+        dev = GetXtstDevice(dev);
     }
 
     /* If the event has a time set, wait for it to pass */
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 137c209..656515b 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -186,8 +186,9 @@ ProcXIChangeHierarchy(ClientPtr client)
                     if (!c->send_core)
                         ptr->coreEvents = keybd->coreEvents =  FALSE;
 
-		    /* Allocate virtual slave devices for xtest events */
-                    rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd);
+                    /* Allocate virtual slave devices for xtest events */
+                    rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd,
+                                         ptr, keybd);
                     if (rc != Success)
                     {
 
@@ -231,7 +232,6 @@ ProcXIChangeHierarchy(ClientPtr client)
             case XIRemoveMaster:
                 {
                     xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
-                    DeviceIntPtr xtstdevice;
 
                     if (r->return_mode != XIAttachToMaster &&
                             r->return_mode != XIFloating)
@@ -257,69 +257,33 @@ ProcXIChangeHierarchy(ClientPtr client)
                         goto unwind;
                     }
 
-                    for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                        if (IsXtstDevice(xtstdevice, ptr))
-                            break;
 
-                    rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
+                    ptr = GetMaster(ptr, MASTER_POINTER);
+                    rc = dixLookupDevice(&ptr,
+                                         ptr->id,
+                                         client,
+                                         DixDestroyAccess);
+                    if (rc != Success)
+                        goto unwind;
+                    keybd = GetMaster(ptr, MASTER_KEYBOARD);
+                    rc = dixLookupDevice(&keybd,
+                                         keybd->id,
+                                         client,
                                          DixDestroyAccess);
                     if (rc != Success)
                         goto unwind;
 
-                    /* find keyboards to destroy */
-                    if (IsPointerDevice(ptr))
-                    {
-                        rc = dixLookupDevice(&keybd,
-                                             ptr->spriteInfo->paired->id,
-                                             client,
-                                             DixDestroyAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                    }
-                    else
-                    {
-                        keybd = ptr;
-                        rc = dixLookupDevice(&ptr,
-                                             keybd->spriteInfo->paired->id,
-                                             client,
-                                             DixDestroyAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                    }
-
-                    /* handle xtst pointer / keyboard slave devices */
-                    if ( IsPointerDevice(xtstptr))
-                    {
-                        /* Search the matching keyboard */
-                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if(IsKeyboardDevice(xtstdevice) && IsXtstDevice(xtstdevice, keybd))
-                                break;
-
-                        rc = dixLookupDevice(&xtstkeybd,
-                                             xtstdevice->id,
-                                             client,
-                                             DixDestroyAccess);
-
-                        if (rc != Success)
-                            goto unwind;
-                    }
-                    else
-                    {
-                        xtstkeybd = xtstptr;
-                        /* Search the matching pointer */
-                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if(IsPointerDevice(xtstdevice) && IsXtstDevice(xtstdevice, ptr))
-                                break;
-                        rc = dixLookupDevice(&xtstptr,
-                                             xtstdevice->id,
-                                             client,
-                                             DixDestroyAccess);
+                    xtstptr = GetXtstDevice(ptr);
+                    rc = dixLookupDevice(&xtstptr, xtstptr->id, client,
+                                         DixDestroyAccess);
+                    if (rc != Success)
+                        goto unwind;
 
-                        if (rc != Success)
-                            goto unwind;
-                    }
+                    xtstkeybd = GetXtstDevice(keybd);
+                    rc = dixLookupDevice(&xtstkeybd, xtstkeybd->id, client,
+                                         DixDestroyAccess);
+                    if (rc != Success)
+                        goto unwind;
 
                     /* Disabling sends the devices floating, reattach them if
                      * desired. */
diff --git a/dix/devices.c b/dix/devices.c
index 2d77657..b7f2192 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -639,8 +639,8 @@ InitCoreDevices(void)
       is a slave device to inputInfo master devices
      */
     if(AllocXtstDevice(serverClient, "Virtual core",
-                       &vxtstpointer,
-                       &vxtstkeyboard) != Success)
+                       &vxtstpointer, &vxtstkeyboard,
+                       inputInfo.pointer, inputInfo.keyboard) != Success)
         FatalError("Failed to allocate XTst devices");
 
     if (ActivateDevice(vxtstpointer, TRUE) != Success ||
@@ -2570,7 +2570,8 @@ AllocDevicePair (ClientPtr client, char* name,
  * still need to be called.
  */
 int AllocXtstDevice (ClientPtr client, char* name,
-		 DeviceIntPtr* ptr, DeviceIntPtr* keybd)
+                     DeviceIntPtr* ptr, DeviceIntPtr* keybd,
+                     DeviceIntPtr master_ptr, DeviceIntPtr master_keybd)
 {
     int retval;
     int len = strlen(name);
@@ -2581,8 +2582,8 @@ int AllocXtstDevice (ClientPtr client, char* name,
 
     retval = AllocDevicePair( client, xtstname, ptr, keybd, FALSE);
     if ( retval == Success ){
-	dixSetPrivate(&((*ptr)->devPrivates), XTstDevicePrivateKey, (void *)True );
-	dixSetPrivate(&((*keybd)->devPrivates), XTstDevicePrivateKey,(void *)True);
+        dixSetPrivate(&((*ptr)->devPrivates), XTstDevicePrivateKey, (void *)master_ptr->id);
+        dixSetPrivate(&((*keybd)->devPrivates), XTstDevicePrivateKey, (void *)master_keybd->id);
     }
 
     xfree( xtstname );
@@ -2599,6 +2600,33 @@ int AllocXtstDevice (ClientPtr client, char* name,
 BOOL
 IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master)
 {
-    return (!IsMaster(dev) && (!master || dev->u.master == master) &&
-           ( dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey) != NULL));
+    int mid;
+    void *tmp; /* shut up, gcc! */
+
+    if (IsMaster(dev))
+        return FALSE;
+
+    tmp = dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey);
+    mid = (int)tmp;
+
+    return (!master || mid == master->id);
 }
+
+/**
+ * @return The X Test virtual device for the given master.
+ */
+DeviceIntPtr
+GetXtstDevice(DeviceIntPtr master)
+{
+    DeviceIntPtr it;
+
+    for (it = inputInfo.devices; it; it = it->next)
+    {
+        if (IsXtstDevice(it, master))
+            return it;
+    }
+
+    /* This only happens if master is a slave device. don't do that */
+    return NULL;
+}
+
diff --git a/include/input.h b/include/input.h
index 1dfbbff..40ba660 100644
--- a/include/input.h
+++ b/include/input.h
@@ -496,8 +496,11 @@ extern int change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *map,
 extern int AllocXtstDevice(ClientPtr client,
                              char* name,
                              DeviceIntPtr* ptr,
-                             DeviceIntPtr* keybd);
+                             DeviceIntPtr* keybd,
+                             DeviceIntPtr master_ptr,
+                             DeviceIntPtr master_keybd);
 extern BOOL IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master);
+extern DeviceIntPtr GetXtstDevice(DeviceIntPtr master);
 
 /* misc event helpers */
 extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);
commit 1bcc0d3c244ce7d9f5cbab626aa5fd5784b41a1c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 22 16:55:12 2009 +1000

    input: abstract Xtst device lookup
    
    The callers should need to use the dev privates key to look up xtest
    devices.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Benjamin Close <Benjamin.Close at clearchain.com>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 917a0d7..137c209 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -54,8 +54,6 @@
 
 #include "xichangehierarchy.h"
 
-extern DevPrivateKey XTstDevicePrivateKey;
-
 /**
  * Send the current state of the device hierarchy to all clients.
  */
@@ -260,8 +258,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                     }
 
                     for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                        if( !IsMaster(xtstdevice) && xtstdevice->u.master == ptr &&
-                            dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                        if (IsXtstDevice(xtstdevice, ptr))
                             break;
 
                     rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
@@ -297,10 +294,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                     {
                         /* Search the matching keyboard */
                         for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == keybd &&
-                                IsKeyboardDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                            if(IsKeyboardDevice(xtstdevice) && IsXtstDevice(xtstdevice, keybd))
                                 break;
 
                         rc = dixLookupDevice(&xtstkeybd,
@@ -316,11 +310,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                         xtstkeybd = xtstptr;
                         /* Search the matching pointer */
                         for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == ptr &&
-                                IsPointerDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey )
-                              )
+                            if(IsPointerDevice(xtstdevice) && IsXtstDevice(xtstdevice, ptr))
                                 break;
                         rc = dixLookupDevice(&xtstptr,
                                              xtstdevice->id,
@@ -412,7 +402,6 @@ ProcXIChangeHierarchy(ClientPtr client)
             case XIDetachSlave:
                 {
                     xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
-                    DeviceIntPtr *xtstdevice;
 
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixManageAccess);
@@ -426,11 +415,8 @@ ProcXIChangeHierarchy(ClientPtr client)
                         goto unwind;
                     }
 
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
                     /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
+                    if (IsXtstDevice(ptr, NULL))
                     {
                         client->errorValue = c->deviceid;
                         rc = BadDevice;
@@ -445,7 +431,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                 {
                     xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
                     DeviceIntPtr newmaster;
-                    DeviceIntPtr *xtstdevice;
 
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixManageAccess);
@@ -459,11 +444,8 @@ ProcXIChangeHierarchy(ClientPtr client)
                         goto unwind;
                     }
 
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
                     /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
+                    if (IsXtstDevice(ptr, NULL))
                     {
                         client->errorValue = c->deviceid;
                         rc = BadDevice;
diff --git a/dix/devices.c b/dix/devices.c
index b237e03..2d77657 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2589,3 +2589,16 @@ int AllocXtstDevice (ClientPtr client, char* name,
 
     return retval;
 }
+
+/**
+ * If master is NULL, return TRUE if the given device is an xtest device or
+ * FALSE otherwise.
+ * If master is not NULL, return TRUE if the given device is this master's
+ * xtest device.
+ */
+BOOL
+IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master)
+{
+    return (!IsMaster(dev) && (!master || dev->u.master == master) &&
+           ( dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey) != NULL));
+}
diff --git a/include/input.h b/include/input.h
index 9711fa8..1dfbbff 100644
--- a/include/input.h
+++ b/include/input.h
@@ -497,6 +497,7 @@ extern int AllocXtstDevice(ClientPtr client,
                              char* name,
                              DeviceIntPtr* ptr,
                              DeviceIntPtr* keybd);
+extern BOOL IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master);
 
 /* misc event helpers */
 extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);
commit 34424fab9abd7a4ca11036be25414129980db0e0
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 23 11:50:29 2009 +1000

    dix: set the client's error value to the bad deviceid in check_butmap_change.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 8194e69..378deb0 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -45,11 +45,17 @@ check_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, CARD32 *errval_out,
     int i, ret;
 
     if (!dev || !dev->button)
+    {
+        client->errorValue = (dev) ? dev->id : 0;
         return BadDevice;
+    }
 
     ret = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess);
     if (ret != Success)
+    {
+        client->errorValue = dev->id;
         return ret;
+    }
 
     for (i = 0; i < len; i++) {
         if (dev->button->map[i + 1] != map[i] && dev->button->down[i + 1])


More information about the xorg-commit mailing list