First import
[xorg_rtime.git] / xorg-server-1.4 / XTrap / xtrapddmi.c
blob73a20c1f66a900a9c4aec012056f06722cc23378
1 /*****************************************************************************
2 Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
4 Permission to use, copy, modify, and distribute this software and its
5 documentation for any purpose and without fee is hereby granted,
6 provided that the above copyright notice appear in all copies and that
7 both that copyright notice and this permission notice appear in
8 supporting documentation, and that the name of Digital not be
9 used in advertising or publicity pertaining to distribution of the
10 software without specific, written prior permission.
12 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
14 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
15 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
17 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
18 SOFTWARE.
20 *****************************************************************************/
22 * ABSTRACT:
24 * This module is the platform-specific but conditionally independent
25 * code for the XTrap extension (usually I/O or platform setup).
26 * This is shared code and is subject to change only by team approval.
28 * CONTRIBUTORS:
30 * Dick Annicchiarico
31 * Robert Chesler
32 * Gene Durso
33 * Marc Evans
34 * Alan Jamison
35 * Mark Henry
36 * Ken Miller
40 #ifdef HAVE_DIX_CONFIG_H
41 #include <dix-config.h>
42 #endif
44 #include <errno.h>
45 #include <X11/Xos.h>
46 #ifdef PC
47 # include "fcntl.h"
48 # include "io.h"
49 # define O_NDELAY 0L
50 #endif
52 #define NEED_REPLIES
53 #define NEED_EVENTS
54 #include <X11/X.h> /* From library include environment */
55 #include "input.h" /* From server include env. (must be before Xlib.h!) */
56 #ifdef PC
57 # include "scrintst.h" /* Screen struct */
58 # include "extnsist.h"
59 #else
60 # include "extnsionst.h" /* Server ExtensionEntry definitions */
61 # include "scrnintstr.h" /* Screen struct */
62 #endif
64 #include <X11/extensions/xtrapdi.h>
65 #include <X11/extensions/xtrapddmi.h>
66 #include <X11/extensions/xtrapproto.h>
68 extern int XETrapErrorBase;
69 extern xXTrapGetAvailReply XETrap_avail;
70 extern DevicePtr XETrapKbdDev;
71 extern DevicePtr XETrapPtrDev;
74 * DESCRIPTION:
76 * This function performs the platform specific setup for server
77 * extension implementations.
79 void XETrapPlatformSetup()
84 #if !defined _XINPUT
86 * DESCRIPTION:
88 * This routine processes the simulation of some input event.
91 int XETrapSimulateXEvent(register xXTrapInputReq *request,
92 register ClientPtr client)
94 ScreenPtr pScr = NULL;
95 int status = Success;
96 xEvent xev;
97 register int x = request->input.x;
98 register int y = request->input.y;
99 DevicePtr keydev = LookupKeyboardDevice();
100 DevicePtr ptrdev = LookupPointerDevice();
102 if (request->input.screen < screenInfo.numScreens)
104 pScr = screenInfo.screens[request->input.screen];
106 else
107 { /* Trying to play bogus events to this WS! */
108 #ifdef VERBOSE
109 ErrorF("%s: Trying to send events to screen %d!\n", XTrapExtName,
110 request->input.screen);
111 #endif
112 status = XETrapErrorBase + BadScreen;
114 /* Fill in the event structure with the information
115 * Note: root, event, child, eventX, eventY, state, and sameScreen
116 * are all updated by FixUpEventFromWindow() when the events
117 * are delivered via DeliverDeviceEvents() or whatever. XTrap
118 * needs to only concern itself with type, detail, time, rootX,
119 * and rootY.
121 if (status == Success)
123 xev.u.u.type = request->input.type;
124 xev.u.u.detail = request->input.detail;
125 xev.u.keyButtonPointer.time = GetTimeInMillis();
126 xev.u.keyButtonPointer.rootX = x;
127 xev.u.keyButtonPointer.rootY = y;
129 if (request->input.type == MotionNotify)
130 { /* Set new cursor position on screen */
131 XETrap_avail.data.cur_x = x;
132 XETrap_avail.data.cur_y = y;
133 NewCurrentScreen (pScr, x, y); /* fix from amnonc@mercury.co.il */
134 if (!(*pScr->SetCursorPosition)(pScr, x, y, xFalse))
136 status = BadImplementation;
140 if (status == Success)
142 switch(request->input.type)
143 { /* Now process the event appropriately */
144 case KeyPress:
145 case KeyRelease:
146 (*XETrapKbdDev->realInputProc)(&xev,(DeviceIntPtr)keydev, 1L);
147 break;
148 case MotionNotify:
149 case ButtonPress:
150 case ButtonRelease:
151 (*XETrapPtrDev->realInputProc)(&xev,(DeviceIntPtr)ptrdev, 1L);
152 break;
153 default:
154 status = BadValue;
155 break;
158 return(status);
160 #endif /* _XINPUT */