~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/darwin/quartz/applewm.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/applewm.c,v 1.2 2003/09/16 00:36:13 torrey Exp $ */
 
2
/**************************************************************************
 
3
 
 
4
Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
 
5
Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a
 
8
copy of this software and associated documentation files (the
 
9
"Software"), to deal in the Software without restriction, including
 
10
without limitation the rights to use, copy, modify, merge, publish,
 
11
distribute, sub license, and/or sell copies of the Software, and to
 
12
permit persons to whom the Software is furnished to do so, subject to
 
13
the following conditions:
 
14
 
 
15
The above copyright notice and this permission notice (including the
 
16
next paragraph) shall be included in all copies or substantial portions
 
17
of the Software.
 
18
 
 
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 
22
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 
23
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 
24
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 
25
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
26
 
 
27
**************************************************************************/
 
28
 
 
29
#include "quartzCommon.h"
 
30
 
 
31
#define NEED_REPLIES
 
32
#define NEED_EVENTS
 
33
#include "misc.h"
 
34
#include "dixstruct.h"
 
35
#include "globals.h"
 
36
#include "extnsionst.h"
 
37
#include "colormapst.h"
 
38
#include "cursorstr.h"
 
39
#include "scrnintstr.h"
 
40
#include "windowstr.h"
 
41
#include "servermd.h"
 
42
#include "swaprep.h"
 
43
#include "propertyst.h"
 
44
#include <X11/Xatom.h>
 
45
#include "darwin.h"
 
46
#define _APPLEWM_SERVER_
 
47
#include "applewmstr.h"
 
48
#include "applewmExt.h"
 
49
 
 
50
#define DEFINE_ATOM_HELPER(func,atom_name)                      \
 
51
static Atom func (void) {                                       \
 
52
    static int generation;                                      \
 
53
    static Atom atom;                                           \
 
54
    if (generation != serverGeneration) {                       \
 
55
        generation = serverGeneration;                          \
 
56
        atom = MakeAtom (atom_name, strlen (atom_name), TRUE);  \
 
57
    }                                                           \
 
58
    return atom;                                                \
 
59
}
 
60
 
 
61
DEFINE_ATOM_HELPER(xa_native_screen_origin, "_NATIVE_SCREEN_ORIGIN")
 
62
DEFINE_ATOM_HELPER (xa_apple_no_order_in, "_APPLE_NO_ORDER_IN")
 
63
 
 
64
static AppleWMProcsPtr appleWMProcs;
 
65
 
 
66
static int WMErrorBase;
 
67
 
 
68
static DISPATCH_PROC(ProcAppleWMDispatch);
 
69
static DISPATCH_PROC(SProcAppleWMDispatch);
 
70
 
 
71
static void AppleWMResetProc(ExtensionEntry* extEntry);
 
72
 
 
73
static unsigned char WMReqCode = 0;
 
74
static int WMEventBase = 0;
 
75
 
 
76
static RESTYPE ClientType, EventType; /* resource types for event masks */
 
77
static XID eventResource;
 
78
 
 
79
/* Currently selected events */
 
80
static unsigned int eventMask = 0;
 
81
 
 
82
static int WMFreeClient (pointer data, XID id);
 
83
static int WMFreeEvents (pointer data, XID id);
 
84
static void SNotifyEvent(xAppleWMNotifyEvent *from, xAppleWMNotifyEvent *to);
 
85
 
 
86
typedef struct _WMEvent *WMEventPtr;
 
87
typedef struct _WMEvent {
 
88
    WMEventPtr      next;
 
89
    ClientPtr       client;
 
90
    XID             clientResource;
 
91
    unsigned int    mask;
 
92
} WMEventRec;
 
93
 
 
94
static inline BoxRec
 
95
make_box (int x, int y, int w, int h)
 
96
{
 
97
    BoxRec r;
 
98
    r.x1 = x;
 
99
    r.y1 = y;
 
100
    r.x2 = x + w;
 
101
    r.y2 = y + h;
 
102
    return r;
 
103
}
 
