summaryrefslogtreecommitdiff
path: root/Xext/xevie.c
blob: f435e79e2e8f5a63277e122947f2065813890a34 (plain)
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/************************************************************

Copyright 2003 Sun Microsystems, Inc.

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.

Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.

************************************************************/

#define NEED_REPLIES
#define NEED_EVENTS
#include <X11/X.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "dixstruct.h"
#include "extnsionst.h"
#include "colormapst.h"
#include "scrnintstr.h"
#include "servermd.h"
#define  _XEVIE_SERVER_
#include "Xeviestr.h"
#include <X11/Xfuncproto.h>
#include "input.h"

#include "../os/osdep.h"

#define NoSuchEvent 0x80000000

extern Bool noXkbExtension;
extern int    xeviegrabState;

static int		ProcDispatch (), SProcDispatch ();
static void		ResetProc ();

static unsigned char	ReqCode = 0;
static int		ErrorBase;

int			xevieFlag = 0;
int	 		xevieClientIndex = 0;
DeviceIntPtr		xeviekb = NULL;
DeviceIntPtr		xeviemouse = NULL;
Mask			xevieMask = 0;
int       		xevieEventSent = 0;
int			xevieKBEventSent = 0;
Mask xevieFilters[128] = 
{
        NoSuchEvent,                   /* 0 */
        NoSuchEvent,                   /* 1 */
        KeyPressMask,                  /* KeyPress */
        KeyReleaseMask,                /* KeyRelease */
        ButtonPressMask,               /* ButtonPress */
        ButtonReleaseMask,             /* ButtonRelease */
        PointerMotionMask              /* MotionNotify (initial state) */
};

static void XevieEnd(int clientIndex);
static void XevieClientStateCallback(CallbackListPtr *pcbl, pointer nulldata,
                                   pointer calldata);
static void XevieServerGrabStateCallback(CallbackListPtr *pcbl,
                                   pointer nulldata,
                                   pointer calldata);

void
XevieExtensionInit ()
{
    ExtensionEntry* extEntry;

    if (!AddCallback(&ServerGrabCallback,XevieServerGrabStateCallback,NULL))
       return;

    if (extEntry = AddExtension (XEVIENAME,
				0,
				XevieNumberErrors,
				ProcDispatch,
				SProcDispatch,
				ResetProc,
				StandardMinorOpcode)) {
	ReqCode = (unsigned char)extEntry->base;
	ErrorBase = extEntry->errorBase;
    }

    /* PC servers initialize the desktop colors (citems) here! */
}

/*ARGSUSED*/
static 
void ResetProc (extEntry)
    ExtensionEntry* extEntry;
{
}

static 
int ProcQueryVersion (client)
    register ClientPtr client;
{
    REQUEST (xXevieQueryVersionReq);
    xXevieQueryVersionReply rep;
    register int n;

    REQUEST_SIZE_MATCH (xXevieQueryVersionReq);
    rep.type = X_Reply;
    rep.length = 0;
    rep.sequence_number = client->sequence;
    rep.server_major_version = XEVIE_MAJOR_VERSION;
    rep.server_minor_version = XEVIE_MINOR_VERSION;
    WriteToClient (client, sizeof (xXevieQueryVersionReply), (char *)&rep);
    return client->noClientException;
}

static
int ProcStart (client)
    register ClientPtr client;
{
    REQUEST (xXevieStartReq);
    xXevieStartReply rep;
    register int n;

    REQUEST_SIZE_MATCH (xXevieStartReq);
    rep.pad1 = 0;

    if(!xevieFlag){
        if (AddCallback(&ClientStateCallback,XevieClientStateCallback,NULL)) {
           xevieFlag = 1;
           rep.pad1 = 1;
           xevieClientIndex = client->index;
        } else
           return BadAlloc;
    } else
        return BadAccess;

    rep.type = X_Reply;
    rep.sequence_number = client->sequence;
    WriteToClient (client, sizeof (xXevieStartReply), (char *)&rep);
    return client->noClientException;
}

static
int ProcEnd (client)
    register ClientPtr client;
{
    xXevieEndReply rep;

    XevieEnd(xevieClientIndex);

    rep.type = X_Reply;
    rep.sequence_number = client->sequence;
    WriteToClient (client, sizeof (xXevieEndReply), (char *)&rep);
    return client->noClientException;
}

