xprAppleWM.c revision 4642e01f
1/*
2 * Xplugin rootless implementation functions for AppleWM extension
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 "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Except as contained in this notice, the name(s) of the above copyright
26 * holders shall not be used in advertising or otherwise to promote the sale,
27 * use or other dealings in this Software without prior written authorization.
28 */
29
30#ifdef HAVE_DIX_CONFIG_H
31#include <dix-config.h>
32#endif
33
34#include "xpr.h"
35
36#define _APPLEWM_SERVER_
37#include <X11/extensions/applewmstr.h>
38
39#include "applewmExt.h"
40#include "rootless.h"
41#include <Xplugin.h>
42#include <X11/X.h>
43#include "quartz.h"
44#include "x-hash.h"
45
46/* This lookup table came straight from the Tiger X11 source.  I tried to figure
47 * it out based on CGWindowLevel.h, but I dunno... -JH
48 */
49static const int normal_window_levels[AppleWMNumWindowLevels+1] = {
500, 3, 4, 5, INT_MIN + 30, INT_MIN + 29,
51};
52static const int rooted_window_levels[AppleWMNumWindowLevels+1] = {
53202, 203, 204, 205, 201, 200
54};
55
56static int xprSetWindowLevel(
57    WindowPtr pWin,
58    int level)
59{
60    xp_window_id wid;
61    xp_window_changes wc;
62
63    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, TRUE));
64    if (wid == 0)
65        return BadWindow;
66
67    RootlessStopDrawing (pWin, FALSE);
68
69    //if (WINREC(WindowTable[pWin->drawable.pScreen->myNum]) == NULL)
70    if (quartzHasRoot)
71        wc.window_level = normal_window_levels[level];
72    else
73        wc.window_level = rooted_window_levels[level];
74
75    if (xp_configure_window (wid, XP_WINDOW_LEVEL, &wc) != Success) {
76        return BadValue;
77    }
78
79    return Success;
80}
81
82
83static int xprFrameDraw(
84    WindowPtr pWin,
85    int class,
86    unsigned int attr,
87    const BoxRec *outer,
88    const BoxRec *inner,
89    unsigned int title_len,
90    const unsigned char *title_bytes)
91{
92    xp_window_id wid;
93
94    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, FALSE));
95    if (wid == 0)
96        return BadWindow;
97
98    if (xp_frame_draw (wid, class, attr, outer, inner,
99                       title_len, title_bytes) != Success)
100    {
101        return BadValue;
102    }
103
104    return Success;
105}
106
107
108static AppleWMProcsRec xprAppleWMProcs = {
109    xp_disable_update,
110    xp_reenable_update,
111    xprSetWindowLevel,
112    xp_frame_get_rect,
113    xp_frame_hit_test,
114    xprFrameDraw
115};
116
117
118void xprAppleWMInit(void)
119{
120    AppleWMExtensionInit(&xprAppleWMProcs);
121}
122