104
 
 
105
void
 
106
AppleWMExtensionInit(
 
107
    AppleWMProcsPtr procsPtr)
 
108
{
 
109
    ExtensionEntry* extEntry;
 
110
 
 
111
    ClientType = CreateNewResourceType(WMFreeClient);
 
112
    EventType = CreateNewResourceType(WMFreeEvents);
 
113
    eventResource = FakeClientID(0);
 
114
 
 
115
    if (ClientType && EventType &&
 
116
        (extEntry = AddExtension(APPLEWMNAME,
 
117
                                 AppleWMNumberEvents,
 
118
                                 AppleWMNumberErrors,
 
119
                                 ProcAppleWMDispatch,
 
120
                                 SProcAppleWMDispatch,
 
121
                                 AppleWMResetProc,
 
122
                                 StandardMinorOpcode)))
 
123
    {
 
124
        WMReqCode = (unsigned char)extEntry->base;
 
125
        WMErrorBase = extEntry->errorBase;
 
126
        WMEventBase = extEntry->eventBase;
 
127
        EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
 
128
        appleWMProcs = procsPtr;
 
129
    }
 
130
}
 
131
 
 
132
/*ARGSUSED*/
 
133
static void
 
134
AppleWMResetProc (
 
135
    ExtensionEntry* extEntry
 
136
)
 
137
{
 
138
}
 
139
 
 
140
/* Updates the _NATIVE_SCREEN_ORIGIN property on the given root window. */
 
141
void
 
142
AppleWMSetScreenOrigin(
 
143
    WindowPtr pWin
 
144
)
 
145
{
 
146
    long data[2];
 
147
 
 
148
    data[0] = (dixScreenOrigins[pWin->drawable.pScreen->myNum].x
 
149
                + darwinMainScreenX);
 
150
    data[1] = (dixScreenOrigins[pWin->drawable.pScreen->myNum].y
 
151
                + darwinMainScreenY);
 
152
 
 
153
    ChangeWindowProperty(pWin, xa_native_screen_origin(), XA_INTEGER,
 
154
                         32, PropModeReplace, 2, data, TRUE);
 
155
}
 
156
 
 
157
/* Window managers can set the _APPLE_NO_ORDER_IN property on windows
 
158
   that are being genie-restored from the Dock. We want them to
 
159
   be mapped but remain ordered-out until the animation
 
160
   completes (when the Dock will order them in). */
 
161
Bool
 
162
AppleWMDoReorderWindow(
 
163
    WindowPtr pWin
 
164
)
 
165
{
 
166
    Atom atom;
 
167
    PropertyPtr prop;
 
168
 
 
169
    atom = xa_apple_no_order_in();
 
170
    for (prop = wUserProps(pWin); prop != NULL; prop = prop->next)
 
171
    {
 
172
        if (prop->propertyName == atom && prop->type == atom)
 
173
            return FALSE;
 
174
    }
 
175
 
 
176
    return TRUE;
 
177
}
 
178
 
 
179
 
 
180
static int
 
181
ProcAppleWMQueryVersion(
 
182
    register ClientPtr client
 
183
)
 
184
{
 
185
    xAppleWMQueryVersionReply rep;
 
186
    register int n;
 
187
 
 
188
    REQUEST_SIZE_MATCH(xAppleWMQueryVersionReq);
 
189
    rep.type = X_Reply;
 
190
    rep.length = 0;
 
191
    rep.sequenceNumber = client->sequence;
 
192
    rep.majorVersion = APPLE_WM_MAJOR_VERSION;
 
193
    rep.minorVersion = APPLE_WM_MINOR_VERSION;
 
194
    rep.patchVersion = APPLE_WM_PATCH_VERSION;
 
195
    if (client->swapped) {
 
196
        swaps(&rep.sequenceNumber, n);
 
197
        swapl(&rep.length, n);
 
198
    }
 
199
    WriteToClient(client, sizeof(xAppleWMQueryVersionReply), (char *)&rep);
 
200
    return (client->noClientException);
 
201
}
 
