Tk Source Code

Artifact [a353fceb]
Login

Artifact a353fceb26432e5ea872032cab8b4e8b3f247091:

Attachment "genericevent.patch" to ticket [2010422f] added by dkf 2008-07-28 19:45:02.
Index: generic/tk.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tk.h,v
retrieving revision 1.112
diff -u -r1.112 tk.h
--- generic/tk.h	19 Jun 2008 19:48:26 -0000	1.112
+++ generic/tk.h	28 Jul 2008 12:38:26 -0000
@@ -627,17 +627,18 @@
  *---------------------------------------------------------------------------
  */
 
-#define VirtualEvent	    (LASTEvent)
-#define ActivateNotify	    (LASTEvent + 1)
-#define DeactivateNotify    (LASTEvent + 2)
-#define MouseWheelEvent     (LASTEvent + 3)
-#define TK_LASTEVENT	    (LASTEvent + 4)
+#if (TK_MAJOR_VERSION > 8)
+#error Maintenance todo: Fix GenericEvent/VirtualEvent clash. [Bug 2010422]
+#endif
+#define VirtualEvent	    (MappingNotify + 1)
+#define ActivateNotify	    (MappingNotify + 2)
+#define DeactivateNotify    (MappingNotify + 3)
+#define MouseWheelEvent     (MappingNotify + 4)
+#define TK_LASTEVENT	    (MappingNotify + 5)
 
 #define MouseWheelMask	    (1L << 28)
-
 #define ActivateMask	    (1L << 29)
 #define VirtualEventMask    (1L << 30)
-#define TK_LASTEVENT	    (LASTEvent + 4)
 
 /*
  * A virtual event shares most of its fields with the XKeyEvent and
Index: generic/tkEvent.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkEvent.c,v
retrieving revision 1.35
diff -u -r1.35 tkEvent.c
--- generic/tkEvent.c	26 Mar 2008 19:04:09 -0000	1.35
+++ generic/tkEvent.c	28 Jul 2008 12:38:27 -0000
@@ -75,7 +75,7 @@
  * Array of event masks corresponding to each X event:
  */
 
-static unsigned long eventMasks[TK_LASTEVENT] = {
+static unsigned long realEventMasks[MappingNotify+1] = {
     0,
     0,
     KeyPressMask,			/* KeyPress */
@@ -113,7 +113,10 @@
     0,					/* SelectionNotify */
     ColormapChangeMask,			/* ColormapNotify */
     0,					/* ClientMessage */
-    0,					/* Mapping Notify */
+    0					/* Mapping Notify */
+};
+
+static unsigned long virtualEventMasks[TK_LASTEVENT-VirtualEvent] = {
     VirtualEventMask,			/* VirtualEvents */
     ActivateMask,			/* ActivateNotify */
     ActivateMask,			/* DeactivateNotify */
@@ -489,7 +492,7 @@
  *
  * GetEventMaskFromXEvent --
  *
- *	The event type is looked up in our eventMasks table, and may be
+ *	The event type is looked up in our eventMasks tables, and may be
  *	changed to a different mask depending on the state of the event and
  *	window members.
  *
@@ -506,7 +509,21 @@
 GetEventMaskFromXEvent(
     XEvent *eventPtr)
 {
-    unsigned long mask = eventMasks[eventPtr->xany.type];
+    unsigned long mask;
+
+    /*
+     * Get the event mask from the correct table. Note that there are two
+     * tables here because that means we no longer need this code to rely on
+     * the exact value of VirtualEvent, which has caused us problems in the
+     * past when X11 changed the value of LASTEvent. [Bug ???]
+     */
+
+    if (eventPtr->xany.type <= MappingNotify) {
+	mask = realEventMasks[eventPtr->xany.type];
+    } else if (eventPtr->xany.type >= VirtualEvent
+	    && eventPtr->xany.type<TK_LASTEVENT) {
+	mask = virtualEventMasks[eventPtr->xany.type - VirtualEvent];
+    }
 
     /*
      * Events selected by StructureNotify require special handling. They look
Index: unix/tkUnixEvent.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixEvent.c,v
retrieving revision 1.28
diff -u -r1.28 tkUnixEvent.c
--- unix/tkUnixEvent.c	27 Apr 2008 22:39:13 -0000	1.28
+++ unix/tkUnixEvent.c	28 Jul 2008 12:38:28 -0000
@@ -289,6 +289,14 @@
 
     while (QLength(display) > 0) {
 	XNextEvent(display, &event);
+#ifdef GenericEvent
+	if (event.type == GenericEvent) {
+	    xGenericEvent *xgePtr = (xGenericEvent *) &event;
+
+	    Tcl_Panic("Wild GenericEvent; panic! (extension=%d,evtype=%d)"
+		    xgePtr->extension, xgePtr->evtype);
+	}
+#endif
 	if (event.type != KeyPress && event.type != KeyRelease) {
 	    if (XFilterEvent(&event, None)) {
 		continue;