xserver: Branch 'master' - 31 commits

Keith Packard keithp at kemper.freedesktop.org
Wed Dec 14 11:42:18 PST 2011


 Xi/exevents.c                           |  147 ++---
 Xi/grabdev.c                            |    2 
 Xi/grabdevb.c                           |    4 
 Xi/grabdevk.c                           |    4 
 Xi/ungrdev.c                            |    2 
 Xi/ungrdevb.c                           |    2 
 Xi/ungrdevk.c                           |    2 
 Xi/xigrabdev.c                          |    4 
 Xi/xipassivegrab.c                      |    8 
 dix/devices.c                           |    1 
 dix/eventconvert.c                      |   16 
 dix/events.c                            |  812 +++++++++++++++++---------------
 dix/extension.c                         |    3 
 dix/getevents.c                         |   38 +
 dix/grabs.c                             |   82 ++-
 dix/inpututils.c                        |   60 ++
 dix/tables.c                            |    2 
 hw/xfree86/common/xf86DGA.c             |    4 
 include/dix.h                           |    5 
 include/dixgrabs.h                      |    4 
 include/eventconvert.h                  |    7 
 include/exevents.h                      |    6 
 include/input.h                         |   20 
 include/inputstr.h                      |   10 
 include/inpututils.h                    |    6 
 include/misc.h                          |    2 
 test/input.c                            |  130 ++---
 test/xi2/protocol-eventconvert.c        |    6 
 test/xi2/protocol-xipassivegrabdevice.c |    4 
 29 files changed, 801 insertions(+), 592 deletions(-)

New commits:
commit 7da7aa96a0acb895e1fe57a9d3f2d093479cf2a2
Merge: b79de3f... 7528a6b...
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 14 11:40:10 2011 -0800

    Merge remote-tracking branch 'whot/for-keith'

commit 7528a6b88eb32098af4369a8bd9d70a808fa6f1c
Merge: f0de5e3... 898d976...
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 13 14:19:54 2011 +1000

    Merge branch 'for-whot' of git://people.freedesktop.org/~alanc/xserver into for-keith

diff --cc dix/grabs.c
index 6f8b39e,3286eb7..da014df
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@@ -60,8 -60,8 +60,9 @@@ SOFTWARE
  #include "dixgrabs.h"
  #include "xace.h"
  #include "exevents.h"
 +#include "exglobals.h"
  #include "inpututils.h"
+ #include "client.h"
  
  #define BITMASK(i) (((Mask)1) << ((i) & 31))
  #define MASKIDX(i) ((i) >> 5)
@@@ -78,11 -78,12 +79,12 @@@ PrintDeviceGrabInfo(DeviceIntPtr dev
      int i, j;
      GrabInfoPtr devGrab = &dev->deviceGrab;
      GrabPtr grab = devGrab->grab;
+     Bool clientIdPrinted = FALSE;
  
-     ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):",
+     ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):\n",
             (unsigned long) grab->resource,
 -           (grab->grabtype == GRABTYPE_XI2) ? "xi2" :
 -            ((grab->grabtype == GRABTYPE_CORE) ? "core" : "xi1"),
 +           (grab->grabtype == XI2) ? "xi2" :
 +            ((grab->grabtype == CORE) ? "core" : "xi1"),
             dev->name, dev->id);
  
      client = clients[CLIENT_ID(grab->resource)];
commit f0de5e3990b70df9899b7dd17d7ee6ff7c768183
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Sun Dec 11 07:31:43 2011 +1000

    dix: add a MAXEVENTS define for the number of core + extension events
    
    Not including GenericEvents
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Walter Harms <wharms at bfs.de>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 357b8d1..6538139 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -367,9 +367,9 @@ extern int DeviceMotionNotify;
  * time a button is pressed, the filter is modified to also contain the
  * matching ButtonXMotion mask.
  */
-Mask event_filters[MAXDEVICES][128];
+Mask event_filters[MAXDEVICES][MAXEVENTS];
 
-static const Mask default_filter[128] =
+static const Mask default_filter[MAXEVENTS] =
 {
 	NoSuchEvent,		       /* 0 */
 	NoSuchEvent,		       /* 1 */
@@ -673,7 +673,7 @@ SetMaskForEvent(int deviceid, Mask mask, int event)
 void
 SetCriticalEvent(int event)
 {
-    if (event >= 128)
+    if (event >= MAXEVENTS)
 	FatalError("SetCriticalEvent: bogus event number");
     criticalEvents[event >> 3] |= 1 << (event & 7);
 }
diff --git a/dix/extension.c b/dix/extension.c
index cc516b6..af9ba31 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include "registry.h"
 #include "xace.h"
 
-#define LAST_EVENT  128
 #define LAST_ERROR 255
 
 static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
@@ -82,7 +81,7 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
 
     if (!MainProc || !SwappedMainProc || !MinorOpcodeProc)
         return((ExtensionEntry *) NULL);
-    if ((lastEvent + NumEvents > LAST_EVENT) || 
+    if ((lastEvent + NumEvents > MAXEVENTS) || 
 	        (unsigned)(lastError + NumErrors > LAST_ERROR)) {
         LogMessage(X_ERROR, "Not enabling extension %s: maximum number of "
                    "events or errors exceeded.\n", name);
diff --git a/dix/tables.c b/dix/tables.c
index 5bd9ea0..45ae2a9 100644
--- a/dix/tables.c
+++ b/dix/tables.c
@@ -592,7 +592,7 @@ int (* SwappedProcVector[256]) (
     ProcBadRequest
 };
 
-EventSwapPtr EventSwapVector[128] =
+EventSwapPtr EventSwapVector[MAXEVENTS] =
 {
     (EventSwapPtr)SErrorEvent,
     NotImplemented,
diff --git a/include/inpututils.h b/include/inpututils.h
index 5aa60c2..9e22c5a 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -32,7 +32,7 @@
 #include "input.h"
 #include <X11/extensions/XI2proto.h>
 
-extern Mask filters[MAXDEVICES][128];
+extern Mask event_filters[MAXDEVICES][MAXEVENTS];
 
 struct _ValuatorMask {
     int8_t      last_bit; /* highest bit set in mask */
diff --git a/include/misc.h b/include/misc.h
index d9811ca..09f928a 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -89,6 +89,8 @@ OF THIS SOFTWARE.
 #define MAXFORMATS	8
 #define MAXDEVICES	40 /* input devices */
 
+/* 128 event opcodes for core + extension events, excluding GE */
+#define MAXEVENTS       128
 #define EXTENSION_EVENT_BASE 64
 #define EXTENSION_BASE 128
 
commit adf8a0d62c0643f4c44a3b6d2e3c6c9b02532915
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 9 18:38:53 2011 +1000

    dix: move event filter retrieval helpers to inpututils.c
    
    No functional changes
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index e98f7b2..357b8d1 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -367,7 +367,7 @@ extern int DeviceMotionNotify;
  * time a button is pressed, the filter is modified to also contain the
  * matching ButtonXMotion mask.
  */
-static Mask filters[MAXDEVICES][128];
+Mask event_filters[MAXDEVICES][128];
 
 static const Mask default_filter[128] =
 {
@@ -408,18 +408,6 @@ static const Mask default_filter[128] =
 	CantBeFiltered		       /* MappingNotify */
 };
 
-static inline Mask
-GetEventFilterMask(DeviceIntPtr dev, int evtype)
-{
-    return filters[dev ? dev->id : 0][evtype];
-}
-
-inline Mask
-GetXI2EventFilterMask(int evtype)
-{
-    return (1 << (evtype % 8));
-}
-
 /**
  * For the given event, return the matching event filter. This filter may then
  * be AND'ed with the selected event mask.
@@ -441,9 +429,9 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
     int evtype = 0;
 
     if (event->u.u.type != GenericEvent)
-        return GetEventFilterMask(dev, event->u.u.type);
+        return event_get_filter_from_type(dev, event->u.u.type);
     else if ((evtype = xi2_get_type(event)))
-        return GetXI2EventFilterMask(evtype);
+        return event_get_filter_from_xi2type(evtype);
     ErrorF("[dix] Unknown event type %d. No filter\n", event->u.u.type);
     return 0;
 }
@@ -459,7 +447,7 @@ GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type)
      * for this mask anyway.
      */
     if (xi2mask_isset(mask, dev, event_type))
-        return GetXI2EventFilterMask(event_type);
+        return event_get_filter_from_xi2type(event_type);
     else
         return 0;
 }
@@ -679,7 +667,7 @@ SetMaskForEvent(int deviceid, Mask mask, int event)
 {
     if (deviceid < 0 || deviceid >= MAXDEVICES)
         FatalError("SetMaskForEvent: bogus device id");
-    filters[deviceid][event] = mask;
+    event_filters[deviceid][event] = mask;
 }
 
 void
@@ -2554,7 +2542,7 @@ EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win)
 
     if ((type = GetXIType(evtype)) != 0)
     {
-        filter = GetEventFilterMask(dev, type);
+        filter = event_get_filter_from_type(dev, type);
 
         /* Check for XI mask */
         if (inputMasks &&
@@ -2570,7 +2558,7 @@ EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win)
 
     if ((type = GetCoreType(evtype)) != 0)
     {
-        filter = GetEventFilterMask(dev, type);
+        filter = event_get_filter_from_type(dev, type);
 
         /* Check for core mask */
         if ((win->deliverableEvents & filter) &&
@@ -5350,7 +5338,7 @@ InitEvents(void)
     inputInfo.pointer = (DeviceIntPtr)NULL;
     for (i = 0; i < MAXDEVICES; i++)
     {
-        memcpy(&filters[i], default_filter, sizeof(default_filter));
+        memcpy(&event_filters[i], default_filter, sizeof(default_filter));
     }
 
     syncEvents.replayDev = (DeviceIntPtr)NULL;
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 5844daf..9232bdc 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -695,6 +695,25 @@ void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event)
     }
 }
 
+/**
+ * Return the event filter mask for the given device and the given core or
+ * XI1 protocol type.
+ */
+Mask
+event_get_filter_from_type(DeviceIntPtr dev, int evtype)
+{
+    return event_filters[dev ? dev->id : 0][evtype];
+}
+
+/**
+ * Return the event filter mask for the given device and the given core or
+ * XI2 protocol type.
+ */
+Mask
+event_get_filter_from_xi2type(int evtype)
+{
+    return (1 << (evtype % 8));
+}
 
 Bool
 point_on_screen(ScreenPtr pScreen, int x, int y)
diff --git a/include/input.h b/include/input.h
index fb24fd5..bd12f68 100644
--- a/include/input.h
+++ b/include/input.h
@@ -544,7 +544,6 @@ extern _X_EXPORT void FreeInputAttributes(InputAttributes *attrs);
 extern Mask GetEventMask(DeviceIntPtr dev, xEvent* ev, InputClientsPtr clients);
 extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);
 extern Bool WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev);
-extern Mask GetXI2EventFilterMask(int evtype);
 extern int GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type);
 void FixUpEventFromWindow(SpritePtr pSprite,
                           xEvent *xE,
diff --git a/include/inpututils.h b/include/inpututils.h
index 96ad6df..5aa60c2 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -32,6 +32,8 @@
 #include "input.h"
 #include <X11/extensions/XI2proto.h>
 
+extern Mask filters[MAXDEVICES][128];
+
 struct _ValuatorMask {
     int8_t      last_bit; /* highest bit set in mask */
     uint8_t     mask[(MAX_VALUATORS + 7)/8];
@@ -42,6 +44,8 @@ extern void verify_internal_event(const InternalEvent *ev);
 extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
 extern int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd);
 extern void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event);
+extern Mask event_get_filter_from_type(DeviceIntPtr dev, int evtype);
+extern Mask event_get_filter_from_xi2type(int evtype);
 
 FP3232 double_to_fp3232(double in);
 FP1616 double_to_fp1616(double in);
commit a03fe819506fbcbfcb299d4919d16061603fd4ec
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 9 18:02:49 2011 +1000

    dix: switch EventIsDeliverable to take the event type only
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 086f438..e98f7b2 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2532,27 +2532,27 @@ FixUpEventFromWindow(
  * client.
  *
  * @param[in] dev The device this event is being sent for.
- * @param[in] event The event that is to be sent.
+ * @param[in] evtype The event type of the event that is to be sent.
  * @param[in] win The current event window.
  *
  * @return Bitmask of ::EVENT_XI2_MASK, ::EVENT_XI1_MASK, ::EVENT_CORE_MASK, and
  *         ::EVENT_DONT_PROPAGATE_MASK.
  */
 int
-EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
+EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win)
 {
     int rc = 0;
     int filter = 0;
     int type;
     OtherInputMasks *inputMasks = wOtherInputMasks(win);
 
-    if ((type = GetXI2Type(event->any.type)) != 0)
+    if ((type = GetXI2Type(evtype)) != 0)
     {
         if (inputMasks && xi2mask_isset(inputMasks->xi2mask, dev, type))
             rc |= EVENT_XI2_MASK;
     }
 
-    if ((type = GetXIType(event->any.type)) != 0)
+    if ((type = GetXIType(evtype)) != 0)
     {
         filter = GetEventFilterMask(dev, type);
 
@@ -2568,7 +2568,7 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
 
     }
 
-    if ((type = GetCoreType(event->any.type)) != 0)
+    if ((type = GetCoreType(evtype)) != 0)
     {
         filter = GetEventFilterMask(dev, type);
 
@@ -2667,7 +2667,7 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
 
     while (pWin)
     {
-        if ((mask = EventIsDeliverable(dev, event, pWin)))
+        if ((mask = EventIsDeliverable(dev, event->any.type, pWin)))
         {
             /* XI2 events first */
             if (mask & EVENT_XI2_MASK)
diff --git a/include/input.h b/include/input.h
index 7c5ad3c..fb24fd5 100644
--- a/include/input.h
+++ b/include/input.h
@@ -552,8 +552,7 @@ void FixUpEventFromWindow(SpritePtr pSprite,
                           Window child,
                           Bool calcChild);
 extern WindowPtr XYToWindow(SpritePtr pSprite, int x, int y);
-extern int EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event,
-                              WindowPtr win);
+extern int EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win);
 extern Bool ActivatePassiveGrab(DeviceIntPtr dev, GrabPtr grab,
                                 InternalEvent *ev);
 /**
commit 10a8c428fac0d4ff8f8a3e3487c13dd349d27ed7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 9 15:49:04 2011 +1000

    dix: move storing last.valuators into a helper function
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/getevents.c b/dix/getevents.c
index 8798f64..57d8c17 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1094,6 +1094,30 @@ transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
         valuator_mask_set_double(mask, 1, y);
 }
 
+static void
+storeLastValuators(DeviceIntPtr dev, ValuatorMask *mask,
+                   int xaxis, int yaxis,
+                   double devx, double devy)
+{
+    int i;
+
+    /* store desktop-wide in last.valuators */
+    if (valuator_mask_isset(mask, xaxis))
+        dev->last.valuators[0] = devx;
+    if (valuator_mask_isset(mask, yaxis))
+        dev->last.valuators[1] = devy;
+
+    for (i = 0; i < valuator_mask_size(mask); i++)
+    {
+        if (i == xaxis || i == yaxis)
+            continue;
+
+        if (valuator_mask_isset(mask, i))
+            dev->last.valuators[i] = valuator_mask_get_double(mask, i);
+    }
+
+}
+
 /**
  * Generate internal events representing this pointer event and enqueue them
  * on the event queue.
@@ -1162,7 +1186,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
                     int buttons, CARD32 ms, int flags,
                     const ValuatorMask *mask_in)
 {
-    int num_events = 1, i;
+    int num_events = 1;
     DeviceEvent *event;
     RawDeviceEvent *raw;
     double screenx = 0.0, screeny = 0.0; /* desktop coordinate system */
@@ -1237,17 +1261,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
 
     clipValuators(pDev, &mask);
 
-    /* store desktop-wide in last.valuators */
-    if (valuator_mask_isset(&mask, 0))
-        pDev->last.valuators[0] = devx;
-    if (valuator_mask_isset(&mask, 1))
-        pDev->last.valuators[1] = devy;
-
-    for (i = 2; i < valuator_mask_size(&mask); i++)
-    {
-        if (valuator_mask_isset(&mask, i))
-            pDev->last.valuators[i] = valuator_mask_get_double(&mask, i);
-    }
+    storeLastValuators(pDev, &mask, 0, 1, devx, devy);
 
     /* Update the MD's co-ordinates, which are always in desktop space. */
     if (!IsMaster(pDev) || !IsFloating(pDev)) {
commit a15abf82ddb5a209dbc30c4d12e1dc23c4adf3e4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 8 15:38:44 2011 +1000

    dix: always allocate and set the grab's sync.event
    
    Allocate the memory at device creation time and always store the event, even
    if we're not frozen. This way we know which event triggered the grab.
    Since the event was never freed anyway except on device shutdown, this
    doesn't really change things much.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index e448eab..9ca8fe0 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -275,6 +275,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     dev->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
     dev->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
     dev->deviceGrab.activeGrab = AllocGrab();
+    dev->deviceGrab.sync.event = calloc(1, sizeof(DeviceEvent));
 
     XkbSetExtension(dev, ProcessKeyboardEvent);
 
diff --git a/dix/events.c b/dix/events.c
index db86f51..086f438 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3717,12 +3717,8 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
     }
 
     if (grabinfo->sync.state == FROZEN_NO_EVENT)
-    {
-        if (!grabinfo->sync.event)
-            grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
-        *grabinfo->sync.event = event->device_event;
         grabinfo->sync.state = FROZEN_WITH_EVENT;
-    }
+    *grabinfo->sync.event = event->device_event;
 
     free(xE);
     return TRUE;
@@ -4310,8 +4306,6 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
 	case FREEZE_NEXT_EVENT:
 	    grabinfo->sync.state = FROZEN_WITH_EVENT;
 	    FreezeThaw(thisDev, TRUE);
-	    if (!grabinfo->sync.event)
-		grabinfo->sync.event = calloc(1, sizeof(InternalEvent));
 	    *grabinfo->sync.event = event->device_event;
 	    break;
 	}