202
 
 
203
 
 
204
/* events */
 
205
 
 
206
static inline void
 
207
updateEventMask (WMEventPtr *pHead)
 
208
{
 
209
    WMEventPtr pCur;
 
210
 
 
211
    eventMask = 0;
 
212
    for (pCur = *pHead; pCur != NULL; pCur = pCur->next)
 
213
        eventMask |= pCur->mask;
 
214
}
 
215
 
 
216
/*ARGSUSED*/
 
217
static int
 
218
WMFreeClient (data, id)
 
219
    pointer     data;
 
220
    XID         id;
 
221
{
 
222
    WMEventPtr   pEvent;
 
223
    WMEventPtr   *pHead, pCur, pPrev;
 
224
 
 
225
    pEvent = (WMEventPtr) data;
 
226
    pHead = (WMEventPtr *) LookupIDByType(eventResource, EventType);
 
227
    if (pHead) {
 
228
        pPrev = 0;
 
229
        for (pCur = *pHead; pCur && pCur != pEvent; pCur=pCur->next)
 
230
            pPrev = pCur;
 
231
        if (pCur) {
 
232
            if (pPrev)
 
233
                pPrev->next = pEvent->next;
 
234
            else
 
235
                *pHead = pEvent->next;
 
236
        }
 
237
        updateEventMask (pHead);
 
238
    }
 
239
    xfree ((pointer) pEvent);
 
240
    return 1;
 
241
}
 
242
 
 
243
/*ARGSUSED*/
 
244
static int
 
245
WMFreeEvents (data, id)
 
246
    pointer     data;
 
247
    XID         id;
 
248
{
 
249
    WMEventPtr   *pHead, pCur, pNext;
 
250
 
 
251
    pHead = (WMEventPtr *) data;
 
252
    for (pCur = *pHead; pCur; pCur = pNext) {
 
253
        pNext = pCur->next;
 
254
        FreeResource (pCur->clientResource, ClientType);
 
255
        xfree ((pointer) pCur);
 
256
    }
 
257
    xfree ((pointer) pHead);
 
258
    eventMask = 0;
 
259
    return 1;
 
260
}
 
261
 
 
262
static int
 
263
ProcAppleWMSelectInput (client)
 
264
    register ClientPtr  client;
 
