~ubuntu-branches/ubuntu/edgy/xorg-server/edgy-updates

« back to all changes in this revision

Viewing changes to Xi/exevents.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Parra Novo
  • Date: 2006-07-25 20:06:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060725200628-gjmmd9gxfxdc4ejs
Tags: 1:1.1.1-0ubuntu1
* New Upstream version
* Changed Build-Depends from mesa-swrast-source to mesa-swx11-source,
  following Debian package nomenclature
* Re-did 12_security_policy_in_etc.diff for 1.1.1
* Dropped 15_security_allocate_local.diff (applied upstream)
* Dropped 16_SECURITY_setuid.diff (applied upstream)
* Dropped 000_ubuntu_fix_read_kernel_mapping.patch (applied upstream)
* Dropped 002_ubuntu_fix_for_certain_intel_chipsets.patch (applied upstream)
* Updated versioned Build-Depends on mesa-swx11-source to version
  6.5.0.cvs.20060725-0ubuntu1
* Added arrayobj.c, arrayobj.h, bitset.h & rbadaptors.h to
  GL/symlink-mesa.sh (linked from mesa-swx11-source)
* Added arrayobj.c to default build target on GL/mesa/main

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Xorg: exevents.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */
2
1
/************************************************************
3
2
 
4
3
Copyright 1989, 1998  The Open Group
44
43
SOFTWARE.
45
44
 
46
45
********************************************************/
47
 
/* $XFree86: xc/programs/Xserver/Xi/exevents.c,v 3.10 2001/12/14 19:58:55 dawes Exp $ */
48
46
 
49
47
/********************************************************************
50
48
 *
69
67
#include "region.h"
70
68
#include "exevents.h"
71
69
#include "extnsionst.h"
72
 
#include "extinit.h"                    /* LookupDeviceIntRec */
 
70
#include "extinit.h"    /* LookupDeviceIntRec */
73
71
#include "exglobals.h"
74
 
#include "dixevents.h"                  /* DeliverFocusedEvent */
75
 
#include "dixgrabs.h"                   /* CreateGrab() */
 
72
#include "dixevents.h"  /* DeliverFocusedEvent */
 
73
#include "dixgrabs.h"   /* CreateGrab() */
76
74
 
77
75
#include "chgptr.h"
78
76
 
85
83
#define Motion_Filter(class) (DevicePointerMotionMask | \
86
84
                              (class)->state | (class)->motionMask)
87
85
 
88
 
static Bool             ShouldFreeInputMasks(
89
 
                                WindowPtr /* pWin */,
90
 
                                Bool /* ignoreSelectedEvents */
91
 
                                );
92
 
static Bool             MakeInputMasks (
93
 
                                WindowPtr /* pWin */
94
 
                                );
 
86
static Bool ShouldFreeInputMasks(WindowPtr /* pWin */ ,
 
87
                                 Bool   /* ignoreSelectedEvents */
 
88
    );
 
89
static Bool MakeInputMasks(WindowPtr    /* pWin */
 
90
    );
95
91
 
96
92
/**************************************************************************
97
93
 *
100
96
 */
101
97
 
102
98
void
103
 
RegisterOtherDevice (device)
104
 
    DeviceIntPtr device;
105
 
    {
 
99
RegisterOtherDevice(DeviceIntPtr device)
 
100
{
106
101
    device->public.processInputProc = ProcessOtherEvent;
107
102
    device->public.realInputProc = ProcessOtherEvent;
108
103
    (device)->ActivateGrab = ActivateKeyboardGrab;
109
104
    (device)->DeactivateGrab = DeactivateKeyboardGrab;
110
 
    }
 
105
}
111
106
 
112
 
/*ARGSUSED*/
113
 
void
114
 
ProcessOtherEvent (xE, other, count)
115
 
    xEventPtr xE;
116
 
    register DeviceIntPtr other;
117
 
    int count;
118
 
    {
119
 
    register BYTE       *kptr;
120
 
    register int        i;
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;
 
107
 /*ARGSUSED*/ void
 
108
ProcessOtherEvent(xEventPtr xE, register DeviceIntPtr other, int count)
 
109
{
 
110
    register BYTE *kptr;
 
111
    register int i;
 
112
    register CARD16 modifiers;
 
113
    register CARD16 mask;
 
114
    GrabPtr grab = other->grab;
 
115
    Bool deactivateDeviceGrab = FALSE;
 
116
    int key = 0, bit = 0, rootX, rootY;
 
117
    ButtonClassPtr b = other->button;
 
118
    KeyClassPtr k = other->key;
 
119
    ValuatorClassPtr v = other->valuator;
 
120
    deviceValuator *xV = (deviceValuator *) xE;
130
121
 
131
122
    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;
136
 
        NoticeEventTime(xE);
137
 
        xE->u.keyButtonPointer.state = inputInfo.keyboard->key->state | 
138
 
                    inputInfo.pointer->button->state;
139
 
        bit = 1 << (key & 7);
 
123
        GetSpritePosition(&rootX, &rootY);
 
124
        xE->u.keyButtonPointer.rootX = rootX;
 
125
        xE->u.keyButtonPointer.rootY = rootY;
 
126
        key = xE->u.u.detail;
 
127
        NoticeEventTime(xE);
 
128
        xE->u.keyButtonPointer.state = inputInfo.keyboard->key->state |
 
129
            inputInfo.pointer->button->state;
 
130
        bit = 1 << (key & 7);
140
131
    }
141
 
    if (DeviceEventCallback)
142
 
    {
 
132
    if (DeviceEventCallback) {
143
133
        DeviceEventInfoRec eventinfo;
 
134
 
144
135
        eventinfo.events = (xEventPtr) xE;
145
136
        eventinfo.count = count;
146
 
        CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
 
137
        CallCallbacks(&DeviceEventCallback, (pointer) & eventinfo);
147
138
    }
148
 
    for (i=1; i<count; i++)
149
 
        if ((++xV)->type == DeviceValuator)
150
 
            {
 
139
    for (i = 1; i < count; i++)
 
140
        if ((++xV)->type == DeviceValuator) {
151
141
            int first = xV->first_valuator;
152
142
            int *axisvals;
153
143
 
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);
 
144
            if (xV->num_valuators
 
145
                && (!v
 
146
                    || (xV->num_valuators
 
147
                        && (first + xV->num_valuators > v->numAxes))))
 
148
                FatalError("Bad valuators reported for device %s\n",
 
149
                           other->name);
156
150
            xV->device_state = 0;
157
151
            if (k)
158
152
                xV->device_state |= k->state;
159
153
            if (b)
160
 
                xV->device_state |= b->state;
161
 
            if (v && v->axisVal)
162
 
                {
163
 
                axisvals = v->axisVal;
164
 
                switch (xV->num_valuators) {
165
 
                    case 6:
166
 
                        *(axisvals+first+5) = xV->valuator5;
167
 
                    case 5:
168
 
                        *(axisvals+first+4) = xV->valuator4;
169
 
                    case 4:
170
 
                        *(axisvals+first+3) = xV->valuator3;
171
 
                    case 3:
172
 
                        *(axisvals+first+2) = xV->valuator2;
173
 
                    case 2:
174
 
                        *(axisvals+first+1) = xV->valuator1;
175
 
                    case 1:
176
 
                        *(axisvals+first) = xV->valuator0;
177
 
                    case 0:
178
 
                    default:
179
 
                        break;
180
 
                    }
 
154
                xV->device_state |= b->state;
 
155
            if (v && v->axisVal) {
 
156
                axisvals = v->axisVal;
 
157
                switch (xV->num_valuators) {
 
158
                case 6:
 
159
                    *(axisvals + first + 5) = xV->valuator5;
 
160
                case 5:
 
161
                    *(axisvals + first + 4) = xV->valuator4;
 
162
                case 4:
 
163
                    *(axisvals + first + 3) = xV->valuator3;
 
164
                case 3:
 
165
                    *(axisvals + first + 2) = xV->valuator2;
 
166
                case 2:
 
167
                    *(axisvals + first + 1) = xV->valuator1;
 
168
                case 1:
 
169
                    *(axisvals + first) = xV->valuator0;
 
170
                case 0:
 
171
                default:
 
172
                    break;
181
173
                }
182
174
            }
183
 
    
184
 
    if (xE->u.u.type == DeviceKeyPress)
185
 
        {
 
175
        }
 
176
 
 
177
    if (xE->u.u.type == DeviceKeyPress) {
186
178
        modifiers = k->modifierMap[key];
187
 
        kptr = &k->down[key >> 3];
188
 
        if (*kptr & bit) /* allow ddx to generate multiple downs */
189
 
            {   
190
 
            if (!modifiers)
191
 
                {
 
179
        kptr = &k->down[key >> 3];
 
180
        if (*kptr & bit) {      /* allow ddx to generate multiple downs */
 
181
            if (!modifiers) {
192
182
                xE->u.u.type = DeviceKeyRelease;
193
183
                ProcessOtherEvent(xE, other, count);
194
184
                xE->u.u.type = DeviceKeyPress;
195
185
                /* release can have side effects, don't fall through */
196
186
                ProcessOtherEvent(xE, other, count);
197
 
                }
 
187
            }
198
188
            return;
199
 
            }
 
189
        }
200
190
        if (other->valuator)
201
191
            other->valuator->motionHintWindow = NullWindow;
202
192
        *kptr |= bit;
203
193
        k->prev_state = k->state;
204
 
        for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
205
 
            {
206
 
            if (mask & modifiers) 
207
 
                {
 
194
        for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
 
195
            if (mask & modifiers) {
208
196
                /* This key affects modifier "i" */
209
197
                k->modifierKeyCount[i]++;
210
198
                k->state |= mask;
211
199
                modifiers &= ~mask;
212
 
                }
213
200
            }
214
 
        if (!grab && CheckDeviceGrabs(other, xE, 0, count))
215
 
            {
 
201
        }
 
202
        if (!grab && CheckDeviceGrabs(other, xE, 0, count)) {
216
203
            other->activatingKey = key;
217
204
            return;
218
 
            }
219
205
        }
220
 
    else if (xE->u.u.type == DeviceKeyRelease)
221
 
        {
222
 
        kptr = &k->down[key >> 3];
223
 
        if (!(*kptr & bit)) /* guard against duplicates */
 
206
    } else if (xE->u.u.type == DeviceKeyRelease) {
 
207
        kptr = &k->down[key >> 3];
 
208
        if (!(*kptr & bit))     /* guard against duplicates */
224
209
            return;
225
210
        modifiers = k->modifierMap[key];
226
211
        if (other->valuator)
227
212
            other->valuator->motionHintWindow = NullWindow;
228
213
        *kptr &= ~bit;
229
214
        k->prev_state = k->state;
230
 
        for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
231
 
            {
232
 
            if (mask & modifiers) 
233
 
                {
 
215
        for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
 
216
            if (mask & modifiers) {
234
217
                /* This key affects modifier "i" */
235
 
                if (--k->modifierKeyCount[i] <= 0) 
236
 
                    {
 
218
                if (--k->modifierKeyCount[i] <= 0) {
237
219
                    k->modifierKeyCount[i] = 0;
238
220
                    k->state &= ~mask;
239
 
                    }
 
221
                }
240
222
                modifiers &= ~mask;
241
 
                }
242
223
            }
 
224
        }
243
225
 
244
226
        if (other->fromPassiveGrab && (key == other->activatingKey))
245
227
            deactivateDeviceGrab = TRUE;
246
 
        }
247
 
    else if (xE->u.u.type == DeviceButtonPress)
248
 
        {
249
 
        kptr = &b->down[key >> 3];
 
228
    } else if (xE->u.u.type == DeviceButtonPress) {
 
229
        kptr = &b->down[key >> 3];
250
230
        *kptr |= bit;
251
231
        if (other->valuator)
252
232
            other->valuator->motionHintWindow = NullWindow;
254
234
        b->motionMask = DeviceButtonMotionMask;
255
235
        xE->u.u.detail = b->map[key];
256
236
        if (xE->u.u.detail == 0)
257
 
             return;
 
237
            return;
258
238
        if (xE->u.u.detail <= 5)
259
239
            b->state |= (Button1Mask >> 1) << xE->u.u.detail;
260
 
        SetMaskForEvent(Motion_Filter(b),DeviceMotionNotify);
 
240
        SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify);
261
241
        if (!grab)
262
242
            if (CheckDeviceGrabs(other, xE, 0, count))
263
243
                return;
264
244
 
265
 
        }
266
 
    else if (xE->u.u.type == DeviceButtonRelease)
267
 
        {
268
 
        kptr = &b->down[key >> 3];
 
245
    } else if (xE->u.u.type == DeviceButtonRelease) {
 
246
        kptr = &b->down[key >> 3];
269
247
        *kptr &= ~bit;
270
248
        if (other->valuator)
271
249
            other->valuator->motionHintWindow = NullWindow;
272
250
        if (!--b->buttonsDown)
273
 
                b->motionMask = 0;
 
251
            b->motionMask = 0;
274
252
        xE->u.u.detail = b->map[key];
275
253
        if (xE->u.u.detail == 0)
276
254
            return;
277
255
        if (xE->u.u.detail <= 5)
278
256
            b->state &= ~((Button1Mask >> 1) << xE->u.u.detail);
279
 
        SetMaskForEvent(Motion_Filter(b),DeviceMotionNotify);
 
257
        SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify);
280
258
        if (!b->state && other->fromPassiveGrab)
281
259
            deactivateDeviceGrab = TRUE;
282
 
        }
283
 
    else if (xE->u.u.type == ProximityIn)
 
260
    } else if (xE->u.u.type == ProximityIn)
284
261
        other->valuator->mode &= ~OutOfProximity;
285
262
    else if (xE->u.u.type == ProximityOut)
286
263
        other->valuator->mode |= OutOfProximity;
294
271
                            other, count);
295
272
 
296
273
    if (deactivateDeviceGrab == TRUE)
297
 
        (*other->DeactivateGrab)(other);
298
 
    }
 