commit 218752bdc5d9323d1e6202e762573a925cf8a4eb
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 8 14:27:01 2011 +1000

    input: replace GRABTYPE_* with the InputLevel enums
    
    They achieve the same thing, re-use the more generic InputLevel so we can
    convert to/fro easier.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 405a8b1..45a289a 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1389,9 +1389,9 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
 int
 CheckGrabValues(ClientPtr client, GrabParameters* param)
 {
-    if (param->grabtype != GRABTYPE_CORE &&
-        param->grabtype != GRABTYPE_XI &&
-        param->grabtype != GRABTYPE_XI2)
+    if (param->grabtype != CORE &&
+        param->grabtype != XI &&
+        param->grabtype != XI2)
     {
         ErrorF("[Xi] grabtype is invalid. This is a bug.\n");
         return BadImplementation;
@@ -1408,7 +1408,7 @@ CheckGrabValues(ClientPtr client, GrabParameters* param)
 	return BadValue;
     }
 
-    if (param->grabtype != GRABTYPE_XI2 && (param->modifiers != AnyModifier) &&
+    if (param->grabtype != XI2 && (param->modifiers != AnyModifier) &&
         (param->modifiers & ~AllModifiersMask)) {
 	client->errorValue = param->modifiers;
 	return BadValue;
@@ -1423,7 +1423,7 @@ CheckGrabValues(ClientPtr client, GrabParameters* param)
 
 int
 GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
-           int button, GrabParameters *param, GrabType grabtype,
+           int button, GrabParameters *param, enum InputLevel grabtype,
 	   GrabMask *mask)
 {
     WindowPtr pWin, confineTo;
@@ -1463,9 +1463,9 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
     if (rc != Success)
 	return rc;
 
-    if (grabtype == GRABTYPE_XI)
+    if (grabtype == XI)
         type = DeviceButtonPress;
-    else if (grabtype == GRABTYPE_XI2)
+    else if (grabtype == XI2)
         type = XI_ButtonPress;
 
     grab = CreateGrab(client->index, dev, modifier_device, pWin, grabtype,
@@ -1476,12 +1476,12 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
 }
 
 /**
- * Grab the given key. If grabtype is GRABTYPE_XI, the key is a keycode. If
- * grabtype is GRABTYPE_XI2, the key is a keysym.
+ * Grab the given key. If grabtype is XI, the key is a keycode. If
+ * grabtype is XI2, the key is a keysym.
  */
 int
 GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
-        int key, GrabParameters *param, GrabType grabtype, GrabMask *mask)
+        int key, GrabParameters *param, enum InputLevel grabtype, GrabMask *mask)
 {
     WindowPtr pWin;
     GrabPtr grab;
@@ -1494,7 +1494,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
         return rc;
     if ((dev->id != XIAllDevices && dev->id != XIAllMasterDevices) && k == NULL)
 	return BadMatch;
-    if (grabtype == GRABTYPE_XI)
+    if (grabtype == XI)
     {
         if ((key > k->xkbInfo->desc->max_key_code ||
                     key < k->xkbInfo->desc->min_key_code)
@@ -1503,7 +1503,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
             return BadValue;
         }
         type = DeviceKeyPress;
-    } else if (grabtype == GRABTYPE_XI2)
+    } else if (grabtype == XI2)
         type = XI_KeyPress;
 
     rc = dixLookupWindow(&pWin, param->grabWindow, client, DixSetAttrAccess);
@@ -1558,7 +1558,7 @@ GrabWindow(ClientPtr client, DeviceIntPtr dev, int type,
     if (rc != Success)
 	return rc;
 
-    grab = CreateGrab(client->index, dev, dev, pWin, GRABTYPE_XI2,
+    grab = CreateGrab(client->index, dev, dev, pWin, XI2,
                       mask, param, (type == XIGrabtypeEnter) ? XI_Enter : XI_FocusIn,
                       0, NULL, cursor);
 
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index 4572c33..8fd114e 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -130,7 +130,7 @@ ProcXGrabDevice(ClientPtr client)
     rc = GrabDevice(client, dev, stuff->other_devices_mode,
                     stuff->this_device_mode, stuff->grabWindow,
 		    stuff->ownerEvents, stuff->time,
-		    &mask, GRABTYPE_XI, None, None,
+		    &mask, XI, None, None,
 		    &rep.status);
 
     if (rc != Success)
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 2897d41..dda0da8 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -137,7 +137,7 @@ ProcXGrabDeviceButton(ClientPtr client)
 	return ret;
 
     memset(&param, 0, sizeof(param));
-    param.grabtype = GRABTYPE_XI;
+    param.grabtype = XI;
     param.ownerEvents = stuff->ownerEvents;
     param.this_device_mode = stuff->this_device_mode;
     param.other_devices_mode = stuff->other_devices_mode;
@@ -146,7 +146,7 @@ ProcXGrabDeviceButton(ClientPtr client)
     mask.xi = tmp[stuff->grabbed_device].mask;
 
     ret = GrabButton(client, dev, mdev, stuff->button, &param,
-                     GRABTYPE_XI, &mask);
+                     XI, &mask);
 
     return ret;
 }
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index cedd90d..61ab43a 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -135,7 +135,7 @@ ProcXGrabDeviceKey(ClientPtr client)
 
 
     memset(&param, 0, sizeof(param));
-    param.grabtype = GRABTYPE_XI;
+    param.grabtype = XI;
     param.ownerEvents = stuff->ownerEvents;
     param.this_device_mode = stuff->this_device_mode;
     param.other_devices_mode = stuff->other_devices_mode;
@@ -143,7 +143,7 @@ ProcXGrabDeviceKey(ClientPtr client)
     param.modifiers = stuff->modifiers;
     mask.xi = tmp[stuff->grabbed_device].mask;
 
-    ret = GrabKey(client, dev, mdev, stuff->key, &param, GRABTYPE_XI, &mask);
+    ret = GrabKey(client, dev, mdev, stuff->key, &param, XI, &mask);
 
     return ret;
 }
diff --git a/Xi/ungrdev.c b/Xi/ungrdev.c
index bc66cfc..58c1f57 100644
--- a/Xi/ungrdev.c
+++ b/Xi/ungrdev.c
@@ -102,7 +102,7 @@ ProcXUngrabDevice(ClientPtr client)
     time = ClientTimeToServerTime(stuff->time);
     if ((CompareTimeStamps(time, currentTime) != LATER) &&
 	(CompareTimeStamps(time, dev->deviceGrab.grabTime) != EARLIER) &&
-	(grab) && SameClient(grab, client) && grab->grabtype == GRABTYPE_XI)
+	(grab) && SameClient(grab, client) && grab->grabtype == XI)
 	(*dev->deviceGrab.DeactivateGrab) (dev);
     return Success;
 }
diff --git a/Xi/ungrdevb.c b/Xi/ungrdevb.c
index 6280248..0ba395c 100644
--- a/Xi/ungrdevb.c
+++ b/Xi/ungrdevb.c
@@ -134,7 +134,7 @@ ProcXUngrabDeviceButton(ClientPtr client)
     temporaryGrab->device = dev;
     temporaryGrab->window = pWin;
     temporaryGrab->type = DeviceButtonPress;
-    temporaryGrab->grabtype = GRABTYPE_XI;
+    temporaryGrab->grabtype = XI;
     temporaryGrab->modifierDevice = mdev;
     temporaryGrab->modifiersDetail.exact = stuff->modifiers;
     temporaryGrab->modifiersDetail.pMask = NULL;
diff --git a/Xi/ungrdevk.c b/Xi/ungrdevk.c
index b0d83cb..8785989 100644
--- a/Xi/ungrdevk.c
+++ b/Xi/ungrdevk.c
@@ -141,7 +141,7 @@ ProcXUngrabDeviceKey(ClientPtr client)
     temporaryGrab->device = dev;
     temporaryGrab->window = pWin;
     temporaryGrab->type = DeviceKeyPress;
-    temporaryGrab->grabtype = GRABTYPE_XI;
+    temporaryGrab->grabtype = XI;
     temporaryGrab->modifierDevice = mdev;
     temporaryGrab->modifiersDetail.exact = stuff->modifiers;
     temporaryGrab->modifiersDetail.pMask = NULL;
diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
index 1cfbf24..2b30550 100644
--- a/Xi/xigrabdev.c
+++ b/Xi/xigrabdev.c
@@ -96,7 +96,7 @@ ProcXIGrabDevice(ClientPtr client)
                      stuff->owner_events,
                      stuff->time,
                      &mask,
-                     GRABTYPE_XI2,
+                     XI2,
                      stuff->cursor,
                      None /* confineTo */,
                      &status);
@@ -148,7 +148,7 @@ ProcXIUngrabDevice(ClientPtr client)
     time = ClientTimeToServerTime(stuff->time);
     if ((CompareTimeStamps(time, currentTime) != LATER) &&
 	(CompareTimeStamps(time, dev->deviceGrab.grabTime) != EARLIER) &&
-	(grab) && SameClient(grab, client) && grab->grabtype == GRABTYPE_XI2)
+	(grab) && SameClient(grab, client) && grab->grabtype == XI2)
 	(*dev->deviceGrab.DeactivateGrab) (dev);
 
     return Success;
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 4860757..713a165 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -139,7 +139,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     rep.num_modifiers = 0;
 
     memset(&param, 0, sizeof(param));
-    param.grabtype = GRABTYPE_XI2;
+    param.grabtype = XI2;
     param.ownerEvents = stuff->owner_events;
     param.this_device_mode = stuff->grab_mode;
     param.other_devices_mode = stuff->paired_device_mode;
@@ -183,11 +183,11 @@ ProcXIPassiveGrabDevice(ClientPtr client)
         {
             case XIGrabtypeButton:
                 status = GrabButton(client, dev, mod_dev, stuff->detail,
-                                    &param, GRABTYPE_XI2, &mask);
+                                    &param, XI2, &mask);
                 break;
             case XIGrabtypeKeycode:
                 status = GrabKey(client, dev, mod_dev, stuff->detail,
-                                 &param, GRABTYPE_XI2, &mask);
+                                 &param, XI2, &mask);
                 break;
             case XIGrabtypeEnter:
             case XIGrabtypeFocusIn:
@@ -313,7 +313,7 @@ ProcXIPassiveUngrabDevice(ClientPtr client)
         case XIGrabtypeEnter:   tempGrab->type = XI_Enter;       break;
         case XIGrabtypeFocusIn: tempGrab->type = XI_FocusIn;     break;
     }
-    tempGrab->grabtype = GRABTYPE_XI2;
+    tempGrab->grabtype = XI2;
     tempGrab->modifierDevice = mod_dev;
     tempGrab->modifiersDetail.pMask = NULL;
     tempGrab->detail.exact = stuff->detail;
diff --git a/dix/events.c b/dix/events.c
index 9703ca9..db86f51 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1484,7 +1484,7 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab,
     Bool isPassive = autoGrab & ~ImplicitGrabMask;
 
     /* slave devices need to float for the duration of the grab. */
-    if (grab->grabtype == GRABTYPE_XI2 &&
+    if (grab->grabtype == XI2 &&
         !(autoGrab & ImplicitGrabMask) && !IsMaster(mouse))
         DetachFromMaster(mouse);
 
@@ -1543,7 +1543,7 @@ DeactivatePointerGrab(DeviceIntPtr mouse)
     if (grab->cursor)
 	FreeCursor(grab->cursor, (Cursor)0);
 
-    if (!wasImplicit && grab->grabtype == GRABTYPE_XI2)
+    if (!wasImplicit && grab->grabtype == XI2)
         ReattachToOldMaster(mouse);
 
     ComputeFreezes();
@@ -1561,7 +1561,7 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool pass
     WindowPtr oldWin;
 
     /* slave devices need to float for the duration of the grab. */
-    if (grab->grabtype == GRABTYPE_XI2 &&
+    if (grab->grabtype == XI2 &&
         !(passive & ImplicitGrabMask) &&
         !IsMaster(keybd))
         DetachFromMaster(keybd);
@@ -1616,7 +1616,7 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd)
     }
     DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab);
 
-    if (!wasImplicit && grab->grabtype == GRABTYPE_XI2)
+    if (!wasImplicit && grab->grabtype == XI2)
         ReattachToOldMaster(keybd);
 
     ComputeFreezes();
@@ -1974,14 +1974,14 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
     GrabPtr tempGrab;
     OtherInputMasks *inputMasks;
     CARD8 type = event->u.u.type;
-    GrabType grabtype;
+    enum InputLevel grabtype;
 
     if (type == ButtonPress)
-        grabtype = GRABTYPE_CORE;
+        grabtype = CORE;
     else if (type == DeviceButtonPress)
-        grabtype = GRABTYPE_XI;
+        grabtype = XI;
     else if ((type = xi2_get_type(event)) == XI_ButtonPress)
-        grabtype = GRABTYPE_XI2;
+        grabtype = XI2;
     else
         return FALSE;
 
@@ -3656,13 +3656,13 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
 
     /* The only consumers of corestate are Xi 1.x and core events, which
      * are guaranteed to come from DeviceEvents. */
-    if (grab->grabtype == GRABTYPE_XI || grab->grabtype == GRABTYPE_CORE)
+    if (grab->grabtype == XI || grab->grabtype == CORE)
     {
         DeviceIntPtr gdev;
 
         event->device_event.corestate &= 0x1f00;
 
-        if (grab->grabtype == GRABTYPE_CORE)
+        if (grab->grabtype == CORE)
             gdev = GetMaster(device, KEYBOARD_OR_FLOAT);
         else
             gdev = grab->modifierDevice;
@@ -3672,7 +3672,7 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
                 gdev->key->xkbInfo->state.grab_mods & (~0x1f00);
     }
 
-    if (grab->grabtype == GRABTYPE_CORE)
+    if (grab->grabtype == CORE)
     {
         rc = EventToCore(event, &xE, &count);
         if (rc != Success)
@@ -3681,7 +3681,7 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
                          "(%d, %d).\n", device->name, event->any.type, rc);
             return FALSE;
         }
