xserver: Branch 'mpx' - 10 commits

Peter Hutterer whot at kemper.freedesktop.org
Mon Feb 25 21:27:38 PST 2008


 Xi/Makefile.am                 |    2 
 Xi/extgrbdev.c                 |   17 ------
 Xi/extinit.c                   |    7 --
 Xi/getpairp.c                  |  104 -----------------------------------------
 Xi/getpairp.h                  |   45 -----------------
 Xi/listdev.c                   |    4 +
 Xi/listdev.h                   |    5 +
 dix/devices.c                  |   45 +++++++++++++++++
 dix/events.c                   |   17 +-----
 dix/getevents.c                |   52 +++++++++++++++-----
 hw/kdrive/src/kinput.c         |   16 ++----
 hw/xfree86/common/xf86Xinput.c |   30 +----------
 include/dix.h                  |    3 -
 include/input.h                |    7 ++
 14 files changed, 119 insertions(+), 235 deletions(-)

New commits:
commit 23ae68a4c74a2ec90b4130c37b0d0aec3f4082ce
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Feb 26 15:12:36 2008 +1030

    dix: before copying the classes the first time, set the VCK's classes to NULL.
    
    XkbFinishDeviceInit does the following:
      xkbi->kbdProc= pXDev->kbdfeed->CtrlProc;
      pXDev->kbdfeed->CtrlProc= XkbDDXKeybdCtrlProc;
    
    If we directly copy the device classes for the VCK, pXDev->kbdfeed->CtrlProc
    at the time of copying is still XbkDDXKeybdCtrlProc. So at some point
    XkbDDXKeybdCtrlProc is called, and calls itself, and calls itself, and...
    
    Setting the device's classes to NULL seems to fix things. The memory isn't
    lost, it gets stored into the devPrivates and freed at device closing time.

diff --git a/dix/devices.c b/dix/devices.c
index 38466f8..f036985 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -484,6 +484,21 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what)
          * If we don't do that, we're in SIGABRT territory (double-frees, etc)
          */
         memcpy(&dummy, pDev, sizeof(DeviceIntRec));
