1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * Quartz-specific support for the Darwin X Server
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 2002-2012 Apple Inc. All rights reserved.
6*4882a593Smuzhiyun * Copyright (c) 2001-2004 Greg Parker and Torrey T. Lyons.
7*4882a593Smuzhiyun * All Rights Reserved.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
10*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
11*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
12*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
14*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
17*4882a593Smuzhiyun * all copies or substantial portions of the Software.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22*4882a593Smuzhiyun * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
23*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * Except as contained in this notice, the name(s) of the above copyright
28*4882a593Smuzhiyun * holders shall not be used in advertising or otherwise to promote the sale,
29*4882a593Smuzhiyun * use or other dealings in this Software without prior written authorization.
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "sanitizedCarbon.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
35*4882a593Smuzhiyun #include <dix-config.h>
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #include "quartzRandR.h"
39*4882a593Smuzhiyun #include "inputstr.h"
40*4882a593Smuzhiyun #include "quartz.h"
41*4882a593Smuzhiyun #include "darwin.h"
42*4882a593Smuzhiyun #include "darwinEvents.h"
43*4882a593Smuzhiyun #include "pseudoramiX.h"
44*4882a593Smuzhiyun #include "extension.h"
45*4882a593Smuzhiyun #include "nonsdk_extinit.h"
46*4882a593Smuzhiyun #include "glx_extinit.h"
47*4882a593Smuzhiyun #define _APPLEWM_SERVER_
48*4882a593Smuzhiyun #include "applewmExt.h"
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #include "X11Application.h"
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #include <X11/extensions/applewmconst.h>
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun // X headers
55*4882a593Smuzhiyun #include "scrnintstr.h"
56*4882a593Smuzhiyun #include "windowstr.h"
57*4882a593Smuzhiyun #include "colormapst.h"
58*4882a593Smuzhiyun #include "globals.h"
59*4882a593Smuzhiyun #include "mi.h"
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun // System headers
62*4882a593Smuzhiyun #include <stdlib.h>
63*4882a593Smuzhiyun #include <string.h>
64*4882a593Smuzhiyun #include <sys/types.h>
65*4882a593Smuzhiyun #include <sys/stat.h>
66*4882a593Smuzhiyun #include <fcntl.h>
67*4882a593Smuzhiyun #include <IOKit/pwr_mgt/IOPMLib.h>
68*4882a593Smuzhiyun #include <libkern/OSAtomic.h>
69*4882a593Smuzhiyun #include <signal.h>
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun #include <rootlessCommon.h>
72*4882a593Smuzhiyun #include <Xplugin.h>
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun // These are vended by the Objective-C runtime, but they are unfortunately
75*4882a593Smuzhiyun // not available as API in the macOS SDK. We are following suit with swift
76*4882a593Smuzhiyun // and clang in declaring them inline here. They canot be removed or changed
77*4882a593Smuzhiyun // in the OS without major bincompat ramifications.
78*4882a593Smuzhiyun //
79*4882a593Smuzhiyun // These were added in macOS 10.7.
80*4882a593Smuzhiyun void * _Nonnull objc_autoreleasePoolPush(void);
81*4882a593Smuzhiyun void objc_autoreleasePoolPop(void * _Nonnull context);
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun DevPrivateKeyRec quartzScreenKeyRec;
84*4882a593Smuzhiyun int aquaMenuBarHeight = 0;
85*4882a593Smuzhiyun QuartzModeProcsPtr quartzProcs = NULL;
86*4882a593Smuzhiyun const char *quartzOpenGLBundle = NULL;
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun Bool XQuartzFullscreenDisableHotkeys = TRUE;
89*4882a593Smuzhiyun Bool XQuartzOptionSendsAlt = FALSE;
90*4882a593Smuzhiyun Bool XQuartzEnableKeyEquivalents = TRUE;
91*4882a593Smuzhiyun Bool XQuartzFullscreenVisible = FALSE;
92*4882a593Smuzhiyun Bool XQuartzRootlessDefault = TRUE;
93*4882a593Smuzhiyun Bool XQuartzIsRootless = TRUE;
94*4882a593Smuzhiyun Bool XQuartzServerVisible = FALSE;
95*4882a593Smuzhiyun Bool XQuartzFullscreenMenu = FALSE;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun int32_t XQuartzShieldingWindowLevel = 0;
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun ===========================================================================
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun Screen functions
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun ===========================================================================
105*4882a593Smuzhiyun */
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /*
108*4882a593Smuzhiyun * QuartzAddScreen
109*4882a593Smuzhiyun * Do mode dependent initialization of each screen for Quartz.
110*4882a593Smuzhiyun */
111*4882a593Smuzhiyun Bool
QuartzAddScreen(int index,ScreenPtr pScreen)112*4882a593Smuzhiyun QuartzAddScreen(int index,
113*4882a593Smuzhiyun ScreenPtr pScreen)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun // The clang static analyzer thinks we leak displayInfo here
116*4882a593Smuzhiyun #ifndef __clang_analyzer__
117*4882a593Smuzhiyun // allocate space for private per screen Quartz specific storage
118*4882a593Smuzhiyun QuartzScreenPtr displayInfo = calloc(sizeof(QuartzScreenRec), 1);
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun // QUARTZ_PRIV(pScreen) = displayInfo;
121*4882a593Smuzhiyun dixSetPrivate(&pScreen->devPrivates, quartzScreenKey, displayInfo);
122*4882a593Smuzhiyun #endif /* __clang_analyzer__ */
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun // do Quartz mode specific initialization
125*4882a593Smuzhiyun return quartzProcs->AddScreen(index, pScreen);
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun /*
129*4882a593Smuzhiyun * QuartzSetupScreen
130*4882a593Smuzhiyun * Finalize mode specific setup of each screen.
131*4882a593Smuzhiyun */
132*4882a593Smuzhiyun Bool
QuartzSetupScreen(int index,ScreenPtr pScreen)133*4882a593Smuzhiyun QuartzSetupScreen(int index,
134*4882a593Smuzhiyun ScreenPtr pScreen)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun // do Quartz mode specific setup
137*4882a593Smuzhiyun if (!quartzProcs->SetupScreen(index, pScreen))
138*4882a593Smuzhiyun return FALSE;
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun // setup cursor support
141*4882a593Smuzhiyun if (!quartzProcs->InitCursor(pScreen))
142*4882a593Smuzhiyun return FALSE;
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun #if defined(RANDR)
145*4882a593Smuzhiyun if (!QuartzRandRInit(pScreen)) {
146*4882a593Smuzhiyun DEBUG_LOG("Failed to init RandR extension.\n");
147*4882a593Smuzhiyun return FALSE;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun #endif
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun return TRUE;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /*
155*4882a593Smuzhiyun * QuartzBlockHandler
156*4882a593Smuzhiyun * Clean out any autoreleased objects.
157*4882a593Smuzhiyun */
158*4882a593Smuzhiyun static void
QuartzBlockHandler(void * blockData,void * pTimeout)159*4882a593Smuzhiyun QuartzBlockHandler(void *blockData, void *pTimeout)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun static void *poolToken = NULL;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun if (poolToken) {
164*4882a593Smuzhiyun objc_autoreleasePoolPop(poolToken);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun poolToken = objc_autoreleasePoolPush();
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun * QuartzWakeupHandler
171*4882a593Smuzhiyun */
172*4882a593Smuzhiyun static void
QuartzWakeupHandler(void * blockData,int result)173*4882a593Smuzhiyun QuartzWakeupHandler(void *blockData, int result)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun /* nothing here */
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /*
179*4882a593Smuzhiyun * QuartzInitOutput
180*4882a593Smuzhiyun * Quartz display initialization.
181*4882a593Smuzhiyun */
182*4882a593Smuzhiyun void
QuartzInitOutput(int argc,char ** argv)183*4882a593Smuzhiyun QuartzInitOutput(int argc,
184*4882a593Smuzhiyun char **argv)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun /* For XQuartz, we want to just use the default signal handler to work better with CrashTracer */
187*4882a593Smuzhiyun signal(SIGSEGV, SIG_DFL);
188*4882a593Smuzhiyun signal(SIGABRT, SIG_DFL);
189*4882a593Smuzhiyun signal(SIGILL, SIG_DFL);
190*4882a593Smuzhiyun #ifdef SIGEMT
191*4882a593Smuzhiyun signal(SIGEMT, SIG_DFL);
192*4882a593Smuzhiyun #endif
193*4882a593Smuzhiyun signal(SIGFPE, SIG_DFL);
194*4882a593Smuzhiyun #ifdef SIGBUS
195*4882a593Smuzhiyun signal(SIGBUS, SIG_DFL);
196*4882a593Smuzhiyun #endif
197*4882a593Smuzhiyun #ifdef SIGSYS
198*4882a593Smuzhiyun signal(SIGSYS, SIG_DFL);
199*4882a593Smuzhiyun #endif
200*4882a593Smuzhiyun #ifdef SIGXCPU
201*4882a593Smuzhiyun signal(SIGXCPU, SIG_DFL);
202*4882a593Smuzhiyun #endif
203*4882a593Smuzhiyun #ifdef SIGXFSZ
204*4882a593Smuzhiyun signal(SIGXFSZ, SIG_DFL);
205*4882a593Smuzhiyun #endif
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun if (!RegisterBlockAndWakeupHandlers(QuartzBlockHandler,
208*4882a593Smuzhiyun QuartzWakeupHandler,
209*4882a593Smuzhiyun NULL)) {
210*4882a593Smuzhiyun FatalError("Could not register block and wakeup handlers.");
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun if (!dixRegisterPrivateKey(&quartzScreenKeyRec, PRIVATE_SCREEN, 0))
214*4882a593Smuzhiyun FatalError("Failed to alloc quartz screen private.\n");
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun // Do display mode specific initialization
217*4882a593Smuzhiyun quartzProcs->DisplayInit();
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun * QuartzInitInput
222*4882a593Smuzhiyun * Inform the main thread the X server is ready to handle events.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun void
QuartzInitInput(int argc,char ** argv)225*4882a593Smuzhiyun QuartzInitInput(int argc,
226*4882a593Smuzhiyun char **argv)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun X11ApplicationSetCanQuit(0);
229*4882a593Smuzhiyun X11ApplicationServerReady();
230*4882a593Smuzhiyun // Do final display mode specific initialization before handling events
231*4882a593Smuzhiyun if (quartzProcs->InitInput)
232*4882a593Smuzhiyun quartzProcs->InitInput(argc, argv);
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun void
QuartzUpdateScreens(void)236*4882a593Smuzhiyun QuartzUpdateScreens(void)
237*4882a593Smuzhiyun {
238*4882a593Smuzhiyun ScreenPtr pScreen;
239*4882a593Smuzhiyun WindowPtr pRoot;
240*4882a593Smuzhiyun int x, y, width, height, sx, sy;
241*4882a593Smuzhiyun xEvent e;
242*4882a593Smuzhiyun BoxRec bounds;
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun if (noPseudoramiXExtension || screenInfo.numScreens != 1) {
245*4882a593Smuzhiyun /* FIXME: if not using Xinerama, we have multiple screens, and
246*4882a593Smuzhiyun to do this properly may need to add or remove screens. Which
247*4882a593Smuzhiyun isn't possible. So don't do anything. Another reason why
248*4882a593Smuzhiyun we default to running with Xinerama. */
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun return;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun pScreen = screenInfo.screens[0];
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun PseudoramiXResetScreens();
256*4882a593Smuzhiyun quartzProcs->AddPseudoramiXScreens(&x, &y, &width, &height, pScreen);
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun pScreen->x = x;
259*4882a593Smuzhiyun pScreen->y = y;
260*4882a593Smuzhiyun pScreen->mmWidth = pScreen->mmWidth * ((double)width / pScreen->width);
261*4882a593Smuzhiyun pScreen->mmHeight = pScreen->mmHeight * ((double)height / pScreen->height);
262*4882a593Smuzhiyun pScreen->width = width;
263*4882a593Smuzhiyun pScreen->height = height;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun DarwinAdjustScreenOrigins(&screenInfo);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun /* DarwinAdjustScreenOrigins or UpdateScreen may change pScreen->x/y,
268*4882a593Smuzhiyun * so use it rather than x/y
269*4882a593Smuzhiyun */
270*4882a593Smuzhiyun sx = pScreen->x + darwinMainScreenX;
271*4882a593Smuzhiyun sy = pScreen->y + darwinMainScreenY;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun /* Adjust the root window. */
274*4882a593Smuzhiyun pRoot = pScreen->root;
275*4882a593Smuzhiyun AppleWMSetScreenOrigin(pRoot);
276*4882a593Smuzhiyun pScreen->ResizeWindow(pRoot, x - sx, y - sy, width, height, NULL);
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun /* <rdar://problem/7770779> pointer events are clipped to old display region after display reconfiguration
279*4882a593Smuzhiyun * http://xquartz.macosforge.org/trac/ticket/346
280*4882a593Smuzhiyun */
281*4882a593Smuzhiyun bounds.x1 = 0;
282*4882a593Smuzhiyun bounds.x2 = width;
283*4882a593Smuzhiyun bounds.y1 = 0;
284*4882a593Smuzhiyun bounds.y2 = height;
285*4882a593Smuzhiyun pScreen->ConstrainCursor(inputInfo.pointer, pScreen, &bounds);
286*4882a593Smuzhiyun inputInfo.pointer->spriteInfo->sprite->physLimits = bounds;
287*4882a593Smuzhiyun inputInfo.pointer->spriteInfo->sprite->hotLimits = bounds;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun DEBUG_LOG(
290*4882a593Smuzhiyun "Root Window: %dx%d @ (%d, %d) darwinMainScreen (%d, %d) xy (%d, %d) dixScreenOrigins (%d, %d)\n",
291*4882a593Smuzhiyun width, height, x - sx, y - sy, darwinMainScreenX, darwinMainScreenY,
292*4882a593Smuzhiyun x, y,
293*4882a593Smuzhiyun pScreen->x, pScreen->y);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun /* Send an event for the root reconfigure */
296*4882a593Smuzhiyun e.u.u.type = ConfigureNotify;
297*4882a593Smuzhiyun e.u.configureNotify.window = pRoot->drawable.id;
298*4882a593Smuzhiyun e.u.configureNotify.aboveSibling = None;
299*4882a593Smuzhiyun e.u.configureNotify.x = x - sx;
300*4882a593Smuzhiyun e.u.configureNotify.y = y - sy;
301*4882a593Smuzhiyun e.u.configureNotify.width = width;
302*4882a593Smuzhiyun e.u.configureNotify.height = height;
303*4882a593Smuzhiyun e.u.configureNotify.borderWidth = wBorderWidth(pRoot);
304*4882a593Smuzhiyun e.u.configureNotify.override = pRoot->overrideRedirect;
305*4882a593Smuzhiyun DeliverEvents(pRoot, &e, 1, NullWindow);
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun quartzProcs->UpdateScreen(pScreen);
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun /* PaintWindow needs to be called after RootlessUpdateScreenPixmap (from xprUpdateScreen) */
310*4882a593Smuzhiyun pScreen->PaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun /* Tell RandR about the new size, so new connections get the correct info */
313*4882a593Smuzhiyun RRScreenSizeNotify(pScreen);
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun static void
pokeActivityCallback(CFRunLoopTimerRef timer,void * info)317*4882a593Smuzhiyun pokeActivityCallback(CFRunLoopTimerRef timer, void *info)
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun UpdateSystemActivity(OverallAct);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun static void
QuartzScreenSaver(int state)323*4882a593Smuzhiyun QuartzScreenSaver(int state)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun static CFRunLoopTimerRef pokeActivityTimer = NULL;
326*4882a593Smuzhiyun static CFRunLoopTimerContext pokeActivityContext =
327*4882a593Smuzhiyun { 0, NULL, NULL, NULL, NULL };
328*4882a593Smuzhiyun static OSSpinLock pokeActivitySpinLock = OS_SPINLOCK_INIT;
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun OSSpinLockLock(&pokeActivitySpinLock);
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun if (state) {
333*4882a593Smuzhiyun if (pokeActivityTimer == NULL)
334*4882a593Smuzhiyun goto QuartzScreenSaverEnd;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun CFRunLoopTimerInvalidate(pokeActivityTimer);
337*4882a593Smuzhiyun CFRelease(pokeActivityTimer);
338*4882a593Smuzhiyun pokeActivityTimer = NULL;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun else {
341*4882a593Smuzhiyun if (pokeActivityTimer != NULL)
342*4882a593Smuzhiyun goto QuartzScreenSaverEnd;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun pokeActivityTimer = CFRunLoopTimerCreate(NULL,
345*4882a593Smuzhiyun CFAbsoluteTimeGetCurrent(),
346*4882a593Smuzhiyun 30, 0, 0,
347*4882a593Smuzhiyun pokeActivityCallback,
348*4882a593Smuzhiyun &pokeActivityContext);
349*4882a593Smuzhiyun if (pokeActivityTimer == NULL) {
350*4882a593Smuzhiyun ErrorF("Unable to create pokeActivityTimer.\n");
351*4882a593Smuzhiyun goto QuartzScreenSaverEnd;
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun CFRunLoopAddTimer(
355*4882a593Smuzhiyun CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes);
356*4882a593Smuzhiyun }
357*4882a593Smuzhiyun QuartzScreenSaverEnd:
358*4882a593Smuzhiyun OSSpinLockUnlock(&pokeActivitySpinLock);
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun void
QuartzShowFullscreen(int state)362*4882a593Smuzhiyun QuartzShowFullscreen(int state)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun int i;
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun DEBUG_LOG("QuartzShowFullscreen: state=%d\n", state);
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun if (XQuartzIsRootless) {
369*4882a593Smuzhiyun ErrorF("QuartzShowFullscreen called while in rootless mode.\n");
370*4882a593Smuzhiyun return;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun QuartzScreenSaver(!state);
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun if (XQuartzFullscreenVisible == state)
376*4882a593Smuzhiyun return;
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun XQuartzFullscreenVisible = state;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun xp_disable_update();
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun if (!XQuartzFullscreenVisible)
383*4882a593Smuzhiyun RootlessHideAllWindows();
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun RootlessUpdateRooted(XQuartzFullscreenVisible);
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun if (XQuartzFullscreenVisible) {
388*4882a593Smuzhiyun RootlessShowAllWindows();
389*4882a593Smuzhiyun for (i = 0; i < screenInfo.numScreens; i++) {
390*4882a593Smuzhiyun ScreenPtr pScreen = screenInfo.screens[i];
391*4882a593Smuzhiyun RootlessRepositionWindows(pScreen);
392*4882a593Smuzhiyun // JH: I don't think this is necessary, but keeping it here as a reminder
393*4882a593Smuzhiyun //RootlessUpdateScreenPixmap(pScreen);
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun /* Somehow the menubar manages to interfere with our event stream
398*4882a593Smuzhiyun * in fullscreen mode, even though it's not visible.
399*4882a593Smuzhiyun */
400*4882a593Smuzhiyun X11ApplicationShowHideMenubar(!XQuartzFullscreenVisible);
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun xp_reenable_update();
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun if (XQuartzFullscreenDisableHotkeys)
405*4882a593Smuzhiyun xp_disable_hot_keys(XQuartzFullscreenVisible);
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun void
QuartzSetRootless(Bool state)409*4882a593Smuzhiyun QuartzSetRootless(Bool state)
410*4882a593Smuzhiyun {
411*4882a593Smuzhiyun DEBUG_LOG("QuartzSetRootless state=%d\n", state);
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun if (XQuartzIsRootless == state)
414*4882a593Smuzhiyun return;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun if (state)
417*4882a593Smuzhiyun QuartzShowFullscreen(FALSE);
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun XQuartzIsRootless = state;
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun xp_disable_update();
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun /* When in rootless, the menubar is not part of the screen, so we need to update our screens on toggle */
424*4882a593Smuzhiyun QuartzUpdateScreens();
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun if (XQuartzIsRootless) {
427*4882a593Smuzhiyun RootlessShowAllWindows();
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun else {
430*4882a593Smuzhiyun RootlessHideAllWindows();
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun X11ApplicationShowHideMenubar(TRUE);
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun xp_reenable_update();
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun xp_disable_hot_keys(FALSE);
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun /*
441*4882a593Smuzhiyun * QuartzShow
442*4882a593Smuzhiyun * Show the X server on screen. Does nothing if already shown.
443*4882a593Smuzhiyun * Calls mode specific screen resume to restore the X clip regions
444*4882a593Smuzhiyun * (if needed) and the X server cursor state.
445*4882a593Smuzhiyun */
446*4882a593Smuzhiyun void
QuartzShow(void)447*4882a593Smuzhiyun QuartzShow(void)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun int i;
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun if (XQuartzServerVisible)
452*4882a593Smuzhiyun return;
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun XQuartzServerVisible = TRUE;
455*4882a593Smuzhiyun for (i = 0; i < screenInfo.numScreens; i++) {
456*4882a593Smuzhiyun if (screenInfo.screens[i]) {
457*4882a593Smuzhiyun quartzProcs->ResumeScreen(screenInfo.screens[i]);
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun }
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun if (!XQuartzIsRootless)
462*4882a593Smuzhiyun QuartzShowFullscreen(TRUE);
463*4882a593Smuzhiyun }
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun /*
466*4882a593Smuzhiyun * QuartzHide
467*4882a593Smuzhiyun * Remove the X server display from the screen. Does nothing if already
468*4882a593Smuzhiyun * hidden. Calls mode specific screen suspend to set X clip regions to
469*4882a593Smuzhiyun * prevent drawing (if needed) and restore the Aqua cursor.
470*4882a593Smuzhiyun */
471*4882a593Smuzhiyun void
QuartzHide(void)472*4882a593Smuzhiyun QuartzHide(void)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun int i;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun if (XQuartzServerVisible) {
477*4882a593Smuzhiyun for (i = 0; i < screenInfo.numScreens; i++) {
478*4882a593Smuzhiyun if (screenInfo.screens[i]) {
479*4882a593Smuzhiyun quartzProcs->SuspendScreen(screenInfo.screens[i]);
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun if (!XQuartzIsRootless)
485*4882a593Smuzhiyun QuartzShowFullscreen(FALSE);
486*4882a593Smuzhiyun XQuartzServerVisible = FALSE;
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun /*
490*4882a593Smuzhiyun * QuartzSetRootClip
491*4882a593Smuzhiyun * Enable or disable rendering to the X screen.
492*4882a593Smuzhiyun */
493*4882a593Smuzhiyun void
QuartzSetRootClip(int mode)494*4882a593Smuzhiyun QuartzSetRootClip(int mode)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun int i;
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun if (!XQuartzServerVisible)
499*4882a593Smuzhiyun return;
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun for (i = 0; i < screenInfo.numScreens; i++) {
502*4882a593Smuzhiyun if (screenInfo.screens[i]) {
503*4882a593Smuzhiyun SetRootClip(screenInfo.screens[i], mode);
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun }
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun /*
509*4882a593Smuzhiyun * QuartzSpaceChanged
510*4882a593Smuzhiyun * Unmap offscreen windows, map onscreen windows
511*4882a593Smuzhiyun */
512*4882a593Smuzhiyun void
QuartzSpaceChanged(uint32_t space_id)513*4882a593Smuzhiyun QuartzSpaceChanged(uint32_t space_id)
514*4882a593Smuzhiyun {
515*4882a593Smuzhiyun /* Do something special here, so we don't depend on quartz-wm for spaces to work... */
516*4882a593Smuzhiyun DEBUG_LOG("Space Changed (%u) ... do something interesting...\n",
517*4882a593Smuzhiyun space_id);
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun /*
521*4882a593Smuzhiyun * QuartzCopyDisplayIDs
522*4882a593Smuzhiyun * Associate an X11 screen with one or more CoreGraphics display IDs by copying
523*4882a593Smuzhiyun * the list into a private array. Free the previously copied array, if present.
524*4882a593Smuzhiyun */
525*4882a593Smuzhiyun void
QuartzCopyDisplayIDs(ScreenPtr pScreen,int displayCount,CGDirectDisplayID * displayIDs)526*4882a593Smuzhiyun QuartzCopyDisplayIDs(ScreenPtr pScreen,
527*4882a593Smuzhiyun int displayCount, CGDirectDisplayID *displayIDs)
528*4882a593Smuzhiyun {
529*4882a593Smuzhiyun QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun free(pQuartzScreen->displayIDs);
532*4882a593Smuzhiyun if (displayCount) {
533*4882a593Smuzhiyun size_t size = displayCount * sizeof(CGDirectDisplayID);
534*4882a593Smuzhiyun pQuartzScreen->displayIDs = malloc(size);
535*4882a593Smuzhiyun memcpy(pQuartzScreen->displayIDs, displayIDs, size);
536*4882a593Smuzhiyun }
537*4882a593Smuzhiyun else {
538*4882a593Smuzhiyun pQuartzScreen->displayIDs = NULL;
539*4882a593Smuzhiyun }
540*4882a593Smuzhiyun pQuartzScreen->displayCount = displayCount;
541*4882a593Smuzhiyun }
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun void
544*4882a593Smuzhiyun NSBeep(void);
545*4882a593Smuzhiyun void
DDXRingBell(int volume,int pitch,int duration)546*4882a593Smuzhiyun DDXRingBell(int volume, // volume is % of max
547*4882a593Smuzhiyun int pitch, // pitch is Hz
548*4882a593Smuzhiyun int duration) // duration is milliseconds
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun if (volume)
551*4882a593Smuzhiyun NSBeep();
552*4882a593Smuzhiyun }
553