-    } else if (grab->grabtype == GRABTYPE_XI2)
+    } else if (grab->grabtype == XI2)
     {
         rc = EventToXI2(event, &xE);
         if (rc != Success)
@@ -3737,7 +3737,7 @@ CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab)
     for (other = inputInfo.devices; other; other = other->next)
     {
         GrabPtr othergrab = other->deviceGrab.grab;
-        if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
+        if (othergrab && othergrab->grabtype == CORE &&
                 SameClient(grab, rClient(othergrab)) &&
                 ((IsPointerDevice(grab->device) &&
                   IsPointerDevice(othergrab->device)) ||
@@ -3781,18 +3781,18 @@ MatchForType(const GrabPtr grab, GrabPtr tmp, enum InputLevel level, int event_t
     switch(level)
     {
         case XI2:
-            grabtype = GRABTYPE_XI2;
+            grabtype = XI2;
             evtype = GetXI2Type(event_type);
             BUG_WARN(!evtype);
             match = XI2_MATCH;
             break;
         case XI:
-            grabtype = GRABTYPE_XI;
+            grabtype = XI;
             evtype = GetXIType(event_type);
             match = XI_MATCH;
             break;
         case CORE:
-            grabtype = GRABTYPE_CORE;
+            grabtype = CORE;
             evtype = GetCoreType(event_type);
             match = CORE_MATCH;
             ignore_device = TRUE;
@@ -3830,10 +3830,10 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
     enum MatchFlags match = 0;
 
     gdev = grab->modifierDevice;
-    if (grab->grabtype == GRABTYPE_CORE)
+    if (grab->grabtype == CORE)
     {
         gdev = GetMaster(device, KEYBOARD_OR_FLOAT);
-    } else if (grab->grabtype == GRABTYPE_XI2)
+    } else if (grab->grabtype == XI2)
     {
         /* if the device is an attached slave device, gdev must be the
          * attached master keyboard. Since the slave may have been
@@ -3868,7 +3868,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
      * device.
      */
 
-    if (grab->grabtype == GRABTYPE_CORE)
+    if (grab->grabtype == CORE)
     {
         /* A passive grab may have been created for a different device
            than it is assigned to at this point in time.
@@ -4272,7 +4272,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
 
         sendCore = (IsMaster(thisDev) && thisDev->coreEvents);
         /* try core event */
-        if (sendCore && grab->grabtype == GRABTYPE_CORE)
+        if (sendCore && grab->grabtype == CORE)
         {
             deliveries = DeliverOneGrabbedEvent(event, thisDev, CORE);
         }
@@ -4970,7 +4970,7 @@ ProcGrabPointer(ClientPtr client)
 
     rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
                     stuff->grabWindow, stuff->ownerEvents, stuff->time,
-                    &mask, GRABTYPE_CORE, stuff->cursor,
+                    &mask, CORE, stuff->cursor,
                     stuff->confineTo, &rep.status);
     if (rc != Success)
         return rc;
@@ -5178,9 +5178,9 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
 	tempGrab->ownerEvents = ownerEvents;
 	tempGrab->keyboardMode = keyboard_mode;
 	tempGrab->pointerMode = pointer_mode;
-	if (grabtype == GRABTYPE_CORE)
+	if (grabtype == CORE)
 	    tempGrab->eventMask = mask->core;
-	else if (grabtype == GRABTYPE_XI)
+	else if (grabtype == XI)
 	    tempGrab->eventMask = mask->xi;
 	else
             xi2mask_merge(tempGrab->xi2mask, mask->xi2mask);
@@ -5217,7 +5217,7 @@ ProcGrabKeyboard(ClientPtr client)
 
     result = GrabDevice(client, keyboard, stuff->pointerMode,
             stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents,
-            stuff->time, &mask, GRABTYPE_CORE, None, None,
+            stuff->time, &mask, CORE, None, None,
             &rep.status);
 
     if (result != Success)
@@ -5250,7 +5250,7 @@ ProcUngrabKeyboard(ClientPtr client)
     time = ClientTimeToServerTime(stuff->id);
     if ((CompareTimeStamps(time, currentTime) != LATER) &&
 	(CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) &&
-	(grab) && SameClient(grab, client) && grab->grabtype == GRABTYPE_CORE)
+	(grab) && SameClient(grab, client) && grab->grabtype == CORE)
 	(*device->deviceGrab.DeactivateGrab)(device);
     return Success;
 }
@@ -5542,7 +5542,7 @@ ProcUngrabKey(ClientPtr client)
     tempGrab->modifiersDetail.pMask = NULL;
     tempGrab->modifierDevice = keybd;
     tempGrab->type = KeyPress;
-    tempGrab->grabtype = GRABTYPE_CORE;
+    tempGrab->grabtype = CORE;
     tempGrab->detail.exact = stuff->key;
     tempGrab->detail.pMask = NULL;
     tempGrab->next = NULL;
@@ -5575,7 +5575,7 @@ ProcGrabKey(ClientPtr client)
     REQUEST_SIZE_MATCH(xGrabKeyReq);
 
     memset(&param, 0, sizeof(param));
-    param.grabtype = GRABTYPE_CORE;
+    param.grabtype = CORE;
     param.ownerEvents = stuff->ownerEvents;
     param.this_device_mode = stuff->keyboardMode;
     param.other_devices_mode = stuff->pointerMode;
@@ -5599,7 +5599,7 @@ ProcGrabKey(ClientPtr client)
 
     mask.core = (KeyPressMask | KeyReleaseMask);
 
-    grab = CreateGrab(client->index, keybd, keybd, pWin, GRABTYPE_CORE, &mask,
+    grab = CreateGrab(client->index, keybd, keybd, pWin, CORE, &mask,
                       &param, KeyPress, stuff->key, NullWindow, NullCursor);
     if (!grab)
 	return BadAlloc;
@@ -5690,7 +5690,7 @@ ProcGrabButton(ClientPtr client)
 	return rc;
 
     memset(&param, 0, sizeof(param));
-    param.grabtype = GRABTYPE_CORE;
+    param.grabtype = CORE;
     param.ownerEvents = stuff->ownerEvents;
     param.this_device_mode = stuff->keyboardMode;
     param.other_devices_mode = stuff->pointerMode;
@@ -5699,7 +5699,7 @@ ProcGrabButton(ClientPtr client)
     mask.core = stuff->eventMask;
 
     grab = CreateGrab(client->index, ptr, modifierDevice, pWin,
-                      GRABTYPE_CORE, &mask, &param, ButtonPress,
+                      CORE, &mask, &param, ButtonPress,
                       stuff->button, confineTo, cursor);
     if (!grab)
 	return BadAlloc;
@@ -5744,7 +5744,7 @@ ProcUngrabButton(ClientPtr client)
     tempGrab->modifierDevice = GetMaster(ptr, MASTER_KEYBOARD);
     tempGrab->type = ButtonPress;
     tempGrab->detail.exact = stuff->button;
-    tempGrab->grabtype = GRABTYPE_CORE;
+    tempGrab->grabtype = CORE;
     tempGrab->detail.pMask = NULL;
     tempGrab->next = NULL;
 
@@ -6151,7 +6151,7 @@ PickPointer(ClientPtr client)
     for(it = inputInfo.devices; it; it = it->next)
     {
         GrabPtr grab = it->deviceGrab.grab;
-        if (grab && grab->grabtype == GRABTYPE_CORE && SameClient(grab, client))
+        if (grab && grab->grabtype == CORE && SameClient(grab, client))
         {
             it = GetMaster(it, MASTER_POINTER);
             return it; /* Always return a core grabbed device */
diff --git a/dix/grabs.c b/dix/grabs.c
index 0157b78..6f8b39e 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -81,8 +81,8 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
 
     ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):",
            (unsigned long) grab->resource,
-           (grab->grabtype == GRABTYPE_XI2) ? "xi2" :
-            ((grab->grabtype == GRABTYPE_CORE) ? "core" : "xi1"),
+           (grab->grabtype == XI2) ? "xi2" :
+            ((grab->grabtype == CORE) ? "core" : "xi1"),
            dev->name, dev->id);
 
     client = clients[CLIENT_ID(grab->resource)];
@@ -111,18 +111,18 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
            devGrab->sync.frozen ? "frozen" : "thawed",
            devGrab->sync.state);
 
-    if (grab->grabtype == GRABTYPE_CORE)
+    if (grab->grabtype == CORE)
     {
         ErrorF("        core event mask 0x%lx\n",
                (unsigned long) grab->eventMask);
     }
-    else if (grab->grabtype == GRABTYPE_XI)
+    else if (grab->grabtype == XI)
     {
         ErrorF("      xi1 event mask 0x%lx\n",
                devGrab->implicitGrab ? (unsigned long) grab->deviceMask :
                                        (unsigned long) grab->eventMask);
     }
-    else if (grab->grabtype == GRABTYPE_XI2)
+    else if (grab->grabtype == XI2)
     {
         for (i = 0; i < xi2mask_num_masks(grab->xi2mask); i++)
         {
@@ -206,7 +206,7 @@ CreateGrab(
     DeviceIntPtr device,
     DeviceIntPtr modDevice,
     WindowPtr window,
-    GrabType grabtype,
+    enum InputLevel grabtype,
     GrabMask *mask,
     GrabParameters *param,
     int type,
@@ -238,7 +238,7 @@ CreateGrab(
     grab->cursor = cursor;
     grab->next = NULL;
 
-    if (grabtype == GRABTYPE_XI2)
+    if (grabtype == XI2)
         xi2mask_merge(grab->xi2mask, mask->xi2mask);
     if (cursor)
 	cursor->refcnt++;
@@ -410,7 +410,7 @@ DetailSupersedesSecond(
 static Bool
 GrabSupersedesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab)
 {
-    unsigned int any_modifier = (pFirstGrab->grabtype == GRABTYPE_XI2) ?
+    unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ?
                                 (unsigned int)XIAnyModifier :
                                 (unsigned int)AnyModifier;
     if (!DetailSupersedesSecond(pFirstGrab->modifiersDetail,
@@ -441,14 +441,14 @@ GrabSupersedesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab)
 Bool
 GrabMatchesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab, Bool ignoreDevice)
 {
-    unsigned int any_modifier = (pFirstGrab->grabtype == GRABTYPE_XI2) ?
+    unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ?
                                 (unsigned int)XIAnyModifier :
                                 (unsigned int)AnyModifier;
 
     if (pFirstGrab->grabtype != pSecondGrab->grabtype)
         return FALSE;
 
-    if (pFirstGrab->grabtype == GRABTYPE_XI2)
+    if (pFirstGrab->grabtype == XI2)
     {
         if (pFirstGrab->device == inputInfo.all_devices ||
             pSecondGrab->device == inputInfo.all_devices)
@@ -500,7 +500,7 @@ GrabMatchesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab, Bool ignoreDevice)
 static Bool
 GrabsAreIdentical(GrabPtr pFirstGrab, GrabPtr pSecondGrab)
 {
-    unsigned int any_modifier = (pFirstGrab->grabtype == GRABTYPE_XI2) ?
+    unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ?
                                 (unsigned int)XIAnyModifier :
                                 (unsigned int)AnyModifier;
 
@@ -550,7 +550,7 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
 
     for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next)
     {
-	if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == GRABTYPE_CORE)))
+	if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == CORE)))
 	{
 	    if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource))
 	    {
@@ -628,9 +628,9 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
 	return FALSE;
     }
 
-    any_modifier = (pMinuendGrab->grabtype == GRABTYPE_XI2) ?
+    any_modifier = (pMinuendGrab->grabtype == XI2) ?
                    (unsigned int)XIAnyModifier : (unsigned int)AnyModifier;
-    any_key = (pMinuendGrab->grabtype == GRABTYPE_XI2) ?
+    any_key = (pMinuendGrab->grabtype == XI2) ?
                    (unsigned int)XIAnyKeycode : (unsigned int)AnyKey;
     ndels = nadds = nups = 0;
     ok = TRUE;
@@ -640,7 +640,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
     {
 	if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) ||
 	    !GrabMatchesSecond(grab, pMinuendGrab,
-                               (grab->grabtype == GRABTYPE_CORE)))
+                               (grab->grabtype == CORE)))
 	    continue;
 	if (GrabSupersedesSecond(pMinuendGrab, grab))
 	{
diff --git a/include/dixgrabs.h b/include/dixgrabs.h
index ea88770..4dd5eae 100644
--- a/include/dixgrabs.h
+++ b/include/dixgrabs.h
@@ -40,7 +40,7 @@ extern GrabPtr CreateGrab(
 	DeviceIntPtr /* device */,
 	DeviceIntPtr /* modDevice */,
 	WindowPtr /* window */,
-        GrabType /* grabtype */,
+        enum InputLevel /* grabtype */,
         GrabMask * /* mask */,
         struct _GrabParameters * /* param */,
 	int /* type */,
diff --git a/include/eventconvert.h b/include/eventconvert.h
index bb45eef..571a511 100644
--- a/include/eventconvert.h
+++ b/include/eventconvert.h
@@ -31,12 +31,6 @@
 
 #define FP1616(integral, frac) ((integral) * (1 << 16) + (frac) * (1 << 16))
 
-enum InputLevel {
-    CORE,
-    XI,
-    XI2,
-};
-
 _X_EXPORT int EventToCore(InternalEvent *event, xEvent **core, int *count);
 _X_EXPORT int EventToXI(InternalEvent *ev, xEvent **xi, int *count);
 _X_EXPORT int EventToXI2(InternalEvent *ev, xEvent **xi);
diff --git a/include/exevents.h b/include/exevents.h
index 12ea378..0ab04f5 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -159,7 +159,7 @@ typedef struct _XIClientRec {
 
 
 typedef struct _GrabParameters {
-    int                 grabtype;               /* GRABTYPE_CORE, etc. */
+    int                 grabtype;               /* CORE, etc. */
     unsigned int        ownerEvents;
     unsigned int        this_device_mode;
     unsigned int        other_devices_mode;
@@ -200,7 +200,7 @@ GrabButton(
 	DeviceIntPtr           /* modifier_device */,
 	int                    /* button */,
         GrabParameters*        /* param */,
-        GrabType               /* grabtype */,
+        enum InputLevel        /* grabtype */,
 	GrabMask*              /* eventMask */);
 
 extern int
@@ -210,7 +210,7 @@ GrabKey(
 	DeviceIntPtr           /* modifier_device */,
 	int                    /* key */,
         GrabParameters*        /* param */,
-        GrabType               /* grabtype */,
+        enum InputLevel        /* grabtype */,
 	GrabMask*              /* eventMask */);
 
 extern int
diff --git a/include/input.h b/include/input.h
index cbfaba7..7c5ad3c 100644
--- a/include/input.h
+++ b/include/input.h
@@ -102,6 +102,12 @@ SOFTWARE.
 #define RevertToFollowKeyboard	3
 #endif
 
+enum InputLevel {
+    CORE,
+    XI,
+    XI2,
+};
+
 typedef unsigned long Leds;
 typedef struct _OtherClients *OtherClientsPtr;
 typedef struct _InputClients *InputClientsPtr;
diff --git a/include/inputstr.h b/include/inputstr.h
index 5634f3c..754a3f8 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -167,12 +167,6 @@ typedef struct _DetailRec {		/* Grab details may be bit masks */
     Mask                *pMask;
 } DetailRec;
 
-typedef enum {
-    GRABTYPE_CORE,
-    GRABTYPE_XI,
-    GRABTYPE_XI2
-} GrabType;
-
 union _GrabMask {
     Mask core;
     Mask xi;
@@ -200,7 +194,7 @@ typedef struct _GrabRec {
     unsigned		ownerEvents:1;
     unsigned		keyboardMode:1;
     unsigned		pointerMode:1;
-    GrabType		grabtype;
+    enum InputLevel	grabtype;
     CARD8		type;		/* event type */
     DetailRec		modifiersDetail;
     DeviceIntPtr	modifierDevice;
diff --git a/test/input.c b/test/input.c
index c44e5f6..d27b3f0 100644
--- a/test/input.c
+++ b/test/input.c
@@ -148,7 +148,7 @@ static void dix_check_grab_values(void)
 
     memset(&client, 0, sizeof(client));
 
-    param.grabtype = GRABTYPE_CORE;
+    param.grabtype = CORE;
     param.this_device_mode = GrabModeSync;
     param.other_devices_mode = GrabModeSync;
     param.modifiers = AnyModifier;
@@ -531,22 +531,22 @@ static void dix_grab_matching(void)
     memset(&b, 0, sizeof(b));
 
     /* different grabtypes must fail */
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = CORE;
+    b.grabtype = XI2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI;
+    b.grabtype = XI2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = XI;
+    b.grabtype = CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
@@ -568,8 +568,8 @@ static void dix_grab_matching(void)
 
     inputInfo.all_devices = &xi_all_devices;
     inputInfo.all_master_devices = &xi_all_master_devices;
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.device = &dev1;
     b.device = &dev2;
 
@@ -598,8 +598,8 @@ static void dix_grab_matching(void)
     assert(rc == FALSE);
 
     /* ignoreDevice FALSE must fail for different devices for CORE and XI */
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.device = &dev1;
     b.device = &dev2;
     a.modifierDevice = &dev1;
@@ -607,8 +607,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.device = &dev1;
     b.device = &dev2;
     a.modifierDevice = &dev1;
@@ -618,8 +618,8 @@ static void dix_grab_matching(void)
 
     /* ignoreDevice FALSE must fail for different modifier devices for CORE
      * and XI */
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -627,8 +627,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -637,8 +637,8 @@ static void dix_grab_matching(void)
     assert(rc == FALSE);
 
     /* different event type must fail */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -650,8 +650,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&a, &b, TRUE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -663,8 +663,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&a, &b, TRUE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -677,8 +677,8 @@ static void dix_grab_matching(void)
     assert(rc == FALSE);
 
     /* different modifiers must fail */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.device = &dev1;
     b.device = &dev1;
     a.modifierDevice = &dev1;
@@ -692,23 +692,23 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
     /* AnyModifier must fail for XI2 */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.modifiersDetail.exact = AnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
@@ -717,8 +717,8 @@ static void dix_grab_matching(void)
     assert(rc == FALSE);
 
     /* XIAnyModifier must fail for CORE and XI */
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.modifiersDetail.exact = XIAnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
@@ -726,8 +726,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.modifiersDetail.exact = XIAnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
@@ -736,8 +736,8 @@ static void dix_grab_matching(void)
     assert(rc == FALSE);
 
     /* different detail must fail */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.detail.exact = 1;
     b.detail.exact = 2;
     a.modifiersDetail.exact = 1;
@@ -747,23 +747,23 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
     /* detail of AnyModifier must fail */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.detail.exact = AnyModifier;
     b.detail.exact = 1;
     a.modifiersDetail.exact = 1;
@@ -773,23 +773,23 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
     /* detail of XIAnyModifier must fail */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.detail.exact = XIAnyModifier;
     b.detail.exact = 1;
     a.modifiersDetail.exact = 1;
@@ -799,23 +799,23 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
     assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == FALSE);
 
     /* XIAnyModifier or AnyModifer must succeed */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.detail.exact = 1;
     b.detail.exact = 1;
     a.modifiersDetail.exact = XIAnyModifier;
@@ -825,8 +825,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == TRUE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.detail.exact = 1;
     b.detail.exact = 1;
     a.modifiersDetail.exact = AnyModifier;
@@ -836,8 +836,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == TRUE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.detail.exact = 1;
     b.detail.exact = 1;
     a.modifiersDetail.exact = AnyModifier;
@@ -848,8 +848,8 @@ static void dix_grab_matching(void)
     assert(rc == TRUE);
 
     /* AnyKey or XIAnyKeycode must succeed */
-    a.grabtype = GRABTYPE_XI2;
-    b.grabtype = GRABTYPE_XI2;
+    a.grabtype = XI2;
+    b.grabtype = XI2;
     a.detail.exact = XIAnyKeycode;
     b.detail.exact = 1;
     a.modifiersDetail.exact = 1;
@@ -859,8 +859,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == TRUE);
 
-    a.grabtype = GRABTYPE_CORE;
-    b.grabtype = GRABTYPE_CORE;
+    a.grabtype = CORE;
+    b.grabtype = CORE;
     a.detail.exact = AnyKey;
     b.detail.exact = 1;
     a.modifiersDetail.exact = 1;
@@ -870,8 +870,8 @@ static void dix_grab_matching(void)
     rc = GrabMatchesSecond(&b, &a, FALSE);
     assert(rc == TRUE);
 
-    a.grabtype = GRABTYPE_XI;
-    b.grabtype = GRABTYPE_XI;
+    a.grabtype = XI;
+    b.grabtype = XI;
     a.detail.exact = AnyKey;
     b.detail.exact = 1;
     a.modifiersDetail.exact = 1;
diff --git a/test/xi2/protocol-xipassivegrabdevice.c b/test/xi2/protocol-xipassivegrabdevice.c
index 1ffcdee..89ffc3d 100644
--- a/test/xi2/protocol-xipassivegrabdevice.c
+++ b/test/xi2/protocol-xipassivegrabdevice.c
@@ -49,7 +49,7 @@ struct test_data {
 } testdata;
 
 int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
-                      int button, GrabParameters *param, GrabType grabtype,
+                      int button, GrabParameters *param, enum InputLevel grabtype,
                       GrabMask *mask);
 static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data, void *userdata);
 
@@ -69,7 +69,7 @@ int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access
 }
 
 int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
-                      int button, GrabParameters *param, GrabType grabtype,
+                      int button, GrabParameters *param, enum InputLevel grabtype,
                       GrabMask *mask)
 {
     /* Fail every odd modifier */
commit cd56bd7b3ee34a4b10eb3a57a6e94cac7512167a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 8 14:59:06 2011 +1000

    Add GrabIsPointerGrab and GrabIsKeyboardGrab helpers
    
    No functional changes
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 8747599..405a8b1 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1001,9 +1001,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
         case ET_KeyRelease:
             if (grab && device->deviceGrab.fromPassiveGrab &&
                 (key == device->deviceGrab.activatingKey) &&
-                (device->deviceGrab.grab->type == KeyPress ||
-                 device->deviceGrab.grab->type == DeviceKeyPress ||
-                 device->deviceGrab.grab->type == XI_KeyPress))
+                GrabIsKeyboardGrab(device->deviceGrab.grab))
                 deactivateDeviceGrab = TRUE;
             break;
         case ET_ButtonPress:
