- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Activate the appropriate menu structure...
- */
- fgActivateMenu( window, button );
-
- break;
- }
-
- /*
- * Check if there is a mouse callback hooked to the window
- */
- if( window->Callbacks.Mouse == NULL )
- break;
-
- /*
- * Set the current window
- */
- fgSetWindow ( window );
-
- /*
- * Remember the current modifiers state
- */
- modifiers = 0;
- if (event.xbutton.state & (ShiftMask|LockMask))
- modifiers |= GLUT_ACTIVE_SHIFT;
- if (event.xbutton.state & ControlMask)
- modifiers |= GLUT_ACTIVE_CTRL;
- if (event.xbutton.state & Mod1Mask)
- modifiers |= GLUT_ACTIVE_ALT;
- fgStructure.Window->State.Modifiers = modifiers;
-
- /*
- * Finally execute the mouse callback
- */
- fgStructure.Window->Callbacks.Mouse(
- button,
- event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
- event.xbutton.x,
- event.xbutton.y
- );
-
- /*
- * Trash the modifiers state
- */
- fgStructure.Window->State.Modifiers = 0xffffffff;
- }
- break;
-
- case KeyRelease:
- case KeyPress:
- {
- FGCBkeyboard keyboard_cb;
- FGCBspecial special_cb;
-
- /*
- * A key has been pressed, find the window that had the focus:
- */
- GETWINDOW( xkey ); GETMOUSE( xkey );
-
- if( event.type == KeyPress )
- {
- keyboard_cb = window->Callbacks.Keyboard;
- special_cb = window->Callbacks.Special;
- }
- else
- {
- keyboard_cb = window->Callbacks.KeyboardUp;
- special_cb = window->Callbacks.SpecialUp;
- }
-
- /*
- * Is there a keyboard/special callback hooked for this window?
- */
- if( (keyboard_cb != NULL) || (special_cb != NULL) )
- {
- XComposeStatus composeStatus;
- char asciiCode[ 32 ];
- KeySym keySym;
- int len;
-
- /*
- * Check for the ASCII/KeySym codes associated with the event:
- */
- len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
-
- /*
- * GLUT API tells us to have two separate callbacks...
- */
- if( len > 0 )
- {
- /*
- * ...one for the ASCII translateable keypresses...
- */
- if( keyboard_cb != NULL )
- {
- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Remember the current modifiers state
- */
- modifiers = 0;
- if (event.xkey.state & (ShiftMask|LockMask))
- modifiers |= GLUT_ACTIVE_SHIFT;
- if (event.xkey.state & ControlMask)
- modifiers |= GLUT_ACTIVE_CTRL;
- if (event.xkey.state & Mod1Mask)
- modifiers |= GLUT_ACTIVE_ALT;
- window->State.Modifiers = modifiers;
-
- /*
- * Execute the callback
- */
- keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
-
- /*
- * Trash the modifiers state
- */
- window->State.Modifiers = 0xffffffff;
- }
- }
- else
- {
- int special = -1;
-
- /*
- * ...and one for all the others, which need to be translated to GLUT_KEY_Xs...
- */
- switch( keySym )
- {
- /*
- * First the function keys come:
- */
- case XK_F1: special = GLUT_KEY_F1; break;
- case XK_F2: special = GLUT_KEY_F2; break;
- case XK_F3: special = GLUT_KEY_F3; break;
- case XK_F4: special = GLUT_KEY_F4; break;
- case XK_F5: special = GLUT_KEY_F5; break;
- case XK_F6: special = GLUT_KEY_F6; break;
- case XK_F7: special = GLUT_KEY_F7; break;
- case XK_F8: special = GLUT_KEY_F8; break;
- case XK_F9: special = GLUT_KEY_F9; break;
- case XK_F10: special = GLUT_KEY_F10; break;
- case XK_F11: special = GLUT_KEY_F11; break;
- case XK_F12: special = GLUT_KEY_F12; break;
-
- /*
- * Then the arrows and stuff:
- */
- case XK_Left: special = GLUT_KEY_LEFT; break;
- case XK_Right: special = GLUT_KEY_RIGHT; break;
- case XK_Up: special = GLUT_KEY_UP; break;
- case XK_Down: special = GLUT_KEY_DOWN; break;
-
- case XK_KP_Prior:
- case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
- case XK_KP_Next:
- case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
- case XK_KP_Home:
- case XK_Home: special = GLUT_KEY_HOME; break;
- case XK_KP_End:
- case XK_End: special = GLUT_KEY_END; break;
- case XK_KP_Insert:
- case XK_Insert: special = GLUT_KEY_INSERT; break;
- }
-
- /*
- * Execute the callback (if one has been specified),
- * given that the special code seems to be valid...
- */
- if( (special_cb != NULL) && (special != -1) )
- {
- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Remember the current modifiers state
- */
- modifiers = 0;
- if (event.xkey.state & (ShiftMask|LockMask))
- modifiers |= GLUT_ACTIVE_SHIFT;
- if (event.xkey.state & ControlMask)
- modifiers |= GLUT_ACTIVE_CTRL;
- if (event.xkey.state & Mod1Mask)
- modifiers |= GLUT_ACTIVE_ALT;
- window->State.Modifiers = modifiers;
-
- special_cb( special, event.xkey.x, event.xkey.y );
-
- /*
- * Trash the modifiers state
- */
- window->State.Modifiers = 0xffffffff;
- }
- }