+        /* Need to set them to NULL. Otherwise, Xkb does some weird stuff and
+         * the dev->key->xkbInfo->kbdProc starts calling itself. This can
+         * probably be fixed in a better way, but I don't know how. (whot) */
+        pDev->key        = NULL;
+        pDev->valuator   = NULL;
+        pDev->button     = NULL;
+        pDev->focus      = NULL;
+        pDev->proximity  = NULL;
+        pDev->absolute   = NULL;
+        pDev->kbdfeed    = NULL;
+        pDev->ptrfeed    = NULL;
+        pDev->intfeed    = NULL;
+        pDev->stringfeed = NULL;
+        pDev->bell       = NULL;
+        pDev->leds       = NULL;
         DeepCopyDeviceClasses(&dummy, pDev);
 
         dixSetPrivate(&pDev->devPrivates, MasterDevClassesPrivateKey,
@@ -547,6 +562,20 @@ CorePointerProc(DeviceIntPtr pDev, int what)
 
         /* See comment in CoreKeyboardProc. */
         memcpy(&dummy, pDev, sizeof(DeviceIntRec));
+        /* Need to set them to NULL for the VCK (see CoreKeyboardProc). Not
+         * sure if also necessary for the VCP, but it doesn't seem to hurt */
+        pDev->key        = NULL;
+        pDev->valuator   = NULL;
+        pDev->button     = NULL;
+        pDev->focus      = NULL;
+        pDev->proximity  = NULL;
+        pDev->absolute   = NULL;
+        pDev->kbdfeed    = NULL;
+        pDev->ptrfeed    = NULL;
+        pDev->intfeed    = NULL;
+        pDev->stringfeed = NULL;
+        pDev->bell       = NULL;
+        pDev->leds       = NULL;
         DeepCopyDeviceClasses(&dummy, pDev);
 
         dixSetPrivate(&pDev->devPrivates, MasterDevClassesPrivateKey, classes);
commit ce9fb2f8c4610016e49321018fc9b24729380afc
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Feb 26 13:19:54 2008 +1030

    Xi: MDs return the paired device's ID in attached field of ListInputDevices.

diff --git a/Xi/listdev.c b/Xi/listdev.c
index 50f34e4..3fb0ab3 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -188,6 +188,8 @@ CopySwapDevice(ClientPtr client, DeviceIntPtr d, int num_classes,
 	dev->use = IsXExtensionDevice;
     if (!d->isMaster)
         dev->attached = (d->u.master) ? d->u.master->id : IsFloating;
+    else
+        dev->attached = GetPairedDevice(d)->id;
 
     if (client->swapped) {
 	swapl(&dev->type, n);	/* macro - braces are required */
commit d61f481a4455dd2a94674d2b7b26429cf9dcece3
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Mon Feb 25 17:52:45 2008 +1030

    Xi: remove GetPairedPointer handling.
    
    obsolete, ListInputDevices provides this information now.

diff --git a/Xi/Makefile.am b/Xi/Makefile.am
index 7804c51..2af1940 100644
--- a/Xi/Makefile.am
+++ b/Xi/Makefile.am
@@ -46,8 +46,6 @@ libXi_la_SOURCES =	\
 	getkmap.h \
 	getmmap.c \
 	getmmap.h \
-	getpairp.c \
-	getpairp.h \
 	getprop.c \
 	getprop.h \
 	getselev.c \
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 0cf429f..f1c2824 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -94,7 +94,6 @@ SOFTWARE.
 #include "getfocus.h"
 #include "getkmap.h"
 #include "getmmap.h"
-#include "getpairp.h"
 #include "getprop.h"
 #include "getselev.h"
 #include "getvers.h"
@@ -335,8 +334,6 @@ ProcIDispatch(ClientPtr client)
         return ProcXSetClientPointer(client);
     else if (stuff->data == X_GetClientPointer)
         return ProcXGetClientPointer(client);
-    else if (stuff->data == X_GetPairedPointer)
-        return ProcXGetPairedPointer(client);
     else if (stuff->data == X_ExtendedGrabDevice)
         return ProcXExtendedGrabDevice(client);
     else {
@@ -446,8 +443,6 @@ SProcIDispatch(ClientPtr client)
         return SProcXSetClientPointer(client);
     else if (stuff->data == X_GetClientPointer)
         return SProcXGetClientPointer(client);
-    else if (stuff->data == X_GetPairedPointer)
-        return SProcXGetPairedPointer(client);
     else if (stuff->data == X_ExtendedGrabDevice)
         return SProcXExtendedGrabDevice(client);
     else {
@@ -530,8 +525,6 @@ SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
                                (xQueryWindowAccessReply*) rep);
     else if (rep->RepType == X_GetClientPointer)
         SRepXGetClientPointer(client, len, (xGetClientPointerReply*) rep);
-    else if (rep->RepType == X_GetPairedPointer)
-        SRepXGetPairedPointer(client, len, (xGetPairedPointerReply*) rep);
     else if (rep->RepType == X_ExtendedGrabDevice)
         SRepXExtendedGrabDevice(client, len, (xExtendedGrabDeviceReply*) rep);
     else {
diff --git a/Xi/getpairp.c b/Xi/getpairp.c
deleted file mode 100644
index 59ed189..0000000
--- a/Xi/getpairp.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
-
-Copyright 2007 Peter Hutterer <peter at cs.unisa.edu.au>
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the author shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from the author.
-
-*/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XIproto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-
-#ifdef PANORAMIX
-#include "panoramiXsrv.h"
-#endif
-
-#include "getpairp.h"
-
-/***********************************************************************
- *
- * This procedure allows a client to query the paired pointer for a keyboard
- * device.
- *
- */
-
-int
-SProcXGetPairedPointer(ClientPtr client)
-{
-    char n;
-    REQUEST(xGetPairedPointerReq);
-    swaps(&stuff->length, n);
-    return (ProcXGetPairedPointer(client));
-}
-
-int 
-ProcXGetPairedPointer(ClientPtr client)
-{
-    xGetPairedPointerReply rep;
-    DeviceIntPtr kbd, ptr;
-    int rc;
-
-    REQUEST(xGetPairedPointerReq);
-    REQUEST_SIZE_MATCH(xGetPairedPointerReq);
-
-    rc = dixLookupDevice(&kbd, stuff->deviceid, client, DixReadAccess);
-    if (rc != Success)
-        return rc;
-    else if (!kbd->key || !kbd->isMaster) {
-        client->errorValue = stuff->deviceid;
-        return BadDevice;
-    }
-
-    ptr = GetPairedDevice(kbd);
-
-    rep.repType = X_Reply;
-    rep.RepType = X_GetPairedPointer;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.paired = TRUE;
-    rep.deviceid = ptr->id;
-    WriteReplyToClient(client, sizeof(xGetPairedPointerReply), &rep);
-    return Success;
-}
-
-void
-SRepXGetPairedPointer(ClientPtr client, int size,
-        xGetPairedPointerReply* rep)
-{
-    char n;
-
-    swaps(&rep->sequenceNumber, n);
-    swapl(&rep->length, n);
-    WriteToClient(client, size, (char *)rep);
-}
diff --git a/Xi/getpairp.h b/Xi/getpairp.h
deleted file mode 100644
index 9b4759e..0000000
--- a/Xi/getpairp.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-
-Copyright 2007 Peter Hutterer <peter at cs.unisa.edu.au>
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the author shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from the author.
-
-*/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef GETPAIRP_H
-#define GETPAIRP_H 1
-
-int SProcXGetPairedPointer(ClientPtr /* client */
-        );
-int ProcXGetPairedPointer(ClientPtr /* client */
-        );
-void SRepXGetPairedPointer(ClientPtr /* client */,
-        int /* size */,
-        xGetPairedPointerReply* /* rep */
-        );
-
-#endif /* GETPAIRP_H */
commit 27b21278939a06ab6a22c9902f202eae6c5fae72
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Mon Feb 25 17:00:42 2008 +1030

    Xi: remove ungrab handling of ExtendedUngrabDevice request.
    
    This can be done by UngrabDevice, no need for separate codepaths.

diff --git a/Xi/extgrbdev.c b/Xi/extgrbdev.c
index 72f8879..6458404 100644
--- a/Xi/extgrbdev.c
+++ b/Xi/extgrbdev.c
@@ -107,19 +107,13 @@ ProcXExtendedGrabDevice(ClientPtr client)
     REQUEST(xExtendedGrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xExtendedGrabDeviceReq);
 
-    if (stuff->ungrab)
-    {
-        REQUEST_SIZE_MATCH(xExtendedGrabDeviceReq);
-    }
-
     rep.repType         = X_Reply;
     rep.RepType         = X_ExtendedGrabDevice;
     rep.sequenceNumber  = client->sequence;
     rep.length          = 0;
 
-    if (!stuff->ungrab && /* other fields are undefined for ungrab */
-            (stuff->length != (sizeof(xExtendedGrabDeviceReq) >> 2) +
-            stuff->event_count + 2 * stuff->generic_event_count))
+    if (stuff->length != (sizeof(xExtendedGrabDeviceReq) >> 2) +
+            stuff->event_count + 2 * stuff->generic_event_count)
     {
         errval = 0;
         rc = BadLength;
@@ -131,13 +125,6 @@ ProcXExtendedGrabDevice(ClientPtr client)
 	goto cleanup;
     }
 
-
-    if (stuff->ungrab)
-    {
-        ExtUngrabDevice(client, dev);
-        goto cleanup;
-    }
-
     rc = dixLookupWindow(&grab_window,
                           stuff->grab_window,
                           client,
diff --git a/dix/events.c b/dix/events.c
index bf2df9f..0b9b768 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -6604,15 +6604,3 @@ ExtGrabDevice(ClientPtr client,
     return GrabSuccess;
 }
 
-
-_X_EXPORT int
-ExtUngrabDevice(ClientPtr client, DeviceIntPtr dev)
-{
-    GrabInfoPtr grabinfo = &dev->deviceGrab;
-    if (grabinfo->grab && SameClient(grabinfo->grab, client))
-        (*grabinfo->DeactivateGrab)(dev);
-    return GrabSuccess;
-}
-
-
-
diff --git a/include/dix.h b/include/dix.h
index 079645d..1ed4af0 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -698,7 +698,4 @@ extern int ExtGrabDevice(ClientPtr client,
                          CursorPtr cursor, 
                          Mask xi_mask,
                          GenericMaskPtr ge_masks);
-extern int ExtUngrabDevice(ClientPtr client,
-                         DeviceIntPtr dev);
-
 #endif /* DIX_H */
commit f14a62f823e257f92745bbcde11838f2ddd32ac8
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Feb 19 21:44:10 2008 +1030

    dix: set evlen to the size of the reallocated memory.
    
    What a good idea this is... I'm very proud of myself.

diff --git a/dix/getevents.c b/dix/getevents.c
index 15b7dc3..7537906 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -613,6 +613,7 @@ SetMinimumEventSize(EventListPtr list, int num_events, int min_size)
     {
         if (list[num_events].evlen < min_size)
         {
+            list[num_events].evlen = min_size;
             list[num_events].event = realloc(list[num_events].event, min_size);
             if (!list[num_events].event)
             {
commit 750d70267679ddee10590c80ec621d890bd3d4a7
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Feb 3 10:25:15 2008 +1030

    dix: Ensure enough memory for ClassesChangedEvent for a new device.
    
    Before we enable the device through the driver, we size it up and make sure
    that the events in the event list contain enough bytes for a possible
    ClassesChangedEvent lateron.

diff --git a/dix/devices.c b/dix/devices.c
index 0ffc798..38466f8 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -206,6 +206,10 @@ EnableDevice(DeviceIntPtr dev)
     DeviceIntRec dummyDev;
     DeviceIntPtr other;
     devicePresenceNotify ev;
+    int namelen = 0; /* dummy */
+    int evsize  = sizeof(xEvent);
+    int listlen;
+    EventListPtr evlist;
 
     for (prev = &inputInfo.off_devices;
 	 *prev && (*prev != dev);
@@ -238,6 +242,18 @@ EnableDevice(DeviceIntPtr dev)
         }
     }
 
+    /* Before actually enabling the device, we need to make sure the event
+     * list's events have enough memory for a ClassesChangedEvent from the
+     * device
+     */
+
+    SizeDeviceInfo(dev, &namelen, &evsize);
+
+    listlen = GetEventList(&evlist);
+    OsBlockSignals();
+    SetMinimumEventSize(evlist, listlen, evsize);
+    OsReleaseSignals();
+
     if ((*prev != dev) || !dev->inited ||
 	((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) {
         ErrorF("[dix] couldn't enable device %d\n", dev->id);
commit 74628d639719815c1beff4cac84662fa41c55925
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Feb 3 10:15:40 2008 +1030

    dix: change GetEventList to return length of list and set parameter in place.
    
    Changing DDXs to use new prototype too.

diff --git a/dix/getevents.c b/dix/getevents.c
index 407ac58..15b7dc3 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -77,10 +77,11 @@ extern Bool XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies);
 EventListPtr InputEventList = NULL;
 int InputEventListLen = 0;
 
-_X_EXPORT EventListPtr
-GetEventList()
+_X_EXPORT int
+GetEventList(EventListPtr* list)
 {
-    return InputEventList;
+    *list = InputEventList;
+    return InputEventListLen;
 }
 
 /**
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 78b4419..62a8261 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -65,7 +65,7 @@ static struct KdConfigDevice *kdConfigPointers    = NULL;
 static KdKeyboardDriver *kdKeyboardDrivers = NULL;
 static KdPointerDriver  *kdPointerDrivers  = NULL;
 
-static EventListPtr     *kdEvents = NULL;
+static EventListPtr     kdEvents = NULL;
 
 static Bool		kdInputEnabled;
 static Bool		kdOffScreen;
@@ -1979,7 +1979,7 @@ KdReleaseAllKeys (void)
              key++) {
             if (IsKeyDown(ki, key)) {
                 KdHandleKeyboardEvent(ki, KeyRelease, key);
-                kdEvents = GetEventList();
+                GetEventList(&kdEvents);
                 nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key);
                 for (i = 0; i < nEvents; i++)
                     KdQueueEvent (ki->dixdev, kdEvents + i);
@@ -2044,7 +2044,7 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo   *ki,
             KdHandleKeyboardEvent(ki, type, key_code);
 	}
 	
-        kdEvents = GetEventList();
+        GetEventList(&kdEvents);
         nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code);
         for (i = 0; i < nEvents; i++)
             KdQueueEvent(ki->dixdev, kdEvents);
@@ -2145,7 +2145,7 @@ _KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z,
     if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel))
         return;
 
-    kdEvents = GetEventList();
+    GetEventList(&kdEvents);
     nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel,
                                0, 3, valuators);
     for (i = 0; i < nEvents; i++)
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index a928b4c..d2c0531 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -569,7 +569,7 @@ xf86PostMotionEventP(DeviceIntPtr	device,
     }
 #endif
 
-    xf86Events = GetEventList();
+    GetEventList(&xf86Events);
     nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
                                flags, first_valuator, num_valuators,
                                valuators);
@@ -601,7 +601,7 @@ xf86PostProximityEvent(DeviceIntPtr	device,
         valuators[i] = va_arg(var, int);
     va_end(var);
 
-    xf86Events = GetEventList();
+    GetEventList(&xf86Events);
     nevents = GetProximityEvents(xf86Events, device,
                                  is_in ? ProximityIn : ProximityOut, 
                                  first_valuator, num_valuators, valuators);
@@ -639,7 +639,7 @@ xf86PostButtonEvent(DeviceIntPtr	device,
         valuators[i] = va_arg(var, int);
     va_end(var);
 
-    xf86Events = GetEventList();
+    GetEventList(&xf86Events);
     nevents = GetPointerEvents(xf86Events, device,
                                is_down ? ButtonPress : ButtonRelease, button,
                                (is_absolute) ? POINTER_ABSOLUTE : POINTER_RELATIVE,
@@ -675,7 +675,7 @@ xf86PostKeyEvent(DeviceIntPtr	device,
             valuators[i] = va_arg(var, int);
         va_end(var);
 
-        xf86Events = GetEventList();
+        GetEventList(&xf86Events);
         nevents = GetKeyboardValuatorEvents(xf86Events, device,
                                             is_down ? KeyPress : KeyRelease,
                                             key_code, first_valuator,
@@ -710,7 +710,7 @@ xf86PostKeyboardEvent(DeviceIntPtr      device,
     }
 #endif
 
-    xf86Events = GetEventList();
+    GetEventList(&xf86Events);
     nevents = GetKeyboardEvents(xf86Events, device,
                                 is_down ? KeyPress : KeyRelease, key_code);
 
diff --git a/include/input.h b/include/input.h
index af330a7..9ba12db 100644
--- a/include/input.h
+++ b/include/input.h
@@ -399,7 +399,7 @@ extern void InitInput(
 
 extern int GetMaximumEventsNum(void);
 
-extern EventListPtr GetEventList();
+extern int GetEventList(EventListPtr* list);
 extern EventListPtr InitEventList(int num_events);
 extern void SetMinimumEventSize(EventListPtr list,
                                 int num_events,
commit 77dba004a9aaf35f183f61ff6875a491a52aa030
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Feb 3 10:10:46 2008 +1030

    dix: add InputEventListLen and SetMinimumEventSize
    
    The latter is used to increase the amount of allocated memory for the event
    list. This will be needed for ClassesChangedEvents that can be of more or less
    arbitrary size (larger than 32 anyway).

diff --git a/dix/events.c b/dix/events.c
index 1155178..bf2df9f 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5712,7 +5712,8 @@ InitEvents(void)
 	DontPropagateRefCnts[i] = 0;
     }
 
-    InputEventList = InitEventList(GetMaximumEventsNum());
+    InputEventListLen = GetMaximumEventsNum();
+    InputEventList = InitEventList(InputEventListLen);
     if (!InputEventList)
         FatalError("[dix] Failed to allocate input event list.\n");
 }
diff --git a/dix/getevents.c b/dix/getevents.c
index 2a9df0f..407ac58 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -75,6 +75,7 @@ extern Bool XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies);
  * Get{Pointer|Keyboard}Events.
  */
 EventListPtr InputEventList = NULL;
+int InputEventListLen = 0;
 
 _X_EXPORT EventListPtr
 GetEventList()
@@ -599,6 +600,29 @@ InitEventList(int num_events)
 }
 
 /**
+ * Allocs min_size memory for each event in the list.
+ */
+_X_EXPORT void
+SetMinimumEventSize(EventListPtr list, int num_events, int min_size)
+{
+    if (!list)
+        return;
+
+    while(num_events--)
+    {
+        if (list[num_events].evlen < min_size)
+        {
+            list[num_events].event = realloc(list[num_events].event, min_size);
+            if (!list[num_events].event)
+            {
+                FatalError("[dix] Failed to set event list's "
+                        "min_size to %d.\n", min_size);
+            }
+        }
+    }
+}
+
+/**
  * Free an event list.
  *
  * @param list The list to be freed.
diff --git a/include/input.h b/include/input.h
index fb24e76..af330a7 100644
--- a/include/input.h
+++ b/include/input.h
@@ -96,6 +96,7 @@ typedef struct _EventList {
 
 /* The DIX stores incoming input events in this list */
 extern EventListPtr InputEventList;
+extern int InputEventListLen;
 
 typedef int (*DeviceProc)(
     DeviceIntPtr /*device*/,
@@ -400,6 +401,9 @@ extern int GetMaximumEventsNum(void);
 
 extern EventListPtr GetEventList();
 extern EventListPtr InitEventList(int num_events);
+extern void SetMinimumEventSize(EventListPtr list,
+                                int num_events,
+                                int min_size);
 extern void FreeEventList(EventListPtr list, int num_events);
 
 extern void CreateClassesChangedEvent(EventListPtr event, 
commit 3fe64d8d271aea0863bf01b0376f3eceec0c90b5
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Feb 3 09:56:19 2008 +1030

    Move input event list initialisation and storage from DDX to DIX.
    
    Rather than letting the DDX allocate the events, allocate them once in the DIX
    and just pass it around when needed.
    
    DDX should call GetEventList() to obtain this list and then pass it into
    Get{Pointer|Keyboard}Events.

diff --git a/dix/events.c b/dix/events.c
index 2928554..1155178 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5711,6 +5711,10 @@ InitEvents(void)
 	DontPropagateMasks[i] = 0;
 	DontPropagateRefCnts[i] = 0;
     }
+
+    InputEventList = InitEventList(GetMaximumEventsNum());
+    if (!InputEventList)
+        FatalError("[dix] Failed to allocate input event list.\n");
 }
 
 /**
diff --git a/dix/getevents.c b/dix/getevents.c
index 840fa2b..2a9df0f 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -70,6 +70,17 @@ extern Bool XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies);
 /* Number of motion history events to store. */
 #define MOTION_HISTORY_SIZE 256
 
+/* InputEventList is the container list for all input events generated by the
+ * DDX. The DDX is expected to call GetEventList() and then pass the list into
+ * Get{Pointer|Keyboard}Events.
+ */
+EventListPtr InputEventList = NULL;
+
+_X_EXPORT EventListPtr
+GetEventList()
+{
+    return InputEventList;
+}
 
 /**
  * Pick some arbitrary size for Xi motion history.
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 5b1dc5c..78b4419 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -65,7 +65,7 @@ static struct KdConfigDevice *kdConfigPointers    = NULL;
 static KdKeyboardDriver *kdKeyboardDrivers = NULL;
 static KdPointerDriver  *kdPointerDrivers  = NULL;
 
-static xEvent           *kdEvents = NULL;
+static EventListPtr     *kdEvents = NULL;
 
 static Bool		kdInputEnabled;
 static Bool		kdOffScreen;
@@ -1391,11 +1391,6 @@ KdInitInput (void)
             ErrorF("Failed to add keyboard!\n");
     }
 
-    if (!kdEvents)
-        kdEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!kdEvents)
-        FatalError("Couldn't allocate event buffer\n");
-
     mieqInit();
 }
 
@@ -1984,6 +1979,7 @@ KdReleaseAllKeys (void)
              key++) {
             if (IsKeyDown(ki, key)) {
                 KdHandleKeyboardEvent(ki, KeyRelease, key);
+                kdEvents = GetEventList();
                 nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key);
                 for (i = 0; i < nEvents; i++)
                     KdQueueEvent (ki->dixdev, kdEvents + i);
@@ -2048,9 +2044,10 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo   *ki,
             KdHandleKeyboardEvent(ki, type, key_code);
 	}
 	
+        kdEvents = GetEventList();
         nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code);
         for (i = 0; i < nEvents; i++)
-            KdQueueEvent(ki->dixdev, kdEvents + i);
+            KdQueueEvent(ki->dixdev, kdEvents);
     }
     else {
         ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n",
@@ -2148,8 +2145,9 @@ _KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z,
     if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel))
         return;
 
-    nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel, 0, 3,
-                               valuators);
+    kdEvents = GetEventList();
+    nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel,
+                               0, 3, valuators);
     for (i = 0; i < nEvents; i++)
         KdQueueEvent(pi->dixdev, kdEvents + i);
 }
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index f99e540..a928b4c 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -569,11 +569,7 @@ xf86PostMotionEventP(DeviceIntPtr	device,
     }
 #endif
 
-    if (!xf86Events)
-        xf86Events = InitEventList(GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
-
+    xf86Events = GetEventList();
     nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
                                flags, first_valuator, num_valuators,
                                valuators);
@@ -605,11 +601,7 @@ xf86PostProximityEvent(DeviceIntPtr	device,
         valuators[i] = va_arg(var, int);
     va_end(var);
 
-    if (!xf86Events)
-        xf86Events = InitEventList(GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
-
+    xf86Events = GetEventList();
     nevents = GetProximityEvents(xf86Events, device,
                                  is_in ? ProximityIn : ProximityOut, 
                                  first_valuator, num_valuators, valuators);
@@ -647,11 +639,7 @@ xf86PostButtonEvent(DeviceIntPtr	device,
         valuators[i] = va_arg(var, int);
     va_end(var);
 
-    if (!xf86Events)
-        xf86Events = InitEventList(GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
-
+    xf86Events = GetEventList();
     nevents = GetPointerEvents(xf86Events, device,
                                is_down ? ButtonPress : ButtonRelease, button,
                                (is_absolute) ? POINTER_ABSOLUTE : POINTER_RELATIVE,
@@ -680,11 +668,6 @@ xf86PostKeyEvent(DeviceIntPtr	device,
            "badly south after this message, then xf86PostKeyEvent is "
            "broken.\n");
 
-    if (!xf86Events)
-        xf86Events = InitEventList(GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
-
     if (is_absolute) {
         valuators = xcalloc(sizeof(int), num_valuators);
         va_start(var, num_valuators);
@@ -692,6 +675,7 @@ xf86PostKeyEvent(DeviceIntPtr	device,
             valuators[i] = va_arg(var, int);
         va_end(var);
 
+        xf86Events = GetEventList();
         nevents = GetKeyboardValuatorEvents(xf86Events, device,
                                             is_down ? KeyPress : KeyRelease,
                                             key_code, first_valuator,
@@ -726,11 +710,7 @@ xf86PostKeyboardEvent(DeviceIntPtr      device,
     }
 #endif
 
-    if (!xf86Events)
-        xf86Events = InitEventList(GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
-
+    xf86Events = GetEventList();
     nevents = GetKeyboardEvents(xf86Events, device,
                                 is_down ? KeyPress : KeyRelease, key_code);
 
diff --git a/include/input.h b/include/input.h
index 1863676..fb24e76 100644
--- a/include/input.h
+++ b/include/input.h
@@ -94,6 +94,8 @@ typedef struct _EventList {
                   ((xGenericEvent*)event)->length * 4 for GenericEvents */
 } EventList, *EventListPtr;
 
+/* The DIX stores incoming input events in this list */
+extern EventListPtr InputEventList;
 
 typedef int (*DeviceProc)(
     DeviceIntPtr /*device*/,
@@ -396,6 +398,7 @@ extern void InitInput(
 
 extern int GetMaximumEventsNum(void);
 
+extern EventListPtr GetEventList();
 extern EventListPtr InitEventList(int num_events);
 extern void FreeEventList(EventListPtr list, int num_events);
 
commit 09a8fc5c7a79ca22fc23224bb544f2e709681f3f
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Feb 3 07:47:18 2008 +1030

    Xi: make SizeDeviceInfo public and re-use from CreateClassesChangedEvent.

diff --git a/Xi/listdev.c b/Xi/listdev.c
index 4aa2688..50f34e4 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -92,7 +92,7 @@ SProcXListInputDevices(ClientPtr client)
  *
  */
 
-static void
+_X_EXPORT void
 SizeDeviceInfo(DeviceIntPtr d, int *namesize, int *size)
 {
     int chunks;
diff --git a/Xi/listdev.h b/Xi/listdev.h
index 22a0d91..39ea2d6 100644
--- a/Xi/listdev.h
+++ b/Xi/listdev.h
@@ -49,4 +49,9 @@ CopySwapClasses(ClientPtr /* client */,
                 CARD8* /* num_classes */,
                 char** /* classbuf */);
 
+void
+SizeDeviceInfo(DeviceIntPtr /* dev */,
+               int* /* namesize */,
+               int* /* size */);
+
 #endif /* LISTDEV_H */
diff --git a/dix/getevents.c b/dix/getevents.c
index 1f8f0e0..840fa2b 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -113,6 +113,7 @@ CreateClassesChangedEvent(EventList* event,
     deviceClassesChangedEvent *dcce;
     int len = sizeof(xEvent);
     CARD32 ms = GetTimeInMillis();
+    int namelen = 0; /* dummy */
 
     /* XXX: ok, this is a bit weird. We need to alloc enough size for the
      * event so it can be filled in in POE lateron. Reason being that if
@@ -120,19 +121,9 @@ CreateClassesChangedEvent(EventList* event,
      * or realloc the original pointer.
      * We can only do it here as we don't have the EventList in the event
      * processing any more.
-     *
-     * Code is basically same as in Xi/listdev.c
      */
-    if (slave->key)
-        len += sizeof(xKeyInfo);
-    if (slave->button)
-        len += sizeof(xButtonInfo);
-    if (slave->valuator)
-    {
-        int chunks = ((int)slave->valuator->numAxes + 19) / VPC;
-        len += (chunks * sizeof(xValuatorInfo) +
-                slave->valuator->numAxes * sizeof(xAxisInfo));
-    }
+    SizeDeviceInfo(slave, &namelen, &len);
+
     if (event->evlen < len)
     {
         event->event = realloc(event->event, len);


More information about the xorg-commit mailing list