static
int ProcSend (client)
    register ClientPtr client;
{
    REQUEST (xXevieSendReq);
    xXevieSendReply rep;
    xEvent *xE;
    OsCommPtr oc;
    static unsigned char lastDetail = 0, lastType = 0;

    xE = (xEvent *)&stuff->event;
    rep.type = X_Reply;
    rep.sequence_number = client->sequence;
    WriteToClient (client, sizeof (xXevieSendReply), (char *)&rep);

    switch(xE->u.u.type) {
	case KeyPress:
        case KeyRelease:
	  xevieKBEventSent = 1;
#ifdef XKB
          if(noXkbExtension)
#endif
            CoreProcessKeyboardEvent (xE, xeviekb, 1);
	  break;
	case ButtonPress:
	case ButtonRelease:
	case MotionNotify:
	  xevieEventSent = 1;
	  CoreProcessPointerEvent(xE, xeviemouse, 1); 
	  break; 
	default:
	  break;
    }
    lastType = xE->u.u.type;
    lastDetail = xE->u.u.detail;
    return client->noClientException;
}

static
int ProcSelectInput (client)
    register ClientPtr client;
{
    REQUEST (xXevieSelectInputReq);
    xXevieSelectInputReply rep;

    xevieMask = (long)stuff->event_mask;
    rep.type = X_Reply;
    rep.sequence_number = client->sequence;
    WriteToClient (client, sizeof (xXevieSelectInputReply), (char *)&rep);
    return client->noClientException;
}

static 
int ProcDispatch (client)
    register ClientPtr	client;
{
    REQUEST (xReq);
    switch (stuff->data)
    {
    case X_XevieQueryVersion:
	return ProcQueryVersion (client);
    case X_XevieStart:
	return ProcStart (client);
    case X_XevieEnd:
	return ProcEnd (client);
    case X_XevieSend:
	return ProcSend (client);
    case X_XevieSelectInput:
	return ProcSelectInput(client);
    default:
	return BadRequest;
    }
}

static 
int SProcQueryVersion (client)
    register ClientPtr	client;
{
    register int n;

    REQUEST(xXevieQueryVersionReq);
    swaps(&stuff->length, n);
    return ProcQueryVersion(client);
}

static 
int SProcStart (client)
    ClientPtr client;
{
    register int n;

    REQUEST (xXevieStartReq);
    swaps (&stuff->length, n);
    swapl (&stuff->screen, n);
    REQUEST_AT_LEAST_SIZE (xXevieStartReq);
    return ProcStart (client);
}

static 
int SProcEnd (client)
    ClientPtr client;
{
    register int n;
    int count;
    xColorItem* pItem;

    REQUEST (xXevieEndReq);
    swaps (&stuff->length, n);
    REQUEST_AT_LEAST_SIZE (xXevieEndReq);
    swapl(&stuff->cmap, n);
    return ProcEnd (client);
}

static
int SProcSend (client)
    ClientPtr client;
{
    register int n;
    int count;

    REQUEST (xXevieSendReq);
    swaps (&stuff->length, n);
    REQUEST_AT_LEAST_SIZE (xXevieSendReq);
    swapl(&stuff->event, n);
    return ProcSend (client);
}

static
int SProcSelectInput (client)
    ClientPtr client;
{
    register int n;
    int count;

    REQUEST (xXevieSelectInputReq);
    swaps (&stuff->length, n);
    REQUEST_AT_LEAST_SIZE (xXevieSendReq);
    swapl(&stuff->event_mask, n);
    return ProcSelectInput (client);
}


static 
int SProcDispatch (client)
    register ClientPtr	client;
{
    REQUEST(xReq);
    switch (stuff->data)
    {
    case X_XevieQueryVersion:
	return SProcQueryVersion (client);
    case X_XevieStart:
	return SProcStart (client);
    case X_XevieEnd:
	return SProcEnd (client);
    case X_XevieSend:
	return SProcSend (client);
    case X_XevieSelectInput:
	return SProcSelectInput(client);
    default:
	return BadRequest;
    }
}

static void
XevieEnd(int clientIndex)
{
    if (!clientIndex || clientIndex == xevieClientIndex) {
       xevieFlag = 0;
       xevieClientIndex = 0;
       DeleteCallback (&ClientStateCallback, XevieClientStateCallback, NULL);
    }
}

static void
XevieClientStateCallback(CallbackListPtr *pcbl, pointer nulldata,
                        pointer calldata)
{
    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
    ClientPtr client = pci->client;
    if (client->clientState == ClientStateGone
       || client->clientState == ClientStateRetained)
       XevieEnd(client->index);
}

static void
XevieServerGrabStateCallback(CallbackListPtr *pcbl, pointer nulldata,
                            pointer calldata)
{
    ServerGrabInfoRec *grbinfo = (ServerGrabInfoRec *)calldata;
    if (grbinfo->grabstate == SERVER_GRABBED)
       xeviegrabState = TRUE;
    else
       xeviegrabState = FALSE;
}