@@ -1023,9 +1021,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
             event->detail.button = b->map[key];
             if (grab && !b->buttonsDown &&
                 device->deviceGrab.fromPassiveGrab &&
-                (device->deviceGrab.grab->type == ButtonPress ||
-                 device->deviceGrab.grab->type == DeviceButtonPress ||
-                 device->deviceGrab.grab->type == XI_ButtonPress))
+                GrabIsPointerGrab(device->deviceGrab.grab))
                 deactivateDeviceGrab = TRUE;
         default:
             break;
diff --git a/dix/grabs.c b/dix/grabs.c
index aced130..0157b78 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -60,6 +60,7 @@ SOFTWARE.
 #include "dixgrabs.h"
 #include "xace.h"
 #include "exevents.h"
+#include "exglobals.h"
 #include "inpututils.h"
 
 #define BITMASK(i) (((Mask)1) << ((i) & 31))
@@ -737,3 +738,19 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
 
 #undef UPDATE
 }
+
+Bool
+GrabIsPointerGrab(GrabPtr grab)
+{
+    return (grab->type == ButtonPress ||
+            grab->type == DeviceButtonPress ||
+            grab->type == XI_ButtonPress);
+}
+
+Bool
+GrabIsKeyboardGrab(GrabPtr grab)
+{
+   return (grab->type == KeyPress ||
+           grab->type == DeviceKeyPress ||
+           grab->type == XI_KeyPress);
+}
diff --git a/include/dixgrabs.h b/include/dixgrabs.h
index 65ff45d..ea88770 100644
--- a/include/dixgrabs.h
+++ b/include/dixgrabs.h
@@ -64,4 +64,6 @@ extern _X_EXPORT int AddPassiveGrabToList(
 extern _X_EXPORT Bool DeletePassiveGrabFromList(
 	GrabPtr /* pMinuendGrab */);
 
+extern Bool GrabIsPointerGrab(GrabPtr grab);
+extern Bool GrabIsKeyboardGrab(GrabPtr grab);
 #endif /* DIXGRABS_H */
commit 47734b2ba2e1f9246fd1a3b7059ca60b0e15acb2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 8 12:00:34 2011 +1000

    dix: move delivery stop condition out of event mask
    
    Previously, this was only called if there was a mask match, so even if we
    had a no-propagate flag set or a stopAt window specified, if no mask
    triggered on the window we would recurse up to the root window and
    eventually deliver.
    Move this, so that the stopAt and do-not-propagate mask is honoured.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 9fcd447..9703ca9 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2693,12 +2693,13 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
                     break;
             }
 
-            if ((deliveries < 0) || (pWin == stopAt) ||
-                (mask & EVENT_DONT_PROPAGATE_MASK))
-            {
-                deliveries = 0;
-                break;
-            }
+        }
+
+        if ((deliveries < 0) || (pWin == stopAt) ||
+            (mask & EVENT_DONT_PROPAGATE_MASK))
+        {
+            deliveries = 0;
+            break;
         }
 
         child = pWin->drawable.id;
commit 1d01e861b69d7ca8fe2335270b8286bc115fb6e9
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 8 10:22:26 2011 +1000

    dix: split out core state and event state setting into helper functions
    
    no functional changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 7983776..8747599 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -915,7 +915,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
     int key = 0, rootX, rootY;
     ButtonClassPtr b;
     int ret = 0;
-    int corestate, i;
+    int corestate;
     DeviceIntPtr mouse = NULL, kbd = NULL;
     DeviceEvent *event = &ev->device_event;
 
@@ -945,33 +945,8 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
             mouse = NULL;
     }
 
-    /* core state needs to be assembled BEFORE the device is updated. */
-    corestate = (kbd && kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->state) : 0;
-    corestate |= (mouse && mouse->button) ? (mouse->button->state) : 0;
-
-    for (i = 0; mouse && mouse->button && i < mouse->button->numButtons; i++)
-        if (BitIsOn(mouse->button->down, i))
-            SetBit(event->buttons, i);
-
-    if (kbd && kbd->key)
-    {
-        XkbStatePtr state;
-        /* we need the state before the event happens */
-        if (event->type == ET_KeyPress || event->type == ET_KeyRelease)
-            state = &kbd->key->xkbInfo->prev_state;
-        else
-            state = &kbd->key->xkbInfo->state;
-
-        event->mods.base = state->base_mods;
-        event->mods.latched = state->latched_mods;
-        event->mods.locked = state->locked_mods;
-        event->mods.effective = state->mods;
-
-        event->group.base = state->base_group;
-        event->group.latched = state->latched_group;
-        event->group.locked = state->locked_group;
-        event->group.effective = state->group;
-    }
+    corestate = event_get_corestate(mouse, kbd);
+    event_set_state(mouse, kbd, event);
 
     ret = UpdateDeviceState(device, event);
     if (ret == DONT_PROCESS)
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 60f9fa0..5844daf 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -657,6 +657,45 @@ void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
     event->sourceid = dev->id;
 }
 
+int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd)
+{
+    int corestate;
+    /* core state needs to be assembled BEFORE the device is updated. */
+    corestate = (kbd && kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->state) : 0;
+    corestate |= (mouse && mouse->button) ? (mouse->button->state) : 0;
+    return corestate;
+}
+
+void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event)
+{
+    int i;
+
+    for (i = 0; mouse && mouse->button && i < mouse->button->numButtons; i++)
+        if (BitIsOn(mouse->button->down, i))
+            SetBit(event->buttons, i);
+
+    if (kbd && kbd->key)
+    {
+        XkbStatePtr state;
+        /* we need the state before the event happens */
+        if (event->type == ET_KeyPress || event->type == ET_KeyRelease)
+            state = &kbd->key->xkbInfo->prev_state;
+        else
+            state = &kbd->key->xkbInfo->state;
+
+        event->mods.base = state->base_mods;
+        event->mods.latched = state->latched_mods;
+        event->mods.locked = state->locked_mods;
+        event->mods.effective = state->mods;
+
+        event->group.base = state->base_group;
+        event->group.latched = state->latched_group;
+        event->group.locked = state->locked_group;
+        event->group.effective = state->group;
+    }
+}
+
+
 Bool
 point_on_screen(ScreenPtr pScreen, int x, int y)
 {
diff --git a/include/inpututils.h b/include/inpututils.h
index 5f9dfec..96ad6df 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -40,6 +40,8 @@ struct _ValuatorMask {
 
 extern void verify_internal_event(const InternalEvent *ev);
 extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
+extern int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd);
+extern void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event);
 
 FP3232 double_to_fp3232(double in);
 FP1616 double_to_fp1616(double in);
commit fb010c543696b781a83b945f72865b7d7b75bf95
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 7 14:41:18 2011 +1000

    dix: move grab matching code into a helper function
    
    No functional changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 4d80358..9fcd447 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3751,6 +3751,62 @@ CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab)
     return interfering;
 }
 
+enum MatchFlags {
+    NO_MATCH    = 0x0,
+    CORE_MATCH  = 0x1,
+    XI_MATCH    = 0x2,
+    XI2_MATCH   = 0x4,
+};
+
+/**
+ * Match the grab against the temporary grab on the given input level.
+ * Modifies the temporary grab pointer.
+ *
+ * @param grab The grab to match against
+ * @param tmp The temporary grab to use for matching
+ * @param level The input level we want to match on
+ * @param event_type Wire protocol event type
+ *
+ * @return The respective matched flag or 0 for no match
+ */
+static enum MatchFlags
+MatchForType(const GrabPtr grab, GrabPtr tmp, enum InputLevel level, int event_type)
+{
+    enum MatchFlags match;
+    BOOL ignore_device = FALSE;
+    int grabtype;
+    int evtype;
+
+    switch(level)
+    {
+        case XI2:
+            grabtype = GRABTYPE_XI2;
+            evtype = GetXI2Type(event_type);
+            BUG_WARN(!evtype);
+            match = XI2_MATCH;
+            break;
+        case XI:
+            grabtype = GRABTYPE_XI;
+            evtype = GetXIType(event_type);
+            match = XI_MATCH;
+            break;
+        case CORE:
+            grabtype = GRABTYPE_CORE;
+            evtype = GetCoreType(event_type);
+            match = CORE_MATCH;
+            ignore_device = TRUE;
+            break;
+    }
+
+    tmp->grabtype = grabtype;
+    tmp->type = evtype;
+
+    if (tmp->type && GrabMatchesSecond(tmp, grab, ignore_device))
+        return match;
+
+    return NO_MATCH;
+}
+
 /**
  * Check an individual grab against an event to determine if a passive grab
  * should be activated.
@@ -3768,12 +3824,9 @@ static Bool
 CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
                  Bool checkCore, GrabPtr tempGrab)
 {
-    static const int CORE_MATCH = 0x1;
-    static const int XI_MATCH = 0x2;
-    static const int XI2_MATCH = 0x4;
     DeviceIntPtr gdev;
     XkbSrvInfoPtr xkbi = NULL;
-    int match = 0;
+    enum MatchFlags match = 0;
 
     gdev = grab->modifierDevice;
     if (grab->grabtype == GRABTYPE_CORE)
@@ -3795,27 +3848,13 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
     tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
 
     /* Check for XI2 and XI grabs first */
-    tempGrab->type = GetXI2Type(event->any.type);
-    tempGrab->grabtype = GRABTYPE_XI2;
-    if (GrabMatchesSecond(tempGrab, grab, FALSE))
-        match = XI2_MATCH;
+    match = MatchForType(grab, tempGrab, XI2, GetXI2Type(event->any.type));
 
     if (!match)
-    {
-        tempGrab->grabtype = GRABTYPE_XI;
-        if ((tempGrab->type = GetXIType(event->any.type)) &&
-            (GrabMatchesSecond(tempGrab, grab, FALSE)))
-            match = XI_MATCH;
-    }
+        match = MatchForType(grab, tempGrab, XI, GetXIType(event->any.type));
 
-    /* Check for a core grab (ignore the device when comparing) */
     if (!match && checkCore)
