aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xquartz
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-01-31 17:39:18 +0000
committermarha <marha@users.sourceforge.net>2010-01-31 17:39:18 +0000
commit007385f704a99ab49dab0789f9c330a1a3a455be (patch)
tree2cf02fe423ea6090e6e7ddb10af9b35b47def4d8 /xorg-server/hw/xquartz
parent74e21f951a8a1c11445cab7accce2ace6c1acef5 (diff)
downloadvcxsrv-007385f704a99ab49dab0789f9c330a1a3a455be.tar.gz
vcxsrv-007385f704a99ab49dab0789f9c330a1a3a455be.tar.bz2
vcxsrv-007385f704a99ab49dab0789f9c330a1a3a455be.zip
git update 31-1-2010
Diffstat (limited to 'xorg-server/hw/xquartz')
-rw-r--r--xorg-server/hw/xquartz/darwin.c1855
-rw-r--r--xorg-server/hw/xquartz/darwin.h184
-rw-r--r--xorg-server/hw/xquartz/xpr/xprScreen.c893
3 files changed, 1452 insertions, 1480 deletions
diff --git a/xorg-server/hw/xquartz/darwin.c b/xorg-server/hw/xquartz/darwin.c
index 30b890589..fc8179394 100644
--- a/xorg-server/hw/xquartz/darwin.c
+++ b/xorg-server/hw/xquartz/darwin.c
@@ -1,947 +1,908 @@
-/**************************************************************
- *
- * Xquartz initialization code
- *
- * Copyright (c) 2007-2008 Apple Inc.
- * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "os.h"
-#include "servermd.h"
-#include "inputstr.h"
-#include "scrnintstr.h"
-#include "mibstore.h" // mi backing store implementation
-#include "mipointer.h" // mi software cursor
-#include "micmap.h" // mi colormap code
-#include "fb.h" // fb framebuffer code
-#include "site.h"
-#include "globals.h"
-#include "dix.h"
-
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XIproto.h>
-#include "exevents.h"
-#include "extinit.h"
-
-#include "xserver-properties.h"
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/syslimits.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#define HAS_UTSNAME 1
-#include <sys/utsname.h>
-
-#define NO_CFPLUGIN
-#include <IOKit/hidsystem/IOHIDLib.h>
-
-#ifdef MITSHM
-#include "shmint.h"
-#endif
-
-#include "darwin.h"
-#include "darwinEvents.h"
-#include "quartzKeyboard.h"
-#include "quartz.h"
-
-#ifdef ENABLE_DEBUG_LOG
-FILE *debug_log_fp = NULL;
-#endif
-
-/*
- * X server shared global variables
- */
-int darwinScreensFound = 0;
-static int darwinScreenKeyIndex;
-DevPrivateKey darwinScreenKey = &darwinScreenKeyIndex;
-io_connect_t darwinParamConnect = 0;
-int darwinEventReadFD = -1;
-int darwinEventWriteFD = -1;
-// int darwinMouseAccelChange = 1;
-int darwinFakeButtons = 0;
-
-// location of X11's (0,0) point in global screen coordinates
-int darwinMainScreenX = 0;
-int darwinMainScreenY = 0;
-
-// parameters read from the command line or user preferences
-unsigned int darwinDesiredWidth = 0, darwinDesiredHeight = 0;
-int darwinDesiredDepth = -1;
-int darwinDesiredRefresh = -1;
-int darwinSyncKeymap = FALSE;
-
-// modifier masks for faking mouse buttons - ANY of these bits trigger it (not all)
-#ifdef NX_DEVICELCMDKEYMASK
-int darwinFakeMouse2Mask = NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK;
-int darwinFakeMouse3Mask = NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK;
-#else
-int darwinFakeMouse2Mask = NX_ALTERNATEMASK;
-int darwinFakeMouse3Mask = NX_COMMANDMASK;
-#endif
-
-// Modifier mask for overriding event delivery to appkit (might be useful to set this to rcommand for input menu
-unsigned int darwinAppKitModMask = 0; // Any of these bits
-
-// Modifier mask for items in the Window menu (0 and -1 cause shortcuts to be disabled)
-unsigned int windowItemModMask = NX_COMMANDMASK;
-
-// devices
-DeviceIntPtr darwinKeyboard = NULL;
-DeviceIntPtr darwinPointer = NULL;
-DeviceIntPtr darwinTabletCurrent = NULL;
-DeviceIntPtr darwinTabletStylus = NULL;
-DeviceIntPtr darwinTabletCursor = NULL;
-DeviceIntPtr darwinTabletEraser = NULL;
-
-// Common pixmap formats
-static PixmapFormatRec formats[] = {
- { 1, 1, BITMAP_SCANLINE_PAD },
- { 4, 8, BITMAP_SCANLINE_PAD },
- { 8, 8, BITMAP_SCANLINE_PAD },
- { 15, 16, BITMAP_SCANLINE_PAD },
- { 16, 16, BITMAP_SCANLINE_PAD },
- { 24, 32, BITMAP_SCANLINE_PAD },
- { 32, 32, BITMAP_SCANLINE_PAD }
-};
-const int NUMFORMATS = sizeof(formats)/sizeof(formats[0]);
-
-#ifndef OSNAME
-#define OSNAME " Darwin"
-#endif
-#ifndef OSVENDOR
-#define OSVENDOR ""
-#endif
-#ifndef PRE_RELEASE
-#define PRE_RELEASE XORG_VERSION_SNAP
-#endif
-#ifndef BUILD_DATE
-#define BUILD_DATE ""
-#endif
-#ifndef XORG_RELEASE
-#define XORG_RELEASE "?"
-#endif
-
-void
-DarwinPrintBanner(void)
-{
- // this should change depending on which specific server we are building
- ErrorF("Xquartz starting:\n");
- ErrorF("X.Org X Server %s\nBuild Date: %s\n", XSERVER_VERSION, BUILD_DATE );
-}
-
-
-/*
- * DarwinSaveScreen
- * X screensaver support. Not implemented.
- */
-static Bool DarwinSaveScreen(ScreenPtr pScreen, int on)
-{
- // FIXME
- if (on == SCREEN_SAVER_FORCER) {
- } else if (on == SCREEN_SAVER_ON) {
- } else {
- }
- return TRUE;
-}
-
-/*
- * DarwinScreenInit
- * This is a callback from dix during AddScreen() from InitOutput().
- * Initialize the screen and communicate information about it back to dix.
- */
-static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv) {
- int dpi;
- static int foundIndex = 0;
- Bool ret;
- DarwinFramebufferPtr dfb;
-
- // reset index of found screens for each server generation
- if (index == 0) {
- foundIndex = 0;
-
- // reset the visual list
- miClearVisualTypes();
- }
-
- // allocate space for private per screen storage
- dfb = xalloc(sizeof(DarwinFramebufferRec));
-
- // SCREEN_PRIV(pScreen) = dfb;
- dixSetPrivate(&pScreen->devPrivates, darwinScreenKey, dfb);
-
- // setup hardware/mode specific details
- ret = QuartzAddScreen(foundIndex, pScreen);
- foundIndex++;
- if (! ret)
- return FALSE;
-
- // setup a single visual appropriate for our pixel type
- if(!miSetVisualTypesAndMasks(dfb->depth, dfb->visuals, dfb->bitsPerRGB,
- dfb->preferredCVC, dfb->redMask,
- dfb->greenMask, dfb->blueMask)) {
- return FALSE;
- }
-
-// TODO: Make PseudoColor visuals not suck in TrueColor mode
-// if(dfb->depth > 8)
-// miSetVisualTypesAndMasks(8, PseudoColorMask, 8, PseudoColor, 0, 0, 0);
- if(dfb->depth > 15)
- miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor, RM_ARGB(0,5,5,5), GM_ARGB(0,5,5,5), BM_ARGB(0,5,5,5));
- if(dfb->depth > 24)
- miSetVisualTypesAndMasks(24, TrueColorMask, 8, TrueColor, RM_ARGB(0,8,8,8), GM_ARGB(0,8,8,8), BM_ARGB(0,8,8,8));
-
- miSetPixmapDepths();
-
- // machine independent screen init
- // setup _Screen structure in pScreen
- if (monitorResolution)
- dpi = monitorResolution;
- else
- dpi = 96;
-
- // initialize fb
- if (! fbScreenInit(pScreen,
- dfb->framebuffer, // pointer to screen bitmap
- dfb->width, dfb->height, // screen size in pixels
- dpi, dpi, // dots per inch
- dfb->pitch/(dfb->bitsPerPixel/8), // pixel width of framebuffer
- dfb->bitsPerPixel)) // bits per pixel for screen
- {
- return FALSE;
- }
-
-#ifdef RENDER
- if (! fbPictureInit(pScreen, 0, 0)) {
- return FALSE;
- }
-#endif
-
-#ifdef MITSHM
- ShmRegisterFbFuncs(pScreen);
-#endif
-
- // this must be initialized (why doesn't X have a default?)
- pScreen->SaveScreen = DarwinSaveScreen;
-
- // finish mode dependent screen setup including cursor support
- if (!QuartzSetupScreen(index, pScreen)) {
- return FALSE;
- }
-
- // create and install the default colormap and
- // set pScreen->blackPixel / pScreen->white
- if (!miCreateDefColormap( pScreen )) {
- return FALSE;
- }
-
- dixScreenOrigins[index].x = dfb->x;
- dixScreenOrigins[index].y = dfb->y;
-
- /* ErrorF("Screen %d added: %dx%d @ (%d,%d)\n",
- index, dfb->width, dfb->height, dfb->x, dfb->y); */
-
- return TRUE;
-}
-
-/*
- =============================================================================
-
- mouse and keyboard callbacks
-
- =============================================================================
-*/
-
-/*
- * DarwinMouseProc: Handle the initialization, etc. of a mouse
- */
-static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
-#define NBUTTONS 7
-#define NAXES 2
- // 7 buttons: left, right, middle, then four scroll wheel "buttons"
- CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3, 4, 5, 6, 7};
- Atom btn_labels[NBUTTONS] = {0};
- Atom axes_labels[NAXES] = {0};
-
- switch (what) {
- case DEVICE_INIT:
- pPointer->public.on = FALSE;
-
- btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
- btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
- btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
- btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
- btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
- btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
- btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
-
- axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
- axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
-
-
- // Set button map.
- InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
- btn_labels,
- (PtrCtrlProcPtr)NoopDDA,
- GetMotionHistorySize(), NAXES,
- axes_labels);
- pPointer->valuator->mode = Absolute; // Relative
- InitAbsoluteClassDeviceStruct(pPointer);
-// InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-// InitValuatorAxisStruct(pPointer, 1, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
- break;
- case DEVICE_ON:
- pPointer->public.on = TRUE;
- AddEnabledDevice( darwinEventReadFD );
- return Success;
- case DEVICE_CLOSE:
- case DEVICE_OFF:
- pPointer->public.on = FALSE;
- RemoveEnabledDevice(darwinEventReadFD);
- return Success;
- }
-
- return Success;
-#undef NBUTTONS
-#undef NAXES
-}
-
-static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
-#define NBUTTONS 3
-#define NAXES 5
- CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3};
- Atom btn_labels[NBUTTONS] = {0};
- Atom axes_labels[NAXES] = {0};
-
- switch (what) {
- case DEVICE_INIT:
- pPointer->public.on = FALSE;
-
- btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
- btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
- btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
-
- axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
- axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
- axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
- axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X);
- axes_labels[4] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y);
-
- // Set button map.
- InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
- btn_labels,
- (PtrCtrlProcPtr)NoopDDA,
- GetMotionHistorySize(), NAXES,
- axes_labels);
- pPointer->valuator->mode = Absolute; // Relative
- InitProximityClassDeviceStruct(pPointer);
- InitAbsoluteClassDeviceStruct(pPointer);
-
- InitValuatorAxisStruct(pPointer, 0, axes_labels[0], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
- InitValuatorAxisStruct(pPointer, 1, axes_labels[1], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
- InitValuatorAxisStruct(pPointer, 2, axes_labels[2], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
- InitValuatorAxisStruct(pPointer, 3, axes_labels[3], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
- InitValuatorAxisStruct(pPointer, 4, axes_labels[4], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-// pPointer->use = IsXExtensionDevice;
- break;
- case DEVICE_ON:
- pPointer->public.on = TRUE;
- AddEnabledDevice( darwinEventReadFD );
- return Success;
- case DEVICE_CLOSE:
- case DEVICE_OFF:
- pPointer->public.on = FALSE;
- RemoveEnabledDevice(darwinEventReadFD);
- return Success;
- }
- return Success;
-#undef NBUTTONS
-#undef NAXES
-}
-
-/*
- * DarwinKeybdProc
- * Callback from X
- */
-static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff )
-{
- switch ( onoff ) {
- case DEVICE_INIT:
- DarwinKeyboardInit( pDev );
- break;
- case DEVICE_ON:
- pDev->public.on = TRUE;
- AddEnabledDevice( darwinEventReadFD );
- break;
- case DEVICE_OFF:
- pDev->public.on = FALSE;
- RemoveEnabledDevice( darwinEventReadFD );
- break;
- case DEVICE_CLOSE:
- break;
- }
-
- return Success;
-}
-
-/*
-===========================================================================
-
- Utility routines
-
-===========================================================================
-*/
-
-/*
- * DarwinParseModifierList
- * Parse a list of modifier names and return a corresponding modifier mask
- */
-int DarwinParseModifierList(const char *constmodifiers, int separatelr)
-{
- int result = 0;
-
- if (constmodifiers) {
- char *modifiers = strdup(constmodifiers);
- char *modifier;
- int nxkey;
- char *p = modifiers;
-
- while (p) {
- modifier = strsep(&p, " ,+&|/"); // allow lots of separators
- nxkey = DarwinModifierStringToNXMask(modifier, separatelr);
- if(nxkey)
- result |= nxkey;
- else
- ErrorF("fakebuttons: Unknown modifier \"%s\"\n", modifier);
- }
- free(modifiers);
- }
- return result;
-}
-
-/*
-===========================================================================
-
- Functions needed to link against device independent X
-
-===========================================================================
-*/
-
-/*
- * InitInput
- * Register the keyboard and mouse devices
- */
-void InitInput( int argc, char **argv )
-{
- darwinKeyboard = AddInputDevice(serverClient, DarwinKeybdProc, TRUE);
- RegisterKeyboardDevice( darwinKeyboard );
- darwinKeyboard->name = strdup("keyboard");
-
- /* here's the snippet from the current gdk sources:
- if (!strcmp (tmp_name, "pointer"))
- gdkdev->info.source = GDK_SOURCE_MOUSE;
- else if (!strcmp (tmp_name, "wacom") ||
- !strcmp (tmp_name, "pen"))
- gdkdev->info.source = GDK_SOURCE_PEN;
- else if (!strcmp (tmp_name, "eraser"))
- gdkdev->info.source = GDK_SOURCE_ERASER;
- else if (!strcmp (tmp_name, "cursor"))
- gdkdev->info.source = GDK_SOURCE_CURSOR;
- else
- gdkdev->info.source = GDK_SOURCE_PEN;
- */
-
- darwinPointer = AddInputDevice(serverClient, DarwinMouseProc, TRUE);
- RegisterPointerDevice( darwinPointer );
- darwinPointer->name = strdup("pointer");
-
- darwinTabletStylus = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
- RegisterPointerDevice( darwinTabletStylus );
- darwinTabletStylus->name = strdup("pen");
-
- darwinTabletCursor = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
- RegisterPointerDevice( darwinTabletCursor );
- darwinTabletCursor->name = strdup("cursor");
-
- darwinTabletEraser = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
- RegisterPointerDevice( darwinTabletEraser );
- darwinTabletEraser->name = strdup("eraser");
-
- darwinTabletCurrent = darwinTabletStylus;
-
- DarwinEQInit();
-
- QuartzInitInput(argc, argv);
-}
-
-
-/*
- * DarwinAdjustScreenOrigins
- * Shift all screens so the X11 (0, 0) coordinate is at the top
- * left of the global screen coordinates.
- *
- * Screens can be arranged so the top left isn't on any screen, so
- * instead use the top left of the leftmost screen as (0,0). This
- * may mean some screen space is in -y, but it's better that (0,0)
- * be onscreen, or else default xterms disappear. It's better that
- * -y be used than -x, because when popup menus are forced
- * "onscreen" by dumb window managers like twm, they'll shift the
- * menus down instead of left, which still looks funny but is an
- * easier target to hit.
- */
-void
-DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
-{
- int i, left, top;
-
- left = dixScreenOrigins[0].x;
- top = dixScreenOrigins[0].y;
-
- /* Find leftmost screen. If there's a tie, take the topmost of the two. */
- for (i = 1; i < pScreenInfo->numScreens; i++) {
- if (dixScreenOrigins[i].x < left ||
- (dixScreenOrigins[i].x == left && dixScreenOrigins[i].y < top))
- {
- left = dixScreenOrigins[i].x;
- top = dixScreenOrigins[i].y;
- }
- }
-
- darwinMainScreenX = left;
- darwinMainScreenY = top;
-
- DEBUG_LOG("top = %d, left=%d\n", top, left);
-
- /* Shift all screens so that there is a screen whose top left
- * is at X11 (0,0) and at global screen coordinate
- * (darwinMainScreenX, darwinMainScreenY).
- */
-
- if (darwinMainScreenX != 0 || darwinMainScreenY != 0) {
- for (i = 0; i < pScreenInfo->numScreens; i++) {
- dixScreenOrigins[i].x -= darwinMainScreenX;
- dixScreenOrigins[i].y -= darwinMainScreenY;
- DEBUG_LOG("Screen %d placed at X11 coordinate (%d,%d).\n",
- i, dixScreenOrigins[i].x, dixScreenOrigins[i].y);
- }
- }
-}
-
-
-/*
- * InitOutput
- * Initialize screenInfo for all actually accessible framebuffers.
- *
- * The display mode dependent code gets called three times. The mode
- * specific InitOutput routines are expected to discover the number
- * of potentially useful screens and cache routes to them internally.
- * Inside DarwinScreenInit are two other mode specific calls.
- * A mode specific AddScreen routine is called for each screen to
- * actually initialize the screen with the ScreenPtr structure.
- * After other screen setup has been done, a mode specific
- * SetupScreen function can be called to finalize screen setup.
- */
-void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv )
-{
- int i;
-
- pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
- pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
- pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
- pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
-
- // List how we want common pixmap formats to be padded
- pScreenInfo->numPixmapFormats = NUMFORMATS;
- for (i = 0; i < NUMFORMATS; i++)
- pScreenInfo->formats[i] = formats[i];
-
- // Discover screens and do mode specific initialization
- QuartzInitOutput(argc, argv);
-
- // Add screens
- for (i = 0; i < darwinScreensFound; i++) {
- AddScreen(DarwinScreenInit, argc, argv);
- }
-
- DarwinAdjustScreenOrigins(pScreenInfo);
-}
-
-
-/*
- * OsVendorFataError
- */
-void OsVendorFatalError( void )
-{
- ErrorF( " OsVendorFatalError\n" );
-}
-
-
-/*
- * OsVendorInit
- * Initialization of Darwin OS support.
- */
-void OsVendorInit(void)
-{
- if (serverGeneration == 1) {
- DarwinPrintBanner();
-#ifdef ENABLE_DEBUG_LOG
- {
- char *home_dir=NULL, *log_file_path=NULL;
- home_dir = getenv("HOME");
- if (home_dir) asprintf(&log_file_path, "%s/%s", home_dir, DEBUG_LOG_NAME);
- if (log_file_path) {
- if (!access(log_file_path, F_OK)) {
- debug_log_fp = fopen(log_file_path, "a");
- if (debug_log_fp) ErrorF("Debug logging enabled to %s\n", log_file_path);
- }
- free(log_file_path);
- }
- }
-#endif
- }
-}
-
-
-/*
- * ddxProcessArgument
- * Process device-dependent command line args. Returns 0 if argument is
- * not device dependent, otherwise Count of number of elements of argv
- * that are part of a device dependent commandline option.
- */
-int ddxProcessArgument( int argc, char *argv[], int i )
-{
-// if ( !strcmp( argv[i], "-fullscreen" ) ) {
-// ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
-// return 1;
-// }
-
-// if ( !strcmp( argv[i], "-rootless" ) ) {
-// ErrorF( "Running rootless inside Mac OS X window server.\n" );
-// return 1;
-// }
-
- // This command line arg is passed when launched from the Aqua GUI.
- if ( !strncmp( argv[i], "-psn_", 5 ) ) {
- return 1;
- }
-
- if ( !strcmp( argv[i], "-fakebuttons" ) ) {
- darwinFakeButtons = TRUE;
- ErrorF( "Faking a three button mouse\n" );
- return 1;
- }
-
- if ( !strcmp( argv[i], "-nofakebuttons" ) ) {
- darwinFakeButtons = FALSE;
- ErrorF( "Not faking a three button mouse\n" );
- return 1;
- }
-
- if (!strcmp( argv[i], "-fakemouse2" ) ) {
- if ( i == argc-1 ) {
- FatalError( "-fakemouse2 must be followed by a modifer list\n" );
- }
- if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
- darwinFakeMouse2Mask = 0;
- else
- darwinFakeMouse2Mask = DarwinParseModifierList(argv[i+1], 1);
- ErrorF("Modifier mask to fake mouse button 2 = 0x%x\n",
- darwinFakeMouse2Mask);
- return 2;
- }
-
- if (!strcmp( argv[i], "-fakemouse3" ) ) {
- if ( i == argc-1 ) {
- FatalError( "-fakemouse3 must be followed by a modifer list\n" );
- }
- if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
- darwinFakeMouse3Mask = 0;
- else
- darwinFakeMouse3Mask = DarwinParseModifierList(argv[i+1], 1);
- ErrorF("Modifier mask to fake mouse button 3 = 0x%x\n",
- darwinFakeMouse3Mask);
- return 2;
- }
-
- if ( !strcmp( argv[i], "+synckeymap" ) ) {
- darwinSyncKeymap = TRUE;
- return 1;
- }
-
- if ( !strcmp( argv[i], "-synckeymap" ) ) {
- darwinSyncKeymap = FALSE;
- return 1;
- }
-
- if ( !strcmp( argv[i], "-size" ) ) {
- if ( i >= argc-2 ) {
- FatalError( "-size must be followed by two numbers\n" );
- }
-#ifdef OLD_POWERBOOK_G3
- ErrorF( "Ignoring unsupported -size option on old PowerBook G3\n" );
-#else
- darwinDesiredWidth = atoi( argv[i+1] );
- darwinDesiredHeight = atoi( argv[i+2] );
- ErrorF( "Attempting to use width x height = %i x %i\n",
- darwinDesiredWidth, darwinDesiredHeight );
-#endif
- return 3;
- }
-
- if ( !strcmp( argv[i], "-depth" ) ) {
- if ( i == argc-1 ) {
- FatalError( "-depth must be followed by a number\n" );
- }
-#ifdef OLD_POWERBOOK_G3
- ErrorF( "Ignoring unsupported -depth option on old PowerBook G3\n");
-#else
- darwinDesiredDepth = atoi( argv[i+1] );
- if(darwinDesiredDepth != -1 &&
- darwinDesiredDepth != 8 &&
- darwinDesiredDepth != 15 &&
- darwinDesiredDepth != 24) {
- FatalError( "Unsupported pixel depth. Use 8, 15, or 24 bits\n" );
- }
-
- ErrorF( "Attempting to use pixel depth of %i\n", darwinDesiredDepth );
-#endif
- return 2;
- }
-
- if ( !strcmp( argv[i], "-refresh" ) ) {
- if ( i == argc-1 ) {
- FatalError( "-refresh must be followed by a number\n" );
- }
-#ifdef OLD_POWERBOOK_G3
- ErrorF( "Ignoring unsupported -refresh option on old PowerBook G3\n");
-#else
- darwinDesiredRefresh = atoi( argv[i+1] );
- ErrorF( "Attempting to use refresh rate of %i\n", darwinDesiredRefresh );
-#endif
- return 2;
- }
-
- if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
- DarwinPrintBanner();
- exit(0);
- }
-
- return 0;
-}
-
-
-/*
- * ddxUseMsg --
- * Print out correct use of device dependent commandline options.
- * Maybe the user now knows what really to do ...
- */
-void ddxUseMsg( void )
-{
- ErrorF("\n");
- ErrorF("\n");
- ErrorF("Device Dependent Usage:\n");
- ErrorF("\n");
- ErrorF("-fakebuttons : fake a three button mouse with Command and Option keys.\n");
- ErrorF("-nofakebuttons : don't fake a three button mouse.\n");
- ErrorF("-fakemouse2 <modifiers> : fake middle mouse button with modifier keys.\n");
- ErrorF("-fakemouse3 <modifiers> : fake right mouse button with modifier keys.\n");
- ErrorF(" ex: -fakemouse2 \"option,shift\" = option-shift-click is middle button.\n");
- ErrorF("-version : show the server version.\n");
- ErrorF("\n");
- ErrorF("\n");
- ErrorF("Options ignored in rootless mode:\n");
- ErrorF("-size <height> <width> : use a screen resolution of <height> x <width>.\n");
- ErrorF("-depth <8,15,24> : use this bit depth.\n");
- ErrorF("-refresh <rate> : use a monitor refresh rate of <rate> Hz.\n");
- ErrorF("\n");
-}
-
-
-/*
- * ddxGiveUp --
- * Device dependent cleanup. Called by dix before normal server death.
- */
-void ddxGiveUp( void )
-{
- ErrorF( "Quitting Xquartz...\n" );
-}
-
-
-/*
- * AbortDDX --
- * DDX - specific abort routine. Called by AbortServer(). The attempt is
- * made to restore all original setting of the displays. Also all devices
- * are closed.
- */
-void AbortDDX( void )
-{
- ErrorF( " AbortDDX\n" );
- /*
- * This is needed for a abnormal server exit, since the normal exit stuff
- * MUST also be performed (i.e. the vt must be left in a defined state)
- */
- ddxGiveUp();
-}
-
-#include "mivalidate.h" // for union _Validate used by windowstr.h
-#include "windowstr.h" // for struct _Window
-#include "scrnintstr.h" // for struct _Screen
-
-// This is copied from Xserver/hw/xfree86/common/xf86Helper.c.
-// Quartz mode uses this when switching in and out of Quartz.
-// Quartz or IOKit can use this when waking from sleep.
-// Copyright (c) 1997-1998 by The XFree86 Project, Inc.
-
-/*
- * xf86SetRootClip --
- * Enable or disable rendering to the screen by
- * setting the root clip list and revalidating
- * all of the windows
- */
-
-void
-xf86SetRootClip (ScreenPtr pScreen, int enable)
-{
- WindowPtr pWin = WindowTable[pScreen->myNum];
- WindowPtr pChild;
- Bool WasViewable = (Bool)(pWin->viewable);
- Bool anyMarked = TRUE;
- RegionPtr pOldClip = NULL, bsExposed;
- WindowPtr pLayerWin;
- BoxRec box;
-
- if (WasViewable)
- {
- for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
- {
- (void) (*pScreen->MarkOverlappedWindows)(pChild,
- pChild,
- &pLayerWin);
- }
- (*pScreen->MarkWindow) (pWin);
- anyMarked = TRUE;
- if (pWin->valdata)
- {
- if (HasBorder (pWin))
- {
- RegionPtr borderVisible;
-
- borderVisible = REGION_CREATE(pScreen, NullBox, 1);
- REGION_SUBTRACT(pScreen, borderVisible,
- &pWin->borderClip, &pWin->winSize);
- pWin->valdata->before.borderVisible = borderVisible;
- }
- pWin->valdata->before.resized = TRUE;
- }
- }
-
- /*
- * Use REGION_BREAK to avoid optimizations in ValidateTree
- * that assume the root borderClip can't change well, normally
- * it doesn't...)
- */
- if (enable)
- {
- box.x1 = 0;
- box.y1 = 0;
- box.x2 = pScreen->width;
- box.y2 = pScreen->height;
- REGION_RESET(pScreen, &pWin->borderClip, &box);
- REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
- }
- else
- {
- REGION_EMPTY(pScreen, &pWin->borderClip);
- REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
- }
-
- ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
-
- if (WasViewable)
- {
- if (pWin->backStorage)
- {
- pOldClip = REGION_CREATE(pScreen, NullBox, 1);
- REGION_COPY(pScreen, pOldClip, &pWin->clipList);
- }
-
- if (pWin->firstChild)
- {
- anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
- pWin->firstChild,
- (WindowPtr *)NULL);
- }
- else
- {
- (*pScreen->MarkWindow) (pWin);
- anyMarked = TRUE;
- }
-
-
- if (anyMarked)
- (*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
- }
-
- if (pWin->backStorage &&
- ((pWin->backingStore == Always) || WasViewable))
- {
- if (!WasViewable)
- pOldClip = &pWin->clipList; /* a convenient empty region */
- bsExposed = (*pScreen->TranslateBackingStore)
- (pWin, 0, 0, pOldClip,
- pWin->drawable.x, pWin->drawable.y);
- if (WasViewable)
- REGION_DESTROY(pScreen, pOldClip);
- if (bsExposed)
- {
- RegionPtr valExposed = NullRegion;
-
- if (pWin->valdata)
- valExposed = &pWin->valdata->after.exposed;
- (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
- if (valExposed)
- REGION_EMPTY(pScreen, valExposed);
- REGION_DESTROY(pScreen, bsExposed);
- }
- }
- if (WasViewable)
- {
- if (anyMarked)
- (*pScreen->HandleExposures)(pWin);
- if (anyMarked && pScreen->PostValidateTree)
- (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
- }
- if (pWin->realized)
- WindowsRestructured ();
- FlushAllOutput ();
-}
+/**************************************************************
+ *
+ * Xquartz initialization code
+ *
+ * Copyright (c) 2007-2008 Apple Inc.
+ * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written authorization.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "os.h"
+#include "servermd.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "mibstore.h" // mi backing store implementation
+#include "mipointer.h" // mi software cursor
+#include "micmap.h" // mi colormap code
+#include "fb.h" // fb framebuffer code
+#include "site.h"
+#include "globals.h"
+#include "dix.h"
+
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include "exevents.h"
+#include "extinit.h"
+
+#include "xserver-properties.h"
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/syslimits.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#define HAS_UTSNAME 1
+#include <sys/utsname.h>
+
+#define NO_CFPLUGIN
+#include <IOKit/hidsystem/IOHIDLib.h>
+
+#ifdef MITSHM
+#include "shmint.h"
+#endif
+
+#include "darwin.h"
+#include "darwinEvents.h"
+#include "quartzKeyboard.h"
+#include "quartz.h"
+
+#ifdef ENABLE_DEBUG_LOG
+FILE *debug_log_fp = NULL;
+#endif
+
+/*
+ * X server shared global variables
+ */
+int darwinScreensFound = 0;
+static int darwinScreenKeyIndex;
+DevPrivateKey darwinScreenKey = &darwinScreenKeyIndex;
+io_connect_t darwinParamConnect = 0;
+int darwinEventReadFD = -1;
+int darwinEventWriteFD = -1;
+// int darwinMouseAccelChange = 1;
+int darwinFakeButtons = 0;
+
+// location of X11's (0,0) point in global screen coordinates
+int darwinMainScreenX = 0;
+int darwinMainScreenY = 0;
+
+// parameters read from the command line or user preferences
+int darwinDesiredDepth = -1;
+int darwinSyncKeymap = FALSE;
+
+// modifier masks for faking mouse buttons - ANY of these bits trigger it (not all)
+#ifdef NX_DEVICELCMDKEYMASK
+int darwinFakeMouse2Mask = NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK;
+int darwinFakeMouse3Mask = NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK;
+#else
+int darwinFakeMouse2Mask = NX_ALTERNATEMASK;
+int darwinFakeMouse3Mask = NX_COMMANDMASK;
+#endif
+
+// Modifier mask for overriding event delivery to appkit (might be useful to set this to rcommand for input menu
+unsigned int darwinAppKitModMask = 0; // Any of these bits
+
+// Modifier mask for items in the Window menu (0 and -1 cause shortcuts to be disabled)
+unsigned int windowItemModMask = NX_COMMANDMASK;
+
+// devices
+DeviceIntPtr darwinKeyboard = NULL;
+DeviceIntPtr darwinPointer = NULL;
+DeviceIntPtr darwinTabletCurrent = NULL;
+DeviceIntPtr darwinTabletStylus = NULL;
+DeviceIntPtr darwinTabletCursor = NULL;
+DeviceIntPtr darwinTabletEraser = NULL;
+
+// Common pixmap formats
+static PixmapFormatRec formats[] = {
+ { 1, 1, BITMAP_SCANLINE_PAD },
+ { 4, 8, BITMAP_SCANLINE_PAD },
+ { 8, 8, BITMAP_SCANLINE_PAD },
+ { 15, 16, BITMAP_SCANLINE_PAD },
+ { 16, 16, BITMAP_SCANLINE_PAD },
+ { 24, 32, BITMAP_SCANLINE_PAD },
+ { 32, 32, BITMAP_SCANLINE_PAD }
+};
+const int NUMFORMATS = sizeof(formats)/sizeof(formats[0]);
+
+#ifndef OSNAME
+#define OSNAME " Darwin"
+#endif
+#ifndef OSVENDOR
+#define OSVENDOR ""
+#endif
+#ifndef PRE_RELEASE
+#define PRE_RELEASE XORG_VERSION_SNAP
+#endif
+#ifndef BUILD_DATE
+#define BUILD_DATE ""
+#endif
+#ifndef XORG_RELEASE
+#define XORG_RELEASE "?"
+#endif
+
+void
+DarwinPrintBanner(void)
+{
+ // this should change depending on which specific server we are building
+ ErrorF("Xquartz starting:\n");
+ ErrorF("X.Org X Server %s\nBuild Date: %s\n", XSERVER_VERSION, BUILD_DATE );
+}
+
+
+/*
+ * DarwinSaveScreen
+ * X screensaver support. Not implemented.
+ */
+static Bool DarwinSaveScreen(ScreenPtr pScreen, int on)
+{
+ // FIXME
+ if (on == SCREEN_SAVER_FORCER) {
+ } else if (on == SCREEN_SAVER_ON) {
+ } else {
+ }
+ return TRUE;
+}
+
+/*
+ * DarwinScreenInit
+ * This is a callback from dix during AddScreen() from InitOutput().
+ * Initialize the screen and communicate information about it back to dix.
+ */
+static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv) {
+ int dpi;
+ static int foundIndex = 0;
+ Bool ret;
+ DarwinFramebufferPtr dfb;
+
+ // reset index of found screens for each server generation
+ if (index == 0) {
+ foundIndex = 0;
+
+ // reset the visual list
+ miClearVisualTypes();
+ }
+
+ // allocate space for private per screen storage
+ dfb = xalloc(sizeof(DarwinFramebufferRec));
+
+ // SCREEN_PRIV(pScreen) = dfb;
+ dixSetPrivate(&pScreen->devPrivates, darwinScreenKey, dfb);
+
+ // setup hardware/mode specific details
+ ret = QuartzAddScreen(foundIndex, pScreen);
+ foundIndex++;
+ if (! ret)
+ return FALSE;
+
+ // setup a single visual appropriate for our pixel type
+ if(!miSetVisualTypesAndMasks(dfb->depth, dfb->visuals, dfb->bitsPerRGB,
+ dfb->preferredCVC, dfb->redMask,
+ dfb->greenMask, dfb->blueMask)) {
+ return FALSE;
+ }
+
+// TODO: Make PseudoColor visuals not suck in TrueColor mode
+// if(dfb->depth > 8)
+// miSetVisualTypesAndMasks(8, PseudoColorMask, 8, PseudoColor, 0, 0, 0);
+ if(dfb->depth > 15)
+ miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor, RM_ARGB(0,5,5,5), GM_ARGB(0,5,5,5), BM_ARGB(0,5,5,5));
+ if(dfb->depth > 24)
+ miSetVisualTypesAndMasks(24, TrueColorMask, 8, TrueColor, RM_ARGB(0,8,8,8), GM_ARGB(0,8,8,8), BM_ARGB(0,8,8,8));
+
+ miSetPixmapDepths();
+
+ // machine independent screen init
+ // setup _Screen structure in pScreen
+ if (monitorResolution)
+ dpi = monitorResolution;
+ else
+ dpi = 96;
+
+ // initialize fb
+ if (! fbScreenInit(pScreen,
+ dfb->framebuffer, // pointer to screen bitmap
+ dfb->width, dfb->height, // screen size in pixels
+ dpi, dpi, // dots per inch
+ dfb->pitch/(dfb->bitsPerPixel/8), // pixel width of framebuffer
+ dfb->bitsPerPixel)) // bits per pixel for screen
+ {
+ return FALSE;
+ }
+
+#ifdef RENDER
+ if (! fbPictureInit(pScreen, 0, 0)) {
+ return FALSE;
+ }
+#endif
+
+#ifdef MITSHM
+ ShmRegisterFbFuncs(pScreen);
+#endif
+
+ // this must be initialized (why doesn't X have a default?)
+ pScreen->SaveScreen = DarwinSaveScreen;
+
+ // finish mode dependent screen setup including cursor support
+ if (!QuartzSetupScreen(index, pScreen)) {
+ return FALSE;
+ }
+
+ // create and install the default colormap and
+ // set pScreen->blackPixel / pScreen->white
+ if (!miCreateDefColormap( pScreen )) {
+ return FALSE;
+ }
+
+ dixScreenOrigins[index].x = dfb->x;
+ dixScreenOrigins[index].y = dfb->y;
+
+ /* ErrorF("Screen %d added: %dx%d @ (%d,%d)\n",
+ index, dfb->width, dfb->height, dfb->x, dfb->y); */
+
+ return TRUE;
+}
+
+/*
+ =============================================================================
+
+ mouse and keyboard callbacks
+
+ =============================================================================
+*/
+
+/*
+ * DarwinMouseProc: Handle the initialization, etc. of a mouse
+ */
+static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
+#define NBUTTONS 7
+#define NAXES 2
+ // 7 buttons: left, right, middle, then four scroll wheel "buttons"
+ CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3, 4, 5, 6, 7};
+ Atom btn_labels[NBUTTONS] = {0};
+ Atom axes_labels[NAXES] = {0};
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+ btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+ btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+ btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+ btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+ btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+ btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+
+ axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+ axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+
+ // Set button map.
+ InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
+ btn_labels,
+ (PtrCtrlProcPtr)NoopDDA,
+ GetMotionHistorySize(), NAXES,
+ axes_labels);
+ pPointer->valuator->mode = Absolute; // Relative
+ InitAbsoluteClassDeviceStruct(pPointer);
+// InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+// InitValuatorAxisStruct(pPointer, 1, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+ break;
+ case DEVICE_ON:
+ pPointer->public.on = TRUE;
+ AddEnabledDevice( darwinEventReadFD );
+ return Success;
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pPointer->public.on = FALSE;
+ RemoveEnabledDevice(darwinEventReadFD);
+ return Success;
+ }
+
+ return Success;
+#undef NBUTTONS
+#undef NAXES
+}
+
+static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
+#define NBUTTONS 3
+#define NAXES 5
+ CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3};
+ Atom btn_labels[NBUTTONS] = {0};
+ Atom axes_labels[NAXES] = {0};
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+ btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+ btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+
+ axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
+ axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
+ axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
+ axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X);
+ axes_labels[4] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y);
+
+ // Set button map.
+ InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
+ btn_labels,
+ (PtrCtrlProcPtr)NoopDDA,
+ GetMotionHistorySize(), NAXES,
+ axes_labels);
+ pPointer->valuator->mode = Absolute; // Relative
+ InitProximityClassDeviceStruct(pPointer);
+ InitAbsoluteClassDeviceStruct(pPointer);
+
+ InitValuatorAxisStruct(pPointer, 0, axes_labels[0], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+ InitValuatorAxisStruct(pPointer, 1, axes_labels[1], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+ InitValuatorAxisStruct(pPointer, 2, axes_labels[2], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+ InitValuatorAxisStruct(pPointer, 3, axes_labels[3], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+ InitValuatorAxisStruct(pPointer, 4, axes_labels[4], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+// pPointer->use = IsXExtensionDevice;
+ break;
+ case DEVICE_ON:
+ pPointer->public.on = TRUE;
+ AddEnabledDevice( darwinEventReadFD );
+ return Success;
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pPointer->public.on = FALSE;
+ RemoveEnabledDevice(darwinEventReadFD);
+ return Success;
+ }
+ return Success;
+#undef NBUTTONS
+#undef NAXES
+}
+
+/*
+ * DarwinKeybdProc
+ * Callback from X
+ */
+static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff )
+{
+ switch ( onoff ) {
+ case DEVICE_INIT:
+ DarwinKeyboardInit( pDev );
+ break;
+ case DEVICE_ON:
+ pDev->public.on = TRUE;
+ AddEnabledDevice( darwinEventReadFD );
+ break;
+ case DEVICE_OFF:
+ pDev->public.on = FALSE;
+ RemoveEnabledDevice( darwinEventReadFD );
+ break;
+ case DEVICE_CLOSE:
+ break;
+ }
+
+ return Success;
+}
+
+/*
+===========================================================================
+
+ Utility routines
+
+===========================================================================
+*/
+
+/*
+ * DarwinParseModifierList
+ * Parse a list of modifier names and return a corresponding modifier mask
+ */
+int DarwinParseModifierList(const char *constmodifiers, int separatelr)
+{
+ int result = 0;
+
+ if (constmodifiers) {
+ char *modifiers = strdup(constmodifiers);
+ char *modifier;
+ int nxkey;
+ char *p = modifiers;
+
+ while (p) {
+ modifier = strsep(&p, " ,+&|/"); // allow lots of separators
+ nxkey = DarwinModifierStringToNXMask(modifier, separatelr);
+ if(nxkey)
+ result |= nxkey;
+ else
+ ErrorF("fakebuttons: Unknown modifier \"%s\"\n", modifier);
+ }
+ free(modifiers);
+ }
+ return result;
+}
+
+/*
+===========================================================================
+
+ Functions needed to link against device independent X
+
+===========================================================================
+*/
+
+/*
+ * InitInput
+ * Register the keyboard and mouse devices
+ */
+void InitInput( int argc, char **argv )
+{
+ darwinKeyboard = AddInputDevice(serverClient, DarwinKeybdProc, TRUE);
+ RegisterKeyboardDevice( darwinKeyboard );
+ darwinKeyboard->name = strdup("keyboard");
+
+ /* here's the snippet from the current gdk sources:
+ if (!strcmp (tmp_name, "pointer"))
+ gdkdev->info.source = GDK_SOURCE_MOUSE;
+ else if (!strcmp (tmp_name, "wacom") ||
+ !strcmp (tmp_name, "pen"))
+ gdkdev->info.source = GDK_SOURCE_PEN;
+ else if (!strcmp (tmp_name, "eraser"))
+ gdkdev->info.source = GDK_SOURCE_ERASER;
+ else if (!strcmp (tmp_name, "cursor"))
+ gdkdev->info.source = GDK_SOURCE_CURSOR;
+ else
+ gdkdev->info.source = GDK_SOURCE_PEN;
+ */
+
+ darwinPointer = AddInputDevice(serverClient, DarwinMouseProc, TRUE);
+ RegisterPointerDevice( darwinPointer );
+ darwinPointer->name = strdup("pointer");
+
+ darwinTabletStylus = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
+ RegisterPointerDevice( darwinTabletStylus );
+ darwinTabletStylus->name = strdup("pen");
+
+ darwinTabletCursor = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
+ RegisterPointerDevice( darwinTabletCursor );
+ darwinTabletCursor->name = strdup("cursor");
+
+ darwinTabletEraser = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
+ RegisterPointerDevice( darwinTabletEraser );
+ darwinTabletEraser->name = strdup("eraser");
+
+ darwinTabletCurrent = darwinTabletStylus;
+
+ DarwinEQInit();
+
+ QuartzInitInput(argc, argv);
+}
+
+
+/*
+ * DarwinAdjustScreenOrigins
+ * Shift all screens so the X11 (0, 0) coordinate is at the top
+ * left of the global screen coordinates.
+ *
+ * Screens can be arranged so the top left isn't on any screen, so
+ * instead use the top left of the leftmost screen as (0,0). This
+ * may mean some screen space is in -y, but it's better that (0,0)
+ * be onscreen, or else default xterms disappear. It's better that
+ * -y be used than -x, because when popup menus are forced
+ * "onscreen" by dumb window managers like twm, they'll shift the
+ * menus down instead of left, which still looks funny but is an
+ * easier target to hit.
+ */
+void
+DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
+{
+ int i, left, top;
+
+ left = dixScreenOrigins[0].x;
+ top = dixScreenOrigins[0].y;
+
+ /* Find leftmost screen. If there's a tie, take the topmost of the two. */
+ for (i = 1; i < pScreenInfo->numScreens; i++) {
+ if (dixScreenOrigins[i].x < left ||
+ (dixScreenOrigins[i].x == left && dixScreenOrigins[i].y < top))
+ {
+ left = dixScreenOrigins[i].x;
+ top = dixScreenOrigins[i].y;
+ }
+ }
+
+ darwinMainScreenX = left;
+ darwinMainScreenY = top;
+
+ DEBUG_LOG("top = %d, left=%d\n", top, left);
+
+ /* Shift all screens so that there is a screen whose top left
+ * is at X11 (0,0) and at global screen coordinate
+ * (darwinMainScreenX, darwinMainScreenY).
+ */
+
+ if (darwinMainScreenX != 0 || darwinMainScreenY != 0) {
+ for (i = 0; i < pScreenInfo->numScreens; i++) {
+ dixScreenOrigins[i].x -= darwinMainScreenX;
+ dixScreenOrigins[i].y -= darwinMainScreenY;
+ DEBUG_LOG("Screen %d placed at X11 coordinate (%d,%d).\n",
+ i, dixScreenOrigins[i].x, dixScreenOrigins[i].y);
+ }
+ }
+}
+
+
+/*
+ * InitOutput
+ * Initialize screenInfo for all actually accessible framebuffers.
+ *
+ * The display mode dependent code gets called three times. The mode
+ * specific InitOutput routines are expected to discover the number
+ * of potentially useful screens and cache routes to them internally.
+ * Inside DarwinScreenInit are two other mode specific calls.
+ * A mode specific AddScreen routine is called for each screen to
+ * actually initialize the screen with the ScreenPtr structure.
+ * After other screen setup has been done, a mode specific
+ * SetupScreen function can be called to finalize screen setup.
+ */
+void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv )
+{
+ int i;
+
+ pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+ pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+
+ // List how we want common pixmap formats to be padded
+ pScreenInfo->numPixmapFormats = NUMFORMATS;
+ for (i = 0; i < NUMFORMATS; i++)
+ pScreenInfo->formats[i] = formats[i];
+
+ // Discover screens and do mode specific initialization
+ QuartzInitOutput(argc, argv);
+
+ // Add screens
+ for (i = 0; i < darwinScreensFound; i++) {
+ AddScreen(DarwinScreenInit, argc, argv);
+ }
+
+ DarwinAdjustScreenOrigins(pScreenInfo);
+}
+
+
+/*
+ * OsVendorFataError
+ */
+void OsVendorFatalError( void )
+{
+ ErrorF( " OsVendorFatalError\n" );
+}
+
+
+/*
+ * OsVendorInit
+ * Initialization of Darwin OS support.
+ */
+void OsVendorInit(void)
+{
+ if (serverGeneration == 1) {
+ DarwinPrintBanner();
+#ifdef ENABLE_DEBUG_LOG
+ {
+ char *home_dir=NULL, *log_file_path=NULL;
+ home_dir = getenv("HOME");
+ if (home_dir) asprintf(&log_file_path, "%s/%s", home_dir, DEBUG_LOG_NAME);
+ if (log_file_path) {
+ if (!access(log_file_path, F_OK)) {
+ debug_log_fp = fopen(log_file_path, "a");
+ if (debug_log_fp) ErrorF("Debug logging enabled to %s\n", log_file_path);
+ }
+ free(log_file_path);
+ }
+ }
+#endif
+ }
+}
+
+
+/*
+ * ddxProcessArgument
+ * Process device-dependent command line args. Returns 0 if argument is
+ * not device dependent, otherwise Count of number of elements of argv
+ * that are part of a device dependent commandline option.
+ */
+int ddxProcessArgument( int argc, char *argv[], int i )
+{
+// if ( !strcmp( argv[i], "-fullscreen" ) ) {
+// ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
+// return 1;
+// }
+
+// if ( !strcmp( argv[i], "-rootless" ) ) {
+// ErrorF( "Running rootless inside Mac OS X window server.\n" );
+// return 1;
+// }
+
+ // This command line arg is passed when launched from the Aqua GUI.
+ if ( !strncmp( argv[i], "-psn_", 5 ) ) {
+ return 1;
+ }
+
+ if ( !strcmp( argv[i], "-fakebuttons" ) ) {
+ darwinFakeButtons = TRUE;
+ ErrorF( "Faking a three button mouse\n" );
+ return 1;
+ }
+
+ if ( !strcmp( argv[i], "-nofakebuttons" ) ) {
+ darwinFakeButtons = FALSE;
+ ErrorF( "Not faking a three button mouse\n" );
+ return 1;
+ }
+
+ if (!strcmp( argv[i], "-fakemouse2" ) ) {
+ if ( i == argc-1 ) {
+ FatalError( "-fakemouse2 must be followed by a modifer list\n" );
+ }
+ if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
+ darwinFakeMouse2Mask = 0;
+ else
+ darwinFakeMouse2Mask = DarwinParseModifierList(argv[i+1], 1);
+ ErrorF("Modifier mask to fake mouse button 2 = 0x%x\n",
+ darwinFakeMouse2Mask);
+ return 2;
+ }
+
+ if (!strcmp( argv[i], "-fakemouse3" ) ) {
+ if ( i == argc-1 ) {
+ FatalError( "-fakemouse3 must be followed by a modifer list\n" );
+ }
+ if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
+ darwinFakeMouse3Mask = 0;
+ else
+ darwinFakeMouse3Mask = DarwinParseModifierList(argv[i+1], 1);
+ ErrorF("Modifier mask to fake mouse button 3 = 0x%x\n",
+ darwinFakeMouse3Mask);
+ return 2;
+ }
+
+ if ( !strcmp( argv[i], "+synckeymap" ) ) {
+ darwinSyncKeymap = TRUE;
+ return 1;
+ }
+
+ if ( !strcmp( argv[i], "-synckeymap" ) ) {
+ darwinSyncKeymap = FALSE;
+ return 1;
+ }
+
+ if ( !strcmp( argv[i], "-depth" ) ) {
+ if ( i == argc-1 ) {
+ FatalError( "-depth must be followed by a number\n" );
+ }
+ darwinDesiredDepth = atoi( argv[i+1] );
+ if(darwinDesiredDepth != -1 &&
+ darwinDesiredDepth != 8 &&
+ darwinDesiredDepth != 15 &&
+ darwinDesiredDepth != 24) {
+ FatalError( "Unsupported pixel depth. Use 8, 15, or 24 bits\n" );
+ }
+
+ ErrorF( "Attempting to use pixel depth of %i\n", darwinDesiredDepth );
+ return 2;
+ }
+
+ if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
+ DarwinPrintBanner();
+ exit(0);
+ }
+
+ return 0;
+}
+
+
+/*
+ * ddxUseMsg --
+ * Print out correct use of device dependent commandline options.
+ * Maybe the user now knows what really to do ...
+ */
+void ddxUseMsg( void )
+{
+ ErrorF("\n");
+ ErrorF("\n");
+ ErrorF("Device Dependent Usage:\n");
+ ErrorF("\n");
+ ErrorF("-depth <8,15,24> : use this bit depth.\n");
+ ErrorF("-fakebuttons : fake a three button mouse with Command and Option keys.\n");
+ ErrorF("-nofakebuttons : don't fake a three button mouse.\n");
+ ErrorF("-fakemouse2 <modifiers> : fake middle mouse button with modifier keys.\n");
+ ErrorF("-fakemouse3 <modifiers> : fake right mouse button with modifier keys.\n");
+ ErrorF(" ex: -fakemouse2 \"option,shift\" = option-shift-click is middle button.\n");
+ ErrorF("-version : show the server version.\n");
+ ErrorF("\n");
+}
+
+
+/*
+ * ddxGiveUp --
+ * Device dependent cleanup. Called by dix before normal server death.
+ */
+void ddxGiveUp( void )
+{
+ ErrorF( "Quitting Xquartz...\n" );
+}
+
+
+/*
+ * AbortDDX --
+ * DDX - specific abort routine. Called by AbortServer(). The attempt is
+ * made to restore all original setting of the displays. Also all devices
+ * are closed.
+ */
+void AbortDDX( void )
+{
+ ErrorF( " AbortDDX\n" );
+ /*
+ * This is needed for a abnormal server exit, since the normal exit stuff
+ * MUST also be performed (i.e. the vt must be left in a defined state)
+ */
+ ddxGiveUp();
+}
+
+#include "mivalidate.h" // for union _Validate used by windowstr.h
+#include "windowstr.h" // for struct _Window
+#include "scrnintstr.h" // for struct _Screen
+
+// This is copied from Xserver/hw/xfree86/common/xf86Helper.c.
+// Quartz mode uses this when switching in and out of Quartz.
+// Quartz or IOKit can use this when waking from sleep.
+// Copyright (c) 1997-1998 by The XFree86 Project, Inc.
+
+/*
+ * xf86SetRootClip --
+ * Enable or disable rendering to the screen by
+ * setting the root clip list and revalidating
+ * all of the windows
+ */
+
+void
+xf86SetRootClip (ScreenPtr pScreen, int enable)
+{
+ WindowPtr pWin = WindowTable[pScreen->myNum];
+ WindowPtr pChild;
+ Bool WasViewable = (Bool)(pWin->viewable);
+ Bool anyMarked = TRUE;
+ RegionPtr pOldClip = NULL, bsExposed;
+ WindowPtr pLayerWin;
+ BoxRec box;
+
+ if (WasViewable)
+ {
+ for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+ {
+ (void) (*pScreen->MarkOverlappedWindows)(pChild,
+ pChild,
+ &pLayerWin);
+ }
+ (*pScreen->MarkWindow) (pWin);
+ anyMarked = TRUE;
+ if (pWin->valdata)
+ {
+ if (HasBorder (pWin))
+ {
+ RegionPtr borderVisible;
+
+ borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+ REGION_SUBTRACT(pScreen, borderVisible,
+ &pWin->borderClip, &pWin->winSize);
+ pWin->valdata->before.borderVisible = borderVisible;
+ }
+ pWin->valdata->before.resized = TRUE;
+ }
+ }
+
+ /*
+ * Use REGION_BREAK to avoid optimizations in ValidateTree
+ * that assume the root borderClip can't change well, normally
+ * it doesn't...)
+ */
+ if (enable)
+ {
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = pScreen->width;
+ box.y2 = pScreen->height;
+ REGION_RESET(pScreen, &pWin->borderClip, &box);
+ REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+ }
+ else
+ {
+ REGION_EMPTY(pScreen, &pWin->borderClip);
+ REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+ }
+
+ ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
+
+ if (WasViewable)
+ {
+ if (pWin->backStorage)
+ {
+ pOldClip = REGION_CREATE(pScreen, NullBox, 1);
+ REGION_COPY(pScreen, pOldClip, &pWin->clipList);
+ }
+
+ if (pWin->firstChild)
+ {
+ anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
+ pWin->firstChild,
+ (WindowPtr *)NULL);
+ }
+ else
+ {
+ (*pScreen->MarkWindow) (pWin);
+ anyMarked = TRUE;
+ }
+
+
+ if (anyMarked)
+ (*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
+ }
+
+ if (pWin->backStorage &&
+ ((pWin->backingStore == Always) || WasViewable))
+ {
+ if (!WasViewable)
+ pOldClip = &pWin->clipList; /* a convenient empty region */
+ bsExposed = (*pScreen->TranslateBackingStore)
+ (pWin, 0, 0, pOldClip,
+ pWin->drawable.x, pWin->drawable.y);
+ if (WasViewable)
+ REGION_DESTROY(pScreen, pOldClip);
+ if (bsExposed)
+ {
+ RegionPtr valExposed = NullRegion;
+
+ if (pWin->valdata)
+ valExposed = &pWin->valdata->after.exposed;
+ (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
+ if (valExposed)
+ REGION_EMPTY(pScreen, valExposed);
+ REGION_DESTROY(pScreen, bsExposed);
+ }
+ }
+ if (WasViewable)
+ {
+ if (anyMarked)
+ (*pScreen->HandleExposures)(pWin);
+ if (anyMarked && pScreen->PostValidateTree)
+ (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
+ }
+ if (pWin->realized)
+ WindowsRestructured ();
+ FlushAllOutput ();
+}
diff --git a/xorg-server/hw/xquartz/darwin.h b/xorg-server/hw/xquartz/darwin.h
index 586044fba..6209b5ef1 100644
--- a/xorg-server/hw/xquartz/darwin.h
+++ b/xorg-server/hw/xquartz/darwin.h
@@ -1,93 +1,91 @@
-/*
- * Copyright (C) 2008 Apple, Inc.
- * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _DARWIN_H
-#define _DARWIN_H
-
-#include <IOKit/IOTypes.h>
-#include "inputstr.h"
-#include "scrnintstr.h"
-#include <X11/extensions/XKB.h>
-#include <assert.h>
-
-#include "threadSafety.h"
-
-#include "darwinfb.h"
-
-// From darwin.c
-void DarwinPrintBanner(void);
-int DarwinParseModifierList(const char *constmodifiers, int separatelr);
-void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
-void xf86SetRootClip (ScreenPtr pScreen, int enable);
-
-#define SCREEN_PRIV(pScreen) ((DarwinFramebufferPtr) \
- dixLookupPrivate(&pScreen->devPrivates, darwinScreenKey))
-
-/*
- * Global variables from darwin.c
- */
-extern DevPrivateKey darwinScreenKey; // index into pScreen.devPrivates
-extern int darwinScreensFound;
-extern io_connect_t darwinParamConnect;
-extern int darwinEventReadFD;
-extern int darwinEventWriteFD;
-extern DeviceIntPtr darwinPointer;
-extern DeviceIntPtr darwinTabletCurrent;
-extern DeviceIntPtr darwinTabletCursor;
-extern DeviceIntPtr darwinTabletStylus;
-extern DeviceIntPtr darwinTabletEraser;
-extern DeviceIntPtr darwinKeyboard;
-
-// User preferences
-extern int darwinMouseAccelChange;
-extern int darwinFakeButtons;
-extern int darwinFakeMouse2Mask;
-extern int darwinFakeMouse3Mask;
-extern unsigned int darwinAppKitModMask;
-extern unsigned int windowItemModMask;
-extern int darwinSyncKeymap;
-extern unsigned int darwinDesiredWidth, darwinDesiredHeight;
-extern int darwinDesiredDepth;
-extern int darwinDesiredRefresh;
-
-// location of X11's (0,0) point in global screen coordinates
-extern int darwinMainScreenX;
-extern int darwinMainScreenY;
-
-#define ENABLE_DEBUG_LOG 1
-
-#ifdef ENABLE_DEBUG_LOG
-extern FILE *debug_log_fp;
-#define DEBUG_LOG_NAME "x11-debug.txt"
-#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%s:%d " msg, threadSafetyID(pthread_self()), __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
-#else
-#define DEBUG_LOG(msg, args...)
-#endif
-
-#define TRACE() DEBUG_LOG("\n")
-
-#endif /* _DARWIN_H */
+/*
+ * Copyright (C) 2008 Apple, Inc.
+ * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written authorization.
+ */
+
+#ifndef _DARWIN_H
+#define _DARWIN_H
+
+#include <IOKit/IOTypes.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include <X11/extensions/XKB.h>
+#include <assert.h>
+
+#include "threadSafety.h"
+
+#include "darwinfb.h"
+
+// From darwin.c
+void DarwinPrintBanner(void);
+int DarwinParseModifierList(const char *constmodifiers, int separatelr);
+void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
+void xf86SetRootClip (ScreenPtr pScreen, int enable);
+
+#define SCREEN_PRIV(pScreen) ((DarwinFramebufferPtr) \
+ dixLookupPrivate(&pScreen->devPrivates, darwinScreenKey))
+
+/*
+ * Global variables from darwin.c
+ */
+extern DevPrivateKey darwinScreenKey; // index into pScreen.devPrivates
+extern int darwinScreensFound;
+extern io_connect_t darwinParamConnect;
+extern int darwinEventReadFD;
+extern int darwinEventWriteFD;
+extern DeviceIntPtr darwinPointer;
+extern DeviceIntPtr darwinTabletCurrent;
+extern DeviceIntPtr darwinTabletCursor;
+extern DeviceIntPtr darwinTabletStylus;
+extern DeviceIntPtr darwinTabletEraser;
+extern DeviceIntPtr darwinKeyboard;
+
+// User preferences
+extern int darwinMouseAccelChange;
+extern int darwinFakeButtons;
+extern int darwinFakeMouse2Mask;
+extern int darwinFakeMouse3Mask;
+extern unsigned int darwinAppKitModMask;
+extern unsigned int windowItemModMask;
+extern int darwinSyncKeymap;
+extern int darwinDesiredDepth;
+
+// location of X11's (0,0) point in global screen coordinates
+extern int darwinMainScreenX;
+extern int darwinMainScreenY;
+
+#define ENABLE_DEBUG_LOG 1
+
+#ifdef ENABLE_DEBUG_LOG
+extern FILE *debug_log_fp;
+#define DEBUG_LOG_NAME "x11-debug.txt"
+#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%s:%d " msg, threadSafetyID(pthread_self()), __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
+#else
+#define DEBUG_LOG(msg, args...)
+#endif
+
+#define TRACE() DEBUG_LOG("\n")
+
+#endif /* _DARWIN_H */
diff --git a/xorg-server/hw/xquartz/xpr/xprScreen.c b/xorg-server/hw/xquartz/xpr/xprScreen.c
index 22a727e67..44067862f 100644
--- a/xorg-server/hw/xquartz/xpr/xprScreen.c
+++ b/xorg-server/hw/xquartz/xpr/xprScreen.c
@@ -1,440 +1,453 @@
-/*
- * Xplugin rootless implementation screen functions
- *
- * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
- * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#include "sanitizedCarbon.h"
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartzCommon.h"
-#include "inputstr.h"
-#include "quartz.h"
-#include "xpr.h"
-#include "xprEvent.h"
-#include "pseudoramiX.h"
-#include "darwin.h"
-#include "darwinEvents.h"
-#include "rootless.h"
-#include "dri.h"
-#include "globals.h"
-#include <Xplugin.h>
-#include "applewmExt.h"
-#include "micmap.h"
-
-#include "rootlessCommon.h"
-
-#ifdef DAMAGE
-# include "damage.h"
-#endif
-
-/* 10.4's deferred update makes X slower.. have to live with the tearing
- for now.. */
-#define XP_NO_DEFERRED_UPDATES 8
-
-// Name of GLX bundle for native OpenGL
-static const char *xprOpenGLBundle = "glxCGL.bundle";
-
-/*
- * eventHandler
- * Callback handler for Xplugin events.
- */
-static void eventHandler(unsigned int type, const void *arg,
- unsigned int arg_size, void *data) {
-
- switch (type) {
- case XP_EVENT_DISPLAY_CHANGED:
- DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
- DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
- break;
-
- case XP_EVENT_WINDOW_STATE_CHANGED:
- if (arg_size >= sizeof(xp_window_state_event)) {
- const xp_window_state_event *ws_arg = arg;
-
- DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
- DarwinSendDDXEvent(kXquartzWindowState, 2,
- ws_arg->id, ws_arg->state);
- } else {
- DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
- }
- break;
-
- case XP_EVENT_WINDOW_MOVED:
- DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
- if (arg_size == sizeof(xp_window_id)) {
- xp_window_id id = * (xp_window_id *) arg;
- DarwinSendDDXEvent(kXquartzWindowMoved, 1, id);
- }
- break;
-
- case XP_EVENT_SURFACE_DESTROYED:
- DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
- case XP_EVENT_SURFACE_CHANGED:
- DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
- if (arg_size == sizeof(xp_surface_id)) {
- int kind;
-
- if (type == XP_EVENT_SURFACE_DESTROYED)
- kind = AppleDRISurfaceNotifyDestroyed;
- else
- kind = AppleDRISurfaceNotifyChanged;
-
- DRISurfaceNotify(*(xp_surface_id *) arg, kind);
- }
- break;
-#ifdef XP_EVENT_SPACE_CHANGED
- case XP_EVENT_SPACE_CHANGED:
- DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n");
- if(arg_size == sizeof(uint32_t)) {
- uint32_t space_id = *(uint32_t *)arg;
- DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
- }
- break;
-#endif
- default:
- ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
- }
-}
-
-/*
- * displayAtIndex
- * Return the display ID for a particular display index.
- */
-static CGDirectDisplayID
-displayAtIndex(int index)
-{
- CGError err;
- CGDisplayCount cnt;
- CGDirectDisplayID dpy[index+1];
-
- err = CGGetActiveDisplayList(index + 1, dpy, &cnt);
- if (err == kCGErrorSuccess && cnt == index + 1)
- return dpy[index];
- else
- return kCGNullDirectDisplay;
-}
-
-/*
- * displayScreenBounds
- * Return the bounds of a particular display.
- */
-static CGRect
-displayScreenBounds(CGDirectDisplayID id)
-{
- CGRect frame;
-
- frame = CGDisplayBounds(id);
-
- DEBUG_LOG(" %dx%d @ (%d,%d).\n",
- (int)frame.size.width, (int)frame.size.height,
- (int)frame.origin.x, (int)frame.origin.y);
-
- /* Remove menubar to help standard X11 window managers. */
- if (quartzEnableRootless &&
- frame.origin.x == 0 && frame.origin.y == 0) {
- frame.origin.y += aquaMenuBarHeight;
- frame.size.height -= aquaMenuBarHeight;
- }
-
- DEBUG_LOG(" %dx%d @ (%d,%d).\n",
- (int)frame.size.width, (int)frame.size.height,
- (int)frame.origin.x, (int)frame.origin.y);
-
- return frame;
-}
-
-/*
- * xprAddPseudoramiXScreens
- * Add a single virtual screen encompassing all the physical screens
- * with PseudoramiX.
- */
-static void
-xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
-{
- CGDisplayCount i, displayCount;
- CGDirectDisplayID *displayList = NULL;
- CGRect unionRect = CGRectNull, frame;
-
- // Find all the CoreGraphics displays
- CGGetActiveDisplayList(0, NULL, &displayCount);
- displayList = xalloc(displayCount * sizeof(CGDirectDisplayID));
- CGGetActiveDisplayList(displayCount, displayList, &displayCount);
-
- /* Get the union of all screens */
- for (i = 0; i < displayCount; i++) {
- CGDirectDisplayID dpy = displayList[i];
- frame = displayScreenBounds(dpy);
- unionRect = CGRectUnion(unionRect, frame);
- }
-
- /* Use unionRect as the screen size for the X server. */
- *x = unionRect.origin.x;
- *y = unionRect.origin.y;
- *width = unionRect.size.width;
- *height = unionRect.size.height;
-
- DEBUG_LOG(" screen union origin: (%d,%d) size: (%d,%d).\n",
- *x, *y, *width, *height);
-
- /* Tell PseudoramiX about the real screens. */
- for (i = 0; i < displayCount; i++)
- {
- CGDirectDisplayID dpy = displayList[i];
-
- frame = displayScreenBounds(dpy);
- frame.origin.x -= unionRect.origin.x;
- frame.origin.y -= unionRect.origin.y;
-
- DEBUG_LOG(" placed at X11 coordinate (%d,%d).\n",
- (int)frame.origin.x, (int)frame.origin.y);
-
- PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
- frame.size.width, frame.size.height);
- }
-
- xfree(displayList);
-}
-
-/*
- * xprDisplayInit
- * Find number of CoreGraphics displays and initialize Xplugin.
- */
-static void
-xprDisplayInit(void)
-{
- CGDisplayCount displayCount;
-
- DEBUG_LOG("");
-
- CGGetActiveDisplayList(0, NULL, &displayCount);
-
- /* With PseudoramiX, the X server only sees one screen; only PseudoramiX
- itself knows about all of the screens. */
-
- if (noPseudoramiXExtension)
- darwinScreensFound = displayCount;
- else
- darwinScreensFound = 1;
-
- if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success)
- FatalError("Could not initialize the Xplugin library.");
-
- xp_select_events(XP_EVENT_DISPLAY_CHANGED
- | XP_EVENT_WINDOW_STATE_CHANGED
- | XP_EVENT_WINDOW_MOVED
-#ifdef XP_EVENT_SPACE_CHANGED
- | XP_EVENT_SPACE_CHANGED
-#endif
- | XP_EVENT_SURFACE_CHANGED
- | XP_EVENT_SURFACE_DESTROYED,
- eventHandler, NULL);
-
- AppleDRIExtensionInit();
- xprAppleWMInit();
-
- if (!quartzEnableRootless)
- RootlessHideAllWindows();
-}
-
-/*
- * xprAddScreen
- * Init the framebuffer and record pixmap parameters for the screen.
- */
-static Bool
-xprAddScreen(int index, ScreenPtr pScreen)
-{
- DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
- int depth = darwinDesiredDepth;
-
- DEBUG_LOG("index=%d depth=%d\n", index, depth);
-
- if(depth == -1) {
- depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
- }
-
- switch(depth) {
- case 8: // pseudo-working
- dfb->visuals = PseudoColorMask;
- dfb->preferredCVC = PseudoColor;
- dfb->depth = 8;
- dfb->bitsPerRGB = 8;
- dfb->bitsPerPixel = 8;
- dfb->redMask = 0;
- dfb->greenMask = 0;
- dfb->blueMask = 0;
- break;
- case 15:
- dfb->visuals = TrueColorMask; //LARGE_VISUALS;
- dfb->preferredCVC = TrueColor;
- dfb->depth = 15;
- dfb->bitsPerRGB = 5;
- dfb->bitsPerPixel = 16;
- dfb->redMask = RM_ARGB(0,5,5,5);
- dfb->greenMask = GM_ARGB(0,5,5,5);
- dfb->blueMask = BM_ARGB(0,5,5,5);
- break;
-// case 24:
- default:
- if(depth != 24)
- 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));
- dfb->visuals = TrueColorMask; //LARGE_VISUALS;
- dfb->preferredCVC = TrueColor;
- dfb->depth = 24;
- dfb->bitsPerRGB = 8;
- dfb->bitsPerPixel = 32;
- dfb->redMask = RM_ARGB(0,8,8,8);
- dfb->greenMask = GM_ARGB(0,8,8,8);
- dfb->blueMask = BM_ARGB(0,8,8,8);
- break;
- }
-
- if (noPseudoramiXExtension)
- {
- CGDirectDisplayID dpy;
- CGRect frame;
-
- ErrorF("Warning: noPseudoramiXExtension!\n");
-
- dpy = displayAtIndex(index);
-
- frame = displayScreenBounds(dpy);
-
- dfb->x = frame.origin.x;
- dfb->y = frame.origin.y;
- dfb->width = frame.size.width;
- dfb->height = frame.size.height;
- }
- else
- {
- xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height);
- }
-
- /* Passing zero width (pitch) makes miCreateScreenResources set the
- screen pixmap to the framebuffer pointer, i.e. NULL. The generic
- rootless code takes care of making this work. */
- dfb->pitch = 0;
- dfb->framebuffer = NULL;
-
- DRIScreenInit(pScreen);
-
- return TRUE;
-}
-
-/*
- * xprSetupScreen
- * Setup the screen for rootless access.
- */
-static Bool
-xprSetupScreen(int index, ScreenPtr pScreen)
-{
- // Initialize accelerated rootless drawing
- // Note that this must be done before DamageSetup().
-
- // These are crashing ugly... better to be stable and not crash for now.
- //RootlessAccelInit(pScreen);
-
-#ifdef DAMAGE
- // The Damage extension needs to wrap underneath the
- // generic rootless layer, so do it now.
- if (!DamageSetup(pScreen))
- return FALSE;
-#endif
-
- // Initialize generic rootless code
- if (!xprInit(pScreen))
- return FALSE;
-
- return DRIFinishScreenInit(pScreen);
-}
-
-/*
- * xprUpdateScreen
- * Update screen after configuation change.
- */
-static void
-xprUpdateScreen(ScreenPtr pScreen)
-{
- rootlessGlobalOffsetX = darwinMainScreenX;
- rootlessGlobalOffsetY = darwinMainScreenY;
-
- AppleWMSetScreenOrigin(WindowTable[pScreen->myNum]);
-
- RootlessRepositionWindows(pScreen);
- RootlessUpdateScreenPixmap(pScreen);
-}
-
-/*
- * xprInitInput
- * Finalize xpr specific setup.
- */
-static void
-xprInitInput(int argc, char **argv)
-{
- int i;
-
- rootlessGlobalOffsetX = darwinMainScreenX;
- rootlessGlobalOffsetY = darwinMainScreenY;
-
- for (i = 0; i < screenInfo.numScreens; i++)
- AppleWMSetScreenOrigin(WindowTable[i]);
-}
-
-/*
- * Quartz display mode function list.
- */
-static QuartzModeProcsRec xprModeProcs = {
- xprDisplayInit,
- xprAddScreen,
- xprSetupScreen,
- xprInitInput,
- QuartzInitCursor,
- QuartzSuspendXCursor,
- QuartzResumeXCursor,
- xprAddPseudoramiXScreens,
- xprUpdateScreen,
- xprIsX11Window,
- xprHideWindows,
- RootlessFrameForWindow,
- TopLevelParent,
- DRICreateSurface,
- DRIDestroySurface
-};
-
-/*
- * QuartzModeBundleInit
- * Initialize the display mode bundle after loading.
- */
-Bool
-QuartzModeBundleInit(void)
-{
- quartzProcs = &xprModeProcs;
- quartzOpenGLBundle = xprOpenGLBundle;
- return TRUE;
-}
+/*
+ * Xplugin rootless implementation screen functions
+ *
+ * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
+ * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written authorization.
+ */
+
+#include "sanitizedCarbon.h"
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "quartzCommon.h"
+#include "inputstr.h"
+#include "quartz.h"
+#include "xpr.h"
+#include "xprEvent.h"
+#include "pseudoramiX.h"
+#include "darwin.h"
+#include "darwinEvents.h"
+#include "rootless.h"
+#include "dri.h"
+#include "globals.h"
+#include <Xplugin.h>
+#include "applewmExt.h"
+#include "micmap.h"
+
+#include "rootlessCommon.h"
+
+#ifdef DAMAGE
+# include "damage.h"
+#endif
+
+/* 10.4's deferred update makes X slower.. have to live with the tearing
+ for now.. */
+#define XP_NO_DEFERRED_UPDATES 8
+
+// Name of GLX bundle for native OpenGL
+static const char *xprOpenGLBundle = "glxCGL.bundle";
+
+/*
+ * eventHandler
+ * Callback handler for Xplugin events.
+ */
+static void eventHandler(unsigned int type, const void *arg,
+ unsigned int arg_size, void *data) {
+
+ switch (type) {
+ case XP_EVENT_DISPLAY_CHANGED:
+ DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
+ DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
+ break;
+
+ case XP_EVENT_WINDOW_STATE_CHANGED:
+ if (arg_size >= sizeof(xp_window_state_event)) {
+ const xp_window_state_event *ws_arg = arg;
+
+ DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
+ DarwinSendDDXEvent(kXquartzWindowState, 2,
+ ws_arg->id, ws_arg->state);
+ } else {
+ DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
+ }
+ break;
+
+ case XP_EVENT_WINDOW_MOVED:
+ DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
+ if (arg_size == sizeof(xp_window_id)) {
+ xp_window_id id = * (xp_window_id *) arg;
+ DarwinSendDDXEvent(kXquartzWindowMoved, 1, id);
+ }
+ break;
+
+ case XP_EVENT_SURFACE_DESTROYED:
+ DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
+ case XP_EVENT_SURFACE_CHANGED:
+ DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
+ if (arg_size == sizeof(xp_surface_id)) {
+ int kind;
+
+ if (type == XP_EVENT_SURFACE_DESTROYED)
+ kind = AppleDRISurfaceNotifyDestroyed;
+ else
+ kind = AppleDRISurfaceNotifyChanged;
+
+ DRISurfaceNotify(*(xp_surface_id *) arg, kind);
+ }
+ break;
+#ifdef XP_EVENT_SPACE_CHANGED
+ case XP_EVENT_SPACE_CHANGED:
+ DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n");
+ if(arg_size == sizeof(uint32_t)) {
+ uint32_t space_id = *(uint32_t *)arg;
+ DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
+ }
+ break;
+#endif
+ default:
+ ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
+ }
+}
+
+/*
+ * displayAtIndex
+ * Return the display ID for a particular display index.
+ */
+static CGDirectDisplayID
+displayAtIndex(int index)
+{
+ CGError err;
+ CGDisplayCount cnt;
+ CGDirectDisplayID dpy[index+1];
+
+ err = CGGetActiveDisplayList(index + 1, dpy, &cnt);
+ if (err == kCGErrorSuccess && cnt == index + 1)
+ return dpy[index];
+ else
+ return kCGNullDirectDisplay;
+}
+
+/*
+ * displayScreenBounds
+ * Return the bounds of a particular display.
+ */
+static CGRect
+displayScreenBounds(CGDirectDisplayID id)
+{
+ CGRect frame;
+
+ frame = CGDisplayBounds(id);
+
+ DEBUG_LOG(" %dx%d @ (%d,%d).\n",
+ (int)frame.size.width, (int)frame.size.height,
+ (int)frame.origin.x, (int)frame.origin.y);
+
+ /* Remove menubar to help standard X11 window managers. */
+ if (quartzEnableRootless &&
+ frame.origin.x == 0 && frame.origin.y == 0) {
+ frame.origin.y += aquaMenuBarHeight;
+ frame.size.height -= aquaMenuBarHeight;
+ }
+
+ DEBUG_LOG(" %dx%d @ (%d,%d).\n",
+ (int)frame.size.width, (int)frame.size.height,
+ (int)frame.origin.x, (int)frame.origin.y);
+
+ return frame;
+}
+
+/*
+ * xprAddPseudoramiXScreens
+ * Add a single virtual screen encompassing all the physical screens
+ * with PseudoramiX.
+ */
+static void
+xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
+{
+ CGDisplayCount i, displayCount;
+ CGDirectDisplayID *displayList = NULL;
+ CGRect unionRect = CGRectNull, frame;
+
+ // Find all the CoreGraphics displays
+ CGGetActiveDisplayList(0, NULL, &displayCount);
+ DEBUG_LOG("displayCount: %d\n", (int)displayCount);
+
+ if(!displayCount) {
+ ErrorF("CoreGraphics has reported no connected displays. Creating a stub 800x600 display.\n");
+ *x = *y = 0;
+ *width = 800;
+ *height = 600;
+ PseudoramiXAddScreen(*x, *y, *width, *height);
+ return;
+ }
+
+ displayList = xalloc(displayCount * sizeof(CGDirectDisplayID));
+ if(!displayList)
+ FatalError("Unable to allocate memory for list of displays.\n");
+ CGGetActiveDisplayList(displayCount, displayList, &displayCount);
+
+ /* Get the union of all screens */
+ for (i = 0; i < displayCount; i++) {
+ CGDirectDisplayID dpy = displayList[i];
+ frame = displayScreenBounds(dpy);
+ unionRect = CGRectUnion(unionRect, frame);
+ }
+
+ /* Use unionRect as the screen size for the X server. */
+ *x = unionRect.origin.x;
+ *y = unionRect.origin.y;
+ *width = unionRect.size.width;
+ *height = unionRect.size.height;
+
+ DEBUG_LOG(" screen union origin: (%d,%d) size: (%d,%d).\n",
+ *x, *y, *width, *height);
+
+ /* Tell PseudoramiX about the real screens. */
+ for (i = 0; i < displayCount; i++)
+ {
+ CGDirectDisplayID dpy = displayList[i];
+
+ frame = displayScreenBounds(dpy);
+ frame.origin.x -= unionRect.origin.x;
+ frame.origin.y -= unionRect.origin.y;
+
+ DEBUG_LOG(" placed at X11 coordinate (%d,%d).\n",
+ (int)frame.origin.x, (int)frame.origin.y);
+
+ PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
+ frame.size.width, frame.size.height);
+ }
+
+ xfree(displayList);
+}
+
+/*
+ * xprDisplayInit
+ * Find number of CoreGraphics displays and initialize Xplugin.
+ */
+static void
+xprDisplayInit(void)
+{
+ CGDisplayCount displayCount;
+
+ DEBUG_LOG("");
+
+ CGGetActiveDisplayList(0, NULL, &displayCount);
+
+ /* With PseudoramiX, the X server only sees one screen; only PseudoramiX
+ itself knows about all of the screens. */
+
+ if (noPseudoramiXExtension)
+ darwinScreensFound = displayCount;
+ else
+ darwinScreensFound = 1;
+
+ if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success)
+ FatalError("Could not initialize the Xplugin library.");
+
+ xp_select_events(XP_EVENT_DISPLAY_CHANGED
+ | XP_EVENT_WINDOW_STATE_CHANGED
+ | XP_EVENT_WINDOW_MOVED
+#ifdef XP_EVENT_SPACE_CHANGED
+ | XP_EVENT_SPACE_CHANGED
+#endif
+ | XP_EVENT_SURFACE_CHANGED
+ | XP_EVENT_SURFACE_DESTROYED,
+ eventHandler, NULL);
+
+ AppleDRIExtensionInit();
+ xprAppleWMInit();
+
+ if (!quartzEnableRootless)
+ RootlessHideAllWindows();
+}
+
+/*
+ * xprAddScreen
+ * Init the framebuffer and record pixmap parameters for the screen.
+ */
+static Bool
+xprAddScreen(int index, ScreenPtr pScreen)
+{
+ DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
+ int depth = darwinDesiredDepth;
+
+ DEBUG_LOG("index=%d depth=%d\n", index, depth);
+
+ if(depth == -1) {
+ depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
+ }
+
+ switch(depth) {
+ case 8: // pseudo-working
+ dfb->visuals = PseudoColorMask;
+ dfb->preferredCVC = PseudoColor;
+ dfb->depth = 8;
+ dfb->bitsPerRGB = 8;
+ dfb->bitsPerPixel = 8;
+ dfb->redMask = 0;
+ dfb->greenMask = 0;
+ dfb->blueMask = 0;
+ break;
+ case 15:
+ dfb->visuals = TrueColorMask; //LARGE_VISUALS;
+ dfb->preferredCVC = TrueColor;
+ dfb->depth = 15;
+ dfb->bitsPerRGB = 5;
+ dfb->bitsPerPixel = 16;
+ dfb->redMask = RM_ARGB(0,5,5,5);
+ dfb->greenMask = GM_ARGB(0,5,5,5);
+ dfb->blueMask = BM_ARGB(0,5,5,5);
+ break;
+// case 24:
+ default:
+ if(depth != 24)
+ 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));
+ dfb->visuals = TrueColorMask; //LARGE_VISUALS;
+ dfb->preferredCVC = TrueColor;
+ dfb->depth = 24;
+ dfb->bitsPerRGB = 8;
+ dfb->bitsPerPixel = 32;
+ dfb->redMask = RM_ARGB(0,8,8,8);
+ dfb->greenMask = GM_ARGB(0,8,8,8);
+ dfb->blueMask = BM_ARGB(0,8,8,8);
+ break;
+ }
+
+ if (noPseudoramiXExtension)
+ {
+ CGDirectDisplayID dpy;
+ CGRect frame;
+
+ ErrorF("Warning: noPseudoramiXExtension!\n");
+
+ dpy = displayAtIndex(index);
+
+ frame = displayScreenBounds(dpy);
+
+ dfb->x = frame.origin.x;
+ dfb->y = frame.origin.y;
+ dfb->width = frame.size.width;
+ dfb->height = frame.size.height;
+ }
+ else
+ {
+ xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height);
+ }
+
+ /* Passing zero width (pitch) makes miCreateScreenResources set the
+ screen pixmap to the framebuffer pointer, i.e. NULL. The generic
+ rootless code takes care of making this work. */
+ dfb->pitch = 0;
+ dfb->framebuffer = NULL;
+
+ DRIScreenInit(pScreen);
+
+ return TRUE;
+}
+
+/*
+ * xprSetupScreen
+ * Setup the screen for rootless access.
+ */
+static Bool
+xprSetupScreen(int index, ScreenPtr pScreen)
+{
+ // Initialize accelerated rootless drawing
+ // Note that this must be done before DamageSetup().
+
+ // These are crashing ugly... better to be stable and not crash for now.
+ //RootlessAccelInit(pScreen);
+
+#ifdef DAMAGE
+ // The Damage extension needs to wrap underneath the
+ // generic rootless layer, so do it now.
+ if (!DamageSetup(pScreen))
+ return FALSE;
+#endif
+
+ // Initialize generic rootless code
+ if (!xprInit(pScreen))
+ return FALSE;
+
+ return DRIFinishScreenInit(pScreen);
+}
+
+/*
+ * xprUpdateScreen
+ * Update screen after configuation change.
+ */
+static void
+xprUpdateScreen(ScreenPtr pScreen)
+{
+ rootlessGlobalOffsetX = darwinMainScreenX;
+ rootlessGlobalOffsetY = darwinMainScreenY;
+
+ AppleWMSetScreenOrigin(WindowTable[pScreen->myNum]);
+
+ RootlessRepositionWindows(pScreen);
+ RootlessUpdateScreenPixmap(pScreen);
+}
+
+/*
+ * xprInitInput
+ * Finalize xpr specific setup.
+ */
+static void
+xprInitInput(int argc, char **argv)
+{
+ int i;
+
+ rootlessGlobalOffsetX = darwinMainScreenX;
+ rootlessGlobalOffsetY = darwinMainScreenY;
+
+ for (i = 0; i < screenInfo.numScreens; i++)
+ AppleWMSetScreenOrigin(WindowTable[i]);
+}
+
+/*
+ * Quartz display mode function list.
+ */
+static QuartzModeProcsRec xprModeProcs = {
+ xprDisplayInit,
+ xprAddScreen,
+ xprSetupScreen,
+ xprInitInput,
+ QuartzInitCursor,
+ QuartzSuspendXCursor,
+ QuartzResumeXCursor,
+ xprAddPseudoramiXScreens,
+ xprUpdateScreen,
+ xprIsX11Window,
+ xprHideWindows,
+ RootlessFrameForWindow,
+ TopLevelParent,
+ DRICreateSurface,
+ DRIDestroySurface
+};
+
+/*
+ * QuartzModeBundleInit
+ * Initialize the display mode bundle after loading.
+ */
+Bool
+QuartzModeBundleInit(void)
+{
+ quartzProcs = &xprModeProcs;
+ quartzOpenGLBundle = xprOpenGLBundle;
+ return TRUE;
+}