home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / xinput / XExtInt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-24  |  18.0 KB  |  624 lines

  1. /* $Header: XExtInt.c,v 1.24 91/07/24 15:44:34 rws Exp $ */
  2.  
  3. /************************************************************
  4. Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California, and the 
  5. Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.             All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the names of Hewlett-Packard or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16.  
  17. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ********************************************************/
  26.  
  27. /***********************************************************************
  28.  *
  29.  * Input Extension library internal functions.
  30.  *
  31.  */
  32.  
  33. #define NEED_EVENTS
  34. #define NEED_REPLIES
  35. #include <stdio.h>
  36. #include "XI.h"
  37. #include "XIproto.h"
  38. #include "Xlibint.h"
  39. #include "XInput.h"
  40. #include "extutil.h"
  41.  
  42. #define ENQUEUE_EVENT    True
  43. #define DONT_ENQUEUE    False
  44.  
  45. static    XExtensionInfo *xinput_info;
  46. static    /* const */ char *xinput_extension_name = INAME;
  47. static    int XInputClose();
  48. static    char *XInputError();
  49. static Bool XInputWireToEvent();
  50. Status    XInputEventToWire();
  51. static    /* const */ XEvent    emptyevent;
  52.  
  53. #define XInputCheckExtension(dpy,i,val) \
  54.   XextCheckExtension (dpy, i, xinput_extension_name, val)
  55.  
  56. static /* const */ XExtensionHooks xinput_extension_hooks = {
  57.     NULL,                /* create_gc */
  58.     NULL,                /* copy_gc */
  59.     NULL,                /* flush_gc */
  60.     NULL,                /* free_gc */
  61.     NULL,                /* create_font */
  62.     NULL,                /* free_font */
  63.     XInputClose,            /* close_display */
  64.     XInputWireToEvent,            /* wire_to_event */
  65.     XInputEventToWire,            /* event_to_wire */
  66.     NULL,                /* error */
  67.     XInputError,            /* error_string */
  68. };
  69.  
  70. static char *XInputErrorList[] = {
  71.     "BadDevice, invalid or uninitialized input device", /* BadDevice */
  72.     "BadEvent, invalid event type",                /* BadEvent    */    
  73.     "BadMode, invalid mode parameter",            /* BadMode    */
  74.     "BadClass, invalid event class",            /* BadClass    */    
  75. };
  76.  
  77. XEXT_GENERATE_FIND_DISPLAY (XInput_find_display, xinput_info, 
  78.     xinput_extension_name, &xinput_extension_hooks, IEVENTS, NULL)
  79.  
  80. static XEXT_GENERATE_ERROR_STRING (XInputError, xinput_extension_name,
  81.                    IERRORS, XInputErrorList)
  82. /*******************************************************************
  83.  *
  84.  * Input extension versions.
  85.  *
  86.  */
  87.  
  88. XExtensionVersion versions[] = {{XI_Absent,0,0},
  89.     {XI_Present, XI_Initial_Release_Major, XI_Initial_Release_Minor},
  90.     {XI_Present, XI_Add_XDeviceBell_Major, XI_Add_XDeviceBell_Minor},
  91.     {XI_Present, XI_Add_XSetDeviceValuators_Major, 
  92.      XI_Add_XSetDeviceValuators_Minor},
  93.     {XI_Present, XI_Add_XChangeDeviceControl_Major, 
  94.      XI_Add_XChangeDeviceControl_Minor}};
  95.  
  96. /***********************************************************************
  97.  *
  98.  * Return errors reported by this extension.
  99.  *
  100.  */
  101.  
  102. _xibaddevice (dpy, error)
  103.     Display *dpy;
  104.     int *error;
  105.     {
  106.     XExtDisplayInfo     *info = (XExtDisplayInfo *) XInput_find_display (dpy);
  107.     *error = info->codes->first_error + XI_BadDevice;
  108.     }
  109.  
  110. _xibadclass (dpy, error)
  111.     Display *dpy;
  112.     int *error;
  113.     {
  114.     XExtDisplayInfo     *info = (XExtDisplayInfo *) XInput_find_display (dpy); 
  115.     *error = info->codes->first_error + XI_BadClass;
  116.     }
  117.  
  118. _xibadevent (dpy, error)
  119.     Display *dpy;
  120.     int *error;
  121.     {
  122.     XExtDisplayInfo     *info = (XExtDisplayInfo *) XInput_find_display (dpy);
  123.     *error = info->codes->first_error + XI_BadEvent;
  124.     }
  125.  
  126. _xibadmode (dpy, error)
  127.     Display *dpy;
  128.     int *error;
  129.     {
  130.     XExtDisplayInfo     *info = (XExtDisplayInfo *) XInput_find_display (dpy);
  131.     *error = info->codes->first_error + XI_BadMode;
  132.     }
  133.  
  134. _xidevicebusy (dpy, error)
  135.     Display *dpy;
  136.     int *error;
  137.     {
  138.     XExtDisplayInfo     *info = (XExtDisplayInfo *) XInput_find_display (dpy); 
  139.     *error = info->codes->first_error + XI_DeviceBusy;
  140.     }
  141.  
  142. /***********************************************************************
  143.  *
  144.  * Check to see if the input extension is installed in the server.
  145.  * Also check to see if the version is >= the requested version.
  146.  *
  147.  */
  148.  
  149. CheckExtInit(dpy, version_index)
  150.     register    Display *dpy;
  151.     register    int    version_index;
  152.     {
  153.     XExtensionVersion     *ext;
  154.     XExtDisplayInfo     *info = XInput_find_display (dpy);
  155.  
  156.     XInputCheckExtension (dpy, info, -1);
  157.  
  158.     if (info->data == NULL)
  159.     {
  160.     info->data = (caddr_t) Xmalloc (sizeof (XEvent));
  161.     if (!info->data)
  162.         return (-1);
  163.     }
  164.  
  165.     if (versions[version_index].major_version > Dont_Check)
  166.     {
  167.     ext = XGetExtensionVersion (dpy, "XInputExtension");
  168.     if ((ext->major_version < versions[version_index].major_version) ||
  169.         ((ext->major_version == versions[version_index].major_version) &&
  170.          (ext->minor_version < versions[version_index].minor_version)))
  171.         {
  172.         XFree ((char *)ext);
  173.             UnlockDisplay(dpy);
  174.         return (-1);
  175.         }
  176.     XFree ((char *)ext);
  177.     }
  178.     return (0);
  179.     }
  180.  
  181. /***********************************************************************
  182.  *
  183.  * Close display routine.
  184.  *
  185.  */
  186.  
  187. static int
  188. XInputClose (dpy, codes)
  189.     Display *dpy;
  190.     XExtCodes *codes;
  191.     {
  192.     XExtDisplayInfo     *info = XInput_find_display (dpy);
  193.  
  194.     XFree((char *)info->data);
  195.     return XextRemoveDisplay (xinput_info, dpy);
  196.     }
  197.  
  198.  
  199. static int
  200. Ones(mask)  
  201.     Mask mask;
  202. {
  203.     register Mask y;
  204.  
  205.     y = (mask >> 1) &033333333333;
  206.     y = mask - y - ((y >>1) & 033333333333);
  207.     return (((y + (y >> 3)) & 030707070707) % 077);
  208. }
  209.  
  210. /***********************************************************************
  211.  *
  212.  * Handle Input extension events.
  213.  * Reformat a wire event into an XEvent structure of the right type.
  214.  *
  215.  */
  216.  
  217. static Bool
  218. XInputWireToEvent (dpy, re, event)
  219.     Display    *dpy;
  220.     XEvent    *re;
  221.     xEvent    *event;
  222.     {
  223.     unsigned    int    type, reltype;
  224.     unsigned    int    i,j;
  225.     XExtDisplayInfo     *info = XInput_find_display (dpy);
  226.     XEvent        *save = (XEvent *) info->data;
  227.  
  228.     type = event->u.u.type & 0x7f;
  229.     reltype = (type - info->codes->first_event);
  230.  
  231.  
  232.  
  233.     if (reltype != XI_DeviceValuator && 
  234.     reltype != XI_DeviceKeystateNotify &&
  235.     reltype != XI_DeviceButtonstateNotify)
  236.     {
  237.     *save = emptyevent;
  238.         save->type = type;
  239.         ((XAnyEvent *)save)->serial = _XSetLastRequestRead(dpy,
  240.         (xGenericReply *)event);
  241.         ((XAnyEvent *)save)->send_event = ((event->u.u.type & 0x80) != 0);
  242.         ((XAnyEvent *)save)->display = dpy;
  243.     }
  244.     
  245.     switch (reltype)
  246.     {
  247.     case XI_DeviceMotionNotify:
  248.         {
  249.         register XDeviceMotionEvent *ev = (XDeviceMotionEvent*) save;
  250.         deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
  251.  
  252.         ev->root         = ev2->root;
  253.         ev->window         = ev2->event;
  254.         ev->subwindow     = ev2->child;
  255.         ev->time         = ev2->time;
  256.         ev->x_root         = ev2->root_x;
  257.         ev->y_root         = ev2->root_y;
  258.         ev->x         = ev2->event_x;
  259.         ev->y         = ev2->event_y;
  260.         ev->state        = ev2->state;
  261.         ev->same_screen    = ev2->same_screen;
  262.         ev->is_hint     = ev2->detail;
  263.         ev->deviceid    = ev2->deviceid & DEVICE_BITS;
  264.             return (DONT_ENQUEUE);
  265.         break;
  266.         }
  267.     case XI_DeviceKeyPress:
  268.     case XI_DeviceKeyRelease:
  269.         {
  270.         register XDeviceKeyEvent *ev = (XDeviceKeyEvent*) save;
  271.         deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
  272.  
  273.         ev->root         = ev2->root;
  274.         ev->window         = ev2->event;
  275.         ev->subwindow     = ev2->child;
  276.         ev->time         = ev2->time;
  277.         ev->x_root         = ev2->root_x;
  278.         ev->y_root         = ev2->root_y;
  279.         ev->x         = ev2->event_x;
  280.         ev->y         = ev2->event_y;
  281.         ev->state        = ev2->state;
  282.         ev->same_screen    = ev2->same_screen;
  283.         ev->keycode     = ev2->detail;
  284.         ev->deviceid    = ev2->deviceid & DEVICE_BITS;
  285.         if (ev2->deviceid & MORE_EVENTS)
  286.         return (DONT_ENQUEUE);
  287.         else
  288.         {
  289.         *re = *save;
  290.         return (ENQUEUE_EVENT);
  291.         }
  292.         break;
  293.         }
  294.     case XI_DeviceButtonPress:
  295.     case XI_DeviceButtonRelease:
  296.         {
  297.         register XDeviceButtonEvent *ev = (XDeviceButtonEvent*) save;
  298.         deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
  299.  
  300.         ev->root         = ev2->root;
  301.         ev->window         = ev2->event;
  302.         ev->subwindow     = ev2->child;
  303.         ev->time         = ev2->time;
  304.         ev->x_root         = ev2->root_x;
  305.         ev->y_root         = ev2->root_y;
  306.         ev->x         = ev2->event_x;
  307.         ev->y         = ev2->event_y;
  308.         ev->state        = ev2->state;
  309.         ev->same_screen    = ev2->same_screen;
  310.         ev->button      = ev2->detail;
  311.         ev->deviceid    = ev2->deviceid & DEVICE_BITS;
  312.         if (ev2->deviceid & MORE_EVENTS)
  313.         return (DONT_ENQUEUE);
  314.         else
  315.         {
  316.         *re = *save;
  317.         return (ENQUEUE_EVENT);
  318.         }
  319.         break;
  320.         }
  321.     case XI_ProximityIn:
  322.     case XI_ProximityOut:
  323.         {
  324.         register XProximityNotifyEvent *ev = 
  325.         (XProximityNotifyEvent *) save;
  326.         deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
  327.  
  328.         ev->root         = ev2->root;
  329.         ev->window         = ev2->event;
  330.         ev->subwindow     = ev2->child;
  331.         ev->time         = ev2->time;
  332.         ev->x_root         = ev2->root_x;
  333.         ev->y_root         = ev2->root_y;
  334.         ev->x         = ev2->event_x;
  335.         ev->y         = ev2->event_y;
  336.         ev->state        = ev2->state;
  337.         ev->same_screen    = ev2->same_screen;
  338.         ev->deviceid    = ev2->deviceid & DEVICE_BITS;
  339.         if (ev2->deviceid & MORE_EVENTS)
  340.         return (DONT_ENQUEUE);
  341.         else
  342.         {
  343.         *re = *save;
  344.         return (ENQUEUE_EVENT);
  345.         }
  346.         break;
  347.         }
  348.     case XI_DeviceValuator:
  349.         {
  350.         deviceValuator *xev = (deviceValuator *) event;
  351.         int save_type = save->type - info->codes->first_event;
  352.  
  353.         if (save_type == XI_DeviceKeyPress ||
  354.             save_type == XI_DeviceKeyRelease)
  355.         {
  356.             XDeviceKeyEvent *kev = (XDeviceKeyEvent*) save;
  357.         kev->device_state = xev->device_state;
  358.         kev->axes_count = xev->num_valuators;
  359.         kev->first_axis = xev->first_valuator;
  360.         i = xev->num_valuators;
  361.         if (i > 6) i = 6;
  362.         switch (i)
  363.             {
  364.             case 6: kev->axis_data[5] = xev->valuator5;
  365.             case 5: kev->axis_data[4] = xev->valuator4;
  366.             case 4: kev->axis_data[3] = xev->valuator3;
  367.             case 3: kev->axis_data[2] = xev->valuator2;
  368.             case 2: kev->axis_data[1] = xev->valuator1;
  369.             case 1: kev->axis_data[0] = xev->valuator0;
  370.             }
  371.         }
  372.         else if (save_type == XI_DeviceButtonPress ||
  373.             save_type == XI_DeviceButtonRelease)
  374.         {
  375.             XDeviceButtonEvent *bev = (XDeviceButtonEvent*) save;
  376.         bev->device_state = xev->device_state;
  377.         bev->axes_count = xev->num_valuators;
  378.         bev->first_axis = xev->first_valuator;
  379.         i = xev->num_valuators;
  380.         if (i > 6) i = 6;
  381.         switch (i)
  382.             {
  383.             case 6: bev->axis_data[5] = xev->valuator5;
  384.             case 5: bev->axis_data[4] = xev->valuator4;
  385.             case 4: bev->axis_data[3] = xev->valuator3;
  386.             case 3: bev->axis_data[2] = xev->valuator2;
  387.             case 2: bev->axis_data[1] = xev->valuator1;
  388.             case 1: bev->axis_data[0] = xev->valuator0;
  389.             }
  390.         }
  391.         else if (save_type == XI_DeviceMotionNotify) 
  392.         {
  393.             XDeviceMotionEvent *mev = (XDeviceMotionEvent*) save;
  394.         mev->device_state = xev->device_state;
  395.         mev->axes_count = xev->num_valuators;
  396.         mev->first_axis = xev->first_valuator;
  397.         i = xev->num_valuators;
  398.         if (i > 6) i = 6;
  399.         switch (i)
  400.             {
  401.             case 6: mev->axis_data[5] = xev->valuator5;
  402.             case 5: mev->axis_data[4] = xev->valuator4;
  403.             case 4: mev->axis_data[3] = xev->valuator3;
  404.             case 3: mev->axis_data[2] = xev->valuator2;
  405.             case 2: mev->axis_data[1] = xev->valuator1;
  406.             case 1: mev->axis_data[0] = xev->valuator0;
  407.             }
  408.         }
  409.         else if (save_type == XI_ProximityIn ||
  410.             save_type == XI_ProximityOut)
  411.         {
  412.             XProximityNotifyEvent *pev = 
  413.             (XProximityNotifyEvent*) save;
  414.         pev->device_state = xev->device_state;
  415.         pev->axes_count = xev->num_valuators;
  416.         pev->first_axis = xev->first_valuator;
  417.         i = xev->num_valuators;
  418.         if (i > 6) i = 6;
  419.         switch (i)
  420.             {
  421.             case 6: pev->axis_data[5] = xev->valuator5;
  422.             case 5: pev->axis_data[4] = xev->valuator4;
  423.             case 4: pev->axis_data[3] = xev->valuator3;
  424.             case 3: pev->axis_data[2] = xev->valuator2;
  425.             case 2: pev->axis_data[1] = xev->valuator1;
  426.             case 1: pev->axis_data[0] = xev->valuator0;
  427.             }
  428.         }
  429.         else if (save_type == XI_DeviceStateNotify)
  430.         {
  431.             XDeviceStateNotifyEvent *sev = 
  432.             (XDeviceStateNotifyEvent*) save;
  433.         XInputClass *any = (XInputClass *) &sev->data[0];
  434.         XValuatorStatus *v;
  435.  
  436.         for (i=0; i<sev->num_classes; i++)
  437.             if (any->class != ValuatorClass)
  438.             any = (XInputClass *) ((char *) any + any->length);
  439.         v = (XValuatorStatus *) any;
  440.         i = v->num_valuators;
  441.         j = xev->num_valuators;
  442.         if (j > 3) j = 3;
  443.         switch (j)
  444.             {
  445.             case 3: v->valuators[i + 2] = xev->valuator2;
  446.             case 2: v->valuators[i + 1] = xev->valuator1;
  447.             case 1: v->valuators[i + 0] = xev->valuator0;
  448.             }
  449.         v->num_valuators += j;
  450.  
  451.         }
  452.         *re = *save;
  453.         return (ENQUEUE_EVENT);
  454.         break;
  455.         }
  456.     case XI_DeviceFocusIn:
  457.     case XI_DeviceFocusOut:
  458.         {
  459.         register XDeviceFocusChangeEvent *ev = 
  460.         (XDeviceFocusChangeEvent *) re;
  461.         deviceFocus *fev = (deviceFocus *) event;
  462.  
  463.         *ev            = *((XDeviceFocusChangeEvent *) save);
  464.         ev->window         = fev->window;
  465.         ev->time           = fev->time;
  466.         ev->mode        = fev->mode;
  467.         ev->detail        = fev->detail;
  468.         ev->deviceid         = fev->deviceid & DEVICE_BITS;
  469.             return (ENQUEUE_EVENT);
  470.         break;
  471.         }
  472.     case XI_DeviceStateNotify:
  473.         {
  474.         XDeviceStateNotifyEvent *stev = 
  475.         (XDeviceStateNotifyEvent *) save;
  476.         deviceStateNotify *sev = (deviceStateNotify *) event;
  477.         char *data;
  478.  
  479.         stev->window     = dpy->current;
  480.         stev->deviceid     = sev->deviceid & DEVICE_BITS;
  481.         stev->time         = sev->time;
  482.         stev->num_classes    = Ones (sev->classes_reported & InputClassBits);
  483.          data = (char *) &stev->data[0];
  484.         if (sev->classes_reported & (1 << KeyClass))
  485.             {
  486.             register XKeyStatus *kstev = (XKeyStatus *) data;
  487.             kstev->class = KeyClass;
  488.             kstev->length = sizeof (XKeyStatus);
  489.             kstev->num_keys = sev->num_keys;
  490.             bcopy ((char *) &sev->keys[0], (char *) &kstev->keys[0], 4);
  491.             data += sizeof (XKeyStatus);
  492.             }
  493.         if (sev->classes_reported & (1 << ButtonClass))
  494.             {
  495.             register XButtonStatus *bev = (XButtonStatus *) data;
  496.             bev->class = ButtonClass;
  497.             bev->length = sizeof (XButtonStatus);
  498.             bev->num_buttons = sev->num_buttons;
  499.             bcopy ((char *) sev->buttons, (char *) bev->buttons, 4);
  500.             data += sizeof (XButtonStatus);
  501.             }
  502.         if (sev->classes_reported & (1 << ValuatorClass))
  503.             {
  504.             register XValuatorStatus *vev = (XValuatorStatus *) data;
  505.             vev->class = ValuatorClass;
  506.             vev->length = sizeof (XValuatorStatus);
  507.             vev->num_valuators = sev->num_valuators;
  508.         vev->mode = sev->classes_reported >> ModeBitsShift;
  509.         j = sev->num_valuators;
  510.         if (j > 3) j = 3;
  511.         switch (j)
  512.             {
  513.             case 3: vev->valuators[2] = sev->valuator2;
  514.             case 2: vev->valuators[1] = sev->valuator1;
  515.             case 1: vev->valuators[0] = sev->valuator0;
  516.             }
  517.             data += sizeof (XValuatorStatus);
  518.             }
  519.             if (sev->deviceid & MORE_EVENTS)
  520.             return (DONT_ENQUEUE);
  521.         else
  522.             {
  523.             *re = *save;
  524.             stev = (XDeviceStateNotifyEvent *) re;
  525.             return (ENQUEUE_EVENT);
  526.             }
  527.         break;
  528.         }
  529.     case XI_DeviceKeystateNotify:
  530.         {
  531.         int i;
  532.         XInputClass *anyclass;
  533.         register XKeyStatus *kv;
  534.         deviceKeyStateNotify *ksev = (deviceKeyStateNotify *) event;
  535.         XDeviceStateNotifyEvent *kstev = 
  536.         (XDeviceStateNotifyEvent *) save;
  537.  
  538.         anyclass = (XInputClass *) &kstev->data[0];
  539.         for (i=0; i<kstev->num_classes; i++)
  540.             if (anyclass->class == KeyClass)
  541.             break;
  542.             else 
  543.             anyclass = (XInputClass *) ((char *) anyclass + 
  544.             anyclass->length);
  545.     
  546.         kv = (XKeyStatus *) anyclass;
  547.         kv->num_keys = 256;
  548.         bcopy ((char *) ksev->keys, (char *) &kv->keys[4], 28);
  549.             if (ksev->deviceid & MORE_EVENTS)
  550.             return (DONT_ENQUEUE);
  551.         else
  552.             {
  553.             *re = *save;
  554.             kstev = (XDeviceStateNotifyEvent *) re;
  555.             return (ENQUEUE_EVENT);
  556.             }
  557.         break;
  558.         }
  559.     case XI_DeviceButtonstateNotify:
  560.         {
  561.         int i;
  562.         XInputClass *anyclass;
  563.         register XButtonStatus *bv;
  564.         deviceButtonStateNotify *bsev = (deviceButtonStateNotify *) event;
  565.         XDeviceStateNotifyEvent *bstev = 
  566.         (XDeviceStateNotifyEvent *) save;
  567.  
  568.  
  569.         anyclass = (XInputClass *) &bstev->data[0];
  570.         for (i=0; i<bstev->num_classes; i++)
  571.             if (anyclass->class == ButtonClass)
  572.             break;
  573.             else 
  574.             anyclass = (XInputClass *) ((char *) anyclass + 
  575.             anyclass->length);
  576.     
  577.         bv = (XButtonStatus *) anyclass;
  578.         bv->num_buttons = 256;
  579.         bcopy ((char *) bsev->buttons, (char *) &bv->buttons[4], 28);
  580.             if (bsev->deviceid & MORE_EVENTS)
  581.             return (DONT_ENQUEUE);
  582.         else
  583.             {
  584.             *re = *save;
  585.             bstev = (XDeviceStateNotifyEvent *) re;
  586.             return (ENQUEUE_EVENT);
  587.             }
  588.         break;
  589.         }
  590.     case XI_DeviceMappingNotify:
  591.         {
  592.         register XDeviceMappingEvent *ev = (XDeviceMappingEvent *) re;
  593.         deviceMappingNotify *ev2 = (deviceMappingNotify *) event;
  594.  
  595.         *ev            = *((XDeviceMappingEvent *) save);
  596.         ev->window        = 0;
  597.         ev->first_keycode     = ev2->firstKeyCode;
  598.         ev->request         = ev2->request;
  599.         ev->count         = ev2->count;
  600.         ev->time          = ev2->time;
  601.         ev->deviceid         = ev2->deviceid & DEVICE_BITS;
  602.             return (ENQUEUE_EVENT);
  603.         }
  604.     case XI_ChangeDeviceNotify:
  605.         {
  606.         register XChangeDeviceNotifyEvent *ev = 
  607.         (XChangeDeviceNotifyEvent *) re;
  608.         changeDeviceNotify *ev2 = (changeDeviceNotify *) event;
  609.  
  610.         *ev            = *((XChangeDeviceNotifyEvent *) save);
  611.         ev->window        = 0;
  612.         ev->request         = ev2->request;
  613.         ev->time          = ev2->time;
  614.         ev->deviceid         = ev2->deviceid & DEVICE_BITS;
  615.             return (ENQUEUE_EVENT);
  616.         }
  617.     default:
  618.         printf ("XInputWireToEvent: UNKNOWN WIRE EVENT! type=%d\n",type);
  619.         break;
  620.     }
  621.  
  622.     return (DONT_ENQUEUE);
  623.     }
  624.