1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun Copyright 1993 by Davor Matic
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun Permission to use, copy, modify, distribute, and sell this software
6*4882a593Smuzhiyun and its documentation for any purpose is hereby granted without fee,
7*4882a593Smuzhiyun provided that the above copyright notice appear in all copies and that
8*4882a593Smuzhiyun both that copyright notice and this permission notice appear in
9*4882a593Smuzhiyun supporting documentation. Davor Matic makes no representations about
10*4882a593Smuzhiyun the suitability of this software for any purpose. It is provided "as
11*4882a593Smuzhiyun is" without express or implied warranty.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #ifdef HAVE_XNEST_CONFIG_H
16*4882a593Smuzhiyun #include <xnest-config.h>
17*4882a593Smuzhiyun #endif
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <X11/X.h>
20*4882a593Smuzhiyun #include <X11/Xproto.h>
21*4882a593Smuzhiyun #include "screenint.h"
22*4882a593Smuzhiyun #include "input.h"
23*4882a593Smuzhiyun #include "misc.h"
24*4882a593Smuzhiyun #include "scrnintstr.h"
25*4882a593Smuzhiyun #include "windowstr.h"
26*4882a593Smuzhiyun #include "servermd.h"
27*4882a593Smuzhiyun #include "inputstr.h"
28*4882a593Smuzhiyun #include "inpututils.h"
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include "mi.h"
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "Xnest.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include "Args.h"
35*4882a593Smuzhiyun #include "Color.h"
36*4882a593Smuzhiyun #include "Display.h"
37*4882a593Smuzhiyun #include "Screen.h"
38*4882a593Smuzhiyun #include "XNWindow.h"
39*4882a593Smuzhiyun #include "Events.h"
40*4882a593Smuzhiyun #include "Keyboard.h"
41*4882a593Smuzhiyun #include "Pointer.h"
42*4882a593Smuzhiyun #include "mipointer.h"
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun CARD32 lastEventTime = 0;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun void
ProcessInputEvents(void)47*4882a593Smuzhiyun ProcessInputEvents(void)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun mieqProcessInputEvents();
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun int
TimeSinceLastInputEvent(void)53*4882a593Smuzhiyun TimeSinceLastInputEvent(void)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun if (lastEventTime == 0)
56*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
57*4882a593Smuzhiyun return GetTimeInMillis() - lastEventTime;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun void
SetTimeSinceLastInputEvent(void)61*4882a593Smuzhiyun SetTimeSinceLastInputEvent(void)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun static Bool
xnestExposurePredicate(Display * dpy,XEvent * event,char * args)67*4882a593Smuzhiyun xnestExposurePredicate(Display * dpy, XEvent * event, char *args)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun return event->type == Expose || event->type == ProcessedExpose;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun static Bool
xnestNotExposurePredicate(Display * dpy,XEvent * event,char * args)73*4882a593Smuzhiyun xnestNotExposurePredicate(Display * dpy, XEvent * event, char *args)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun return !xnestExposurePredicate(dpy, event, args);
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun void
xnestCollectExposures(void)79*4882a593Smuzhiyun xnestCollectExposures(void)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun XEvent X;
82*4882a593Smuzhiyun WindowPtr pWin;
83*4882a593Smuzhiyun RegionRec Rgn;
84*4882a593Smuzhiyun BoxRec Box;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun while (XCheckIfEvent(xnestDisplay, &X, xnestExposurePredicate, NULL)) {
87*4882a593Smuzhiyun pWin = xnestWindowPtr(X.xexpose.window);
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun if (pWin && X.xexpose.width && X.xexpose.height) {
90*4882a593Smuzhiyun Box.x1 = pWin->drawable.x + wBorderWidth(pWin) + X.xexpose.x;
91*4882a593Smuzhiyun Box.y1 = pWin->drawable.y + wBorderWidth(pWin) + X.xexpose.y;
92*4882a593Smuzhiyun Box.x2 = Box.x1 + X.xexpose.width;
93*4882a593Smuzhiyun Box.y2 = Box.y1 + X.xexpose.height;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun RegionInit(&Rgn, &Box, 1);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun miSendExposures(pWin, &Rgn, Box.x2, Box.y2);
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun void
xnestQueueKeyEvent(int type,unsigned int keycode)103*4882a593Smuzhiyun xnestQueueKeyEvent(int type, unsigned int keycode)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
106*4882a593Smuzhiyun QueueKeyboardEvents(xnestKeyboardDevice, type, keycode);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun void
xnestCollectEvents(void)110*4882a593Smuzhiyun xnestCollectEvents(void)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun XEvent X;
113*4882a593Smuzhiyun int valuators[2];
114*4882a593Smuzhiyun ValuatorMask mask;
115*4882a593Smuzhiyun ScreenPtr pScreen;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun while (XCheckIfEvent(xnestDisplay, &X, xnestNotExposurePredicate, NULL)) {
118*4882a593Smuzhiyun switch (X.type) {
119*4882a593Smuzhiyun case KeyPress:
120*4882a593Smuzhiyun xnestUpdateModifierState(X.xkey.state);
121*4882a593Smuzhiyun xnestQueueKeyEvent(KeyPress, X.xkey.keycode);
122*4882a593Smuzhiyun break;
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun case KeyRelease:
125*4882a593Smuzhiyun xnestUpdateModifierState(X.xkey.state);
126*4882a593Smuzhiyun xnestQueueKeyEvent(KeyRelease, X.xkey.keycode);
127*4882a593Smuzhiyun break;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun case ButtonPress:
130*4882a593Smuzhiyun valuator_mask_set_range(&mask, 0, 0, NULL);
131*4882a593Smuzhiyun xnestUpdateModifierState(X.xkey.state);
132*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
133*4882a593Smuzhiyun QueuePointerEvents(xnestPointerDevice, ButtonPress,
134*4882a593Smuzhiyun X.xbutton.button, POINTER_RELATIVE, &mask);
135*4882a593Smuzhiyun break;
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun case ButtonRelease:
138*4882a593Smuzhiyun valuator_mask_set_range(&mask, 0, 0, NULL);
139*4882a593Smuzhiyun xnestUpdateModifierState(X.xkey.state);
140*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
141*4882a593Smuzhiyun QueuePointerEvents(xnestPointerDevice, ButtonRelease,
142*4882a593Smuzhiyun X.xbutton.button, POINTER_RELATIVE, &mask);
143*4882a593Smuzhiyun break;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun case MotionNotify:
146*4882a593Smuzhiyun valuators[0] = X.xmotion.x;
147*4882a593Smuzhiyun valuators[1] = X.xmotion.y;
148*4882a593Smuzhiyun valuator_mask_set_range(&mask, 0, 2, valuators);
149*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
150*4882a593Smuzhiyun QueuePointerEvents(xnestPointerDevice, MotionNotify,
151*4882a593Smuzhiyun 0, POINTER_ABSOLUTE, &mask);
152*4882a593Smuzhiyun break;
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun case FocusIn:
155*4882a593Smuzhiyun if (X.xfocus.detail != NotifyInferior) {
156*4882a593Smuzhiyun pScreen = xnestScreen(X.xfocus.window);
157*4882a593Smuzhiyun if (pScreen)
158*4882a593Smuzhiyun xnestDirectInstallColormaps(pScreen);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun break;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun case FocusOut:
163*4882a593Smuzhiyun if (X.xfocus.detail != NotifyInferior) {
164*4882a593Smuzhiyun pScreen = xnestScreen(X.xfocus.window);
165*4882a593Smuzhiyun if (pScreen)
166*4882a593Smuzhiyun xnestDirectUninstallColormaps(pScreen);
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun break;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun case KeymapNotify:
171*4882a593Smuzhiyun break;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun case EnterNotify:
174*4882a593Smuzhiyun if (X.xcrossing.detail != NotifyInferior) {
175*4882a593Smuzhiyun pScreen = xnestScreen(X.xcrossing.window);
176*4882a593Smuzhiyun if (pScreen) {
177*4882a593Smuzhiyun NewCurrentScreen(inputInfo.pointer, pScreen, X.xcrossing.x,
178*4882a593Smuzhiyun X.xcrossing.y);
179*4882a593Smuzhiyun valuators[0] = X.xcrossing.x;
180*4882a593Smuzhiyun valuators[1] = X.xcrossing.y;
181*4882a593Smuzhiyun valuator_mask_set_range(&mask, 0, 2, valuators);
182*4882a593Smuzhiyun lastEventTime = GetTimeInMillis();
183*4882a593Smuzhiyun QueuePointerEvents(xnestPointerDevice, MotionNotify,
184*4882a593Smuzhiyun 0, POINTER_ABSOLUTE, &mask);
185*4882a593Smuzhiyun xnestDirectInstallColormaps(pScreen);
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun break;
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun case LeaveNotify:
191*4882a593Smuzhiyun if (X.xcrossing.detail != NotifyInferior) {
192*4882a593Smuzhiyun pScreen = xnestScreen(X.xcrossing.window);
193*4882a593Smuzhiyun if (pScreen) {
194*4882a593Smuzhiyun xnestDirectUninstallColormaps(pScreen);
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun break;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun case DestroyNotify:
200*4882a593Smuzhiyun if (xnestParentWindow != (Window) 0 &&
201*4882a593Smuzhiyun X.xdestroywindow.window == xnestParentWindow)
202*4882a593Smuzhiyun exit(0);
203*4882a593Smuzhiyun break;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun case CirculateNotify:
206*4882a593Smuzhiyun case ConfigureNotify:
207*4882a593Smuzhiyun case GravityNotify:
208*4882a593Smuzhiyun case MapNotify:
209*4882a593Smuzhiyun case ReparentNotify:
210*4882a593Smuzhiyun case UnmapNotify:
211*4882a593Smuzhiyun break;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun default:
214*4882a593Smuzhiyun ErrorF("xnest warning: unhandled event\n");
215*4882a593Smuzhiyun break;
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun }
219