-    {
-        tempGrab->grabtype = GRABTYPE_CORE;
-        if ((tempGrab->type = GetCoreType(event->any.type)) &&
-            (GrabMatchesSecond(tempGrab, grab, TRUE)))
-            match = CORE_MATCH;
-    }
+        match = MatchForType(grab, tempGrab, CORE, GetCoreType(event->any.type));
 
     if (!match || (grab->confineTo &&
                    (!grab->confineTo->realized ||
commit d253a262c2c690357a4db7e235c48ab5dd0b77f8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 7 13:57:25 2011 +1000

    dix: split core grab interference check into helper function
    
    No functional changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 349d9b4..4d80358 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3727,6 +3727,30 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
     return TRUE;
 }
 
+static BOOL
+CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab)
+{
+    DeviceIntPtr other;
+    BOOL interfering = FALSE;
+
+    for (other = inputInfo.devices; other; other = other->next)
+    {
+        GrabPtr othergrab = other->deviceGrab.grab;
+        if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
+                SameClient(grab, rClient(othergrab)) &&
+                ((IsPointerDevice(grab->device) &&
+                  IsPointerDevice(othergrab->device)) ||
+                 (IsKeyboardDevice(grab->device) &&
+                  IsKeyboardDevice(othergrab->device))))
+        {
+            interfering = TRUE;
+            break;
+        }
+    }
+
+    return interfering;
+}
+
 /**
  * Check an individual grab against an event to determine if a passive grab
  * should be activated.
@@ -3806,9 +3830,6 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
 
     if (grab->grabtype == GRABTYPE_CORE)
     {
-        DeviceIntPtr other;
-        BOOL interfering = FALSE;
-
         /* A passive grab may have been created for a different device
            than it is assigned to at this point in time.
            Update the grab's device and modifier device to reflect the
@@ -3822,21 +3843,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
             grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
         }
 
-        for (other = inputInfo.devices; other; other = other->next)
-        {
-            GrabPtr othergrab = other->deviceGrab.grab;
-            if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
-                SameClient(grab, rClient(othergrab)) &&
-                ((IsPointerDevice(grab->device) &&
-                 IsPointerDevice(othergrab->device)) ||
-                 (IsKeyboardDevice(grab->device) &&
-                  IsKeyboardDevice(othergrab->device))))
-            {
-                interfering = TRUE;
-                break;
-            }
-        }
-        if (interfering)
+        if (CoreGrabInterferes(device, grab))
             return FALSE;
     }
 
commit 97d79dd740ed1ac4eb02b0d4135850f953716278
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 7 13:54:28 2011 +1000

    dix: compare the grab type, not the tempGrab type
    
    No functional change. To get here, GrabMatchesSecond() needs to be TRUE and
    for that the two grab types must be identical.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index e94001a..349d9b4 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3816,7 +3816,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
            Since XGrabDeviceButton requires to specify the
            modifierDevice explicitly, we don't override this choice.
          */
-        if (tempGrab->type < GenericEvent)
+        if (grab->type < GenericEvent)
         {
             grab->device = device;
             grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
commit b9d6ae42b686287d7d23c2eefe2b12da98fe6ff8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 7 15:43:31 2011 +1000

    dix: remove event type check
    
    Can't remember why this is there but we'll need to pass in XI2 events soon,
    so this check is obsolete.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 3041ae6..e94001a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3653,13 +3653,6 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
     int count;
     int rc;
 
-    if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
-    {
-        ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
-               " XI 1.x nor core\n", event->any.type);
-        return FALSE;
-    }
-
     /* The only consumers of corestate are Xi 1.x and core events, which
      * are guaranteed to come from DeviceEvents. */
     if (grab->grabtype == GRABTYPE_XI || grab->grabtype == GRABTYPE_CORE)
commit 80816366aa77f1730a1b6ddabfa55a946d76d494
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Nov 25 13:57:03 2011 -0800

    dix: Split ActivatePassiveGrab() from CheckPassiveGrab()
    
    The changed logic means we don't require the explicit grab = NULL setting
    and early exit anymore. Not 100% of it, but if we see that message pop up in
    a log we know it's broken.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index 09d38a1..3041ae6 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3635,38 +3635,128 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
 }
 
 /**
+ * Activate the given passive grab. If the grab is activated successfully, the
+ * event has been delivered to the client.
+ *
+ * @param device The device of the event to check.
+ * @param grab The grab to check.
+ * @param event The current device event.
+ *
+ * @return Whether the grab has been activated.
+ */
+Bool
+ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event)
+{
+    SpritePtr pSprite = device->spriteInfo->sprite;
+    GrabInfoPtr grabinfo = &device->deviceGrab;
+    xEvent *xE = NULL;
+    int count;
+    int rc;
+
+    if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
+    {
+        ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
+               " XI 1.x nor core\n", event->any.type);
+        return FALSE;
+    }
+
+    /* The only consumers of corestate are Xi 1.x and core events, which
+     * are guaranteed to come from DeviceEvents. */
+    if (grab->grabtype == GRABTYPE_XI || grab->grabtype == GRABTYPE_CORE)
+    {
+        DeviceIntPtr gdev;
+
+        event->device_event.corestate &= 0x1f00;
+
+        if (grab->grabtype == GRABTYPE_CORE)
+            gdev = GetMaster(device, KEYBOARD_OR_FLOAT);
+        else
+            gdev = grab->modifierDevice;
+
+        if (gdev && gdev->key && gdev->key->xkbInfo)
+            event->device_event.corestate |=
+                gdev->key->xkbInfo->state.grab_mods & (~0x1f00);
+    }
+
+    if (grab->grabtype == GRABTYPE_CORE)
+    {
+        rc = EventToCore(event, &xE, &count);
+        if (rc != Success)
+        {
+            BUG_WARN_MSG(rc != BadMatch,"[dix] %s: core conversion failed"
+                         "(%d, %d).\n", device->name, event->any.type, rc);
+            return FALSE;
+        }
+    } else if (grab->grabtype == GRABTYPE_XI2)
+    {
+        rc = EventToXI2(event, &xE);
+        if (rc != Success)
+        {
+            if (rc != BadMatch)
+                BUG_WARN_MSG(rc != BadMatch,"[dix] %s: XI2 conversion failed"
+                             "(%d, %d).\n", device->name, event->any.type, rc);
+            return FALSE;
+        }
+        count = 1;
+    } else
+    {
+        rc = EventToXI(event, &xE, &count);
+        if (rc != Success)
+        {
+            if (rc != BadMatch)
+                BUG_WARN_MSG(rc != BadMatch,"[dix] %s: XI conversion failed"
+                             "(%d, %d).\n", device->name, event->any.type, rc);
+            return FALSE;
+        }
+    }
+
+    (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
+
+    if (xE)
+    {
+        FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
+
+        /* XXX: XACE? */
+        TryClientEvents(rClient(grab), device, xE, count,
+                        GetEventFilter(device, xE),
+                        GetEventFilter(device, xE), grab);
+    }
+
+    if (grabinfo->sync.state == FROZEN_NO_EVENT)
+    {
+        if (!grabinfo->sync.event)
+            grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
+        *grabinfo->sync.event = event->device_event;
+        grabinfo->sync.state = FROZEN_WITH_EVENT;
+    }
+
+    free(xE);
+    return TRUE;
+}
+
+/**
  * Check an individual grab against an event to determine if a passive grab
  * should be activated.
- * If activate is true and a passive grab is found, it will be activated, and
- * the event will be delivered to the client.
  *
  * @param device The device of the event to check.
  * @param grab The grab to check.
  * @param event The current device event.
  * @param checkCore Check for core grabs too.
- * @param activate Whether to activate a matching grab.
  * @param tempGrab A pre-allocated temporary grab record for matching. This
  *        must have the window and device values filled in.
- * @param[out] grab_return The modified value of grab, to be used in the
- * caller for grab activation if a this function returns TRUE. May be NULL.
  *
  * @return Whether the grab matches the event.
  */
 static Bool
 CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
-                 Bool checkCore, Bool activate, GrabPtr tempGrab, GrabPtr *grab_return)
+                 Bool checkCore, GrabPtr tempGrab)
 {
     static const int CORE_MATCH = 0x1;
     static const int XI_MATCH = 0x2;
     static const int XI2_MATCH = 0x4;
-    SpritePtr pSprite = device->spriteInfo->sprite;
-    GrabInfoPtr grabinfo;
     DeviceIntPtr gdev;
     XkbSrvInfoPtr xkbi = NULL;
-    xEvent *xE = NULL;
     int match = 0;
-    int count;
-    int rc;
 
     gdev = grab->modifierDevice;
     if (grab->grabtype == GRABTYPE_CORE)
@@ -3715,8 +3805,6 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
                     !BorderSizeNotEmpty(device, grab->confineTo))))
         return FALSE;
 
-    *grab_return = grab;
-    grabinfo = &device->deviceGrab;
     /* In some cases a passive core grab may exist, but the client
      * already has a core grab on some other device. In this case we
      * must not get the grab, otherwise we may never ungrab the
@@ -3759,79 +3847,6 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
             return FALSE;
     }
 
-    if (!activate)
-        return TRUE;
-    else if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
-    {
-        ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
-               " XI 1.x nor core\n", event->any.type);
-        *grab_return = NULL;
-        return TRUE;
-    }
-
-    /* The only consumers of corestate are Xi 1.x and core events, which
-     * are guaranteed to come from DeviceEvents. */
-    if (match & (XI_MATCH | CORE_MATCH))
-    {
-        event->device_event.corestate &= 0x1f00;
-        event->device_event.corestate |= tempGrab->modifiersDetail.exact &
-                                          (~0x1f00);
-    }
-
-    if (match & CORE_MATCH)
-    {
-        rc = EventToCore(event, &xE, &count);
-        if (rc != Success)
-        {
-            if (rc != BadMatch)
-                ErrorF("[dix] %s: core conversion failed in CPGFW "
-                        "(%d, %d).\n", device->name, event->any.type, rc);
-            return TRUE;
-        }
-    } else if (match & XI2_MATCH)
-    {
-        rc = EventToXI2(event, &xE);
-        if (rc != Success)
-        {
-            if (rc != BadMatch)
-                ErrorF("[dix] %s: XI2 conversion failed in CPGFW "
-                        "(%d, %d).\n", device->name, event->any.type, rc);
-            return TRUE;
-        }
-        count = 1;
-    } else
-    {
-        rc = EventToXI(event, &xE, &count);
-        if (rc != Success)
-        {
-            if (rc != BadMatch)
-                ErrorF("[dix] %s: XI conversion failed in CPGFW "
-                        "(%d, %d).\n", device->name, event->any.type, rc);
-            return TRUE;
-        }
-    }
-
-    (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
-
-    if (xE)
-    {
-        FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
-
-        /* XXX: XACE? */
-        TryClientEvents(rClient(grab), device, xE, count,
-                        GetEventFilter(device, xE),
-                        GetEventFilter(device, xE), grab);
-    }
-
-    if (grabinfo->sync.state == FROZEN_NO_EVENT)
-    {
-        if (!grabinfo->sync.event)
-            grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
-        *grabinfo->sync.event = event->device_event;
-        grabinfo->sync.state = FROZEN_WITH_EVENT;
-    }
-
-    free(xE);
     return TRUE;
 }
 
@@ -3887,9 +3902,15 @@ CheckPassiveGrabsOnWindow(
     tempGrab->next = NULL;
 
     for (; grab; grab = grab->next)
-        if (CheckPassiveGrab(device, grab, event, checkCore, activate,
-                             tempGrab, &grab))
-            break;
+    {
+        if (!CheckPassiveGrab(device, grab, event, checkCore, tempGrab))
+            continue;
+
+        if (activate && !ActivatePassiveGrab(device, grab, event))
+            continue;
+
+        break;
+    }
 
     FreeGrab(tempGrab);
     return grab;
diff --git a/include/input.h b/include/input.h
index de2a75d..cbfaba7 100644
--- a/include/input.h
+++ b/include/input.h
@@ -548,6 +548,8 @@ void FixUpEventFromWindow(SpritePtr pSprite,
 extern WindowPtr XYToWindow(SpritePtr pSprite, int x, int y);
 extern int EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event,
                               WindowPtr win);
+extern Bool ActivatePassiveGrab(DeviceIntPtr dev, GrabPtr grab,
+                                InternalEvent *ev);
 /**
  * Masks specifying the type of event to deliver for an InternalEvent; used
  * by EventIsDeliverable.
commit 9ee62cd8ce3c3effc3663f3d56b322385ce12fdb
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Thu Nov 17 17:40:24 2011 -0800

    dix: Move grab check and activation logic to CheckPassiveGrab()
    
    This is needed for future pointer emulation work.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index 12c1678..09d38a1 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3635,6 +3635,207 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
 }
 
 /**
+ * Check an individual grab against an event to determine if a passive grab
+ * should be activated.
+ * If activate is true and a passive grab is found, it will be activated, and
+ * the event will be delivered to the client.
+ *
+ * @param device The device of the event to check.
+ * @param grab The grab to check.
+ * @param event The current device event.
+ * @param checkCore Check for core grabs too.
+ * @param activate Whether to activate a matching grab.
+ * @param tempGrab A pre-allocated temporary grab record for matching. This
+ *        must have the window and device values filled in.
+ * @param[out] grab_return The modified value of grab, to be used in the
+ * caller for grab activation if a this function returns TRUE. May be NULL.
+ *
+ * @return Whether the grab matches the event.
+ */
+static Bool
+CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
+                 Bool checkCore, Bool activate, GrabPtr tempGrab, GrabPtr *grab_return)
+{
+    static const int CORE_MATCH = 0x1;
+    static const int XI_MATCH = 0x2;
+    static const int XI2_MATCH = 0x4;
+    SpritePtr pSprite = device->spriteInfo->sprite;
+    GrabInfoPtr grabinfo;
+    DeviceIntPtr gdev;
+    XkbSrvInfoPtr xkbi = NULL;
+    xEvent *xE = NULL;
+    int match = 0;
+    int count;
+    int rc;
+
+    gdev = grab->modifierDevice;
+    if (grab->grabtype == GRABTYPE_CORE)
+    {
+        gdev = GetMaster(device, KEYBOARD_OR_FLOAT);
+    } else if (grab->grabtype == GRABTYPE_XI2)
+    {
+        /* if the device is an attached slave device, gdev must be the
+         * attached master keyboard. Since the slave may have been
+         * reattached after the grab, the modifier device may not be the
+         * same. */
+        if (!IsMaster(grab->device) && !IsFloating(device))
+            gdev = GetMaster(device, MASTER_KEYBOARD);
+    }
+
+    if (gdev && gdev->key)
+        xkbi= gdev->key->xkbInfo;
+    tempGrab->modifierDevice = grab->modifierDevice;
+    tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
+
+    /* Check for XI2 and XI grabs first */
+    tempGrab->type = GetXI2Type(event->any.type);
+    tempGrab->grabtype = GRABTYPE_XI2;
+    if (GrabMatchesSecond(tempGrab, grab, FALSE))
+        match = XI2_MATCH;
+
+    if (!match)
+    {
+        tempGrab->grabtype = GRABTYPE_XI;
+        if ((tempGrab->type = GetXIType(event->any.type)) &&
+            (GrabMatchesSecond(tempGrab, grab, FALSE)))
+            match = XI_MATCH;
+    }
+
+    /* Check for a core grab (ignore the device when comparing) */
+    if (!match && checkCore)
+    {
+        tempGrab->grabtype = GRABTYPE_CORE;
+        if ((tempGrab->type = GetCoreType(event->any.type)) &&
+            (GrabMatchesSecond(tempGrab, grab, TRUE)))
+            match = CORE_MATCH;
+    }
+
+    if (!match || (grab->confineTo &&
+                   (!grab->confineTo->realized ||
+                    !BorderSizeNotEmpty(device, grab->confineTo))))
+        return FALSE;
+
+    *grab_return = grab;
+    grabinfo = &device->deviceGrab;
+    /* In some cases a passive core grab may exist, but the client
+     * already has a core grab on some other device. In this case we
+     * must not get the grab, otherwise we may never ungrab the
+     * device.
+     */
+
+    if (grab->grabtype == GRABTYPE_CORE)
+    {
+        DeviceIntPtr other;
+        BOOL interfering = FALSE;
+
+        /* A passive grab may have been created for a different device
+           than it is assigned to at this point in time.
+           Update the grab's device and modifier device to reflect the
+           current state.
+           Since XGrabDeviceButton requires to specify the
+           modifierDevice explicitly, we don't override this choice.
+         */
+        if (tempGrab->type < GenericEvent)
+        {
+            grab->device = device;
+            grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
+        }
+
+        for (other = inputInfo.devices; other; other = other->next)
+        {
+            GrabPtr othergrab = other->deviceGrab.grab;
+            if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
+                SameClient(grab, rClient(othergrab)) &&
+                ((IsPointerDevice(grab->device) &&
+                 IsPointerDevice(othergrab->device)) ||
+                 (IsKeyboardDevice(grab->device) &&
+                  IsKeyboardDevice(othergrab->device))))
+            {
+                interfering = TRUE;
+                break;
+            }
+        }
+        if (interfering)
+            return FALSE;
+    }
+
+    if (!activate)
+        return TRUE;
+    else if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
+    {
+        ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
+               " XI 1.x nor core\n", event->any.type);
+        *grab_return = NULL;
+        return TRUE;
+    }
+
+    /* The only consumers of corestate are Xi 1.x and core events, which
+     * are guaranteed to come from DeviceEvents. */
+    if (match & (XI_MATCH | CORE_MATCH))
+    {
+        event->device_event.corestate &= 0x1f00;
+        event->device_event.corestate |= tempGrab->modifiersDetail.exact &
+                                          (~0x1f00);
+    }
+
+    if (match & CORE_MATCH)
+    {
+        rc = EventToCore(event, &xE, &count);
+        if (rc != Success)
+        {
+            if (rc != BadMatch)
+                ErrorF("[dix] %s: core conversion failed in CPGFW "
+                        "(%d, %d).\n", device->name, event->any.type, rc);
+            return TRUE;
+        }
+    } else if (match & XI2_MATCH)
+    {
+        rc = EventToXI2(event, &xE);
+        if (rc != Success)
+        {
+            if (rc != BadMatch)
+                ErrorF("[dix] %s: XI2 conversion failed in CPGFW "
+                        "(%d, %d).\n", device->name, event->any.type, rc);
+            return TRUE;
+        }
+        count = 1;
+    } else
+    {
+        rc = EventToXI(event, &xE, &count);
+        if (rc != Success)
+        {
+            if (rc != BadMatch)
+                ErrorF("[dix] %s: XI conversion failed in CPGFW "
+                        "(%d, %d).\n", device->name, event->any.type, rc);
+            return TRUE;
+        }
+    }
+
+    (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
+
+    if (xE)
+    {
+        FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
+
+        /* XXX: XACE? */
+        TryClientEvents(rClient(grab), device, xE, count,
+                        GetEventFilter(device, xE),
+                        GetEventFilter(device, xE), grab);
+    }
+
+    if (grabinfo->sync.state == FROZEN_NO_EVENT)
+    {
+        if (!grabinfo->sync.event)
+            grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
+        *grabinfo->sync.event = event->device_event;
+        grabinfo->sync.state = FROZEN_WITH_EVENT;
+    }
+
+    free(xE);
+    return TRUE;
+}
+
+/**
  * "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a
  * passive grab set on the window to be activated.
  * If activate is true and a passive grab is found, it will be activated,
@@ -3655,14 +3856,8 @@ CheckPassiveGrabsOnWindow(
     BOOL checkCore,
     BOOL activate)
 {
-    SpritePtr pSprite = device->spriteInfo->sprite;
     GrabPtr grab = wPassiveGrabs(pWin);
     GrabPtr tempGrab;
-    GrabInfoPtr grabinfo;
-#define CORE_MATCH      0x1
-#define XI_MATCH        0x2
-#define XI2_MATCH        0x4
-    int match = 0;
 
     if (!grab)
 	return NULL;
@@ -3690,185 +3885,14 @@ CheckPassiveGrabsOnWindow(
     tempGrab->detail.pMask = NULL;
     tempGrab->modifiersDetail.pMask = NULL;
     tempGrab->next = NULL;
-    for (; grab; grab = grab->next)
-    {
-	DeviceIntPtr	gdev;
-	XkbSrvInfoPtr	xkbi = NULL;
-	xEvent *xE = NULL;
-        int count, rc;
-
-	gdev= grab->modifierDevice;
-        if (grab->grabtype == GRABTYPE_CORE)
-        {
-            gdev = GetMaster(device, KEYBOARD_OR_FLOAT);
-        } else if (grab->grabtype == GRABTYPE_XI2)
-        {
-            /* if the device is an attached slave device, gdev must be the
-             * attached master keyboard. Since the slave may have been
-             * reattached after the grab, the modifier device may not be the
-             * same. */
-            if (!IsMaster(grab->device) && !IsFloating(device))
-                gdev = GetMaster(device, MASTER_KEYBOARD);
-        }
 