265
{
 
266
    REQUEST(xAppleWMSelectInputReq);
 
267
    WMEventPtr      pEvent, pNewEvent, *pHead;
 
268
    XID             clientResource;
 
269
 
 
270
    REQUEST_SIZE_MATCH (xAppleWMSelectInputReq);
 
271
    pHead = (WMEventPtr *)SecurityLookupIDByType(client,
 
272
                        eventResource, EventType, SecurityWriteAccess);
 
273
    if (stuff->mask != 0) {
 
274
        if (pHead) {
 
275
            /* check for existing entry. */
 
276
            for (pEvent = *pHead; pEvent; pEvent = pEvent->next)
 
277
            {
 
278
                if (pEvent->client == client)
 
279
                {
 
280
                    pEvent->mask = stuff->mask;
 
281
                    updateEventMask (pHead);
 
282
                    return Success;
 
283
                }
 
284
            }
 
285
        }
 
286
 
 
287
        /* build the entry */
 
288
        pNewEvent = (WMEventPtr) xalloc (sizeof (WMEventRec));
 
289
        if (!pNewEvent)
 
290
            return BadAlloc;
 
291
        pNewEvent->next = 0;
 
292
        pNewEvent->client = client;
 
293
        pNewEvent->mask = stuff->mask;
 
294
        /*
 
295
         * add a resource that will be deleted when
 
296
         * the client goes away
 
297
         */
 
298
        clientResource = FakeClientID (client->index);
 
299
        pNewEvent->clientResource = clientResource;
 
300
        if (!AddResource (clientResource, ClientType, (pointer)pNewEvent))
 
301
            return BadAlloc;
 
302
        /*
 
303
         * create a resource to contain a pointer to the list
 
304
         * of clients selecting input.  This must be indirect as
 
305
         * the list may be arbitrarily rearranged which cannot be
 
306
         * done through the resource database.
 
307
         */
 
308
        if (!pHead)
 
309
        {
 
310
            pHead = (WMEventPtr *) xalloc (sizeof (WMEventPtr));
 
311
            if (!pHead ||
 
312
                !AddResource (eventResource, EventType, (pointer)pHead))
 
313
            {
 
314
                FreeResource (clientResource, RT_NONE);
 
315
                return BadAlloc;
 
316
            }
 
317
            *pHead = 0;
 
318
        }
 
319
        pNewEvent->next = *pHead;
 
320
        *pHead = pNewEvent;
 
321
        updateEventMask (pHead);
 
322
    } else if (stuff->mask == 0) {
 
323
        /* delete the interest */
 
324
        if (pHead) {
 
325
            pNewEvent = 0;
 
326
            for (pEvent = *pHead; pEvent; pEvent = pEvent->next) {
 
327
                if (pEvent->client == client)
 
328
                    break;
 
329
                pNewEvent = pEvent;
 
330
            }
 
331
            if (pEvent) {
 
332
                FreeResource (pEvent->clientResource, ClientType);
 
333
                if (pNewEvent)
 
334
                    pNewEvent->next = pEvent->next;
 
335
                else
 
336
                    *pHead = pEvent->next;
 
337
                xfree (pEvent);
 
338
                updateEventMask (pHead);
 
339
            }
 
340
        }
 
341
    } else {
 
342
        client->errorValue = stuff->mask;
 
343
        return BadValue;
 
344
    }
 
345
    return Success;
 
346
}
 
347
 
 
348
/*
 
349
 * deliver the event
 
350
 */
 
351
 
 
352
void
 
353
AppleWMSendEvent (type, mask, which, arg)
 
354
    int type, which, arg;
 
355
    unsigned int mask;
 
356
{
 
357
    WMEventPtr      *pHead, pEvent;
 
358
    ClientPtr       client;
 
359
    xAppleWMNotifyEvent se;
 
360
 
 
361
    pHead = (WMEventPtr *) LookupIDByType(eventResource, EventType);
 
362
    if (!pHead)
 
363
        return;
 
364
    for (pEvent = *pHead; pEvent; pEvent = pEvent->next) {
 
365
        client = pEvent->client;
 
366
        if ((pEvent->mask & mask) == 0
 
367
            || client == serverClient || client->clientGone)
 
368
        {
 
369
            continue;
 
370
        }
 
371
        se.type = type + WMEventBase;
 
372
        se.kind = which;
 
373
        se.arg = arg;
 
374
        se.sequenceNumber = client->sequence;
 
375
        se.time = currentTime.milliseconds;
 
376
        WriteEventsToClient (client, 1, (xEvent *) &se);
 
377
    }
 
378
}
 
379
 
 
380
/* Safe to call from any thread. */
 
381
unsigned int
 
382
AppleWMSelectedEvents (void)
 
383
{
 
384
    return eventMask;
 
385
}
 
386
 
 
387
 
 
388
/* general utility functions */
 
389
 
 
390
static int
 
391
ProcAppleWMDisableUpdate(
 
392
    register ClientPtr client
 
393
)
 
394
{
 
395
    REQUEST_SIZE_MATCH(xAppleWMDisableUpdateReq);
 
396
 
 
397
    appleWMProcs->DisableUpdate();
 
398
 
 
399
    return (client->noClientException);
 
400
}
 
401
 
 
402
static int
 
403
ProcAppleWMReenableUpdate(
 
404
    register ClientPtr client
 
405
)
 
