home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / test / xinput / XTouch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-17  |  52.9 KB  |  1,891 lines

  1. /* $XConsortium: XTouch.c,v 1.3 91/07/17 16:17:34 rws Exp $ */
  2. /************************************************************************
  3.  *
  4.  * XTouch.c
  5.  * This test attempts to invoke all of the functions provided by the
  6.  * input extension.  This is a "touch test", i.e, no attempt is made to
  7.  * exercise all permutations of parameters, and the result of the invocation
  8.  * may not be verified.  This test just invokes each function with one set
  9.  * of valid parameters.
  10.  *
  11.  */
  12.  
  13. #include <X11/Xlib.h>
  14. #include <X11/extensions/XInput.h>
  15. #include <X11/Xutil.h>
  16. #include "stdio.h"
  17.  
  18. #define PRINT                    0
  19. #define NOPRINT                    1
  20.  
  21. #define XGetExtensionVersion_code        1
  22. #define XListInputDevices_code            2
  23. #define XOpenDevice_code            3
  24. #define XCloseDevice_code            4
  25. #define XSetDeviceMode_code            5
  26. #define XSelectExtensionEvent_code          6
  27. #define XGetSelectedExtensionEvents_code    7
  28. #define XChangeDeviceDontPropagateList_code     8
  29. #define XGetDeviceDontPropagateList_code     9
  30. #define XGetDeviceMotionEvents_code         10 
  31. #define XChangeKeyboardDevice_code        11
  32. #define XChangePointerDevice_code        12
  33. #define XGrabDevice_code             13
  34. #define XUngrabDevice_code              14
  35. #define XGrabDeviceKey_code            15
  36. #define XUngrabDeviceKey_code            16
  37. #define XGrabDeviceButton_code            17
  38. #define XUngrabDeviceButton_code        18
  39. #define XAllowDeviceEvents_code            19
  40. #define XGetDeviceFocus_code            20
  41. #define XSetDeviceFocus_code            21
  42. #define XGetFeedbackControl_code        22
  43. #define XChangeFeedbackControl_code        23
  44. #define XGetDeviceKeyMapping_code        24
  45. #define XChangeDeviceKeyMapping_code        25
  46. #define XGetDeviceModifierMapping_code        26
  47. #define XSetDeviceModifierMapping_code        27
  48. #define XGetDeviceButtonMapping_code        28
  49. #define XSetDeviceButtonMapping_code        29
  50. #define XQueryDeviceState_code             30
  51.  
  52. char *ext_errors[] = {"BadDevice","BadEvent","BadMode","DeviceBusy","BadClass"};
  53.  
  54. char *std_errors[] = {"Success","BadRequest","BadValue","BadWindow","BadPixmap",
  55.         "BadAtom","BadCursor","BadFont","BadMatch","BadDrawable",
  56.         "BadAccess","BadAlloc","BadColor","BadGC","BadIDChoice",
  57.         "BadName","BadLength","BadImplementation"};
  58.  
  59. char *extfuncs[] = {"undefined", "GetExtensionVersion","ListInputDevices",
  60. "OpenDevice", "CloseDevice","SetDeviceMode","SelectExtensionEvent",
  61. "GetSelectedExtensionEvents", "ChangeDeviceDontPropagateList",
  62. "GetDeviceDontPropagateList","GetDeviceMotionEvents", "ChangeKeyboardDevice",
  63. "ChangePointerDevice","GrabDevice","UngrabDevice", "GrabDeviceKey",
  64. "UngrabDeviceKey","GrabDeviceButton","UngrabDeviceButton", "AllowDeviceEvents",
  65. "GetDeviceFocus","SetDeviceFocus", "GetFeedbackControl",
  66. "ChangeFeedbackControl","GetDeviceKeyMapping","ChangeDeviceKeyMapping",
  67. "GetDeviceModifierMapping","SetDeviceModifierMapping","GetDeviceButtonMapping",
  68. "SetDeviceButtonMapping","QueryDeviceState"};
  69.  
  70. int    Dflag = 0;
  71.  
  72. int    gstatus;
  73. int    expect = Success;
  74. int    error_code;
  75. int    major_code;
  76. int    first_err;
  77.  
  78. int    devicekeypress;
  79. int    devicekeyrelease;
  80. int    devicebuttonpress;
  81. int    devicebuttonrelease;
  82. int    devicemotionnotify;
  83. int    devicefocusin;
  84. int    devicefocusout;
  85. int    proximityin;
  86. int    proximityout;
  87. int    devicemappingnotify;
  88. int    devicestatenotify;
  89. int    changedevicenotify;
  90.  
  91. struct    classes
  92.     {
  93.     int valid;
  94.     XEventClass class[15];
  95.     } class[256];
  96.  
  97. XDeviceInfoPtr    savlist[256];
  98. XDevice        *sdev[256];
  99. XDevice        *keydevice;
  100.  
  101. Window        root;
  102.  
  103. main(argc,argv)
  104.     int argc;
  105.     char *argv[];
  106.     {
  107.     int         i,j;
  108.     int         ndevices;
  109.     char        *name;
  110.     Display        *display;
  111.     Window        my, my2, my3;
  112.     XDeviceInfoPtr     list_input_devices ();
  113.     XDeviceInfoPtr    list, slist;
  114.     XInputClassInfo    *ip;
  115.     XEvent        event;
  116.  
  117.     name = argv[0];
  118.     display = XOpenDisplay ("");
  119.     if (display == NULL)
  120.     {
  121.     printf ("No connection to server - aborting test.\n");
  122.     exit(1);
  123.     }
  124.     root = RootWindow (display,0);
  125.  
  126.     init_error_handler (display);
  127.     query_extension_version (display);
  128.     create_two_windows (display, root, &my, &my2, &my3);
  129.     slist = list_input_devices (display, &ndevices);
  130.     list = slist;
  131.     open_all_devices (display, list, ndevices);
  132.  
  133.     for (i=0; i<ndevices; i++, list++)
  134.     if (list->use != IsXPointer && list->use != IsXKeyboard)
  135.         {
  136.         select_all_input (display, root, list->name, sdev[i]);
  137.         select_all_input (display, my2, list->name, sdev[i]);
  138.         for (ip= sdev[i]->classes, j=0; j<sdev[i]->num_classes; j++, ip++)
  139.             {
  140.         if (ip->input_class == KeyClass)
  141.             {
  142.             do_key_mapping (display, list->name, sdev[i], savlist[i]);
  143.             do_modifier_mapping (display, list->name, sdev[i]);
  144.                 grab_device_key (display, list->name, sdev[i], my, my2);
  145.                 ungrab_device_key (display, list->name, sdev[i], my, my2);
  146.             }
  147.         else if (ip->input_class == ButtonClass)
  148.             {
  149.             do_button_mapping (display, sdev[i], savlist[i]);
  150.                 grab_device_button (display, list->name, sdev[i], my, my2);
  151.                 ungrab_device_button (display, list->name, sdev[i], my, 
  152.             my2);
  153.             }
  154.         else if (ip->input_class == ValuatorClass)
  155.             {
  156.             get_motion_history (display, list->name, sdev[i]);
  157.             set_device_mode (display, name, sdev[i]);
  158.             }
  159.         else if (ip->input_class == FeedbackClass)
  160.             {
  161.             do_feedback_control (display, name, sdev[i]);
  162.             }
  163.         }
  164.         do_propagate_list (display, my2, list->name, sdev[i]);
  165.         focus_input_device (display, list->name, sdev[i], my3);
  166.         grab_input_device (display, list->name, sdev[i], my, my2, my3);
  167.         allow_device_event (display, list->name, sdev[i]);
  168.             ungrab_input_device (display, list->name, sdev[i]);
  169.         query_device_state (display, list->name, sdev[i]);
  170.         send_extension_event (display, name, sdev[i], my2);
  171.         }
  172.  
  173.     close_input_devices (display, slist, sdev, ndevices);
  174.     }
  175.  
  176. /******************************************************************
  177.  *
  178.  * This function closes all open input devices.
  179.  *
  180.  */
  181.  
  182. close_input_devices (display, list, devices, count)
  183.     Display        *display;
  184.     XDeviceInfoPtr    list;
  185.     XDevice        *devices[];
  186.     int            count;
  187.     {
  188.     int        i;
  189.  
  190.     for (i=0; i<count; i++, list++)
  191.     if (list->use != IsXKeyboard && list->use != IsXPointer)
  192.             XCloseDevice (display, devices[i]);
  193.     }
  194.  
  195. /******************************************************************
  196.  *
  197.  * This function creates two test windows.
  198.  *
  199.  */
  200.  
  201. create_two_windows (display, root, my, my2, my3)
  202.     Display *display;
  203.     Window root, *my, *my2, *my3;
  204.     {   
  205.     XSetWindowAttributes attributes;
  206.     unsigned long     attribute_mask;
  207.     int         status;
  208.     XSizeHints         hints;
  209.     Screen        *screen = XDefaultScreenOfDisplay (display);
  210.  
  211.     attribute_mask = CWBackPixmap; 
  212.     attribute_mask = CWBackPixel; 
  213.     attribute_mask |= CWEventMask; 
  214.     attribute_mask |= CWDontPropagate; 
  215.     attributes.do_not_propagate_mask = 0;
  216.     attributes.background_pixmap = None;
  217.     attributes.background_pixel = WhitePixel(display, 0);
  218.     attributes.event_mask = ExposureMask;
  219.     
  220.     *my = XCreateWindow (display, root, 100,100, 400,200,1,
  221.     DefaultDepthOfScreen (screen),
  222.     InputOutput, CopyFromParent, attribute_mask, &attributes);
  223.  
  224.     if (*my == 0) {
  225.     fprintf (stderr, "can't create window!\n");
  226.     exit (1);
  227.     }
  228.     status = XGetNormalHints (display, *my, &hints);
  229.     hints.flags |= (PPosition | PSize | PMinSize);
  230.     hints.x = 100;
  231.     hints.y = 100;
  232.     hints.width = 400;
  233.     hints.height = 200;
  234.     hints.min_width = 400;
  235.     hints.min_height = 200;
  236.     XSetNormalHints (display, *my, &hints);
  237.     XMapWindow (display, *my);
  238.     XFlush(display);
  239.  
  240.     attribute_mask = CWBackPixmap;
  241.     attribute_mask = CWBackPixel; 
  242.     attribute_mask |= CWEventMask; 
  243.     attributes.background_pixmap = None;
  244.     attributes.background_pixel = BlackPixel(display, 0);
  245.     attributes.event_mask = ExposureMask;
  246.  
  247.     *my2 = XCreateWindow (display, *my, 50,50, 300,100,1,
  248.     DefaultDepthOfScreen (screen),
  249.     InputOutput, CopyFromParent, attribute_mask, &attributes);
  250.     if (my2 == 0) {
  251.     fprintf (stderr, "can't create window!\n");
  252.     exit (1);
  253.     }
  254.     status = XGetNormalHints (display, *my2, &hints);
  255.     hints.flags |= (PPosition | PSize | PMinSize);
  256.     hints.x = 50;
  257.     hints.y = 50;
  258.     hints.width = 300;
  259.     hints.height = 100;
  260.     hints.min_width = 300;
  261.     hints.min_height = 100;
  262.     XSetNormalHints (display, *my2, &hints);
  263.     XMapWindow (display, *my2);
  264.  
  265.     attribute_mask = CWBackPixmap;
  266.     attribute_mask = CWBackPixel; 
  267.     attribute_mask |= CWEventMask; 
  268.     attributes.background_pixmap = None;
  269.     attributes.background_pixel = BlackPixel(display, 0);
  270.     attributes.event_mask = ExposureMask;
  271.  
  272.     *my3 = XCreateWindow (display, *my2, 50,50, 200,50,1,
  273.     DefaultDepthOfScreen (screen),
  274.     InputOutput, CopyFromParent, attribute_mask, &attributes);
  275.     if (my3 == 0) {
  276.     fprintf (stderr, "can't create window!\n");
  277.     exit (1);
  278.     }
  279.     status = XGetNormalHints (display, *my3, &hints);
  280.     hints.flags |= (USPosition | USSize | PPosition | PSize);
  281.     XSetNormalHints (display, *my3, &hints);
  282.     XFlush(display);
  283.  
  284.     }
  285.  
  286. /******************************************************************
  287.  *
  288.  * This function lists all available input devices.
  289.  *
  290.  */
  291.  
  292. XDeviceInfoPtr
  293. list_input_devices (display, ndevices)
  294.     Display *display;
  295.     int        *ndevices;
  296.     {
  297.     int            i,j,k;
  298.     XDeviceInfoPtr    list, slist;
  299.     XAnyClassPtr    any;
  300.     XKeyInfoPtr        K;
  301.     XButtonInfoPtr    b;
  302.     XValuatorInfoPtr    v;
  303.     XAxisInfoPtr    a;
  304.  
  305.     list = (XDeviceInfoPtr) XListInputDevices (display, ndevices);
  306.     slist = list;
  307.     if (Dflag)
  308.     printf ("The number of available input devices is %d\n",*ndevices);
  309.     for (i=0; i<*ndevices; i++, list++)
  310.     {
  311.     savlist[i] = list;
  312.     if (Dflag)
  313.         {
  314.         printf ("\nid is %d\n",list->id);
  315.         printf ("type is %d\n",list->type);
  316.         printf ("name is %s\n",list->name);
  317.         printf ("num_classes is %d\n\n",list->num_classes);
  318.         }
  319.     if (list->num_classes > 0)
  320.         {
  321.         any = (XAnyClassPtr) (list->inputclassinfo);
  322.         for (j=0; j<list->num_classes; j++)
  323.         {
  324.         if (Dflag)
  325.             {
  326.             printf ("input class is %d\n", any->class);
  327.             printf ("length is %d\n", any->length);
  328.             }
  329.         switch (any->class)
  330.             {
  331.             case KeyClass:
  332.             K = (XKeyInfoPtr) any;
  333.             if (Dflag)
  334.                 {
  335.                 printf ("num_keys is %d\n",K->num_keys);
  336.                 printf ("min_keycode is %d\n",K->min_keycode);
  337.                 printf ("max_keycode is %d\n\n",K->max_keycode);
  338.                 }
  339.             break;
  340.             case ButtonClass:
  341.             b = (XButtonInfoPtr) any;
  342.             if (Dflag)
  343.                 printf ("num_buttons is %d\n\n",b->num_buttons);
  344.             break;
  345.             case ValuatorClass:
  346.             v = (XValuatorInfoPtr) any;
  347.             a = (XAxisInfoPtr) ((char *) v + 
  348.                 sizeof (XValuatorInfo));
  349.             if (Dflag)
  350.                 printf ("num_axes is %d\n\n",v->num_axes);
  351.             for (k=0; k<v->num_axes; k++,a++)
  352.                 {
  353.                 if (Dflag)
  354.                 {
  355.                 printf ("min_value is %d\n",a->min_value);
  356.                 printf ("max_value is %d\n",a->max_value);
  357.                 printf ("resolution is %d\n\n",a->resolution);
  358.                 }
  359.                 }
  360.             break;
  361.             default:
  362.             printf ("unknown class\n");
  363.             }
  364.         any = (XAnyClassPtr) ((char *) any + any->length);
  365.         }
  366.         }
  367.     }
  368.     return (slist);
  369.     }
  370.  
  371.  
  372. /******************************************************************
  373.  *
  374.  * This function finds input class information of a given class.
  375.  *
  376.  */
  377.  
  378. XAnyClassPtr
  379. FindInputClass (list, class)
  380.     XDeviceInfoPtr    list;
  381.     int            class;
  382.     {
  383.     int            i;
  384.     XAnyClassPtr       any;
  385.  
  386.     any = (XAnyClassPtr) (list->inputclassinfo);
  387.     for (i=0; i<list->num_classes; i++)
  388.     {
  389.     if (any->class == class)
  390.         return (any);
  391.     any = (XAnyClassPtr) ((char *) any + any->length);
  392.     }
  393.     }
  394.  
  395. /******************************************************************
  396.  *
  397.  * This function opens all extension input devices.
  398.  *
  399.  */
  400.  
  401. open_all_devices (display, list, ndevices)
  402.     Display        *display;
  403.     XDeviceInfoPtr     list;
  404.     int            ndevices;
  405.     {
  406.     int            valid;
  407.     int            i,j;
  408.     XDevice        *dev;
  409.     XDevice        *XOpenDevice();
  410.     XInputClassInfo    *ip;
  411.  
  412.     for (i=0; i<ndevices; i++, list++)
  413.     if (list->use != IsXPointer &&
  414.         list->use != IsXKeyboard)
  415.         {
  416.         dev = XOpenDevice (display, list->id);
  417.         sdev[i] = dev;
  418.         if (Dflag)
  419.         printf ("\nOpened device %s id is %d\n",
  420.             list->name, dev->device_id);
  421.         for (ip= dev->classes, j=0; j<dev->num_classes; j++, ip++)
  422.         {
  423.         if (Dflag)
  424.             {
  425.             printf ("class is %d\n",ip->input_class);
  426.             printf ("event type base is %x\n\n",ip->event_type_base);
  427.             }
  428.         if (ip->input_class == KeyClass)
  429.             {
  430.             keydevice = dev;
  431.             valid = class[dev->device_id].valid++;
  432.                 DeviceKeyPress (dev, devicekeypress, 
  433.             class[dev->device_id].class[valid]);
  434.             valid = class[dev->device_id].valid++;
  435.                 DeviceKeyRelease (dev, devicekeyrelease, 
  436.             class[dev->device_id].class[valid]);
  437.             if (Dflag)
  438.             {
  439.             printf ("DeviceKeyPress reports: type=%x class=%x\n",
  440.                 devicekeypress, 
  441.                 class[dev->device_id].class[valid]);
  442.             printf ("DeviceKeyRelease reports: type=%x class=%x\n",
  443.                 devicekeyrelease, 
  444.                 class[dev->device_id].class[valid]);
  445.                     printf("\n");
  446.             }
  447.             }
  448.         else if (ip->input_class == ButtonClass)
  449.             {
  450.             valid = class[dev->device_id].valid++;
  451.                 DeviceButtonPress (dev, devicebuttonpress, 
  452.             class[dev->device_id].class[valid]);
  453.             valid = class[dev->device_id].valid++;
  454.                 DeviceButtonRelease (dev, devicebuttonrelease, 
  455.             class[dev->device_id].class[valid]);
  456.             if (Dflag)
  457.             {
  458.             printf ("DeviceButtonPress reports: type=%x class=%x\n",
  459.                 devicebuttonpress, 
  460.                 class[dev->device_id].class[valid-1]);
  461.             printf ("DeviceButtonRelease: type=%x class=%x\n",
  462.                 devicebuttonrelease, 
  463.                 class[dev->device_id].class[valid]);
  464.             printf("\n");
  465.             }
  466.             }
  467.         else if (ip->input_class == ValuatorClass)
  468.             {
  469.             valid = class[dev->device_id].valid++;
  470.                 DeviceMotionNotify (dev, devicemotionnotify, 
  471.             class[dev->device_id].class[valid]);
  472.             if (Dflag)
  473.             printf ("DeviceMotionNotify: type=%x class=%x\n",
  474.                 devicemotionnotify, 
  475.                 class[dev->device_id].class[valid]);
  476.             }
  477.         else if (ip->input_class == FocusClass)
  478.             {
  479.             valid = class[dev->device_id].valid++;
  480.                 DeviceFocusIn (dev, devicefocusin, 
  481.             class[dev->device_id].class[valid]);
  482.             valid = class[dev->device_id].valid++;
  483.                 DeviceFocusOut (dev, devicefocusout, 
  484.             class[dev->device_id].class[valid]);
  485.             if (Dflag)
  486.             {
  487.             printf ("DeviceFocusIn: type=%x class=%x\n",
  488.                 devicefocusin, 
  489.                 class[dev->device_id].class[valid-1]);
  490.             printf ("DeviceFocusOut: type=%x class=%x\n",
  491.                 devicefocusout, class[dev->device_id].class[valid]);
  492.             }
  493.             }
  494.         else if (ip->input_class == ProximityClass)
  495.             {
  496.             valid = class[dev->device_id].valid++;
  497.                 ProximityIn (dev, proximityin, 
  498.             class[dev->device_id].class[valid]);
  499.             valid = class[dev->device_id].valid++;
  500.                 ProximityOut (dev, proximityout, 
  501.             class[dev->device_id].class[valid]);
  502.             if (Dflag)
  503.             {
  504.             printf ("ProximityIn: type=%x class=%x\n",
  505.                 proximityin, class[dev->device_id].class[valid-1]);
  506.             printf ("ProximityOut: type=%x class=%x\n",
  507.                 proximityout, class[dev->device_id].class[valid]);
  508.             }
  509.             }
  510.         else if (ip->input_class == OtherClass)
  511.             {
  512.             valid = class[dev->device_id].valid++;
  513.                 DeviceMappingNotify (dev, devicemappingnotify, 
  514.             class[dev->device_id].class[valid]);
  515.             valid = class[dev->device_id].valid++;
  516.                 DeviceStateNotify (dev, devicestatenotify, 
  517.             class[dev->device_id].class[valid]);
  518.             valid = class[dev->device_id].valid++;
  519.                 ChangeDeviceNotify (dev, changedevicenotify, 
  520.             class[dev->device_id].class[valid]);
  521.             if (Dflag)
  522.             {
  523.             printf ("DeviceMappingNotify: type=%x class=%x\n",
  524.                 devicemappingnotify, 
  525.                 class[dev->device_id].class[valid-2]);
  526.             printf ("DeviceStateNotify: type=%x class=%x\n",
  527.                 devicestatenotify, 
  528.                 class[dev->device_id].class[valid-1]);
  529.             printf ("ChangeDeviceNotify: type=%x class=%x\n",
  530.                 changedevicenotify, 
  531.                 class[dev->device_id].class[valid]);
  532.                 }
  533.             }
  534.         }
  535.         }
  536.     }
  537.  
  538. /******************************************************************
  539.  *
  540.  * This function manipulates the button mapping of an extension
  541.  * device that supports input class buttons.
  542.  *
  543.  */
  544.  
  545. do_button_mapping (display, dev, list)
  546.     Display        *display;
  547.     XDevice        *dev;
  548.     XDeviceInfoPtr    *list;
  549.     {
  550.     int            status = 0;
  551.     int            i;
  552.     int         len;
  553.     unsigned char    map[256];
  554.     unsigned char    map2[256];
  555.     unsigned char    smap[256];
  556.     XButtonInfoPtr     b;
  557.     XEvent         event;
  558.     XDeviceMappingEvent *m = (XDeviceMappingEvent *) &event;;
  559.  
  560.  
  561.     for (i=0; i<256; i++)
  562.     map2[i] = 255-i;
  563.     b = (XButtonInfoPtr) FindInputClass (list, ButtonClass);
  564.     if (b == NULL)
  565.     return;
  566.  
  567.     len = XGetDeviceButtonMapping (display, dev, smap, b->num_buttons);
  568.     if (Dflag)
  569.     {
  570.     printf ("\n");
  571.     for (i=0; i<len; i++)
  572.         printf ("len is %d map[%d] is %d\n", len, i, smap[i]);
  573.     printf ("\n");
  574.     }
  575.     status = XSetDeviceButtonMapping (display, dev, map2, len);
  576.     XSync (display, 0);
  577.     if (status != MappingBusy)
  578.     {
  579.     status = -1;
  580.     while (XPending (display) > 0)
  581.         {
  582.         XNextEvent (display, &event);
  583.         process_device_events (m, NOPRINT);
  584.         if (m->type == devicemappingnotify &&
  585.             m->request == MappingPointer)
  586.             status = 0;
  587.         }
  588.     }
  589.     XGetDeviceButtonMapping (display, dev, map, len);
  590.     for (i=0; i<len; i++)
  591.     if (map[i] != map2[i])
  592.         status = -1;
  593.     if (Dflag)
  594.     {
  595.     printf ("\n");
  596.     for (i=0; i<len; i++)
  597.         printf ("len is %d map[%d] is %d\n", len, i, map[i]);
  598.         printf ("\n");
  599.     }
  600.     status = XSetDeviceButtonMapping (display, dev, smap, len);
  601.     XSync (display, 0);
  602.     if (status != MappingBusy)
  603.     {
  604.     status = -1;
  605.     while (XPending (display) > 0)
  606.         {
  607.         XNextEvent (display,&event);
  608.         process_device_events (m, NOPRINT);
  609.         if (m->type == devicemappingnotify &&
  610.             m->request == MappingPointer)
  611.             status = 0;
  612.         }
  613.     }
  614.     if (status == 0)
  615.     printf ("Test of XGet/ SetDeviceButtonMapping passed.\n");
  616.     else
  617.     printf ("Test of XGet/ SetDeviceButtonMapping failed.\n");
  618.     }
  619.  
  620. /******************************************************************
  621.  *
  622.  * This function selects all available input from an extension 
  623.  * device.
  624.  *
  625.  */
  626.  
  627. select_all_input (display, win, name, dev)
  628.     Display    *display;
  629.     Window    win;
  630.     char    *name;
  631.     XDevice    *dev;
  632.     {
  633.     int            i, j;
  634.     int            status = 0;
  635.     int            this_client_count;
  636.     int            all_clients_count;
  637.     XEventClass        *this_client, *s_this;
  638.     XEventClass        *all_clients, *s_all;
  639.  
  640.     if (Dflag)
  641.     printf ("Selecting input from %s.\n", name);
  642.     XSelectExtensionEvent (display, win, 
  643.     &(class[dev->device_id].class[0]), 
  644.     class[dev->device_id].valid);
  645.     XGetSelectedExtensionEvents (display, win, &this_client_count,
  646.     &this_client, &all_clients_count, &all_clients);
  647.    
  648.     s_this = this_client;
  649.     s_all = all_clients;
  650.     for (i=0; i<2; i++)
  651.     {
  652.         for (j=0; j<this_client_count; j++)
  653.         if (*this_client++ == class[dev->device_id].class[i])
  654.         break;
  655.     if (j==this_client_count)
  656.         status = -1;
  657.     }
  658.  
  659.     if (Dflag)
  660.     {
  661.     printf ("This_client_count is %d, all_clients_count is %d\n",
  662.         this_client_count, all_clients_count);
  663.     this_client = s_this;
  664.     all_clients = s_all;
  665.     for (i=0; i<this_client_count; i++)
  666.         printf ("This_client class[i] is %x\n", *this_client++);
  667.     for (i=0; i<all_clients_count; i++)
  668.         printf ("All_clients class[i] is %x\n", *all_clients++);
  669.     printf ("\n");
  670.     }
  671.  
  672.     if (status == 0)
  673.     printf ("Test of XSelect/ XGetSelectedExtensionEvents passed.\n");
  674.     else
  675.     printf ("Test of XSelect/ XGetSelectedExtensionEvents failed.\n");
  676.     }
  677.  
  678. /******************************************************************
  679.  *
  680.  * This function manipulates the do_not_propagate list for a window.
  681.  *
  682.  */
  683.  
  684. do_propagate_list (display, win, name, dev)
  685.     Display    *display;
  686.     Window    win;
  687.     char    *name;
  688.     XDevice    *dev;
  689.     {
  690.     int        i;
  691.     int        status = 0;
  692.     int        count, scount;
  693.     XEventClass    tlist[2];
  694.     XEventClass    *list, *slist;
  695.  
  696.     slist = (XEventClass *) 
  697.     XGetDeviceDontPropagateList (display, win, &count);
  698.     scount = count;
  699.  
  700.     XChangeDeviceDontPropagateList (display, win, count, slist, 
  701.     DeleteFromList);
  702.  
  703.     list = (XEventClass *) 
  704.     XGetDeviceDontPropagateList (display, win, &count);
  705.  
  706.     if (count > 0)
  707.     status = -1;
  708.  
  709.     XChangeDeviceDontPropagateList (display, win, scount, slist, 
  710.     AddToList);
  711.  
  712.     list = (XEventClass *) 
  713.     XGetDeviceDontPropagateList (display, win, &count);
  714.  
  715.     if (count != scount)
  716.     status = -1;
  717.  
  718.     for (i=0; i<scount; i++)
  719.     if (*list != *slist)
  720.         status = -1;
  721.  
  722.     if (status == 0)
  723.     printf ("Test of XGet/ XChangeDeviceDontPropagateList passed.\n");
  724.     else
  725.     printf ("Test of XGet/ XChangeDeviceDontPropagateList failed.\n");
  726.     }
  727.  
  728. /******************************************************************
  729.  *
  730.  * This function gets and sets the focus for extension input devices.
  731.  *
  732.  * Valid cases:
  733.  *    1). focus = None
  734.  *    2). focus = PointerRoot
  735.  *    3). focus = FollowKeyboard
  736.  *    4). focus = window id
  737.  *    5). time invalid
  738.  *    6). while grabbed & not grabbed.
  739.  */
  740.  
  741. focus_input_device (display, name, dev, win)
  742.     Display    *display;
  743.     char    *name;
  744.     XDevice    *dev;
  745.     Window    win;
  746.     {
  747.     int            status = -1;
  748.     Window        sfocus;
  749.     Window        focus;
  750.     int            revert_to;
  751.     int            focus_time;
  752.     Window        root = RootWindow (display, 0);
  753.     XEvent        event;
  754.     XDeviceFocusChangeEvent    *f = (XDeviceFocusChangeEvent *) &event;
  755.  
  756.     XGetDeviceFocus (display, dev, &sfocus, &revert_to, &focus_time);
  757.     if (Dflag)
  758.     printf ("focus for %s is %x, revert_to is %x time is %x\n",
  759.         name, sfocus, revert_to, focus_time);
  760.  
  761.     XSetDeviceFocus (display, dev, None, RevertToNone, CurrentTime);
  762.     XSync (display, 0);
  763.     while (XPending (display) > 0)
  764.     {
  765.     XNextEvent (display,&event);
  766.     process_device_events (&event, NOPRINT);
  767.     if ((f->type == devicefocusin || f->type == devicefocusout) &&
  768.         f->deviceid == dev->device_id)
  769.         status = 0;
  770.     }
  771.     XGetDeviceFocus (display, dev, &focus, &revert_to, &focus_time);
  772.     if (focus != None || revert_to != RevertToNone)
  773.     status = -1;
  774.  
  775.     XSetDeviceFocus (display, dev, root, RevertToParent, 
  776.     CurrentTime);
  777.     XSync (display, 0);
  778.     while (XPending (display) > 0)
  779.     {
  780.     XNextEvent (display,&event);
  781.     process_device_events (&event, NOPRINT);
  782.     if ((f->type == devicefocusin || f->type == devicefocusout) &&
  783.         f->deviceid == dev->device_id)
  784.         status = 0;
  785.     }
  786.     XGetDeviceFocus (display, dev, &focus, &revert_to, &focus_time);
  787.     if (focus != root || revert_to != RevertToParent)
  788.     status = -1;
  789.  
  790.     XSetDeviceFocus (display, dev, PointerRoot, RevertToPointerRoot, 
  791.     CurrentTime);
  792.     XSync (display, 0);
  793.     while (XPending (display) > 0)
  794.     {
  795.     XNextEvent (display,&event);
  796.     process_device_events (&event, NOPRINT);
  797.     if ((f->type == devicefocusin || f->type == devicefocusout) &&
  798.         f->deviceid == dev->device_id)
  799.         status = 0;
  800.     }
  801.     XGetDeviceFocus (display, dev, &focus, &revert_to, &focus_time);
  802.     if (focus != PointerRoot || revert_to != RevertToPointerRoot)
  803.     status = -1;
  804.  
  805.     XSetDeviceFocus (display, dev, FollowKeyboard, RevertToFollowKeyboard, 
  806.     CurrentTime);
  807.     XSync (display, 0);
  808.     while (XPending (display) > 0)
  809.     {
  810.     XNextEvent (display,&event);
  811.     process_device_events (&event, NOPRINT);
  812.     if ((f->type == devicefocusin || f->type == devicefocusout) &&
  813.         f->deviceid == dev->device_id)
  814.         status = 0;
  815.     }
  816.     XGetDeviceFocus (display, dev, &focus, &revert_to, &focus_time);
  817.     if (focus != FollowKeyboard || revert_to != RevertToFollowKeyboard)
  818.     status = -1;
  819.  
  820.     XSetDeviceFocus (display, dev, FollowKeyboard, RevertToPointerRoot, 
  821.     CurrentTime);
  822.     XSync (display, 0);
  823.     while (XPending (display) > 0)
  824.     {
  825.     XNextEvent (display,&event);
  826.     process_device_events (&event, NOPRINT);
  827.     if ((f->type == devicefocusin || f->type == devicefocusout) &&
  828.         f->deviceid == dev->device_id)
  829.         status = 0;
  830.     }
  831.     XGetDeviceFocus (display, dev, &focus, &revert_to, &focus_time);
  832.     if (focus != FollowKeyboard || revert_to != RevertToPointerRoot)
  833.     status = -1;
  834.     if (Dflag)
  835.     printf ("focus for %s is %x, revert_to is %x time is %x\n",
  836.         name, focus, revert_to, focus_time);
  837.  
  838.     if (status == 0)
  839.     printf ("Test of XGet/ XSetDeviceFocus passed.\n");
  840.     else
  841.     printf ("Test of XGet/ XSetDeviceFocus failed.\n");
  842.     }
  843.  
  844. /******************************************************************
  845.  *
  846.  * This function grabs extension input devices.
  847.  *
  848.  * Valid cases:
  849.  *    1). AlreadyGrabbed.
  850.  *    2). GrabInvalidTime.
  851.  *    3). GrabFrozen.
  852.  *    4). GrabNotViewable.
  853.  *    5). focus state was FollowKeyboard.
  854.  *
  855.  */
  856.  
  857. grab_input_device (display, name, dev, win1, win2, win3)
  858.     Display    *display;
  859.     char    *name;
  860.     XDevice    *dev;
  861.     Window    win1, win2, win3;
  862.     {
  863.     int        i;
  864.     char    *p1, *p2;
  865.     XEvent     event;
  866.     XDeviceKeyEvent     *k = (XDeviceKeyEvent *) &event;
  867.     int        status = -1;
  868.     int        tstatus = -1;
  869.     int        ret = -1;
  870.     XEvent    saveevent;
  871.     XDeviceFocusChangeEvent *f = (XDeviceFocusChangeEvent *) &event;
  872.     Time    time;
  873.  
  874.     tstatus = XGrabDevice (display, dev, win1, True,
  875.     class[dev->device_id].valid, &class[dev->device_id].class[0], 
  876.     GrabModeAsync, GrabModeAsync, CurrentTime);
  877.     XSync (display,0);
  878.     if (tstatus == Success)
  879.     {
  880.     status = -1;
  881.     while (XPending (display) > 0)
  882.         {
  883.         XNextEvent (display,&event);
  884.         if (f->type == devicefocusin)
  885.         {
  886.         time = f->time;
  887.         status = 0;
  888.         }
  889.         }
  890.     }
  891.     else
  892.     printf ("GrabDevice failed.\n");
  893.  
  894.     tstatus = XGrabDevice (display, dev, win1, True,
  895.     class[dev->device_id].valid, &class[dev->device_id].class[0], 
  896.     GrabModeAsync, GrabModeAsync, time - 1);
  897.     XSync (display,0);
  898.     if (tstatus != GrabInvalidTime)
  899.     {
  900.     printf ("GrabDevice did not return Invalidtime as it should have.\n");
  901.     status = tstatus;
  902.     }
  903.  
  904.     tstatus = XGrabDevice (display, dev, win3, True,
  905.     class[dev->device_id].valid, 
  906.     &class[dev->device_id].class[0], 
  907.     GrabModeAsync, GrabModeAsync, CurrentTime);
  908.     if (tstatus != GrabNotViewable)
  909.     {
  910.     printf ("GrabDevice didn't return GrabNotViewable as it should.\n");
  911.     printf ("Status = %d\n",tstatus);
  912.     status = tstatus;
  913.     }
  914.  
  915.     status = XGrabDevice (display, dev, win1, True,
  916.     class[dev->device_id].valid, 
  917.     &class[dev->device_id].class[0], 
  918.     GrabModeAsync, GrabModeAsync, CurrentTime);
  919.  
  920.     status = XGrabDevice (display, dev, win1, True,
  921.     class[dev->device_id].valid, 
  922.     &class[dev->device_id].class[0], 
  923.     GrabModeSync, GrabModeAsync, CurrentTime);
  924.  
  925.     status = XGrabDevice (display, dev, win1, True,
  926.     class[dev->device_id].valid, 
  927.     &class[dev->device_id].class[0], 
  928.     GrabModeAsync, GrabModeSync, CurrentTime);
  929.  
  930.     status = XGrabDevice (display, dev, win1, True,
  931.     class[dev->device_id].valid, 
  932.     &class[dev->device_id].class[0], 
  933.     GrabModeSync, GrabModeSync, CurrentTime);
  934.  
  935.     if (Dflag)
  936.     printf ("grab status is %x.\n", status);
  937.  
  938.     if (status == GrabSuccess)
  939.     printf ("Test of XGrabDevice passed.\n");
  940.     else
  941.     printf ("Test of XGrabDevice failed.\n");
  942.     }
  943.  
  944. /******************************************************************
  945.  *
  946.  * This function grabs keys on extension input devices.
  947.  *
  948.  */
  949.  
  950. grab_device_key (display, name, dev, win1, win2)
  951.     Display    *display;
  952.     char    *name;
  953.     XDevice    *dev;
  954.     Window    win1, win2;
  955.     {
  956.     int        status = -1;
  957.  
  958.     XGrabDeviceKey (display, dev, AnyKey, AnyModifier, dev, win1, True, 
  959.     class[dev->device_id].valid,
  960.     &class[dev->device_id].class[0], GrabModeAsync, GrabModeAsync);
  961.     }
  962.  
  963. /******************************************************************
  964.  *
  965.  * This function ungrabs keys on extension input devices.
  966.  *
  967.  */
  968.  
  969. ungrab_device_key (display, name, dev, win1, win2)
  970.     Display    *display;
  971.     char    *name;
  972.     XDevice    *dev;
  973.     Window    win1, win2;
  974.     {
  975.  
  976.     XUngrabDeviceKey (display, dev, AnyKey, AnyModifier, dev, win1);
  977.     }
  978.  
  979. /******************************************************************
  980.  *
  981.  * This function grabs buttons on extension input devices.
  982.  *
  983.  */
  984.  
  985. grab_device_button (display, name, dev, win1, win2)
  986.     Display    *display;
  987.     char    *name;
  988.     XDevice    *dev;
  989.     Window    win1, win2;
  990.     {
  991.     int        status = -1;
  992.  
  993.     XGrabDeviceButton (display, dev, AnyButton, AnyModifier, keydevice, win1, 
  994.     True, 
  995.     class[dev->device_id].valid, 
  996.     &class[dev->device_id].class[0], GrabModeAsync, GrabModeAsync);
  997.     }
  998.  
  999. /******************************************************************
  1000.  *
  1001.  * This function ungrabs buttons on extension input devices.
  1002.  *
  1003.  */
  1004.  
  1005. ungrab_device_button (display, name, dev, win1, win2)
  1006.     Display    *display;
  1007.     char    *name;
  1008.     XDevice    *dev;
  1009.     Window    win1, win2;
  1010.     {
  1011.  
  1012.     XUngrabDeviceButton (display, dev, AnyButton, AnyModifier, keydevice, win1);
  1013.     }
  1014.  
  1015. /******************************************************************
  1016.  *
  1017.  * This function ungrabs extension input devices.
  1018.  *
  1019.  */
  1020.  
  1021. ungrab_input_device (display, name, dev)
  1022.     Display    *display;
  1023.     char    *name;
  1024.     XDevice    *dev;
  1025.     {
  1026.     int        ret;
  1027.  
  1028.     XUngrabDevice (display, dev, CurrentTime);
  1029.     }
  1030.  
  1031. /******************************************************************
  1032.  *
  1033.  * This function exercises the device key mapping functions.
  1034.  *
  1035.  */
  1036.  
  1037. do_key_mapping (display, name, dev, list)
  1038.     Display        *display;
  1039.     char        *name;
  1040.     XDevice        *dev;
  1041.     XDeviceInfoPtr    list;
  1042.     {
  1043.     int        status = 0;
  1044.     int        l=0;
  1045.     int        i, j, iret;
  1046.     int        ksyms_per_code = 2;
  1047.     XKeyInfoPtr k;
  1048.     KeySym    save[1024];
  1049.     KeySym    *ret = NULL;
  1050.     KeySym    *sret = NULL;
  1051.     XEvent    event;
  1052.     XDeviceMappingEvent    *m = (XDeviceMappingEvent *) &event;
  1053.  
  1054.     k = (XKeyInfoPtr) FindInputClass (list, KeyClass);
  1055.     if (k == NULL)
  1056.     return;
  1057.  
  1058.     ret = XGetDeviceKeyMapping (display, dev, k->min_keycode, 
  1059.     k->num_keys, &ksyms_per_code);
  1060.  
  1061.     sret = ret;
  1062.  
  1063.     if (Dflag)
  1064.     {
  1065.         printf ("keysyms per keycode for device %s is %d\n",
  1066.         name, ksyms_per_code);
  1067.         printf ("before values for device %s:\n", name);
  1068.         printf ("    syms_per_code is: %d\n",ksyms_per_code);
  1069.         for (i=0; i<k->num_keys; i++)
  1070.         {
  1071.         printf ("syms for code %d: ",k->min_keycode+i);
  1072.         for (j=0; j<ksyms_per_code; j++,ret++)
  1073.            printf ("%x ",(*ret)++);
  1074.         printf ("\n");
  1075.         }
  1076.     }
  1077.  
  1078.     ret = sret;
  1079.     for (i=0; i<k->num_keys; i++)
  1080.     for (j=0; j<ksyms_per_code; j++,ret++)
  1081.         {
  1082.         save[l++] = *ret;
  1083.         *ret = (KeySym) i*10+j;
  1084.         }
  1085.  
  1086.     iret = XChangeDeviceKeyMapping (display, dev, k->min_keycode, 
  1087.     ksyms_per_code, sret, k->num_keys);
  1088.     XSync (display, 0);
  1089.     status = -1;
  1090.     while (XPending (display) > 0)
  1091.     {
  1092.     XNextEvent (display,&event);
  1093.     process_device_events (m, NOPRINT);
  1094.     if (m->type == devicemappingnotify &&
  1095.         m->request == MappingKeyboard &&
  1096.         m->first_keycode == k->min_keycode)
  1097.         status = 0;
  1098.     }
  1099.     ret = XGetDeviceKeyMapping (display, dev, k->min_keycode, 
  1100.     k->num_keys, &ksyms_per_code);
  1101.     sret = ret;
  1102.  
  1103.     for (i=0; i<k->num_keys; i++)
  1104.         for (j=0; j<ksyms_per_code; j++)
  1105.         {
  1106.         if (*ret != (KeySym) i*10+j)
  1107.         status = -1;
  1108.         ret++;
  1109.         }
  1110.  
  1111.     ret = sret;
  1112.  
  1113.     if (Dflag)
  1114.     {
  1115.         printf ("after values for device %s:\n", name);
  1116.         for (i=0; i<k->num_keys; i++)
  1117.         {
  1118.         printf ("syms for code %d: ",k->min_keycode+i);
  1119.             for (j=0; j<ksyms_per_code; j++)
  1120.            printf ("%x ",(*ret)++);
  1121.             printf ("\n");
  1122.         }
  1123.         printf ("\n");
  1124.     }
  1125.  
  1126.     iret = XChangeDeviceKeyMapping (display, dev, k->min_keycode, 
  1127.     ksyms_per_code, save, k->num_keys);
  1128.     process_events (display,NOPRINT);
  1129.     if (status == 0)
  1130.     printf ("Test of XGet/ XChangeDeviceKeyMapping passed.\n");
  1131.     else
  1132.     printf ("Test of XGet/ XChangeDeviceKeyMapping failed.\n");
  1133.     }
  1134.  
  1135. /******************************************************************
  1136.  *
  1137.  * This function exercises the device modifier mapping functions.
  1138.  *
  1139.  */
  1140.  
  1141. do_modifier_mapping (display, name, dev)
  1142.     Display    *display;
  1143.     char    *name;
  1144.     XDevice    *dev;
  1145.     {
  1146.     int            tstatus = 0;
  1147.     int            status = 0;
  1148.     int            i,j;
  1149.     int            k=0;
  1150.     int            iret;
  1151.     XModifierKeymap    *ret = NULL;
  1152.     KeyCode        *first;
  1153.     KeyCode        savcodes[256];
  1154.     XEvent         event;
  1155.     XDeviceMappingEvent *m = (XDeviceMappingEvent *) &event;
  1156.  
  1157.     ret = XGetDeviceModifierMapping (display, dev);
  1158.     if (Dflag)
  1159.     {
  1160.     printf ("before values for device %s:\n", name);
  1161.     printf ("    max_keypermod is: %d\n",ret->max_keypermod);
  1162.     printf ("codes for modifiers\n");
  1163.     first = ret->modifiermap;
  1164.     for (i=0; i<ret->max_keypermod; i++)
  1165.         {
  1166.         for (j=0; j<8; j++)
  1167.             printf ("%x ",(*first)++);
  1168.         printf ("\n");
  1169.         }
  1170.     }
  1171.  
  1172.     first = ret->modifiermap;
  1173.     for (i=0; i<ret->max_keypermod; i++)
  1174.     for (j=0; j<8; j++,first++)
  1175.         {
  1176.         savcodes[k++] = *first;
  1177.         *first = (KeyCode) (i+1)*10+j;
  1178.         }
  1179.  
  1180.     tstatus = XSetDeviceModifierMapping (display, dev, ret);
  1181.     XSync (display, 0);
  1182.     if (tstatus == MappingSuccess)
  1183.     {
  1184.     status = -1;
  1185.     while (XPending (display) > 0)
  1186.         {
  1187.         XNextEvent (display,&event);
  1188.         process_device_events (m, NOPRINT);
  1189.         if (m->type == devicemappingnotify &&
  1190.             m->request == MappingModifier)
  1191.             status = 0;
  1192.         }
  1193.     }
  1194.     ret = XGetDeviceModifierMapping (display, dev);
  1195.  
  1196.     if (Dflag)
  1197.     {
  1198.     printf ("after values for device %s:\n", name);
  1199.     printf ("    max_keypermod is: %d\n",ret->max_keypermod);
  1200.     printf ("codes for modifiers\n");
  1201.     }
  1202.     first = ret->modifiermap;
  1203.  
  1204.     for (i=0; i<ret->max_keypermod; i++)
  1205.     for (j=0; j<8; j++,first++)
  1206.         if (*first != (KeyCode) (i+1)*10+j)
  1207.         status = -1;
  1208.  
  1209.     if (Dflag)
  1210.     {
  1211.         first = ret->modifiermap;
  1212.     for (i=0; i<ret->max_keypermod; i++)
  1213.         {
  1214.         for (j=0; j<8; j++)
  1215.         printf ("%x ",(*first)++);
  1216.         printf ("\n");
  1217.         }
  1218.     printf ("\n");
  1219.     }
  1220.  
  1221.     ret->modifiermap = savcodes;
  1222.     tstatus = XSetDeviceModifierMapping (display, dev, ret);
  1223.     if (tstatus == MappingSuccess)
  1224.     process_events (display, NOPRINT);
  1225.  
  1226.     if (status == 0)
  1227.     printf ("Test of XGet/ SetDeviceModifierMap passed.\n");
  1228.     else
  1229.     printf ("Test of XGet/ SetDeviceModifierMap failed.\n");
  1230.     }
  1231.  
  1232. /******************************************************************
  1233.  *
  1234.  * This function gets the motion history for a device that supports
  1235.  * input class Valuators.
  1236.  *
  1237.  */
  1238.  
  1239. get_motion_history (display, name, dev)
  1240.     Display    *display;
  1241.     char    *name;
  1242.     XDevice    *dev;
  1243.     {
  1244.     Time        start = CurrentTime;
  1245.     Time        stop = CurrentTime;
  1246.     int            nevents;
  1247.     int            mode;
  1248.     int            axis_count;
  1249.     XDeviceTimeCoord    *events;
  1250.  
  1251.     events = XGetDeviceMotionEvents (display, dev, start, stop, &nevents,
  1252.     &mode, &axis_count);
  1253.     if (Dflag)
  1254.     printf ("nevents is %d mode is %d axis_count is %d\n",
  1255.        nevents, mode, axis_count);
  1256.     XFreeDeviceMotionEvents (events);
  1257.     }
  1258.  
  1259. /******************************************************************
  1260.  *
  1261.  * This function queries the extension version.
  1262.  *
  1263.  */
  1264.  
  1265. query_extension_version (display)
  1266.     {
  1267.     int            status = 0;
  1268.     XExtensionVersion     *ext;
  1269.  
  1270.     ext = XGetExtensionVersion(display, "XInputExtension");
  1271.  
  1272.     if (ext->present && status == 0)
  1273.     printf ("Test of XGetExtensionVersion passed.\n");
  1274.     else
  1275.     printf ("Test of XGetExtensionVersion failed.\n");
  1276.  
  1277.     if (Dflag)
  1278.     {
  1279.         printf ("present is %d\n", ext->present);
  1280.         printf ("major version is %d\n", ext->major_version);
  1281.         printf ("minor version is %d\n", ext->minor_version);
  1282.     }
  1283.     }
  1284.  
  1285. /******************************************************************
  1286.  *
  1287.  * This function queries the state of a device.
  1288.  *
  1289.  */
  1290.  
  1291. query_device_state (display, name, dev)
  1292.     Display    *display;
  1293.     char    *name;
  1294.     XDevice    *dev;
  1295.     {
  1296.     int            i;
  1297.     XDeviceState     *state;
  1298.     XInputClass        *class;
  1299.  
  1300.     state = XQueryDeviceState (display, dev);
  1301.     if (Dflag)
  1302.     {
  1303.     printf ("state information: device id is %d\n",state->device_id);
  1304.     printf ("     num_class is %d\n",state->num_classes);
  1305.     }
  1306.     class = state->data;
  1307.     if (Dflag)
  1308.     for (i=0; i<state->num_classes; i++)
  1309.         {
  1310.         printf ("class id is %d\n",class->class);
  1311.         printf ("length is %d\n",class->length);
  1312.         class = (XInputClass *) ((char *) class + class->length);
  1313.         }
  1314.     XFreeDeviceState (state);
  1315.     if (state != NULL)
  1316.     printf ("Test of XQueryDeviceState passed.\n");
  1317.     else
  1318.     printf ("Test of XQueryDeviceState failed.\n");
  1319.     }
  1320.  
  1321. /******************************************************************
  1322.  *
  1323.  * This function allows a frozen device to be thawed.
  1324.  *
  1325.  */
  1326.  
  1327. allow_device_event (display, name, dev)
  1328.     Display    *display;
  1329.     char    *name;
  1330.     XDevice    *dev;
  1331.     {
  1332.     XAllowDeviceEvents (display, dev, SyncAll, CurrentTime);
  1333.     XAllowDeviceEvents (display, dev, SyncThisDevice, CurrentTime);
  1334.     XAllowDeviceEvents (display, dev, ReplayThisDevice, CurrentTime);
  1335.     XAllowDeviceEvents (display, dev, AsyncThisDevice, CurrentTime);
  1336.     XAllowDeviceEvents (display, dev, AsyncOtherDevices, CurrentTime);
  1337.     XAllowDeviceEvents (display, dev, AsyncAll, CurrentTime);
  1338.     }
  1339.  
  1340. /******************************************************************
  1341.  *
  1342.  * This function gets the feedback control values of a device.
  1343.  *
  1344.  */
  1345.  
  1346. do_feedback_control (display, name, dev)
  1347.     Display    *display;
  1348.     char    *name;
  1349.     XDevice    *dev;
  1350.     {
  1351.     int            i,j;
  1352.     int            num_feedbacks;
  1353.     int            mask=0;
  1354.     XFeedbackState    *state, *sav;
  1355.     XKbdFeedbackState    *kbd;
  1356.     XPtrFeedbackState    *ptr;
  1357.     XKbdFeedbackControl    kbdf;
  1358.     XPtrFeedbackControl    ptrf;
  1359.  
  1360.     state = XGetFeedbackControl (display, dev, &num_feedbacks);
  1361.     sav = state;
  1362.     if (Dflag)
  1363.     printf ("num_feedbacks is %d\n",num_feedbacks);
  1364.  
  1365.     for (i=0; i<num_feedbacks; i++)
  1366.     {
  1367.     if (Dflag)
  1368.         {
  1369.         printf ("feedback class is %d\n",state->class);
  1370.         printf ("feedback length is %d\n",state->length);
  1371.         }
  1372.     if (state->class == KbdFeedbackClass)
  1373.         {
  1374.         kbd = (XKbdFeedbackState *) state;
  1375.         if (Dflag)
  1376.         {
  1377.             printf ("bell_pitch is %d\n",kbd->pitch);
  1378.             printf ("bell_percent is %d\n",kbd->percent);
  1379.             printf ("bell_duration is %d\n",kbd->duration);
  1380.             printf ("led_mask is %d\n",kbd->led_mask);
  1381.             printf ("global_auto_repeat is %d\n",kbd->global_auto_repeat);
  1382.             printf ("key_click_percent is %d\n",kbd->click);
  1383.             printf ("auto_repeats are:\n");
  1384.             for (j=0; j<32; j++)
  1385.                 printf ("%x ",kbd->auto_repeats[j]);
  1386.             printf ("\n");
  1387.         }
  1388.         state = (XFeedbackState *) ((char *) state + state->length);
  1389.         }
  1390.     else if (state->class == PtrFeedbackClass)
  1391.         {
  1392.         ptr = (XPtrFeedbackState *) state;
  1393.         if (Dflag)
  1394.         {
  1395.             printf ("accelNumerator is %d\n",ptr->accelNum);
  1396.             printf ("accelDenominator is %d\n",ptr->accelDenom);
  1397.             printf ("threshold is %d\n",ptr->threshold);
  1398.         }
  1399.         state = (XFeedbackState *) ((char *) state + state->length);
  1400.         }
  1401.     else 
  1402.         printf ("bogus state\n");
  1403.     }
  1404.  
  1405.     for (i=0; i<num_feedbacks; i++)
  1406.     {
  1407.     state = sav;
  1408.     if (state->class == KbdFeedbackClass)
  1409.         {
  1410.         mask = DvPercent | DvPitch | DvDuration;
  1411.         mask |= DvLed | DvKeyClickPercent | DvKey | DvAutoRepeatMode;
  1412.         kbdf.class = KbdFeedbackClass;
  1413.         kbdf.length = sizeof (XKbdFeedbackControl);
  1414.         kbdf.pitch = 33;
  1415.         kbdf.percent = 55;
  1416.         kbdf.duration = 44;
  1417.         kbdf.click = 99;
  1418.         kbdf.led_mask = 0xf0f0; 
  1419.         kbdf.led_value = 0xcf3f; 
  1420.         kbdf.key = 0x81; 
  1421.         kbdf.auto_repeat_mode = AutoRepeatModeOff; 
  1422.         XChangeFeedbackControl (display, dev, mask, &kbdf);
  1423.         }
  1424.     else if (state->class == PtrFeedbackClass)
  1425.         {
  1426.         mask = DvAccelNum | DvAccelDenom | DvThreshold;
  1427.         ptrf.class = PtrFeedbackClass;
  1428.         ptrf.length = sizeof (XPtrFeedbackControl);
  1429.         ptrf.accelNum = 10;
  1430.         ptrf.accelDenom = 2;
  1431.         ptrf.threshold = 6;
  1432.         XChangeFeedbackControl (display, dev, mask, &ptrf);
  1433.         }
  1434.     }
  1435.     XFreeFeedbackList (state);
  1436.     }
  1437.  
  1438. /******************************************************************
  1439.  *
  1440.  * This function changes the mode of a device.
  1441.  *
  1442.  */
  1443.  
  1444. set_device_mode (display, name, dev)
  1445.     Display    *display;
  1446.     char    *name;
  1447.     XDevice    *dev;
  1448.     {
  1449.     int    status;
  1450.  
  1451.     status = XSetDeviceMode (display, dev, Absolute);
  1452.     status = XSetDeviceMode (display, dev, Relative);
  1453.     }
  1454.  
  1455. /******************************************************************
  1456.  *
  1457.  * This function sends extension events to this client.
  1458.  *
  1459.  */
  1460.  
  1461. send_extension_event (display, name, dev, win)
  1462.     Display    *display;
  1463.     char    *name;
  1464.     XDevice    *dev;
  1465.     Window    win;
  1466.     {
  1467.     int            i;
  1468.     int            expect = sizeof (XDeviceKeyEvent);
  1469.     char        *p1, *p2;
  1470.     int            status;
  1471.     Bool        propagate = True;
  1472.     XEvent        send, receive;
  1473.     XDeviceKeyEvent    *sendp = (XDeviceKeyEvent *) &send;
  1474.     XDeviceKeyEvent    *receivep = (XDeviceKeyEvent *) &receive;
  1475.  
  1476.     for (i=0,p1=(char *) sendp; i<sizeof (XEvent); i++)
  1477.     *p1++ = 0;
  1478.     sendp->type = devicekeypress;
  1479.     sendp->serial =  1;
  1480.     sendp->send_event = 0;
  1481.     sendp->display = display;
  1482.     sendp->root = root;
  1483.     sendp->x = 10;
  1484.     sendp->y = 10;
  1485.     sendp->same_screen = 1;
  1486.     sendp->subwindow = win;
  1487.     sendp->deviceid = dev->device_id;
  1488.     sendp->state = 0;
  1489.     sendp->keycode = 0xd;
  1490.     sendp->axes_count = 0;
  1491.     sendp->window = win;
  1492.     sendp->x_root = 160;
  1493.     sendp->y_root = 160;
  1494.     sendp->time = 0x50505050;
  1495.     sendp->device_state = 1;
  1496.     sendp->axes_count = 6;
  1497.     sendp->first_axis = 0;
  1498.     for (i=0; i<6; i++)
  1499.         sendp->axis_data[i] = i;
  1500.  
  1501.     process_events (display, NOPRINT);
  1502.     status = XSendExtensionEvent (display, dev, win, propagate,
  1503.     class[dev->device_id].valid, &class[dev->device_id].class[0], sendp);
  1504.     XSync (display, 0);
  1505.     if (status == 0)
  1506.     {
  1507.     printf ("Test of XSendExtensionEvent failed. (Conversion failed.)\n");
  1508.     return;
  1509.     }
  1510.  
  1511.     while (XPending (display) > 0)
  1512.     {
  1513.     XNextEvent (display,&receive);
  1514.     p1 = (char *) sendp;
  1515.     p2 = (char *) receivep;
  1516.     for (i=0; i<expect; i++,p1++,p2++)
  1517.         if (*p1 != *p2 && (i<4 || i>11))
  1518.         break;
  1519.     if (i == expect)
  1520.         status = 0;
  1521.     else
  1522.         status = -1;
  1523.     }
  1524.     if (status != 0)
  1525.     printf ("Test of XSendExtensionEvent failed.\n");
  1526.     else
  1527.     printf ("Test of XSendExtensionEvent passed.\n");
  1528.     }
  1529.  
  1530. /******************************************************************
  1531.  *
  1532.  * This function displays the contents of extension events.
  1533.  *
  1534.  */
  1535.  
  1536. process_device_events (event, mode)
  1537.     XEvent    *event;
  1538.     int        mode;
  1539.     {
  1540.     int                i, j;
  1541.     char            *buf;
  1542.     XKeyStatus            *kdata;
  1543.     XButtonStatus        *bdata;
  1544.     XValuatorStatus        *vdata;
  1545.     XDeviceKeyEvent        *k;
  1546.     XDeviceButtonEvent        *b;
  1547.     XDeviceMappingEvent        *m;
  1548.     XDeviceMotionEvent        *M;
  1549.     XDeviceFocusChangeEvent    *f;
  1550.     XProximityNotifyEvent    *p;
  1551.     XChangeDeviceNotifyEvent    *c;
  1552.     XDeviceStateNotifyEvent    *s;
  1553.     XInputClass         *anyclass;
  1554.  
  1555.     if (event->type == devicekeypress)
  1556.     {
  1557.     k = (XDeviceKeyEvent * ) event;
  1558.     if (mode == PRINT)
  1559.         {
  1560.         printf ("Device key press event device=%d\n", k->deviceid);
  1561.         printf ("     type =        %d\n", k->type);
  1562.         printf ("     serial =      %ld\n", k->serial);
  1563.         printf ("     send_event =  %ld\n", k->send_event);
  1564.         printf ("     display =     %x\n", k->display);
  1565.         printf ("     window =      %x\n", k->window);
  1566.         printf ("     root =        %x\n", k->root);
  1567.         printf ("     subwindow =   %x\n", k->subwindow);
  1568.         printf ("     time =        %x\n", k->time);
  1569.         printf ("     x =           %d\n", k->x);
  1570.             printf ("     y =           %d\n", k->y);
  1571.         printf ("     x_root =      %d\n", k->x_root);
  1572.         printf ("     y_root =      %d\n", k->y_root);
  1573.         printf ("     state =       %d\n", k->state);
  1574.         printf ("     keycode =     %x\n", k->keycode);
  1575.         printf ("     same_screen = %d\n", k->same_screen);
  1576.         }
  1577.         if (k->keycode == 0xd)
  1578.         return (-1);
  1579.     }
  1580.     else if (event->type == devicekeyrelease)
  1581.     {
  1582.     k = (XDeviceKeyEvent * ) event;
  1583.     if (mode == PRINT)
  1584.         {
  1585.         printf ("Device key release event device=%d\n", k->deviceid);
  1586.         printf ("     type =        %d\n", k->type);
  1587.         printf ("     serial =      %ld\n", k->serial);
  1588.         printf ("     send_event =  %ld\n", k->send_event);
  1589.         printf ("     display =     %x\n", k->display);
  1590.         printf ("     window =      %x\n", k->window);
  1591.         printf ("     root =        %x\n", k->root);
  1592.         printf ("     subwindow =   %x\n", k->subwindow);
  1593.         printf ("     time =        %x\n", k->time);
  1594.         printf ("     x =           %d\n", k->x);
  1595.         printf ("     y =           %d\n", k->y);
  1596.         printf ("     x_root =      %d\n", k->x_root);
  1597.         printf ("     y_root =      %d\n", k->y_root);
  1598.         printf ("     state =       %d\n", k->state);
  1599.         printf ("     keycode =     %x\n", k->keycode);
  1600.         printf ("     same_screen = %d\n", k->same_screen);
  1601.         }
  1602.         if (k->keycode == 0xd)
  1603.         return (-1);
  1604.     }
  1605.     else if (event->type == devicebuttonpress)
  1606.     {
  1607.     if (mode == PRINT)
  1608.         {
  1609.         b = (XDeviceButtonEvent * ) event;
  1610.         printf ("Device button press event device=%d\n", b->deviceid);
  1611.         printf ("     type =        %d\n", b->type);
  1612.         printf ("     serial =      %ld\n", b->serial);
  1613.         printf ("     send_event =  %ld\n", b->send_event);
  1614.         printf ("     display =     %x\n", b->display);
  1615.         printf ("     window =      %x\n", b->window);
  1616.         printf ("     root =        %x\n", b->root);
  1617.         printf ("     subwindow =   %x\n", b->subwindow);
  1618.         printf ("     time =        %x\n", b->time);
  1619.         printf ("     x =           %d\n", b->x);
  1620.         printf ("     y =           %d\n", b->y);
  1621.         printf ("     x_root =      %d\n", b->x_root);
  1622.         printf ("     y_root =      %d\n", b->y_root);
  1623.         printf ("     state =       %d\n", b->state);
  1624.         printf ("     button =      %x\n", b->button);
  1625.         printf ("     same_screen = %d\n", b->same_screen);
  1626.         }
  1627.     }
  1628.     else if (event->type == devicebuttonrelease)
  1629.      {
  1630.     if (mode == PRINT)
  1631.         {
  1632.         b = (XDeviceButtonEvent * ) event;
  1633.         printf ("Device button release event device=%d\n", b->deviceid);
  1634.         printf ("     type =        %d\n", b->type);
  1635.         printf ("     serial =      %ld\n", b->serial);
  1636.         printf ("     send_event =  %ld\n", b->send_event);
  1637.         printf ("     display =     %x\n", b->display);
  1638.         printf ("     window =      %x\n", b->window);
  1639.         printf ("     root =        %x\n", b->root);
  1640.         printf ("     subwindow =   %x\n", b->subwindow);
  1641.         printf ("     time =        %x\n", b->time);
  1642.         printf ("     x =           %d\n", b->x);
  1643.         printf ("     y =           %d\n", b->y);
  1644.         printf ("     x_root =      %d\n", b->x_root);
  1645.         printf ("     y_root =      %d\n", b->y_root);
  1646.         printf ("     state =       %d\n", b->state);
  1647.         printf ("     button =      %x\n", b->button);
  1648.         printf ("     same_screen = %d\n", b->same_screen);
  1649.             }
  1650.         }
  1651.     else if (event->type == devicemotionnotify)
  1652.     {
  1653.     if (mode == PRINT)
  1654.         {
  1655.         M = (XDeviceMotionEvent * ) event;
  1656.         printf ("Device motion event device=%d\n", M->deviceid);
  1657.         printf ("     type =          %d\n", M->type);
  1658.         printf ("     serial =        %ld\n", M->serial);
  1659.         printf ("     send_event =    %ld\n", M->send_event);
  1660.         printf ("     display =       %x\n", M->display);
  1661.         printf ("     window =        %x\n", M->window);
  1662.         printf ("     root =        %x\n", M->root);
  1663.         printf ("     subwindow =   %x\n", M->subwindow);
  1664.         printf ("     time =        %x\n", M->time);
  1665.         printf ("     x =           %d\n", M->x);
  1666.         printf ("     y =           %d\n", M->y);
  1667.         printf ("     x_root =      %d\n", M->x_root);
  1668.         printf ("     y_root =      %d\n", M->y_root);
  1669.         printf ("     state =       %d\n", M->state);
  1670.         printf ("     is_hint =     %x\n", M->is_hint);
  1671.         printf ("     same_screen = %d\n", M->same_screen);
  1672.         printf ("     axes_count  = %d\n", M->axes_count);
  1673.         printf ("     first_axis  = %d\n", M->first_axis);
  1674.         }
  1675.     }
  1676.     else if (event->type == devicefocusin || event->type == devicefocusout)
  1677.     {
  1678.     if (mode == PRINT)
  1679.         {
  1680.         f = (XDeviceFocusChangeEvent * ) event;
  1681.         printf ("Device focus event device=%d\n", f->deviceid);
  1682.         printf ("     type =          %d\n", f->type);
  1683.         printf ("     serial =        %ld\n", f->serial);
  1684.         printf ("     send_event =    %ld\n", f->send_event);
  1685.         printf ("     display =       %x\n", f->display);
  1686.         printf ("     window =        %x\n", f->window);
  1687.         printf ("     time =          %x\n", f->time);
  1688.         printf ("     mode =          %x\n", f->mode);
  1689.         printf ("     detail =        %x\n", f->detail);
  1690.         }
  1691.     }
  1692.     else if (event->type == proximityin || event->type == proximityout)
  1693.     {
  1694.     if (mode == PRINT)
  1695.         {
  1696.         p = (XProximityNotifyEvent * ) event;
  1697.         printf ("Device proximity event device=%d\n", p->deviceid);
  1698.         printf ("     type =          %d\n", p->type);
  1699.         printf ("     serial =        %ld\n", p->serial);
  1700.         printf ("     send_event =    %ld\n", p->send_event);
  1701.         printf ("     display =       %x\n", p->display);
  1702.         printf ("     window =        %x\n", p->window);
  1703.         printf ("     root =        %x\n", p->root);
  1704.         printf ("     subwindow =   %x\n", p->subwindow);
  1705.         printf ("     time =        %x\n", p->time);
  1706.         printf ("     x =           %d\n", p->x);
  1707.         printf ("     y =           %d\n", p->y);
  1708.         printf ("     x_root =      %d\n", p->x_root);
  1709.         printf ("     y_root =      %d\n", p->y_root);
  1710.         printf ("     state =       %d\n", p->state);
  1711.         printf ("     same_screen = %d\n", p->same_screen);
  1712.         printf ("     axes_count  = %d\n", p->axes_count);
  1713.         printf ("     first_axis  = %d\n", p->first_axis);
  1714.         }
  1715.     }
  1716.     else if (event->type == devicemappingnotify)
  1717.     {
  1718.     if (mode == PRINT)
  1719.         {
  1720.         m = (XDeviceMappingEvent * ) event;
  1721.         printf ("Device mapping event device=%d\n", m->deviceid);
  1722.         printf ("     type =          %d\n", m->type);
  1723.         printf ("     serial =        %ld\n", m->serial);
  1724.         printf ("     send_event =    %ld\n", m->send_event);
  1725.         printf ("     display =       %x\n", m->display);
  1726.         printf ("     window =        %x\n", m->window);
  1727.         printf ("     time =          %x\n", m->time);
  1728.         printf ("     request =       %x\n", m->request);
  1729.         printf ("     first_keycode = %x\n", m->first_keycode);
  1730.         printf ("     count =         %x\n", m->count);
  1731.         }
  1732.     }
  1733.     else if (event->type == devicestatenotify)
  1734.     {
  1735.     if (mode == PRINT)
  1736.     {
  1737.     s = (XDeviceStateNotifyEvent * ) event;
  1738.     printf ("Device state notify event device=%d\n", s->deviceid);
  1739.     printf ("     type =          %d\n", s->type);
  1740.     printf ("     serial =        %ld\n", s->serial);
  1741.     printf ("     send_event =    %ld\n", s->send_event);
  1742.     printf ("     display =       %x\n", s->display);
  1743.     printf ("     window =        %x\n", s->window);
  1744.     printf ("     time =          %x\n", s->time);
  1745.     printf ("     num_classes =   %x\n", s->num_classes);
  1746.     printf ("     data =          %x\n", s->data);
  1747.     anyclass = (XInputClass *) (&s->data[0]);
  1748.     for (i=0; i<s->num_classes; i++)
  1749.         {
  1750.         switch (anyclass->class)
  1751.         {
  1752.         case KeyClass:
  1753.             kdata = (XKeyStatus *) anyclass;
  1754.             printf ("num_keys is %d\n",kdata->num_keys);
  1755.             for (j=0; j<kdata->num_keys/8; j++)
  1756.             printf ("%x ", *(kdata->keys+j));
  1757.             printf ("\n");
  1758.             anyclass = (XInputClass *) ++kdata;
  1759.             break;
  1760.         case ButtonClass:
  1761.             bdata = (XButtonStatus *) anyclass;
  1762.             printf ("num_buttons is %d\n",bdata->num_buttons);
  1763.             for (j=0; j<bdata->num_buttons/8; j++)
  1764.             printf ("%x ", *(bdata->buttons+j));
  1765.             printf ("\n");
  1766.             anyclass = (XInputClass *) ++bdata;
  1767.             break;
  1768.         case ValuatorClass:
  1769.             vdata = (XValuatorStatus *) anyclass;
  1770.             printf ("num_valuators is %d\n",vdata->num_valuators);
  1771.             for (j=0; j<vdata->num_valuators; j++)
  1772.                 printf ("valuator %d has value %x\n",
  1773.                 j, *(vdata->valuators+j));
  1774.             anyclass = (XInputClass *) ++vdata;
  1775.             break;
  1776.             }
  1777.         }
  1778.     }
  1779.     }
  1780.     else if (event->type == changedevicenotify)
  1781.     {
  1782.     if (mode == PRINT)
  1783.         {
  1784.         c = (XChangeDeviceNotifyEvent * ) event;
  1785.         printf ("Device change event device=%d\n", c->deviceid);
  1786.         printf ("     type =          %d\n", c->type);
  1787.         printf ("     serial =        %ld\n", c->serial);
  1788.         printf ("     send_event =    %ld\n", c->send_event);
  1789.         printf ("     display =       %x\n", c->display);
  1790.         printf ("     window =        %x\n", c->window);
  1791.         printf ("     time =          %x\n", c->time);
  1792.         printf ("     request =       %x\n", c->request);
  1793.         }
  1794.     }
  1795.     else if (event->type == Expose)
  1796.     return (-1);
  1797.     else 
  1798.     {
  1799.     buf = (char *) event;
  1800.     printf ("unknown event!\n");
  1801.     for (i=0; i<32; i++)
  1802.         printf ("%x ",buf[i]);
  1803.         return (1);
  1804.     }
  1805.     return (0);
  1806.     }
  1807.  
  1808. /***********************************************************************
  1809.  *
  1810.  * This function initializes an X error handler.
  1811.  *
  1812.  */
  1813.  
  1814. init_error_handler (disp)
  1815.     Display    *disp;
  1816.     {
  1817.     int         event;
  1818.     int         handle_x_errors();
  1819.  
  1820.     XQueryExtension (disp, "XInputExtension", &major_code, &event, &first_err);
  1821.     XSetErrorHandler (handle_x_errors);
  1822.     }
  1823.  
  1824. /***********************************************************************
  1825.  *
  1826.  * This function handles X errors.
  1827.  *
  1828.  */
  1829.  
  1830. handle_x_errors (disp, error)
  1831.     Display    *disp;
  1832.     XErrorEvent *error;
  1833.     {
  1834.     char buf[256];
  1835.  
  1836.     if (error->request_code == major_code &&
  1837.         error->minor_code == error_code &&
  1838.         error->error_code == expect)
  1839.         if (error->error_code >= first_err &&
  1840.             error->error_code <= first_err+4)
  1841.         {
  1842.         if (Dflag)
  1843.                 printf ("%s returned %s correctly.\n",
  1844.             extfuncs[error->minor_code],
  1845.             ext_errors[error->error_code-first_err]);
  1846.         return;
  1847.         }
  1848.     else
  1849.         {
  1850.         if (Dflag)
  1851.                 printf ("%s returned %s correctly.\n",
  1852.             extfuncs[error->minor_code],
  1853.                 std_errors[error->error_code]);
  1854.         return;
  1855.         }
  1856.     if (error->request_code == major_code)
  1857.         printf ("    Minor code=%s.\n",extfuncs[error->minor_code]);
  1858.     else
  1859.         printf ("    Minor code=%d.\n",error->minor_code);
  1860.     
  1861.     if (error->error_code >= Success &&
  1862.         error->error_code <= BadImplementation)
  1863.         printf ("    Error code=%s.\n",std_errors[error->error_code]);
  1864.     else if (error->error_code >= first_err &&
  1865.         error->error_code <= first_err+4)
  1866.         printf ("    Error code=%s.\n",ext_errors[error->error_code-first_err]);
  1867.     else
  1868.         printf ("    Error code=%d.\n",error->error_code);
  1869.     printf ("    Resource id=%d.\n",error->resourceid);
  1870.     return (0);
  1871.     }
  1872.  
  1873. process_events (display, mode)
  1874.     Display *display;
  1875.     int    mode;
  1876.     {
  1877.     int    ret;
  1878.     int    count = 0;
  1879.     XEvent event;
  1880.  
  1881.     XSync (display,0);
  1882.     while (XPending (display) > 0)
  1883.     {
  1884.     XNextEvent (display,&event);
  1885.     process_device_events (&event, mode);
  1886.     count++;
  1887.     }
  1888.     if (Dflag)
  1889.     printf ("processed %d events\n",count);
  1890.     }
  1891.