-
-        if (gdev && gdev->key)
-            xkbi= gdev->key->xkbInfo;
-        tempGrab->modifierDevice = grab->modifierDevice;
-        tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
-
-        /* Check for XI2 and XI grabs first */
-        tempGrab->type = GetXI2Type(event->any.type);
-        tempGrab->grabtype = GRABTYPE_XI2;
-        if (GrabMatchesSecond(tempGrab, grab, FALSE))
-            match = XI2_MATCH;
-
-        if (!match)
-        {
-            tempGrab->grabtype = GRABTYPE_XI;
-            if ((tempGrab->type = GetXIType(event->any.type)) &&
-                (GrabMatchesSecond(tempGrab, grab, FALSE)))
-                match = XI_MATCH;
-        }
-
-        /* Check for a core grab (ignore the device when comparing) */
-        if (!match && checkCore)
-        {
-            tempGrab->grabtype = GRABTYPE_CORE;
-            if ((tempGrab->type = GetCoreType(event->any.type)) &&
-                (GrabMatchesSecond(tempGrab, grab, TRUE)))
-                match = CORE_MATCH;
-        }
-
-        if (!match || (grab->confineTo &&
-                       (!grab->confineTo->realized ||
-                        !BorderSizeNotEmpty(device, grab->confineTo))))
-            continue;
-
-        grabinfo = &device->deviceGrab;
-        /* In some cases a passive core grab may exist, but the client
-         * already has a core grab on some other device. In this case we
-         * must not get the grab, otherwise we may never ungrab the
-         * device.
-         */
-
-        if (grab->grabtype == GRABTYPE_CORE)
-        {
-            DeviceIntPtr other;
-            BOOL interfering = FALSE;
-
-            /* A passive grab may have been created for a different device
-               than it is assigned to at this point in time.
-               Update the grab's device and modifier device to reflect the
-               current state.
-               Since XGrabDeviceButton requires to specify the
-               modifierDevice explicitly, we don't override this choice.
-               */
-            if (tempGrab->type < GenericEvent)
-            {
-                grab->device = device;
-                grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
-            }
-
-            for (other = inputInfo.devices; other; other = other->next)
-            {
-                GrabPtr othergrab = other->deviceGrab.grab;
-                if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
-                    SameClient(grab, rClient(othergrab)) &&
-                    ((IsPointerDevice(grab->device) &&
-                     IsPointerDevice(othergrab->device)) ||
-                     (IsKeyboardDevice(grab->device) &&
-                      IsKeyboardDevice(othergrab->device))))
-                {
-                    interfering = TRUE;
-                    break;
-                }
-            }
-            if (interfering)
-                continue;
-        }
-
-        if (!activate)
-            break;
-        else if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
-        {
-            ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
-                   " XI 1.x nor core\n", event->any.type);
-            grab = NULL;
+    for (; grab; grab = grab->next)
+        if (CheckPassiveGrab(device, grab, event, checkCore, activate,
+                             tempGrab, &grab))
             break;
-        }
-
-        /* The only consumers of corestate are Xi 1.x and core events, which
-         * are guaranteed to come from DeviceEvents. */
-        if (match & (XI_MATCH | CORE_MATCH))
-        {
-            event->device_event.corestate &= 0x1f00;
-            event->device_event.corestate |= tempGrab->modifiersDetail.exact &
-                                              (~0x1f00);
-        }
-
-        if (match & CORE_MATCH)
-        {
-            rc = EventToCore(event, &xE, &count);
-            if (rc != Success)
-            {
-                if (rc != BadMatch)
-                    ErrorF("[dix] %s: core conversion failed in CPGFW "
-                            "(%d, %d).\n", device->name, event->any.type, rc);
-                continue;
-            }
-        } else if (match & XI2_MATCH)
-        {
-            rc = EventToXI2(event, &xE);
-            if (rc != Success)
-            {
-                if (rc != BadMatch)
-                    ErrorF("[dix] %s: XI2 conversion failed in CPGFW "
-                            "(%d, %d).\n", device->name, event->any.type, rc);
-                continue;
-            }
-            count = 1;
-        } else
-        {
-            rc = EventToXI(event, &xE, &count);
-            if (rc != Success)
-            {
-                if (rc != BadMatch)
-                    ErrorF("[dix] %s: XI conversion failed in CPGFW "
-                            "(%d, %d).\n", device->name, event->any.type, rc);
-                continue;
-            }
-        }
-
-        (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
-
-        if (xE)
-        {
-            FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
-
-            /* XXX: XACE? */
-            TryClientEvents(rClient(grab), device, xE, count,
-                            GetEventFilter(device, xE),
-                            GetEventFilter(device, xE), grab);
-        }
-
-        if (grabinfo->sync.state == FROZEN_NO_EVENT)
-        {
-            if (!grabinfo->sync.event)
-                grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
-            *grabinfo->sync.event = event->device_event;
-            grabinfo->sync.state = FROZEN_WITH_EVENT;
-        }
-
-        free(xE);
-        break;
-    }
 
     FreeGrab(tempGrab);
     return grab;
-#undef CORE_MATCH
-#undef XI_MATCH
-#undef XI2_MATCH
 }
 
 /**
commit c53651dabc66aeb9882819a404a799a364f00a29
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 6 12:57:38 2011 +1000

    dix: move EventDeliveryState into a header file, we'll need it elsewhere
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 6e015fe..12c1678 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2014,13 +2014,6 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
     return TRUE;
 }
 
-enum EventDeliveryState {
-    EVENT_DELIVERED,     /**< Event has been delivered to a client  */
-    EVENT_NOT_DELIVERED, /**< Event was not delivered to any client */
-    EVENT_SKIP,          /**< Event can be discarded by the caller  */
-    EVENT_REJECTED,      /**< Event was rejected for delivery to the client */
-};
-
 /**
  * Attempt event delivery to the client owning the window.
  */
diff --git a/include/input.h b/include/input.h
index 917e92f..de2a75d 100644
--- a/include/input.h
+++ b/include/input.h
@@ -560,6 +560,13 @@ extern int EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event,
 #define EVENT_XI2_MASK                (1 << 3) /**< XI2 mask set on window */
 /* @} */
 
+enum EventDeliveryState {
+    EVENT_DELIVERED,     /**< Event has been delivered to a client  */
+    EVENT_NOT_DELIVERED, /**< Event was not delivered to any client */
+    EVENT_SKIP,          /**< Event can be discarded by the caller  */
+    EVENT_REJECTED,      /**< Event was rejected for delivery to the client */
+};
+
 /* Implemented by the DDX. */
 extern _X_EXPORT int NewInputDeviceRequest(
     InputOption *options,
commit 86c3137c81e924bacd919e9d65809e07afeabbff
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 6 12:04:11 2011 +1000

    Xi: split updating button count and state into helper functions
    
    Functional change: for a button mapped to 0, the motionHintWindow is not
    updated to the NullWindow anymore. Before it got updated unconditionally to
    the button mapping. I have no idea what the practical effect of this is, but
    I guess it's closer to the correct behaviour: pressing a button that's
    logically disabled now does not disrupt the motion hint delivery.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 2110957..7983776 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -726,6 +726,32 @@ UpdateDeviceMotionMask(DeviceIntPtr device, unsigned short state,
     SetMaskForEvent(device->id, mask, MotionNotify);
 }
 
+static void
+IncreaseButtonCount(DeviceIntPtr dev, int key, CARD8 *buttons_down,
+                    Mask *motion_mask, unsigned short *state)
+{
+    if (dev->valuator)
+        dev->valuator->motionHintWindow = NullWindow;
+
+    (*buttons_down)++;
+    *motion_mask = DeviceButtonMotionMask;
+    if (dev->button->map[key] <= 5)
+        *state |= (Button1Mask >> 1) << dev->button->map[key];
+}
+
+static void
+DecreaseButtonCount(DeviceIntPtr dev, int key, CARD8 *buttons_down,
+                    Mask *motion_mask, unsigned short *state)
+{
+    if (dev->valuator)
+        dev->valuator->motionHintWindow = NullWindow;
+
+    if (*buttons_down >= 1 && !--(*buttons_down))
+        *motion_mask = 0;
+    if (dev->button->map[key] <= 5)
+        *state &= ~((Button1Mask >> 1) << dev->button->map[key]);
+}
+
 /**
  * Update the device state according to the data in the event.
  *
@@ -831,15 +857,11 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
             return DONT_PROCESS;
 
         set_button_down(device, key, BUTTON_PROCESSED);
-	if (device->valuator)
-	    device->valuator->motionHintWindow = NullWindow;
+
         if (!b->map[key])
             return DONT_PROCESS;
-        b->buttonsDown++;
-	b->motionMask = DeviceButtonMotionMask;
-        if (b->map[key] <= 5)
-	    b->state |= (Button1Mask >> 1) << b->map[key];
 
+        IncreaseButtonCount(device, key, &b->buttonsDown, &b->motionMask, &b->state);
         UpdateDeviceMotionMask(device, b->state, b->motionMask);
     } else if (event->type == ET_ButtonRelease) {
         if (!b)
@@ -867,15 +889,10 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
             }
         }
         set_button_up(device, key, BUTTON_PROCESSED);
-	if (device->valuator)
-	    device->valuator->motionHintWindow = NullWindow;
         if (!b->map[key])
             return DONT_PROCESS;
-        if (b->buttonsDown >= 1 && !--b->buttonsDown)
-	    b->motionMask = 0;
-	if (b->map[key] <= 5)
-	    b->state &= ~((Button1Mask >> 1) << b->map[key]);
 
+        DecreaseButtonCount(device, key, &b->buttonsDown, &b->motionMask, &b->state);
         UpdateDeviceMotionMask(device,  b->state, b->motionMask);
     } else if (event->type == ET_ProximityIn)
 	device->proximity->in_proximity = TRUE;
commit e0f37250ffff5dcb3bc0e8cad63439995ce01a20
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 6 11:40:33 2011 +1000

    Xi: deduplicate button motion mask setting
    
    No functional changes
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index b2e82ec..2110957 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -704,6 +704,29 @@ ChangeMasterDeviceClasses(DeviceIntPtr device, DeviceChangedEvent *dce)
 }
 
 /**
+ * Add state and motionMask to the filter for this event. The protocol
+ * supports some extra masks for motion when a button is down:
+ * ButtonXMotionMask and the DeviceButtonMotionMask to trigger only when at
+ * least one button (or that specific button is down). These masks need to
+ * be added to the filters for core/XI motion events.
+ *
+ * @param device The device to update the mask for
+ * @param state The current button state mask
+ * @param motion_mask The motion mask (DeviceButtonMotionMask or 0)
+ */
+static void
+UpdateDeviceMotionMask(DeviceIntPtr device, unsigned short state,
+                       Mask motion_mask)
+{
+    Mask mask;
+
+    mask = DevicePointerMotionMask | state | motion_mask;
+    SetMaskForEvent(device->id, mask, DeviceMotionNotify);
+    mask = PointerMotionMask | state | motion_mask;
+    SetMaskForEvent(device->id, mask, MotionNotify);
+}
+
+/**
  * Update the device state according to the data in the event.
  *
  * return values are
@@ -801,7 +824,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 	    device->valuator->motionHintWindow = NullWindow;
 	set_key_up(device, key, KEY_PROCESSED);
     } else if (event->type == ET_ButtonPress) {
-        Mask mask;
         if (!b)
             return DONT_PROCESS;
 
@@ -818,13 +840,8 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         if (b->map[key] <= 5)
 	    b->state |= (Button1Mask >> 1) << b->map[key];
 
-        /* Add state and motionMask to the filter for this event */
-        mask = DevicePointerMotionMask | b->state | b->motionMask;
-        SetMaskForEvent(device->id, mask, DeviceMotionNotify);
-        mask = PointerMotionMask | b->state | b->motionMask;
-        SetMaskForEvent(device->id, mask, MotionNotify);
+        UpdateDeviceMotionMask(device, b->state, b->motionMask);
     } else if (event->type == ET_ButtonRelease) {
-        Mask mask;
         if (!b)
             return DONT_PROCESS;
 
@@ -859,11 +876,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 	if (b->map[key] <= 5)
 	    b->state &= ~((Button1Mask >> 1) << b->map[key]);
 
-        /* Add state and motionMask to the filter for this event */
-        mask = DevicePointerMotionMask | b->state | b->motionMask;
-        SetMaskForEvent(device->id, mask, DeviceMotionNotify);
-        mask = PointerMotionMask | b->state | b->motionMask;
-        SetMaskForEvent(device->id, mask, MotionNotify);
+        UpdateDeviceMotionMask(device,  b->state, b->motionMask);
     } else if (event->type == ET_ProximityIn)
 	device->proximity->in_proximity = TRUE;
     else if (event->type == ET_ProximityOut)
