1
/* $Xorg: exevents.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */
2
/************************************************************
4
Copyright 1989, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
26
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
30
Permission to use, copy, modify, and distribute this software and its
31
documentation for any purpose and without fee is hereby granted,
32
provided that the above copyright notice appear in all copies and that
33
both that copyright notice and this permission notice appear in
34
supporting documentation, and that the name of Hewlett-Packard not be
35
used in advertising or publicity pertaining to distribution of the
36
software without specific, written prior permission.
38
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46
********************************************************/
47
/* $XFree86: xc/programs/Xserver/Xi/exevents.c,v 3.10 2001/12/14 19:58:55 dawes Exp $ */
49
/********************************************************************
51
* Routines to register and initialize extension input devices.
52
* This also contains ProcessOtherEvent, the routine called from DDX
53
* to route extension events.
58
#ifdef HAVE_DIX_CONFIG_H
59
#include <dix-config.h>
63
#include <X11/Xproto.h>
64
#include <X11/extensions/XI.h>
65
#include <X11/extensions/XIproto.h>
67
#include "windowstr.h"
68
#include "miscstruct.h"
71
#include "extnsionst.h"
72
#include "extinit.h" /* LookupDeviceIntRec */
73
#include "exglobals.h"
74
#include "dixevents.h" /* DeliverFocusedEvent */
75
#include "dixgrabs.h" /* CreateGrab() */
79
#define WID(w) ((w) ? ((w)->drawable.id) : 0)
80
#define AllModifiersMask ( \
81
ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \
82
Mod3Mask | Mod4Mask | Mod5Mask )
83
#define AllButtonsMask ( \
84
Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
85
#define Motion_Filter(class) (DevicePointerMotionMask | \
86
(class)->state | (class)->motionMask)
88
static Bool ShouldFreeInputMasks(
90
Bool /* ignoreSelectedEvents */
92
static Bool MakeInputMasks (
96
/**************************************************************************
98
* Procedures for extension device event routing.
103
RegisterOtherDevice (device)
106
device->public.processInputProc = ProcessOtherEvent;
107
device->public.realInputProc = ProcessOtherEvent;
108
(device)->ActivateGrab = ActivateKeyboardGrab;
109
(device)->DeactivateGrab = DeactivateKeyboardGrab;
114
ProcessOtherEvent (xE, other, count)
116
register DeviceIntPtr other;
121
register CARD16 modifiers;
122
register CARD16 mask;
123
GrabPtr grab = other->grab;
124
Bool deactivateDeviceGrab = FALSE;
125
int key = 0, bit = 0, rootX, rootY;
126
ButtonClassPtr b = other->button;
127
KeyClassPtr k = other->key;
128
ValuatorClassPtr v = other->valuator;
129
deviceValuator *xV = (deviceValuator *) xE;
131
if (xE->u.u.type != DeviceValuator) {
132
GetSpritePosition(&rootX, &rootY);
133
xE->u.keyButtonPointer.rootX = rootX;
134
xE->u.keyButtonPointer.rootY = rootY;
135
key = xE->u.u.detail;
137
xE->u.keyButtonPointer.state = inputInfo.keyboard->key->state |
138
inputInfo.pointer->button->state;
139
bit = 1 << (key & 7);
141
if (DeviceEventCallback)
143
DeviceEventInfoRec eventinfo;
144
eventinfo.events = (xEventPtr) xE;
145
eventinfo.count = count;
146
CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
148
for (i=1; i<count; i++)
149
if ((++xV)->type == DeviceValuator)
151
int first = xV->first_valuator;
154
if (xV->num_valuators && (!v || (xV->num_valuators && (first + xV->num_valuators > v->numAxes))))
155
FatalError("Bad valuators reported for device %s\n",other->name);
156
xV->device_state = 0;
158
xV->device_state |= k->state;
160
xV->device_state |= b->state;
163
axisvals = v->axisVal;
164
switch (xV->num_valuators) {
166
*(axisvals+first+5) = xV->valuator5;
168
*(axisvals+first+4) = xV->valuator4;
170
*(axisvals+first+3) = xV->valuator3;
172
*(axisvals+first+2) = xV->valuator2;
174
*(axisvals+first+1) = xV->valuator1;
176
*(axisvals+first) = xV->valuator0;
184
if (xE->u.u.type == DeviceKeyPress)
186
modifiers = k->modifierMap[key];
187
kptr = &k->down[key >> 3];
188
if (*kptr & bit) /* allow ddx to generate multiple downs */
192
xE->u.u.type = DeviceKeyRelease;
193
ProcessOtherEvent(xE, other, count);
194
xE->u.u.type = DeviceKeyPress;
195
/* release can have side effects, don't fall through */
196
ProcessOtherEvent(xE, other, count);
201
other->valuator->motionHintWindow = NullWindow;
203
k->prev_state = k->state;
204
for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
206
if (mask & modifiers)
208
/* This key affects modifier "i" */
209
k->modifierKeyCount[i]++;
214
if (!grab && CheckDeviceGrabs(other, xE, 0, count))
216
other->activatingKey = key;
220
else if (xE->u.u.type == DeviceKeyRelease)
222
kptr = &k->down[key >> 3];
223
if (!(*kptr & bit)) /* guard against duplicates */
225
modifiers = k->modifierMap[key];
227
other->valuator->motionHintWindow = NullWindow;
229
k->prev_state = k->state;
230
for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
232
if (mask & modifiers)
234
/* This key affects modifier "i" */
235
if (--k->modifierKeyCount[i] <= 0)
237
k->modifierKeyCount[i] = 0;
244
if (other->fromPassiveGrab && (key == other->activatingKey))
245
deactivateDeviceGrab = TRUE;
247
else if (xE->u.u.type == DeviceButtonPress)
249
kptr = &b->down[key >> 3];
252
other->valuator->motionHintWindow = NullWindow;
254
b->motionMask = DeviceButtonMotionMask;
255
xE->u.u.detail = b->map[key];
256
if (xE->u.u.detail == 0)
258
if (xE->u.u.detail <= 5)
259
b->state |= (Button1Mask >> 1) << xE->u.u.detail;
260
SetMaskForEvent(Motion_Filter(b),DeviceMotionNotify);
262
if (CheckDeviceGrabs(other, xE, 0, count))
266
else if (xE->u.u.type == DeviceButtonRelease)
268
kptr = &b->down[key >> 3];
271
other->valuator->motionHintWindow = NullWindow;
272
if (!--b->buttonsDown)
274
xE->u.u.detail = b->map[key];
275
if (xE->u.u.detail == 0)
277
if (xE->u.u.detail <= 5)
278
b->state &= ~((Button1Mask >> 1) << xE->u.u.detail);
279
SetMaskForEvent(Motion_Filter(b),DeviceMotionNotify);
280
if (!b->state && other->fromPassiveGrab)
281
deactivateDeviceGrab = TRUE;
283
else if (xE->u.u.type == ProximityIn)
284
other->valuator->mode &= ~OutOfProximity;
285
else if (xE->u.u.type == ProximityOut)
286
other->valuator->mode |= OutOfProximity;
289
DeliverGrabbedEvent(xE, other, deactivateDeviceGrab, count);
290
else if (other->focus)
291
DeliverFocusedEvent(other, xE, GetSpriteWindow(), count);
293
DeliverDeviceEvents(GetSpriteWindow(), xE, NullGrab, NullWindow,
296
if (deactivateDeviceGrab == TRUE)
297
(*other->DeactivateGrab)(other);
301
InitProximityClassDeviceStruct( DeviceIntPtr dev)
303
register ProximityClassPtr proxc;
305
proxc = (ProximityClassPtr)xalloc(sizeof(ProximityClassRec));
308
dev->proximity = proxc;
313
InitValuatorAxisStruct( DeviceIntPtr dev,
321
register AxisInfoPtr ax = dev->valuator->axes + axnum;
323
ax->min_value = minval;
324
ax->max_value = maxval;
325
ax->resolution = resolution;
326
ax->min_resolution = min_res;
327
ax->max_resolution = max_res;
331
FixDeviceStateNotify (
333
deviceStateNotify *ev,
339
ev->type = DeviceStateNotify;
340
ev->deviceid = dev->id;
341
ev->time = currentTime.milliseconds;
342
ev->classes_reported = 0;
345
ev->num_valuators = 0;
348
ev->classes_reported |= (1 << ButtonClass);
349
ev->num_buttons = b->numButtons;
350
memmove((char *) &ev->buttons[0], (char *) b->down, 4);
353
ev->classes_reported |= (1 << KeyClass);
354
ev->num_keys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode;
355
memmove((char *) &ev->keys[0], (char *) k->down, 4);
358
int nval = v->numAxes - first;
359
ev->classes_reported |= (1 << ValuatorClass);
360
ev->classes_reported |= (dev->valuator->mode << ModeBitsShift);
361
ev->num_valuators = nval < 3 ? nval : 3;
362
switch (ev->num_valuators)
365
ev->valuator2 = v->axisVal[first+2];
367
ev->valuator1 = v->axisVal[first+1];
369
ev->valuator0 = v->axisVal[first];
382
int nval = v->numAxes - first;
384
ev->type = DeviceValuator;
385
ev->deviceid = dev->id;
386
ev->num_valuators = nval < 3 ? nval : 3;
387
ev->first_valuator = first;
388
switch (ev->num_valuators) {
390
ev->valuator2 = v->axisVal[first+2];
392
ev->valuator1 = v->axisVal[first+1];
394
ev->valuator0 = v->axisVal[first];
397
first += ev->num_valuators;
401
DeviceFocusEvent(dev, type, mode, detail, pWin)
403
int type, mode, detail;
404
register WindowPtr pWin;
409
type = DeviceFocusIn;
411
type = DeviceFocusOut;
413
event.deviceid = dev->id;
416
event.detail = detail;
417
event.window = pWin->drawable.id;
418
event.time = currentTime.milliseconds;
420
(void) DeliverEventsToWindow(pWin, (xEvent *)&event, 1,
421
DeviceFocusChangeMask, NullGrab, dev->id);
423
if ((type == DeviceFocusIn) &&
424
(wOtherInputMasks(pWin)) &&
425
(wOtherInputMasks(pWin)->inputEvents[dev->id] & DeviceStateNotifyMask))
428
deviceStateNotify *ev, *sev;
429
deviceKeyStateNotify *kev;
430
deviceButtonStateNotify *bev;
435
int nval=0, nkeys=0, nbuttons=0, first=0;
437
if ((b=dev->button) != NULL) {
438
nbuttons = b->numButtons;
442
if ((k=dev->key) != NULL) {
443
nkeys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode;
450
if ((v=dev->valuator) != NULL) {
459
evcount += ((nval - 7) / 3);
463
sev = ev = (deviceStateNotify *) xalloc(evcount * sizeof(xEvent));
464
FixDeviceStateNotify (dev, ev, NULL, NULL, NULL, first);
467
FixDeviceStateNotify (dev, ev++, NULL, b, v, first);
471
(ev-1)->deviceid |= MORE_EVENTS;
472
bev = (deviceButtonStateNotify *) ev++;
473
bev->type = DeviceButtonStateNotify;
474
bev->deviceid = dev->id;
475
memmove((char *) &bev->buttons[0], (char *) &b->down[4], 28);
478
(ev-1)->deviceid |= MORE_EVENTS;
479
FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
486
FixDeviceStateNotify (dev, ev++, k, NULL, v, first);
490
(ev-1)->deviceid |= MORE_EVENTS;
491
kev = (deviceKeyStateNotify *) ev++;
492
kev->type = DeviceKeyStateNotify;
493
kev->deviceid = dev->id;
494
memmove((char *) &kev->keys[0], (char *) &k->down[4], 28);
497
(ev-1)->deviceid |= MORE_EVENTS;
498
FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
505
FixDeviceStateNotify (dev, ev++, NULL, NULL, v, first);
509
(ev-1)->deviceid |= MORE_EVENTS;
510
FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
516
(void) DeliverEventsToWindow(pWin, (xEvent *)sev, evcount,
517
DeviceStateNotifyMask, NullGrab, dev->id);
526
BYTE this_device_mode,
527
BYTE other_devices_mode,
529
DeviceIntPtr modifier_device,
537
WindowPtr pWin, confineTo;
541
if ((this_device_mode != GrabModeSync) &&
542
(this_device_mode != GrabModeAsync))
544
client->errorValue = this_device_mode;
547
if ((other_devices_mode != GrabModeSync) &&
548
(other_devices_mode != GrabModeAsync))
550
client->errorValue = other_devices_mode;
553
if ((modifiers != AnyModifier) &&
554
(modifiers & ~AllModifiersMask))
556
client->errorValue = modifiers;
559
if ((ownerEvents != xFalse) && (ownerEvents != xTrue))
561
client->errorValue = ownerEvents;
564
pWin = LookupWindow(grabWindow, client);
567
if (rconfineTo == None)
568
confineTo = NullWindow;
571
confineTo = LookupWindow(rconfineTo, client);
579
cursor = (CursorPtr)LookupIDByType(rcursor, RT_CURSOR);
582
client->errorValue = rcursor;
587
grab = CreateGrab(client->index, dev, pWin, eventMask,
588
(Bool)ownerEvents, (Bool) this_device_mode, (Bool)other_devices_mode,
589
modifier_device, modifiers, DeviceButtonPress, button, confineTo,
593
return AddPassiveGrabToList(grab);
600
BYTE this_device_mode,
601
BYTE other_devices_mode,
603
DeviceIntPtr modifier_device,
611
KeyClassPtr k = dev->key;
615
if ((other_devices_mode != GrabModeSync) &&
616
(other_devices_mode != GrabModeAsync))
618
client->errorValue = other_devices_mode;
621
if ((this_device_mode != GrabModeSync) &&
622
(this_device_mode != GrabModeAsync))
624
client->errorValue = this_device_mode;
627
if (((key > k->curKeySyms.maxKeyCode) ||
628
(key < k->curKeySyms.minKeyCode))
631
client->errorValue = key;
634
if ((modifiers != AnyModifier) &&
635
(modifiers & ~AllModifiersMask))
637
client->errorValue = modifiers;
640
if ((ownerEvents != xTrue) && (ownerEvents != xFalse))
642
client->errorValue = ownerEvents;
645
pWin = LookupWindow(grabWindow, client);
649
grab = CreateGrab(client->index, dev, pWin,
650
mask, ownerEvents, this_device_mode, other_devices_mode,
651
modifier_device, modifiers, DeviceKeyPress, key, NullWindow,
655
return AddPassiveGrabToList(grab);
659
SelectForWindow(dev, pWin, client, mask, exclusivemasks, validmasks)
667
int mskidx = dev->id;
670
InputClientsPtr others;
672
if (mask & ~validmasks)
674
client->errorValue = mask;
677
check = (mask & exclusivemasks);
678
if (wOtherInputMasks(pWin))
680
if (check & wOtherInputMasks(pWin)->inputEvents[mskidx])
681
{ /* It is illegal for two different
682
clients to select on any of the
683
events for maskcheck. However,
684
it is OK, for some client to
685
continue selecting on one of those
687
for (others = wOtherInputMasks(pWin)->inputClients; others;
688
others = others->next)
690
if (!SameClient(others, client) && (check &
691
others->mask[mskidx]))
695
for (others = wOtherInputMasks(pWin)->inputClients; others;
696
others = others->next)
698
if (SameClient(others, client))
700
check = others->mask[mskidx];
701
others->mask[mskidx] = mask;
704
for (i=0; i<EMASKSIZE; i++)
705
if (i != mskidx && others->mask[i] != 0)
709
RecalculateDeviceDeliverableEvents(pWin);
710
if (ShouldFreeInputMasks(pWin, FALSE))
711
FreeResource(others->resource, RT_NONE);
720
if ((ret = AddExtensionClient (pWin, client, mask, mskidx)) != Success)
724
if ((dev->valuator->motionHintWindow == pWin) &&
725
(mask & DevicePointerMotionHintMask) &&
726
!(check & DevicePointerMotionHintMask) &&
728
dev->valuator->motionHintWindow = NullWindow;
729
RecalculateDeviceDeliverableEvents(pWin);
734
AddExtensionClient (pWin, client, mask, mskidx)
740
InputClientsPtr others;
742
if (!pWin->optional && !MakeWindowOptional (pWin))
744
others = (InputClients *) xalloc(sizeof(InputClients));
747
if (!pWin->optional->inputMasks && !MakeInputMasks (pWin))
749
bzero((char *) &others->mask[0], sizeof(Mask)*EMASKSIZE);
750
others->mask[mskidx] = mask;
751
others->resource = FakeClientID(client->index);
752
others->next = pWin->optional->inputMasks->inputClients;
753
pWin->optional->inputMasks->inputClients = others;
754
if (!AddResource(others->resource, RT_INPUTCLIENT, (pointer)pWin))
760
MakeInputMasks (pWin)
763
struct _OtherInputMasks *imasks;
765
imasks = (struct _OtherInputMasks *)
766
xalloc (sizeof (struct _OtherInputMasks));
769
bzero((char *) imasks, sizeof (struct _OtherInputMasks));
770
pWin->optional->inputMasks = imasks;
775
RecalculateDeviceDeliverableEvents(pWin)
778
register InputClientsPtr others;
779
struct _OtherInputMasks *inputMasks; /* default: NULL */
780
register WindowPtr pChild, tmp;
786
if ((inputMasks = wOtherInputMasks(pChild)) != 0)
788
for (others = inputMasks->inputClients; others;
789
others = others->next)
791
for (i=0; i<EMASKSIZE; i++)
792
inputMasks->inputEvents[i] |= others->mask[i];
794
for (i=0; i<EMASKSIZE; i++)
795
inputMasks->deliverableEvents[i] = inputMasks->inputEvents[i];
796
for (tmp = pChild->parent; tmp; tmp=tmp->parent)
797
if (wOtherInputMasks(tmp))
798
for (i=0; i<EMASKSIZE; i++)
799
inputMasks->deliverableEvents[i] |=
800
(wOtherInputMasks(tmp)->deliverableEvents[i]
801
& ~inputMasks->dontPropagateMask[i] & PropagateMask[i]);
803
if (pChild->firstChild)
805
pChild = pChild->firstChild;
808
while (!pChild->nextSib && (pChild != pWin))
809
pChild = pChild->parent;
812
pChild = pChild->nextSib;
817
InputClientGone(pWin, id)
818
register WindowPtr pWin;
821
register InputClientsPtr other, prev;
822
if (!wOtherInputMasks(pWin))
825
for (other = wOtherInputMasks(pWin)->inputClients; other;
828
if (other->resource == id)
832
prev->next = other->next;
835
else if (!(other->next))
837
if (ShouldFreeInputMasks(pWin, TRUE))
839
wOtherInputMasks(pWin)->inputClients = other->next;
840
xfree(wOtherInputMasks(pWin));
841
pWin->optional->inputMasks = (OtherInputMasks *) NULL;
842
CheckWindowOptionalNeed (pWin);
847
other->resource = FakeClientID(0);
848
if (!AddResource(other->resource, RT_INPUTCLIENT,
855
wOtherInputMasks(pWin)->inputClients = other->next;
858
RecalculateDeviceDeliverableEvents(pWin);
863
FatalError("client not on device event list");
868
SendEvent (client, d, dest, propagate, ev, mask, count)
878
WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */
879
WindowPtr spriteWin=GetSpriteWindow();
881
if (dest == PointerWindow)
883
else if (dest == InputFocus)
885
WindowPtr inputFocus;
888
inputFocus = spriteWin;
890
inputFocus = d->focus->win;
892
if (inputFocus == FollowKeyboardWin)
893
inputFocus = inputInfo.keyboard->focus->win;
895
if (inputFocus == NoneWin)
898
/* If the input focus is PointerRootWin, send the event to where
899
the pointer is if possible, then perhaps propogate up to root. */
900
if (inputFocus == PointerRootWin)
901
inputFocus = GetCurrentRootWindow();
903
if (IsParent(inputFocus, spriteWin))
905
effectiveFocus = inputFocus;
909
effectiveFocus = pWin = inputFocus;
912
pWin = LookupWindow(dest, client);
915
if ((propagate != xFalse) && (propagate != xTrue))
917
client->errorValue = propagate;
920
ev->u.u.type |= 0x80;
923
for (;pWin; pWin = pWin->parent)
925
if (DeliverEventsToWindow( pWin, ev, count, mask, NullGrab, d->id))
927
if (pWin == effectiveFocus)
929
if (wOtherInputMasks(pWin))
930
mask &= ~wOtherInputMasks(pWin)->dontPropagateMask[d->id];
936
(void)(DeliverEventsToWindow( pWin, ev, count, mask, NullGrab, d->id));
941
SetButtonMapping (client, dev, nElts, map)
948
ButtonClassPtr b = dev->button;
953
if (nElts != b->numButtons)
955
client->errorValue = nElts;
958
if (BadDeviceMap(&map[0], nElts, 1, 255, &client->errorValue))
960
for (i=0; i < nElts; i++)
961
if ((b->map[i + 1] != map[i]) &&
962
BitIsOn(b->down, i + 1))
964
for (i = 0; i < nElts; i++)
965
b->map[i + 1] = map[i];
970
SetModifierMapping(client, dev, len, rlen, numKeyPerModifier, inputMap, k)
975
int numKeyPerModifier;
986
if (len != ((numKeyPerModifier<<1) + rlen))
989
inputMapLen = 8*numKeyPerModifier;
992
* Now enforce the restriction that "all of the non-zero keycodes must be
993
* in the range specified by min-keycode and max-keycode in the
994
* connection setup (else a Value error)"
999
&& (inputMap[i] < (*k)->curKeySyms.minKeyCode
1000
|| inputMap[i] > (*k)->curKeySyms.maxKeyCode)) {
1001
client->errorValue = inputMap[i];
1002
return -1; /* BadValue collides with MappingFailed */
1007
* Now enforce the restriction that none of the old or new
1008
* modifier keys may be down while we change the mapping, and
1009
* that the DDX layer likes the choice.
1011
if (!AllModifierKeysAreUp (dev, (*k)->modifierKeyMap,
1012
(int)(*k)->maxKeysPerModifier, inputMap, (int)numKeyPerModifier)
1014
!AllModifierKeysAreUp(dev, inputMap, (int)numKeyPerModifier,
1015
(*k)->modifierKeyMap, (int)(*k)->maxKeysPerModifier)) {
1018
for (i = 0; i < inputMapLen; i++) {
1019
if (inputMap[i] && !LegalModifier(inputMap[i], (DevicePtr)dev)) {
1020
return MappingFailed;
1026
* Now build the keyboard's modifier bitmap from the
1030
map = (KeyCode *)xalloc(inputMapLen);
1034
if ((*k)->modifierKeyMap)
1035
xfree((*k)->modifierKeyMap);
1037
(*k)->modifierKeyMap = map;
1038
memmove((char *)(*k)->modifierKeyMap, (char *)inputMap, inputMapLen);
1040
(*k)->modifierKeyMap = NULL;
1042
(*k)->maxKeysPerModifier = numKeyPerModifier;
1043
for (i = 0; i < MAP_LENGTH; i++)
1044
(*k)->modifierMap[i] = 0;
1045
for (i = 0; i < inputMapLen; i++) if (inputMap[i]) {
1046
(*k)->modifierMap[inputMap[i]]
1047
|= (1<<(i/ (*k)->maxKeysPerModifier));
1050
return(MappingSuccess);
1054
SendDeviceMappingNotify(
1056
KeyCode firstKeyCode,
1061
deviceMappingNotify *ev = (deviceMappingNotify *) &event;
1063
ev->type = DeviceMappingNotify;
1064
ev->request = request;
1065
ev->deviceid = dev->id;
1066
ev->time = currentTime.milliseconds;
1067
if (request == MappingKeyboard)
1069
ev->firstKeyCode = firstKeyCode;
1073
SendEventToAllWindows (dev, DeviceMappingNotifyMask, (xEvent *)ev, 1);
1082
KeyCode firstKeyCode,
1084
CARD8 keySymsPerKeyCode,
1088
KeyClassPtr k = dev->key;
1093
if (len != (keyCodes * keySymsPerKeyCode))
1096
if ((firstKeyCode < k->curKeySyms.minKeyCode) ||
1097
(firstKeyCode + keyCodes - 1 > k->curKeySyms.maxKeyCode))
1099
client->errorValue = firstKeyCode;
1102
if (keySymsPerKeyCode == 0)
1104
client->errorValue = 0;
1107
keysyms.minKeyCode = firstKeyCode;
1108
keysyms.maxKeyCode = firstKeyCode + keyCodes - 1;
1109
keysyms.mapWidth = keySymsPerKeyCode;
1111
if (!SetKeySymsMap(&k->curKeySyms, &keysyms))
1113
SendDeviceMappingNotify(MappingKeyboard, firstKeyCode, keyCodes,
1115
return client->noClientException;
1119
DeleteWindowFromAnyExtEvents(pWin, freeResources)
1126
struct _OtherInputMasks *inputMasks;
1128
for (dev=inputInfo.devices; dev; dev=dev->next)
1130
if (dev == inputInfo.pointer ||
1131
dev == inputInfo.keyboard)
1133
DeleteDeviceFromAnyExtEvents(pWin, dev);
1136
for (dev=inputInfo.off_devices; dev; dev=dev->next)
1137
DeleteDeviceFromAnyExtEvents(pWin, dev);
1140
while ((inputMasks = wOtherInputMasks(pWin)) != 0)
1142
ic = inputMasks->inputClients;
1143
for (i=0; i<EMASKSIZE; i++)
1144
inputMasks->dontPropagateMask[i] = 0;
1145
FreeResource(ic->resource, RT_NONE);
1150
DeleteDeviceFromAnyExtEvents(pWin, dev)
1156
/* Deactivate any grabs performed on this window, before making
1157
any input focus changes.
1158
Deactivating a device grab should cause focus events. */
1160
if (dev->grab && (dev->grab->window == pWin))
1161
(*dev->DeactivateGrab)(dev);
1163
/* If the focus window is a root window (ie. has no parent)
1164
then don't delete the focus from it. */
1166
if (dev->focus && (pWin==dev->focus->win) && (pWin->parent != NullWindow))
1168
int focusEventMode = NotifyNormal;
1170
/* If a grab is in progress, then alter the mode of focus events. */
1173
focusEventMode = NotifyWhileGrabbed;
1175
switch (dev->focus->revert)
1178
DoFocusEvents(dev, pWin, NoneWin, focusEventMode);
1179
dev->focus->win = NoneWin;
1180
dev->focus->traceGood = 0;
1182
case RevertToParent:
1186
parent = parent->parent;
1187
dev->focus->traceGood--;
1188
} while (!parent->realized);
1189
DoFocusEvents(dev, pWin, parent, focusEventMode);
1190
dev->focus->win = parent;
1191
dev->focus->revert = RevertToNone;
1193
case RevertToPointerRoot:
1194
DoFocusEvents(dev, pWin, PointerRootWin, focusEventMode);
1195
dev->focus->win = PointerRootWin;
1196
dev->focus->traceGood = 0;
1198
case RevertToFollowKeyboard:
1199
if (inputInfo.keyboard->focus->win) {
1200
DoFocusEvents(dev, pWin, inputInfo.keyboard->focus->win,
1202
dev->focus->win = FollowKeyboardWin;
1203
dev->focus->traceGood = 0;
1205
DoFocusEvents(dev, pWin, NoneWin, focusEventMode);
1206
dev->focus->win = NoneWin;
1207
dev->focus->traceGood = 0;
1214
if (dev->valuator->motionHintWindow == pWin)
1215
dev->valuator->motionHintWindow = NullWindow;
1219
MaybeSendDeviceMotionNotifyHint (pEvents, mask)
1220
deviceKeyButtonPointer *pEvents;
1225
dev = LookupDeviceIntRec (pEvents->deviceid & DEVICE_BITS);
1226
if (pEvents->type == DeviceMotionNotify)
1228
if (mask & DevicePointerMotionHintMask)
1230
if (WID(dev->valuator->motionHintWindow) == pEvents->event)
1232
return 1; /* don't send, but pretend we did */
1234
pEvents->detail = NotifyHint;
1238
pEvents->detail = NotifyNormal;
1245
CheckDeviceGrabAndHintWindow (pWin, type, xE, grab, client, deliveryMask)
1248
deviceKeyButtonPointer *xE;
1255
dev = LookupDeviceIntRec (xE->deviceid & DEVICE_BITS);
1256
if (type == DeviceMotionNotify)
1257
dev->valuator->motionHintWindow = pWin;
1258
else if ((type == DeviceButtonPress) && (!grab) &&
1259
(deliveryMask & DeviceButtonGrabMask))
1263
tempGrab.device = dev;
1264
tempGrab.resource = client->clientAsMask;
1265
tempGrab.window = pWin;
1266
tempGrab.ownerEvents = (deliveryMask & DeviceOwnerGrabButtonMask) ? TRUE : FALSE;
1267
tempGrab.eventMask = deliveryMask;
1268
tempGrab.keyboardMode = GrabModeAsync;
1269
tempGrab.pointerMode = GrabModeAsync;
1270
tempGrab.confineTo = NullWindow;
1271
tempGrab.cursor = NullCursor;
1272
(*dev->ActivateGrab)(dev, &tempGrab, currentTime, TRUE);
1277
DeviceEventMaskForClient(dev, pWin, client)
1282
register InputClientsPtr other;
1284
if (!wOtherInputMasks(pWin))
1286
for (other = wOtherInputMasks(pWin)->inputClients; other;
1287
other = other->next)
1289
if (SameClient(other, client))
1290
return other->mask[dev->id];
1296
MaybeStopDeviceHint(dev, client)
1297
register DeviceIntPtr dev;
1301
GrabPtr grab = dev->grab;
1302
pWin = dev->valuator->motionHintWindow;
1304
if ((grab && SameClient(grab, client) &&
1305
((grab->eventMask & DevicePointerMotionHintMask) ||
1306
(grab->ownerEvents &&
1307
(DeviceEventMaskForClient(dev, pWin, client) &
1308
DevicePointerMotionHintMask)))) ||
1310
(DeviceEventMaskForClient(dev, pWin, client) &
1311
DevicePointerMotionHintMask)))
1312
dev->valuator->motionHintWindow = NullWindow;
1316
DeviceEventSuppressForWindow(pWin, client, mask, maskndx)
1322
struct _OtherInputMasks *inputMasks = wOtherInputMasks (pWin);
1324
if (mask & ~PropagateMask[maskndx])
1326
client->errorValue = mask;
1333
inputMasks->dontPropagateMask[maskndx] = mask;
1338
AddExtensionClient (pWin, client, 0, 0);
1339
inputMasks = wOtherInputMasks(pWin);
1340
inputMasks->dontPropagateMask[maskndx] = mask;
1342
RecalculateDeviceDeliverableEvents(pWin);
1343
if (ShouldFreeInputMasks(pWin, FALSE))
1344
FreeResource(inputMasks->inputClients->resource, RT_NONE);
1349
ShouldFreeInputMasks (pWin, ignoreSelectedEvents)
1351
Bool ignoreSelectedEvents;
1354
Mask allInputEventMasks = 0;
1355
struct _OtherInputMasks *inputMasks = wOtherInputMasks (pWin);
1357
for (i=0; i<EMASKSIZE; i++)
1358
allInputEventMasks |= inputMasks->dontPropagateMask[i];
1359
if (!ignoreSelectedEvents)
1360
for (i=0; i<EMASKSIZE; i++)
1361
allInputEventMasks |= inputMasks->inputEvents[i];
1362
if (allInputEventMasks == 0)