Tizen 2.0 Release
[pkgs/xorg/lib/libxtrap.git] / src / XEDsptch.c
1 /* $XFree86$ */
2 /*****************************************************************************
3 Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
4
5 Permission to use, copy, modify, and distribute this software and its 
6 documentation for any purpose and without fee is hereby granted, 
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in 
9 supporting documentation, and that the name of Digital not be
10 used in advertising or publicity pertaining to distribution of the
11 software without specific, written prior permission.  
12
13 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
14 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
15 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
16 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19 SOFTWARE.
20
21 *****************************************************************************/
22 /*
23  *
24  *  CONTRIBUTORS:
25  *
26  *      Dick Annicchiarico
27  *      Robert Chesler
28  *      Dan Coutu
29  *      Gene Durso
30  *      Marc Evans
31  *      Alan Jamison
32  *      Mark Henry
33  *      Ken Miller
34  *
35  */
36
37 #include <stdio.h>
38 #include <errno.h>
39 #include <X11/extensions/xtraplib.h>
40 #include <X11/extensions/xtraplibp.h>
41
42 static void XETrapDispatchCB(XETC *tc, XETrapDatum *pdatum)
43 {
44     void_function pfunc = NULL;
45     BYTE *userp = NULL;
46
47     /* Need to deal with Delta Timestamps here before calling client CB */
48     if (XETrapGetTCFlagDeltaTimes(tc))
49     {
50         CARD32 last_time = XETrapGetTCTime(tc);
51         if (XETrapHeaderIsEvent(&pdatum->hdr))
52         {   /* then we can play with the timestamps */
53             pdatum->hdr.timestamp = 
54                 pdatum->u.event.u.keyButtonPointer.time;
55         }
56         else
57         {   /* 
58              * the current one from GetTimeInMillis is worthless
59              * as it's only updated during event instances (e.g. not
60              * wall clock).
61              */
62             pdatum->hdr.timestamp = last_time;
63         }
64         if (!pdatum->hdr.timestamp)
65         {   /* for dual monitor bug */
66             pdatum->hdr.timestamp = last_time;
67         }
68         if (!last_time)
69         {   /* first one!  Prime it! */
70             last_time = pdatum->hdr.timestamp;
71         }
72         tc->values.last_time = pdatum->hdr.timestamp;   /* no macro! */
73         if (pdatum->hdr.timestamp < last_time)
74         {   /* for clock rollover */
75             pdatum->hdr.timestamp = 0;
76         }
77         else
78         {   /* the real delta */
79             pdatum->hdr.timestamp = pdatum->hdr.timestamp - last_time;
80         }
81     }
82     /*  Get the user supplied callback function */
83     if (XETrapHeaderIsEvent(&pdatum->hdr))
84     {
85         pfunc = tc->values.evt_cb[pdatum->u.event.u.u.type].func;
86         userp = tc->values.evt_cb[pdatum->u.event.u.u.type].data;
87     }
88     else if (XETrapHeaderIsRequest(&pdatum->hdr) ||
89         XETrapHeaderIsReply(&pdatum->hdr))
90     {
91         pfunc = tc->values.req_cb[pdatum->u.req.reqType].func;
92         userp = tc->values.req_cb[pdatum->u.req.reqType].data;
93     }
94
95     /* If there is a callback then call it with the data */
96     if (pfunc != NULL)
97     { 
98         (*pfunc)(tc,pdatum,userp); 
99     }
100 }
101 \f
102 Boolean XETrapDispatchXLib(XETrapDataEvent *event, XETC *tc)
103 {   
104     memcpy(&tc->xbuff[event->idx*sz_EventData], event->data, sz_EventData);
105
106     if (event->detail == XETrapDataLast)
107     {
108         XETrapDispatchCB(tc, (XETrapDatum *)tc->xbuff);
109     }
110     return True;
111 }