dix.h revision 4642e01f
1/***********************************************************
2
3Copyright 1987, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25
26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28                        All Rights Reserved
29
30Permission to use, copy, modify, and distribute this software and its
31documentation for any purpose and without fee is hereby granted,
32provided that the above copyright notice appear in all copies and that
33both that copyright notice and this permission notice appear in
34supporting documentation, and that the name of Digital not be
35used in advertising or publicity pertaining to distribution of the
36software without specific, written prior permission.
37
38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44SOFTWARE.
45
46******************************************************************/
47
48#ifndef DIX_H
49#define DIX_H
50
51#include "gc.h"
52#include "window.h"
53#include "input.h"
54#include "cursor.h"
55#include "geext.h"
56#include <X11/extensions/XI.h>
57
58#define EARLIER -1
59#define SAMETIME 0
60#define LATER 1
61
62#define NullClient ((ClientPtr) 0)
63#define REQUEST(type) \
64	type *stuff = (type *)client->requestBuffer
65
66
67#define REQUEST_SIZE_MATCH(req)\
68    if ((sizeof(req) >> 2) != client->req_len)\
69         return(BadLength)
70
71#define REQUEST_AT_LEAST_SIZE(req) \
72    if ((sizeof(req) >> 2) > client->req_len )\
73         return(BadLength)
74
75#define REQUEST_FIXED_SIZE(req, n)\
76    if (((sizeof(req) >> 2) > client->req_len) || \
77        (((sizeof(req) + (n) + 3) >> 2) != client->req_len)) \
78         return(BadLength)
79
80#define LEGAL_NEW_RESOURCE(id,client)\
81    if (!LegalNewID(id,client)) \
82    {\
83	client->errorValue = id;\
84        return(BadIDChoice);\
85    }
86
87#define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, mode)\
88    {\
89	int rc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY, mode);\
90	if (rc != Success)\
91	    return rc;\
92	rc = dixLookupGC(&(pGC), stuff->gc, client, DixUseAccess);\
93	if (rc != Success)\
94	    return rc;\
95	if ((pGC->depth != pDraw->depth) || (pGC->pScreen != pDraw->pScreen))\
96	    return (BadMatch);\
97    }\
98    if (pGC->serialNumber != pDraw->serialNumber)\
99	ValidateGC(pDraw, pGC);
100
101
102#define WriteReplyToClient(pClient, size, pReply) { \
103   if ((pClient)->swapped) \
104      (*ReplySwapVector[((xReq *)(pClient)->requestBuffer)->reqType]) \
105           (pClient, (int)(size), pReply); \
106      else (void) WriteToClient(pClient, (int)(size), (char *)(pReply)); }
107
108#define WriteSwappedDataToClient(pClient, size, pbuf) \
109   if ((pClient)->swapped) \
110      (*(pClient)->pSwapReplyFunc)(pClient, (int)(size), pbuf); \
111   else (void) WriteToClient (pClient, (int)(size), (char *)(pbuf));
112
113typedef struct _TimeStamp *TimeStampPtr;
114
115#ifndef _XTYPEDEF_CLIENTPTR
116typedef struct _Client *ClientPtr; /* also in misc.h */
117#define _XTYPEDEF_CLIENTPTR
118#endif
119
120typedef struct _WorkQueue	*WorkQueuePtr;
121
122extern ClientPtr clients[MAXCLIENTS];
123extern ClientPtr serverClient;
124extern int currentMaxClients;
125extern char dispatchExceptionAtReset;
126
127typedef int HWEventQueueType;
128typedef HWEventQueueType* HWEventQueuePtr;
129
130extern HWEventQueuePtr checkForInput[2];
131
132typedef struct _TimeStamp {
133    CARD32 months;	/* really ~49.7 days */
134    CARD32 milliseconds;
135}           TimeStamp;
136
137/* dispatch.c */
138
139extern void SetInputCheck(
140    HWEventQueuePtr /*c0*/,
141    HWEventQueuePtr /*c1*/);
142
143extern void CloseDownClient(
144    ClientPtr /*client*/);
145
146extern void UpdateCurrentTime(void);
147
148extern void UpdateCurrentTimeIf(void);
149
150extern int dixDestroyPixmap(
151    pointer /*value*/,
152    XID /*pid*/);
153
154extern void InitClient(
155    ClientPtr /*client*/,
156    int /*i*/,
157    pointer /*ospriv*/);
158
159extern ClientPtr NextAvailableClient(
160    pointer /*ospriv*/);
161
162extern void SendErrorToClient(
163    ClientPtr /*client*/,
164    unsigned int /*majorCode*/,
165    unsigned int /*minorCode*/,
166    XID /*resId*/,
167    int /*errorCode*/);
168
169extern void MarkClientException(
170    ClientPtr /*client*/);
171
172extern void ddxBeforeReset (void);
173
174/* dixutils.c */
175
176extern void CopyISOLatin1Lowered(
177    unsigned char * /*dest*/,
178    unsigned char * /*source*/,
179    int /*length*/);
180
181extern int CompareISOLatin1Lowered(
182    unsigned char * /*a*/,
183    int alen,
184    unsigned char * /*b*/,
185    int blen);
186
187extern int dixLookupWindow(
188    WindowPtr *result,
189    XID id,
190    ClientPtr client,
191    Mask access_mode);
192
193extern int dixLookupDrawable(
194    DrawablePtr *result,
195    XID id,
196    ClientPtr client,
197    Mask type_mask,
198    Mask access_mode);
199
200extern int dixLookupGC(
201    GCPtr *result,
202    XID id,
203    ClientPtr client,
204    Mask access_mode);
205
206extern int dixLookupClient(
207    ClientPtr *result,
208    XID id,
209    ClientPtr client,
210    Mask access_mode);
211
212extern void NoopDDA(void);
213
214extern int AlterSaveSetForClient(
215    ClientPtr /*client*/,
216    WindowPtr /*pWin*/,
217    unsigned /*mode*/,
218    Bool /*toRoot*/,
219    Bool /*map*/);
220
221extern void DeleteWindowFromAnySaveSet(
222    WindowPtr /*pWin*/);
223
224extern void BlockHandler(
225    pointer /*pTimeout*/,
226    pointer /*pReadmask*/);
227
228extern void WakeupHandler(
229    int /*result*/,
230    pointer /*pReadmask*/);
231
232typedef void (* WakeupHandlerProcPtr)(
233    pointer /* blockData */,
234    int /* result */,
235    pointer /* pReadmask */);
236
237extern Bool RegisterBlockAndWakeupHandlers(
238    BlockHandlerProcPtr /*blockHandler*/,
239    WakeupHandlerProcPtr /*wakeupHandler*/,
240    pointer /*blockData*/);
241
242extern void RemoveBlockAndWakeupHandlers(
243    BlockHandlerProcPtr /*blockHandler*/,
244    WakeupHandlerProcPtr /*wakeupHandler*/,
245    pointer /*blockData*/);
246
247extern void InitBlockAndWakeupHandlers(void);
248
249extern void ProcessWorkQueue(void);
250
251extern void ProcessWorkQueueZombies(void);
252
253extern Bool QueueWorkProc(
254    Bool (* /*function*/)(
255        ClientPtr /*clientUnused*/,
256        pointer /*closure*/),
257    ClientPtr /*client*/,
258    pointer /*closure*/
259);
260
261typedef Bool (* ClientSleepProcPtr)(
262    ClientPtr /*client*/,
263    pointer /*closure*/);
264
265extern Bool ClientSleep(
266    ClientPtr /*client*/,
267    ClientSleepProcPtr /* function */,
268    pointer /*closure*/);
269
270#ifndef ___CLIENTSIGNAL_DEFINED___
271#define ___CLIENTSIGNAL_DEFINED___
272extern Bool ClientSignal(
273    ClientPtr /*client*/);
274#endif /* ___CLIENTSIGNAL_DEFINED___ */
275
276extern void ClientWakeup(
277    ClientPtr /*client*/);
278
279extern Bool ClientIsAsleep(
280    ClientPtr /*client*/);
281
282/* atom.c */
283
284extern Atom MakeAtom(
285    char * /*string*/,
286    unsigned /*len*/,
287    Bool /*makeit*/);
288
289extern Bool ValidAtom(
290    Atom /*atom*/);
291
292extern char *NameForAtom(
293    Atom /*atom*/);
294
295extern void AtomError(void);
296
297extern void FreeAllAtoms(void);
298
299extern void InitAtoms(void);
300
301/* main.c */
302
303extern void SetVendorRelease(int release);
304
305extern void SetVendorString(char *string);
306
307/* events.c */
308
309extern void SetMaskForEvent(
310    int /* deviceid */,
311    Mask /* mask */,
312    int /* event */);
313
314extern void ConfineToShape(
315    DeviceIntPtr /* pDev */,
316    RegionPtr /* shape */,
317    int*      /* px */,
318    int*      /* py */);
319
320extern Bool IsParent(
321    WindowPtr /* maybeparent */,
322    WindowPtr /* child */);
323
324extern WindowPtr GetCurrentRootWindow(DeviceIntPtr pDev);
325
326extern WindowPtr GetSpriteWindow(DeviceIntPtr pDev);
327
328
329extern void NoticeEventTime(xEventPtr /* xE */);
330
331extern void EnqueueEvent(
332    xEventPtr /* xE */,
333    DeviceIntPtr /* device */,
334    int	/* count */);
335
336extern void ActivatePointerGrab(
337    DeviceIntPtr /* mouse */,
338    GrabPtr /* grab */,
339    TimeStamp /* time */,
340    Bool /* autoGrab */);
341
342extern void DeactivatePointerGrab(
343    DeviceIntPtr /* mouse */);
344
345extern void ActivateKeyboardGrab(
346    DeviceIntPtr /* keybd */,
347    GrabPtr /* grab */,
348    TimeStamp /* time */,
349    Bool /* passive */);
350
351extern void DeactivateKeyboardGrab(
352    DeviceIntPtr /* keybd */);
353
354extern void AllowSome(
355    ClientPtr	/* client */,
356    TimeStamp /* time */,
357    DeviceIntPtr /* thisDev */,
358    int /* newState */,
359    Bool /* core */);
360
361extern void ReleaseActiveGrabs(
362    ClientPtr client);
363
364extern int DeliverEventsToWindow(
365    DeviceIntPtr /* pWin */,
366    WindowPtr /* pWin */,
367    xEventPtr /* pEvents */,
368    int /* count */,
369    Mask /* filter */,
370    GrabPtr /* grab */,
371    int /* mskidx */);
372
373extern int DeliverDeviceEvents(
374    WindowPtr /* pWin */,
375    xEventPtr /* xE */,
376    GrabPtr /* grab */,
377    WindowPtr /* stopAt */,
378    DeviceIntPtr /* dev */,
379    int /* count */);
380
381extern void DefineInitialRootWindow(
382    WindowPtr /* win */);
383
384extern void SetupSprite(
385    DeviceIntPtr /* pDev */,
386    ScreenPtr    /* pScreen */);
387
388extern void InitializeSprite(
389    DeviceIntPtr /* pDev */,
390    WindowPtr    /* pWin */);
391
392extern void UpdateSpriteForScreen(
393    DeviceIntPtr /* pDev */,
394    ScreenPtr /* pScreen */);
395
396extern void WindowHasNewCursor(
397    WindowPtr /* pWin */);
398
399extern Bool CheckDeviceGrabs(
400    DeviceIntPtr /* device */,
401    xEventPtr /* xE */,
402    int /* checkFirst */,
403    int /* count */);
404
405extern void DeliverFocusedEvent(
406    DeviceIntPtr /* keybd */,
407    xEventPtr /* xE */,
408    WindowPtr /* window */,
409    int /* count */);
410
411extern void DeliverGrabbedEvent(
412    xEventPtr /* xE */,
413    DeviceIntPtr /* thisDev */,
414    Bool /* deactivateGrab */,
415    int /* count */);
416
417#ifdef XKB
418extern void FixKeyState(
419    xEvent * /* xE */,
420    DeviceIntPtr /* keybd */);
421#endif /* XKB */
422
423extern void RecalculateDeliverableEvents(
424    WindowPtr /* pWin */);
425
426extern int OtherClientGone(
427    pointer /* value */,
428    XID /* id */);
429
430extern void DoFocusEvents(
431    DeviceIntPtr /* dev */,
432    WindowPtr /* fromWin */,
433    WindowPtr /* toWin */,
434    int /* mode */);
435
436extern int SetInputFocus(
437    ClientPtr /* client */,
438    DeviceIntPtr /* dev */,
439    Window /* focusID */,
440    CARD8 /* revertTo */,
441    Time /* ctime */,
442    Bool /* followOK */);
443
444extern int GrabDevice(
445    ClientPtr /* client */,
446    DeviceIntPtr /* dev */,
447    unsigned /* this_mode */,
448    unsigned /* other_mode */,
449    Window /* grabWindow */,
450    unsigned /* ownerEvents */,
451    Time /* ctime */,
452    Mask /* mask */,
453    CARD8 * /* status */,
454    Bool /* coreGrab */);
455
456extern void InitEvents(void);
457extern void InitSprite(
458        DeviceIntPtr /* pDev */,
459        Bool /* hasCursor */
460        );
461
462extern void CloseDownEvents(void);
463
464extern void DeleteWindowFromAnyEvents(
465    WindowPtr	/* pWin */,
466    Bool /* freeResources */);
467
468
469extern Mask EventMaskForClient(
470    WindowPtr /* pWin */,
471    ClientPtr /* client */);
472
473
474
475extern int DeliverEvents(
476    WindowPtr /*pWin*/,
477    xEventPtr /*xE*/,
478    int /*count*/,
479    WindowPtr /*otherParent*/);
480
481extern Bool
482CheckMotion(
483    xEvent* /* xE */,
484    DeviceIntPtr /* pDev */);
485
486extern void WriteEventsToClient(
487    ClientPtr /*pClient*/,
488    int	     /*count*/,
489    xEventPtr /*events*/);
490
491extern int TryClientEvents(
492    ClientPtr /*client*/,
493    DeviceIntPtr /* device */,
494    xEventPtr /*pEvents*/,
495    int /*count*/,
496    Mask /*mask*/,
497    Mask /*filter*/,
498    GrabPtr /*grab*/);
499
500extern void WindowsRestructured(void);
501
502extern Bool SetClientPointer(
503        ClientPtr /* client */,
504        ClientPtr /* setter */,
505        DeviceIntPtr /* device */);
506
507extern DeviceIntPtr PickPointer(
508    ClientPtr /* client */);
509
510extern DeviceIntPtr PickKeyboard(
511    ClientPtr /* client */);
512
513extern Bool IsInterferingGrab(
514        ClientPtr /* client */,
515        DeviceIntPtr /* dev */,
516        xEvent* /* events */);
517
518#ifdef PANORAMIX
519extern void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff);
520#endif
521
522#ifdef RANDR
523void
524ScreenRestructured (ScreenPtr pScreen);
525#endif
526
527extern int ffs(int i);
528
529/*
530 *  callback manager stuff
531 */
532
533#ifndef _XTYPEDEF_CALLBACKLISTPTR
534typedef struct _CallbackList *CallbackListPtr; /* also in misc.h */
535#define _XTYPEDEF_CALLBACKLISTPTR
536#endif
537
538typedef void (*CallbackProcPtr) (
539    CallbackListPtr *, pointer, pointer);
540
541extern Bool AddCallback(
542    CallbackListPtr * /*pcbl*/,
543    CallbackProcPtr /*callback*/,
544    pointer /*data*/);
545
546extern Bool DeleteCallback(
547    CallbackListPtr * /*pcbl*/,
548    CallbackProcPtr /*callback*/,
549    pointer /*data*/);
550
551extern void CallCallbacks(
552    CallbackListPtr * /*pcbl*/,
553    pointer /*call_data*/);
554
555extern void DeleteCallbackList(
556    CallbackListPtr * /*pcbl*/);
557
558extern void InitCallbackManager(void);
559
560/*
561 *  ServerGrabCallback stuff
562 */
563
564extern CallbackListPtr ServerGrabCallback;
565
566typedef enum {SERVER_GRABBED, SERVER_UNGRABBED,
567	      CLIENT_PERVIOUS, CLIENT_IMPERVIOUS } ServerGrabState;
568
569typedef struct {
570    ClientPtr client;
571    ServerGrabState grabstate;
572} ServerGrabInfoRec;
573
574/*
575 *  EventCallback stuff
576 */
577
578extern CallbackListPtr EventCallback;
579
580typedef struct {
581    ClientPtr client;
582    xEventPtr events;
583    int count;
584} EventInfoRec;
585
586/*
587 *  DeviceEventCallback stuff
588 */
589
590extern CallbackListPtr DeviceEventCallback;
591
592typedef struct {
593    xEventPtr events;
594    int count;
595} DeviceEventInfoRec;
596
597extern int XItoCoreType(int xi_type);
598extern Bool DevHasCursor(DeviceIntPtr pDev);
599extern Bool IsPointerDevice( DeviceIntPtr dev);
600extern Bool IsKeyboardDevice(DeviceIntPtr dev);
601extern Bool IsPointerEvent(xEvent* xE);
602
603/*
604 * These are deprecated compatibility functions and will be removed soon!
605 * Please use the noted replacements instead.
606 */
607/* replaced by dixLookupWindow */
608extern WindowPtr SecurityLookupWindow(
609    XID id,
610    ClientPtr client,
611    Mask access_mode);
612/* replaced by dixLookupWindow */
613extern WindowPtr LookupWindow(
614    XID id,
615    ClientPtr client);
616
617/* replaced by dixLookupDrawable */
618extern pointer SecurityLookupDrawable(
619    XID id,
620    ClientPtr client,
621    Mask access_mode);
622
623/* replaced by dixLookupDrawable */
624extern pointer LookupDrawable(
625    XID id,
626    ClientPtr client);
627
628/* replaced by dixLookupClient */
629extern ClientPtr LookupClient(
630    XID id,
631    ClientPtr client);
632
633/* GE stuff */
634extern void SetGenericFilter(int extension, Mask* filters);
635extern int ExtGrabDevice(ClientPtr client,
636                         DeviceIntPtr dev,
637                         int device_mode,
638                         WindowPtr grabWindow,
639                         WindowPtr confineTo,
640                         TimeStamp ctime,
641                         Bool ownerEvents,
642                         CursorPtr cursor,
643                         Mask xi_mask,
644                         GenericMaskPtr ge_masks);
645#endif /* DIX_H */
646