xprAppleWM.c revision c8548ba8
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
85static int
86xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent)
87{
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 =
97            x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE));
98        if (parent_wid == 0)
99            return BadWindow;
100    }
101    else {
102        parent_wid = 0;
103    }
104
105    wc.transient_for = parent_wid;
106
107    RootlessStopDrawing(pWinChild, FALSE);
108
109    if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT,
110                            &wc) != Success) {
111        return BadValue;
112    }
113
114    return Success;
115}
116
117static int
118xprFrameDraw(WindowPtr pWin,
119             xp_frame_class class,
120             xp_frame_attr attr,
121             const BoxRec *outer,
122             const BoxRec *inner,
123             unsigned int title_len,
124             const unsigned char *title_bytes)
125{
126    xp_window_id wid;
127
128    wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, FALSE));
129    if (wid == 0)
130        return BadWindow;
131
132    if (xp_frame_draw(wid, class, attr, outer, inner,
133                      title_len, title_bytes) != Success) {
134        return BadValue;
135    }
136
137    return Success;
138}
139
140static AppleWMProcsRec xprAppleWMProcs = {
141    xp_disable_update,
142    xp_reenable_update,
143    xprSetWindowLevel,
144    xp_frame_get_rect,
145    xp_frame_hit_test,
146    xprFrameDraw,
147    xp_set_dock_proxy,
148    xprAttachTransient
149};
150
151void
152xprAppleWMInit(void)
153{
154    AppleWMExtensionInit(&xprAppleWMProcs);
155}
156