+ if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
+ INVOKE_WCB( *window, Mouse, ( button,
+ pressed ? GLUT_DOWN : GLUT_UP,
+ event.xbutton.x,
+ event.xbutton.y )
+ );
+ else
+ {
+ /*
+ * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
+ * " 6 and 7 " " one; ...
+ *
+ * XXX This *should* be behind some variables/macros,
+ * XXX since the order and numbering isn't certain
+ * XXX See XFree86 configuration docs (even back in the
+ * XXX 3.x days, and especially with 4.x).
+ *
+ * XXX Note that {button} has already been decremeted
+ * XXX in mapping from X button numbering to GLUT.
+ */
+ int wheel_number = (button - 3) / 2;
+ int direction = -1;
+ if( button % 2 )
+ direction = 1;
+
+ if( pressed )
+ INVOKE_WCB( *window, MouseWheel, ( wheel_number,
+ direction,
+ event.xbutton.x,
+ event.xbutton.y )
+ );
+ }
+
+ /* Trash the modifiers state */
+ fgState.Modifiers = 0xffffffff;
+ }
+ break;
+
+ case KeyRelease:
+ case KeyPress:
+ {
+ FGCBKeyboard keyboard_cb;
+ FGCBSpecial special_cb;
+
+ GETWINDOW( xkey );
+ GETMOUSE( xkey );
+
+ /* Detect auto repeated keys, if configured globally or per-window */
+
+ if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
+ {
+ if (event.type==KeyRelease)
+ {
+ /*
+ * Look at X11 keystate to detect repeat mode.
+ * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
+ */
+
+ char keys[32];
+ XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
+
+ if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
+ {
+ if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
+ window->State.KeyRepeating = GL_TRUE;
+ else
+ window->State.KeyRepeating = GL_FALSE;
+ }
+ }
+ }
+ else
+ window->State.KeyRepeating = GL_FALSE;
+
+ /* Cease processing this event if it is auto repeated */
+
+ if (window->State.KeyRepeating)
+ break;
+
+ if( event.type == KeyPress )
+ {
+ keyboard_cb = FETCH_WCB( *window, Keyboard );
+ special_cb = FETCH_WCB( *window, Special );
+ }
+ else
+ {
+ keyboard_cb = FETCH_WCB( *window, KeyboardUp );
+ special_cb = FETCH_WCB( *window, SpecialUp );
+ }
+
+ /* Is there a keyboard/special callback hooked for this window? */
+ if( keyboard_cb || special_cb )