2
* Xplugin rootless implementation screen functions
4
* Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
5
* Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
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:
14
* The above copyright notice and this permission notice shall be included in
15
* all copies or substantial portions of the Software.
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.
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.
30
#include "sanitizedCarbon.h"
32
#ifdef HAVE_DIX_CONFIG_H
33
#include <dix-config.h>
36
#include "quartzCommon.h"
41
#include "pseudoramiX.h"
43
#include "darwinEvents.h"
48
#include "applewmExt.h"
51
#include "rootlessCommon.h"
57
/* 10.4's deferred update makes X slower.. have to live with the tearing
59
#define XP_NO_DEFERRED_UPDATES 8
61
// Name of GLX bundle for native OpenGL
62
static const char *xprOpenGLBundle = "glxCGL.bundle";
66
* Callback handler for Xplugin events.
68
static void eventHandler(unsigned int type, const void *arg,
69
unsigned int arg_size, void *data) {
72
case XP_EVENT_DISPLAY_CHANGED:
73
DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
74
DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
77
case XP_EVENT_WINDOW_STATE_CHANGED:
78
if (arg_size >= sizeof(xp_window_state_event)) {
79
const xp_window_state_event *ws_arg = arg;
81
DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
82
DarwinSendDDXEvent(kXquartzWindowState, 2,
83
ws_arg->id, ws_arg->state);
85
DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
89
case XP_EVENT_WINDOW_MOVED:
90
DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
91
if (arg_size == sizeof(xp_window_id)) {
92
xp_window_id id = * (xp_window_id *) arg;
93
DarwinSendDDXEvent(kXquartzWindowMoved, 1, id);
97
case XP_EVENT_SURFACE_DESTROYED:
98
DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
99
case XP_EVENT_SURFACE_CHANGED:
100
DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
101
if (arg_size == sizeof(xp_surface_id)) {
104
if (type == XP_EVENT_SURFACE_DESTROYED)
105
kind = AppleDRISurfaceNotifyDestroyed;
107
kind = AppleDRISurfaceNotifyChanged;
109
DRISurfaceNotify(*(xp_surface_id *) arg, kind);
112
#ifdef XP_EVENT_SPACE_CHANGED
113
case XP_EVENT_SPACE_CHANGED:
114
DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n");
115
if(arg_size == sizeof(uint32_t)) {
116
uint32_t space_id = *(uint32_t *)arg;
117
DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
122
ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
128
* Return the display ID for a particular display index.
130
static CGDirectDisplayID
131
displayAtIndex(int index)
135
CGDirectDisplayID dpy[index+1];
137
err = CGGetActiveDisplayList(index + 1, dpy, &cnt);
138
if (err == kCGErrorSuccess && cnt == index + 1)
141
return kCGNullDirectDisplay;
145
* displayScreenBounds
146
* Return the bounds of a particular display.
149
displayScreenBounds(CGDirectDisplayID id)
153
frame = CGDisplayBounds(id);
155
DEBUG_LOG(" %dx%d @ (%d,%d).\n",
156
(int)frame.size.width, (int)frame.size.height,
157
(int)frame.origin.x, (int)frame.origin.y);
159
/* Remove menubar to help standard X11 window managers. */
160
if (quartzEnableRootless &&
161
frame.origin.x == 0 && frame.origin.y == 0) {
162
frame.origin.y += aquaMenuBarHeight;
163
frame.size.height -= aquaMenuBarHeight;
166
DEBUG_LOG(" %dx%d @ (%d,%d).\n",
167
(int)frame.size.width, (int)frame.size.height,
168
(int)frame.origin.x, (int)frame.origin.y);
174
* xprAddPseudoramiXScreens
175
* Add a single virtual screen encompassing all the physical screens
179
xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
181
CGDisplayCount i, displayCount;
182
CGDirectDisplayID *displayList = NULL;
183
CGRect unionRect = CGRectNull, frame;
185
// Find all the CoreGraphics displays
186
CGGetActiveDisplayList(0, NULL, &displayCount);
187
DEBUG_LOG("displayCount: %d\n", (int)displayCount);
190
ErrorF("CoreGraphics has reported no connected displays. Creating a stub 800x600 display.\n");
194
PseudoramiXAddScreen(*x, *y, *width, *height);
198
displayList = xalloc(displayCount * sizeof(CGDirectDisplayID));
200
FatalError("Unable to allocate memory for list of displays.\n");
201
CGGetActiveDisplayList(displayCount, displayList, &displayCount);
203
/* Get the union of all screens */
204
for (i = 0; i < displayCount; i++) {
205
CGDirectDisplayID dpy = displayList[i];
206
frame = displayScreenBounds(dpy);
207
unionRect = CGRectUnion(unionRect, frame);
210
/* Use unionRect as the screen size for the X server. */
211
*x = unionRect.origin.x;
212
*y = unionRect.origin.y;
213
*width = unionRect.size.width;
214
*height = unionRect.size.height;
216
DEBUG_LOG(" screen union origin: (%d,%d) size: (%d,%d).\n",
217
*x, *y, *width, *height);
219
/* Tell PseudoramiX about the real screens. */
220
for (i = 0; i < displayCount; i++)
222
CGDirectDisplayID dpy = displayList[i];
224
frame = displayScreenBounds(dpy);
225
frame.origin.x -= unionRect.origin.x;
226
frame.origin.y -= unionRect.origin.y;
228
DEBUG_LOG(" placed at X11 coordinate (%d,%d).\n",
229
(int)frame.origin.x, (int)frame.origin.y);
231
PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
232
frame.size.width, frame.size.height);
240
* Find number of CoreGraphics displays and initialize Xplugin.
245
CGDisplayCount displayCount;
249
CGGetActiveDisplayList(0, NULL, &displayCount);
251
/* With PseudoramiX, the X server only sees one screen; only PseudoramiX
252
itself knows about all of the screens. */
254
if (noPseudoramiXExtension)
255
darwinScreensFound = displayCount;
257
darwinScreensFound = 1;
259
if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success)
260
FatalError("Could not initialize the Xplugin library.");
262
xp_select_events(XP_EVENT_DISPLAY_CHANGED
263
| XP_EVENT_WINDOW_STATE_CHANGED
264
| XP_EVENT_WINDOW_MOVED
265
#ifdef XP_EVENT_SPACE_CHANGED
266
| XP_EVENT_SPACE_CHANGED
268
| XP_EVENT_SURFACE_CHANGED
269
| XP_EVENT_SURFACE_DESTROYED,
272
AppleDRIExtensionInit();
275
if (!quartzEnableRootless)
276
RootlessHideAllWindows();
281
* Init the framebuffer and record pixmap parameters for the screen.
284
xprAddScreen(int index, ScreenPtr pScreen)
286
DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
287
int depth = darwinDesiredDepth;
289
DEBUG_LOG("index=%d depth=%d\n", index, depth);
292
depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
296
case 8: // pseudo-working
297
dfb->visuals = PseudoColorMask;
298
dfb->preferredCVC = PseudoColor;
301
dfb->bitsPerPixel = 8;
307
dfb->visuals = TrueColorMask; //LARGE_VISUALS;
308
dfb->preferredCVC = TrueColor;
311
dfb->bitsPerPixel = 16;
312
dfb->redMask = RM_ARGB(0,5,5,5);
313
dfb->greenMask = GM_ARGB(0,5,5,5);
314
dfb->blueMask = BM_ARGB(0,5,5,5);
319
ErrorF("Unsupported color depth requested. Defaulting to 24bit. (depth=%d darwinDesiredDepth=%d CGDisplaySamplesPerPixel=%d CGDisplayBitsPerSample=%d)\n", darwinDesiredDepth, depth, (int)CGDisplaySamplesPerPixel(kCGDirectMainDisplay), (int)CGDisplayBitsPerSample(kCGDirectMainDisplay));
320
dfb->visuals = TrueColorMask; //LARGE_VISUALS;
321
dfb->preferredCVC = TrueColor;
324
dfb->bitsPerPixel = 32;
325
dfb->redMask = RM_ARGB(0,8,8,8);
326
dfb->greenMask = GM_ARGB(0,8,8,8);
327
dfb->blueMask = BM_ARGB(0,8,8,8);
331
if (noPseudoramiXExtension)
333
CGDirectDisplayID dpy;
336
ErrorF("Warning: noPseudoramiXExtension!\n");
338
dpy = displayAtIndex(index);
340
frame = displayScreenBounds(dpy);
342
dfb->x = frame.origin.x;
343
dfb->y = frame.origin.y;
344
dfb->width = frame.size.width;
345
dfb->height = frame.size.height;
349
xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height);
352
/* Passing zero width (pitch) makes miCreateScreenResources set the
353
screen pixmap to the framebuffer pointer, i.e. NULL. The generic
354
rootless code takes care of making this work. */
356
dfb->framebuffer = NULL;
358
DRIScreenInit(pScreen);
365
* Setup the screen for rootless access.
368
xprSetupScreen(int index, ScreenPtr pScreen)
370
// Initialize accelerated rootless drawing
371
// Note that this must be done before DamageSetup().
373
// These are crashing ugly... better to be stable and not crash for now.
374
//RootlessAccelInit(pScreen);
377
// The Damage extension needs to wrap underneath the
378
// generic rootless layer, so do it now.
379
if (!DamageSetup(pScreen))
383
// Initialize generic rootless code
384
if (!xprInit(pScreen))
387
return DRIFinishScreenInit(pScreen);
392
* Update screen after configuation change.
395
xprUpdateScreen(ScreenPtr pScreen)
397
rootlessGlobalOffsetX = darwinMainScreenX;
398
rootlessGlobalOffsetY = darwinMainScreenY;
400
AppleWMSetScreenOrigin(WindowTable[pScreen->myNum]);
402
RootlessRepositionWindows(pScreen);
403
RootlessUpdateScreenPixmap(pScreen);
408
* Finalize xpr specific setup.
411
xprInitInput(int argc, char **argv)
415
rootlessGlobalOffsetX = darwinMainScreenX;
416
rootlessGlobalOffsetY = darwinMainScreenY;
418
for (i = 0; i < screenInfo.numScreens; i++)
419
AppleWMSetScreenOrigin(WindowTable[i]);
423
* Quartz display mode function list.
425
static QuartzModeProcsRec xprModeProcs = {
431
QuartzSuspendXCursor,
433
xprAddPseudoramiXScreens,
437
RootlessFrameForWindow,
444
* QuartzModeBundleInit
445
* Initialize the display mode bundle after loading.
448
QuartzModeBundleInit(void)
450
quartzProcs = &xprModeProcs;
451
quartzOpenGLBundle = xprOpenGLBundle;