xprAppleWM.c revision 9ace9065
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#include <X11/extensions/applewmproto.h>
37
38#include "applewmExt.h"
39#include "rootless.h"
40#include "rootlessCommon.h"
41#include <Xplugin.h>
42#include <X11/X.h>
43#include "quartz.h"
44#include "x-hash.h"
45
46static int xprSetWindowLevel(
47    WindowPtr pWin,
48    int level)
49{
50    xp_window_id wid;
51    xp_window_changes wc;
52    RootlessWindowRec *winRec;
53
54    // AppleWMNumWindowLevels is allowed, but is only set by the server
55    // for the root window.
56    if (level < 0 || level >= AppleWMNumWindowLevels) {
57        return BadValue;
58    }
59
60    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, TRUE));
61    if (wid == 0)
62        return BadWindow;
63
64    RootlessStopDrawing (pWin, FALSE);
65    winRec = WINREC(pWin);
66
67    if(!winRec)
68        return BadWindow;
69
70    if(XQuartzIsRootless)
71        wc.window_level = normal_window_levels[level];
72    else if(XQuartzShieldingWindowLevel)
73        wc.window_level = XQuartzShieldingWindowLevel + 1;
74    else
75        wc.window_level = rooted_window_levels[level];
76
77    if (xp_configure_window (wid, XP_WINDOW_LEVEL, &wc) != Success) {
78        return BadValue;
79    }
80
81    winRec->level = level;
82
83    return Success;
84}
85
86#if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 3
87static int xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) {
88    xp_window_id child_wid, parent_wid;
89    xp_window_changes wc;
90
91    child_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinChild, TRUE));
92    if (child_wid == 0)
93        return BadWindow;
94
95    if(pWinParent) {
96        parent_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE));
97        if (parent_wid == 0)
98            return BadWindow;
99    } else {
100        parent_wid = 0;
101    }
102
103    wc.transient_for = parent_wid;
104
105    RootlessStopDrawing (pWinChild, FALSE);
106
107    if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT, &wc) != Success) {
108        return BadValue;
109    }
110
111    return Success;
112}
113#endif
114
115static int xprFrameDraw(
116    WindowPtr pWin,
117    xp_frame_class class,
118    xp_frame_attr attr,
119    const BoxRec *outer,
120    const BoxRec *inner,
121    unsigned int title_len,
122    const unsigned char *title_bytes)
123{
124    xp_window_id wid;
125
126    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, FALSE));
127    if (wid == 0)
128        return BadWindow;
129
130    if (xp_frame_draw (wid, class, attr, outer, inner,
131                       title_len, title_bytes) != Success)
132    {
133        return BadValue;
134    }
135
136    return Success;
137}
138
139static AppleWMProcsRec xprAppleWMProcs = {
140    xp_disable_update,
141    xp_reenable_update,
142    xprSetWindowLevel,
143    xp_frame_get_rect,
144    xp_frame_hit_test,
145    xprFrameDraw,
146#if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 3
147    xp_set_dock_proxy,
148    xprAttachTransient
149#elif defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 2
150    xp_set_dock_proxy,
151    NULL
152#else
153    NULL,
154    NULL
155#endif
156};
157
158
159void xprAppleWMInit(void)
160{
161    AppleWMExtensionInit(&xprAppleWMProcs);
162}
163