274
        (*other->DeactivateGrab) (other);
 
275
}
299
276
 
300
 
int
301
 
InitProximityClassDeviceStruct( DeviceIntPtr dev)
 
277
_X_EXPORT int
 
278
InitProximityClassDeviceStruct(DeviceIntPtr dev)
302
279
{
303
280
    register ProximityClassPtr proxc;
304
281
 
305
 
    proxc = (ProximityClassPtr)xalloc(sizeof(ProximityClassRec));
 
282
    proxc = (ProximityClassPtr) xalloc(sizeof(ProximityClassRec));
306
283
    if (!proxc)
307
284
        return FALSE;
308
285
    dev->proximity = proxc;
309
286
    return TRUE;
310
287
}
311
288
 
312
 
void
313
 
InitValuatorAxisStruct( DeviceIntPtr dev,
314
 
                                                int axnum,
315
 
                                                int minval,
316
 
                                                int maxval,
317
 
                                                int resolution,
318
 
                                                int min_res,
319
 
                                                int max_res )
 
289
_X_EXPORT void
 
290
InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
 
291
                       int resolution, int min_res, int max_res)
320
292
{
321
293
    register AxisInfoPtr ax = dev->valuator->axes + axnum;
322
294
 
328
300
}
329
301
 
330
302
static void
331
 
FixDeviceStateNotify (
332
 
    DeviceIntPtr dev,
333
 
    deviceStateNotify *ev,
334
 
    KeyClassPtr k,
335
 
    ButtonClassPtr b,
336
 
    ValuatorClassPtr v,
337
 
    int first)
 
303
FixDeviceStateNotify(DeviceIntPtr dev, deviceStateNotify * ev, KeyClassPtr k,
 
304
                     ButtonClassPtr b, ValuatorClassPtr v, int first)
338
305
{
339
306
    ev->type = DeviceStateNotify;
340
307
    ev->deviceid = dev->id;
347
314
    if (b) {
348
315
        ev->classes_reported |= (1 << ButtonClass);
349
316
        ev->num_buttons = b->numButtons;
350
 
        memmove((char *) &ev->buttons[0], (char *) b->down, 4);
351
 
        }
352
 
    else if (k) {
 
317
        memmove((char *)&ev->buttons[0], (char *)b->down, 4);
 
318
    } else if (k) {
353
319
        ev->classes_reported |= (1 << KeyClass);
354
320
        ev->num_keys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode;
355
 
        memmove((char *) &ev->keys[0], (char *) k->down, 4);
356
 
        }
 
321
        memmove((char *)&ev->keys[0], (char *)k->down, 4);
 
322
    }
357
323
    if (v) {
358
324
        int nval = v->numAxes - first;
 
325
 
359
326
        ev->classes_reported |= (1 << ValuatorClass);
360
327
        ev->classes_reported |= (dev->valuator->mode << ModeBitsShift);
361
328
        ev->num_valuators = nval < 3 ? nval : 3;
362
 
        switch (ev->num_valuators) 
363
 
            {
364
 
            case 3:
365
 
                ev->valuator2 = v->axisVal[first+2];
366
 
            case 2:
367
 
                ev->valuator1 = v->axisVal[first+1];
368
 
            case 1:
369
 
                ev->valuator0 = v->axisVal[first];
 
329
        switch (ev->num_valuators) {
 
330
        case 3:
 
331
            ev->valuator2 = v->axisVal[first + 2];
 
332
        case 2:
 
333
            ev->valuator1 = v->axisVal[first + 1];
 
334
        case 1:
 
335
            ev->valuator0 = v->axisVal[first];
370
336
            break;
371
 
            }
372
337
        }
373
338
    }
 
339
}
374
340
 
375
341
static void
376
 
FixDeviceValuator (
377
 
    DeviceIntPtr dev,
378
 
    deviceValuator *ev,
379
 
    ValuatorClassPtr v,
380
 
    int first)
 
342
FixDeviceValuator(DeviceIntPtr dev, deviceValuator * ev, ValuatorClassPtr v,
 
343
                  int first)
381
344
{
382
345
    int nval = v->numAxes - first;
383
346
 
386
349
    ev->num_valuators = nval < 3 ? nval : 3;
387
350
    ev->first_valuator = first;
388
351
    switch (ev->num_valuators) {
389
 
        case 3:
390
 
            ev->valuator2 = v->axisVal[first+2];
391
 
        case 2:
392
 
            ev->valuator1 = v->axisVal[first+1];
393
 
        case 1:
394
 
            ev->valuator0 = v->axisVal[first];
 
352
    case 3:
 
353
        ev->valuator2 = v->axisVal[first + 2];
 
354
    case 2:
 
355
        ev->valuator1 = v->axisVal[first + 1];
 
356
    case 1:
 
357
        ev->valuator0 = v->axisVal[first];
395
358
        break;
396
 
        }
 
359
    }
