14642e01fSmrg/* 24642e01fSmrg * Xplugin rootless implementation functions for AppleWM extension 34642e01fSmrg * 435c4bbdfSmrg * Copyright (c) 2002-2012 Apple Computer, Inc. All rights reserved. 54642e01fSmrg * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved. 64642e01fSmrg * 74642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 84642e01fSmrg * copy of this software and associated documentation files (the "Software"), 94642e01fSmrg * to deal in the Software without restriction, including without limitation 104642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 114642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the 124642e01fSmrg * Software is furnished to do so, subject to the following conditions: 134642e01fSmrg * 144642e01fSmrg * The above copyright notice and this permission notice shall be included in 154642e01fSmrg * all copies or substantial portions of the Software. 164642e01fSmrg * 174642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 184642e01fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 194642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 204642e01fSmrg * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 214642e01fSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 224642e01fSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 234642e01fSmrg * DEALINGS IN THE SOFTWARE. 244642e01fSmrg * 254642e01fSmrg * Except as contained in this notice, the name(s) of the above copyright 264642e01fSmrg * holders shall not be used in advertising or otherwise to promote the sale, 274642e01fSmrg * use or other dealings in this Software without prior written authorization. 284642e01fSmrg */ 294642e01fSmrg 304642e01fSmrg#ifdef HAVE_DIX_CONFIG_H 314642e01fSmrg#include <dix-config.h> 324642e01fSmrg#endif 334642e01fSmrg 344642e01fSmrg#include "xpr.h" 354642e01fSmrg 366747b715Smrg#include <X11/extensions/applewmproto.h> 374642e01fSmrg 384642e01fSmrg#include "applewmExt.h" 394642e01fSmrg#include "rootless.h" 406747b715Smrg#include "rootlessCommon.h" 414642e01fSmrg#include <Xplugin.h> 424642e01fSmrg#include <X11/X.h> 434642e01fSmrg#include "quartz.h" 444642e01fSmrg#include "x-hash.h" 454642e01fSmrg 4635c4bbdfSmrgstatic int 4735c4bbdfSmrgxprSetWindowLevel(WindowPtr pWin, int level) 484642e01fSmrg{ 494642e01fSmrg xp_window_id wid; 504642e01fSmrg xp_window_changes wc; 516747b715Smrg RootlessWindowRec *winRec; 524642e01fSmrg 536747b715Smrg // AppleWMNumWindowLevels is allowed, but is only set by the server 546747b715Smrg // for the root window. 556747b715Smrg if (level < 0 || level >= AppleWMNumWindowLevels) { 566747b715Smrg return BadValue; 576747b715Smrg } 5835c4bbdfSmrg 5935c4bbdfSmrg wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, TRUE)); 604642e01fSmrg if (wid == 0) 614642e01fSmrg return BadWindow; 624642e01fSmrg 6335c4bbdfSmrg RootlessStopDrawing(pWin, FALSE); 646747b715Smrg winRec = WINREC(pWin); 6535c4bbdfSmrg 6635c4bbdfSmrg if (!winRec) 676747b715Smrg return BadWindow; 6835c4bbdfSmrg 6935c4bbdfSmrg if (XQuartzIsRootless) 704642e01fSmrg wc.window_level = normal_window_levels[level]; 7135c4bbdfSmrg else if (XQuartzShieldingWindowLevel) 728223e2f2Smrg wc.window_level = XQuartzShieldingWindowLevel + 1; 734642e01fSmrg else 744642e01fSmrg wc.window_level = rooted_window_levels[level]; 7535c4bbdfSmrg 7635c4bbdfSmrg if (xp_configure_window(wid, XP_WINDOW_LEVEL, &wc) != Success) { 774642e01fSmrg return BadValue; 784642e01fSmrg } 794642e01fSmrg 806747b715Smrg winRec->level = level; 816747b715Smrg 824642e01fSmrg return Success; 834642e01fSmrg} 844642e01fSmrg 8535c4bbdfSmrgstatic int 8635c4bbdfSmrgxprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) 8735c4bbdfSmrg{ 8835c4bbdfSmrg xp_window_id child_wid, parent_wid; 896747b715Smrg xp_window_changes wc; 906747b715Smrg 916747b715Smrg child_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinChild, TRUE)); 926747b715Smrg if (child_wid == 0) 936747b715Smrg return BadWindow; 946747b715Smrg 9535c4bbdfSmrg if (pWinParent) { 9635c4bbdfSmrg parent_wid = 9735c4bbdfSmrg x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE)); 986747b715Smrg if (parent_wid == 0) 996747b715Smrg return BadWindow; 10035c4bbdfSmrg } 10135c4bbdfSmrg else { 1026747b715Smrg parent_wid = 0; 1036747b715Smrg } 10435c4bbdfSmrg 1056747b715Smrg wc.transient_for = parent_wid; 1066747b715Smrg 10735c4bbdfSmrg RootlessStopDrawing(pWinChild, FALSE); 1086747b715Smrg 10935c4bbdfSmrg if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT, 11035c4bbdfSmrg &wc) != Success) { 1116747b715Smrg return BadValue; 1126747b715Smrg } 1136747b715Smrg 11435c4bbdfSmrg return Success; 1156747b715Smrg} 1164642e01fSmrg 11735c4bbdfSmrgstatic int 11835c4bbdfSmrgxprFrameDraw(WindowPtr pWin, 11935c4bbdfSmrg xp_frame_class class, 12035c4bbdfSmrg xp_frame_attr attr, 12135c4bbdfSmrg const BoxRec *outer, 12235c4bbdfSmrg const BoxRec *inner, 12335c4bbdfSmrg unsigned int title_len, 12435c4bbdfSmrg const unsigned char *title_bytes) 1254642e01fSmrg{ 1264642e01fSmrg xp_window_id wid; 1274642e01fSmrg 12835c4bbdfSmrg wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, FALSE)); 1294642e01fSmrg if (wid == 0) 1304642e01fSmrg return BadWindow; 1314642e01fSmrg 13235c4bbdfSmrg if (xp_frame_draw(wid, class, attr, outer, inner, 13335c4bbdfSmrg title_len, title_bytes) != Success) { 1344642e01fSmrg return BadValue; 1354642e01fSmrg } 1364642e01fSmrg 1374642e01fSmrg return Success; 1384642e01fSmrg} 1394642e01fSmrg 1404642e01fSmrgstatic AppleWMProcsRec xprAppleWMProcs = { 1414642e01fSmrg xp_disable_update, 1424642e01fSmrg xp_reenable_update, 1434642e01fSmrg xprSetWindowLevel, 1444642e01fSmrg xp_frame_get_rect, 1454642e01fSmrg xp_frame_hit_test, 1466747b715Smrg xprFrameDraw, 1476747b715Smrg xp_set_dock_proxy, 1486747b715Smrg xprAttachTransient 1494642e01fSmrg}; 1504642e01fSmrg 15135c4bbdfSmrgvoid 15235c4bbdfSmrgxprAppleWMInit(void) 1534642e01fSmrg{ 1544642e01fSmrg AppleWMExtensionInit(&xprAppleWMProcs); 1554642e01fSmrg} 156