home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / custEducation / opengl2 / lib / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.2 KB  |  205 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18.  
  19. #include <aux.h>
  20. #include <auxPrivate.h>
  21.  
  22. /**************************************************************************
  23.  *   auxEventPending() - Check to see if there's an event on the queue 
  24.  **************************************************************************/
  25.  
  26. GLboolean
  27. auxEventPending( GLvoid )
  28. {
  29.     if ( XPending( auxState.display ) > ZERO )
  30.         return GL_TRUE;
  31.     else
  32.         return GL_FALSE;
  33. }
  34.  
  35.  
  36. /**************************************************************************
  37.  *   GetWindow() - Match an X window to an auxWindow id   ( STATIC )
  38.  **************************************************************************/
  39.  
  40. static auxWindow *
  41. GetWindow( Window window )
  42. {
  43.     auxWindow          *tmp;
  44.  
  45.     for ( tmp = auxState.head; tmp; tmp = tmp->next )
  46.         if ( tmp->glxWindow == window )
  47.             return tmp;
  48.  
  49.     auxFatalError( "Unable to find window" );
  50. }
  51.  
  52.  
  53. /**************************************************************************
  54.  *   auxReadEvent() - Check to see if there's an event on the queue 
  55.  **************************************************************************/
  56.  
  57. GLint
  58. auxReadEvent( GLint *value, GLint *mousex, GLint *mousey )
  59. {
  60.     GLint           windowId;
  61.     auxWindow       *tmp;
  62.     KeySym          keysym;
  63.     XEvent          event, ahead;
  64.  
  65.  
  66.     static GLint    auxButtonList[] = {
  67.         None, AUX_LEFTBUTTON, AUX_MIDDLEBUTTON, AUX_RIGHTBUTTON
  68.     };
  69.  
  70.     auxMouseX = MINUS_ONE;
  71.     auxMouseY = MINUS_ONE;
  72.  
  73.     XNextEvent( auxState.display, &event );
  74.  
  75. #ifdef DEBUG3
  76.     printf("   Reveivced %s Event\n", eventName[event.type] );
  77. #endif
  78.  
  79.     switch( event.type ) {
  80.  
  81.         case ConfigureNotify :
  82.             tmp = GetWindow( event.xconfigure.window );
  83.             tmp->x = event.xconfigure.x;
  84.             tmp->y = event.xconfigure.y;
  85.             tmp->width = event.xconfigure.width;
  86.             tmp->height = event.xconfigure.height;
  87.             auxValue = tmp->id;
  88.             auxDevice = AUX_CONFIG;    
  89. #ifdef DEBUG3
  90.     printf("\tauxWindow : %d     X Window : 0x%x\n", tmp->id, tmp->glxWindow );
  91.     printf("\torigin : ( %d, %d )   size : ( %d, %d )\n", tmp->x, tmp->y,
  92.         tmp->width, tmp->height );
  93. #endif
  94.             break;
  95.  
  96.         case Expose :
  97.             while( XPending( auxState.display ) > ZERO ){
  98.                 XPeekEvent( auxState.display, &ahead );
  99.                 if ( ahead.type != Expose )
  100.                     break;
  101.                 if ( ahead.xexpose.window != event.xexpose.window )
  102.                     break;
  103.                 XNextEvent( auxState.display, &event );
  104.             }
  105.             tmp = GetWindow( event.xexpose.window );
  106.             auxValue = tmp->id;
  107.             auxDevice =  AUX_EXPOSE;
  108. #ifdef DEBUG3
  109.     printf("\tauxWindow : %d     X Window : 0x%x\n", tmp->id, tmp->glxWindow );
  110.     printf("\torigin : ( %d, %d )   size : ( %d, %d )\n", event.xexpose.x,
  111.         event.xexpose.y, event.xexpose.width, event.xexpose.height );
  112. #endif
  113.             break;
  114.  
  115.         case KeyPress :
  116.         case KeyRelease : {
  117.             const  GLint    bufSize = 8;
  118.             char            buf[bufSize];
  119.  
  120.             XLookupString( (XKeyEvent *) &event, buf, bufSize, &keysym, ZERO );
  121. #ifdef DEBUG3
  122.             printf("   Keysym = 0x%3x    buf = '%s'\n", keysym, buf );
  123. #endif
  124.             }
  125.  
  126.             auxMouseX = event.xkey.x;
  127.             auxMouseY = event.xkey.y;
  128.  
  129.             auxValue = ( event.type == KeyPress ? ONE : ZERO );
  130.             auxDevice = keysym;
  131.             break;
  132.  
  133.         case ButtonPress :
  134.         case ButtonRelease :
  135.             auxValue = ( event.type == ButtonPress ? ONE : ZERO );
  136.             auxMouseX = event.xbutton.x;
  137.             auxMouseY = event.xbutton.y;
  138. #ifdef DEBUG3
  139.             {    static char *auxButtonNames[] = {
  140.                     "None",
  141.                     "AUX_LEFTBUTTON",
  142.                     "AUX_MIDDLEBUTTON",
  143.                     "AUX_RIGHTBUTTON"
  144.                 };
  145.                 
  146.             printf("   Button = %s  value = %d     ( %d, %d )\n",
  147.                 auxButtonNames[event.xbutton.button], *value, *mousex, *mousey );
  148.             }
  149. #endif
  150.             auxDevice =  auxButtonList[event.xbutton.button];
  151.             break;
  152.  
  153.         case FocusIn :
  154.             tmp = GetWindow( event.xfocus.window );
  155.             auxValue = tmp->id;
  156.             auxDevice = AUX_INPUTCHANGE;
  157.             break;
  158.  
  159.         case FocusOut :
  160.             auxValue = ZERO;
  161.             auxDevice = AUX_INPUTCHANGE;
  162.             break;
  163.  
  164.         case MotionNotify :
  165.             auxValue = ZERO;
  166.             auxMouseX = event.xmotion.x;
  167.             auxMouseY = event.xmotion.y;
  168.             auxDevice = AUX_MOUSELOC;
  169.             break;
  170.  
  171.         case EnterNotify :
  172.         case LeaveNotify :
  173.         case KeymapNotify :
  174.         case GraphicsExpose :
  175.         case NoExpose :
  176.         case VisibilityNotify :
  177.         case CreateNotify :
  178.         case DestroyNotify :
  179.         case UnmapNotify :
  180.         case MapNotify :
  181.         case ReparentNotify :
  182.         case GravityNotify :
  183.         case CirculateNotify :
  184.         case PropertyNotify :
  185.         case SelectionClear :
  186.         case SelectionNotify :
  187.         case ColormapNotify :
  188.         case ClientMessage :
  189.         case MappingNotify :
  190.         case MapRequest :
  191.         case ConfigureRequest :
  192.         case ResizeRequest :
  193.         case CirculateRequest :
  194.         case SelectionRequest :
  195.             auxDevice = AUX_NOEVENT;
  196.             break;
  197.     }
  198.  
  199.     *value = auxValue;
  200.     *mousex = auxMouseX;
  201.     *mousey = auxMouseY;
  202.  
  203.     return auxDevice;
  204. }    
  205.