home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / xtest / XTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  7.1 KB  |  273 lines

  1. /* $XConsortium: XTest.c,v 1.7 92/04/20 13:14:52 rws Exp $ */
  2. /*
  3.  
  4. Copyright 1990, 1991 by UniSoft Group Limited
  5. Copyright 1992 by the Massachusetts Institute of Technology
  6.  
  7. Permission to use, copy, modify, distribute, and sell this software and its
  8. documentation for any purpose is hereby granted without fee, provided that
  9. the above copyright notice appear in all copies and that both that
  10. copyright notice and this permission notice appear in supporting
  11. documentation, and that the name of M.I.T. not be used in advertising or
  12. publicity pertaining to distribution of the software without specific,
  13. written prior permission.  M.I.T. makes no representations about the
  14. suitability of this software for any purpose.  It is provided "as is"
  15. without express or implied warranty.
  16.  
  17. */
  18.  
  19. #define NEED_REPLIES
  20. #include "Xlibint.h"
  21. #include "XTest.h"
  22. #include "xteststr.h"
  23. #include "Xext.h"
  24. #include "extutil.h"
  25.  
  26. static XExtensionInfo _xtest_info_data;
  27. static XExtensionInfo *xtest_info = &_xtest_info_data;
  28. static /* const */ char *xtest_extension_name = XTestExtensionName;
  29.  
  30. #define XTestCheckExtension(dpy,i,val) \
  31.   XextCheckExtension (dpy, i, xtest_extension_name, val)
  32.  
  33. /*****************************************************************************
  34.  *                                                                           *
  35.  *               private utility routines                          *
  36.  *                                                                           *
  37.  *****************************************************************************/
  38.  
  39. static int close_display();
  40. static /* const */ XExtensionHooks xtest_extension_hooks = {
  41.     NULL,                /* create_gc */
  42.     NULL,                /* copy_gc */
  43.     NULL,                /* flush_gc */
  44.     NULL,                /* free_gc */
  45.     NULL,                /* create_font */
  46.     NULL,                /* free_font */
  47.     close_display,            /* close_display */
  48.     NULL,                /* wire_to_event */
  49.     NULL,                /* event_to_wire */
  50.     NULL,                /* error */
  51.     NULL                /* error_string */
  52. };
  53.  
  54. static XEXT_GENERATE_FIND_DISPLAY (find_display, xtest_info,
  55.                    xtest_extension_name, 
  56.                    &xtest_extension_hooks, XTestNumberEvents,
  57.                    NULL)
  58.  
  59. static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xtest_info)
  60.  
  61. /*****************************************************************************
  62.  *                                                                           *
  63.  *            public routines                                *
  64.  *                                                                           *
  65.  *****************************************************************************/
  66.  
  67. Bool
  68. XTestQueryExtension (dpy, event_basep, error_basep, majorp, minorp)
  69.     Display *dpy;
  70.     int *event_basep, *error_basep;
  71.     int *majorp, *minorp;
  72. {
  73.     XExtDisplayInfo *info = find_display (dpy);
  74.     register xXTestGetVersionReq *req;
  75.     xXTestGetVersionReply rep;
  76.  
  77.     if (XextHasExtension(info)) {
  78.     LockDisplay(dpy);
  79.     GetReq(XTestGetVersion, req);
  80.     req->reqType = info->codes->major_opcode;
  81.     req->xtReqType = X_XTestGetVersion;
  82.     req->majorVersion = XTestMajorVersion;
  83.     req->minorVersion = XTestMinorVersion;
  84.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  85.         UnlockDisplay(dpy);
  86.         SyncHandle();
  87.         return False;
  88.     }
  89.     UnlockDisplay(dpy);
  90.     SyncHandle();
  91.     *event_basep = info->codes->first_event;
  92.     *error_basep = info->codes->first_error;
  93.     *majorp = rep.majorVersion;
  94.     *minorp = rep.minorVersion;
  95.     return True;
  96.     } else {
  97.     return False;
  98.     }
  99. }
  100.  
  101. Bool
  102. XTestCompareCursorWithWindow(dpy, window, cursor)
  103.     Display *dpy;
  104.     Window window;
  105.     Cursor cursor;
  106. {
  107.     XExtDisplayInfo *info = find_display (dpy);
  108.     register xXTestCompareCursorReq *req;
  109.     xXTestCompareCursorReply rep;
  110.  
  111.     XTestCheckExtension (dpy, info, 0);
  112.  
  113.     LockDisplay(dpy);
  114.     GetReq(XTestCompareCursor, req);
  115.     req->reqType = info->codes->major_opcode;
  116.     req->xtReqType = X_XTestCompareCursor;
  117.     req->window = window;
  118.     req->cursor = cursor;
  119.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  120.     UnlockDisplay(dpy);
  121.     SyncHandle();
  122.     return False;
  123.     }
  124.     UnlockDisplay(dpy);
  125.     SyncHandle();
  126.     return rep.same;
  127. }
  128.  
  129. Bool
  130. XTestCompareCurrentCursorWithWindow(dpy, window)
  131.     Display *dpy;
  132.     Window window;
  133. {
  134.     return XTestCompareCursorWithWindow(dpy, window, XTestCurrentCursor);
  135. }
  136.  
  137. XTestFakeKeyEvent(dpy, keycode, is_press, delay)
  138.     Display *dpy;
  139.     unsigned int keycode;
  140.     Bool is_press;
  141.     unsigned long delay;
  142. {
  143.     XExtDisplayInfo *info = find_display (dpy);
  144.     register xXTestFakeInputReq *req;
  145.  
  146.     XTestCheckExtension (dpy, info, 0);
  147.  
  148.     LockDisplay(dpy);
  149.     GetReq(XTestFakeInput, req);
  150.     req->reqType = info->codes->major_opcode;
  151.     req->xtReqType = X_XTestFakeInput;
  152.     req->type = is_press ? KeyPress : KeyRelease;
  153.     req->detail = keycode;
  154.     req->time = delay;
  155.     UnlockDisplay(dpy);
  156.     SyncHandle();
  157. }
  158.  
  159. XTestFakeButtonEvent(dpy, button, is_press, delay)
  160.     Display *dpy;
  161.     unsigned int button;
  162.     Bool is_press;
  163.     unsigned long delay;
  164. {
  165.     XExtDisplayInfo *info = find_display (dpy);
  166.     register xXTestFakeInputReq *req;
  167.  
  168.     XTestCheckExtension (dpy, info, 0);
  169.  
  170.     LockDisplay(dpy);
  171.     GetReq(XTestFakeInput, req);
  172.     req->reqType = info->codes->major_opcode;
  173.     req->xtReqType = X_XTestFakeInput;
  174.     req->type = is_press ? ButtonPress : ButtonRelease;
  175.     req->detail = button;
  176.     req->time = delay;
  177.     UnlockDisplay(dpy);
  178.     SyncHandle();
  179. }
  180.  
  181. XTestFakeMotionEvent(dpy, screen, x, y, delay)
  182.     Display *dpy;
  183.     int screen;
  184.     int x, y;
  185.     unsigned long delay;
  186. {
  187.     XExtDisplayInfo *info = find_display (dpy);
  188.     register xXTestFakeInputReq *req;
  189.  
  190.     XTestCheckExtension (dpy, info, 0);
  191.  
  192.     LockDisplay(dpy);
  193.     GetReq(XTestFakeInput, req);
  194.     req->reqType = info->codes->major_opcode;
  195.     req->xtReqType = X_XTestFakeInput;
  196.     req->type = MotionNotify;
  197.     req->detail = False;
  198.     if (screen == -1)
  199.     req->root = None;
  200.     else
  201.     req->root = RootWindow(dpy, screen);
  202.     req->rootX = x;
  203.     req->rootY = y;
  204.     req->time = delay;
  205.     UnlockDisplay(dpy);
  206.     SyncHandle();
  207. }
  208.  
  209. XTestFakeRelativeMotionEvent(dpy, dx, dy, delay)
  210.     Display *dpy;
  211.     int dx, dy;
  212.     unsigned long delay;
  213. {
  214.     XExtDisplayInfo *info = find_display (dpy);
  215.     register xXTestFakeInputReq *req;
  216.  
  217.     XTestCheckExtension (dpy, info, 0);
  218.  
  219.     LockDisplay(dpy);
  220.     GetReq(XTestFakeInput, req);
  221.     req->reqType = info->codes->major_opcode;
  222.     req->xtReqType = X_XTestFakeInput;
  223.     req->type = MotionNotify;
  224.     req->detail = True;
  225.     req->root = None;
  226.     req->rootX = dx;
  227.     req->rootY = dy;
  228.     req->time = delay;
  229.     UnlockDisplay(dpy);
  230.     SyncHandle();
  231. }
  232.  
  233. void
  234. XTestSetGContextOfGC(gc, gid)
  235.     GC gc;
  236.     GContext gid;
  237. {
  238.     gc->gid = gid;
  239. }
  240.  
  241. void
  242. XTestSetVisualIDOfVisual(visual, visualid)
  243.     Visual *visual;
  244.     VisualID visualid;
  245. {
  246.     visual->visualid = visualid;
  247. }
  248.  
  249. static xReq _dummy_request = {
  250.     0, 0, 0
  251. };
  252.  
  253. Status
  254. XTestDiscard(dpy)
  255.     Display *dpy;
  256. {
  257.     Bool something;
  258.     register char *ptr;
  259.  
  260.     LockDisplay(dpy);
  261.     if (something = (dpy->bufptr != dpy->buffer)) {
  262.     for (ptr = dpy->buffer;
  263.          ptr < dpy->bufptr;
  264.          ptr += (((xReq *)ptr)->length << 2))
  265.         dpy->request--;
  266.     dpy->bufptr = dpy->buffer;
  267.     dpy->last_req = (char *)&_dummy_request;
  268.     }
  269.     UnlockDisplay(dpy);
  270.     SyncHandle();
  271.     return something;
  272. }
  273.