406
{
 
407
    REQUEST_SIZE_MATCH(xAppleWMReenableUpdateReq);
 
408
 
 
409
    appleWMProcs->EnableUpdate();
 
410
 
 
411
    return (client->noClientException);
 
412
}
 
413
 
 
414
 
 
415
/* window functions */
 
416
 
 
417
static int
 
418
ProcAppleWMSetWindowMenu(
 
419
    register ClientPtr client
 
420
)
 
421
{
 
422
    const char *bytes, **items;
 
423
    char *shortcuts;
 
424
    int max_len, nitems, i, j;
 
425
    REQUEST(xAppleWMSetWindowMenuReq);
 
426
 
 
427
    REQUEST_AT_LEAST_SIZE(xAppleWMSetWindowMenuReq);
 
428
 
 
429
    nitems = stuff->nitems;
 
430
    items = xalloc (sizeof (char *) * nitems);
 
431
    shortcuts = xalloc (sizeof (char) * nitems);
 
432
 
 
433
    max_len = (stuff->length << 2) - sizeof(xAppleWMSetWindowMenuReq);
 
434
    bytes = (char *) &stuff[1];
 
435
 
 
436
    for (i = j = 0; i < max_len && j < nitems;)
 
437
    {
 
438
        shortcuts[j] = bytes[i++];
 
439
        items[j++] = bytes + i;
 
440
 
 
441
        while (i < max_len)
 
442
        {
 
443
            if (bytes[i++] == 0)
 
444
                break;
 
445
        }
 
446
    }
 
447
 
 
448
    QuartzSetWindowMenu (nitems, items, shortcuts);
 
449
 
 
450
    free(items);
 
451
    free(shortcuts);
 
452
 
 
453
    return (client->noClientException);
 
454
}
 
455
 
 
456
static int
 
457
ProcAppleWMSetWindowMenuCheck(
 
458
    register ClientPtr client
 
459
)
 
460
{
 
461
    REQUEST(xAppleWMSetWindowMenuCheckReq);
 
462
 
 
463
    REQUEST_SIZE_MATCH(xAppleWMSetWindowMenuCheckReq);
 
464
 
 
465
    QuartzMessageMainThread(kQuartzSetWindowMenuCheck, &stuff->index,
 
466
                            sizeof(stuff->index));
 
467
 
 
468
    return (client->noClientException);
 
469
}
 
470
 
 
471
static int
 
472
ProcAppleWMSetFrontProcess(
 
473
    register ClientPtr client
 
474
)
 
475
{
 
476
    REQUEST_SIZE_MATCH(xAppleWMSetFrontProcessReq);
 
477
 
 
478
    QuartzMessageMainThread(kQuartzSetFrontProcess, NULL, 0);
 
479
 
 
480
    return (client->noClientException);
 
481
}
 
482
 
 
483
static int
 
484
ProcAppleWMSetWindowLevel(
 
485
    register ClientPtr client
 
486
)
 
487
{
 
488
    REQUEST(xAppleWMSetWindowLevelReq);
 
489
    WindowPtr pWin;
 
490
    int errno;
 
491
 
 
492
    REQUEST_SIZE_MATCH(xAppleWMSetWindowLevelReq);
 
493
 
 
494
    if (!(pWin = SecurityLookupWindow((Drawable)stuff->window,
 
495
                                      client, SecurityReadAccess)))
 
496
    {
 
497
        return BadValue;
 
498
    }
 
499
 
 
500
    if (stuff->level < 0 || stuff->level >= AppleWMNumWindowLevels) {
 
501
        return BadValue;
 
502
    }
 
503
 
 
504
     errno = appleWMProcs->SetWindowLevel(pWin, stuff->level);
 
505
     if (errno != Success) {
 
506
        return errno;
 
507
    }
 
508
 
 
509
    return (client->noClientException);
 
510
}
 
511
 
 
512
static int
 
513
ProcAppleWMSetCanQuit(
 
514
    register ClientPtr client
 
515
)
 
