home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / extensions / xtest1.info < prev    next >
Encoding:
Text File  |  1991-06-09  |  2.7 KB  |  91 lines

  1. XTestGenerateEvent is supposed to cause the server to generate a key or
  2. button event, exactly as one would be generated if a user pressed a key
  3. or pushed a mouse button.  Without knowing how your server does that for
  4. normal input events, I can't tell you exactly how that should look, but 
  5. it would be something like:
  6.  
  7. void
  8. XTestGenerateEvent (dev_type, key_or_button_code, direction, x, y)
  9.     int dev_type;        /* MOUSE = X pointer, KEYBOARD = X keyboard */
  10.     int key_or_button_code;    /* code to stash in event */
  11.     int direction;              /* XTestKEY_UP or XTestKEY_DOWN */
  12.     int x,y;            /* location of event  */
  13.     {
  14.     int type;
  15.     xEvent *xE;        
  16.  
  17.     if (key_or_button_code < 8)        /* must be a button */
  18.     if (direction == XTestKEY_UP)    /* it's a release event*/
  19.         type = ButtonRelease;
  20.     else
  21.         type = ButtonPress;
  22.     else                /* must be a key */
  23.     if (direction == XTestKEY_UP)    /* it's a release event*/
  24.         type = KeyRelease;
  25.     else
  26.         type = KeyPress;
  27.  
  28.     /* get an xEvent from some place where ProcessInputEvents can find it. */
  29.     /* I don't know how your implementation does this. */
  30.  
  31.     xE = somehow_get_xEvent();
  32.  
  33.     xE->u.u.type = type;
  34.     xE->u.u.detail = key_or_button_code;
  35.     xE->u.keyButtonPointer.time = GetTimeInMillis();
  36.     xE->u.keyButtonPointer.rootX = x;
  37.     xE->u.keyButtonPointer.rootY = y;
  38.  
  39.     /* now call ProcessInputEvents to send the event to DIX for routing to the
  40.        appropriate client(s). */
  41.  
  42.     ProcessInputEvents();
  43.     }
  44.  
  45.  
  46. XTestJumpPointer performs the equivalent function for pointer events.
  47.  
  48. void
  49. XTestJumpPointer (x, y, dev_type)
  50.     int x,y;
  51.     int dev_type;
  52.     {
  53.     /* get an xEvent from some place where ProcessInputEvents can find it. */
  54.     /* I don't know how your implementation does this. */
  55.  
  56.     xE = somehow_get_xEvent();
  57.  
  58.     xE->u.u.type = MotionNotify;
  59.     xE->u.keyButtonPointer.time = GetTimeInMillis();
  60.     xE->u.keyButtonPointer.rootX = x;
  61.     xE->u.keyButtonPointer.rootY = y;
  62.  
  63.     /* Call some place in your server code that takes care of acceleration and 
  64.        threshold.  Also constrain the move to the screen bounds.  You
  65.        may also have a motion history buffer that should be updated with
  66.        the information in this event.
  67.        */
  68.  
  69.     deal_with_acceleration ();
  70.     constrainxy();
  71.     update_motion_history();
  72.  
  73.     /* now call ProcessInputEvents to send the event to DIX for routing to the
  74.        appropriate client(s). */
  75.  
  76.     ProcessInputEvents();
  77.     }
  78.  
  79. XTestGetPointerPos returns the server's notion of where the X pointer currently
  80. is.  This is probably kept by ddx in some implementation-specific structure:
  81.  
  82. Implementation_Specific_Struct *i;
  83.  
  84. void
  85. XTestGetPointerPos (x,y)
  86.     short *x,*y;
  87.     {
  88.     *x = i->x;
  89.     *y = i->y;
  90.     }
  91.