397
360
    first += ev->num_valuators;
398
 
    }
 
361
}
399
362
 
400
363
void
401
 
DeviceFocusEvent(dev, type, mode, detail, pWin)
402
 
    DeviceIntPtr dev;
403
 
    int type, mode, detail;
404
 
    register WindowPtr pWin;
405
 
    {
406
 
    deviceFocus event;
 
364
DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
 
365
                 register WindowPtr pWin)
 
366
{
 
367
    deviceFocus event;
407
368
 
408
369
    if (type == FocusIn)
409
370
        type = DeviceFocusIn;
417
378
    event.window = pWin->drawable.id;
418
379
    event.time = currentTime.milliseconds;
419
380
 
420
 
    (void) DeliverEventsToWindow(pWin, (xEvent *)&event, 1,
421
 
        DeviceFocusChangeMask, NullGrab, dev->id);
 
381
    (void)DeliverEventsToWindow(pWin, (xEvent *) & event, 1,
 
382
                                DeviceFocusChangeMask, NullGrab, dev->id);
422
383
 
423
 
    if ((type == DeviceFocusIn) && 
 
384
    if ((type == DeviceFocusIn) &&
424
385
        (wOtherInputMasks(pWin)) &&
425
386
        (wOtherInputMasks(pWin)->inputEvents[dev->id] & DeviceStateNotifyMask))
426
 
        {
427
 
        int                     evcount = 1;
428
 
        deviceStateNotify       *ev, *sev;
429
 
        deviceKeyStateNotify    *kev;
 
387
    {
 
388
        int evcount = 1;
 
389
        deviceStateNotify *ev, *sev;
 
390
        deviceKeyStateNotify *kev;
430
391
        deviceButtonStateNotify *bev;
431
392
 
432
393
        KeyClassPtr k;
433
394
        ButtonClassPtr b;
434
395
        ValuatorClassPtr v;
435
 
        int nval=0, nkeys=0, nbuttons=0, first=0;
 
396
        int nval = 0, nkeys = 0, nbuttons = 0, first = 0;
436
397
 
437
 
        if ((b=dev->button) != NULL) {
 
398
        if ((b = dev->button) != NULL) {
438
399
            nbuttons = b->numButtons;
439
400
            if (nbuttons > 32)
440
401
                evcount++;
441
402
        }
442
 
        if ((k=dev->key) != NULL) {
 
403
        if ((k = dev->key) != NULL) {
443
404
            nkeys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode;
444
405
            if (nkeys > 32)
445
406
                evcount++;
447
408
                evcount++;
448
409
            }
449
410
        }
450
 
        if ((v=dev->valuator) != NULL) {
 
411
        if ((v = dev->valuator) != NULL) {
451
412
            nval = v->numAxes;
452
413
 
453
414
            if (nval > 3)
461
422
        }
462
423
 
463
424
        sev = ev = (deviceStateNotify *) xalloc(evcount * sizeof(xEvent));
464
 
        FixDeviceStateNotify (dev, ev, NULL, NULL, NULL, first);
 
425
        FixDeviceStateNotify(dev, ev, NULL, NULL, NULL, first);
465
426
 
466
427
        if (b != NULL) {
467
 
            FixDeviceStateNotify (dev, ev++, NULL, b, v, first);
 
428
            FixDeviceStateNotify(dev, ev++, NULL, b, v, first);
468
429
            first += 3;
469
430
            nval -= 3;
470
431
            if (nbuttons > 32) {
471
 
                (ev-1)->deviceid |= MORE_EVENTS;
472
 
                bev = (deviceButtonStateNotify *) ev++; 
 
432
                (ev - 1)->deviceid |= MORE_EVENTS;
 
433
                bev = (deviceButtonStateNotify *) ev++;
473
434
                bev->type = DeviceButtonStateNotify;
474
435
                bev->deviceid = dev->id;
475
 
                memmove((char *) &bev->buttons[0], (char *) &b->down[4], 28);
 
436
                memmove((char *)&bev->buttons[0], (char *)&b->down[4], 28);
476
437
            }
477
438
            if (nval > 0) {
478
 
                (ev-1)->deviceid |= MORE_EVENTS;
479
 
                FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
 
439
                (ev - 1)->deviceid |= MORE_EVENTS;
 
440
                FixDeviceValuator(dev, (deviceValuator *) ev++, v, first);
480
441
                first += 3;
481
442
                nval -= 3;
482
443
            }
483
444
        }
484
445
 
485
446
        if (k != NULL) {
486
 
            FixDeviceStateNotify (dev, ev++, k, NULL, v, first);
 
447
            FixDeviceStateNotify(dev, ev++, k, NULL, v, first);
487
448
            first += 3;
488
449
            nval -= 3;
489
450
            if (nkeys > 32) {
490
 
                (ev-1)->deviceid |= MORE_EVENTS;
491
 
                kev = (deviceKeyStateNotify *) ev++; 
 
451
                (ev - 1)->deviceid |= MORE_EVENTS;
 
452
                kev = (deviceKeyStateNotify *) ev++;
492
453
                kev->type = DeviceKeyStateNotify;
493
454
                kev->deviceid = dev->id;
494
 
                memmove((char *) &kev->keys[0], (char *) &k->down[4], 28);
 
455
                memmove((char *)&kev->keys[0], (char *)&k->down[4], 28);
495
456
            }
496
457
            if (nval > 0) {
497
 
                (ev-1)->deviceid |= MORE_EVENTS;
498
 
                FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
 
458
                (ev - 1)->deviceid |= MORE_EVENTS;
 
459
                FixDeviceValuator(dev, (deviceValuator *) ev++, v, first);
499
460
                first += 3;
500
461
                nval -= 3;
501
462
            }
502
463
        }
503
464
 
504
465
        while (nval > 0) {
505
 
            FixDeviceStateNotify (dev, ev++, NULL, NULL, v, first);
 
466
            FixDeviceStateNotify(dev, ev++, NULL, NULL, v, first);
506
467
            first += 3;
507
468
            nval -= 3;
508
469
            if (nval > 0) {
509
 
                (ev-1)->deviceid |= MORE_EVENTS;
510
 
                FixDeviceValuator (dev, (deviceValuator *) ev++, v, first);
 
470
                (ev - 1)->deviceid |= MORE_EVENTS;
 
471
                FixDeviceValuator(dev, (deviceValuator *) ev++, v, first);
511
472
                first += 3;
512
473
                nval -= 3;
513
474
            }
514
475
        }
515
476
 
516
 
        (void) DeliverEventsToWindow(pWin, (xEvent *)sev, evcount,
517
 
            DeviceStateNotifyMask, NullGrab, dev->id);
518
 
        xfree (sev);
519
 
        }
 
477
        (void)DeliverEventsToWindow(pWin, (xEvent *) sev, evcount,
 
478
                                    DeviceStateNotifyMask, NullGrab, dev->id);
 
479
        xfree(sev);
520
480
    }
 
481
}
521
482
 
522
483
int
523
 
GrabButton(
524
 
    ClientPtr client,
525
 
    DeviceIntPtr dev,
526
 
    BYTE this_device_mode,
527
 
    BYTE other_devices_mode,
528
 
    CARD16 modifiers,
529
 
    DeviceIntPtr modifier_device,
530
 
    CARD8 button,
531
 
    Window grabWindow,
532
 
    BOOL ownerEvents,
533
 
    Cursor rcursor,
534
 
    Window rconfineTo,
535
 
    Mask eventMask)
 
484
GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 
485
           BYTE other_devices_mode, CARD16 modifiers,
 
486
           DeviceIntPtr modifier_device, CARD8 button, Window grabWindow,
 
487
           BOOL ownerEvents, Cursor rcursor, Window rconfineTo, Mask eventMask)
536
488
{
537
489
    WindowPtr pWin, confineTo;
538
490
    CursorPtr cursor;
539
491
    GrabPtr grab;
540
492
 
541
493
    if ((this_device_mode != GrabModeSync) &&
542
 
        (this_device_mode != GrabModeAsync))
543
 
    {
 
494
        (this_device_mode != GrabModeAsync)) {
544
495
        client->errorValue = this_device_mode;
545
 
        return BadValue;
 
496
        return BadValue;
546
497
    }
547
498
    if ((other_devices_mode != GrabModeSync) &&
548
 
        (other_devices_mode != GrabModeAsync))
549
 
    {
 
499
        (other_devices_mode != GrabModeAsync)) {
550
500
        client->errorValue = other_devices_mode;
551
 
        return BadValue;
 
501
        return BadValue;
552
502
    }
553
 
    if ((modifiers != AnyModifier) &&
554
 
        (modifiers & ~AllModifiersMask))
555
 
    {
 
503
    if ((modifiers != AnyModifier) && (modifiers & ~AllModifiersMask)) {
556
504
        client->errorValue = modifiers;
557
505
        return BadValue;
558
506
    }
559
 
    if ((ownerEvents != xFalse) && (ownerEvents != xTrue))
560
 
    {
 
507
    if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) {
561
508
        client->errorValue = ownerEvents;
562
509
        return BadValue;
563
510
    }
566
513
        return BadWindow;
567
514
    if (rconfineTo == None)
568
515
        confineTo = NullWindow;
569
 
    else
570
 
    {
 
516
    else {
571
517
        confineTo = LookupWindow(rconfineTo, client);
572
518
        if (!confineTo)
573
519
            return BadWindow;
574
520
    }
575
521
    if (rcursor == None)
576
522
        cursor = NullCursor;
577
 
    else
578
 
    {
579
 
        cursor = (CursorPtr)LookupIDByType(rcursor, RT_CURSOR);
580
 
        if (!cursor)
581
 
        {
 
523
    else {
 
524
        cursor = (CursorPtr) LookupIDByType(rcursor, RT_CURSOR);
 
525
        if (!cursor) {
582
526
            client->errorValue = rcursor;
583
527
            return BadCursor;
584
528
        }
585
529
    }
586
530
 
587
531
    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, 
590
 
        cursor);
 
532
                      (Bool) ownerEvents, (Bool) this_device_mode,
 
533
                      (Bool) other_devices_mode, modifier_device, modifiers,
 
534
                      DeviceButtonPress, button, confineTo, cursor);
591
535
    if (!grab)
592
536
        return BadAlloc;
593
537
    return AddPassiveGrabToList(grab);
594
 
    }
 
538
}
595
539
 
596
540
int
597
 
GrabKey(
598
 
    ClientPtr client,
599
 
    DeviceIntPtr dev,
600
 
    BYTE this_device_mode,
601
 
    BYTE other_devices_mode,
602
 
    CARD16 modifiers,
603
 
    DeviceIntPtr modifier_device,
604
 
    CARD8 key,
605
 
    Window grabWindow,
606
 
    BOOL ownerEvents,
607
 
    Mask mask)
 
541
GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 
542
        BYTE other_devices_mode, CARD16 modifiers,
 
543
        DeviceIntPtr modifier_device, CARD8 key, Window grabWindow,
 
544
        BOOL ownerEvents, Mask mask)
608
545
{
609
546
    WindowPtr pWin;
610
547
    GrabPtr grab;
611
548
    KeyClassPtr k = dev->key;
612
549
 
613
 
    if (k==NULL)
 
550
    if (k == NULL)
614
551
        return BadMatch;
615
552
    if ((other_devices_mode != GrabModeSync) &&
616
 
        (other_devices_mode != GrabModeAsync))
617
 
    {
 
553
        (other_devices_mode != GrabModeAsync)) {
618
554
        client->errorValue = other_devices_mode;
619
 
        return BadValue;
 
555
        return BadValue;
620
556
    }
621
557
    if ((this_device_mode != GrabModeSync) &&
622
 
        (this_device_mode != GrabModeAsync))
623
 
    {
 
558
        (this_device_mode != GrabModeAsync)) {
624
559
        client->errorValue = this_device_mode;
625
 
        return BadValue;
 
560
        return BadValue;
626
561
    }
627
 
    if (((key > k->curKeySyms.maxKeyCode) || 
628
 
         (key < k->curKeySyms.minKeyCode))
629
 
        && (key != AnyKey))
630
 
    {
 
562
    if (((key > k->curKeySyms.maxKeyCode) || (key < k->curKeySyms.minKeyCode))
 
563
        && (key != AnyKey)) {
631
564
        client->errorValue = key;
632
 
        return BadValue;
 
565
        return BadValue;
633
566
    }
634
 
    if ((modifiers != AnyModifier) &&
635
 
        (modifiers & ~AllModifiersMask))
636
 
    {
 
567
    if ((modifiers != AnyModifier) && (modifiers & ~AllModifiersMask)) {
637
568
        client->errorValue = modifiers;
638
569
        return BadValue;
639
570
    }
640
 
    if ((ownerEvents != xTrue) && (ownerEvents != xFalse))
641
 
    {
 
571
    if ((ownerEvents != xTrue) && (ownerEvents != xFalse)) {
642
572
        client->errorValue = ownerEvents;
643
 
        return BadValue;
 
573
        return BadValue;
644
574
    }
645
575
    pWin = LookupWindow(grabWindow, client);
646
576
    if (!pWin)
647
577
        return BadWindow;
648
578
 
649
 
    grab = CreateGrab(client->index, dev, pWin, 
650
 
        mask, ownerEvents, this_device_mode, other_devices_mode, 
651
 
        modifier_device, modifiers, DeviceKeyPress, key, NullWindow, 
652
 
        NullCursor);
 
579
    grab = CreateGrab(client->index, dev, pWin,
 
580
                      mask, ownerEvents, this_device_mode, other_devices_mode,
 
581
                      modifier_device, modifiers, DeviceKeyPress, key,
 
582
                      NullWindow, NullCursor);
653
583
    if (!grab)
654
584
        return BadAlloc;
655
585
    return AddPassiveGrabToList(grab);
656
 
    }
 
586
}
657
587
 
658
588
int
659
 
SelectForWindow(dev, pWin, client, mask, exclusivemasks, validmasks)
660
 
        DeviceIntPtr dev;
661
 
        WindowPtr pWin;
662
 
        ClientPtr client;
663
 
        Mask mask;
664
 
        Mask exclusivemasks;
665
 
        Mask validmasks;
 
589
SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client,
 
590
                Mask mask, Mask exclusivemasks, Mask validmasks)
666
591
{
667
592
    int mskidx = dev->id;
668
593
    int i, ret;
669
594
    Mask check;
670
595
    InputClientsPtr others;
671
596
 
672
 
    if (mask & ~validmasks)
673
 
    {
 
597
    if (mask & ~validmasks) {
674
598
        client->errorValue = mask;
675
599
        return BadValue;
676
600
    }
677
601
    check = (mask & exclusivemasks);
678
 
    if (wOtherInputMasks(pWin))
679
 
        {
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
686
 
                                          events.  */
687
 
            for (others = wOtherInputMasks(pWin)->inputClients; others; 
688
 
                others = others->next)
689
 
                {
690
 
                if (!SameClient(others, client) && (check & 
691
 
                    others->mask[mskidx]))
 
602
    if (wOtherInputMasks(pWin)) {
 
603
        if (check & wOtherInputMasks(pWin)->inputEvents[mskidx]) {      /* It is illegal for two different
 
604
                                                                         * clients to select on any of the
 
605
                                                                         * events for maskcheck. However,
 
606
                                                                         * it is OK, for some client to
 
607
                                                                         * continue selecting on one of those
 
608
                                                                         * events.  */
 
609
            for (others = wOtherInputMasks(pWin)->inputClients; others;
 
610
                 others = others->next) {
 
611
                if (!SameClient(others, client) && (check &
 
612
                                                    others->mask[mskidx]))
692
613
                    return BadAccess;
693
 
                }
694
 
            }
695
 
        for (others = wOtherInputMasks(pWin)->inputClients; others; 
696
 
                others = others->next)
697
 
            {
698
 
            if (SameClient(others, client))
699
 
                {
 
614
            }
 
615
        }
 
616
        for (others = wOtherInputMasks(pWin)->inputClients; others;
 
617
             others = others->next) {
 
618
            if (SameClient(others, client)) {
700
619
                check = others->mask[mskidx];
701
620
                others->mask[mskidx] = mask;
702
 
                if (mask == 0)
703
 
                    {
704
 
                    for (i=0; i<EMASKSIZE; i++)
 
621
                if (mask == 0) {
 
622
                    for (i = 0; i < EMASKSIZE; i++)
705
623
                        if (i != mskidx && others->mask[i] != 0)
706
624
                            break;
707
 
                    if (i == EMASKSIZE)
708
 
                        {
 
625
                    if (i == EMASKSIZE) {
709
626
                        RecalculateDeviceDeliverableEvents(pWin);
710
627
                        if (ShouldFreeInputMasks(pWin, FALSE))
711
628
                            FreeResource(others->resource, RT_NONE);
712
 
                        return Success;
713
 
                        }
 
629
                        return Success;
714
630
                    }
 
631
                }
715
632
                goto maskSet;
716
 
                }
717
633
            }
718
634
        }
 
635
    }
719
636
    check = 0;
720
 
    if ((ret = AddExtensionClient (pWin, client, mask, mskidx)) != Success)
 
637
    if ((ret = AddExtensionClient(pWin, client, mask, mskidx)) != Success)
721
638
        return ret;
722
 
maskSet: 
 
639
  maskSet:
723
640
    if (dev->valuator)
724
641
        if ((dev->valuator->motionHintWindow == pWin) &&
725
642
            (mask & DevicePointerMotionHintMask) &&
726
 
            !(check & DevicePointerMotionHintMask) &&
727
 
            !dev->grab)
 
643
            !(check & DevicePointerMotionHintMask) && !dev->grab)
728
644
            dev->valuator->motionHintWindow = NullWindow;
729
645
    RecalculateDeviceDeliverableEvents(pWin);
730
646
    return Success;
731
647
}
732
648
 
733
 
int 
734
 
AddExtensionClient (pWin, client, mask, mskidx)
735
 
    WindowPtr pWin;
736
 
    ClientPtr client;
737
 
    Mask mask;
738
 
    int mskidx;
739
 
    {
 
649
int
 
650
AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
 
651
{
740
652
    InputClientsPtr others;
741
653
 
742
 
    if (!pWin->optional && !MakeWindowOptional (pWin))
 
654
    if (!pWin->optional && !MakeWindowOptional(pWin))
743
655
        return BadAlloc;
744
656
    others = (InputClients *) xalloc(sizeof(InputClients));
745
657
    if (!others)
746
658
        return BadAlloc;
747
 
    if (!pWin->optional->inputMasks && !MakeInputMasks (pWin))
 
659
    if (!pWin->optional->inputMasks && !MakeInputMasks(pWin))
748
660
        return BadAlloc;
749
 
    bzero((char *) &others->mask[0], sizeof(Mask)*EMASKSIZE);
 
661
    bzero((char *)&others->mask[0], sizeof(Mask) * EMASKSIZE);
750
662
    others->mask[mskidx] = mask;
751
663
    others->resource = FakeClientID(client->index);
752
664
    others->next = pWin->optional->inputMasks->inputClients;
753
665
    pWin->optional->inputMasks->inputClients = others;
754
 
    if (!AddResource(others->resource, RT_INPUTCLIENT, (pointer)pWin))
 
666
    if (!AddResource(others->resource, RT_INPUTCLIENT, (pointer) pWin))
755
667
        return BadAlloc;
756
668
    return Success;
757
 
    }
 
669
}
758
670
 
759
671
static Bool
760
 
MakeInputMasks (pWin)
761
 
    WindowPtr   pWin;
762
 
    {
 
672
MakeInputMasks(WindowPtr pWin)
 
673
{
763
674
    struct _OtherInputMasks *imasks;
764
675
 
765
 
    imasks = (struct _OtherInputMasks *) 
766
 
        xalloc (sizeof (struct _OtherInputMasks));
 
676
    imasks = (struct _OtherInputMasks *)
 
677
        xalloc(sizeof(struct _OtherInputMasks));
767
678
    if (!imasks)
768
679
        return FALSE;
769
 
    bzero((char *) imasks, sizeof (struct _OtherInputMasks));
 
680
    bzero((char *)imasks, sizeof(struct _OtherInputMasks));
770
681
    pWin->optional->inputMasks = imasks;
771
682
    return TRUE;
772
 
    }
 
683
}
773
684
 
774
685
void
775
 
RecalculateDeviceDeliverableEvents(pWin)
776
 
    WindowPtr pWin;
777
 
    {
 
686
RecalculateDeviceDeliverableEvents(WindowPtr pWin)
 
687
{
778
688
    register InputClientsPtr others;
779
 
    struct _OtherInputMasks *inputMasks;   /* default: NULL */
 
689
    struct _OtherInputMasks *inputMasks;        /* default: NULL */
780
690
    register WindowPtr pChild, tmp;
781
691
    int i;
782
692
 
783
693
    pChild = pWin;
784
 
    while (1)
785
 
        {
786
 
        if ((inputMasks = wOtherInputMasks(pChild)) != 0)
787
 
            {
788
 
            for (others = inputMasks->inputClients; others; 
789
 
                others = others->next)
790
 
                {
791
 
                for (i=0; i<EMASKSIZE; i++)
 
694
    while (1) {
 
695
        if ((inputMasks = wOtherInputMasks(pChild)) != 0) {
 
696
            for (others = inputMasks->inputClients; others;
 
697
                 others = others->next) {
 
698
                for (i = 0; i < EMASKSIZE; i++)
792
699
                    inputMasks->inputEvents[i] |= others->mask[i];
793
 
                }
794
 
            for (i=0; i<EMASKSIZE; i++)
 
700
            }
 
701
            for (i = 0; i < EMASKSIZE; i++)
795
702
                inputMasks->deliverableEvents[i] = inputMasks->inputEvents[i];
796
 
            for (tmp = pChild->parent; tmp; tmp=tmp->parent)
 
703
            for (tmp = pChild->parent; tmp; tmp = tmp->parent)
797
704
                if (wOtherInputMasks(tmp))
798
 
                    for (i=0; i<EMASKSIZE; i++)
 
705
                    for (i = 0; i < EMASKSIZE; i++)
799
706
                        inputMasks->deliverableEvents[i] |=
800
 
                        (wOtherInputMasks(tmp)->deliverableEvents[i] 
801
 
                        & ~inputMasks->dontPropagateMask[i] & PropagateMask[i]);
802
 
            }
803
 
        if (pChild->firstChild)
804
 
            {
 
707
                            (wOtherInputMasks(tmp)->deliverableEvents[i]
 
708
                             & ~inputMasks->
 
709
                             dontPropagateMask[i] & PropagateMask[i]);
 
710
        }
 
711
        if (pChild->firstChild) {
805
712
            pChild = pChild->firstChild;
806
713
            continue;
807
 
            }
 
714
        }
808
715
        while (!pChild->nextSib && (pChild != pWin))
809
716
            pChild = pChild->parent;
810
717
        if (pChild == pWin)
811
718
            break;
812
719
        pChild = pChild->nextSib;
813
 
        }
814
720
    }
 
721
}
815
722
 
816
723
int
817
 
InputClientGone(pWin, id)
818
 
    register WindowPtr pWin;
819
 
    XID   id;
820
 
    {
 
724
InputClientGone(register WindowPtr pWin, XID id)
 
725
{
821
726
    register InputClientsPtr other, prev;
 
727
 
822
728
    if (!wOtherInputMasks(pWin))
823
 
        return(Success);
 
729
        return (Success);
824
730
    prev = 0;
825
 
    for (other = wOtherInputMasks(pWin)->inputClients; other; 
826
 
        other = other->next)
827
 
        {
828
 
        if (other->resource == id)
829
 
            {
830
 
            if (prev)
831
 
                {
 
731
    for (other = wOtherInputMasks(pWin)->inputClients; other;
 
732
         other = other->next) {
 
733
        if (other->resource == id) {
 
734
            if (prev) {
832
735
                prev->next = other->next;
833
736
                xfree(other);
834
 
                }
835
 
            else if (!(other->next))
836
 
                {
837
 
                if (ShouldFreeInputMasks(pWin, TRUE))
838
 
                    {
 
737
            } else if (!(other->next)) {
 
738
                if (ShouldFreeInputMasks(pWin, TRUE)) {
839
739
                    wOtherInputMasks(pWin)->inputClients = other->next;
840
740
                    xfree(wOtherInputMasks(pWin));
841
741
                    pWin->optional->inputMasks = (OtherInputMasks *) NULL;
842
 
                    CheckWindowOptionalNeed (pWin);
 
742
                    CheckWindowOptionalNeed(pWin);
843
743
                    xfree(other);
844
 
                    }
845
 
                else
846
 
                    {
 
744
                } else {
847
745
                    other->resource = FakeClientID(0);
848
 
                    if (!AddResource(other->resource, RT_INPUTCLIENT, 
849
 
                        (pointer)pWin))
 
746
                    if (!AddResource(other->resource, RT_INPUTCLIENT,
 
747
                                     (pointer) pWin))
850
748
                        return BadAlloc;
851
 
                    }
852
749
                }
853
 
            else
854
 
                {
 
750
            } else {
855
751
                wOtherInputMasks(pWin)->inputClients = other->next;
856
752
                xfree(other);
857
 
                }
 
753
            }
858
754
            RecalculateDeviceDeliverableEvents(pWin);
859
 
            return(Success);
860
 
            }
 
755
            return (Success);
 
756
        }
861
757
        prev = other;
862
 
        }
 
758
    }
863
759
    FatalError("client not on device event list");
864
 
    /*NOTREACHED*/
865
 
    }
 
760
}
866
761
 
867
762
int
868
 
SendEvent (client, d, dest, propagate, ev, mask, count)
869
 
    ClientPtr           client;
870
 
    DeviceIntPtr        d;
871
 
    Window              dest;
872
 
    Bool                propagate;
873
 
    xEvent              *ev;
874
 
    Mask                mask;
875
 
    int                 count;
876
 
    {
 
763
SendEvent(ClientPtr client, DeviceIntPtr d, Window dest, Bool propagate,
 
764
          xEvent * ev, Mask mask, int count)
 
765
{
877
766
    WindowPtr pWin;
878
 
    WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */
879
 
    WindowPtr spriteWin=GetSpriteWindow();
 
767
    WindowPtr effectiveFocus = NullWindow;      /* only set if dest==InputFocus */
 
768
    WindowPtr spriteWin = GetSpriteWindow();
880
769
 
881
770
    if (dest == PointerWindow)
882
771
        pWin = spriteWin;
883
 
    else if (dest == InputFocus)
884
 
    {
 
772
    else if (dest == InputFocus) {
885
773
        WindowPtr inputFocus;
886
 
        
 
774
 
887
775
        if (!d->focus)
888
776
            inputFocus = spriteWin;
889
777
        else
896
784
            return Success;
897
785
 
898
786
        /* 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)
 
787
         * the pointer is if possible, then perhaps propogate up to root. */
 
788
        if (inputFocus == PointerRootWin)
901
789
            inputFocus = GetCurrentRootWindow();
902
790
 
903
 
        if (IsParent(inputFocus, spriteWin))
904
 
        {
 
791
        if (IsParent(inputFocus, spriteWin)) {
905
792
            effectiveFocus = inputFocus;
906
793
            pWin = spriteWin;
907
 
        }
908
 
        else
 
794
        } else
909
795
            effectiveFocus = pWin = inputFocus;
910
 
    }
911
 
    else
 
796
    } else
912
797
        pWin = LookupWindow(dest, client);
913
798
    if (!pWin)
914
799
        return BadWindow;
915
 
    if ((propagate != xFalse) && (propagate != xTrue))
916
 
    {
 
800
    if ((propagate != xFalse) && (propagate != xTrue)) {
917
801
        client->errorValue = propagate;
918
802
        return BadValue;
919
803
    }
920
804
    ev->u.u.type |= 0x80;
921
 
    if (propagate)
922
 
    {
923
 
        for (;pWin; pWin = pWin->parent)
924
 
        {
925
 
            if (DeliverEventsToWindow( pWin, ev, count, mask, NullGrab, d->id))
 
805
    if (propagate) {
 
806
        for (; pWin; pWin = pWin->parent) {
 
807
            if (DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, d->id))
926
808
                return Success;
927
809
            if (pWin == effectiveFocus)
928
810
                return Success;
931
813
            if (!mask)
932
814
                break;
933
815
        }
934
 
    }
935
 
    else
936
 
        (void)(DeliverEventsToWindow( pWin, ev, count, mask, NullGrab, d->id));
 
816
    } else
 
817
        (void)(DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, d->id));
937
818
    return Success;
938
 
    }
 
819
}
939
820
 
940
821
int
941
 
SetButtonMapping (client, dev, nElts, map)
942
 
    ClientPtr client;
943
 
    DeviceIntPtr dev;
944
 
    int nElts;
945
 
    BYTE *map;
946
 
    {
 
822
SetButtonMapping(ClientPtr client, DeviceIntPtr dev, int nElts, BYTE * map)
 
823
{
947
824
    register int i;
948
825
    ButtonClassPtr b = dev->button;
949
826
 
950
827
    if (b == NULL)
951
828
        return BadMatch;
952
829
 
953
 
    if (nElts != b->numButtons)
954
 
    {
 
830
    if (nElts != b->numButtons) {
955
831
        client->errorValue = nElts;
956
832
        return BadValue;
957
833
    }
958
834
    if (BadDeviceMap(&map[0], nElts, 1, 255, &client->errorValue))
959
835
        return BadValue;
960
 
    for (i=0; i < nElts; i++)
961
 
        if ((b->map[i + 1] != map[i]) &&
962
 
                BitIsOn(b->down, i + 1))
963
 
            return MappingBusy;
 
836
    for (i = 0; i < nElts; i++)
 
837
        if ((b->map[i + 1] != map[i]) && BitIsOn(b->down, i + 1))
 
838
            return MappingBusy;
964
839
    for (i = 0; i < nElts; i++)
965
840
        b->map[i + 1] = map[i];
966
841
    return Success;
967
 
    }
 
842
}
968
843
 
969
 
int 
970
 
SetModifierMapping(client, dev, len, rlen, numKeyPerModifier, inputMap, k)
971
 
    ClientPtr client;
972
 
    DeviceIntPtr dev;
973
 
    int len;
974
 
    int rlen;
975
 
    int numKeyPerModifier;
976
 
    KeyCode *inputMap;
977
 
    KeyClassPtr *k;
 
844
int
 
845
SetModifierMapping(ClientPtr client, DeviceIntPtr dev, int len, int rlen,
 
846
                   int numKeyPerModifier, KeyCode * inputMap, KeyClassPtr * k)
978
847
{
979
848
    KeyCode *map = NULL;
980
849
    int inputMapLen;
981
850
    register int i;
982
 
    
 
851
 
983
852
    *k = dev->key;
984
853
    if (*k == NULL)
985
854
        return BadMatch;
986
 
    if (len != ((numKeyPerModifier<<1) + rlen))
 
855
    if (len != ((numKeyPerModifier << 1) + rlen))
987
856
        return BadLength;
988
857
 
989
 
    inputMapLen = 8*numKeyPerModifier;
 
858
    inputMapLen = 8 * numKeyPerModifier;
990
859
 
991
860
    /*
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)"
 
861
     *  Now enforce the restriction that "all of the non-zero keycodes must be
 
862
     *  in the range specified by min-keycode and max-keycode in the
 
863
     *  connection setup (else a Value error)"
995
864
     */
996
865
    i = inputMapLen;
997
866
    while (i--) {
998
867
        if (inputMap[i]
999
868
            && (inputMap[i] < (*k)->curKeySyms.minKeyCode
1000
869
                || inputMap[i] > (*k)->curKeySyms.maxKeyCode)) {
1001
 
                client->errorValue = inputMap[i];
1002
 
                return -1; /* BadValue collides with MappingFailed */
1003
 
                }
 
870
            client->errorValue = inputMap[i];
 
871
            return -1;  /* BadValue collides with MappingFailed */
 
872
        }
1004
873
    }
1005
874
 
1006
875
    /*
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.
 
876
     *  Now enforce the restriction that none of the old or new
 
877
     *  modifier keys may be down while we change the mapping,  and
 
878
     *  that the DDX layer likes the choice.
1010
879
     */
1011
 
    if (!AllModifierKeysAreUp (dev, (*k)->modifierKeyMap, 
1012
 
        (int)(*k)->maxKeysPerModifier, inputMap, (int)numKeyPerModifier)
1013
 
            ||
1014
 
        !AllModifierKeysAreUp(dev, inputMap, (int)numKeyPerModifier,
1015
 
              (*k)->modifierKeyMap, (int)(*k)->maxKeysPerModifier)) {
 
880
    if (!AllModifierKeysAreUp(dev, (*k)->modifierKeyMap,
 
881
                              (int)(*k)->maxKeysPerModifier, inputMap,
 
882
                              (int)numKeyPerModifier)
 
883
        || !AllModifierKeysAreUp(dev, inputMap, (int)numKeyPerModifier,
 
884
                                 (*k)->modifierKeyMap,
 
885
                                 (int)(*k)->maxKeysPerModifier)) {
1016
886
        return MappingBusy;
1017
887
    } else {
1018
888
        for (i = 0; i < inputMapLen; i++) {
1019
 
            if (inputMap[i] && !LegalModifier(inputMap[i], (DevicePtr)dev)) {
 
889
            if (inputMap[i] && !LegalModifier(inputMap[i], (DevicePtr) dev)) {
1020
890
                return MappingFailed;
1021
891
            }
1022
892
        }
1023
893
    }
1024
894
 
1025
895
    /*
1026
 
     *  Now build the keyboard's modifier bitmap from the
1027
 
     *  list of keycodes.
 
896
     *  Now build the keyboard's modifier bitmap from the
 
897
     *  list of keycodes.
1028
898
     */
1029
899
    if (inputMapLen) {
1030
 
        map = (KeyCode *)xalloc(inputMapLen);
1031
 
        if (!map)
1032
 
            return BadAlloc;
 
900
        map = (KeyCode *) xalloc(inputMapLen);
 
901
        if (!map)
 
902
            return BadAlloc;
1033
903
    }
1034
904
    if ((*k)->modifierKeyMap)
1035
 
        xfree((*k)->modifierKeyMap);
 
905
        xfree((*k)->modifierKeyMap);
1036
906
    if (inputMapLen) {
1037
 
        (*k)->modifierKeyMap = map;
1038
 
        memmove((char *)(*k)->modifierKeyMap, (char *)inputMap, inputMapLen);
 
907
        (*k)->modifierKeyMap = map;
 
908
        memmove((char *)(*k)->modifierKeyMap, (char *)inputMap, inputMapLen);
1039
909
    } else
1040
910
        (*k)->modifierKeyMap = NULL;
1041
911
 
1042
912
    (*k)->maxKeysPerModifier = numKeyPerModifier;
1043
913
    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));
1048
 
    }
 
914
        (*k)->modifierMap[i] = 0;
 
915
    for (i = 0; i < inputMapLen; i++)
 
916
        if (inputMap[i]) {
 
917
            (*k)->modifierMap[inputMap[i]]
 
918
                |= (1 << (i / (*k)->maxKeysPerModifier));
 
919
        }
1049
920
 
1050
 
    return(MappingSuccess);
1051
 
    }
 
921
    return (MappingSuccess);
 
922
}
1052
923
 
1053
924
void
1054
 
SendDeviceMappingNotify(
1055
 
    CARD8 request,
1056
 
    KeyCode firstKeyCode,
1057
 
    CARD8 count,
1058
 
    DeviceIntPtr dev)
 
925
SendDeviceMappingNotify(CARD8 request,
 
926
                        KeyCode firstKeyCode, CARD8 count, DeviceIntPtr dev)
1059
927
{
1060
928
    xEvent event;
1061
 
    deviceMappingNotify         *ev = (deviceMappingNotify *) &event;
 
929
    deviceMappingNotify *ev = (deviceMappingNotify *) & event;
1062
930
 
1063
931
    ev->type = DeviceMappingNotify;
1064
932
    ev->request = request;
1065
933
    ev->deviceid = dev->id;
1066
934
    ev->time = currentTime.milliseconds;
1067
 
    if (request == MappingKeyboard)
1068
 
        {
 
935
    if (request == MappingKeyboard) {
1069
936
        ev->firstKeyCode = firstKeyCode;
1070
937
        ev->count = count;
1071
 
        }
1072
 
 
1073
 
    SendEventToAllWindows (dev, DeviceMappingNotifyMask, (xEvent *)ev, 1);
1074
938
    }
1075
939
 
 
940
    SendEventToAllWindows(dev, DeviceMappingNotifyMask, (xEvent *) ev, 1);
 
941
}
 
942
 
1076
943
int
1077
 
ChangeKeyMapping(
1078
 
    ClientPtr   client,
1079
 
    DeviceIntPtr dev,
1080
 
    unsigned    len,
1081
 
    int         type,
1082
 
    KeyCode     firstKeyCode,
1083
 
    CARD8       keyCodes,
1084
 
    CARD8       keySymsPerKeyCode,
1085
 
    KeySym      *map)
 
944
ChangeKeyMapping(ClientPtr client,
 
945
                 DeviceIntPtr dev,
 
946
                 unsigned len,
 
947
                 int type,
 
948
                 KeyCode firstKeyCode,
 
949
                 CARD8 keyCodes, CARD8 keySymsPerKeyCode, KeySym * map)
1086
950
{
1087
951
    KeySymsRec keysyms;
1088
952
    KeyClassPtr k = dev->key;
1091
955
        return (BadMatch);
1092
956
 
1093
957
    if (len != (keyCodes * keySymsPerKeyCode))
1094
 
            return BadLength;
 
958
        return BadLength;
1095
959
 
1096
960
    if ((firstKeyCode < k->curKeySyms.minKeyCode) ||
1097
 
        (firstKeyCode + keyCodes - 1 > k->curKeySyms.maxKeyCode))
1098
 
    {
1099
 
            client->errorValue = firstKeyCode;
1100
 
            return BadValue;
 
961
        (firstKeyCode + keyCodes - 1 > k->curKeySyms.maxKeyCode)) {
 
962
        client->errorValue = firstKeyCode;
 
963
        return BadValue;
1101
964
    }
1102
 
    if (keySymsPerKeyCode == 0)
1103
 
    {
1104
 
            client->errorValue = 0;
1105
 
            return BadValue;
 
965
    if (keySymsPerKeyCode == 0) {
 
966
        client->errorValue = 0;
 
967
        return BadValue;
1106
968
    }
1107
969
    keysyms.minKeyCode = firstKeyCode;
1108
970
    keysyms.maxKeyCode = firstKeyCode + keyCodes - 1;
1110
972
    keysyms.map = map;
1111
973
    if (!SetKeySymsMap(&k->curKeySyms, &keysyms))
1112
974
        return BadAlloc;
1113
 
    SendDeviceMappingNotify(MappingKeyboard, firstKeyCode, keyCodes,
1114
 
        dev);
 
975
    SendDeviceMappingNotify(MappingKeyboard, firstKeyCode, keyCodes, dev);
1115
976
    return client->noClientException;
1116
 
    }
 
977
}
1117
978
 
1118
979
void
1119
 
DeleteWindowFromAnyExtEvents(pWin, freeResources)
1120
 
    WindowPtr           pWin;
1121
 
    Bool                freeResources;
1122
 
    {
1123
 
    int                 i;
1124
 
    DeviceIntPtr        dev;
1125
 
    InputClientsPtr     ic;
 
980
DeleteWindowFromAnyExtEvents(WindowPtr pWin, Bool freeResources)
 
981
{
 
982
    int i;
 
983
    DeviceIntPtr dev;
 
984
    InputClientsPtr ic;
1126
985
    struct _OtherInputMasks *inputMasks;
1127
986
 
1128
 
    for (dev=inputInfo.devices; dev; dev=dev->next)
1129
 
        {
1130
 
        if (dev == inputInfo.pointer ||
1131
 
            dev == inputInfo.keyboard)
 
987
    for (dev = inputInfo.devices; dev; dev = dev->next) {
 
988
        if (dev == inputInfo.pointer || dev == inputInfo.keyboard)
1132
989
            continue;
1133
990
        DeleteDeviceFromAnyExtEvents(pWin, dev);
1134
 
        }
 
991
    }
1135
992
 
1136
 
    for (dev=inputInfo.off_devices; dev; dev=dev->next)
 
993
    for (dev = inputInfo.off_devices; dev; dev = dev->next)
1137
994
        DeleteDeviceFromAnyExtEvents(pWin, dev);
1138
995
 
1139
996
    if (freeResources)
1140
 
        while ((inputMasks = wOtherInputMasks(pWin)) != 0)
1141
 
            {
 
997
        while ((inputMasks = wOtherInputMasks(pWin)) != 0) {
1142
998
            ic = inputMasks->inputClients;
1143
 
            for (i=0; i<EMASKSIZE; i++)
 
999
            for (i = 0; i < EMASKSIZE; i++)
1144
1000
                inputMasks->dontPropagateMask[i] = 0;
1145
1001
            FreeResource(ic->resource, RT_NONE);
1146
 
            }
1147
 
    }
 
1002
        }
 
1003
}
1148
1004
 
1149
1005
void
1150
 
DeleteDeviceFromAnyExtEvents(pWin, dev)
1151
 
    WindowPtr           pWin;
1152
 
    DeviceIntPtr        dev;
1153
 
    {
1154
 
    WindowPtr           parent;
 
1006
DeleteDeviceFromAnyExtEvents(WindowPtr pWin, DeviceIntPtr dev)
 
1007
{
 
1008
    WindowPtr parent;
1155
1009
 
1156
1010
    /* Deactivate any grabs performed on this window, before making
1157
 
        any input focus changes.
1158
 
        Deactivating a device grab should cause focus events. */
 
1011
     * any input focus changes.
 
1012
     * Deactivating a device grab should cause focus events. */
1159
1013
 
1160
1014
    if (dev->grab && (dev->grab->window == pWin))
1161
 
        (*dev->DeactivateGrab)(dev);
 
1015
        (*dev->DeactivateGrab) (dev);
1162
1016
 
1163
1017
    /* If the focus window is a root window (ie. has no parent) 
1164
 
        then don't delete the focus from it. */
1165
 
    
1166
 
    if (dev->focus && (pWin==dev->focus->win) && (pWin->parent != NullWindow))
1167
 
        {
 
1018
     * then don't delete the focus from it. */
 
1019
 
 
1020
    if (dev->focus && (pWin == dev->focus->win) && (pWin->parent != NullWindow)) {
1168
1021
        int focusEventMode = NotifyNormal;
1169
1022
 
1170
 
        /* If a grab is in progress, then alter the mode of focus events. */
 
1023
        /* If a grab is in progress, then alter the mode of focus events. */
1171
1024
 
1172
1025
        if (dev->grab)
1173
1026
            focusEventMode = NotifyWhileGrabbed;
1174
1027
 
1175
 
        switch (dev->focus->revert)
1176
 
            {
1177
 
            case RevertToNone:
 
1028
        switch (dev->focus->revert) {
 
1029
        case RevertToNone:
 
1030
            DoFocusEvents(dev, pWin, NoneWin, focusEventMode);
 
1031
            dev->focus->win = NoneWin;
 
1032
            dev->focus->traceGood = 0;
 
1033
            break;
 
1034
        case RevertToParent:
 
1035
            parent = pWin;
 
1036
            do {
 
1037
                parent = parent->parent;
 
1038
                dev->focus->traceGood--;
 
1039
            }
 
1040
            while (!parent->realized);
 
1041
            DoFocusEvents(dev, pWin, parent, focusEventMode);
 
1042
            dev->focus->win = parent;
 
1043
            dev->focus->revert = RevertToNone;
 
1044
            break;
 
1045
        case RevertToPointerRoot:
 
1046
            DoFocusEvents(dev, pWin, PointerRootWin, focusEventMode);
 
1047
            dev->focus->win = PointerRootWin;
 
1048
            dev->focus->traceGood = 0;
 
1049
            break;
 
1050
        case RevertToFollowKeyboard:
 
1051
            if (inputInfo.keyboard->focus->win) {
 
1052
                DoFocusEvents(dev, pWin, inputInfo.keyboard->focus->win,
 
1053
                              focusEventMode);
 
1054
                dev->focus->win = FollowKeyboardWin;
 
1055
                dev->focus->traceGood = 0;
 
1056
            } else {
1178
1057
                DoFocusEvents(dev, pWin, NoneWin, focusEventMode);
1179
1058
                dev->focus->win = NoneWin;
1180
1059
                dev->focus->traceGood = 0;
1181
 
                break;
1182
 
            case RevertToParent:
1183
 
                parent = pWin;
1184
 
                do
1185
 
                    {
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;
1192
 
                break;
1193
 
            case RevertToPointerRoot:
1194
 
                DoFocusEvents(dev, pWin, PointerRootWin, focusEventMode);
1195
 
                dev->focus->win = PointerRootWin;
1196
 
                dev->focus->traceGood = 0;
1197
 
                break;
1198
 
            case RevertToFollowKeyboard:
1199
 
                if (inputInfo.keyboard->focus->win) {
1200
 
                    DoFocusEvents(dev, pWin, inputInfo.keyboard->focus->win,
1201
 
                                  focusEventMode);
1202
 
                    dev->focus->win = FollowKeyboardWin;
1203
 
                    dev->focus->traceGood = 0;
1204
 
                } else {
1205
 
                    DoFocusEvents(dev, pWin, NoneWin, focusEventMode);
1206
 
                    dev->focus->win = NoneWin;
1207
 
                    dev->focus->traceGood = 0;
1208
 
                }
1209
 
                break;
1210
1060
            }
 
1061
            break;
1211
1062
        }
 
1063
    }
1212
1064
 
1213
1065
    if (dev->valuator)
1214
1066
        if (dev->valuator->motionHintWindow == pWin)
1215
1067
            dev->valuator->motionHintWindow = NullWindow;
1216
 
    }
 
1068
}
1217
1069
 
1218
1070
int
1219
 
MaybeSendDeviceMotionNotifyHint (pEvents, mask)
1220
 
    deviceKeyButtonPointer *pEvents;
1221
 
    Mask mask;
1222
 
    {
 
1071
MaybeSendDeviceMotionNotifyHint(deviceKeyButtonPointer * pEvents, Mask mask)
 
1072
{
1223
1073
    DeviceIntPtr dev;
1224
1074
 
1225
 
    dev = LookupDeviceIntRec (pEvents->deviceid & DEVICE_BITS);
1226
 
    if (pEvents->type == DeviceMotionNotify)
1227
 
        {
1228
 
        if (mask & DevicePointerMotionHintMask)
1229
 
            {
1230
 
            if (WID(dev->valuator->motionHintWindow) == pEvents->event)
1231
 
                {
1232
 
                return 1; /* don't send, but pretend we did */
1233
 
                }
 
1075
    dev = LookupDeviceIntRec(pEvents->deviceid & DEVICE_BITS);
 
1076
    if (pEvents->type == DeviceMotionNotify) {
 
1077
        if (mask & DevicePointerMotionHintMask) {
 
1078
            if (WID(dev->valuator->motionHintWindow) == pEvents->event) {
 
1079
                return 1;       /* don't send, but pretend we did */
 
1080
            }
1234
1081
            pEvents->detail = NotifyHint;
1235
 
            }
1236
 
         else
1237
 
            {
 
1082
        } else {
1238
1083
            pEvents->detail = NotifyNormal;
1239
 
            }
1240
1084
        }
 
1085
    }
1241
1086
    return (0);
1242
 
    }
 
1087
}
1243
1088
 
1244
1089
void
1245
 
CheckDeviceGrabAndHintWindow (pWin, type, xE, grab, client, deliveryMask)
1246
 
    WindowPtr pWin;
1247
 
    int type;
1248
 
    deviceKeyButtonPointer *xE;
1249
 
    GrabPtr grab;
1250
 
    ClientPtr client;
1251
 
    Mask deliveryMask;
1252
 
    {
 
1090
CheckDeviceGrabAndHintWindow(WindowPtr pWin, int type,
 
1091
                             deviceKeyButtonPointer * xE, GrabPtr grab,
 
1092
                             ClientPtr client, Mask deliveryMask)
 
1093
{
1253
1094
    DeviceIntPtr dev;
1254
1095
 
1255
 
    dev = LookupDeviceIntRec (xE->deviceid & DEVICE_BITS);
 
1096
    dev = LookupDeviceIntRec(xE->deviceid & DEVICE_BITS);
1256
1097
    if (type == DeviceMotionNotify)
1257
1098
        dev->valuator->motionHintWindow = pWin;
1258
 
    else if ((type == DeviceButtonPress) && (!grab) && 
1259
 
        (deliveryMask & DeviceButtonGrabMask))
1260
 
        {
 
1099
    else if ((type == DeviceButtonPress) && (!grab) &&
 
1100
             (deliveryMask & DeviceButtonGrabMask)) {
1261
1101
        GrabRec tempGrab;
1262
1102
 
1263
1103
        tempGrab.device = dev;
1264
1104
        tempGrab.resource = client->clientAsMask;
1265
1105
        tempGrab.window = pWin;
1266
 
        tempGrab.ownerEvents = (deliveryMask & DeviceOwnerGrabButtonMask) ? TRUE : FALSE;
 
1106
        tempGrab.ownerEvents =
 
1107
            (deliveryMask & DeviceOwnerGrabButtonMask) ? TRUE : FALSE;
1267
1108
        tempGrab.eventMask = deliveryMask;
1268
1109
        tempGrab.keyboardMode = GrabModeAsync;
1269
1110
        tempGrab.pointerMode = GrabModeAsync;
1270
1111
        tempGrab.confineTo = NullWindow;
1271
1112
        tempGrab.cursor = NullCursor;
1272
 
        (*dev->ActivateGrab)(dev, &tempGrab, currentTime, TRUE);
1273
 
        }
 
1113
        (*dev->ActivateGrab) (dev, &tempGrab, currentTime, TRUE);
1274
1114
    }
 
1115
}
1275
1116
 
1276
1117
Mask
1277
 
DeviceEventMaskForClient(dev, pWin, client)
1278
 
    DeviceIntPtr        dev;
1279
 
    WindowPtr           pWin;
1280
 
    ClientPtr           client;
1281
 
    {
 
1118
DeviceEventMaskForClient(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client)
 
1119
{
1282
1120
    register InputClientsPtr other;
1283
1121
 
1284
1122
    if (!wOtherInputMasks(pWin))
1285
1123
        return 0;
1286
 
    for (other = wOtherInputMasks(pWin)->inputClients; other; 
1287
 
        other = other->next)
1288
 
        {
 
1124
    for (other = wOtherInputMasks(pWin)->inputClients; other;
 
1125
         other = other->next) {
1289
1126
        if (SameClient(other, client))
1290
1127
            return other->mask[dev->id];
1291
 
        }
 
1128
    }
1292
1129
    return 0;
1293
 
    }
 
1130
}
1294
1131
 
1295
1132
void
1296
 
MaybeStopDeviceHint(dev, client)
1297
 
    register DeviceIntPtr dev;
1298
 
    ClientPtr client;
 
1133
MaybeStopDeviceHint(register DeviceIntPtr dev, ClientPtr client)
1299
1134
{
1300
1135
    WindowPtr pWin;
1301
1136
    GrabPtr grab = dev->grab;
 
1137
 
1302
1138
    pWin = dev->valuator->motionHintWindow;
1303
1139
 
1304
1140
    if ((grab && SameClient(grab, client) &&
1313
1149
}
1314
1150
 
1315
1151
int
1316
 
DeviceEventSuppressForWindow(pWin, client, mask, maskndx)
1317
 
        WindowPtr pWin;
1318
 
        ClientPtr client;
1319
 
        Mask mask;
1320
 
        int maskndx;
1321
 
    {
1322
 
    struct _OtherInputMasks *inputMasks = wOtherInputMasks (pWin);
 
1152
DeviceEventSuppressForWindow(WindowPtr pWin, ClientPtr client, Mask mask,
 
1153
                             int maskndx)
 
1154
{
 
1155
    struct _OtherInputMasks *inputMasks = wOtherInputMasks(pWin);
1323
1156
 
1324
 
    if (mask & ~PropagateMask[maskndx])
1325
 
        {
 
1157
    if (mask & ~PropagateMask[maskndx]) {
1326
1158
        client->errorValue = mask;
1327
1159
        return BadValue;
1328
 
        }
 
1160
    }
1329
1161
 
1330
 
    if (mask == 0) 
1331
 
        {
 
1162
    if (mask == 0) {
1332
1163
        if (inputMasks)
1333
1164
            inputMasks->dontPropagateMask[maskndx] = mask;
1334
 
        } 
1335
 
    else 
1336
 
        {
 
1165
    } else {
1337
1166
        if (!inputMasks)
1338
 
            AddExtensionClient (pWin, client, 0, 0);
 
1167
            AddExtensionClient(pWin, client, 0, 0);
1339
1168
        inputMasks = wOtherInputMasks(pWin);
1340
1169
        inputMasks->dontPropagateMask[maskndx] = mask;
1341
 
        }
 
1170
    }
1342
1171
    RecalculateDeviceDeliverableEvents(pWin);
1343
1172
    if (ShouldFreeInputMasks(pWin, FALSE))
1344
 
        FreeResource(inputMasks->inputClients->resource, RT_NONE);
 
1173
        FreeResource(inputMasks->inputClients->resource, RT_NONE);
1345
1174
    return Success;
1346
 
    }
 
1175
}
1347
1176
 
1348
1177
static Bool
1349
 
ShouldFreeInputMasks (pWin, ignoreSelectedEvents)
1350
 
    WindowPtr pWin;
1351
 
    Bool ignoreSelectedEvents;
1352
 
    {
 
1178
ShouldFreeInputMasks(WindowPtr pWin, Bool ignoreSelectedEvents)
 
1179
{
1353
1180
    int i;
1354
1181
    Mask allInputEventMasks = 0;
1355
 
    struct _OtherInputMasks *inputMasks = wOtherInputMasks (pWin);
 
1182
    struct _OtherInputMasks *inputMasks = wOtherInputMasks(pWin);
1356
1183
 
1357
 
    for (i=0; i<EMASKSIZE; i++)
 
1184
    for (i = 0; i < EMASKSIZE; i++)
1358
1185
        allInputEventMasks |= inputMasks->dontPropagateMask[i];
1359
1186
    if (!ignoreSelectedEvents)
1360
 
        for (i=0; i<EMASKSIZE; i++)
 
1187
        for (i = 0; i < EMASKSIZE; i++)
1361
1188
            allInputEventMasks |= inputMasks->inputEvents[i];
1362
1189
    if (allInputEventMasks == 0)
1363
1190
        return TRUE;
1364
1191
    else
1365
1192
        return FALSE;
1366
 
    }
 
1193
}