516
{
 
517
    REQUEST(xAppleWMSetCanQuitReq);
 
518
 
 
519
    REQUEST_SIZE_MATCH(xAppleWMSetCanQuitReq);
 
520
 
 
521
    QuartzMessageMainThread(kQuartzSetCanQuit, &stuff->state,
 
522
                            sizeof(stuff->state));
 
523
 
 
524
    return (client->noClientException);
 
525
}
 
526
 
 
527
 
 
528
/* frame functions */
 
529
 
 
530
static int
 
531
ProcAppleWMFrameGetRect(
 
532
    register ClientPtr client
 
533
)
 
534
{
 
535
    xAppleWMFrameGetRectReply rep;
 
536
    BoxRec ir, or, rr;
 
537
    REQUEST(xAppleWMFrameGetRectReq);
 
538
 
 
539
    REQUEST_SIZE_MATCH(xAppleWMFrameGetRectReq);
 
540
    rep.type = X_Reply;
 
541
    rep.length = 0;
 
542
    rep.sequenceNumber = client->sequence;
 
543
 
 
544
    ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih);
 
545
    or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh);
 
546
 
 
547
    if (appleWMProcs->FrameGetRect(stuff->frame_rect,
 
548
                                   stuff->frame_class,
 
549
                                   &or, &ir, &rr) != Success)
 
550
    {
 
551
        return BadValue;
 
552
    }
 
553
 
 
554
    rep.x = rr.x1;
 
555
    rep.y = rr.y1;
 
556
    rep.w = rr.x2 - rr.x1;
 
557
    rep.h = rr.y2 - rr.y1;
 
558
 
 
559
    WriteToClient(client, sizeof(xAppleWMFrameGetRectReply), (char *)&rep);
 
560
    return (client->noClientException);
 
561
}
 
562
 
 
563
static int
 
564
ProcAppleWMFrameHitTest(
 
565
    register ClientPtr client
 
566
)
 
567
{
 
568
    xAppleWMFrameHitTestReply rep;
 
569
    BoxRec ir, or;
 
570
    int ret;
 
571
    REQUEST(xAppleWMFrameHitTestReq);
 
572
 
 
573
    REQUEST_SIZE_MATCH(xAppleWMFrameHitTestReq);
 
574
    rep.type = X_Reply;
 
575
    rep.length = 0;
 
576
    rep.sequenceNumber = client->sequence;
 
577
 
 
578
    ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih);
 
579
    or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh);
 
580
 
 
581
    if (appleWMProcs->FrameHitTest(stuff->frame_class, stuff->px,
 
582
                                   stuff->py, &or, &ir, &ret) != Success)
 
583
    {
 
584
        return BadValue;
 
585
    }
 
586
 
 
587
    rep.ret = ret;
 
588
 
 
589
    WriteToClient(client, sizeof(xAppleWMFrameHitTestReply), (char *)&rep);
 
590
    return (client->noClientException);
 
591
}
 
592
 
 
593
static int
 
594
ProcAppleWMFrameDraw(
 
595
    register ClientPtr client
 
596
)
 
597
{
 
598
    BoxRec ir, or;
 
599
    unsigned int title_length, title_max;
 
600
    unsigned char *title_bytes;
 
601
    REQUEST(xAppleWMFrameDrawReq);
 
602
    WindowPtr pWin;
 
603
 
 
604
    REQUEST_AT_LEAST_SIZE(xAppleWMFrameDrawReq);
 
605
 
 
606
    if (!(pWin = SecurityLookupWindow((Drawable)stuff->window,
 
607
                                      client, SecurityReadAccess)))
 
608
    {
 
609
        return BadValue;
 
610
    }
 
611
 
 
612
    ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih);
 
613
    or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh);
 
614
 
 
615
    title_length = stuff->title_length;
 
616
    title_max = (stuff->length << 2) - sizeof(xAppleWMFrameDrawReq);
 
617
 
 
618
    if (title_max < title_length)
 
619
        return BadValue;
 
620
 
 
621
    title_bytes = (unsigned char *) &stuff[1];
 