commit 6eff14a789341d366b3013c5aa020e959c954651
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 5 18:54:30 2011 +1000

    dix: deduplicate callers of DeliverDeviceEvents in DeliverGrabbedEvents
    
    No functional change.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 37039c6..6e015fe 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4156,6 +4156,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
     if (grab->ownerEvents)
     {
 	WindowPtr focus;
+	WindowPtr win;
 
         /* Hack: Some pointer device have a focus class. So we need to check
          * for the type of event, to see if we really want to deliver it to
@@ -4172,15 +4173,16 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
 	else
 	    focus = PointerRootWin;
 	if (focus == PointerRootWin)
-	    deliveries = DeliverDeviceEvents(pSprite->win, event, grab,
-                                             NullWindow, thisDev);
-	else if (focus && (focus == pSprite->win ||
-                    IsParent(focus, pSprite->win)))
-	    deliveries = DeliverDeviceEvents(pSprite->win, event, grab, focus,
-					     thisDev);
+	{
+	    win = pSprite->win;
+	    focus = NullWindow;
+	} else if (focus && (focus == pSprite->win ||
+		    IsParent(focus, pSprite->win)))
+	    win = pSprite->win;
 	else if (focus)
-	    deliveries = DeliverDeviceEvents(focus, event, grab, focus,
-					     thisDev);
+	    win = focus;
+
+	deliveries = DeliverDeviceEvents(win, event, grab, focus, thisDev);
     }
     if (!deliveries)
     {
commit 93945b0a74aa8156a88f52b8ba77f1210042f396
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 5 18:42:05 2011 +1000

    dix: split grab event conversion and delivery into a helper function
    
    Effective functional change: XI2 events are checked with XACE now.
    
    DeliverOneGrabbedEvent is exported for future use by touch events.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 705b079..37039c6 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4061,6 +4061,75 @@ unwind:
     return;
 }
 
+
+int
+DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level)
+{
+    SpritePtr pSprite = dev->spriteInfo->sprite;
+    int rc;
+    xEvent *xE = NULL;
+    int count = 0;
+    int deliveries = 0;
+    Mask mask;
+    GrabInfoPtr grabinfo = &dev->deviceGrab;
+    GrabPtr grab = grabinfo->grab;
+    Mask filter;
+
+    switch(level)
+    {
+        case XI2:
+            rc = EventToXI2(event, &xE);
+            count = 1;
+            if (rc == Success)
+            {
+                int evtype = xi2_get_type(xE);
+                mask = xi2mask_isset(grab->xi2mask, dev, evtype);
+                filter = 1;
+            }
+            break;
+        case XI:
+            if (grabinfo->fromPassiveGrab && grabinfo->implicitGrab)
+                mask = grab->deviceMask;
+            else
+                mask = grab->eventMask;
+            rc = EventToXI(event, &xE, &count);
+            if (rc == Success)
+                filter = GetEventFilter(dev, xE);
+            break;
+        case CORE:
+            rc = EventToCore(event, &xE, &count);
+            mask = grab->eventMask;
+            if (rc == Success)
+                filter = GetEventFilter(dev, xE);
+            break;
+        default:
+            BUG_WARN_MSG(1, "Invalid input level %d\n", level);
+            return 0;
+    }
+
+    if (rc == Success)
+    {
+        FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
+        if (XaceHook(XACE_SEND_ACCESS, 0, dev,
+                    grab->window, xE, count) ||
+                XaceHook(XACE_RECEIVE_ACCESS, rClient(grab),
+                    grab->window, xE, count))
+            deliveries = 1; /* don't send, but pretend we did */
+        else if (level != CORE || !IsInterferingGrab(rClient(grab), dev, xE))
+        {
+            deliveries = TryClientEvents(rClient(grab), dev,
+                    xE, count, mask, filter,
+                    grab);
+        }
+    } else
+        BUG_WARN_MSG(rc != BadMatch, "%s: conversion to mode %d failed on %d with %d\n",
+                dev->name, level, event->any.type, rc);
+
+    free(xE);
+    return deliveries;
+}
+
+
 /**
  * Deliver an event from a device that is currently grabbed. Uses
  * DeliverDeviceEvents() for further delivery if a ownerEvents is set on the
@@ -4080,10 +4149,6 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
     DeviceIntPtr dev;
     SpritePtr pSprite = thisDev->spriteInfo->sprite;
     BOOL sendCore = FALSE;
-    int rc, count = 0;
-    xEvent *xi = NULL;
-    xEvent *xi2 = NULL;
-    xEvent *core = NULL;
 
     grabinfo = &thisDev->deviceGrab;
     grab = grabinfo->grab;
@@ -4119,88 +4184,27 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
     }
     if (!deliveries)
     {
-        Mask mask;
-
         /* XXX: In theory, we could pass the internal events through to
          * everything and only convert just before hitting the wire. We can't
          * do that yet, so DGE is the last stop for internal events. From here
          * onwards, we deal with core/XI events.
          */
 
-        mask = grab->eventMask;
-
         sendCore = (IsMaster(thisDev) && thisDev->coreEvents);
         /* try core event */
         if (sendCore && grab->grabtype == GRABTYPE_CORE)
         {
-            rc = EventToCore(event, &core, &count);
-            if (rc == Success)
-            {
-                FixUpEventFromWindow(pSprite, core, grab->window, None, TRUE);
-                if (XaceHook(XACE_SEND_ACCESS, 0, thisDev,
-                            grab->window, core, count) ||
-                        XaceHook(XACE_RECEIVE_ACCESS, rClient(grab),
-                            grab->window, core, count))
-                    deliveries = 1; /* don't send, but pretend we did */
-                else if (!IsInterferingGrab(rClient(grab), thisDev, core))
-                {
-                    deliveries = TryClientEvents(rClient(grab), thisDev,
-                            core, count, mask,
-                            GetEventFilter(thisDev, core),
-                            grab);
-                }
-            } else
-                BUG_WARN_MSG(rc != BadMatch, "%s: Core conversion failed on %d with %d\n",
-                             thisDev->name, event->any.type, rc);
+            deliveries = DeliverOneGrabbedEvent(event, thisDev, CORE);
         }
 
         if (!deliveries)
         {
-            rc = EventToXI2(event, &xi2);
-            if (rc == Success)
-            {
-                int evtype = xi2_get_type(xi2);
-                mask = xi2mask_isset(grab->xi2mask, thisDev, evtype);
-                /* try XI2 event */
-                FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
-                /* XXX: XACE */
-                deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask, 1, grab);
-            } else
-                BUG_WARN_MSG(rc != BadMatch, "%s: XI2 conversion failed on %d with %d\n",
-                             thisDev->name, event->any.type, rc);
+            deliveries = DeliverOneGrabbedEvent(event, thisDev, XI2);
         }
 
         if (!deliveries)
         {
-            rc = EventToXI(event, &xi, &count);
-            if (rc == Success)
-            {
-                /* try XI event */
-                if (grabinfo->fromPassiveGrab  &&
-                        grabinfo->implicitGrab)
-                    mask = grab->deviceMask;
-                else
-                    mask = grab->eventMask;
-
-                FixUpEventFromWindow(pSprite, xi, grab->window, None, TRUE);
-
-                if (XaceHook(XACE_SEND_ACCESS, 0, thisDev,
-                            grab->window, xi, count) ||
-                        XaceHook(XACE_RECEIVE_ACCESS, rClient(grab),
-                            grab->window, xi, count))
-                    deliveries = 1; /* don't send, but pretend we did */
-                else
-                {
-                    deliveries =
-                        TryClientEvents(rClient(grab), thisDev,
-                                xi, count,
-                                mask,
-                                GetEventFilter(thisDev, xi),
-                                grab);
-                }
-            } else
-                BUG_WARN_MSG(rc != BadMatch, "%s: XI conversion failed on %d with %d\n",
-                             thisDev->name, event->any.type, rc);
+            deliveries = DeliverOneGrabbedEvent(event, thisDev, XI);
         }
 
         if (deliveries && (event->any.type == ET_Motion))
@@ -4233,10 +4237,6 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
 	}
     }
 
-    free(core);
-    free(xi);
-    free(xi2);
-
     return deliveries;
 }
 
diff --git a/include/dix.h b/include/dix.h
index cfbfa1f..9b9dc4b 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -400,6 +400,11 @@ extern int DeliverDeviceEvents(
     WindowPtr /* stopAt */,
     DeviceIntPtr /* dev */);
 
+extern int DeliverOneGrabbedEvent(
+    InternalEvent* /* event*/,
+    DeviceIntPtr /* dev */,
+    enum InputLevel /* level */);
+
 extern void InitializeSprite(
     DeviceIntPtr /* pDev */,
     WindowPtr    /* pWin */);
commit c81cdb0862e2184f033b3933e6bacbe0809ef2c0
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 5 18:29:27 2011 +1000

    dix: replace conversion errors with BUG_WARN_MSG
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index ced29f7..705b079 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4149,8 +4149,9 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
                             GetEventFilter(thisDev, core),
                             grab);
                 }
-            } else if (rc != BadMatch)
-                ErrorF("[dix] DeliverGrabbedEvent. Core conversion failed.\n");
+            } else
+                BUG_WARN_MSG(rc != BadMatch, "%s: Core conversion failed on %d with %d\n",
+                             thisDev->name, event->any.type, rc);
         }
 
         if (!deliveries)
@@ -4164,9 +4165,9 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
                 FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
                 /* XXX: XACE */
                 deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask, 1, grab);
-            } else if (rc != BadMatch)
-                ErrorF("[dix] %s: XI2 conversion failed in DGE (%d, %d). Skipping delivery.\n",
-                        thisDev->name, event->any.type, rc);
+            } else
+                BUG_WARN_MSG(rc != BadMatch, "%s: XI2 conversion failed on %d with %d\n",
+                             thisDev->name, event->any.type, rc);
         }
 
         if (!deliveries)
@@ -4197,9 +4198,9 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
                                 GetEventFilter(thisDev, xi),
                                 grab);
                 }
-            } else if (rc != BadMatch)
-                ErrorF("[dix] %s: XI conversion failed in DGE (%d, %d). Skipping delivery.\n",
-                        thisDev->name, event->any.type, rc);
+            } else
+                BUG_WARN_MSG(rc != BadMatch, "%s: XI conversion failed on %d with %d\n",
+                             thisDev->name, event->any.type, rc);
         }
 
         if (deliveries && (event->any.type == ET_Motion))
commit 6368c2aa4613a7c7eb0e8afca8d41f1a9bc4fc4d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 5 16:46:18 2011 +1000

    dix: deduplicate event delivery code
    
    Move all the event delivery code into DeliverOneEvent, based on the
    InputLevel we're sending to.
    
    Functional change: we now check XI2 events with XACE too.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 49f70c3..ced29f7 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2592,6 +2592,57 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
     return rc;
 }
 
+static int
+DeliverEvent(DeviceIntPtr dev, xEvent *xE, int count,
+             WindowPtr win, Window child, GrabPtr grab)
+{
+    SpritePtr pSprite = dev->spriteInfo->sprite;
+    Mask filter;
+    int deliveries = 0;
+
+    if (XaceHook(XACE_SEND_ACCESS, NULL, dev, win, xE, count) == Success) {
+        filter = GetEventFilter(dev, xE);
+        FixUpEventFromWindow(pSprite, xE, win, child, FALSE);
+        deliveries = DeliverEventsToWindow(dev, win, xE, count,
+                filter, grab);
+    }
+
+    return deliveries;
+}
+
+static int
+DeliverOneEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level,
+                WindowPtr win, Window child, GrabPtr grab)
+{
+    xEvent *xE = NULL;
+    int count = 0;
+    int deliveries = 0;
+    int rc;
+
+    switch(level)
+    {
+        case XI2:
+            rc = EventToXI2(event, &xE);
+            count = 1;
+            break;
+        case XI:
+            rc = EventToXI(event, &xE, &count);
+            break;
+        case CORE:
+            rc = EventToCore(event, &xE, &count);
+            break;
+    }
+
+    if (rc == Success)
+    {
+        deliveries = DeliverEvent(dev, xE, count, win, child, grab);
+        free(xE);
+    } else
+        BUG_WARN_MSG(rc != BadMatch, "%s: conversion to level %d failed with rc %d\n",
+                     dev->name, level, rc);
+    return deliveries;
+}
+
 /**
  * Deliver events caused by input devices.
  *
@@ -2615,12 +2666,9 @@ int
 DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
                     WindowPtr stopAt, DeviceIntPtr dev)
 {
-    SpritePtr pSprite = dev->spriteInfo->sprite;
     Window child = None;
-    Mask filter;
     int deliveries = 0;
-    xEvent *xE = NULL, *core = NULL;
-    int rc, mask, count = 0;
+    int mask;
 
     verify_internal_event(event);
 
@@ -2631,64 +2679,32 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
             /* XI2 events first */
             if (mask & EVENT_XI2_MASK)
             {
-                xEvent *xi2 = NULL;
-                rc = EventToXI2(event, &xi2);
-                if (rc == Success)
-                {
-                    /* XXX: XACE */
-                    filter = GetEventFilter(dev, xi2);
-                    FixUpEventFromWindow(pSprite, xi2, pWin, child, FALSE);
-                    deliveries = DeliverEventsToWindow(dev, pWin, xi2, 1,
-                                                       filter, grab);
-                    free(xi2);
-                    if (deliveries > 0)
-                        goto unwind;
-                } else if (rc != BadMatch)
-                    ErrorF("[dix] %s: XI2 conversion failed in DDE (%d).\n",
-                            dev->name, rc);
+                deliveries = DeliverOneEvent(event, dev, XI2, pWin, child, grab);
+                if (deliveries > 0)
+                    break;
             }
 
             /* XI events */
             if (mask & EVENT_XI1_MASK)
             {
-                rc = EventToXI(event, &xE, &count);
-                if (rc == Success) {
-                    if (XaceHook(XACE_SEND_ACCESS, NULL, dev, pWin, xE, count) == Success) {
-                        filter = GetEventFilter(dev, xE);
-                        FixUpEventFromWindow(pSprite, xE, pWin, child, FALSE);
-                        deliveries = DeliverEventsToWindow(dev, pWin, xE, count,
-                                                           filter, grab);
-                        if (deliveries > 0)
-                            goto unwind;
-                    }
-                } else if (rc != BadMatch)
-                    ErrorF("[dix] %s: XI conversion failed in DDE (%d, %d). Skipping delivery.\n",
-                            dev->name, event->any.type, rc);
+                deliveries = DeliverOneEvent(event, dev, XI, pWin, child, grab);
+                if (deliveries > 0)
+                    break;
             }
 
             /* Core event */
             if ((mask & EVENT_CORE_MASK) && IsMaster(dev) && dev->coreEvents)
             {
-                rc = EventToCore(event, &core, &count);
-                if (rc == Success) {
-                    if (XaceHook(XACE_SEND_ACCESS, NULL, dev, pWin, core, count) == Success) {
-                        filter = GetEventFilter(dev, core);
-                        FixUpEventFromWindow(pSprite, core, pWin, child, FALSE);
-                        deliveries = DeliverEventsToWindow(dev, pWin, core,
-                                                           count, filter, grab);
-                        if (deliveries > 0)
-                            goto unwind;
-                    }
-                } else if (rc != BadMatch)
-                        ErrorF("[dix] %s: Core conversion failed in DDE (%d, %d).\n",
-                                dev->name, event->any.type, rc);
+                deliveries = DeliverOneEvent(event, dev, CORE, pWin, child, grab);
+                if (deliveries > 0)
+                    break;
             }
 
             if ((deliveries < 0) || (pWin == stopAt) ||
                 (mask & EVENT_DONT_PROPAGATE_MASK))
             {
                 deliveries = 0;
-                goto unwind;
+                break;
             }
         }
 
@@ -2696,9 +2712,6 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
         pWin = pWin->parent;
     }
 
-unwind:
-    free(core);
-    free(xE);
     return deliveries;
 }
 
commit 7e2207548b3173afc9accb5ccd532c181a7b94ed
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Wed Dec 7 20:32:28 2011 +1000

    include: Add an InputLevel enum
    
    Currently unused, but will be in the future.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/eventconvert.h b/include/eventconvert.h
index 571a511..bb45eef 100644
--- a/include/eventconvert.h
+++ b/include/eventconvert.h
@@ -31,6 +31,12 @@
 
 #define FP1616(integral, frac) ((integral) * (1 << 16) + (frac) * (1 << 16))
 
+enum InputLevel {
+    CORE,
+    XI,
+    XI2,
+};
+
 _X_EXPORT int EventToCore(InternalEvent *event, xEvent **core, int *count);
 _X_EXPORT int EventToXI(InternalEvent *ev, xEvent **xi, int *count);
 _X_EXPORT int EventToXI2(InternalEvent *ev, xEvent **xi);
