-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathevents.c
6152 lines (5435 loc) · 191 KB
/
events.c
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR 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.
********************************************************/
/* The panoramix components contained the following notice */
/*****************************************************************
Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
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, sublicense, and/or sell
copies of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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. IN NO EVENT SHALL
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Digital Equipment Corporation
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from Digital
Equipment Corporation.
******************************************************************/
/*
* Copyright (c) 2003-2005, Oracle and/or its affiliates. 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, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* 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. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/** @file events.c
* This file handles event delivery and a big part of the server-side protocol
* handling (the parts for input devices).
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include "misc.h"
#include "resource.h"
#include <X11/Xproto.h>
#include "windowstr.h"
#include "inputstr.h"
#include "inpututils.h"
#include "scrnintstr.h"
#include "cursorstr.h"
#include "dixstruct.h"
#ifdef PANORAMIX
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif
#include "globals.h"
#include <X11/extensions/XKBproto.h>
#include "xkbsrv.h"
#include "xace.h"
#include "probes.h"
#include <X11/extensions/XIproto.h>
#include <X11/extensions/XI2proto.h>
#include <X11/extensions/XI.h>
#include <X11/extensions/XI2.h>
#include "exglobals.h"
#include "exevents.h"
#include "extnsionst.h"
#include "dixevents.h"
#include "dixgrabs.h"
#include "dispatch.h"
#include <X11/extensions/ge.h>
#include "geext.h"
#include "geint.h"
#include "eventstr.h"
#include "enterleave.h"
#include "eventconvert.h"
#include "mi.h"
/* Extension events type numbering starts at EXTENSION_EVENT_BASE. */
#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */
#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask )
#define AllButtonsMask ( \
Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
#define MotionMask ( \
PointerMotionMask | Button1MotionMask | \
Button2MotionMask | Button3MotionMask | Button4MotionMask | \
Button5MotionMask | ButtonMotionMask )
#define PropagateMask ( \
KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \
MotionMask )
#define PointerGrabMask ( \
ButtonPressMask | ButtonReleaseMask | \
EnterWindowMask | LeaveWindowMask | \
PointerMotionHintMask | KeymapStateMask | \
MotionMask )
#define AllModifiersMask ( \
ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \
Mod3Mask | Mod4Mask | Mod5Mask )
#define LastEventMask OwnerGrabButtonMask
#define AllEventMasks (LastEventMask|(LastEventMask-1))
/* @return the core event type or 0 if the event is not a core event */
static inline int
core_get_type(const xEvent *event)
{
int type = event->u.u.type;
return ((type & EXTENSION_EVENT_BASE) || type == GenericEvent) ? 0 : type;
}
/* @return the XI2 event type or 0 if the event is not a XI2 event */
static inline int
xi2_get_type(const xEvent *event)
{
const xGenericEvent *e = (const xGenericEvent *) event;
return (e->type != GenericEvent ||
e->extension != IReqCode) ? 0 : e->evtype;
}
/**
* Used to indicate a implicit passive grab created by a ButtonPress event.
* See DeliverEventsToWindow().
*/
#define ImplicitGrabMask (1 << 7)
#define WID(w) ((w) ? ((w)->drawable.id) : 0)
#define XE_KBPTR (xE->u.keyButtonPointer)
CallbackListPtr EventCallback;
CallbackListPtr DeviceEventCallback;
#define DNPMCOUNT 8
Mask DontPropagateMasks[DNPMCOUNT];
static int DontPropagateRefCnts[DNPMCOUNT];
static void CheckVirtualMotion(DeviceIntPtr pDev, QdEventPtr qe,
WindowPtr pWin);
static void CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor,
Bool generateEvents, Bool confineToScreen,
ScreenPtr pScreen);
static Bool IsWrongPointerBarrierClient(ClientPtr client,
DeviceIntPtr dev,
xEvent *event);
/** Key repeat hack. Do not use but in TryClientEvents */
extern BOOL EventIsKeyRepeat(xEvent *event);
/**
* Main input device struct.
* inputInfo.pointer
* is the core pointer. Referred to as "virtual core pointer", "VCP",
* "core pointer" or inputInfo.pointer. The VCP is the first master
* pointer device and cannot be deleted.
*
* inputInfo.keyboard
* is the core keyboard ("virtual core keyboard", "VCK", "core keyboard").
* See inputInfo.pointer.
*
* inputInfo.devices
* linked list containing all devices including VCP and VCK.
*
* inputInfo.off_devices
* Devices that have not been initialized and are thus turned off.
*
* inputInfo.numDevices
* Total number of devices.
*
* inputInfo.all_devices
* Virtual device used for XIAllDevices passive grabs. This device is
* not part of the inputInfo.devices list and mostly unset except for
* the deviceid. It exists because passivegrabs need a valid device
* reference.
*
* inputInfo.all_master_devices
* Virtual device used for XIAllMasterDevices passive grabs. This device
* is not part of the inputInfo.devices list and mostly unset except for
* the deviceid. It exists because passivegrabs need a valid device
* reference.
*/
InputInfo inputInfo;
EventSyncInfoRec syncEvents;
static struct DeviceEventTime {
Bool reset;
TimeStamp time;
} lastDeviceEventTime[MAXDEVICES];
/**
* The root window the given device is currently on.
*/
#define RootWindow(sprite) sprite->spriteTrace[0]
static xEvent *swapEvent = NULL;
static int swapEventLen = 0;
void
NotImplemented(xEvent *from, xEvent *to)
{
FatalError("Not implemented");
}
/**
* Convert the given event type from an XI event to a core event.
* @param[in] The XI 1.x event type.
* @return The matching core event type or 0 if there is none.
*/
int
XItoCoreType(int xitype)
{
int coretype = 0;
if (xitype == DeviceMotionNotify)
coretype = MotionNotify;
else if (xitype == DeviceButtonPress)
coretype = ButtonPress;
else if (xitype == DeviceButtonRelease)
coretype = ButtonRelease;
else if (xitype == DeviceKeyPress)
coretype = KeyPress;
else if (xitype == DeviceKeyRelease)
coretype = KeyRelease;
return coretype;
}
/**
* @return true if the device owns a cursor, false if device shares a cursor
* sprite with another device.
*/
Bool
DevHasCursor(DeviceIntPtr pDev)
{
return pDev->spriteInfo->spriteOwner;
}
/*
* @return true if a device is a pointer, check is the same as used by XI to
* fill the 'use' field.
*/
Bool
IsPointerDevice(DeviceIntPtr dev)
{
return (dev->type == MASTER_POINTER) ||
(dev->valuator && dev->button) || (dev->valuator && !dev->key);
}
/*
* @return true if a device is a keyboard, check is the same as used by XI to
* fill the 'use' field.
*
* Some pointer devices have keys as well (e.g. multimedia keys). Try to not
* count them as keyboard devices.
*/
Bool
IsKeyboardDevice(DeviceIntPtr dev)
{
return (dev->type == MASTER_KEYBOARD) ||
((dev->key && dev->kbdfeed) && !IsPointerDevice(dev));
}
Bool
IsMaster(DeviceIntPtr dev)
{
return dev->type == MASTER_POINTER || dev->type == MASTER_KEYBOARD;
}
Bool
IsFloating(DeviceIntPtr dev)
{
return !IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == NULL;
}
/**
* Max event opcode.
*/
extern int lastEvent;
#define CantBeFiltered NoEventMask
/**
* Event masks for each event type.
*
* One set of filters for each device, initialized by memcpy of
* default_filter in InitEvents.
*
* Filters are used whether a given event may be delivered to a client,
* usually in the form of if (window-event-mask & filter); then deliver event.
*
* One notable filter is for PointerMotion/DevicePointerMotion events. Each
* time a button is pressed, the filter is modified to also contain the
* matching ButtonXMotion mask.
*/
Mask event_filters[MAXDEVICES][MAXEVENTS];
static const Mask default_filter[MAXEVENTS] = {
NoSuchEvent, /* 0 */
NoSuchEvent, /* 1 */
KeyPressMask, /* KeyPress */
KeyReleaseMask, /* KeyRelease */
ButtonPressMask, /* ButtonPress */
ButtonReleaseMask, /* ButtonRelease */
PointerMotionMask, /* MotionNotify (initial state) */
EnterWindowMask, /* EnterNotify */
LeaveWindowMask, /* LeaveNotify */
FocusChangeMask, /* FocusIn */
FocusChangeMask, /* FocusOut */
KeymapStateMask, /* KeymapNotify */
ExposureMask, /* Expose */
CantBeFiltered, /* GraphicsExpose */
CantBeFiltered, /* NoExpose */
VisibilityChangeMask, /* VisibilityNotify */
SubstructureNotifyMask, /* CreateNotify */
StructureAndSubMask, /* DestroyNotify */
StructureAndSubMask, /* UnmapNotify */
StructureAndSubMask, /* MapNotify */
SubstructureRedirectMask, /* MapRequest */
StructureAndSubMask, /* ReparentNotify */
StructureAndSubMask, /* ConfigureNotify */
SubstructureRedirectMask, /* ConfigureRequest */
StructureAndSubMask, /* GravityNotify */
ResizeRedirectMask, /* ResizeRequest */
StructureAndSubMask, /* CirculateNotify */
SubstructureRedirectMask, /* CirculateRequest */
PropertyChangeMask, /* PropertyNotify */
CantBeFiltered, /* SelectionClear */
CantBeFiltered, /* SelectionRequest */
CantBeFiltered, /* SelectionNotify */
ColormapChangeMask, /* ColormapNotify */
CantBeFiltered, /* ClientMessage */
CantBeFiltered /* MappingNotify */
};
/**
* For the given event, return the matching event filter. This filter may then
* be AND'ed with the selected event mask.
*
* For XI2 events, the returned filter is simply the byte containing the event
* mask we're interested in. E.g. for a mask of (1 << 13), this would be
* byte[1].
*
* @param[in] dev The device the event belongs to, may be NULL.
* @param[in] event The event to get the filter for. Only the type of the
* event matters, or the extension + evtype for GenericEvents.
* @return The filter mask for the given event.
*
* @see GetEventMask
*/
Mask
GetEventFilter(DeviceIntPtr dev, xEvent *event)
{
int evtype = 0;
if (event->u.u.type != GenericEvent)
return event_get_filter_from_type(dev, event->u.u.type);
else if ((evtype = xi2_get_type(event)))
return event_get_filter_from_xi2type(evtype);
ErrorF("[dix] Unknown event type %d. No filter\n", event->u.u.type);
return 0;
}
/**
* Return the single byte of the device's XI2 mask that contains the mask
* for the event_type.
*/
int
GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type)
{
/* we just return the matching filter because that's the only use
* for this mask anyway.
*/
if (xi2mask_isset(mask, dev, event_type))
return event_get_filter_from_xi2type(event_type);
else
return 0;
}
/**
* @return TRUE if the mask is set for this event from this device on the
* window, or FALSE otherwise.
*/
Bool
WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent *ev)
{
OtherInputMasks *inputMasks = wOtherInputMasks(win);
int evtype;
if (!inputMasks || xi2_get_type(ev) == 0)
return 0;
evtype = ((xGenericEvent *) ev)->evtype;
return xi2mask_isset(inputMasks->xi2mask, dev, evtype);
}
Mask
GetEventMask(DeviceIntPtr dev, xEvent *event, InputClients * other)
{
int evtype;
/* XI2 filters are only ever 8 bit, so let's return a 8 bit mask */
if ((evtype = xi2_get_type(event))) {
return GetXI2MaskByte(other->xi2mask, dev, evtype);
}
else if (core_get_type(event) != 0)
return other->mask[XIAllDevices];
else
return other->mask[dev->id];
}
static CARD8 criticalEvents[32] = {
0x7c, 0x30, 0x40 /* key, button, expose, and configure events */
};
static void
SyntheticMotion(DeviceIntPtr dev, int x, int y)
{
int screenno = 0;
#ifdef PANORAMIX
if (!noPanoramiXExtension)
screenno = dev->spriteInfo->sprite->screen->myNum;
#endif
PostSyntheticMotion(dev, x, y, screenno,
(syncEvents.playingEvents) ? syncEvents.time.
milliseconds : currentTime.milliseconds);
}
#ifdef PANORAMIX
static void PostNewCursor(DeviceIntPtr pDev);
static Bool
XineramaSetCursorPosition(DeviceIntPtr pDev, int x, int y, Bool generateEvent)
{
ScreenPtr pScreen;
int i;
SpritePtr pSprite = pDev->spriteInfo->sprite;
/* x,y are in Screen 0 coordinates. We need to decide what Screen
to send the message too and what the coordinates relative to
that screen are. */
pScreen = pSprite->screen;
x += screenInfo.screens[0]->x;
y += screenInfo.screens[0]->y;
if (!point_on_screen(pScreen, x, y)) {
FOR_NSCREENS(i) {
if (i == pScreen->myNum)
continue;
if (point_on_screen(screenInfo.screens[i], x, y)) {
pScreen = screenInfo.screens[i];
break;
}
}
}
pSprite->screen = pScreen;
pSprite->hotPhys.x = x - screenInfo.screens[0]->x;
pSprite->hotPhys.y = y - screenInfo.screens[0]->y;
x -= pScreen->x;
y -= pScreen->y;
return (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
}
static void
XineramaConstrainCursor(DeviceIntPtr pDev)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
ScreenPtr pScreen;
BoxRec newBox;
pScreen = pSprite->screen;
newBox = pSprite->physLimits;
/* Translate the constraining box to the screen
the sprite is actually on */
newBox.x1 += screenInfo.screens[0]->x - pScreen->x;
newBox.x2 += screenInfo.screens[0]->x - pScreen->x;
newBox.y1 += screenInfo.screens[0]->y - pScreen->y;
newBox.y2 += screenInfo.screens[0]->y - pScreen->y;
(*pScreen->ConstrainCursor) (pDev, pScreen, &newBox);
}
static Bool
XineramaSetWindowPntrs(DeviceIntPtr pDev, WindowPtr pWin)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
if (pWin == screenInfo.screens[0]->root) {
int i;
FOR_NSCREENS(i)
pSprite->windows[i] = screenInfo.screens[i]->root;
}
else {
PanoramiXRes *win;
int rc, i;
rc = dixLookupResourceByType((void **) &win, pWin->drawable.id,
XRT_WINDOW, serverClient, DixReadAccess);
if (rc != Success)
return FALSE;
FOR_NSCREENS(i) {
rc = dixLookupWindow(pSprite->windows + i, win->info[i].id,
serverClient, DixReadAccess);
if (rc != Success) /* window is being unmapped */
return FALSE;
}
}
return TRUE;
}
static void
XineramaConfineCursorToWindow(DeviceIntPtr pDev,
WindowPtr pWin, Bool generateEvents)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
int x, y, off_x, off_y, i;
if (!XineramaSetWindowPntrs(pDev, pWin))
return;
i = PanoramiXNumScreens - 1;
RegionCopy(&pSprite->Reg1, &pSprite->windows[i]->borderSize);
off_x = screenInfo.screens[i]->x;
off_y = screenInfo.screens[i]->y;
while (i--) {
x = off_x - screenInfo.screens[i]->x;
y = off_y - screenInfo.screens[i]->y;
if (x || y)
RegionTranslate(&pSprite->Reg1, x, y);
RegionUnion(&pSprite->Reg1, &pSprite->Reg1,
&pSprite->windows[i]->borderSize);
off_x = screenInfo.screens[i]->x;
off_y = screenInfo.screens[i]->y;
}
pSprite->hotLimits = *RegionExtents(&pSprite->Reg1);
if (RegionNumRects(&pSprite->Reg1) > 1)
pSprite->hotShape = &pSprite->Reg1;
else
pSprite->hotShape = NullRegion;
pSprite->confined = FALSE;
pSprite->confineWin =
(pWin == screenInfo.screens[0]->root) ? NullWindow : pWin;
CheckPhysLimits(pDev, pSprite->current, generateEvents, FALSE, NULL);
}
#endif /* PANORAMIX */
/**
* Modifies the filter for the given protocol event type to the given masks.
*
* There's only two callers: UpdateDeviceState() and XI's SetMaskForExtEvent().
* The latter initialises masks for the matching XI events, it's a once-off
* setting.
* UDS however changes the mask for MotionNotify and DeviceMotionNotify each
* time a button is pressed to include the matching ButtonXMotion mask in the
* filter.
*
* @param[in] deviceid The device to modify the filter for.
* @param[in] mask The new filter mask.
* @param[in] event Protocol event type.
*/
void
SetMaskForEvent(int deviceid, Mask mask, int event)
{
if (deviceid < 0 || deviceid >= MAXDEVICES)
FatalError("SetMaskForEvent: bogus device id");
event_filters[deviceid][event] = mask;
}
void
SetCriticalEvent(int event)
{
if (event >= MAXEVENTS)
FatalError("SetCriticalEvent: bogus event number");
criticalEvents[event >> 3] |= 1 << (event & 7);
}
void
ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py)
{
BoxRec box;
int x = *px, y = *py;
int incx = 1, incy = 1;
if (RegionContainsPoint(shape, x, y, &box))
return;
box = *RegionExtents(shape);
/* this is rather crude */
do {
x += incx;
if (x >= box.x2) {
incx = -1;
x = *px - 1;
}
else if (x < box.x1) {
incx = 1;
x = *px;
y += incy;
if (y >= box.y2) {
incy = -1;
y = *py - 1;
}
else if (y < box.y1)
return; /* should never get here! */
}
} while (!RegionContainsPoint(shape, x, y, &box));
*px = x;
*py = y;
}
static void
CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, Bool generateEvents,
Bool confineToScreen, /* unused if PanoramiX on */
ScreenPtr pScreen) /* unused if PanoramiX on */
{
HotSpot new;
SpritePtr pSprite = pDev->spriteInfo->sprite;
if (!cursor)
return;
new = pSprite->hotPhys;
#ifdef PANORAMIX
if (!noPanoramiXExtension)
/* I don't care what the DDX has to say about it */
pSprite->physLimits = pSprite->hotLimits;
else
#endif
{
if (pScreen)
new.pScreen = pScreen;
else
pScreen = new.pScreen;
(*pScreen->CursorLimits) (pDev, pScreen, cursor, &pSprite->hotLimits,
&pSprite->physLimits);
pSprite->confined = confineToScreen;
(*pScreen->ConstrainCursor) (pDev, pScreen, &pSprite->physLimits);
}
/* constrain the pointer to those limits */
if (new.x < pSprite->physLimits.x1)
new.x = pSprite->physLimits.x1;
else if (new.x >= pSprite->physLimits.x2)
new.x = pSprite->physLimits.x2 - 1;
if (new.y < pSprite->physLimits.y1)
new.y = pSprite->physLimits.y1;
else if (new.y >= pSprite->physLimits.y2)
new.y = pSprite->physLimits.y2 - 1;
if (pSprite->hotShape)
ConfineToShape(pDev, pSprite->hotShape, &new.x, &new.y);
if ((
#ifdef PANORAMIX
noPanoramiXExtension &&
#endif
(pScreen != pSprite->hotPhys.pScreen)) ||
(new.x != pSprite->hotPhys.x) || (new.y != pSprite->hotPhys.y)) {
#ifdef PANORAMIX
if (!noPanoramiXExtension)
XineramaSetCursorPosition(pDev, new.x, new.y, generateEvents);
else
#endif
{
if (pScreen != pSprite->hotPhys.pScreen)
pSprite->hotPhys = new;
(*pScreen->SetCursorPosition)
(pDev, pScreen, new.x, new.y, generateEvents);
}
if (!generateEvents)
SyntheticMotion(pDev, new.x, new.y);
}
#ifdef PANORAMIX
/* Tell DDX what the limits are */
if (!noPanoramiXExtension)
XineramaConstrainCursor(pDev);
#endif
}
static void
CheckVirtualMotion(DeviceIntPtr pDev, QdEventPtr qe, WindowPtr pWin)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
RegionPtr reg = NULL;
DeviceEvent *ev = NULL;
if (qe) {
ev = &qe->event->device_event;
switch (ev->type) {
case ET_Motion:
case ET_ButtonPress:
case ET_ButtonRelease:
case ET_KeyPress:
case ET_KeyRelease:
case ET_ProximityIn:
case ET_ProximityOut:
pSprite->hot.pScreen = qe->pScreen;
pSprite->hot.x = ev->root_x;
pSprite->hot.y = ev->root_y;
pWin =
pDev->deviceGrab.grab ? pDev->deviceGrab.grab->
confineTo : NullWindow;
break;
default:
break;
}
}
if (pWin) {
BoxRec lims;
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
int x, y, off_x, off_y, i;
if (!XineramaSetWindowPntrs(pDev, pWin))
return;
i = PanoramiXNumScreens - 1;
RegionCopy(&pSprite->Reg2, &pSprite->windows[i]->borderSize);
off_x = screenInfo.screens[i]->x;
off_y = screenInfo.screens[i]->y;
while (i--) {
x = off_x - screenInfo.screens[i]->x;
y = off_y - screenInfo.screens[i]->y;
if (x || y)
RegionTranslate(&pSprite->Reg2, x, y);
RegionUnion(&pSprite->Reg2, &pSprite->Reg2,
&pSprite->windows[i]->borderSize);
off_x = screenInfo.screens[i]->x;
off_y = screenInfo.screens[i]->y;
}
}
else
#endif
{
if (pSprite->hot.pScreen != pWin->drawable.pScreen) {
pSprite->hot.pScreen = pWin->drawable.pScreen;
pSprite->hot.x = pSprite->hot.y = 0;
}
}
lims = *RegionExtents(&pWin->borderSize);
if (pSprite->hot.x < lims.x1)
pSprite->hot.x = lims.x1;
else if (pSprite->hot.x >= lims.x2)
pSprite->hot.x = lims.x2 - 1;
if (pSprite->hot.y < lims.y1)
pSprite->hot.y = lims.y1;
else if (pSprite->hot.y >= lims.y2)
pSprite->hot.y = lims.y2 - 1;
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
if (RegionNumRects(&pSprite->Reg2) > 1)
reg = &pSprite->Reg2;
}
else
#endif
{
if (wBoundingShape(pWin))
reg = &pWin->borderSize;
}
if (reg)
ConfineToShape(pDev, reg, &pSprite->hot.x, &pSprite->hot.y);
if (qe && ev) {
qe->pScreen = pSprite->hot.pScreen;
ev->root_x = pSprite->hot.x;
ev->root_y = pSprite->hot.y;
}
}
#ifdef PANORAMIX
if (noPanoramiXExtension) /* No typo. Only set the root win if disabled */
#endif
RootWindow(pDev->spriteInfo->sprite) = pSprite->hot.pScreen->root;
}
static void
ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents,
Bool confineToScreen)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
if (syncEvents.playingEvents) {
CheckVirtualMotion(pDev, (QdEventPtr) NULL, pWin);
SyntheticMotion(pDev, pSprite->hot.x, pSprite->hot.y);
}
else {
ScreenPtr pScreen = pWin->drawable.pScreen;
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
XineramaConfineCursorToWindow(pDev, pWin, generateEvents);
return;
}
#endif
pSprite->hotLimits = *RegionExtents(&pWin->borderSize);
pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize
: NullRegion;
CheckPhysLimits(pDev, pSprite->current, generateEvents,
confineToScreen, pWin->drawable.pScreen);
if (*pScreen->CursorConfinedTo)
(*pScreen->CursorConfinedTo) (pDev, pScreen, pWin);
}
}
Bool
PointerConfinedToScreen(DeviceIntPtr pDev)
{
return pDev->spriteInfo->sprite->confined;
}
/**
* Update the sprite cursor to the given cursor.
*
* ChangeToCursor() will display the new cursor and free the old cursor (if
* applicable). If the provided cursor is already the updated cursor, nothing
* happens.
*/
static void
ChangeToCursor(DeviceIntPtr pDev, CursorPtr cursor)
{
SpritePtr pSprite = pDev->spriteInfo->sprite;
ScreenPtr pScreen;
if (cursor != pSprite->current) {
if ((pSprite->current->bits->xhot != cursor->bits->xhot) ||
(pSprite->current->bits->yhot != cursor->bits->yhot))
CheckPhysLimits(pDev, cursor, FALSE, pSprite->confined,
(ScreenPtr) NULL);
#ifdef PANORAMIX
/* XXX: is this really necessary?? (whot) */
if (!noPanoramiXExtension)
pScreen = pSprite->screen;
else
#endif
pScreen = pSprite->hotPhys.pScreen;
(*pScreen->DisplayCursor) (pDev, pScreen, cursor);
FreeCursor(pSprite->current, (Cursor) 0);
pSprite->current = RefCursor(cursor);
}
}
/**
* @returns true if b is a descendent of a
*/
Bool
IsParent(WindowPtr a, WindowPtr b)
{
for (b = b->parent; b; b = b->parent)
if (b == a)
return TRUE;
return FALSE;
}
/**
* Update the cursor displayed on the screen.
*
* Called whenever a cursor may have changed shape or position.
*/
static void
PostNewCursor(DeviceIntPtr pDev)
{
WindowPtr win;
GrabPtr grab = pDev->deviceGrab.grab;
SpritePtr pSprite = pDev->spriteInfo->sprite;
CursorPtr pCursor;
if (syncEvents.playingEvents)
return;
if (grab) {
if (grab->cursor) {
ChangeToCursor(pDev, grab->cursor);
return;
}
if (IsParent(grab->window, pSprite->win))
win = pSprite->win;
else
win = grab->window;
}
else
win = pSprite->win;
for (; win; win = win->parent) {
if (win->optional) {
pCursor = WindowGetDeviceCursor(win, pDev);
if (!pCursor && win->optional->cursor != NullCursor)
pCursor = win->optional->cursor;
if (pCursor) {
ChangeToCursor(pDev, pCursor);
return;
}
}
}
}
/**
* @param dev device which you want to know its current root window
* @return root window where dev's sprite is located
*/
WindowPtr
GetCurrentRootWindow(DeviceIntPtr dev)
{