xprAppleWM.c revision 6747b715
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
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    winRec->level = level;
80
81    return Success;
82}
83
84#if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 3
85static int xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) {
86    xp_window_id child_wid, parent_wid;
87    xp_window_changes wc;
88
89    child_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinChild, TRUE));
90    if (child_wid == 0)
91        return BadWindow;
92
93    if(pWinParent) {
94        parent_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE));
95        if (parent_wid == 0)
96            return BadWindow;
97    } else {
98        parent_wid = 0;
99    }
100
101    wc.transient_for = parent_wid;
102
103    RootlessStopDrawing (pWinChild, FALSE);
104
105    if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT, &wc) != Success) {
106        return BadValue;
107    }
108
109    return Success;
110}
111#endif
112
113static int xprFrameDraw(
114    WindowPtr pWin,
115    int class,
116    unsigned int attr,
117    const BoxRec *outer,
118    const BoxRec *inner,
119    unsigned int title_len,
120    const unsigned char *title_bytes)
121{
122    xp_window_id wid;
123
124    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, FALSE));
125    if (wid == 0)
126        return BadWindow;
127
128    if (xp_frame_draw (wid, class, attr, outer, inner,
129                       title_len, title_bytes) != Success)
130    {
131        return BadValue;
132    }
133
134    return Success;
135}
136
137static AppleWMProcsRec xprAppleWMProcs = {
138    xp_disable_update,
139    xp_reenable_update,
140    xprSetWindowLevel,
141    xp_frame_get_rect,
142    xp_frame_hit_test,
143    xprFrameDraw,
144#if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 3
145    xp_set_dock_proxy,
146    xprAttachTransient
147#elif defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 2
148    xp_set_dock_proxy,
149    NULL
150#else
151    NULL,
152    NULL
153#endif
154};
155
156
157void xprAppleWMInit(void)
158{
159    AppleWMExtensionInit(&xprAppleWMProcs);
160}
161