1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Xplugin rootless implementation functions for AppleWM extension
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (c) 2002-2012 Apple Computer, Inc. All rights reserved.
5*4882a593Smuzhiyun * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
8*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
9*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
10*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
12*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
15*4882a593Smuzhiyun * all copies or substantial portions of the Software.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*4882a593Smuzhiyun * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Except as contained in this notice, the name(s) of the above copyright
26*4882a593Smuzhiyun * holders shall not be used in advertising or otherwise to promote the sale,
27*4882a593Smuzhiyun * use or other dealings in this Software without prior written authorization.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
31*4882a593Smuzhiyun #include <dix-config.h>
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include "xpr.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include <X11/extensions/applewmproto.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #include "applewmExt.h"
39*4882a593Smuzhiyun #include "rootless.h"
40*4882a593Smuzhiyun #include "rootlessCommon.h"
41*4882a593Smuzhiyun #include <Xplugin.h>
42*4882a593Smuzhiyun #include <X11/X.h>
43*4882a593Smuzhiyun #include "quartz.h"
44*4882a593Smuzhiyun #include "x-hash.h"
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun static int
xprSetWindowLevel(WindowPtr pWin,int level)47*4882a593Smuzhiyun xprSetWindowLevel(WindowPtr pWin, int level)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun xp_window_id wid;
50*4882a593Smuzhiyun xp_window_changes wc;
51*4882a593Smuzhiyun RootlessWindowRec *winRec;
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun // AppleWMNumWindowLevels is allowed, but is only set by the server
54*4882a593Smuzhiyun // for the root window.
55*4882a593Smuzhiyun if (level < 0 || level >= AppleWMNumWindowLevels) {
56*4882a593Smuzhiyun return BadValue;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, TRUE));
60*4882a593Smuzhiyun if (wid == 0)
61*4882a593Smuzhiyun return BadWindow;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun RootlessStopDrawing(pWin, FALSE);
64*4882a593Smuzhiyun winRec = WINREC(pWin);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun if (!winRec)
67*4882a593Smuzhiyun return BadWindow;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun if (XQuartzIsRootless)
70*4882a593Smuzhiyun wc.window_level = normal_window_levels[level];
71*4882a593Smuzhiyun else if (XQuartzShieldingWindowLevel)
72*4882a593Smuzhiyun wc.window_level = XQuartzShieldingWindowLevel + 1;
73*4882a593Smuzhiyun else
74*4882a593Smuzhiyun wc.window_level = rooted_window_levels[level];
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun if (xp_configure_window(wid, XP_WINDOW_LEVEL, &wc) != Success) {
77*4882a593Smuzhiyun return BadValue;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun winRec->level = level;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun return Success;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun static int
xprAttachTransient(WindowPtr pWinChild,WindowPtr pWinParent)86*4882a593Smuzhiyun xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun xp_window_id child_wid, parent_wid;
89*4882a593Smuzhiyun xp_window_changes wc;
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun child_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinChild, TRUE));
92*4882a593Smuzhiyun if (child_wid == 0)
93*4882a593Smuzhiyun return BadWindow;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun if (pWinParent) {
96*4882a593Smuzhiyun parent_wid =
97*4882a593Smuzhiyun x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE));
98*4882a593Smuzhiyun if (parent_wid == 0)
99*4882a593Smuzhiyun return BadWindow;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun else {
102*4882a593Smuzhiyun parent_wid = 0;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun wc.transient_for = parent_wid;
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun RootlessStopDrawing(pWinChild, FALSE);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT,
110*4882a593Smuzhiyun &wc) != Success) {
111*4882a593Smuzhiyun return BadValue;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun return Success;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun static int
xprFrameDraw(WindowPtr pWin,xp_frame_class class,xp_frame_attr attr,const BoxRec * outer,const BoxRec * inner,unsigned int title_len,const unsigned char * title_bytes)118*4882a593Smuzhiyun xprFrameDraw(WindowPtr pWin,
119*4882a593Smuzhiyun xp_frame_class class,
120*4882a593Smuzhiyun xp_frame_attr attr,
121*4882a593Smuzhiyun const BoxRec *outer,
122*4882a593Smuzhiyun const BoxRec *inner,
123*4882a593Smuzhiyun unsigned int title_len,
124*4882a593Smuzhiyun const unsigned char *title_bytes)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun xp_window_id wid;
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, FALSE));
129*4882a593Smuzhiyun if (wid == 0)
130*4882a593Smuzhiyun return BadWindow;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun if (xp_frame_draw(wid, class, attr, outer, inner,
133*4882a593Smuzhiyun title_len, title_bytes) != Success) {
134*4882a593Smuzhiyun return BadValue;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun return Success;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun static AppleWMProcsRec xprAppleWMProcs = {
141*4882a593Smuzhiyun xp_disable_update,
142*4882a593Smuzhiyun xp_reenable_update,
143*4882a593Smuzhiyun xprSetWindowLevel,
144*4882a593Smuzhiyun xp_frame_get_rect,
145*4882a593Smuzhiyun xp_frame_hit_test,
146*4882a593Smuzhiyun xprFrameDraw,
147*4882a593Smuzhiyun xp_set_dock_proxy,
148*4882a593Smuzhiyun xprAttachTransient
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun void
xprAppleWMInit(void)152*4882a593Smuzhiyun xprAppleWMInit(void)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun AppleWMExtensionInit(&xprAppleWMProcs);
155*4882a593Smuzhiyun }
156