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