1966bf024Smrg/* $XFree86$ */
2966bf024Smrg/*****************************************************************************
3966bf024SmrgCopyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
4966bf024Smrg
5966bf024SmrgPermission to use, copy, modify, and distribute this software and its
6966bf024Smrgdocumentation for any purpose and without fee is hereby granted,
7966bf024Smrgprovided that the above copyright notice appear in all copies and that
8966bf024Smrgboth that copyright notice and this permission notice appear in
9966bf024Smrgsupporting documentation, and that the name of Digital not be
10966bf024Smrgused in advertising or publicity pertaining to distribution of the
11966bf024Smrgsoftware without specific, written prior permission.
12966bf024Smrg
13966bf024SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
14966bf024SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
15966bf024SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
16966bf024SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17966bf024SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18966bf024SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19966bf024SmrgSOFTWARE.
20966bf024Smrg
21966bf024Smrg*****************************************************************************/
22966bf024Smrg/*
23966bf024Smrg *
24966bf024Smrg *  CONTRIBUTORS:
25966bf024Smrg *
26966bf024Smrg *      Dick Annicchiarico
27966bf024Smrg *      Robert Chesler
28966bf024Smrg *      Dan Coutu
29966bf024Smrg *      Gene Durso
30966bf024Smrg *      Marc Evans
31966bf024Smrg *      Alan Jamison
32966bf024Smrg *      Mark Henry
33966bf024Smrg *      Ken Miller
34966bf024Smrg *
35966bf024Smrg */
36966bf024Smrg
37966bf024Smrg#include <stdio.h>
38966bf024Smrg#include <errno.h>
39966bf024Smrg#include <X11/extensions/xtraplib.h>
40966bf024Smrg#include <X11/extensions/xtraplibp.h>
41966bf024Smrg
42966bf024Smrgstatic void XETrapDispatchCB(XETC *tc, XETrapDatum *pdatum)
43966bf024Smrg{
44966bf024Smrg    void_function pfunc = NULL;
45966bf024Smrg    BYTE *userp = NULL;
46966bf024Smrg
47966bf024Smrg    /* Need to deal with Delta Timestamps here before calling client CB */
48966bf024Smrg    if (XETrapGetTCFlagDeltaTimes(tc))
49966bf024Smrg    {
50966bf024Smrg        CARD32 last_time = XETrapGetTCTime(tc);
51966bf024Smrg        if (XETrapHeaderIsEvent(&pdatum->hdr))
52966bf024Smrg        {   /* then we can play with the timestamps */
53966bf024Smrg            pdatum->hdr.timestamp =
54966bf024Smrg                pdatum->u.event.u.keyButtonPointer.time;
55966bf024Smrg        }
56966bf024Smrg        else
57966bf024Smrg        {   /*
58966bf024Smrg             * the current one from GetTimeInMillis is worthless
59966bf024Smrg             * as it's only updated during event instances (e.g. not
60966bf024Smrg             * wall clock).
61966bf024Smrg             */
62966bf024Smrg            pdatum->hdr.timestamp = last_time;
63966bf024Smrg        }
64966bf024Smrg        if (!pdatum->hdr.timestamp)
65966bf024Smrg        {   /* for dual monitor bug */
66966bf024Smrg            pdatum->hdr.timestamp = last_time;
67966bf024Smrg        }
68966bf024Smrg        if (!last_time)
69966bf024Smrg        {   /* first one!  Prime it! */
70966bf024Smrg            last_time = pdatum->hdr.timestamp;
71966bf024Smrg        }
72966bf024Smrg        tc->values.last_time = pdatum->hdr.timestamp;   /* no macro! */
73966bf024Smrg        if (pdatum->hdr.timestamp < last_time)
74966bf024Smrg        {   /* for clock rollover */
75966bf024Smrg            pdatum->hdr.timestamp = 0;
76966bf024Smrg        }
77966bf024Smrg        else
78966bf024Smrg        {   /* the real delta */
79966bf024Smrg            pdatum->hdr.timestamp = pdatum->hdr.timestamp - last_time;
80966bf024Smrg        }
81966bf024Smrg    }
82966bf024Smrg    /*  Get the user supplied callback function */
83966bf024Smrg    if (XETrapHeaderIsEvent(&pdatum->hdr))
84966bf024Smrg    {
85966bf024Smrg        pfunc = tc->values.evt_cb[pdatum->u.event.u.u.type].func;
86966bf024Smrg        userp = tc->values.evt_cb[pdatum->u.event.u.u.type].data;
87966bf024Smrg    }
88966bf024Smrg    else if (XETrapHeaderIsRequest(&pdatum->hdr) ||
89966bf024Smrg        XETrapHeaderIsReply(&pdatum->hdr))
90966bf024Smrg    {
91966bf024Smrg        pfunc = tc->values.req_cb[pdatum->u.req.reqType].func;
92966bf024Smrg        userp = tc->values.req_cb[pdatum->u.req.reqType].data;
93966bf024Smrg    }
94966bf024Smrg
95966bf024Smrg    /* If there is a callback then call it with the data */
96966bf024Smrg    if (pfunc != NULL)
97966bf024Smrg    {
98966bf024Smrg        (*pfunc)(tc,pdatum,userp);
99966bf024Smrg    }
100966bf024Smrg}
101966bf024Smrg
102966bf024SmrgBoolean XETrapDispatchXLib(XETrapDataEvent *event, XETC *tc)
103966bf024Smrg{
104966bf024Smrg    memcpy(&tc->xbuff[event->idx*sz_EventData], event->data, sz_EventData);
105966bf024Smrg
106966bf024Smrg    if (event->detail == XETrapDataLast)
107966bf024Smrg    {
108966bf024Smrg        XETrapDispatchCB(tc, (XETrapDatum *)tc->xbuff);
109966bf024Smrg    }
110966bf024Smrg    return True;
111966bf024Smrg}
112