commit 898d97672907a8074031d0d1038cd44bb5caf40d
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Dec 12 16:49:33 2011 -0800

    verify_internal_event: preserve constness of data pointer
    
    All we're using it for is ErrorF calls, so make it a const char *
    to stop gcc from warning:
    
    inpututils.c: In function 'verify_internal_event':
    inpututils.c:629:9: warning: cast discards qualifiers from pointer target type
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 60f9fa0..5e2ab87 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -626,7 +626,7 @@ void verify_internal_event(const InternalEvent *ev)
     if (ev && ev->any.header != ET_Internal)
     {
         int i;
-        unsigned char *data = (unsigned char*)ev;
+        const unsigned char *data = (const unsigned char*)ev;
 
         ErrorF("dix: invalid event type %d\n", ev->any.header);
 
commit 79d09647d878e66721a778979a9eb1f4bba5f8d6
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Dec 12 16:49:33 2011 -0800

    Use const cast in BitIsOn macro to avoid angering gcc
    
    Fixes gcc warnings such as:
    inpututils.c: In function 'valuator_mask_isset':
    inpututils.c:498:5: warning: cast discards qualifiers from pointer target type
    inpututils.c: In function 'CountBits':
    inpututils.c:613:9: warning: cast discards qualifiers from pointer target type
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/inputstr.h b/include/inputstr.h
index 5634f3c..6af7264 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -57,7 +57,7 @@ SOFTWARE.
 #include "geext.h"
 #include "privates.h"
 
-#define BitIsOn(ptr, bit) (!!(((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7))))
+#define BitIsOn(ptr, bit) (!!(((const BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7))))
 #define SetBit(ptr, bit)  (((BYTE *) (ptr))[(bit)>>3] |= (1 << ((bit) & 7)))
 #define ClearBit(ptr, bit) (((BYTE *)(ptr))[(bit)>>3] &= ~(1 << ((bit) & 7)))
 extern _X_EXPORT int CountBits(const uint8_t *mask, int len);
commit 99dfe9b1de09cb481e95bd4c45dcf7493480798b
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Dec 12 16:49:32 2011 -0800

    Fix deconstifying cast warning in xi2_get_type
    
    Since we're just comparing values in the struct, cast it to a
    const xGenericEvent * to clear gcc warning of:
    
    events.c: In function 'xi2_get_type':
    events.c:193:5: warning: cast discards qualifiers from pointer target type
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index 59caa91..5c0f9dd 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -190,7 +190,7 @@ core_get_type(const xEvent *event)
 static inline int
 xi2_get_type(const xEvent *event)
 {
-    xGenericEvent* e = (xGenericEvent*)event;
+    const xGenericEvent* e = (const xGenericEvent*)event;
 
     return (e->type != GenericEvent || e->extension != IReqCode) ? 0 : e->evtype;
 }
commit dd80156bf05c9eb4000d0981e00d0d9fb69a94f6
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Wed Dec 7 22:58:45 2011 -0800

    Include client name if available in PrintDeviceGrabInfo
    
    Also adds missing newline to first line of output.
    
    Before patch:
    
    [3581472.414] (II) Printing all currently active device grabs:
    [3581472.414] Active grab 0x1800000 (core) on device 'Virtual core pointer' (2):
          client pid 26174 uid 0 gid 10
    [3581472.415]       at 3581469139 (from active grab) (device thawed, state 1)
    [3581472.415]         core event mask 0x0
    [3581472.415]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
    [3581472.415] Active grab 0x1800000 (core) on device 'Virtual core keyboard' (3)
    :      client pid 26174 uid 0 gid 10
    [3581472.415]       at 3581469139 (from active grab) (device thawed, state 1)
    [3581472.415]         core event mask 0x3
    [3581472.415]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
    [3581472.415] (II) End list of active device grabs
    
    After patch:
    [3581736.601] (II) Printing all currently active device grabs:
    [3581736.601] Active grab 0x1600000 (core) on device 'Virtual core pointer' (2):
    [3581736.601]       client pid 26741 /usr/bin/xscreensaver -nosplash
    [3581736.601]       at 3581735000 (from active grab) (device thawed, state 1)
    [3581736.601]         core event mask 0x0
    [3581736.601]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
    [3581736.601] Active grab 0x1600000 (core) on device 'Virtual core keyboard' (3)
    :
    [3581736.601]       client pid 26741 /usr/bin/xscreensaver -nosplash
    [3581736.601]       at 3581735000 (from active grab) (device thawed, state 1)
    [3581736.601]         core event mask 0x3
    [3581736.601]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
    [3581736.601] (II) End list of active device grabs
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Rami Ylimäki <rami.ylimaki at vincit.fi>

diff --git a/dix/grabs.c b/dix/grabs.c
index aced130..3286eb7 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -61,6 +61,7 @@ SOFTWARE.
 #include "xace.h"
 #include "exevents.h"
 #include "inpututils.h"
+#include "client.h"
 
 #define BITMASK(i) (((Mask)1) << ((i) & 31))
 #define MASKIDX(i) ((i) >> 5)
@@ -77,25 +78,41 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
     int i, j;
     GrabInfoPtr devGrab = &dev->deviceGrab;
     GrabPtr grab = devGrab->grab;
+    Bool clientIdPrinted = FALSE;
 
-    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):",
+    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):\n",
            (unsigned long) grab->resource,
            (grab->grabtype == GRABTYPE_XI2) ? "xi2" :
             ((grab->grabtype == GRABTYPE_CORE) ? "core" : "xi1"),
            dev->name, dev->id);
 
     client = clients[CLIENT_ID(grab->resource)];
-    if (client && GetLocalClientCreds(client, &lcc) != -1)
+    if (client)
     {
-        ErrorF("      client pid %ld uid %ld gid %ld\n",
-               (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
-               (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
-               (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
-        FreeLocalClientCreds(lcc);
+        pid_t clientpid = GetClientPid(client);
+        const char *cmdname = GetClientCmdName(client);
+        const char *cmdargs = GetClientCmdArgs(client);
+
+        if ((clientpid > 0) && (cmdname != NULL))
+        {
+            ErrorF("      client pid %ld %s %s\n",
+                   (long) clientpid, cmdname, cmdargs ? cmdargs : "");
+            clientIdPrinted = TRUE;
+        }
+        else if (GetLocalClientCreds(client, &lcc) != -1)
+        {
+            ErrorF("      client pid %ld uid %ld gid %ld\n",
+                   (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
+                   (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
+                   (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
+            FreeLocalClientCreds(lcc);
+            clientIdPrinted = TRUE;
+        }
     }
-    else
+    if (!clientIdPrinted)
     {
-        ErrorF("      (no client information available)\n");
+        ErrorF("      (no client information available for client %d)\n",
+               CLIENT_ID(grab->resource));
     }
 
     /* XXX is this even correct? */
commit e5aa00989cda9ebd18063c5e955235123ad37b88
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 7 14:14:10 2011 +1000

    Change GetXI2/XI/CoreType to just take a type argument
    
    Avoids the dummy-event dance if we have an event type and need to get the
    matching XI2 type.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index c9da396..67b420a 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -647,7 +647,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
     xde = (xXIDeviceEvent*)*xi;
     xde->type           = GenericEvent;
     xde->extension      = IReqCode;
-    xde->evtype         = GetXI2Type((InternalEvent*)ev);
+    xde->evtype         = GetXI2Type(ev->type);
     xde->time           = ev->time;
     xde->length         = bytes_to_int32(len - sizeof(xEvent));
     xde->detail         = ev->detail.button;
@@ -714,7 +714,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
     raw = (xXIRawEvent*)*xi;
     raw->type           = GenericEvent;
     raw->extension      = IReqCode;
-    raw->evtype         = GetXI2Type((InternalEvent*)ev);
+    raw->evtype         = GetXI2Type(ev->type);
     raw->time           = ev->time;
     raw->length         = bytes_to_int32(len - sizeof(xEvent));
     raw->detail         = ev->detail.button;
@@ -746,10 +746,10 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
  * equivalent exists.
  */
 int
-GetCoreType(InternalEvent *event)
+GetCoreType(enum EventType type)
 {
     int coretype = 0;
-    switch(event->any.type)
+    switch(type)
     {
         case ET_Motion:         coretype = MotionNotify;  break;
         case ET_ButtonPress:    coretype = ButtonPress;   break;
@@ -767,10 +767,10 @@ GetCoreType(InternalEvent *event)
  * equivalent exists.
  */
 int
-GetXIType(InternalEvent *event)
+GetXIType(enum EventType type)
 {
     int xitype = 0;
-    switch(event->any.type)
+    switch(type)
     {
         case ET_Motion:         xitype = DeviceMotionNotify;  break;
         case ET_ButtonPress:    xitype = DeviceButtonPress;   break;
@@ -790,11 +790,11 @@ GetXIType(InternalEvent *event)
  * equivalent exists.
  */
 int
-GetXI2Type(InternalEvent *event)
+GetXI2Type(enum EventType type)
 {
     int xi2type = 0;
 
-    switch(event->any.type)
+    switch(type)
     {
         case ET_Motion:         xi2type = XI_Motion;           break;
         case ET_ButtonPress:    xi2type = XI_ButtonPress;      break;
diff --git a/dix/events.c b/dix/events.c
index 5dfcbf3..49f70c3 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2553,13 +2553,13 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
     int type;
     OtherInputMasks *inputMasks = wOtherInputMasks(win);
 
-    if ((type = GetXI2Type(event)) != 0)
+    if ((type = GetXI2Type(event->any.type)) != 0)
     {
         if (inputMasks && xi2mask_isset(inputMasks->xi2mask, dev, type))
             rc |= EVENT_XI2_MASK;
     }
 
-    if ((type = GetXIType(event)) != 0)
+    if ((type = GetXIType(event->any.type)) != 0)
     {
         filter = GetEventFilterMask(dev, type);
 
@@ -2575,7 +2575,7 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
 
     }
 
-    if ((type = GetCoreType(event)) != 0)
+    if ((type = GetCoreType(event->any.type)) != 0)
     {
         filter = GetEventFilterMask(dev, type);
 
@@ -3712,7 +3712,7 @@ CheckPassiveGrabsOnWindow(
         tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
 
         /* Check for XI2 and XI grabs first */
-        tempGrab->type = GetXI2Type(event);
+        tempGrab->type = GetXI2Type(event->any.type);
         tempGrab->grabtype = GRABTYPE_XI2;
         if (GrabMatchesSecond(tempGrab, grab, FALSE))
             match = XI2_MATCH;
@@ -3720,7 +3720,7 @@ CheckPassiveGrabsOnWindow(
         if (!match)
         {
             tempGrab->grabtype = GRABTYPE_XI;
-            if ((tempGrab->type = GetXIType(event)) &&
+            if ((tempGrab->type = GetXIType(event->any.type)) &&
                 (GrabMatchesSecond(tempGrab, grab, FALSE)))
                 match = XI_MATCH;
         }
@@ -3729,7 +3729,7 @@ CheckPassiveGrabsOnWindow(
         if (!match && checkCore)
         {
             tempGrab->grabtype = GRABTYPE_CORE;
-            if ((tempGrab->type = GetCoreType(event)) &&
+            if ((tempGrab->type = GetCoreType(event->any.type)) &&
                 (GrabMatchesSecond(tempGrab, grab, TRUE)))
                 match = CORE_MATCH;
         }
@@ -3784,7 +3784,7 @@ CheckPassiveGrabsOnWindow(
 
         if (!activate)
             break;
-        else if (!GetXIType(event) && !GetCoreType(event))
+        else if (!GetXIType(event->any.type) && !GetCoreType(event->any.type))
         {
             ErrorF("Event type %d in CheckPassiveGrabsOnWindow is neither"
                    " XI 1.x nor core\n", event->any.type);
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 46e3005..0c958cd 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -1037,7 +1037,7 @@ DGAProcessKeyboardEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr keybd)
     if (pScreenPriv->client)
     {
         dgaEvent de;
-        de.u.u.type = *XDGAEventBase + GetCoreType((InternalEvent*)&ev);
+        de.u.u.type = *XDGAEventBase + GetCoreType(ev.type);
         de.u.u.detail = event->detail;
         de.u.event.time = event->time;
         de.u.event.dx = event->dx;
@@ -1091,7 +1091,7 @@ DGAProcessPointerEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr mouse)
         dgaEvent        de;
         int		coreEquiv;
 
-        coreEquiv = GetCoreType((InternalEvent*)&ev);
+        coreEquiv = GetCoreType(ev.type);
 
         de.u.u.type = *XDGAEventBase + coreEquiv;
         de.u.u.detail = event->detail;
diff --git a/include/eventconvert.h b/include/eventconvert.h
index b000abc..571a511 100644
--- a/include/eventconvert.h
+++ b/include/eventconvert.h
@@ -27,14 +27,15 @@
 #include <X11/extensions/XIproto.h>
 #include "input.h"
 #include "events.h"
+#include "eventstr.h"
 
 #define FP1616(integral, frac) ((integral) * (1 << 16) + (frac) * (1 << 16))
 
 _X_EXPORT int EventToCore(InternalEvent *event, xEvent **core, int *count);
 _X_EXPORT int EventToXI(InternalEvent *ev, xEvent **xi, int *count);
 _X_EXPORT int EventToXI2(InternalEvent *ev, xEvent **xi);
-_X_INTERNAL int GetCoreType(InternalEvent* ev);
-_X_INTERNAL int GetXIType(InternalEvent* ev);
-_X_INTERNAL int GetXI2Type(InternalEvent* ev);
+_X_INTERNAL int GetCoreType(enum EventType type);
+_X_INTERNAL int GetXIType(enum EventType type);
+_X_INTERNAL int GetXI2Type(enum EventType type);
 
 #endif /* _EVENTCONVERT_H_ */
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index dce1c50..e2037f9 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -59,7 +59,7 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
 
     assert(out->type == GenericEvent);
     assert(out->extension == 0); /* IReqCode defaults to 0 */
-    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->evtype == GetXI2Type(in->type));
     assert(out->time == in->time);
     assert(out->detail == in->detail.button);
     assert(out->deviceid == in->deviceid);
@@ -305,7 +305,7 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
     }
 
     assert(out->extension == 0); /* IReqCode defaults to 0 */
-    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->evtype == GetXI2Type(in->type));
     assert(out->time == in->time);
     assert(out->detail == in->detail.button);
     assert(out->length >= 12);
@@ -662,7 +662,7 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
 
     assert(out->type == GenericEvent);
     assert(out->extension == 0); /* IReqCode defaults to 0 */
-    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->evtype == GetXI2Type(in->type));
     assert(out->time == in->time);
     assert(out->deviceid == in->deviceid);
     assert(out->sourceid == in->sourceid);
commit 6cc0e6a0afa6a87802767d484aa4e68fa935d3eb
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Oct 28 12:55:55 2011 +1000

    include: add GetXI2MaskByte and GetXI2EventFilterMask to headers
    
    This is needed for touch event processing.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/events.c b/dix/events.c
index 59caa91..5dfcbf3 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -414,7 +414,7 @@ GetEventFilterMask(DeviceIntPtr dev, int evtype)
     return filters[dev ? dev->id : 0][evtype];
 }
 
-static inline Mask
+inline Mask
 GetXI2EventFilterMask(int evtype)
 {
     return (1 << (evtype % 8));
@@ -452,7 +452,7 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
  * Return the single byte of the device's XI2 mask that contains the mask
  * for the event_type.
  */
-static int
+int
 GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type)
 {
     /* we just return the matching filter because that's the only use
diff --git a/include/input.h b/include/input.h
index 8b0c18e..917e92f 100644
--- a/include/input.h
+++ b/include/input.h
@@ -57,6 +57,7 @@ SOFTWARE.
 #include "xkbrules.h"
 #include "events.h"
 #include "list.h"
+#include <X11/extensions/XI2.h>
 
 #define DEVICE_INIT	0
 #define DEVICE_ON	1
@@ -537,6 +538,8 @@ extern _X_EXPORT void FreeInputAttributes(InputAttributes *attrs);
 extern Mask GetEventMask(DeviceIntPtr dev, xEvent* ev, InputClientsPtr clients);
 extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);
 extern Bool WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev);
+extern Mask GetXI2EventFilterMask(int evtype);
+extern int GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type);
 void FixUpEventFromWindow(SpritePtr pSprite,
                           xEvent *xE,
                           WindowPtr pWin,


More information about the xorg-commit mailing list