Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xnest / Events.c
blob38fefa7a251a547f8f6ab7ef1aeab2eb7dcb9cb4
1 /*
3 Copyright 1993 by Davor Matic
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in
9 supporting documentation. Davor Matic makes no representations about
10 the suitability of this software for any purpose. It is provided "as
11 is" without express or implied warranty.
15 #ifdef HAVE_XNEST_CONFIG_H
16 #include <xnest-config.h>
17 #endif
19 #include <X11/X.h>
20 #define NEED_EVENTS
21 #include <X11/Xproto.h>
22 #include "screenint.h"
23 #include "input.h"
24 #include "misc.h"
25 #include "scrnintstr.h"
26 #include "windowstr.h"
27 #include "servermd.h"
29 #include "mi.h"
31 #include "Xnest.h"
33 #include "Args.h"
34 #include "Color.h"
35 #include "Display.h"
36 #include "Screen.h"
37 #include "XNWindow.h"
38 #include "Events.h"
39 #include "Keyboard.h"
40 #include "Pointer.h"
41 #include "mipointer.h"
43 CARD32 lastEventTime = 0;
45 extern xEvent *xnestEvents;
47 void
48 ProcessInputEvents()
50 mieqProcessInputEvents();
51 miPointerUpdate();
54 int
55 TimeSinceLastInputEvent(void)
57 if (lastEventTime == 0)
58 lastEventTime = GetTimeInMillis();
59 return GetTimeInMillis() - lastEventTime;
62 void
63 SetTimeSinceLastInputEvent(void)
65 lastEventTime = GetTimeInMillis();
68 static Bool
69 xnestExposurePredicate(Display *display, XEvent *event, char *args)
71 return (event->type == Expose || event->type == ProcessedExpose);
74 static Bool
75 xnestNotExposurePredicate(Display *display, XEvent *event, char *args)
77 return !xnestExposurePredicate(display, event, args);
80 void
81 xnestCollectExposures(void)
83 XEvent X;
84 WindowPtr pWin;
85 RegionRec Rgn;
86 BoxRec Box;
88 while (XCheckIfEvent(xnestDisplay, &X, xnestExposurePredicate, NULL)) {
89 pWin = xnestWindowPtr(X.xexpose.window);
91 if (pWin) {
92 Box.x1 = pWin->drawable.x + wBorderWidth(pWin) + X.xexpose.x;
93 Box.y1 = pWin->drawable.y + wBorderWidth(pWin) + X.xexpose.y;
94 Box.x2 = Box.x1 + X.xexpose.width;
95 Box.y2 = Box.y1 + X.xexpose.height;
97 REGION_INIT(pWin->drawable.pScreen, &Rgn, &Box, 1);
99 miWindowExposures(pWin, &Rgn, NullRegion);
104 void
105 xnestQueueKeyEvent(int type, unsigned int keycode)
107 int i, n;
109 lastEventTime = GetTimeInMillis();
110 n = GetKeyboardEvents(xnestEvents, xnestKeyboardDevice, type, keycode);
111 for (i = 0; i < n; i++)
112 mieqEnqueue(xnestKeyboardDevice, xnestEvents + i);
115 void
116 xnestCollectEvents(void)
118 XEvent X;
119 xEvent x;
120 int i, n, valuators[2];
121 ScreenPtr pScreen;
123 while (XCheckIfEvent(xnestDisplay, &X, xnestNotExposurePredicate, NULL)) {
124 switch (X.type) {
125 case KeyPress:
126 xnestUpdateModifierState(X.xkey.state);
127 xnestQueueKeyEvent(KeyPress, X.xkey.keycode);
128 break;
130 case KeyRelease:
131 xnestUpdateModifierState(X.xkey.state);
132 xnestQueueKeyEvent(KeyRelease, X.xkey.keycode);
133 break;
135 case ButtonPress:
136 xnestUpdateModifierState(X.xkey.state);
137 lastEventTime = GetTimeInMillis();
138 n = GetPointerEvents(xnestEvents, xnestPointerDevice, ButtonPress,
139 X.xbutton.button, POINTER_RELATIVE, 0, 0, NULL);
140 for (i = 0; i < n; i++)
141 mieqEnqueue(xnestPointerDevice, xnestEvents + i);
142 break;
144 case ButtonRelease:
145 xnestUpdateModifierState(X.xkey.state);
146 lastEventTime = GetTimeInMillis();
147 n = GetPointerEvents(xnestEvents, xnestPointerDevice, ButtonRelease,
148 X.xbutton.button, POINTER_RELATIVE, 0, 0, NULL);
149 for (i = 0; i < n; i++)
150 mieqEnqueue(xnestPointerDevice, xnestEvents + i);
151 break;
153 case MotionNotify:
154 valuators[0] = X.xmotion.x;
155 valuators[1] = X.xmotion.y;
156 lastEventTime = GetTimeInMillis();
157 n = GetPointerEvents(xnestEvents, xnestPointerDevice, MotionNotify,
158 0, POINTER_ABSOLUTE, 0, 2, valuators);
159 for (i = 0; i < n; i++)
160 mieqEnqueue(xnestPointerDevice, xnestEvents + i);
161 break;
163 case FocusIn:
164 if (X.xfocus.detail != NotifyInferior) {
165 pScreen = xnestScreen(X.xfocus.window);
166 if (pScreen)
167 xnestDirectInstallColormaps(pScreen);
169 break;
171 case FocusOut:
172 if (X.xfocus.detail != NotifyInferior) {
173 pScreen = xnestScreen(X.xfocus.window);
174 if (pScreen)
175 xnestDirectUninstallColormaps(pScreen);
177 break;
179 case KeymapNotify:
180 break;
182 case EnterNotify:
183 if (X.xcrossing.detail != NotifyInferior) {
184 pScreen = xnestScreen(X.xcrossing.window);
185 if (pScreen) {
186 NewCurrentScreen(pScreen, X.xcrossing.x, X.xcrossing.y);
187 valuators[0] = X.xcrossing.x;
188 valuators[1] = X.xcrossing.y;
189 lastEventTime = GetTimeInMillis();
190 n = GetPointerEvents(xnestEvents, xnestPointerDevice, MotionNotify,
191 0, POINTER_ABSOLUTE, 0, 2, valuators);
192 for (i = 0; i < n; i++)
193 mieqEnqueue(xnestPointerDevice, xnestEvents + i);
194 xnestDirectInstallColormaps(pScreen);
197 break;
199 case LeaveNotify:
200 if (X.xcrossing.detail != NotifyInferior) {
201 pScreen = xnestScreen(X.xcrossing.window);
202 if (pScreen) {
203 xnestDirectUninstallColormaps(pScreen);
206 break;
208 case DestroyNotify:
209 if (xnestParentWindow != (Window) 0 &&
210 X.xdestroywindow.window == xnestParentWindow)
211 exit (0);
212 break;
214 case CirculateNotify:
215 case ConfigureNotify:
216 case GravityNotify:
217 case MapNotify:
218 case ReparentNotify:
219 case UnmapNotify:
220 break;
222 default:
223 ErrorF("xnest warning: unhandled event\n");
224 break;