622
 
 
623
    errno = appleWMProcs->FrameDraw(pWin, stuff->frame_class,
 
624
                                    stuff->frame_attr, &or, &ir,
 
625
                                    title_length, title_bytes);
 
626
    if (errno != Success) {
 
627
        return errno;
 
628
    }
 
629
 
 
630
    return (client->noClientException);
 
631
}
 
632
 
 
633
 
 
634
/* dispatch */
 
635
 
 
636
static int
 
637
ProcAppleWMDispatch (
 
638
    register ClientPtr  client
 
639
)
 
640
{
 
641
    REQUEST(xReq);
 
642
 
 
643
    switch (stuff->data)
 
644
    {
 
645
    case X_AppleWMQueryVersion:
 
646
        return ProcAppleWMQueryVersion(client);
 
647
    }
 
648
 
 
649
    if (!LocalClient(client))
 
650
        return WMErrorBase + AppleWMClientNotLocal;
 
651
 
 
652
    switch (stuff->data)
 
653
    {
 
654
    case X_AppleWMSelectInput:
 
655
        return ProcAppleWMSelectInput(client);
 
656
    case X_AppleWMDisableUpdate:
 
657
        return ProcAppleWMDisableUpdate(client);
 
658
    case X_AppleWMReenableUpdate:
 
659
        return ProcAppleWMReenableUpdate(client);
 
660
    case X_AppleWMSetWindowMenu:
 
661
        return ProcAppleWMSetWindowMenu(client);
 
662
    case X_AppleWMSetWindowMenuCheck:
 
663
        return ProcAppleWMSetWindowMenuCheck(client);
 
664
    case X_AppleWMSetFrontProcess:
 
665
        return ProcAppleWMSetFrontProcess(client);
 
666
    case X_AppleWMSetWindowLevel:
 
667
        return ProcAppleWMSetWindowLevel(client);
 
668
    case X_AppleWMSetCanQuit:
 
669
        return ProcAppleWMSetCanQuit(client);
 
670
    case X_AppleWMFrameGetRect:
 
671
        return ProcAppleWMFrameGetRect(client);
 
672
    case X_AppleWMFrameHitTest:
 
673
        return ProcAppleWMFrameHitTest(client);
 
674
    case X_AppleWMFrameDraw:
 
675
        return ProcAppleWMFrameDraw(client);
 
676
    default:
 
677
        return BadRequest;
 
678
    }
 
679
}
 
680
 
 
681
static void
 
682
SNotifyEvent(from, to)
 
683
    xAppleWMNotifyEvent *from, *to;
 
684
{
 
685
    to->type = from->type;
 
686
    to->kind = from->kind;
 
687
    cpswaps (from->sequenceNumber, to->sequenceNumber);
 
688
    cpswapl (from->time, to->time);
 
689
    cpswapl (from->arg, to->arg);
 
690
}
 
691
 
 
692
static int
 
693
SProcAppleWMQueryVersion(
 
694
    register ClientPtr  client
 
695
)
 
696
{
 
697
    register int n;
 
698
    REQUEST(xAppleWMQueryVersionReq);
 
699
    swaps(&stuff->length, n);
 
700
    return ProcAppleWMQueryVersion(client);
 
701
}
 
702
 
 
703
static int
 
704
SProcAppleWMDispatch (
 
705
    register ClientPtr  client
 
706
)
 
707
{
 
708
    REQUEST(xReq);
 
709
 
 
710
    /* It is bound to be non-local when there is byte swapping */
 
711
    if (!LocalClient(client))
 
712
        return WMErrorBase + AppleWMClientNotLocal;
 
713
 
 
714
    /* only local clients are allowed WM access */
 
715
    switch (stuff->data)
 
716
    {
 
717
    case X_AppleWMQueryVersion:
 
718
        return SProcAppleWMQueryVersion(client);
 
719
    default:
 
720
        return BadRequest;
 
721
    }
 
722
}