1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/* $XFree86$ */
/*****************************************************************************
Copyright 1987, 1988, 1989, 1990, 1991, 1994 by Digital Equipment Corp.,
Maynard, MA
X11R6 Changes Copyright (c) 1994 by Robert Chesler of Absol-Puter, Hudson, NH.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL AND ABSOL-PUTER DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL DIGITAL OR ABSOL-PUTER BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*****************************************************************************/
#include <stdio.h>
#include <X11/extensions/xtraplib.h>
#include <X11/extensions/xtraplibp.h>
#ifdef vms
#define IS_AT_OR_AFTER(t1, t2) (((t2).high > (t1).high) \
|| (((t2).high == (t1).high)&& ((t2).low >= (t1).low)))
typedef struct _vms_time {
unsigned long low;
unsigned long high;
}vms_time; /* from IntrinsicP.h */
#ifdef VMSDW_V3
typedef struct _ModToKeysymTable {
Modifiers mask;
int count;
int index;
} ModToKeysymTable; /* from TranslateI.h */
typedef struct _ConverterRec **ConverterTable; /* from ConvertI.h */
#include "libdef.h"
typedef struct _CallbackRec *CallbackList; /* from CallbackI.h */
typedef struct _XtGrabRec *XtGrabList; /* from EventI.h */
#include <X11/PassivGraI.h>
#include <X11/InitialI.h>
#else /* VMSDW_V3 */
typedef struct _ModToKeysymTable {
Modifiers mask;
int count;
int index;
} ModToKeysymTable; /* from TranslateI.h */
typedef struct _ConverterRec **ConverterTable; /* from ConvertI.h */
#include "libdef.h"
#define NFDBITS (sizeof(fd_mask) * 8)
typedef long fd_mask;
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y))
#endif /* howmany */
typedef struct Fd_set {
fd_mask fds_bits[howmany(256, NFDBITS)];
} Fd_set; /* from fd.h */
#include <X11/InitializeI.h>
#endif /* VMSDW_V3 */
#else /* !vms */
#include <X11/IntrinsicI.h>
#define IS_AT_OR_AFTER(t1, t2) (((t2).tv_sec > (t1).tv_sec) \
|| (((t2).tv_sec == (t1).tv_sec)&& ((t2).tv_usec >= (t1).tv_usec)))
#endif /* vms */
/* The following has been lifted from NextEvent.c in X11R4 */
#ifndef NEEDS_NTPD_FIXUP
# ifdef sun
# define NEEDS_NTPD_FIXUP 1
# else
# define NEEDS_NTPD_FIXUP 0
# endif
#endif
#if NEEDS_NTPD_FIXUP
#define FIXUP_TIMEVAL(t) { \
while ((t).tv_usec >= 1000000) { \
(t).tv_usec -= 1000000; \
(t).tv_sec++; \
} \
while ((t).tv_usec < 0) { \
if ((t).tv_sec > 0) { \
(t).tv_usec += 1000000; \
(t).tv_sec--; \
} else { \
(t).tv_usec = 0; \
break; \
} \
}}
#else
#define FIXUP_TIMEVAL(t)
#endif /*NEEDS_NTPD_FIXUP*/
/* The following code is required for the use of the XLIB transport of XTrap
* events. This is in line with what MIT wants to see proper extension
* implementations do, as compared to using one of the core input event masks.
*/
Boolean (*XETrapGetEventHandler(XETC *tc, CARD32 id))(XETrapDataEvent *event, XETC *tc)
{
return((id < XETrapNumberEvents) ? tc->eventFunc[id] : NULL);
}
Boolean (*XETrapSetEventHandler(XETC *tc, CARD32 id,
Boolean (*pfunc)(XETrapDataEvent *event, XETC *tc)))(XETrapDataEvent *event, XETC *tc)
{
register Boolean (*rfunc)(XETrapDataEvent *event, XETC *tc) = NULL;
if (id < XETrapNumberEvents)
{
rfunc = XETrapGetEventHandler(tc,id);
tc->eventFunc[id] = pfunc;
}
return(rfunc);
}
Boolean XETrapDispatchEvent(XEvent *pevent, XETC *tc)
{
Boolean status = False;
register CARD32 id = pevent->type;
register CARD32 firstEvent = tc->eventBase;
register CARD32 lastEvent = tc->eventBase + XETrapNumberEvents - 1L;
/* If it is our extension event, handle it specially, otherwise, pass
* it off to Xt.
*/
if (firstEvent != 0 && id >= firstEvent && id <= lastEvent)
{
/* We may be ignoring the event */
if (tc->eventFunc[id - firstEvent] != NULL)
{
status = (*tc->eventFunc[id - firstEvent])((XETrapDataEvent*)pevent,tc);
}
}
else
{
status = XtDispatchEvent(pevent);
}
return(status);
}
XtInputMask XETrapAppPending(XtAppContext app)
{
TimerEventRec *te_ptr;
#ifndef VMS
struct timeval cur_time;
#else /* vms */
vms_time cur_time;
long efnMask = 0L;
int status;
#endif /* vms */
XtInputMask retmask = XtAppPending(app); /* Prime XtIMEvent */
retmask &= ~(XtIMTimer | XtIMAlternateInput); /* clear timer & input */
/* Now test for timer */
te_ptr = app->timerQueue;
while (te_ptr != NULL)
{
#ifndef vms
(void)gettimeofday(&cur_time, NULL);
FIXUP_TIMEVAL(cur_time);
#else
sys$gettim(&cur_time);
#endif /* vms */
if (IS_AT_OR_AFTER(te_ptr->te_timer_value, cur_time))
{ /* this timer is due to fire */
retmask |= XtIMTimer;
break;
}
te_ptr = te_ptr->te_next;
}
/* Now test for alternate input */
#ifndef vms
if (app->outstandingQueue != NULL)
{
retmask |= XtIMAlternateInput;
}
#else /* vms */
if ((app->Input_EF_Mask != 0L) && ((status=SYS$READEF(1,&efnMask)) == 1))
{ /* we have input configured & retrieved the efn cluster 0 */
efnMask &= app->Input_EF_Mask; /* mask out non-input */
if (efnMask) /* any left? */
{ /* yes, an alt-input efn is set */
retmask |= XtIMAlternateInput;
}
}
#endif /* vms */
return(retmask);
}
void XETrapAppMainLoop(XtAppContext app, XETC *tc)
{
XEvent event;
XtInputMask imask;
while (1)
{
imask = XETrapAppPending(app);
/* Check to see what's going on so that we don't block
* in either NextEvent or ProcessEvent since neither
* of these routines can correctly deal with XTrap Events
*/
if (imask & XtIMXEvent)
{
(void)XtAppNextEvent(app,&event);
(void)XETrapDispatchEvent(&event,tc);
}
else if (imask & (XtIMTimer | XtIMAlternateInput))
{
XtAppProcessEvent(app, (XtIMTimer | XtIMAlternateInput));
}
else
{ /* Nothing going on, so we need to block */
(void)XETrapWaitForSomething(app);
}
}
}
int XETrapAppWhileLoop(XtAppContext app, XETC *tc, Bool *done)
{
XEvent event;
XtInputMask imask;
int status = True;
if(done)
{
while (!(*done))
{
imask = XETrapAppPending(app);
/* Check to see what's going on so that we don't block
* in either NextEvent or ProcessEvent since neither
* of these routines can correctly deal with XTrap Events
*/
if (imask & XtIMXEvent)
{
(void)XtAppNextEvent(app, &event);
(void)XETrapDispatchEvent(&event,tc);
}
else if (imask & (XtIMTimer | XtIMAlternateInput))
{
XtAppProcessEvent(app, (XtIMTimer | XtIMAlternateInput));
}
else
{ /* Nothing going on, so we need to block */
(void)XETrapWaitForSomething(app);
}
}
}
else
{
status = False;
}
return(status);
}
/* Wait for either Timer, Alternate Input, or an X Event to arrive */
int XETrapWaitForSomething(XtAppContext app)
{
#ifndef vms
return(_XtWaitForSomething(app, FALSE, FALSE, FALSE, FALSE, TRUE
#ifdef XTHREADS
, FALSE
#endif /* XTHREADS */
, 0L));
#else /* vms */
#define IS_AFTER(t1,t2) (((t2).high > (t1).high) \
||(((t2).high == (t1).high)&& ((t2).low > (t1).low)))
long retval = 0L;
TimerEventRec *te_ptr;
vms_time cur_time,result_time;
int status = 0;
long quotient, remainder = 0;
int d;
if (app->timerQueue!= NULL)
{ /* check timeout queue */
cur_time.low = cur_time.high = result_time.low = result_time.high = 0;
te_ptr = app->timerQueue;
sys$gettim(&cur_time);
if ((IS_AFTER(app->timerQueue->te_timer_value, cur_time)) &&
(app->timerQueue->te_proc != 0))
{ /* it's fired! return! */
return(0);
}
/* Jump through hoops to get the time specified in the queue into
* milliseconds
*/
status = lib$sub_times (&(te_ptr->te_timer_value.low), &cur_time,
&result_time);
/*
* See if this timer has expired. A timer is considered expired
* if it's value in the past (the NEGTIM case) or if there is
* less than one integral milli second before it would go off.
*/
if (status == LIB$_NEGTIM ||
(result_time.high == -1 && result_time.low > -10000))
{ /* We've got a timer and it's ready to fire! */
return(0);
}
else if ((status & 1) == 1)
{
lib$ediv (&(10000), &result_time, "ient, &remainder);
quotient *= -1; /* flip the sign bit */
return(XMultiplexInput(app->count, &(app->list[0L]),
app->Input_EF_Mask, quotient, 0L, &retval));
}
else
{
status = -1;
}
}
return((status == -1 ? -1 : XMultiplexInput(app->count, &(app->list[0L]),
app->Input_EF_Mask, 0L, 0L, &retval)));
#endif /* vms */
}
|