xserver: Branch 'xorg-server-1.2-apple' - 4 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Tue Dec 4 18:01:44 PST 2007


 configure.ac                                                   |    3 
 dev/null                                                       |binary
 hw/darwin/Makefile.am                                          |   58 
 hw/darwin/Xquartz.man                                          |  156 -
 hw/darwin/apple/English.lproj/main.nib/classes.nib             |  318 ---
 hw/darwin/apple/English.lproj/main.nib/info.nib                |   18 
 hw/darwin/apple/Info.plist                                     |   37 
 hw/darwin/apple/Makefile.am                                    |   28 
 hw/darwin/apple/X11.xcodeproj/project.pbxproj                  |  344 ---
 hw/darwin/apple/bundle-main.c                                  |   82 
 hw/darwin/apple/launcher-main.c                                |   81 
 hw/darwin/apple/org.x.X11.plist                                |   25 
 hw/darwin/apple/server-main.c                                  |  904 ----------
 hw/darwin/quartz/Makefile.am                                   |   38 
 hw/darwin/quartz/X11Application.m                              |    3 
 hw/darwin/quartz/X11Controller.h                               |    2 
 hw/darwin/quartz/Xplugin.h                                     |  589 ------
 hw/darwin/quartz/apple/English.lproj/InfoPlist.strings         |binary
 hw/darwin/quartz/apple/English.lproj/Localizable.strings       |binary
 hw/darwin/quartz/apple/English.lproj/main.nib/classes.nib      |  318 +++
 hw/darwin/quartz/apple/English.lproj/main.nib/info.nib         |   18 
 hw/darwin/quartz/apple/English.lproj/main.nib/keyedobjects.nib |binary
 hw/darwin/quartz/apple/Info.plist                              |   37 
 hw/darwin/quartz/apple/Makefile.am                             |   28 
 hw/darwin/quartz/apple/X11.icns                                |binary
 hw/darwin/quartz/apple/X11.xcodeproj/project.pbxproj           |  344 +++
 hw/darwin/quartz/apple/bundle-main.c                           |   82 
 hw/darwin/quartz/apple/launcher-main.c                         |   81 
 hw/darwin/quartz/apple/org.x.X11.plist                         |   25 
 hw/darwin/quartz/apple/server-main.c                           |  904 ++++++++++
 hw/darwin/quartz/appledri.c                                    |  353 ---
 hw/darwin/quartz/appledri.h                                    |  106 -
 hw/darwin/quartz/appledristr.h                                 |  175 -
 hw/darwin/quartz/dri.c                                         |  760 --------
 hw/darwin/quartz/dri.h                                         |  128 -
 hw/darwin/quartz/dristruct.h                                   |   81 
 hw/darwin/quartz/x-hash.c                                      |  343 ---
 hw/darwin/quartz/x-hash.h                                      |   60 
 hw/darwin/quartz/x-hook.c                                      |  109 -
 hw/darwin/quartz/x-hook.h                                      |   42 
 hw/darwin/quartz/x-list.c                                      |  337 ---
 hw/darwin/quartz/x-list.h                                      |   77 
 hw/darwin/quartz/xpr.h                                         |   47 
 hw/darwin/quartz/xpr/Makefile.am                               |   71 
 hw/darwin/quartz/xpr/Xplugin.h                                 |  589 ++++++
 hw/darwin/quartz/xpr/Xquartz.man                               |  156 +
 hw/darwin/quartz/xpr/appledri.c                                |  353 +++
 hw/darwin/quartz/xpr/appledri.h                                |  106 +
 hw/darwin/quartz/xpr/appledristr.h                             |  175 +
 hw/darwin/quartz/xpr/dri.c                                     |  760 ++++++++
 hw/darwin/quartz/xpr/dri.h                                     |  128 +
 hw/darwin/quartz/xpr/dristruct.h                               |   81 
 hw/darwin/quartz/xpr/x-hash.c                                  |  343 +++
 hw/darwin/quartz/xpr/x-hash.h                                  |   60 
 hw/darwin/quartz/xpr/x-hook.c                                  |  109 +
 hw/darwin/quartz/xpr/x-hook.h                                  |   42 
 hw/darwin/quartz/xpr/x-list.c                                  |  337 +++
 hw/darwin/quartz/xpr/x-list.h                                  |   77 
 hw/darwin/quartz/xpr/xpr.h                                     |   47 
 hw/darwin/quartz/xpr/xprAppleWM.c                              |  100 +
 hw/darwin/quartz/xpr/xprCursor.c                               |  431 ++++
 hw/darwin/quartz/xpr/xprFrame.c                                |  538 +++++
 hw/darwin/quartz/xpr/xprScreen.c                               |  416 ++++
 hw/darwin/quartz/xprAppleWM.c                                  |  100 -
 hw/darwin/quartz/xprCursor.c                                   |  431 ----
 hw/darwin/quartz/xprFrame.c                                    |  538 -----
 hw/darwin/quartz/xprScreen.c                                   |  416 ----
 67 files changed, 6778 insertions(+), 6767 deletions(-)

New commits:
commit e8399fd4d66a2b77b770c277e2fa424229a721b2
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Tue Dec 4 17:59:13 2007 -0800

    Darwin: Rework build system to more accurately reveal code infrastructure and facilitate future modularity.

diff --git a/configure.ac b/configure.ac
index 170243a..7b1b78f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2028,8 +2028,8 @@ hw/xgl/glxext/module/Makefile
 hw/xnest/Makefile
 hw/xwin/Makefile
 hw/darwin/Makefile
-hw/darwin/apple/Makefile
 hw/darwin/quartz/Makefile
+hw/darwin/quartz/apple/Makefile
 hw/darwin/quartz/xpr/Makefile
 hw/kdrive/Makefile
 hw/kdrive/ati/Makefile
diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 75fc4d9..0311b3e 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -1,22 +1,14 @@
+noinst_LTLIBRARIES = libXdarwin.la
 AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_CPPFLAGS = \
 	-DBUILD_DATE=\"$(BUILD_DATE)\" \
 	-DINXQUARTZ \
 	-DUSE_NEW_CLUT \
-	-DXFree86Server \
-	-I$(top_srcdir)/miext/rootless
+	-DXFree86Server
 
-if X11APP
-X11APP_SUBDIRS = apple
-endif
+SUBDIRS = . quartz
 
-SUBDIRS = quartz $(X11APP_SUBDIRS)
-DIST_SUBDIRS = quartz apple
-
-bin_PROGRAMS = Xquartz
-man1_MANS = Xquartz.man
-
-Xquartz_SOURCES = \
+libXdarwin_la_SOURCES = \
 	darwin.c \
 	darwinEvents.c \
 	darwinKeyboard.c \
@@ -24,49 +16,7 @@ Xquartz_SOURCES = \
 	$(top_srcdir)/fb/fbcmap.c \
 	$(top_srcdir)/mi/miinitext.c
 
-#		We should probably add these once they're working, or are these obsolete and to be removed?
-#		./quartz/cr/libcr.a
-#		./quartz/fullscreen/libfullscreen.a
-
-Xquartz_LDADD = \
-	./quartz/libXquartz.a \
-	./quartz/xpr/libxpr.a \
-	$(top_builddir)/dix/dixfonts.lo \
-	$(top_builddir)/dix/libdix.la \
-	$(top_builddir)/os/libos.la \
-	$(top_builddir)/dix/libxpstubs.la \
-	$(top_builddir)/miext/shadow/libshadow.la \
-	$(top_builddir)/fb/libfb.la \
-	$(top_builddir)/mi/libmi.la \
-	$(top_builddir)/composite/libcomposite.la \
-	$(top_builddir)/damageext/libdamageext.la \
-	$(top_builddir)/miext/damage/libdamage.la \
-	$(top_builddir)/xfixes/libxfixes.la \
-	$(top_builddir)/miext/cw/libcw.la \
-	$(top_builddir)/Xext/libXext.la \
-	$(top_builddir)/xkb/libxkb.la \
-	$(top_builddir)/xkb/libxkbstubs.la \
-	$(top_builddir)/Xi/libXi.la \
-	$(top_builddir)/dbe/libdbe.la \
-	$(top_builddir)/record/librecord.la \
-	$(top_builddir)/XTrap/libxtrap.la \
-	$(top_builddir)/miext/rootless/librootless.la \
-	$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
-	$(top_builddir)/miext/rootless/accel/librlAccel.la \
-	$(DARWIN_LIBS) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) -lXplugin
-
-Xquartz_LDFLAGS =  \
-	-XCClinker -Objc \
-	-Wl,-u,_miDCInitialize \
-	-Wl,-framework,Carbon \
-	-L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL \
-	-Wl,-framework,OpenGL \
-	-Wl,-framework,Cocoa \
-	-Wl,-framework,CoreAudio \
-	-Wl,-framework,IOKit
-
 EXTRA_DIST = \
-	Xquartz.man \
 	darwinClut8.h \
 	darwin.h \
 	darwinKeyboard.h
diff --git a/hw/darwin/Xquartz.man b/hw/darwin/Xquartz.man
deleted file mode 100644
index 37a7f1a..0000000
--- a/hw/darwin/Xquartz.man
+++ /dev/null
@@ -1,156 +0,0 @@
-.TH XQUARTZ 1 __vendorversion__
-.SH NAME
-Xquartz \- X window system server for Quartz operating system
-.SH SYNOPSIS
-.B Xquartz
-[ options ] ...
-.SH DESCRIPTION
-.I Xquartz
-is the X window server for Mac OS X provided by Apple.
-.I Xquartz
-runs in parallel with Aqua in rootless mode. In rootless mode, the X
-window system and Mac OS X share your display.  The root window of the
-X11 display is the size of the screen and contains all the other
-windows. The X11 root window is not displayed in rootless mode as Mac
-OS X handles the desktop background.
-.SH OPTIONS
-.PP
-In addition to the normal server options described in the \fIXserver(1)\fP
-manual page, \fIXquartz\fP accepts the following command line switches:
-.TP 8
-.B \-fakebuttons
-Emulates a 3 button mouse using modifier keys. By default, the Command modifier
-is used to emulate button 2 and Option is used for button 3. Thus, clicking the
-first mouse button while holding down Command will act like clicking
-button 2. Holding down Option will simulate button 3.
-.TP 8
-.B \-nofakebuttons
-Do not emulate a 3 button mouse. This is the default.
-.TP 8
-.B "\-fakemouse2 \fImodifiers\fP"
-Change the modifier keys used to emulate the second mouse button. By default,
-Command is used to emulate the second button. Any combination of the following
-modifier names may be used: Shift, Option, Control, Command, Fn. For example,
-.B \-fakemouse2 """Option,Shift""
-will set holding Option, Shift and clicking on button one as equivalent to
-clicking the second mouse button.
-.TP 8
-.B "\-fakemouse3 \fImodifiers\fP"
-Change the modifier keys used to emulate the third mouse button. By default,
-Option is used to emulate the third button. Any combination of the following
-modifier names may be used: Shift, Option, Control, Command, Fn. For example,
-.B \-fakemouse3 """Control,Shift""
-will set holding Control, Shift and clicking on button one as equivalent to
-clicking the third mouse button.
-.TP 8
-.B "\-swapAltMeta"
-Swaps the meaning of the Alt and Meta modifier keys.
-.TP 8
-.B "\-keymap \fIfile\fP"
-On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
-The default is to read this keymapping from USA.keymapping. With this option
-the keymapping will be read from \fIfile\fP instead. If the file's path is
-not specified, it will be searched for in Library/Keyboards/ underneath the
-following directories (in order): ~, /, /Network, /System.
-.TP 8
-.B \-nokeymap
-On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
-With this option \fIXquartz\fP queries the kernel for the current keymapping
-instead of reading it from a file. This will often fail on newer kernels.
-.TP 8
-.B "\-depth \fIdepth\fP"
-Specifies the color bit depth to use. Currently only 15, and 24 color
-bits per pixel are supported. If not specified, defaults to the depth
-of the main display.
-.SH CUSTOMIZATION
-\fIXquartz\fP can also be customized using the defaults(1) command. The available options are:
-.TP 8
-.B defaults write com.apple.x11 enable_fake_buttons -boolean true
-Equivalent to the \fB-fakebuttons\fP command line option.
-.TP 8
-.B defaults write com.apple.x11 fake_button2 \fImodifiers\fP
-Equivalent to the \fB-fakemouse2\fP option.
-.TP 8
-.B defaults write com.apple.x11 fake_button3 \fImodifiers\fP
-Equivalent to the \fB-fakemouse3\fP option.
-.TP 8
-.B defaults write com.apple.x11 swap_alt_meta -boolean true
-Equivalent to the \fB-swapAltMeta\fP option.
-.TP 8
-.B defaults write com.apple.x11 keymap_file \fIfilename\fP
-Equivalent to the \fB-keymap\fP option.
-.TP 8
-.B defaults write com.apple.x11 no_quit_alert -boolean true
-Disables the alert dialog displayed when attempting to quit X11.
-.TP 8
-.B defaults write com.apple.x11 no_auth -boolean true
-Stops the X server requiring that clients authenticate themselves when
-connecting. See Xsecurity(__miscmansuffix__).
-.TP 8
-.B defaults write com.apple.x11 nolisten_tcp -boolean true
-Prevents the X server accepting remote connections.
-.TP 8
-.B defaults write com.apple.x11 xinit_kills_server -boolean false
-Stops the X server exiting when the xinitrc script terminates.
-.TP 8
-.B defaults write com.apple.x11 fullscreen_hotkeys -boolean false
-Allows system hotkeys to be handled while in X11 fullscreen mode.
-.TP 8
-.B defaults write com.apple.x11 enable_system_beep -boolean false
-Don't use the standard system beep effect for X11 alerts.
-.TP 8
-.B defaults write com.apple.x11 enable_key_equivalents -boolean false
-Disable menu keyboard equivalents while X11 windows are focused.
-.TP 8
-.B defaults write com.apple.x11 depth \fIdepth\fP
-Equivalent to the \fB-depth\fP option.
-.SH "SEE ALSO"
-.PP
-X(__miscmansuffix__), XFree86(1), Xserver(1), xdm(1), xinit(1)
-.PP
-.SH AUTHORS
-XFree86 was originally ported to Mac OS X Server by John Carmack. Dave
-Zarzycki used this as the basis of his port of XFree86 4.0 to Darwin 1.0.
-Torrey T. Lyons improved and integrated this code into the XFree86
-Project's mainline for the 4.0.2 release.
-.PP
-The following members of the XonX Team contributed to the following
-releases (in alphabetical order):
-.TP 4
-XFree86 4.1.0:
-.br
-Rob Braun - Darwin x86 support
-.br
-Torrey T. Lyons - Project Lead
-.br
-Andreas Monitzer - Cocoa version of XDarwin front end
-.br
-Gregory Robert Parker - Original Quartz implementation
-.br
-Christoph Pfisterer - Dynamic shared X libraries
-.br
-Toshimitsu Tanaka - Japanese localization
-.TP 4
-XFree86 4.2.0:
-.br
-Rob Braun - Darwin x86 support
-.br
-Pablo Di Noto - Spanish localization
-.br
-Paul Edens - Dutch localization
-.br
-Kyunghwan Kim - Korean localization
-.br
-Mario Klebsch - Non-US keyboard support
-.br
-Torrey T. Lyons - Project Lead
-.br
-Andreas Monitzer - German localization
-.br
-Patrik Montgomery - Swedish localization
-.br
-Greg Parker - Rootless support
-.br
-Toshimitsu Tanaka - Japanese localization
-.br
-Olivier Verdier - French localization
diff --git a/hw/darwin/apple/English.lproj/InfoPlist.strings b/hw/darwin/apple/English.lproj/InfoPlist.strings
deleted file mode 100644
index 88e1f04..0000000
Binary files a/hw/darwin/apple/English.lproj/InfoPlist.strings and /dev/null differ
diff --git a/hw/darwin/apple/English.lproj/Localizable.strings b/hw/darwin/apple/English.lproj/Localizable.strings
deleted file mode 100644
index c83b085..0000000
Binary files a/hw/darwin/apple/English.lproj/Localizable.strings and /dev/null differ
diff --git a/hw/darwin/apple/English.lproj/main.nib/classes.nib b/hw/darwin/apple/English.lproj/main.nib/classes.nib
deleted file mode 100644
index a82159b..0000000
--- a/hw/darwin/apple/English.lproj/main.nib/classes.nib
+++ /dev/null
@@ -1,318 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>IBClasses</key>
-	<array>
-		<dict>
-			<key>CLASS</key>
-			<string>IBLibraryObjectTemplate</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>OUTLETS</key>
-			<dict>
-				<key>draggedView</key>
-				<string>NSView</string>
-				<key>representedObject</key>
-				<string>NSObject</string>
-			</dict>
-			<key>SUPERCLASS</key>
-			<string>NSView</string>
-		</dict>
-		<dict>
-			<key>CLASS</key>
-			<string>IBInspector</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>OUTLETS</key>
-			<dict>
-				<key>inspectorView</key>
-				<string>NSView</string>
-			</dict>
-			<key>SUPERCLASS</key>
-			<string>NSObject</string>
-		</dict>
-		<dict>
-			<key>CLASS</key>
-			<string>NSDateFormatter</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>SUPERCLASS</key>
-			<string>NSFormatter</string>
-		</dict>
-		<dict>
-			<key>ACTIONS</key>
-			<dict>
-				<key>apps_table_cancel</key>
-				<string>id</string>
-				<key>apps_table_delete</key>
-				<string>id</string>
-				<key>apps_table_done</key>
-				<string>id</string>
-				<key>apps_table_duplicate</key>
-				<string>id</string>
-				<key>apps_table_new</key>
-				<string>id</string>
-				<key>apps_table_show</key>
-				<string>id</string>
-				<key>bring_to_front</key>
-				<string>id</string>
-				<key>close_window</key>
-				<string>id</string>
-				<key>enable_fullscreen_changed</key>
-				<string>id</string>
-				<key>minimize_window</key>
-				<string>id</string>
-				<key>next_window</key>
-				<string>id</string>
-				<key>prefs_changed</key>
-				<string>id</string>
-				<key>prefs_show</key>
-				<string>id</string>
-				<key>previous_window</key>
-				<string>id</string>
-				<key>toggle_fullscreen</key>
-				<string>id</string>
-				<key>x11_help</key>
-				<string>id</string>
-				<key>zoom_window</key>
-				<string>id</string>
-			</dict>
-			<key>CLASS</key>
-			<string>X11Controller</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>OUTLETS</key>
-			<dict>
-				<key>apps_separator</key>
-				<string>id</string>
-				<key>apps_table</key>
-				<string>id</string>
-				<key>depth</key>
-				<string>id</string>
-				<key>dock_apps_menu</key>
-				<string>id</string>
-				<key>dock_menu</key>
-				<string>id</string>
-				<key>dock_window_separator</key>
-				<string>id</string>
-				<key>enable_auth</key>
-				<string>id</string>
-				<key>enable_fullscreen</key>
-				<string>id</string>
-				<key>enable_keyequivs</key>
-				<string>id</string>
-				<key>enable_tcp</key>
-				<string>id</string>
-				<key>fake_buttons</key>
-				<string>id</string>
-				<key>prefs_panel</key>
-				<string>id</string>
-				<key>sync_keymap</key>
-				<string>id</string>
-				<key>toggle_fullscreen_item</key>
-				<string>id</string>
-				<key>use_sysbeep</key>
-				<string>id</string>
-				<key>window_separator</key>
-				<string>id</string>
-				<key>x11_about_item</key>
-				<string>id</string>
-			</dict>
-			<key>SUPERCLASS</key>
-			<string>NSObject</string>
-		</dict>
-		<dict>
-			<key>CLASS</key>
-			<string>NSNumberFormatter</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>SUPERCLASS</key>
-			<string>NSFormatter</string>
-		</dict>
-		<dict>
-			<key>CLASS</key>
-			<string>NSFormatter</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>SUPERCLASS</key>
-			<string>NSObject</string>
-		</dict>
-		<dict>
-			<key>ACTIONS</key>
-			<dict>
-				<key>alignCenter:</key>
-				<string>id</string>
-				<key>alignJustified:</key>
-				<string>id</string>
-				<key>alignLeft:</key>
-				<string>id</string>
-				<key>alignRight:</key>
-				<string>id</string>
-				<key>arrangeInFront:</key>
-				<string>id</string>
-				<key>centerSelectionInVisibleArea:</key>
-				<string>id</string>
-				<key>changeFont:</key>
-				<string>id</string>
-				<key>checkSpelling:</key>
-				<string>id</string>
-				<key>clear:</key>
-				<string>id</string>
-				<key>clearRecentDocuments:</key>
-				<string>id</string>
-				<key>complete:</key>
-				<string>id</string>
-				<key>copy:</key>
-				<string>id</string>
-				<key>copyFont:</key>
-				<string>id</string>
-				<key>copyRuler:</key>
-				<string>id</string>
-				<key>cut:</key>
-				<string>id</string>
-				<key>delete:</key>
-				<string>id</string>
-				<key>deminiaturize:</key>
-				<string>id</string>
-				<key>fax:</key>
-				<string>id</string>
-				<key>hide:</key>
-				<string>id</string>
-				<key>hideOtherApplications:</key>
-				<string>id</string>
-				<key>loosenKerning:</key>
-				<string>id</string>
-				<key>lowerBaseline:</key>
-				<string>id</string>
-				<key>makeKeyAndOrderFront:</key>
-				<string>id</string>
-				<key>miniaturize:</key>
-				<string>id</string>
-				<key>newDocument:</key>
-				<string>id</string>
-				<key>openDocument:</key>
-				<string>id</string>
-				<key>orderBack:</key>
-				<string>id</string>
-				<key>orderFront:</key>
-				<string>id</string>
-				<key>orderFrontColorPanel:</key>
-				<string>id</string>
-				<key>orderFrontHelpPanel:</key>
-				<string>id</string>
-				<key>orderOut:</key>
-				<string>id</string>
-				<key>outline:</key>
-				<string>id</string>
-				<key>paste:</key>
-				<string>id</string>
-				<key>pasteAsPlainText:</key>
-				<string>id</string>
-				<key>pasteAsRichText:</key>
-				<string>id</string>
-				<key>pasteFont:</key>
-				<string>id</string>
-				<key>pasteRuler:</key>
-				<string>id</string>
-				<key>pause:</key>
-				<string>id</string>
-				<key>performClose:</key>
-				<string>id</string>
-				<key>performFindPanelAction:</key>
-				<string>id</string>
-				<key>performMiniaturize:</key>
-				<string>id</string>
-				<key>performZoom:</key>
-				<string>id</string>
-				<key>play:</key>
-				<string>id</string>
-				<key>print:</key>
-				<string>id</string>
-				<key>printDocument:</key>
-				<string>id</string>
-				<key>raiseBaseline:</key>
-				<string>id</string>
-				<key>record:</key>
-				<string>id</string>
-				<key>redo:</key>
-				<string>id</string>
-				<key>resume:</key>
-				<string>id</string>
-				<key>revertDocumentToSaved:</key>
-				<string>id</string>
-				<key>run:</key>
-				<string>id</string>
-				<key>runPageLayout:</key>
-				<string>id</string>
-				<key>runToolbarCustomizationPalette:</key>
-				<string>id</string>
-				<key>saveAllDocuments:</key>
-				<string>id</string>
-				<key>saveDocument:</key>
-				<string>id</string>
-				<key>saveDocumentAs:</key>
-				<string>id</string>
-				<key>saveDocumentTo:</key>
-				<string>id</string>
-				<key>selectAll:</key>
-				<string>id</string>
-				<key>selectText:</key>
-				<string>id</string>
-				<key>showGuessPanel:</key>
-				<string>id</string>
-				<key>showHelp:</key>
-				<string>id</string>
-				<key>start:</key>
-				<string>id</string>
-				<key>startSpeaking:</key>
-				<string>id</string>
-				<key>stop:</key>
-				<string>id</string>
-				<key>stopSpeaking:</key>
-				<string>id</string>
-				<key>subscript:</key>
-				<string>id</string>
-				<key>superscript:</key>
-				<string>id</string>
-				<key>terminate:</key>
-				<string>id</string>
-				<key>tightenKerning:</key>
-				<string>id</string>
-				<key>toggleContinuousSpellChecking:</key>
-				<string>id</string>
-				<key>toggleRuler:</key>
-				<string>id</string>
-				<key>toggleToolbarShown:</key>
-				<string>id</string>
-				<key>turnOffKerning:</key>
-				<string>id</string>
-				<key>turnOffLigatures:</key>
-				<string>id</string>
-				<key>underline:</key>
-				<string>id</string>
-				<key>undo:</key>
-				<string>id</string>
-				<key>unhideAllApplications:</key>
-				<string>id</string>
-				<key>unscript:</key>
-				<string>id</string>
-				<key>useAllLigatures:</key>
-				<string>id</string>
-				<key>useStandardKerning:</key>
-				<string>id</string>
-				<key>useStandardLigatures:</key>
-				<string>id</string>
-			</dict>
-			<key>CLASS</key>
-			<string>FirstResponder</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>SUPERCLASS</key>
-			<string>NSObject</string>
-		</dict>
-	</array>
-	<key>IBVersion</key>
-	<integer>1</integer>
-</dict>
-</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/info.nib b/hw/darwin/apple/English.lproj/main.nib/info.nib
deleted file mode 100644
index 88bc626..0000000
--- a/hw/darwin/apple/English.lproj/main.nib/info.nib
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>IBFramework Version</key>
-	<string>588</string>
-	<key>IBOpenObjects</key>
-	<array>
-		<integer>244</integer>
-		<integer>29</integer>
-		<integer>423</integer>
-	</array>
-	<key>IBSystem Version</key>
-	<string>9A356</string>
-	<key>targetFramework</key>
-	<string>IBCocoaFramework</string>
-</dict>
-</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib b/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib
deleted file mode 100644
index 8b31450..0000000
Binary files a/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib and /dev/null differ
diff --git a/hw/darwin/apple/Info.plist b/hw/darwin/apple/Info.plist
deleted file mode 100644
index 9437f77..0000000
--- a/hw/darwin/apple/Info.plist
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>X11</string>
-	<key>CFBundleGetInfoString</key>
-	<string>X11</string>
-	<key>CFBundleIconFile</key>
-	<string>X11.icns</string>
-	<key>CFBundleIdentifier</key>
-	<string>org.x.X11</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleName</key>
-	<string>X11</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleShortVersionString</key>
-	<string>2.1.0</string>
-	<key>CFBundleSignature</key>
-	<string>x11a</string>
-	<key>CSResourcesFileMapped</key>
-	<true/>
-	<key>NSHumanReadableCopyright</key>
-	<string>Copyright © 2003-2007, Apple Inc.
-Copyright © 2003, XFree86 Project, Inc.
-Copyright © 2003-2007, X.org Project, Inc.
-</string>
-	<key>NSMainNibFile</key>
-	<string>main</string>
-	<key>NSPrincipalClass</key>
-	<string>X11Application</string>
-</dict>
-</plist>
diff --git a/hw/darwin/apple/Makefile.am b/hw/darwin/apple/Makefile.am
deleted file mode 100644
index a6e2dfb..0000000
--- a/hw/darwin/apple/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-bin_SCRIPTS = x11app
-
-.PHONY: x11app
-
-x11app:
-	xcodebuild CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" ARCHS="$(X11APP_ARCHS)"
-
-install-data-hook:
-	xcodebuild install DSTROOT="/$(DESTDIR)" INSTALL_PATH="$(APPLE_APPLICATIONS_DIR)" DEPLOYMENT_LOCATION=YES SKIP_INSTALL=NO ARCHS="$(X11APP_ARCHS)"
-	$(MKDIR_P) "$(DESTDIR)/System/Library/LaunchAgents/"
-	$(INSTALL) org.x.X11.plist "$(DESTDIR)/System/Library/LaunchAgents/"
-
-clean-local:
-	rm -rf build
-
-EXTRA_DIST = \
-	org.x.X11.plist \
-	Info.plist \
-	X11.icns \
-	bundle-main.c \
-	launcher-main.c \
-	server-main.c \
-	English.lproj/InfoPlist.strings \
-	English.lproj/Localizable.strings \
-	English.lproj/main.nib/classes.nib \
-	English.lproj/main.nib/info.nib \
-	English.lproj/main.nib/keyedobjects.nib \
-	X11.xcodeproj/project.pbxproj
diff --git a/hw/darwin/apple/X11.icns b/hw/darwin/apple/X11.icns
deleted file mode 100644
index d770e61..0000000
Binary files a/hw/darwin/apple/X11.icns and /dev/null differ
diff --git a/hw/darwin/apple/X11.xcodeproj/project.pbxproj b/hw/darwin/apple/X11.xcodeproj/project.pbxproj
deleted file mode 100644
index 225f371..0000000
--- a/hw/darwin/apple/X11.xcodeproj/project.pbxproj
+++ /dev/null
@@ -1,344 +0,0 @@
-// !$*UTF8*$!
-{
-	archiveVersion = 1;
-	classes = {
-	};
-	objectVersion = 42;
-	objects = {
-
-/* Begin PBXBuildFile section */
-		3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDE0D04BF110020CA24 /* launcher-main.c */; };
-		3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDF0D04BF110020CA24 /* server-main.c */; };
-		527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
-		527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
-		527F241B0B5D938C007840A7 /* X11.icns in Resources */ = {isa = PBXBuildFile; fileRef = 50459C5F038587C60ECA21EC /* X11.icns */; };
-		527F241D0B5D938C007840A7 /* bundle-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 50EE2AB703849F0B0ECA21EC /* bundle-main.c */; };
-		527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */; };
-		527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570C5748047186C400ACF82F /* SystemConfiguration.framework */; };
-		527F24370B5D9D89007840A7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 527F24260B5D938C007840A7 /* Info.plist */; };
-		52D9C0ED0BCDDF6B00CD2AFC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */; };
-/* End PBXBuildFile section */
-
-/* Begin PBXFileReference section */
-		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
-		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
-		3F5E1BDE0D04BF110020CA24 /* launcher-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "launcher-main.c"; sourceTree = "<group>"; };
-		3F5E1BDF0D04BF110020CA24 /* server-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "server-main.c"; sourceTree = "<group>"; };
-		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
-		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
-		50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
-		527F24260B5D938C007840A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
-		527F24270B5D938C007840A7 /* X11.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = X11.app; sourceTree = BUILT_PRODUCTS_DIR; };
-		52D9C0EC0BCDDF6B00CD2AFC /* English */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/Localizable.strings; sourceTree = "<group>"; };
-		570C5748047186C400ACF82F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
-/* End PBXFileReference section */
-
-/* Begin PBXFrameworksBuildPhase section */
-		527F241E0B5D938C007840A7 /* Frameworks */ = {
-			isa = PBXFrameworksBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-				527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */,
-				527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-/* End PBXFrameworksBuildPhase section */
-
-/* Begin PBXGroup section */
-		195DF8CFFE9D517E11CA2CBB /* Products */ = {
-			isa = PBXGroup;
-			children = (
-				527F24270B5D938C007840A7 /* X11.app */,
-			);
-			name = Products;
-			sourceTree = "<group>";
-		};
-		20286C29FDCF999611CA2CEA /* X11 */ = {
-			isa = PBXGroup;
-			children = (
-				20286C2AFDCF999611CA2CEA /* Sources */,
-				20286C2CFDCF999611CA2CEA /* Resources */,
-				20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */,
-				195DF8CFFE9D517E11CA2CBB /* Products */,
-				527F24260B5D938C007840A7 /* Info.plist */,
-			);
-			name = X11;
-			sourceTree = "<group>";
-		};
-		20286C2AFDCF999611CA2CEA /* Sources */ = {
-			isa = PBXGroup;
-			children = (
-				3F5E1BDE0D04BF110020CA24 /* launcher-main.c */,
-				3F5E1BDF0D04BF110020CA24 /* server-main.c */,
-				50EE2AB703849F0B0ECA21EC /* bundle-main.c */,
-			);
-			name = Sources;
-			sourceTree = "<group>";
-		};
-		20286C2CFDCF999611CA2CEA /* Resources */ = {
-			isa = PBXGroup;
-			children = (
-				52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */,
-				50459C5F038587C60ECA21EC /* X11.icns */,
-				0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */,
-				02345980000FD03B11CA0E72 /* main.nib */,
-			);
-			name = Resources;
-			sourceTree = "<group>";
-		};
-		20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */ = {
-			isa = PBXGroup;
-			children = (
-				50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */,
-				570C5748047186C400ACF82F /* SystemConfiguration.framework */,
-			);
-			name = "External Frameworks and Libraries";
-			sourceTree = "<group>";
-		};
-/* End PBXGroup section */
-
-/* Begin PBXHeadersBuildPhase section */
-		527F24170B5D938C007840A7 /* Headers */ = {
-			isa = PBXHeadersBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-/* End PBXHeadersBuildPhase section */
-
-/* Begin PBXNativeTarget section */
-		527F24160B5D938C007840A7 /* X11 */ = {
-			isa = PBXNativeTarget;
-			buildConfigurationList = 527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */;
-			buildPhases = (
-				527F24170B5D938C007840A7 /* Headers */,
-				527F24180B5D938C007840A7 /* Resources */,
-				527F241C0B5D938C007840A7 /* Sources */,
-				527F241E0B5D938C007840A7 /* Frameworks */,
-				527F24210B5D938C007840A7 /* Rez */,
-			);
-			buildRules = (
-			);
-			dependencies = (
-			);
-			name = X11;
-			productName = X11;
-			productReference = 527F24270B5D938C007840A7 /* X11.app */;
-			productType = "com.apple.product-type.application";
-		};
-/* End PBXNativeTarget section */
-
-/* Begin PBXProject section */
-		20286C28FDCF999611CA2CEA /* Project object */ = {
-			isa = PBXProject;
-			buildConfigurationList = 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */;
-			compatibilityVersion = "Xcode 2.4";
-			hasScannedForEncodings = 1;
-			mainGroup = 20286C29FDCF999611CA2CEA /* X11 */;
-			projectDirPath = "";
-			projectRoot = "";
-			targets = (
-				527F24160B5D938C007840A7 /* X11 */,
-			);
-		};
-/* End PBXProject section */
-
-/* Begin PBXResourcesBuildPhase section */
-		527F24180B5D938C007840A7 /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-				527F24370B5D9D89007840A7 /* Info.plist in Resources */,
-				527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */,
-				527F241A0B5D938C007840A7 /* main.nib in Resources */,
-				527F241B0B5D938C007840A7 /* X11.icns in Resources */,
-				52D9C0ED0BCDDF6B00CD2AFC /* Localizable.strings in Resources */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-/* End PBXResourcesBuildPhase section */
-
-/* Begin PBXRezBuildPhase section */
-		527F24210B5D938C007840A7 /* Rez */ = {
-			isa = PBXRezBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-/* End PBXRezBuildPhase section */
-
-/* Begin PBXSourcesBuildPhase section */
-		527F241C0B5D938C007840A7 /* Sources */ = {
-			isa = PBXSourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-				527F241D0B5D938C007840A7 /* bundle-main.c in Sources */,
-				3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */,
-				3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-/* End PBXSourcesBuildPhase section */
-
-/* Begin PBXVariantGroup section */
-		02345980000FD03B11CA0E72 /* main.nib */ = {
-			isa = PBXVariantGroup;
-			children = (
-				1870340FFE93FCAF11CA0CD7 /* English */,
-			);
-			name = main.nib;
-			sourceTree = "<group>";
-		};
-		0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */ = {
-			isa = PBXVariantGroup;
-			children = (
-				0867D6ABFE840B52C02AAC07 /* English */,
-			);
-			name = InfoPlist.strings;
-			sourceTree = "<group>";
-		};
-		52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */ = {
-			isa = PBXVariantGroup;
-			children = (
-				52D9C0EC0BCDDF6B00CD2AFC /* English */,
-			);
-			name = Localizable.strings;
-			sourceTree = "<group>";
-		};
-/* End PBXVariantGroup section */
-
-/* Begin XCBuildConfiguration section */
-		527F24090B5D8FFC007840A7 /* Development */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				INSTALL_MODE_FLAG = "a+rX";
-			};
-			name = Development;
-		};
-		527F240A0B5D8FFC007840A7 /* Deployment */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				INSTALL_MODE_FLAG = "a+rX";
-			};
-			name = Deployment;
-		};
-		527F240B0B5D8FFC007840A7 /* Default */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				INSTALL_MODE_FLAG = "a+rX";
-			};
-			name = Default;
-		};
-		527F24230B5D938C007840A7 /* Development */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-				FRAMEWORK_SEARCH_PATHS = "";
-				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
-				INFOPLIST_FILE = Info.plist;
-				INSTALL_PATH = /usr/X11;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lxcb",
-					"-lX11",
-				);
-				OTHER_REZFLAGS = "";
-				PRODUCT_NAME = X11;
-				SECTORDER_FLAGS = "";
-				WARNING_CFLAGS = (
-					"-Wmost",
-					"-Wno-four-char-constants",
-					"-Wno-unknown-pragmas",
-				);
-				WRAPPER_EXTENSION = app;
-			};
-			name = Development;
-		};
-		527F24240B5D938C007840A7 /* Deployment */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-				FRAMEWORK_SEARCH_PATHS = "";
-				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
-				INFOPLIST_FILE = Info.plist;
-				INSTALL_PATH = /usr/X11;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lxcb",
-					"-lX11",
-				);
-				OTHER_REZFLAGS = "";
-				PRODUCT_NAME = X11;
-				SECTORDER_FLAGS = "";
-				WARNING_CFLAGS = (
-					"-Wmost",
-					"-Wno-four-char-constants",
-					"-Wno-unknown-pragmas",
-				);
-				WRAPPER_EXTENSION = app;
-			};
-			name = Deployment;
-		};
-		527F24250B5D938C007840A7 /* Default */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				FRAMEWORK_SEARCH_PATHS = "";
-				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
-				INFOPLIST_FILE = Info.plist;
-				INSTALL_PATH = /usr/X11;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lxcb",
-					"-lX11",
-				);
-				OTHER_REZFLAGS = "";
-				PRODUCT_NAME = X11;
-				SECTORDER_FLAGS = "";
-				WARNING_CFLAGS = (
-					"-Wmost",
-					"-Wno-four-char-constants",
-					"-Wno-unknown-pragmas",
-				);
-				WRAPPER_EXTENSION = app;
-			};
-			name = Default;
-		};
-/* End XCBuildConfiguration section */
-
-/* Begin XCConfigurationList section */
-		527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */ = {
-			isa = XCConfigurationList;
-			buildConfigurations = (
-				527F24090B5D8FFC007840A7 /* Development */,
-				527F240A0B5D8FFC007840A7 /* Deployment */,
-				527F240B0B5D8FFC007840A7 /* Default */,
-			);
-			defaultConfigurationIsVisible = 0;
-			defaultConfigurationName = Default;
-		};
-		527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */ = {
-			isa = XCConfigurationList;
-			buildConfigurations = (
-				527F24230B5D938C007840A7 /* Development */,
-				527F24240B5D938C007840A7 /* Deployment */,
-				527F24250B5D938C007840A7 /* Default */,
-			);
-			defaultConfigurationIsVisible = 0;
-			defaultConfigurationName = Default;
-		};
-/* End XCConfigurationList section */
-	};
-	rootObject = 20286C28FDCF999611CA2CEA /* Project object */;
-}
diff --git a/hw/darwin/apple/bundle-main.c b/hw/darwin/apple/bundle-main.c
deleted file mode 100644
index c436d51..0000000
--- a/hw/darwin/apple/bundle-main.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* main.c -- X application launcher
- 
- Copyright (c) 2007 Jeremy Huddleston
- Copyright (c) 2007 Apple Inc
- 
- 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 <X11/Xlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-
-int launcher_main(int argc, char **argv);
-int server_main(int argc, char **argv);
-
-int main(int argc, char **argv) {
-    Display *display;
-  
-    fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
-    int i;
-    for(i=0; i < argc; i++) {
-        fprintf(stderr, "\targv[%d] = %s\n", i, argv[i]);
-    }
-    
-    /* First check if launchd started us */
-    if(argc == 2 && !strncmp(argv[1], "--launchd", 9)) {
-        argc--;
-        argv[1] = argv[0];
-        argv++;
-        fprintf(stderr, "X11.app: main(): launchd called us, running server_main()");
-        return server_main(argc, argv);
-    }
-
-    /* If we have a process serial number and it's our only arg, act as if
-     * the user double clicked the app bundle: launch app_to_run if possible
-     */
-    if(argc == 1 || (argc == 2 && !strncmp(argv[1], "-psn_", 5))) {
-        /* Now, try to open a display, if so, run the launcher */
-        display = XOpenDisplay(NULL);
-        if(display) {
-            fprintf(stderr, "X11.app: main(): closing the display");
-            /* Could open the display, start the launcher */
-            XCloseDisplay(display);
-
-            /* Give 2 seconds for the server to start... 
-             * TODO: *Really* fix this race condition
-             */
-            usleep(2000);
-            fprintf(stderr, "X11.app: main(): running launcher_main()");
-            return launcher_main(argc, argv);
-        }
-    }
-
-    /* Couldn't open the display or we were called with arguments,
-     * just want to start a server.
-     */
-    fprintf(stderr, "X11.app: main(): running server_main()");
-    return server_main(argc, argv);
-}
diff --git a/hw/darwin/apple/launcher-main.c b/hw/darwin/apple/launcher-main.c
deleted file mode 100644
index 60a1624..0000000
--- a/hw/darwin/apple/launcher-main.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* main.c -- X application launcher
- 
- Copyright (c) 2007 Apple Inc.
- 
- 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 <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <CoreFoundation/CoreFoundation.h>
-
-#define DEFAULT_APP "/usr/X11/bin/xterm"
-
-int launcher_main (int argc, char **argv) {
-  char *command = DEFAULT_APP;
-  const char *newargv[7];
-  int child;
-  
-
-	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"),
-									kCFPreferencesCurrentApplication);
-	
-	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_APP), 
-								 kCFPreferencesCurrentApplication);
-		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
-	} else {
-		int len = CFStringGetLength((CFStringRef)PlistRef)+1;
-		command = (char *) malloc(len);
-		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
-		fprintf(stderr, "command=%s\n", command);
-	}
-	
-	if (PlistRef) CFRelease(PlistRef);
-	
-	newargv[0] = "/usr/bin/login";
-	newargv[1] = "-fp";
-	newargv[2] = getlogin();
-	newargv[3] = "/bin/sh";
-	newargv[4] = "-c";
-	newargv[5] = command;
-	newargv[6] = NULL;
-
-    child = fork();
-	
-    switch (child) {
-    case -1:				/* error */
-      perror ("fork");
-      return EXIT_FAILURE;		
-    case 0:				    /* child */
-      execvp (newargv[0], (char **const) newargv);
-      perror ("Couldn't exec");
-      _exit (1);
-   }
-	
-    return 0;
-}
diff --git a/hw/darwin/apple/org.x.X11.plist b/hw/darwin/apple/org.x.X11.plist
deleted file mode 100644
index 6c6be91..0000000
--- a/hw/darwin/apple/org.x.X11.plist
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>Label</key>
-		<string>org.x.X11</string>
-	<key>Program</key>
-		<string>/Applications/Utilities/X11.app/Contents/MacOS/X11</string>
-	<key>ProgramArguments</key>
-		<array>
-		<string>/Applications/Utilities/X11.app/Contents/MacOS/X11</string>
-		<string>--launchd</string>
-		</array>
-	<key>Sockets</key>
-		<dict>
-		<key>:0</key>
-			<dict>
-			<key>SecureSocketWithKey</key>
-				<string>DISPLAY</string>
-			</dict>
-		</dict>
-	<key>ServiceIPC</key>
-		<true/>
-</dict>
-</plist>
diff --git a/hw/darwin/apple/server-main.c b/hw/darwin/apple/server-main.c
deleted file mode 100644
index 26fcbb0..0000000
--- a/hw/darwin/apple/server-main.c
+++ /dev/null
@@ -1,904 +0,0 @@
-/* bundle-main.c -- X server launcher
- 
- Copyright (c) 2002-2007 Apple Inc. 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.
- 
- Parts of this file are derived from xdm, which has this copyright:
- 
- Copyright 1988, 1998  The Open Group
- 
- Permission to use, copy, modify, distribute, and sell this software
- and its documentation for any purpose is hereby granted without fee,
- provided that the above copyright notice appear in all copies and
- that both that copyright notice and this permission notice appear in
- supporting documentation.
- 
- 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 OPEN GROUP 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 of The Open Group shall
- not be used in advertising or otherwise to promote the sale, use or
- other dealings in this Software without prior written authorization
- from The Open Group. */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/utsname.h>
-#include <ifaddrs.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <time.h>
-#include <sys/wait.h>
-#include <setjmp.h>
-#include <sys/ioctl.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xauth.h>
-#include <xcb/xcb.h>
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <SystemConfiguration/SystemConfiguration.h>
-
-#define X_SERVER "/usr/X11/bin/Xquartz"
-#define XTERM_PATH "/usr/X11/bin/xterm"
-#define WM_PATH "/usr/bin/quartz-wm"
-#define DEFAULT_XINITRC "/usr/X11/lib/X11/xinit/xinitrc"
-#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"
-
-/* what xinit does */
-#ifndef SHELL
-# define SHELL "sh"
-#endif
-
-#undef FALSE
-#define FALSE 0
-#undef TRUE
-#define TRUE 1
-
-#define MAX_DISPLAYS 64
-
-static int server_pid = -1, client_pid = -1;
-static int xinit_kills_server = FALSE;
-static jmp_buf exit_continuation;
-static const char *server_name = NULL;
-static Display *server_dpy;
-
-static char *auth_file;
-
-typedef struct addr_list_struct addr_list;
-
-struct addr_list_struct {
-    addr_list *next;
-    Xauth auth;
-};
-
-static addr_list *addresses;
-
-
-/* Utility functions. */
-
-/* Return the current host name. Matches what Xlib does. */
-static char *
-host_name (void)
-{
-#ifdef NEED_UTSNAME
-    static struct utsname name;
-	
-    uname(&name);
-	
-    return name.nodename;
-#else
-    static char buf[100];
-	
-    gethostname(buf, sizeof(buf));
-	
-    return buf;
-#endif
-}
-
-static int
-read_boolean_pref (CFStringRef name, int default_)
-{
-    int value;
-    Boolean ok;
-	
-    value = CFPreferencesGetAppBooleanValue (name,
-											 CFSTR ("com.apple.x11"), &ok);
-    return ok ? value : default_;
-}
-
-static inline int
-binary_equal (const void *a, const void *b, int length)
-{
-    return memcmp (a, b, length) == 0;
-}
-
-static inline void *
-binary_dup (const void *a, int length)
-{
-    void *b = malloc (length);
-    if (b != NULL)
-		memcpy (b, a, length);
-    return b;
-}
-
-static inline void
-binary_free (void *data, int length)
-{
-    if (data != NULL)
-		free (data);
-}
-
-
-/* Functions for managing the authentication entries. */
-
-/* Returns true if something matching AUTH is in our list of auth items */
-static int
-check_auth_item (Xauth *auth)
-{
-    addr_list *a;
-	
-    for (a = addresses; a != NULL; a = a->next)
-    {
-		if (a->auth.family == auth->family
-			&& a->auth.address_length == auth->address_length
-			&& binary_equal (a->auth.address, auth->address, auth->address_length)
-			&& a->auth.number_length == auth->number_length
-			&& binary_equal (a->auth.number, auth->number, auth->number_length)
-			&& a->auth.name_length == auth->name_length
-			&& binary_equal (a->auth.name, auth->name, auth->name_length))
-		{
-			return TRUE;
-		}
-    }
-	
-    return FALSE;
-}
-
-/* Add one item to our list of auth items. */
-static void
-add_auth_item (Xauth *auth)
-{
-    addr_list *a = malloc (sizeof (addr_list));
-	
-    a->auth.family = auth->family;
-    a->auth.address_length = auth->address_length;
-    a->auth.address = binary_dup (auth->address, auth->address_length);
-    a->auth.number_length = auth->number_length;
-    a->auth.number = binary_dup (auth->number, auth->number_length);
-    a->auth.name_length = auth->name_length;
-    a->auth.name = binary_dup (auth->name, auth->name_length);
-    a->auth.data_length = auth->data_length;
-    a->auth.data = binary_dup (auth->data, auth->data_length);
-	
-    a->next = addresses;
-    addresses = a;
-}
-
-/* Free all allocated auth items. */
-static void
-free_auth_items (void)
-{
-    addr_list *a;
-	
-    while ((a = addresses) != NULL)
-    {
-		addresses = a->next;
-		
-		binary_free (a->auth.address, a->auth.address_length);
-		binary_free (a->auth.number, a->auth.number_length);
-		binary_free (a->auth.name, a->auth.name_length);
-		binary_free (a->auth.data, a->auth.data_length);
-		free (a);
-    }
-}
-
-/* Add the unix domain auth item. */
-static void
-define_local (Xauth *auth)
-{
-    char *host = host_name ();
-	
-#ifdef DEBUG
-    fprintf (stderr, "x11: hostname is %s\n", host);
-#endif
-	
-    auth->family = FamilyLocal;
-    auth->address_length = strlen (host);
-    auth->address = host;
-	
-    add_auth_item (auth);
-}
-
-/* Add the tcp auth item. */
-static void
-define_named (Xauth *auth, const char *name)
-{
-    struct ifaddrs *addrs, *ptr;
-	
-    if (getifaddrs (&addrs) != 0)
-		return;
-	
-    for (ptr = addrs; ptr != NULL; ptr = ptr->ifa_next)
-    {
-		if (ptr->ifa_addr->sa_family != AF_INET)
-			continue;
-		
-		auth->family = FamilyInternet;
-		auth->address_length = sizeof (struct in_addr);
-		auth->address = (char *) &(((struct sockaddr_in *) ptr->ifa_addr)->sin_addr);
-		
-#ifdef DEBUG
-		fprintf (stderr, "x11: ipaddr is %d.%d.%d.%d\n",
-				 (unsigned char) auth->address[0],
-				 (unsigned char) auth->address[1],
-				 (unsigned char) auth->address[2],
-				 (unsigned char) auth->address[3]);
-#endif
-		
-		add_auth_item (auth);
-    }
-	
-    freeifaddrs (addrs);
-}
-
-/* Parse the display number from NAME and add it to AUTH. */
-static void
-set_auth_number (Xauth *auth, const char *name)
-{
-    char *colon;
-    char *dot, *number;
-	
-    colon = strrchr(name, ':');
-    if (colon != NULL)
-    {
-		colon++;
-		dot = strchr(colon, '.');
-		
-		if (dot != NULL)
-			auth->number_length = dot - colon;
-		else
-			auth->number_length = strlen (colon);
-		
-		number = malloc (auth->number_length + 1);
-		if (number != NULL)
-		{
-			strncpy (number, colon, auth->number_length);
-			number[auth->number_length] = '\0';
-		}
-		else
-		{
-			auth->number_length = 0;
-		}
-		
-		auth->number = number;
-    }
-}
-
-/* Put 128 bits of random data into DATA. If possible, it will be "high
- quality" */
-static int
-generate_mit_magic_cookie (char data[16])
-{
-    int fd, ret, i;
-    long *ldata = (long *) data;
-	
-    fd = open ("/dev/random", O_RDONLY);
-    if (fd > 0) {
-		ret = read (fd, data, 16);
-		close (fd);
-		if (ret == 16) return TRUE;
-    }
-	
-    /* fall back to the usual crappy rng */
-	
-    srand48 (getpid () ^ time (NULL));
-	
-    for (i = 0; i < 4; i++)
-		ldata[i] = lrand48 ();
-	
-    return TRUE;
-}
-
-/* Create the keys we'll be using for the display named NAME. */
-static int
-make_auth_keys (const char *name)
-{
-    Xauth auth;
-    char key[16];
-	
-    if (auth_file == NULL)
-		return FALSE;
-	
-    auth.name = "MIT-MAGIC-COOKIE-1";
-    auth.name_length = strlen (auth.name);
-	
-    if (!generate_mit_magic_cookie (key))
-    {
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    auth.data = key;
-    auth.data_length = 16;
-	
-    set_auth_number (&auth, name);
-	
-    define_named (&auth, host_name ());
-    define_local (&auth);
-	
-    free (auth.number);
-	
-    return TRUE;
-}
-
-/* If ADD-ENTRIES is true, merge our auth entries into the existing
- Xauthority file. If ADD-ENTRIES is false, remove our entries. */
-static int
-write_auth_file (int add_entries)
-{
-    char *home, newname[1024];
-    int fd, ret;
-    FILE *new_fh, *old_fh;
-    addr_list *addr;
-    Xauth *auth;
-	
-    if (auth_file == NULL)
-		return FALSE;
-	
-    home = getenv ("HOME");
-    if (home == NULL)
-    {
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    snprintf (newname, sizeof (newname), "%s/.XauthorityXXXXXX", home);
-    mktemp (newname);
-	
-    if (XauLockAuth (auth_file, 1, 2, 10) != LOCK_SUCCESS)
-    {
-		/* FIXME: do something here? */
-		
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    fd = open (newname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-    if (fd >= 0)
-    {
-		new_fh = fdopen (fd, "w");
-		if (new_fh != NULL)
-		{
-			if (add_entries)
-			{
-				for (addr = addresses; addr != NULL; addr = addr->next)
-				{
-					XauWriteAuth (new_fh, &addr->auth);
-				}
-			}
-			
-			old_fh = fopen (auth_file, "r");
-			if (old_fh != NULL)
-			{
-				while ((auth = XauReadAuth (old_fh)) != NULL)
-				{
-					if (!check_auth_item (auth))
-						XauWriteAuth (new_fh, auth);
-					XauDisposeAuth (auth);
-				}
-				fclose (old_fh);
-			}
-			
-			fclose (new_fh);
-			unlink (auth_file);
-			
-			ret = rename (newname, auth_file);
-			
-			if (ret != 0)
-				auth_file = NULL;
-			
-			XauUnlockAuth (auth_file);
-			return ret == 0;
-		}
-		
-		close (fd);
-    }
-	
-    XauUnlockAuth (auth_file);
-    auth_file = NULL;
-    return FALSE;
-}
-
-
-/* Subprocess management functions. */
-
-static int
-start_server (char **xargv)
-{
-    int child;
-	
-    child = fork ();
-	
-    switch (child)
-    {
-    case -1:				/* error */
-		perror ("fork");
-		return FALSE;
-		
-    case 0:				/* child */
-		execv (X_SERVER, xargv);
-		perror ("Couldn't exec " X_SERVER);
-		_exit (1);
-		
-    default:				/* parent */
-		server_pid = child;
-		return TRUE;
-    }
-}
-
-static int
-wait_for_server (void)
-{
-    int count = 100;
-	
-    while (count-- > 0)
-    {
-		int status;
-		
-		server_dpy = XOpenDisplay (server_name);
-		if (server_dpy != NULL)
-			return TRUE;
-		
-		if (waitpid (server_pid, &status, WNOHANG) == server_pid)
-			return FALSE;
-		
-		sleep (1);
-    }
-	
-    return FALSE;
-}
-
-static int
-start_client (void)
-{
-    int child;
-	
-    child = fork();
-	
-    switch (child) {
-		char *temp, buf[1024];		
-
-	case -1:				/* error */
-		perror("fork");
-		return FALSE;
-
-	case 0:					/* child */
-		/* Setup environment */
-		temp = getenv("DISPLAY");
-//		if (temp == NULL && temp[0] != 0)
-			setenv("DISPLAY", server_name, TRUE);
-
-		temp = getenv("PATH");
-		if (temp == NULL || temp[0] == 0) 
-			setenv ("PATH", DEFAULT_PATH, TRUE);
-		else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) {
-			snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp);		
-			setenv("PATH", buf, TRUE);	
-		}
-		
-		/* First try value of $XINITRC, if set. */
-		temp = getenv("XINITRC");
-		if (temp != NULL && temp[0] != 0 && access(temp, R_OK) == 0)
-			execlp (SHELL, SHELL, temp, NULL);
-
-		/* Then look for .xinitrc in user's home directory. */
-		temp = getenv("HOME");
-		if (temp != NULL && temp[0] != 0) {
-			chdir(temp);
-			snprintf (buf, sizeof (buf), "%s/.xinitrc", temp);
-			if (access(buf, R_OK) == 0)
-				execlp(SHELL, SHELL, buf, NULL);
-		}
-		
-		/* Then try the default xinitrc in the lib directory. */
-		
-		if (access(DEFAULT_XINITRC, R_OK) == 0)
-			execlp(SHELL, SHELL, DEFAULT_XINITRC, NULL);
-		
-		/* Then fallback to hardcoding an xterm and the window manager. */
-		
-		//		system(XTERM_PATH " &");
-		execl(WM_PATH, WM_PATH, NULL);
-		
-		perror("exec");
-		_exit(1);
-		
-    default:				/* parent */
-		client_pid = child;
-		return TRUE;
-    }
-}
-
-static void
-sigchld_handler (int sig)
-{
-    int pid, status;
-	
-	again:
-    pid = waitpid (WAIT_ANY, &status, WNOHANG);
-	
-    if (pid > 0)
-    {
-		if (pid == server_pid)
-		{
-			server_pid = -1;
-			
-			if (client_pid >= 0)
-				kill (client_pid, SIGTERM);
-		}
-		else if (pid == client_pid)
-		{
-			client_pid = -1;
-			
-			if (server_pid >= 0 && xinit_kills_server)
-				kill (server_pid, SIGTERM);
-		}
-		goto again;
-    }
-	
-    if (server_pid == -1 && client_pid == -1)
-		longjmp (exit_continuation, 1);
-	
-    signal (SIGCHLD, sigchld_handler);
-}
-
-
-/* Server utilities. */
-
-static Boolean
-display_exists_p (int number)
-{
-    char buf[64];
-    xcb_connection_t *conn;
-    char *fullname = NULL;
-    int idisplay, iscreen;
-    char *conn_auth_name, *conn_auth_data;
-    int conn_auth_namelen, conn_auth_datalen;
-    
-    //    extern void *_X11TransConnectDisplay ();
-    //    extern void _XDisconnectDisplay ();
-	
-    /* Since connecting to the display waits for a few seconds if the
-	 display doesn't exist, check for trivial non-existence - if the
-	 socket in /tmp exists or not.. (note: if the socket exists, the
-	 server may still not, so we need to try to connect in that case..) */
-	
-    sprintf (buf, "/tmp/.X11-unix/X%d", number);
-    if (access (buf, F_OK) != 0)
-		return FALSE;
-    
-    sprintf (buf, ":%d", number);
-    conn = xcb_connect(buf, NULL);
-    if (xcb_connection_has_error(conn)) return FALSE;
-	
-    xcb_disconnect(conn);
-    return TRUE;
-}
-
-
-/* Monitoring when the system's ip addresses change. */
-
-static Boolean pending_timer;
-
-static void
-timer_callback (CFRunLoopTimerRef timer, void *info)
-{
-    pending_timer = FALSE;
-	
-    /* Update authentication names. Need to write .Xauthority file first
-	 without the existing entries, then again with the new entries.. */
-	
-    write_auth_file (FALSE);
-	
-    free_auth_items ();
-    make_auth_keys (server_name);
-	
-    write_auth_file (TRUE);
-}
-
-/* This function is called when the system's ip addresses may have changed. */
-static void
-ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
-{
-#if DEBUG
-    if (changed_keys != NULL) {
-		fprintf (stderr, "x11: changed sc keys: ");
-		CFShow (changed_keys);
-    }
-#endif
-
-    if (auth_file != NULL && !pending_timer)
-    {
-		CFRunLoopTimerRef timer;
-		
-		timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
-									  0.0, 0, 0, timer_callback, NULL);
-		CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
-						   kCFRunLoopDefaultMode);
-		CFRelease (timer);
-		
-		pending_timer = TRUE;
-    }
-}
-
-/* This code adapted from "Living in a Dynamic TCP/IP Environment" technote. */
-static Boolean
-install_ipaddr_source (void)
-{
-    CFRunLoopSourceRef source = NULL;
-	
-    SCDynamicStoreContext context = {0};
-    SCDynamicStoreRef ref;
-	
-    ref = SCDynamicStoreCreate (NULL,
-								CFSTR ("AddIPAddressListChangeCallbackSCF"),
-								ipaddr_callback, &context);
-	
-    if (ref != NULL)
-    {
-		const void *keys[4], *patterns[2];
-		int i;
-		
-		keys[0] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
-		keys[1] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6);
-		keys[2] = SCDynamicStoreKeyCreateComputerName (NULL);
-		keys[3] = SCDynamicStoreKeyCreateHostNames (NULL);
-		
-		patterns[0] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4);
-		patterns[1] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6);
-		
-		if (keys[0] != NULL && keys[1] != NULL && keys[2] != NULL
-			&& keys[3] != NULL && patterns[0] != NULL && patterns[1] != NULL)
-		{
-			CFArrayRef key_array, pattern_array;
-			
-			key_array = CFArrayCreate (NULL, keys, 4, &kCFTypeArrayCallBacks);
-			pattern_array = CFArrayCreate (NULL, patterns, 2, &kCFTypeArrayCallBacks);
-			
-			if (key_array != NULL || pattern_array != NULL)
-			{
-				SCDynamicStoreSetNotificationKeys (ref, key_array, pattern_array);
-				source = SCDynamicStoreCreateRunLoopSource (NULL, ref, 0);
-			}
-			
-			if (key_array != NULL)
-				CFRelease (key_array);
-			if (pattern_array != NULL)
-				CFRelease (pattern_array);
-		}
-		
-		
-		for (i = 0; i < 4; i++)
-			if (keys[i] != NULL)
-			CFRelease (keys[i]);
-		for (i = 0; i < 2; i++)
-			if (patterns[i] != NULL)
-			CFRelease (patterns[i]);
-		
-		CFRelease (ref); 
-    }
-	
-    if (source != NULL)
-    {
-		CFRunLoopAddSource (CFRunLoopGetCurrent (),
-							source, kCFRunLoopDefaultMode);
-		CFRelease (source);
-    }
-	
-    return source != NULL;
-}
-
-
-/* Entrypoint. */
-
-void
-termination_signal_handler (int unused_sig)
-{
-    signal (SIGTERM, SIG_DFL);
-    signal (SIGHUP, SIG_DFL);
-    signal (SIGINT, SIG_DFL);
-    signal (SIGQUIT, SIG_DFL);
-
-    longjmp (exit_continuation, 1);
-}
-
-int
-server_main (int argc, char **argv)
-{
-    char **xargv;
-    int i, j;
-    int fd;
-	
-    xargv = alloca (sizeof (char *) * (argc + 32));
-	
-    if (!read_boolean_pref (CFSTR ("no_auth"), FALSE))
-		auth_file = XauFileName ();
-	
-    /* The standard X11 behaviour is for the server to quit when the first
-	 client exits. But it can be useful for debugging (and to mimic our
-	 behaviour in the beta releases) to not do that. */
-	
-    xinit_kills_server = read_boolean_pref (CFSTR ("xinit_kills_server"), TRUE);
-	
-    for (i = 1; i < argc; i++)
-    {
-		if (argv[i][0] == ':')
-			server_name = argv[i];
-    }
-	
-    if (server_name == NULL)
-    {
-		static char name[8];
-		
-		/* No display number specified, so search for the first unused.
-		 
-		 There's a big old race condition here if two servers start at
-		 the same time, but that's fairly unlikely. We could create
-		 lockfiles or something, but that's seems more likely to cause
-		 problems than the race condition itself.. */
-		
-		for (i = 0; i < MAX_DISPLAYS; i++)
-		{
-			if (!display_exists_p (i))
-				break;
-		}
-		
-		if (i == MAX_DISPLAYS)
-		{
-			fprintf (stderr, "%s: couldn't allocate a display number", argv[0]);
-			exit (1);
-		}
-		
-		sprintf (name, ":%d", i);
-		server_name = name;
-    }
-	
-    if (auth_file != NULL)
-    {
-		/* Create new Xauth keys and add them to the .Xauthority file */
-		
-		make_auth_keys (server_name);
-		write_auth_file (TRUE);
-    }
-	
-    /* Construct our new argv */
-	
-    i = j = 0;
-	
-    xargv[i++] = argv[j++];
-	
-    if (auth_file != NULL)
-    {
-		xargv[i++] = "-auth";
-		xargv[i++] = auth_file;
-    }
-	
-    /* By default, don't listen on tcp sockets if Xauth is disabled. */
-	
-    if (read_boolean_pref (CFSTR ("nolisten_tcp"), auth_file == NULL))
-    {
-		xargv[i++] = "-nolisten";
-		xargv[i++] = "tcp";
-    }
-	
-    while (j < argc)
-    {
-		if (argv[j++][0] != ':')
-			xargv[i++] = argv[j-1];
-    }
-	
-    xargv[i++] = (char *) server_name;
-    xargv[i++] = NULL;
-	
-    /* Detach from any controlling terminal and connect stdin to /dev/null */
-	
-#ifdef TIOCNOTTY
-    fd = open ("/dev/tty", O_RDONLY);
-    if (fd != -1)
-    {
-		ioctl (fd, TIOCNOTTY, 0);
-		close (fd);
-    }
-#endif
-	
-    fd = open ("/dev/null", O_RDWR, 0);
-    if (fd >= 0)
-    {
-		dup2 (fd, 0);
-		if (fd > 0)
-			close (fd);
-    }
-	
-    if (!start_server (xargv))
-		return 1;
-	
-    if (!wait_for_server ())
-    {
-		kill (server_pid, SIGTERM);
-		return 1;
-    }
-	
-    if (!start_client ())
-    {
-		kill (server_pid, SIGTERM);
-		return 1;
-    }
-	
-    signal (SIGCHLD, sigchld_handler);
-	
-    signal (SIGTERM, termination_signal_handler);
-    signal (SIGHUP, termination_signal_handler);
-    signal (SIGINT, termination_signal_handler);
-    signal (SIGQUIT, termination_signal_handler);
-
-    if (setjmp (exit_continuation) == 0)
-    {
-		if (install_ipaddr_source ())
-			CFRunLoopRun ();
-		else
-			while (1) pause ();
-    }
-	
-    signal (SIGCHLD, SIG_IGN);
-
-    if (client_pid >= 0) kill (client_pid, SIGTERM);
-    if (server_pid >= 0) kill (server_pid, SIGTERM);
-	
-    if (auth_file != NULL)
-    {
-		/* Remove our Xauth keys */
-		
-		write_auth_file (FALSE);
-    }
-	
-    free_auth_items ();
-	
-    return 0;
-}
diff --git a/hw/darwin/quartz/Makefile.am b/hw/darwin/quartz/Makefile.am
index f5199df..38f48d0 100644
--- a/hw/darwin/quartz/Makefile.am
+++ b/hw/darwin/quartz/Makefile.am
@@ -1,14 +1,21 @@
-noinst_LIBRARIES = libXQuartz.a
+noinst_LTLIBRARIES = libXQuartz.la
 
 AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_OBJCFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
+
+# TODO: This should not pull in rootless... rootless should all be in xpr
 AM_CPPFLAGS = \
 	-I$(srcdir) -I$(srcdir)/.. \
 	-I$(top_srcdir)/miext/rootless
 
-SUBDIRS = xpr
+if X11APP
+X11APP_SUBDIRS = apple
+endif
+
+SUBDIRS = . xpr $(X11APP_SUBDIRS)
+DIST_SUBDIRS = xpr apple
 
-libXQuartz_a_SOURCES = \
+libXQuartz_la_SOURCES = \
 	X11Application.m \
 	X11Controller.m \
 	applewm.c \
diff --git a/hw/darwin/quartz/X11Application.m b/hw/darwin/quartz/X11Application.m
index 48acff2..fc23724 100644
--- a/hw/darwin/quartz/X11Application.m
+++ b/hw/darwin/quartz/X11Application.m
@@ -65,8 +65,7 @@ int X11EnableKeyEquivalents = TRUE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
 extern int darwinFakeButtons, input_check_flag;
-// extern Bool enable_stereo; 
-Bool enable_stereo;  //<-- this needs to go back to being an extern once glxCGL is fixed
+extern Bool enable_stereo; 
 
 extern xEvent *darwinEvents;
 
diff --git a/hw/darwin/quartz/apple/English.lproj/InfoPlist.strings b/hw/darwin/quartz/apple/English.lproj/InfoPlist.strings
new file mode 100644
index 0000000..88e1f04
Binary files /dev/null and b/hw/darwin/quartz/apple/English.lproj/InfoPlist.strings differ
diff --git a/hw/darwin/quartz/apple/English.lproj/Localizable.strings b/hw/darwin/quartz/apple/English.lproj/Localizable.strings
new file mode 100644
index 0000000..c83b085
Binary files /dev/null and b/hw/darwin/quartz/apple/English.lproj/Localizable.strings differ
diff --git a/hw/darwin/quartz/apple/English.lproj/main.nib/classes.nib b/hw/darwin/quartz/apple/English.lproj/main.nib/classes.nib
new file mode 100644
index 0000000..a82159b
--- /dev/null
+++ b/hw/darwin/quartz/apple/English.lproj/main.nib/classes.nib
@@ -0,0 +1,318 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBClasses</key>
+	<array>
+		<dict>
+			<key>CLASS</key>
+			<string>IBLibraryObjectTemplate</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>draggedView</key>
+				<string>NSView</string>
+				<key>representedObject</key>
+				<string>NSObject</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSView</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>IBInspector</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>inspectorView</key>
+				<string>NSView</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSDateFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>apps_table_cancel</key>
+				<string>id</string>
+				<key>apps_table_delete</key>
+				<string>id</string>
+				<key>apps_table_done</key>
+				<string>id</string>
+				<key>apps_table_duplicate</key>
+				<string>id</string>
+				<key>apps_table_new</key>
+				<string>id</string>
+				<key>apps_table_show</key>
+				<string>id</string>
+				<key>bring_to_front</key>
+				<string>id</string>
+				<key>close_window</key>
+				<string>id</string>
+				<key>enable_fullscreen_changed</key>
+				<string>id</string>
+				<key>minimize_window</key>
+				<string>id</string>
+				<key>next_window</key>
+				<string>id</string>
+				<key>prefs_changed</key>
+				<string>id</string>
+				<key>prefs_show</key>
+				<string>id</string>
+				<key>previous_window</key>
+				<string>id</string>
+				<key>toggle_fullscreen</key>
+				<string>id</string>
+				<key>x11_help</key>
+				<string>id</string>
+				<key>zoom_window</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>X11Controller</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>apps_separator</key>
+				<string>id</string>
+				<key>apps_table</key>
+				<string>id</string>
+				<key>depth</key>
+				<string>id</string>
+				<key>dock_apps_menu</key>
+				<string>id</string>
+				<key>dock_menu</key>
+				<string>id</string>
+				<key>dock_window_separator</key>
+				<string>id</string>
+				<key>enable_auth</key>
+				<string>id</string>
+				<key>enable_fullscreen</key>
+				<string>id</string>
+				<key>enable_keyequivs</key>
+				<string>id</string>
+				<key>enable_tcp</key>
+				<string>id</string>
+				<key>fake_buttons</key>
+				<string>id</string>
+				<key>prefs_panel</key>
+				<string>id</string>
+				<key>sync_keymap</key>
+				<string>id</string>
+				<key>toggle_fullscreen_item</key>
+				<string>id</string>
+				<key>use_sysbeep</key>
+				<string>id</string>
+				<key>window_separator</key>
+				<string>id</string>
+				<key>x11_about_item</key>
+				<string>id</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSNumberFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>alignCenter:</key>
+				<string>id</string>
+				<key>alignJustified:</key>
+				<string>id</string>
+				<key>alignLeft:</key>
+				<string>id</string>
+				<key>alignRight:</key>
+				<string>id</string>
+				<key>arrangeInFront:</key>
+				<string>id</string>
+				<key>centerSelectionInVisibleArea:</key>
+				<string>id</string>
+				<key>changeFont:</key>
+				<string>id</string>
+				<key>checkSpelling:</key>
+				<string>id</string>
+				<key>clear:</key>
+				<string>id</string>
+				<key>clearRecentDocuments:</key>
+				<string>id</string>
+				<key>complete:</key>
+				<string>id</string>
+				<key>copy:</key>
+				<string>id</string>
+				<key>copyFont:</key>
+				<string>id</string>
+				<key>copyRuler:</key>
+				<string>id</string>
+				<key>cut:</key>
+				<string>id</string>
+				<key>delete:</key>
+				<string>id</string>
+				<key>deminiaturize:</key>
+				<string>id</string>
+				<key>fax:</key>
+				<string>id</string>
+				<key>hide:</key>
+				<string>id</string>
+				<key>hideOtherApplications:</key>
+				<string>id</string>
+				<key>loosenKerning:</key>
+				<string>id</string>
+				<key>lowerBaseline:</key>
+				<string>id</string>
+				<key>makeKeyAndOrderFront:</key>
+				<string>id</string>
+				<key>miniaturize:</key>
+				<string>id</string>
+				<key>newDocument:</key>
+				<string>id</string>
+				<key>openDocument:</key>
+				<string>id</string>
+				<key>orderBack:</key>
+				<string>id</string>
+				<key>orderFront:</key>
+				<string>id</string>
+				<key>orderFrontColorPanel:</key>
+				<string>id</string>
+				<key>orderFrontHelpPanel:</key>
+				<string>id</string>
+				<key>orderOut:</key>
+				<string>id</string>
+				<key>outline:</key>
+				<string>id</string>
+				<key>paste:</key>
+				<string>id</string>
+				<key>pasteAsPlainText:</key>
+				<string>id</string>
+				<key>pasteAsRichText:</key>
+				<string>id</string>
+				<key>pasteFont:</key>
+				<string>id</string>
+				<key>pasteRuler:</key>
+				<string>id</string>
+				<key>pause:</key>
+				<string>id</string>
+				<key>performClose:</key>
+				<string>id</string>
+				<key>performFindPanelAction:</key>
+				<string>id</string>
+				<key>performMiniaturize:</key>
+				<string>id</string>
+				<key>performZoom:</key>
+				<string>id</string>
+				<key>play:</key>
+				<string>id</string>
+				<key>print:</key>
+				<string>id</string>
+				<key>printDocument:</key>
+				<string>id</string>
+				<key>raiseBaseline:</key>
+				<string>id</string>
+				<key>record:</key>
+				<string>id</string>
+				<key>redo:</key>
+				<string>id</string>
+				<key>resume:</key>
+				<string>id</string>
+				<key>revertDocumentToSaved:</key>
+				<string>id</string>
+				<key>run:</key>
+				<string>id</string>
+				<key>runPageLayout:</key>
+				<string>id</string>
+				<key>runToolbarCustomizationPalette:</key>
+				<string>id</string>
+				<key>saveAllDocuments:</key>
+				<string>id</string>
+				<key>saveDocument:</key>
+				<string>id</string>
+				<key>saveDocumentAs:</key>
+				<string>id</string>
+				<key>saveDocumentTo:</key>
+				<string>id</string>
+				<key>selectAll:</key>
+				<string>id</string>
+				<key>selectText:</key>
+				<string>id</string>
+				<key>showGuessPanel:</key>
+				<string>id</string>
+				<key>showHelp:</key>
+				<string>id</string>
+				<key>start:</key>
+				<string>id</string>
+				<key>startSpeaking:</key>
+				<string>id</string>
+				<key>stop:</key>
+				<string>id</string>
+				<key>stopSpeaking:</key>
+				<string>id</string>
+				<key>subscript:</key>
+				<string>id</string>
+				<key>superscript:</key>
+				<string>id</string>
+				<key>terminate:</key>
+				<string>id</string>
+				<key>tightenKerning:</key>
+				<string>id</string>
+				<key>toggleContinuousSpellChecking:</key>
+				<string>id</string>
+				<key>toggleRuler:</key>
+				<string>id</string>
+				<key>toggleToolbarShown:</key>
+				<string>id</string>
+				<key>turnOffKerning:</key>
+				<string>id</string>
+				<key>turnOffLigatures:</key>
+				<string>id</string>
+				<key>underline:</key>
+				<string>id</string>
+				<key>undo:</key>
+				<string>id</string>
+				<key>unhideAllApplications:</key>
+				<string>id</string>
+				<key>unscript:</key>
+				<string>id</string>
+				<key>useAllLigatures:</key>
+				<string>id</string>
+				<key>useStandardKerning:</key>
+				<string>id</string>
+				<key>useStandardLigatures:</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>FirstResponder</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+	</array>
+	<key>IBVersion</key>
+	<integer>1</integer>
+</dict>
+</plist>
diff --git a/hw/darwin/quartz/apple/English.lproj/main.nib/info.nib b/hw/darwin/quartz/apple/English.lproj/main.nib/info.nib
new file mode 100644
index 0000000..88bc626
--- /dev/null
+++ b/hw/darwin/quartz/apple/English.lproj/main.nib/info.nib
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBFramework Version</key>
+	<string>588</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>244</integer>
+		<integer>29</integer>
+		<integer>423</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>9A356</string>
+	<key>targetFramework</key>
+	<string>IBCocoaFramework</string>
+</dict>
+</plist>
diff --git a/hw/darwin/quartz/apple/English.lproj/main.nib/keyedobjects.nib b/hw/darwin/quartz/apple/English.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..8b31450
Binary files /dev/null and b/hw/darwin/quartz/apple/English.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/darwin/quartz/apple/Info.plist b/hw/darwin/quartz/apple/Info.plist
new file mode 100644
index 0000000..9437f77
--- /dev/null
+++ b/hw/darwin/quartz/apple/Info.plist
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>X11</string>
+	<key>CFBundleGetInfoString</key>
+	<string>X11</string>
+	<key>CFBundleIconFile</key>
+	<string>X11.icns</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.x.X11</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>X11</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>2.1.0</string>
+	<key>CFBundleSignature</key>
+	<string>x11a</string>
+	<key>CSResourcesFileMapped</key>
+	<true/>
+	<key>NSHumanReadableCopyright</key>
+	<string>Copyright © 2003-2007, Apple Inc.
+Copyright © 2003, XFree86 Project, Inc.
+Copyright © 2003-2007, X.org Project, Inc.
+</string>
+	<key>NSMainNibFile</key>
+	<string>main</string>
+	<key>NSPrincipalClass</key>
+	<string>X11Application</string>
+</dict>
+</plist>
diff --git a/hw/darwin/quartz/apple/Makefile.am b/hw/darwin/quartz/apple/Makefile.am
new file mode 100644
index 0000000..a6e2dfb
--- /dev/null
+++ b/hw/darwin/quartz/apple/Makefile.am
@@ -0,0 +1,28 @@
+bin_SCRIPTS = x11app
+
+.PHONY: x11app
+
+x11app:
+	xcodebuild CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" ARCHS="$(X11APP_ARCHS)"
+
+install-data-hook:
+	xcodebuild install DSTROOT="/$(DESTDIR)" INSTALL_PATH="$(APPLE_APPLICATIONS_DIR)" DEPLOYMENT_LOCATION=YES SKIP_INSTALL=NO ARCHS="$(X11APP_ARCHS)"
+	$(MKDIR_P) "$(DESTDIR)/System/Library/LaunchAgents/"
+	$(INSTALL) org.x.X11.plist "$(DESTDIR)/System/Library/LaunchAgents/"
+
+clean-local:
+	rm -rf build
+
+EXTRA_DIST = \
+	org.x.X11.plist \
+	Info.plist \
+	X11.icns \
+	bundle-main.c \
+	launcher-main.c \
+	server-main.c \
+	English.lproj/InfoPlist.strings \
+	English.lproj/Localizable.strings \
+	English.lproj/main.nib/classes.nib \
+	English.lproj/main.nib/info.nib \
+	English.lproj/main.nib/keyedobjects.nib \
+	X11.xcodeproj/project.pbxproj
diff --git a/hw/darwin/quartz/apple/X11.icns b/hw/darwin/quartz/apple/X11.icns
new file mode 100644
index 0000000..d770e61
Binary files /dev/null and b/hw/darwin/quartz/apple/X11.icns differ
diff --git a/hw/darwin/quartz/apple/X11.xcodeproj/project.pbxproj b/hw/darwin/quartz/apple/X11.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..225f371
--- /dev/null
+++ b/hw/darwin/quartz/apple/X11.xcodeproj/project.pbxproj
@@ -0,0 +1,344 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 42;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDE0D04BF110020CA24 /* launcher-main.c */; };
+		3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDF0D04BF110020CA24 /* server-main.c */; };
+		527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
+		527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
+		527F241B0B5D938C007840A7 /* X11.icns in Resources */ = {isa = PBXBuildFile; fileRef = 50459C5F038587C60ECA21EC /* X11.icns */; };
+		527F241D0B5D938C007840A7 /* bundle-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 50EE2AB703849F0B0ECA21EC /* bundle-main.c */; };
+		527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */; };
+		527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570C5748047186C400ACF82F /* SystemConfiguration.framework */; };
+		527F24370B5D9D89007840A7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 527F24260B5D938C007840A7 /* Info.plist */; };
+		52D9C0ED0BCDDF6B00CD2AFC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
+		3F5E1BDE0D04BF110020CA24 /* launcher-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "launcher-main.c"; sourceTree = "<group>"; };
+		3F5E1BDF0D04BF110020CA24 /* server-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "server-main.c"; sourceTree = "<group>"; };
+		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
+		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
+		50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
+		527F24260B5D938C007840A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
+		527F24270B5D938C007840A7 /* X11.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = X11.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		52D9C0EC0BCDDF6B00CD2AFC /* English */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/Localizable.strings; sourceTree = "<group>"; };
+		570C5748047186C400ACF82F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		527F241E0B5D938C007840A7 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */,
+				527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		195DF8CFFE9D517E11CA2CBB /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				527F24270B5D938C007840A7 /* X11.app */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		20286C29FDCF999611CA2CEA /* X11 */ = {
+			isa = PBXGroup;
+			children = (
+				20286C2AFDCF999611CA2CEA /* Sources */,
+				20286C2CFDCF999611CA2CEA /* Resources */,
+				20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */,
+				195DF8CFFE9D517E11CA2CBB /* Products */,
+				527F24260B5D938C007840A7 /* Info.plist */,
+			);
+			name = X11;
+			sourceTree = "<group>";
+		};
+		20286C2AFDCF999611CA2CEA /* Sources */ = {
+			isa = PBXGroup;
+			children = (
+				3F5E1BDE0D04BF110020CA24 /* launcher-main.c */,
+				3F5E1BDF0D04BF110020CA24 /* server-main.c */,
+				50EE2AB703849F0B0ECA21EC /* bundle-main.c */,
+			);
+			name = Sources;
+			sourceTree = "<group>";
+		};
+		20286C2CFDCF999611CA2CEA /* Resources */ = {
+			isa = PBXGroup;
+			children = (
+				52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */,
+				50459C5F038587C60ECA21EC /* X11.icns */,
+				0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */,
+				02345980000FD03B11CA0E72 /* main.nib */,
+			);
+			name = Resources;
+			sourceTree = "<group>";
+		};
+		20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */ = {
+			isa = PBXGroup;
+			children = (
+				50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */,
+				570C5748047186C400ACF82F /* SystemConfiguration.framework */,
+			);
+			name = "External Frameworks and Libraries";
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+		527F24170B5D938C007840A7 /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+		527F24160B5D938C007840A7 /* X11 */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */;
+			buildPhases = (
+				527F24170B5D938C007840A7 /* Headers */,
+				527F24180B5D938C007840A7 /* Resources */,
+				527F241C0B5D938C007840A7 /* Sources */,
+				527F241E0B5D938C007840A7 /* Frameworks */,
+				527F24210B5D938C007840A7 /* Rez */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = X11;
+			productName = X11;
+			productReference = 527F24270B5D938C007840A7 /* X11.app */;
+			productType = "com.apple.product-type.application";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		20286C28FDCF999611CA2CEA /* Project object */ = {
+			isa = PBXProject;
+			buildConfigurationList = 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */;
+			compatibilityVersion = "Xcode 2.4";
+			hasScannedForEncodings = 1;
+			mainGroup = 20286C29FDCF999611CA2CEA /* X11 */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				527F24160B5D938C007840A7 /* X11 */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+		527F24180B5D938C007840A7 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F24370B5D9D89007840A7 /* Info.plist in Resources */,
+				527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */,
+				527F241A0B5D938C007840A7 /* main.nib in Resources */,
+				527F241B0B5D938C007840A7 /* X11.icns in Resources */,
+				52D9C0ED0BCDDF6B00CD2AFC /* Localizable.strings in Resources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXRezBuildPhase section */
+		527F24210B5D938C007840A7 /* Rez */ = {
+			isa = PBXRezBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXRezBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+		527F241C0B5D938C007840A7 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F241D0B5D938C007840A7 /* bundle-main.c in Sources */,
+				3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */,
+				3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+		02345980000FD03B11CA0E72 /* main.nib */ = {
+			isa = PBXVariantGroup;
+			children = (
+				1870340FFE93FCAF11CA0CD7 /* English */,
+			);
+			name = main.nib;
+			sourceTree = "<group>";
+		};
+		0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */ = {
+			isa = PBXVariantGroup;
+			children = (
+				0867D6ABFE840B52C02AAC07 /* English */,
+			);
+			name = InfoPlist.strings;
+			sourceTree = "<group>";
+		};
+		52D9C0EB0BCDDF6B00CD2AFC /* Localizable.strings */ = {
+			isa = PBXVariantGroup;
+			children = (
+				52D9C0EC0BCDDF6B00CD2AFC /* English */,
+			);
+			name = Localizable.strings;
+			sourceTree = "<group>";
+		};
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+		527F24090B5D8FFC007840A7 /* Development */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				INSTALL_MODE_FLAG = "a+rX";
+			};
+			name = Development;
+		};
+		527F240A0B5D8FFC007840A7 /* Deployment */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				INSTALL_MODE_FLAG = "a+rX";
+			};
+			name = Deployment;
+		};
+		527F240B0B5D8FFC007840A7 /* Default */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				INSTALL_MODE_FLAG = "a+rX";
+			};
+			name = Default;
+		};
+		527F24230B5D938C007840A7 /* Development */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = /usr/X11;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lxcb",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Development;
+		};
+		527F24240B5D938C007840A7 /* Deployment */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = /usr/X11;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lxcb",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Deployment;
+		};
+		527F24250B5D938C007840A7 /* Default */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = /usr/X11;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lxcb",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Default;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				527F24090B5D8FFC007840A7 /* Development */,
+				527F240A0B5D8FFC007840A7 /* Deployment */,
+				527F240B0B5D8FFC007840A7 /* Default */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Default;
+		};
+		527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				527F24230B5D938C007840A7 /* Development */,
+				527F24240B5D938C007840A7 /* Deployment */,
+				527F24250B5D938C007840A7 /* Default */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Default;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 20286C28FDCF999611CA2CEA /* Project object */;
+}
diff --git a/hw/darwin/quartz/apple/bundle-main.c b/hw/darwin/quartz/apple/bundle-main.c
new file mode 100644
index 0000000..c436d51
--- /dev/null
+++ b/hw/darwin/quartz/apple/bundle-main.c
@@ -0,0 +1,82 @@
+/* main.c -- X application launcher
+ 
+ Copyright (c) 2007 Jeremy Huddleston
+ Copyright (c) 2007 Apple Inc
+ 
+ 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 <X11/Xlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+int launcher_main(int argc, char **argv);
+int server_main(int argc, char **argv);
+
+int main(int argc, char **argv) {
+    Display *display;
+  
+    fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
+    int i;
+    for(i=0; i < argc; i++) {
+        fprintf(stderr, "\targv[%d] = %s\n", i, argv[i]);
+    }
+    
+    /* First check if launchd started us */
+    if(argc == 2 && !strncmp(argv[1], "--launchd", 9)) {
+        argc--;
+        argv[1] = argv[0];
+        argv++;
+        fprintf(stderr, "X11.app: main(): launchd called us, running server_main()");
+        return server_main(argc, argv);
+    }
+
+    /* If we have a process serial number and it's our only arg, act as if
+     * the user double clicked the app bundle: launch app_to_run if possible
+     */
+    if(argc == 1 || (argc == 2 && !strncmp(argv[1], "-psn_", 5))) {
+        /* Now, try to open a display, if so, run the launcher */
+        display = XOpenDisplay(NULL);
+        if(display) {
+            fprintf(stderr, "X11.app: main(): closing the display");
+            /* Could open the display, start the launcher */
+            XCloseDisplay(display);
+
+            /* Give 2 seconds for the server to start... 
+             * TODO: *Really* fix this race condition
+             */
+            usleep(2000);
+            fprintf(stderr, "X11.app: main(): running launcher_main()");
+            return launcher_main(argc, argv);
+        }
+    }
+
+    /* Couldn't open the display or we were called with arguments,
+     * just want to start a server.
+     */
+    fprintf(stderr, "X11.app: main(): running server_main()");
+    return server_main(argc, argv);
+}
diff --git a/hw/darwin/quartz/apple/launcher-main.c b/hw/darwin/quartz/apple/launcher-main.c
new file mode 100644
index 0000000..60a1624
--- /dev/null
+++ b/hw/darwin/quartz/apple/launcher-main.c
@@ -0,0 +1,81 @@
+/* main.c -- X application launcher
+ 
+ Copyright (c) 2007 Apple Inc.
+ 
+ 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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#define DEFAULT_APP "/usr/X11/bin/xterm"
+
+int launcher_main (int argc, char **argv) {
+  char *command = DEFAULT_APP;
+  const char *newargv[7];
+  int child;
+  
+
+	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"),
+									kCFPreferencesCurrentApplication);
+	
+	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_APP), 
+								 kCFPreferencesCurrentApplication);
+		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+	} else {
+		int len = CFStringGetLength((CFStringRef)PlistRef)+1;
+		command = (char *) malloc(len);
+		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
+		fprintf(stderr, "command=%s\n", command);
+	}
+	
+	if (PlistRef) CFRelease(PlistRef);
+	
+	newargv[0] = "/usr/bin/login";
+	newargv[1] = "-fp";
+	newargv[2] = getlogin();
+	newargv[3] = "/bin/sh";
+	newargv[4] = "-c";
+	newargv[5] = command;
+	newargv[6] = NULL;
+
+    child = fork();
+	
+    switch (child) {
+    case -1:				/* error */
+      perror ("fork");
+      return EXIT_FAILURE;		
+    case 0:				    /* child */
+      execvp (newargv[0], (char **const) newargv);
+      perror ("Couldn't exec");
+      _exit (1);
+   }
+	
+    return 0;
+}
diff --git a/hw/darwin/quartz/apple/org.x.X11.plist b/hw/darwin/quartz/apple/org.x.X11.plist
new file mode 100644
index 0000000..6c6be91
--- /dev/null
+++ b/hw/darwin/quartz/apple/org.x.X11.plist
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>Label</key>
+		<string>org.x.X11</string>
+	<key>Program</key>
+		<string>/Applications/Utilities/X11.app/Contents/MacOS/X11</string>
+	<key>ProgramArguments</key>
+		<array>
+		<string>/Applications/Utilities/X11.app/Contents/MacOS/X11</string>
+		<string>--launchd</string>
+		</array>
+	<key>Sockets</key>
+		<dict>
+		<key>:0</key>
+			<dict>
+			<key>SecureSocketWithKey</key>
+				<string>DISPLAY</string>
+			</dict>
+		</dict>
+	<key>ServiceIPC</key>
+		<true/>
+</dict>
+</plist>
diff --git a/hw/darwin/quartz/apple/server-main.c b/hw/darwin/quartz/apple/server-main.c
new file mode 100644
index 0000000..26fcbb0
--- /dev/null
+++ b/hw/darwin/quartz/apple/server-main.c
@@ -0,0 +1,904 @@
+/* bundle-main.c -- X server launcher
+ 
+ Copyright (c) 2002-2007 Apple Inc. 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.
+ 
+ Parts of this file are derived from xdm, which has this copyright:
+ 
+ Copyright 1988, 1998  The Open Group
+ 
+ Permission to use, copy, modify, distribute, and sell this software
+ and its documentation for any purpose is hereby granted without fee,
+ provided that the above copyright notice appear in all copies and
+ that both that copyright notice and this permission notice appear in
+ supporting documentation.
+ 
+ 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 OPEN GROUP 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 of The Open Group shall
+ not be used in advertising or otherwise to promote the sale, use or
+ other dealings in this Software without prior written authorization
+ from The Open Group. */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/utsname.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <time.h>
+#include <sys/wait.h>
+#include <setjmp.h>
+#include <sys/ioctl.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xauth.h>
+#include <xcb/xcb.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+#define X_SERVER "/usr/X11/bin/Xquartz"
+#define XTERM_PATH "/usr/X11/bin/xterm"
+#define WM_PATH "/usr/bin/quartz-wm"
+#define DEFAULT_XINITRC "/usr/X11/lib/X11/xinit/xinitrc"
+#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"
+
+/* what xinit does */
+#ifndef SHELL
+# define SHELL "sh"
+#endif
+
+#undef FALSE
+#define FALSE 0
+#undef TRUE
+#define TRUE 1
+
+#define MAX_DISPLAYS 64
+
+static int server_pid = -1, client_pid = -1;
+static int xinit_kills_server = FALSE;
+static jmp_buf exit_continuation;
+static const char *server_name = NULL;
+static Display *server_dpy;
+
+static char *auth_file;
+
+typedef struct addr_list_struct addr_list;
+
+struct addr_list_struct {
+    addr_list *next;
+    Xauth auth;
+};
+
+static addr_list *addresses;
+
+
+/* Utility functions. */
+
+/* Return the current host name. Matches what Xlib does. */
+static char *
+host_name (void)
+{
+#ifdef NEED_UTSNAME
+    static struct utsname name;
+	
+    uname(&name);
+	
+    return name.nodename;
+#else
+    static char buf[100];
+	
+    gethostname(buf, sizeof(buf));
+	
+    return buf;
+#endif
+}
+
+static int
+read_boolean_pref (CFStringRef name, int default_)
+{
+    int value;
+    Boolean ok;
+	
+    value = CFPreferencesGetAppBooleanValue (name,
+											 CFSTR ("com.apple.x11"), &ok);
+    return ok ? value : default_;
+}
+
+static inline int
+binary_equal (const void *a, const void *b, int length)
+{
+    return memcmp (a, b, length) == 0;
+}
+
+static inline void *
+binary_dup (const void *a, int length)
+{
+    void *b = malloc (length);
+    if (b != NULL)
+		memcpy (b, a, length);
+    return b;
+}
+
+static inline void
+binary_free (void *data, int length)
+{
+    if (data != NULL)
+		free (data);
+}
+
+
+/* Functions for managing the authentication entries. */
+
+/* Returns true if something matching AUTH is in our list of auth items */
+static int
+check_auth_item (Xauth *auth)
+{
+    addr_list *a;
+	
+    for (a = addresses; a != NULL; a = a->next)
+    {
+		if (a->auth.family == auth->family
+			&& a->auth.address_length == auth->address_length
+			&& binary_equal (a->auth.address, auth->address, auth->address_length)
+			&& a->auth.number_length == auth->number_length
+			&& binary_equal (a->auth.number, auth->number, auth->number_length)
+			&& a->auth.name_length == auth->name_length
+			&& binary_equal (a->auth.name, auth->name, auth->name_length))
+		{
+			return TRUE;
+		}
+    }
+	
+    return FALSE;
+}
+
+/* Add one item to our list of auth items. */
+static void
+add_auth_item (Xauth *auth)
+{
+    addr_list *a = malloc (sizeof (addr_list));
+	
+    a->auth.family = auth->family;
+    a->auth.address_length = auth->address_length;
+    a->auth.address = binary_dup (auth->address, auth->address_length);
+    a->auth.number_length = auth->number_length;
+    a->auth.number = binary_dup (auth->number, auth->number_length);
+    a->auth.name_length = auth->name_length;
+    a->auth.name = binary_dup (auth->name, auth->name_length);
+    a->auth.data_length = auth->data_length;
+    a->auth.data = binary_dup (auth->data, auth->data_length);
+	
+    a->next = addresses;
+    addresses = a;
+}
+
+/* Free all allocated auth items. */
+static void
+free_auth_items (void)
+{
+    addr_list *a;
+	
+    while ((a = addresses) != NULL)
+    {
+		addresses = a->next;
+		
+		binary_free (a->auth.address, a->auth.address_length);
+		binary_free (a->auth.number, a->auth.number_length);
+		binary_free (a->auth.name, a->auth.name_length);
+		binary_free (a->auth.data, a->auth.data_length);
+		free (a);
+    }
+}
+
+/* Add the unix domain auth item. */
+static void
+define_local (Xauth *auth)
+{
+    char *host = host_name ();
+	
+#ifdef DEBUG
+    fprintf (stderr, "x11: hostname is %s\n", host);
+#endif
+	
+    auth->family = FamilyLocal;
+    auth->address_length = strlen (host);
+    auth->address = host;
+	
+    add_auth_item (auth);
+}
+
+/* Add the tcp auth item. */
+static void
+define_named (Xauth *auth, const char *name)
+{
+    struct ifaddrs *addrs, *ptr;
+	
+    if (getifaddrs (&addrs) != 0)
+		return;
+	
+    for (ptr = addrs; ptr != NULL; ptr = ptr->ifa_next)
+    {
+		if (ptr->ifa_addr->sa_family != AF_INET)
+			continue;
+		
+		auth->family = FamilyInternet;
+		auth->address_length = sizeof (struct in_addr);
+		auth->address = (char *) &(((struct sockaddr_in *) ptr->ifa_addr)->sin_addr);
+		
+#ifdef DEBUG
+		fprintf (stderr, "x11: ipaddr is %d.%d.%d.%d\n",
+				 (unsigned char) auth->address[0],
+				 (unsigned char) auth->address[1],
+				 (unsigned char) auth->address[2],
+				 (unsigned char) auth->address[3]);
+#endif
+		
+		add_auth_item (auth);
+    }
+	
+    freeifaddrs (addrs);
+}
+
+/* Parse the display number from NAME and add it to AUTH. */
+static void
+set_auth_number (Xauth *auth, const char *name)
+{
+    char *colon;
+    char *dot, *number;
+	
+    colon = strrchr(name, ':');
+    if (colon != NULL)
+    {
+		colon++;
+		dot = strchr(colon, '.');
+		
+		if (dot != NULL)
+			auth->number_length = dot - colon;
+		else
+			auth->number_length = strlen (colon);
+		
+		number = malloc (auth->number_length + 1);
+		if (number != NULL)
+		{
+			strncpy (number, colon, auth->number_length);
+			number[auth->number_length] = '\0';
+		}
+		else
+		{
+			auth->number_length = 0;
+		}
+		
+		auth->number = number;
+    }
+}
+
+/* Put 128 bits of random data into DATA. If possible, it will be "high
+ quality" */
+static int
+generate_mit_magic_cookie (char data[16])
+{
+    int fd, ret, i;
+    long *ldata = (long *) data;
+	
+    fd = open ("/dev/random", O_RDONLY);
+    if (fd > 0) {
+		ret = read (fd, data, 16);
+		close (fd);
+		if (ret == 16) return TRUE;
+    }
+	
+    /* fall back to the usual crappy rng */
+	
+    srand48 (getpid () ^ time (NULL));
+	
+    for (i = 0; i < 4; i++)
+		ldata[i] = lrand48 ();
+	
+    return TRUE;
+}
+
+/* Create the keys we'll be using for the display named NAME. */
+static int
+make_auth_keys (const char *name)
+{
+    Xauth auth;
+    char key[16];
+	
+    if (auth_file == NULL)
+		return FALSE;
+	
+    auth.name = "MIT-MAGIC-COOKIE-1";
+    auth.name_length = strlen (auth.name);
+	
+    if (!generate_mit_magic_cookie (key))
+    {
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    auth.data = key;
+    auth.data_length = 16;
+	
+    set_auth_number (&auth, name);
+	
+    define_named (&auth, host_name ());
+    define_local (&auth);
+	
+    free (auth.number);
+	
+    return TRUE;
+}
+
+/* If ADD-ENTRIES is true, merge our auth entries into the existing
+ Xauthority file. If ADD-ENTRIES is false, remove our entries. */
+static int
+write_auth_file (int add_entries)
+{
+    char *home, newname[1024];
+    int fd, ret;
+    FILE *new_fh, *old_fh;
+    addr_list *addr;
+    Xauth *auth;
+	
+    if (auth_file == NULL)
+		return FALSE;
+	
+    home = getenv ("HOME");
+    if (home == NULL)
+    {
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    snprintf (newname, sizeof (newname), "%s/.XauthorityXXXXXX", home);
+    mktemp (newname);
+	
+    if (XauLockAuth (auth_file, 1, 2, 10) != LOCK_SUCCESS)
+    {
+		/* FIXME: do something here? */
+		
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    fd = open (newname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+    if (fd >= 0)
+    {
+		new_fh = fdopen (fd, "w");
+		if (new_fh != NULL)
+		{
+			if (add_entries)
+			{
+				for (addr = addresses; addr != NULL; addr = addr->next)
+				{
+					XauWriteAuth (new_fh, &addr->auth);
+				}
+			}
+			
+			old_fh = fopen (auth_file, "r");
+			if (old_fh != NULL)
+			{
+				while ((auth = XauReadAuth (old_fh)) != NULL)
+				{
+					if (!check_auth_item (auth))
+						XauWriteAuth (new_fh, auth);
+					XauDisposeAuth (auth);
+				}
+				fclose (old_fh);
+			}
+			
+			fclose (new_fh);
+			unlink (auth_file);
+			
+			ret = rename (newname, auth_file);
+			
+			if (ret != 0)
+				auth_file = NULL;
+			
+			XauUnlockAuth (auth_file);
+			return ret == 0;
+		}
+		
+		close (fd);
+    }
+	
+    XauUnlockAuth (auth_file);
+    auth_file = NULL;
+    return FALSE;
+}
+
+
+/* Subprocess management functions. */
+
+static int
+start_server (char **xargv)
+{
+    int child;
+	
+    child = fork ();
+	
+    switch (child)
+    {
+    case -1:				/* error */
+		perror ("fork");
+		return FALSE;
+		
+    case 0:				/* child */
+		execv (X_SERVER, xargv);
+		perror ("Couldn't exec " X_SERVER);
+		_exit (1);
+		
+    default:				/* parent */
+		server_pid = child;
+		return TRUE;
+    }
+}
+
+static int
+wait_for_server (void)
+{
+    int count = 100;
+	
+    while (count-- > 0)
+    {
+		int status;
+		
+		server_dpy = XOpenDisplay (server_name);
+		if (server_dpy != NULL)
+			return TRUE;
+		
+		if (waitpid (server_pid, &status, WNOHANG) == server_pid)
+			return FALSE;
+		
+		sleep (1);
+    }
+	
+    return FALSE;
+}
+
+static int
+start_client (void)
+{
+    int child;
+	
+    child = fork();
+	
+    switch (child) {
+		char *temp, buf[1024];		
+
+	case -1:				/* error */
+		perror("fork");
+		return FALSE;
+
+	case 0:					/* child */
+		/* Setup environment */
+		temp = getenv("DISPLAY");
+//		if (temp == NULL && temp[0] != 0)
+			setenv("DISPLAY", server_name, TRUE);
+
+		temp = getenv("PATH");
+		if (temp == NULL || temp[0] == 0) 
+			setenv ("PATH", DEFAULT_PATH, TRUE);
+		else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) {
+			snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp);		
+			setenv("PATH", buf, TRUE);	
+		}
+		
+		/* First try value of $XINITRC, if set. */
+		temp = getenv("XINITRC");
+		if (temp != NULL && temp[0] != 0 && access(temp, R_OK) == 0)
+			execlp (SHELL, SHELL, temp, NULL);
+
+		/* Then look for .xinitrc in user's home directory. */
+		temp = getenv("HOME");
+		if (temp != NULL && temp[0] != 0) {
+			chdir(temp);
+			snprintf (buf, sizeof (buf), "%s/.xinitrc", temp);
+			if (access(buf, R_OK) == 0)
+				execlp(SHELL, SHELL, buf, NULL);
+		}
+		
+		/* Then try the default xinitrc in the lib directory. */
+		
+		if (access(DEFAULT_XINITRC, R_OK) == 0)
+			execlp(SHELL, SHELL, DEFAULT_XINITRC, NULL);
+		
+		/* Then fallback to hardcoding an xterm and the window manager. */
+		
+		//		system(XTERM_PATH " &");
+		execl(WM_PATH, WM_PATH, NULL);
+		
+		perror("exec");
+		_exit(1);
+		
+    default:				/* parent */
+		client_pid = child;
+		return TRUE;
+    }
+}
+
+static void
+sigchld_handler (int sig)
+{
+    int pid, status;
+	
+	again:
+    pid = waitpid (WAIT_ANY, &status, WNOHANG);
+	
+    if (pid > 0)
+    {
+		if (pid == server_pid)
+		{
+			server_pid = -1;
+			
+			if (client_pid >= 0)
+				kill (client_pid, SIGTERM);
+		}
+		else if (pid == client_pid)
+		{
+			client_pid = -1;
+			
+			if (server_pid >= 0 && xinit_kills_server)
+				kill (server_pid, SIGTERM);
+		}
+		goto again;
+    }
+	
+    if (server_pid == -1 && client_pid == -1)
+		longjmp (exit_continuation, 1);
+	
+    signal (SIGCHLD, sigchld_handler);
+}
+
+
+/* Server utilities. */
+
+static Boolean
+display_exists_p (int number)
+{
+    char buf[64];
+    xcb_connection_t *conn;
+    char *fullname = NULL;
+    int idisplay, iscreen;
+    char *conn_auth_name, *conn_auth_data;
+    int conn_auth_namelen, conn_auth_datalen;
+    
+    //    extern void *_X11TransConnectDisplay ();
+    //    extern void _XDisconnectDisplay ();
+	
+    /* Since connecting to the display waits for a few seconds if the
+	 display doesn't exist, check for trivial non-existence - if the
+	 socket in /tmp exists or not.. (note: if the socket exists, the
+	 server may still not, so we need to try to connect in that case..) */
+	
+    sprintf (buf, "/tmp/.X11-unix/X%d", number);
+    if (access (buf, F_OK) != 0)
+		return FALSE;
+    
+    sprintf (buf, ":%d", number);
+    conn = xcb_connect(buf, NULL);
+    if (xcb_connection_has_error(conn)) return FALSE;
+	
+    xcb_disconnect(conn);
+    return TRUE;
+}
+
+
+/* Monitoring when the system's ip addresses change. */
+
+static Boolean pending_timer;
+
+static void
+timer_callback (CFRunLoopTimerRef timer, void *info)
+{
+    pending_timer = FALSE;
+	
+    /* Update authentication names. Need to write .Xauthority file first
+	 without the existing entries, then again with the new entries.. */
+	
+    write_auth_file (FALSE);
+	
+    free_auth_items ();
+    make_auth_keys (server_name);
+	
+    write_auth_file (TRUE);
+}
+
+/* This function is called when the system's ip addresses may have changed. */
+static void
+ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
+{
+#if DEBUG
+    if (changed_keys != NULL) {
+		fprintf (stderr, "x11: changed sc keys: ");
+		CFShow (changed_keys);
+    }
+#endif
+
+    if (auth_file != NULL && !pending_timer)
+    {
+		CFRunLoopTimerRef timer;
+		
+		timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
+									  0.0, 0, 0, timer_callback, NULL);
+		CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
+						   kCFRunLoopDefaultMode);
+		CFRelease (timer);
+		
+		pending_timer = TRUE;
+    }
+}
+
+/* This code adapted from "Living in a Dynamic TCP/IP Environment" technote. */
+static Boolean
+install_ipaddr_source (void)
+{
+    CFRunLoopSourceRef source = NULL;
+	
+    SCDynamicStoreContext context = {0};
+    SCDynamicStoreRef ref;
+	
+    ref = SCDynamicStoreCreate (NULL,
+								CFSTR ("AddIPAddressListChangeCallbackSCF"),
+								ipaddr_callback, &context);
+	
+    if (ref != NULL)
+    {
+		const void *keys[4], *patterns[2];
+		int i;
+		
+		keys[0] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
+		keys[1] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6);
+		keys[2] = SCDynamicStoreKeyCreateComputerName (NULL);
+		keys[3] = SCDynamicStoreKeyCreateHostNames (NULL);
+		
+		patterns[0] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4);
+		patterns[1] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6);
+		
+		if (keys[0] != NULL && keys[1] != NULL && keys[2] != NULL
+			&& keys[3] != NULL && patterns[0] != NULL && patterns[1] != NULL)
+		{
+			CFArrayRef key_array, pattern_array;
+			
+			key_array = CFArrayCreate (NULL, keys, 4, &kCFTypeArrayCallBacks);
+			pattern_array = CFArrayCreate (NULL, patterns, 2, &kCFTypeArrayCallBacks);
+			
+			if (key_array != NULL || pattern_array != NULL)
+			{
+				SCDynamicStoreSetNotificationKeys (ref, key_array, pattern_array);
+				source = SCDynamicStoreCreateRunLoopSource (NULL, ref, 0);
+			}
+			
+			if (key_array != NULL)
+				CFRelease (key_array);
+			if (pattern_array != NULL)
+				CFRelease (pattern_array);
+		}
+		
+		
+		for (i = 0; i < 4; i++)
+			if (keys[i] != NULL)
+			CFRelease (keys[i]);
+		for (i = 0; i < 2; i++)
+			if (patterns[i] != NULL)
+			CFRelease (patterns[i]);
+		
+		CFRelease (ref); 
+    }
+	
+    if (source != NULL)
+    {
+		CFRunLoopAddSource (CFRunLoopGetCurrent (),
+							source, kCFRunLoopDefaultMode);
+		CFRelease (source);
+    }
+	
+    return source != NULL;
+}
+
+
+/* Entrypoint. */
+
+void
+termination_signal_handler (int unused_sig)
+{
+    signal (SIGTERM, SIG_DFL);
+    signal (SIGHUP, SIG_DFL);
+    signal (SIGINT, SIG_DFL);
+    signal (SIGQUIT, SIG_DFL);
+
+    longjmp (exit_continuation, 1);
+}
+
+int
+server_main (int argc, char **argv)
+{
+    char **xargv;
+    int i, j;
+    int fd;
+	
+    xargv = alloca (sizeof (char *) * (argc + 32));
+	
+    if (!read_boolean_pref (CFSTR ("no_auth"), FALSE))
+		auth_file = XauFileName ();
+	
+    /* The standard X11 behaviour is for the server to quit when the first
+	 client exits. But it can be useful for debugging (and to mimic our
+	 behaviour in the beta releases) to not do that. */
+	
+    xinit_kills_server = read_boolean_pref (CFSTR ("xinit_kills_server"), TRUE);
+	
+    for (i = 1; i < argc; i++)
+    {
+		if (argv[i][0] == ':')
+			server_name = argv[i];
+    }
+	
+    if (server_name == NULL)
+    {
+		static char name[8];
+		
+		/* No display number specified, so search for the first unused.
+		 
+		 There's a big old race condition here if two servers start at
+		 the same time, but that's fairly unlikely. We could create
+		 lockfiles or something, but that's seems more likely to cause
+		 problems than the race condition itself.. */
+		
+		for (i = 0; i < MAX_DISPLAYS; i++)
+		{
+			if (!display_exists_p (i))
+				break;
+		}
+		
+		if (i == MAX_DISPLAYS)
+		{
+			fprintf (stderr, "%s: couldn't allocate a display number", argv[0]);
+			exit (1);
+		}
+		
+		sprintf (name, ":%d", i);
+		server_name = name;
+    }
+	
+    if (auth_file != NULL)
+    {
+		/* Create new Xauth keys and add them to the .Xauthority file */
+		
+		make_auth_keys (server_name);
+		write_auth_file (TRUE);
+    }
+	
+    /* Construct our new argv */
+	
+    i = j = 0;
+	
+    xargv[i++] = argv[j++];
+	
+    if (auth_file != NULL)
+    {
+		xargv[i++] = "-auth";
+		xargv[i++] = auth_file;
+    }
+	
+    /* By default, don't listen on tcp sockets if Xauth is disabled. */
+	
+    if (read_boolean_pref (CFSTR ("nolisten_tcp"), auth_file == NULL))
+    {
+		xargv[i++] = "-nolisten";
+		xargv[i++] = "tcp";
+    }
+	
+    while (j < argc)
+    {
+		if (argv[j++][0] != ':')
+			xargv[i++] = argv[j-1];
+    }
+	
+    xargv[i++] = (char *) server_name;
+    xargv[i++] = NULL;
+	
+    /* Detach from any controlling terminal and connect stdin to /dev/null */
+	
+#ifdef TIOCNOTTY
+    fd = open ("/dev/tty", O_RDONLY);
+    if (fd != -1)
+    {
+		ioctl (fd, TIOCNOTTY, 0);
+		close (fd);
+    }
+#endif
+	
+    fd = open ("/dev/null", O_RDWR, 0);
+    if (fd >= 0)
+    {
+		dup2 (fd, 0);
+		if (fd > 0)
+			close (fd);
+    }
+	
+    if (!start_server (xargv))
+		return 1;
+	
+    if (!wait_for_server ())
+    {
+		kill (server_pid, SIGTERM);
+		return 1;
+    }
+	
+    if (!start_client ())
+    {
+		kill (server_pid, SIGTERM);
+		return 1;
+    }
+	
+    signal (SIGCHLD, sigchld_handler);
+	
+    signal (SIGTERM, termination_signal_handler);
+    signal (SIGHUP, termination_signal_handler);
+    signal (SIGINT, termination_signal_handler);
+    signal (SIGQUIT, termination_signal_handler);
+
+    if (setjmp (exit_continuation) == 0)
+    {
+		if (install_ipaddr_source ())
+			CFRunLoopRun ();
+		else
+			while (1) pause ();
+    }
+	
+    signal (SIGCHLD, SIG_IGN);
+
+    if (client_pid >= 0) kill (client_pid, SIGTERM);
+    if (server_pid >= 0) kill (server_pid, SIGTERM);
+	
+    if (auth_file != NULL)
+    {
+		/* Remove our Xauth keys */
+		
+		write_auth_file (FALSE);
+    }
+	
+    free_auth_items ();
+	
+    return 0;
+}
diff --git a/hw/darwin/quartz/xpr/Makefile.am b/hw/darwin/quartz/xpr/Makefile.am
index 8980ad7..7696622 100644
--- a/hw/darwin/quartz/xpr/Makefile.am
+++ b/hw/darwin/quartz/xpr/Makefile.am
@@ -1,12 +1,16 @@
-noinst_LIBRARIES = libxpr.a
+bin_PROGRAMS = Xquartz
+
+# TODO: This man page needs sed magic and cleanup
+man1_MANS = Xquartz.man
+
 AM_CFLAGS =  $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_CPPFLAGS = \
-	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
-	   -I$(top_srcdir)/miext \
-	   -I$(top_srcdir)/miext/rootless \
-	   -I$(top_srcdir)/miext/rootless/safeAlpha
+	-I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
+	-I$(top_srcdir)/miext \
+	-I$(top_srcdir)/miext/rootless \
+	-I$(top_srcdir)/miext/rootless/safeAlpha
 
-libxpr_a_SOURCES = \
+Xquartz_SOURCES = \
 	appledri.c \
 	dri.c \
 	xprAppleWM.c \
@@ -17,7 +21,45 @@ libxpr_a_SOURCES = \
 	x-hook.c \
 	x-list.c
 
+Xquartz_LDADD = \
+	$(top_builddir)/hw/darwin/quartz/libXquartz.la \
+	$(top_builddir)/hw/darwin/libXdarwin.la \
+	$(top_builddir)/dix/dixfonts.lo \
+	$(top_builddir)/dix/libdix.la \
+	$(top_builddir)/os/libos.la \
+	$(top_builddir)/dix/libxpstubs.la \
+	$(top_builddir)/miext/shadow/libshadow.la \
+	$(top_builddir)/fb/libfb.la \
+	$(top_builddir)/mi/libmi.la \
+	$(top_builddir)/composite/libcomposite.la \
+	$(top_builddir)/damageext/libdamageext.la \
+	$(top_builddir)/miext/damage/libdamage.la \
+	$(top_builddir)/xfixes/libxfixes.la \
+	$(top_builddir)/miext/cw/libcw.la \
+	$(top_builddir)/Xext/libXext.la \
+	$(top_builddir)/xkb/libxkb.la \
+	$(top_builddir)/xkb/libxkbstubs.la \
+	$(top_builddir)/Xi/libXi.la \
+	$(top_builddir)/dbe/libdbe.la \
+	$(top_builddir)/record/librecord.la \
+	$(top_builddir)/XTrap/libxtrap.la \
+	$(top_builddir)/miext/rootless/librootless.la \
+	$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+	$(top_builddir)/miext/rootless/accel/librlAccel.la \
+	$(DARWIN_LIBS) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) -lXplugin
+
+Xquartz_LDFLAGS =  \
+	-XCClinker -Objc \
+	-Wl,-u,_miDCInitialize \
+	-Wl,-framework,Carbon \
+	-L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL \
+	-Wl,-framework,OpenGL \
+	-Wl,-framework,Cocoa \
+	-Wl,-framework,CoreAudio \
+	-Wl,-framework,IOKit
+
 EXTRA_DIST = \
+	Xquartz.man \
 	dri.h \
 	dristruct.h \
 	appledri.h \
diff --git a/hw/darwin/quartz/xpr/Xquartz.man b/hw/darwin/quartz/xpr/Xquartz.man
new file mode 100644
index 0000000..37a7f1a
--- /dev/null
+++ b/hw/darwin/quartz/xpr/Xquartz.man
@@ -0,0 +1,156 @@
+.TH XQUARTZ 1 __vendorversion__
+.SH NAME
+Xquartz \- X window system server for Quartz operating system
+.SH SYNOPSIS
+.B Xquartz
+[ options ] ...
+.SH DESCRIPTION
+.I Xquartz
+is the X window server for Mac OS X provided by Apple.
+.I Xquartz
+runs in parallel with Aqua in rootless mode. In rootless mode, the X
+window system and Mac OS X share your display.  The root window of the
+X11 display is the size of the screen and contains all the other
+windows. The X11 root window is not displayed in rootless mode as Mac
+OS X handles the desktop background.
+.SH OPTIONS
+.PP
+In addition to the normal server options described in the \fIXserver(1)\fP
+manual page, \fIXquartz\fP accepts the following command line switches:
+.TP 8
+.B \-fakebuttons
+Emulates a 3 button mouse using modifier keys. By default, the Command modifier
+is used to emulate button 2 and Option is used for button 3. Thus, clicking the
+first mouse button while holding down Command will act like clicking
+button 2. Holding down Option will simulate button 3.
+.TP 8
+.B \-nofakebuttons
+Do not emulate a 3 button mouse. This is the default.
+.TP 8
+.B "\-fakemouse2 \fImodifiers\fP"
+Change the modifier keys used to emulate the second mouse button. By default,
+Command is used to emulate the second button. Any combination of the following
+modifier names may be used: Shift, Option, Control, Command, Fn. For example,
+.B \-fakemouse2 """Option,Shift""
+will set holding Option, Shift and clicking on button one as equivalent to
+clicking the second mouse button.
+.TP 8
+.B "\-fakemouse3 \fImodifiers\fP"
+Change the modifier keys used to emulate the third mouse button. By default,
+Option is used to emulate the third button. Any combination of the following
+modifier names may be used: Shift, Option, Control, Command, Fn. For example,
+.B \-fakemouse3 """Control,Shift""
+will set holding Control, Shift and clicking on button one as equivalent to
+clicking the third mouse button.
+.TP 8
+.B "\-swapAltMeta"
+Swaps the meaning of the Alt and Meta modifier keys.
+.TP 8
+.B "\-keymap \fIfile\fP"
+On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
+The default is to read this keymapping from USA.keymapping. With this option
+the keymapping will be read from \fIfile\fP instead. If the file's path is
+not specified, it will be searched for in Library/Keyboards/ underneath the
+following directories (in order): ~, /, /Network, /System.
+.TP 8
+.B \-nokeymap
+On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
+With this option \fIXquartz\fP queries the kernel for the current keymapping
+instead of reading it from a file. This will often fail on newer kernels.
+.TP 8
+.B "\-depth \fIdepth\fP"
+Specifies the color bit depth to use. Currently only 15, and 24 color
+bits per pixel are supported. If not specified, defaults to the depth
+of the main display.
+.SH CUSTOMIZATION
+\fIXquartz\fP can also be customized using the defaults(1) command. The available options are:
+.TP 8
+.B defaults write com.apple.x11 enable_fake_buttons -boolean true
+Equivalent to the \fB-fakebuttons\fP command line option.
+.TP 8
+.B defaults write com.apple.x11 fake_button2 \fImodifiers\fP
+Equivalent to the \fB-fakemouse2\fP option.
+.TP 8
+.B defaults write com.apple.x11 fake_button3 \fImodifiers\fP
+Equivalent to the \fB-fakemouse3\fP option.
+.TP 8
+.B defaults write com.apple.x11 swap_alt_meta -boolean true
+Equivalent to the \fB-swapAltMeta\fP option.
+.TP 8
+.B defaults write com.apple.x11 keymap_file \fIfilename\fP
+Equivalent to the \fB-keymap\fP option.
+.TP 8
+.B defaults write com.apple.x11 no_quit_alert -boolean true
+Disables the alert dialog displayed when attempting to quit X11.
+.TP 8
+.B defaults write com.apple.x11 no_auth -boolean true
+Stops the X server requiring that clients authenticate themselves when
+connecting. See Xsecurity(__miscmansuffix__).
+.TP 8
+.B defaults write com.apple.x11 nolisten_tcp -boolean true
+Prevents the X server accepting remote connections.
+.TP 8
+.B defaults write com.apple.x11 xinit_kills_server -boolean false
+Stops the X server exiting when the xinitrc script terminates.
+.TP 8
+.B defaults write com.apple.x11 fullscreen_hotkeys -boolean false
+Allows system hotkeys to be handled while in X11 fullscreen mode.
+.TP 8
+.B defaults write com.apple.x11 enable_system_beep -boolean false
+Don't use the standard system beep effect for X11 alerts.
+.TP 8
+.B defaults write com.apple.x11 enable_key_equivalents -boolean false
+Disable menu keyboard equivalents while X11 windows are focused.
+.TP 8
+.B defaults write com.apple.x11 depth \fIdepth\fP
+Equivalent to the \fB-depth\fP option.
+.SH "SEE ALSO"
+.PP
+X(__miscmansuffix__), XFree86(1), Xserver(1), xdm(1), xinit(1)
+.PP
+.SH AUTHORS
+XFree86 was originally ported to Mac OS X Server by John Carmack. Dave
+Zarzycki used this as the basis of his port of XFree86 4.0 to Darwin 1.0.
+Torrey T. Lyons improved and integrated this code into the XFree86
+Project's mainline for the 4.0.2 release.
+.PP
+The following members of the XonX Team contributed to the following
+releases (in alphabetical order):
+.TP 4
+XFree86 4.1.0:
+.br
+Rob Braun - Darwin x86 support
+.br
+Torrey T. Lyons - Project Lead
+.br
+Andreas Monitzer - Cocoa version of XDarwin front end
+.br
+Gregory Robert Parker - Original Quartz implementation
+.br
+Christoph Pfisterer - Dynamic shared X libraries
+.br
+Toshimitsu Tanaka - Japanese localization
+.TP 4
+XFree86 4.2.0:
+.br
+Rob Braun - Darwin x86 support
+.br
+Pablo Di Noto - Spanish localization
+.br
+Paul Edens - Dutch localization
+.br
+Kyunghwan Kim - Korean localization
+.br
+Mario Klebsch - Non-US keyboard support
+.br
+Torrey T. Lyons - Project Lead
+.br
+Andreas Monitzer - German localization
+.br
+Patrik Montgomery - Swedish localization
+.br
+Greg Parker - Rootless support
+.br
+Toshimitsu Tanaka - Japanese localization
+.br
+Olivier Verdier - French localization
commit b823224a497cbeadbc5b2d548bdb2ab0f126a59b
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Tue Dec 4 17:34:42 2007 -0800

    Revert "build system cleanup: move all files from quartz/xpr/ to quartz/"
    
    This reverts commit 73c6f7983d335d0dc6698d1cb8a027f054b3ba3c.

diff --git a/configure.ac b/configure.ac
index 3425eec..170243a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2030,6 +2030,7 @@ hw/xwin/Makefile
 hw/darwin/Makefile
 hw/darwin/apple/Makefile
 hw/darwin/quartz/Makefile
+hw/darwin/quartz/xpr/Makefile
 hw/kdrive/Makefile
 hw/kdrive/ati/Makefile
 hw/kdrive/chips/Makefile
diff --git a/hw/darwin/quartz/Makefile.am b/hw/darwin/quartz/Makefile.am
index eb7d427..f5199df 100644
--- a/hw/darwin/quartz/Makefile.am
+++ b/hw/darwin/quartz/Makefile.am
@@ -4,8 +4,9 @@ AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_OBJCFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_CPPFLAGS = \
 	-I$(srcdir) -I$(srcdir)/.. \
-	-I$(top_srcdir)/miext/rootless \
-	-I$(top_srcdir)/miext/rootless/safeAlpha
+	-I$(top_srcdir)/miext/rootless
+
+SUBDIRS = xpr
 
 libXQuartz_a_SOURCES = \
 	X11Application.m \
@@ -18,16 +19,7 @@ libXQuartz_a_SOURCES = \
 	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzPasteboard.c \
-	quartzStartup.c \
-	appledri.c \
-	dri.c \
-	xprAppleWM.c \
-	xprCursor.c \
-	xprFrame.c \
-	xprScreen.c \
-	x-hash.c \
-	x-hook.c \
-	x-list.c
+	quartzStartup.c
 
 EXTRA_DIST = \
 	X11Application.h \
@@ -40,13 +32,4 @@ EXTRA_DIST = \
 	quartzCursor.c \
 	quartzCursor.h \
 	quartz.h \
-	quartzPasteboard.h \
-	dri.h \
-	dristruct.h \
-	appledri.h \
-	appledristr.h \
-	x-hash.h \
-	x-hook.h \
-	x-list.h \
-	Xplugin.h \
-	xpr.h
+	quartzPasteboard.h
diff --git a/hw/darwin/quartz/Xplugin.h b/hw/darwin/quartz/Xplugin.h
deleted file mode 100644
index a10b1b8..0000000
--- a/hw/darwin/quartz/Xplugin.h
+++ /dev/null
@@ -1,589 +0,0 @@
-/* Xplugin.h -- windowing API for rootless X11 server
-
-   Copyright (c) 2002 Apple Computer, Inc. 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.
-
-   Note that these interfaces are provided solely for the use of the
-   X11 server. Any other uses are unsupported and strongly discouraged. */
-
-#ifndef XPLUGIN_H
-#define XPLUGIN_H 1
-
-#include <stdint.h>
-
-/* By default we use the X server definition of BoxRec to define xp_box,
-   so that the compiler can silently convert between the two. But if
-   XP_NO_X_HEADERS is defined, we'll define it ourselves. */
-
-#ifndef XP_NO_X_HEADERS
-# include "miscstruct.h"
-  typedef BoxRec xp_box;
-#else
-  struct xp_box_struct {
-      short x1, y1, x2, y2;
-  };
-  typedef struct xp_box_struct xp_box;
-#endif
-
-typedef unsigned int xp_resource_id;
-typedef xp_resource_id xp_window_id;
-typedef xp_resource_id xp_surface_id;
-typedef unsigned int xp_client_id;
-typedef unsigned int xp_request_type;
-typedef int xp_error;
-typedef int xp_bool;
-
-
-/* Error codes that the functions declared here may return. They all
-   numerically match their X equivalents, i.e. the XP_ can be dropped
-   if <X11/X.h> has been included. */
-
-enum xp_error_enum {
-    XP_Success			= 0,
-    XP_BadRequest		= 1,
-    XP_BadValue			= 2,
-    XP_BadWindow		= 3,
-    XP_BadMatch			= 8,
-    XP_BadAccess		= 10,
-    XP_BadImplementation	= 17,
-};    
-
-
-/* Event types generated by the plugin. */
-
-enum xp_event_type_enum {
-    /* The global display configuration changed somehow. */
-    XP_EVENT_DISPLAY_CHANGED	= 1 << 0,
-
-    /* A window changed state. Argument is xp_window_state_event */
-    XP_EVENT_WINDOW_STATE_CHANGED = 1 << 1,
-
-    /* An async request encountered an error. Argument is of type
-       xp_async_error_event */
-    XP_EVENT_ASYNC_ERROR	= 1 << 2,
-
-    /* Sent when a surface is destroyed as a side effect of destroying
-       a window. Arg is of type xp_surface_id. */
-    XP_EVENT_SURFACE_DESTROYED	= 1 << 3,
-
-    /* Sent when any GL contexts pointing at the given surface need to
-       call xp_update_gl_context () to refresh their state (because the
-       window moved or was resized. Arg is of type xp_surface_id. */
-    XP_EVENT_SURFACE_CHANGED	= 1 << 4,
-
-    /* Sent when a window has been moved. Arg is of type xp_window_id. */
-    XP_EVENT_WINDOW_MOVED	= 1 << 5,
-};
-
-/* Function type used to receive events. */
-
-typedef void (xp_event_fun) (unsigned int type, const void *arg,
-			     unsigned int arg_size, void *user_data);
-
-
-/* Operation types. Used when reporting errors asynchronously. */
-
-enum xp_request_type_enum {
-    XP_REQUEST_NIL = 0,
-    XP_REQUEST_DESTROY_WINDOW = 1,
-    XP_REQUEST_CONFIGURE_WINDOW = 2,
-    XP_REQUEST_FLUSH_WINDOW = 3,
-    XP_REQUEST_COPY_WINDOW = 4,
-    XP_REQUEST_UNLOCK_WINDOW = 5,
-    XP_REQUEST_DISABLE_UPDATE = 6,
-    XP_REQUEST_REENABLE_UPDATE = 7,
-    XP_REQUEST_HIDE_CURSOR = 8,
-    XP_REQUEST_SHOW_CURSOR = 9,
-    XP_REQUEST_FRAME_DRAW = 10,
-};
-
-/* Structure used to report an error asynchronously. Passed as the "arg"
-   of an XP_EVENT_ASYNC_ERROR event. */
-
-struct xp_async_error_event_struct {
-    xp_request_type request_type;
-    xp_resource_id id;
-    xp_error error;
-};
-
-typedef struct xp_async_error_event_struct xp_async_error_event;
-
-
-/* Possible window states. */
-
-enum xp_window_state_enum {
-    /* The window is not in the global list of possibly-visible windows. */
-    XP_WINDOW_STATE_OFFSCREEN	= 1 << 0,
-
-    /* Parts of the window may be obscured by other windows. */
-    XP_WINDOW_STATE_OBSCURED	= 1 << 1,
-};
-
-/* Structure passed as argument of an XP_EVENT_WINDOW_STATE_CHANGED event. */
-
-struct xp_window_state_event_struct {
-    xp_window_id id;
-    unsigned int state;
-};
-
-typedef struct xp_window_state_event_struct xp_window_state_event;
-
-
-/* Function type used to supply a colormap for indexed drawables. */
-
-typedef xp_error (xp_colormap_fun) (void *data, int first_color,
-				    int n_colors, uint32_t *colors);
-
-
-/* Window attributes structure. Used when creating and configuring windows.
-   Also used when configuring surfaces attached to windows. Functions that
-   take one of these structures also take a bit mask defining which
-   fields are set to meaningful values. */
-
-enum xp_window_changes_enum {
-    XP_ORIGIN			= 1 << 0,
-    XP_SIZE			= 1 << 1,
-    XP_BOUNDS			= XP_ORIGIN | XP_SIZE,
-    XP_SHAPE			= 1 << 2,
-    XP_STACKING			= 1 << 3,
-    XP_DEPTH			= 1 << 4,
-    XP_COLORMAP			= 1 << 5,
-    XP_WINDOW_LEVEL		= 1 << 6,
-};
-
-struct xp_window_changes_struct {
-    /* XP_ORIGIN */
-    int x, y;
-
-    /* XP_SIZE */
-    unsigned int width, height;
-    int bit_gravity;			/* how to resize the backing store */
-
-    /* XP_SHAPE */
-    int shape_nrects;			/* -1 = remove shape */
-    xp_box *shape_rects;
-    int shape_tx, shape_ty;		/* translation for shape */
-
-    /* XP_STACKING */
-    int stack_mode;
-    xp_window_id sibling;		/* may be zero; in ABOVE/BELOW modes
-					   it may specify a relative window */
-    /* XP_DEPTH, window-only */
-    unsigned int depth;
-
-    /* XP_COLORMAP, window-only */
-    xp_colormap_fun *colormap;
-    void *colormap_data;
-
-    /* XP_WINDOW_LEVEL, window-only */
-    int window_level;
-};
-
-typedef struct xp_window_changes_struct xp_window_changes;
-
-/* Values for bit_gravity field */
-
-enum xp_bit_gravity_enum {
-    XP_GRAVITY_NONE		= 0,	/* no gravity, fill everything */
-    XP_GRAVITY_NORTH_WEST	= 1,	/* anchor to top-left corner */
-    XP_GRAVITY_NORTH_EAST	= 2,	/* anchor to top-right corner */
-    XP_GRAVITY_SOUTH_EAST	= 3,	/* anchor to bottom-right corner */
-    XP_GRAVITY_SOUTH_WEST	= 4,	/* anchor to bottom-left corner */
-};
-
-/* Values for stack_mode field */
-
-enum xp_window_stack_mode_enum {
-    XP_UNMAPPED			= 0,	/* remove the window */
-    XP_MAPPED_ABOVE		= 1,	/* display the window on top */
-    XP_MAPPED_BELOW		= 2,	/* display the window at bottom */
-};
-
-/* Data formats for depth field and composite functions */
-
-enum xp_depth_enum {
-    XP_DEPTH_NIL = 0,			/* null source when compositing */
-    XP_DEPTH_ARGB8888,
-    XP_DEPTH_RGB555,
-    XP_DEPTH_A8,			/* for masks when compositing */
-    XP_DEPTH_INDEX8,
-};
-
-/* Options that may be passed to the xp_init () function. */
-
-enum xp_init_options_enum {
-    /* Don't mark that this process can be in the foreground. */
-    XP_IN_BACKGROUND		= 1 << 0,
-
-    /* Deliver background pointer events to this process. */
-    XP_BACKGROUND_EVENTS	= 1 << 1,
-};
-
-
-
-/* Miscellaneous functions */
-
-/* Initialize the plugin library. Only the copy/fill/composite functions
-   may be called without having previously called xp_init () */
-
-extern xp_error xp_init (unsigned int options);
-
-/* Sets the current set of requested notifications to MASK. When any of
-   these arrive, CALLBACK will be invoked with CALLBACK-DATA. Note that
-   calling this function cancels any previously requested notifications
-   that aren't set in MASK. */
-
-extern xp_error xp_select_events (unsigned int mask,
-				  xp_event_fun *callback,
-				  void *callback_data);
-
-/* Waits for all initiated operations to complete. */
-
-extern xp_error xp_synchronize (void);
-
-/* Causes any display update initiated through the plugin libary to be
-   queued until update is reenabled. Note that calls to these functions
-   nest. */
-  
-extern xp_error xp_disable_update (void);
-extern xp_error xp_reenable_update (void);
-
-
-
-/* Cursor functions. */
-
-/* Installs the specified cursor. ARGB-DATA should point to 32-bit
-   premultiplied big-endian ARGB data. The HOT-X,HOT-Y parameters
-   specify the offset to the cursor's hot spot from its top-left
-   corner. */
-
-extern xp_error xp_set_cursor (unsigned int width, unsigned int height,
-			       unsigned int hot_x, unsigned int hot_y,
-			       const uint32_t *argb_data,
-			       unsigned int rowbytes);
-
-/* Hide and show the cursor if it's owned by the current process. Calls
-   to these functions nest. */
-
-extern xp_error xp_hide_cursor (void);
-extern xp_error xp_show_cursor (void);
-
-
-
-/* Window functions. */
-
-/* Create a new window as defined by MASK and VALUES. MASK must contain
-   XP_BOUNDS or an error is raised. The id of the newly created window
-   is stored in *RET-ID if this function returns XP_Success. */
-
-extern xp_error xp_create_window (unsigned int mask,
-				  const xp_window_changes *values,
-				  xp_window_id *ret_id);
-
-/* Destroys the window identified by ID. */
-
-extern xp_error xp_destroy_window (xp_window_id id);
-
-/* Reconfigures the given window according to MASK and VALUES. */
-
-extern xp_error xp_configure_window (xp_window_id id, unsigned int mask,
-				     const xp_window_changes *values);
-
-
-/* Returns true if NATIVE-ID is a window created by the plugin library.
-   If so and RET-ID is non-null, stores the id of the window in *RET-ID. */
-
-extern xp_bool xp_lookup_native_window (unsigned int native_id,
-					xp_window_id *ret_id);
-
-/* If ID names a window created by the plugin library, stores it's native
-   window id in *RET-NATIVE-ID. */
-
-extern xp_error xp_get_native_window (xp_window_id id,
-				      unsigned int *ret_native_id);
-
-
-/* Locks the rectangle IN-RECT (or, if null, the entire window) of the
-   given window's backing store. Any other non-null parameters are filled
-   in as follows:
-
-   DEPTH = format of returned data. Currently either XP_DEPTH_ARGB8888
-   or XP_DEPTH_RGB565 (possibly with 8 bit planar alpha). Data is
-   always stored in native byte order.
-
-   BITS[0] = pointer to top-left pixel of locked color data
-   BITS[1] = pointer to top-left of locked alpha data, or null if window
-   has no alpha. If the alpha data is meshed, then BITS[1] = BITS[0].
-
-   ROWBYTES[0,1] = size in bytes of each row of color,alpha data
-
-   OUT-RECT = rectangle specifying the current position and size of the
-   locked region relative to the window origin.
-
-   Note that an error is raised when trying to lock an already locked
-   window. While the window is locked, the only operations that may
-   be performed on it are to modify, access or flush its marked region. */
-
-extern xp_error xp_lock_window (xp_window_id id,
-				const xp_box *in_rect,
-				unsigned int *depth,
-				void *bits[2],
-				unsigned int rowbytes[2],
-				xp_box *out_rect);
-
-/* Mark that the region specified by SHAPE-NRECTS, SHAPE-RECTS,
-   SHAPE-TX, and SHAPE-TY in the specified window has been updated, and
-   will need to subsequently be redisplayed. */
-
-extern xp_error xp_mark_window (xp_window_id id, int shape_nrects,
-				const xp_box *shape_rects,
-				int shape_tx, int shape_ty);
-
-/* Unlocks the specified window. If FLUSH is true, then any marked
-   regions are immediately redisplayed. Note that it's an error to
-   unlock an already unlocked window. */
-
-extern xp_error xp_unlock_window (xp_window_id id, xp_bool flush);
-
-/* If anything is marked in the given window for redisplay, do it now. */
-
-extern xp_error xp_flush_window (xp_window_id id);
-
-/* Moves the contents of the region DX,DY pixels away from that specified
-   by DST_RECTS and DST_NRECTS in the window with SRC-ID to the
-   destination region in the window DST-ID. Note that currently source
-   and destination windows must be the same. */
-
-extern xp_error xp_copy_window (xp_window_id src_id, xp_window_id dst_id,
-				int dst_nrects, const xp_box *dst_rects,
-				int dx, int dy);
-
-/* Returns true if the given window has any regions marked for
-   redisplay. */
-
-extern xp_bool xp_is_window_marked (xp_window_id id);
-
-/* If successful returns a superset of the region marked for update in
-   the given window. Use xp_free_region () to release the returned data. */
-
-extern xp_error xp_get_marked_shape (xp_window_id id,
-				     int *ret_nrects, xp_box **ret_rects);
-
-extern void xp_free_shape (int nrects, xp_box *rects);
-
-/* Searches for the first window below ABOVE-ID containing the point X,Y,
-   and returns it's window id in *RET-ID. If no window is found, *RET-ID
-   is set to zero. If ABOVE-ID is zero, finds the topmost window
-   containing the given point. */
-
-extern xp_error xp_find_window (int x, int y, xp_window_id above_id,
-				xp_window_id *ret_id);
-
-/* Returns the current origin and size of the window ID in *BOUNDS-RET if
-   successful. */
-extern xp_error xp_get_window_bounds (xp_window_id id, xp_box *bounds_ret);
-
-
-
-/* Window surface functions. */
-
-/* Create a new VRAM surface on the specified window. If successful,
-   returns the identifier of the new surface in *RET-SID. */
-
-extern xp_error xp_create_surface (xp_window_id id, xp_surface_id *ret_sid);
-
-/* Destroys the specified surface. */
-
-extern xp_error xp_destroy_surface (xp_surface_id sid);
-
-/* Reconfigures the specified surface as defined by MASK and VALUES.
-   Note that specifying XP_DEPTH is an error. */
-
-extern xp_error xp_configure_surface (xp_surface_id sid, unsigned int mask,
-				      const xp_window_changes *values);
-
-/* If successful, places the client identifier of the current process
-   in *RET-CLIENT. */
-
-extern xp_error xp_get_client_id (xp_client_id *ret_client);
-
-/* Given a valid window,surface combination created by the current
-   process, attempts to allow the specified external client access
-   to that surface. If successful, returns two integers in RET-KEY
-   which the client can use to import the surface into their process. */
-
-extern xp_error xp_export_surface (xp_window_id wid, xp_surface_id sid,
-				   xp_client_id client,
-				   unsigned int ret_key[2]);
-
-/* Given a two integer key returned from xp_export_surface (), tries
-   to import the surface into the current process. If successful the
-   local surface identifier is stored in *SID-RET. */
-
-extern xp_error xp_import_surface (const unsigned int key[2],
-				   xp_surface_id *sid_ret);
-
-/* If successful, stores the number of surfaces attached to the
-   specified window in *RET. */
-
-extern xp_error xp_get_window_surface_count (xp_window_id id,
-					     unsigned int *ret);
-
-/* Attaches the CGLContextObj CGL-CTX to the specified surface. */
-
-extern xp_error xp_attach_gl_context (void *cgl_ctx, xp_surface_id sid);
-
-/* Updates the CGLContextObj CGL-CTX to reflect any recent changes to
-   the surface it's attached to. */
-
-extern xp_error xp_update_gl_context (void *cgl_ctx);
-
-
-
-/* Window frame functions. */
-
-/* Possible arguments to xp_frame_get_rect (). */
-
-enum xp_frame_rect_enum {
-    XP_FRAME_RECT_TITLEBAR		= 1,
-    XP_FRAME_RECT_TRACKING		= 2,
-    XP_FRAME_RECT_GROWBOX		= 3,
-};
-
-/* Classes of window frame. */
-
-enum xp_frame_class_enum {
-    XP_FRAME_CLASS_DOCUMENT		= 1 << 0,
-    XP_FRAME_CLASS_DIALOG		= 1 << 1,
-    XP_FRAME_CLASS_MODAL_DIALOG		= 1 << 2,
-    XP_FRAME_CLASS_SYSTEM_MODAL_DIALOG	= 1 << 3,
-    XP_FRAME_CLASS_UTILITY		= 1 << 4,
-    XP_FRAME_CLASS_TOOLBAR		= 1 << 5,
-    XP_FRAME_CLASS_MENU			= 1 << 6,
-    XP_FRAME_CLASS_SPLASH		= 1 << 7,
-    XP_FRAME_CLASS_BORDERLESS		= 1 << 8,
-};
-
-/* Attributes of window frames. */
-
-enum xp_frame_attr_enum {
-    XP_FRAME_ACTIVE			= 0x0001,
-    XP_FRAME_URGENT			= 0x0002,
-    XP_FRAME_TITLE			= 0x0004,
-    XP_FRAME_PRELIGHT			= 0x0008,
-    XP_FRAME_SHADED			= 0x0010,
-    XP_FRAME_CLOSE_BOX			= 0x0100,
-    XP_FRAME_COLLAPSE			= 0x0200,
-    XP_FRAME_ZOOM			= 0x0400,
-    XP_FRAME_ANY_BUTTON			= 0x0700,
-    XP_FRAME_CLOSE_BOX_CLICKED		= 0x0800,
-    XP_FRAME_COLLAPSE_BOX_CLICKED	= 0x1000,
-    XP_FRAME_ZOOM_BOX_CLICKED		= 0x2000,
-    XP_FRAME_ANY_CLICKED		= 0x3800,
-    XP_FRAME_GROW_BOX			= 0x4000,
-};
-
-#define XP_FRAME_ATTR_IS_SET(a,b)	(((a) & (b)) == (b))
-#define XP_FRAME_ATTR_IS_CLICKED(a,m)	((a) & ((m) << 3))
-#define XP_FRAME_ATTR_SET_CLICKED(a,m)	((a) |= ((m) << 3))
-#define XP_FRAME_ATTR_UNSET_CLICKED(a,m) ((a) &= ~((m) << 3))
-
-#define XP_FRAME_POINTER_ATTRS		(XP_FRAME_PRELIGHT		\
-					 | XP_FRAME_ANY_BUTTON		\
-					 | XP_FRAME_ANY_CLICKED)
-
-extern xp_error xp_frame_get_rect (int type, int class, const xp_box *outer,
-				   const xp_box *inner, xp_box *ret);
-extern xp_error xp_frame_hit_test (int class, int x, int y,
-				   const xp_box *outer,
-				   const xp_box *inner, int *ret);
-extern xp_error xp_frame_draw (xp_window_id wid, int class, unsigned int attr,
-			       const xp_box *outer, const xp_box *inner,
-			       unsigned int title_len,
-			       const unsigned char *title_bytes);
-
-
-
-/* Memory manipulation functions. */
-
-enum xp_composite_op_enum {
-    XP_COMPOSITE_SRC = 0,
-    XP_COMPOSITE_OVER,
-};
-
-#define XP_COMPOSITE_FUNCTION(op, src_depth, mask_depth, dest_depth) \
-    (((op) << 24) | ((src_depth) << 16) \
-     | ((mask_depth) << 8) | ((dest_depth) << 0))
-
-#define XP_COMPOSITE_FUNCTION_OP(f)         (((f) >> 24) & 255)
-#define XP_COMPOSITE_FUNCTION_SRC_DEPTH(f)  (((f) >> 16) & 255)
-#define XP_COMPOSITE_FUNCTION_MASK_DEPTH(f) (((f) >>  8) & 255)
-#define XP_COMPOSITE_FUNCTION_DEST_DEPTH(f) (((f) >>  0) & 255)
-
-/* Composite WIDTH by HEIGHT pixels from source and mask to destination
-   using a specified function (if source and destination overlap,
-   undefined behavior results).
-
-   For SRC and DEST, the first element of the array is the color data. If
-   the second element is non-null it implies that there is alpha data
-   (which may be meshed or planar). Data without alpha is assumed to be
-   opaque.
-
-   Passing a null SRC-ROWBYTES pointer implies that the data SRC points
-   to is a single element.
-
-   Operations that are not supported will return XP_BadImplementation. */
-
-extern xp_error xp_composite_pixels (unsigned int width, unsigned int height,
-				     unsigned int function,
-				     void *src[2], unsigned int src_rowbytes[2],
-				     void *mask, unsigned int mask_rowbytes,
-				     void *dest[2], unsigned int dest_rowbytes[2]);
-
-/* Fill HEIGHT rows of data starting at DST. Each row will have WIDTH
-   bytes filled with the 32-bit pattern VALUE. Each row is DST-ROWBYTES
-   wide in total. */
-
-extern void xp_fill_bytes (unsigned int width,
-			   unsigned int height, uint32_t value,
-			   void *dst, unsigned int dst_rowbytes);
-
-/* Copy HEIGHT rows of bytes from SRC to DST. Each row will have WIDTH
-   bytes copied. SRC and DST may overlap, and the right thing will happen. */
-
-extern void xp_copy_bytes (unsigned int width, unsigned int height,
-			   const void *src, unsigned int src_rowbytes,
-			   void *dst, unsigned int dst_rowbytes);
-
-/* Suggestions for the minimum number of bytes or pixels for which it
-   makes sense to use some of the xp_ functions */
-
-extern unsigned int xp_fill_bytes_threshold, xp_copy_bytes_threshold,
-    xp_composite_area_threshold, xp_scroll_area_threshold;
-
-
-#endif /* XPLUGIN_H */
diff --git a/hw/darwin/quartz/appledri.c b/hw/darwin/quartz/appledri.c
deleted file mode 100644
index 8178261..0000000
--- a/hw/darwin/quartz/appledri.c
+++ /dev/null
@@ -1,353 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Kevin E. Martin <martin at valinux.com>
- *   Jens Owen <jens at valinux.com>
- *   Rickard E. (Rik) Faith <faith at valinux.com>
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "dixstruct.h"
-#include "extnsionst.h"
-#include "colormapst.h"
-#include "cursorstr.h"
-#include "scrnintstr.h"
-#include "servermd.h"
-#define _APPLEDRI_SERVER_
-#include "appledristr.h"
-#include "swaprep.h"
-#include "dri.h"
-#include "dristruct.h"
-
-static int DRIErrorBase = 0;
-
-static DISPATCH_PROC(ProcAppleDRIDispatch);
-static DISPATCH_PROC(SProcAppleDRIDispatch);
-
-static void AppleDRIResetProc(ExtensionEntry* extEntry);
-
-static unsigned char DRIReqCode = 0;
-static int DRIEventBase = 0;
-
-static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
-
-typedef struct _DRIEvent *DRIEventPtr;
-typedef struct _DRIEvent {
-    DRIEventPtr     next;
-    ClientPtr       client;
-    XID             clientResource;
-    unsigned int    mask;
-} DRIEventRec;
-
-
-void
-AppleDRIExtensionInit(void)
-{
-    ExtensionEntry* extEntry;
-
-    if (DRIExtensionInit() &&
-        (extEntry = AddExtension(APPLEDRINAME,
-                                 AppleDRINumberEvents,
-                                 AppleDRINumberErrors,
-                                 ProcAppleDRIDispatch,
-                                 SProcAppleDRIDispatch,
-                                 AppleDRIResetProc,
-                                 StandardMinorOpcode))) {
-        DRIReqCode = (unsigned char)extEntry->base;
-        DRIErrorBase = extEntry->errorBase;
-        DRIEventBase = extEntry->eventBase;
-        EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
-    }
-}
-
-/*ARGSUSED*/
-static void
-AppleDRIResetProc (
-    ExtensionEntry* extEntry
-)
-{
-    DRIReset();
-}
-
-static int
-ProcAppleDRIQueryVersion(
-    register ClientPtr client
-)
-{
-    xAppleDRIQueryVersionReply rep;
-    register int n;
-
-    REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = APPLE_DRI_MAJOR_VERSION;
-    rep.minorVersion = APPLE_DRI_MINOR_VERSION;
-    rep.patchVersion = APPLE_DRI_PATCH_VERSION;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber, n);
-        swapl(&rep.length, n);
-    }
-    WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
-    return (client->noClientException);
-}
-
-
-/* surfaces */
-
-static int
-ProcAppleDRIQueryDirectRenderingCapable(
-    register ClientPtr client
-)
-{
-    xAppleDRIQueryDirectRenderingCapableReply rep;
-    Bool isCapable;
-
-    REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
-    REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen], 
-                                         &isCapable)) {
-        return BadValue;
-    }
-    rep.isCapable = isCapable;
-
-    if (!LocalClient(client))
-        rep.isCapable = 0;
-
-    WriteToClient(client, 
-        sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
-    return (client->noClientException);
-}
-
-static int
-ProcAppleDRIAuthConnection(
-    register ClientPtr client
-)
-{
-    xAppleDRIAuthConnectionReply rep;
-    
-    REQUEST(xAppleDRIAuthConnectionReq);
-    REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
-
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.authenticated = 1;
-
-    if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
-        ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic);
-        rep.authenticated = 0;
-    }
-    WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
-    return (client->noClientException);
-}
-
-static void surface_notify(
-    void *_arg,
-    void *data
-)
-{
-    DRISurfaceNotifyArg *arg = _arg;
-    int client_index = (int) data;
-    ClientPtr client;
-    xAppleDRINotifyEvent se;
-
-    if (client_index < 0 || client_index >= currentMaxClients)
-        return;
-
-    client = clients[client_index];
-    if (client == NULL || client == serverClient || client->clientGone)
-        return;
-
-    se.type = DRIEventBase + AppleDRISurfaceNotify;
-    se.kind = arg->kind;
-    se.arg = arg->id;
-    se.sequenceNumber = client->sequence;
-    se.time = currentTime.milliseconds;
-    WriteEventsToClient (client, 1, (xEvent *) &se);
-}
-
-static int
-ProcAppleDRICreateSurface(
-    ClientPtr client
-)
-{
-    xAppleDRICreateSurfaceReply rep;
-    DrawablePtr pDrawable;
-    xp_surface_id sid;
-    unsigned int key[2];
-
-    REQUEST(xAppleDRICreateSurfaceReq);
-    REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
-                                                (Drawable)stuff->drawable,
-                                                client, 
-                                                SecurityReadAccess))) {
-        return BadValue;
-    }
-
-    rep.key_0 = rep.key_1 = rep.uid = 0;
-
-    if (!DRICreateSurface( screenInfo.screens[stuff->screen],
-                           (Drawable)stuff->drawable, pDrawable,
-                           stuff->client_id, &sid, key,
-                           surface_notify, (void *) client->index)) {
-        return BadValue;
-    }
-
-    rep.key_0 = key[0];
-    rep.key_1 = key[1];
-    rep.uid = sid;
-
-    WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
-    return (client->noClientException);
-}
-
-static int
-ProcAppleDRIDestroySurface(
-    register ClientPtr client
-)
-{
-    REQUEST(xAppleDRIDestroySurfaceReq);
-    DrawablePtr pDrawable;
-    REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
-
-    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
-                                                (Drawable)stuff->drawable,
-                                                client, 
-                                                SecurityReadAccess))) {
-        return BadValue;
-    }
-
-    if (!DRIDestroySurface( screenInfo.screens[stuff->screen], 
-                            (Drawable)stuff->drawable,
-                            pDrawable, NULL, NULL)) {
-        return BadValue;
-    }
-
-    return (client->noClientException);
-}
-
-
-/* dispatch */
-
-static int
-ProcAppleDRIDispatch (
-    register ClientPtr client
-)
-{
-    REQUEST(xReq);
-
-    switch (stuff->data)
-    {
-    case X_AppleDRIQueryVersion:
-        return ProcAppleDRIQueryVersion(client);
-    case X_AppleDRIQueryDirectRenderingCapable:
-        return ProcAppleDRIQueryDirectRenderingCapable(client);
-    }
-
-    if (!LocalClient(client))
-        return DRIErrorBase + AppleDRIClientNotLocal;
-
-    switch (stuff->data)
-    {
-    case X_AppleDRIAuthConnection:
-        return ProcAppleDRIAuthConnection(client);
-    case X_AppleDRICreateSurface:
-        return ProcAppleDRICreateSurface(client);
-    case X_AppleDRIDestroySurface:
-        return ProcAppleDRIDestroySurface(client);
-    default:
-        return BadRequest;
-    }
-}
-
-static void
-SNotifyEvent(
-    xAppleDRINotifyEvent *from,
-    xAppleDRINotifyEvent *to
-)
-{
-    to->type = from->type;
-    to->kind = from->kind;
-    cpswaps (from->sequenceNumber, to->sequenceNumber);
-    cpswapl (from->time, to->time);
-    cpswapl (from->arg, to->arg);
-}
-
-static int
-SProcAppleDRIQueryVersion(
-    register ClientPtr client
-)
-{
-    register int n;
-    REQUEST(xAppleDRIQueryVersionReq);
-    swaps(&stuff->length, n);
-    return ProcAppleDRIQueryVersion(client);
-}
-
-static int
-SProcAppleDRIDispatch (
-    register ClientPtr client
-)
-{
-    REQUEST(xReq);
-
-    /* It is bound to be non-local when there is byte swapping */
-    if (!LocalClient(client))
-        return DRIErrorBase + AppleDRIClientNotLocal;
-
-    /* only local clients are allowed DRI access */
-    switch (stuff->data)
-    {
-    case X_AppleDRIQueryVersion:
-        return SProcAppleDRIQueryVersion(client);
-    default:
-        return BadRequest;
-    }
-}
diff --git a/hw/darwin/quartz/appledri.h b/hw/darwin/quartz/appledri.h
deleted file mode 100644
index c4e43be..0000000
--- a/hw/darwin/quartz/appledri.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Kevin E. Martin <martin at valinux.com>
- *   Jens Owen <jens at valinux.com>
- *   Rickard E. (Rik) Faith <faith at valinux.com>
- *
- */
-
-#ifndef _APPLEDRI_H_
-#define _APPLEDRI_H_
-
-#include <X11/Xfuncproto.h>
-
-#define X_AppleDRIQueryVersion			0
-#define X_AppleDRIQueryDirectRenderingCapable	1
-#define X_AppleDRICreateSurface			2
-#define X_AppleDRIDestroySurface		3
-#define X_AppleDRIAuthConnection                4
-/* Requests up to and including 18 were used in a previous version */
-
-/* Events */
-#define AppleDRIObsoleteEvent1		0
-#define AppleDRIObsoleteEvent2		1
-#define AppleDRIObsoleteEvent3		2
-#define AppleDRISurfaceNotify		3
-#define AppleDRINumberEvents		4
-
-/* Errors */
-#define AppleDRIClientNotLocal		0
-#define AppleDRIOperationNotSupported	1
-#define AppleDRINumberErrors		(AppleDRIOperationNotSupported + 1)
-
-/* Kinds of SurfaceNotify events: */
-#define AppleDRISurfaceNotifyChanged	0
-#define AppleDRISurfaceNotifyDestroyed	1
-
-#ifndef _APPLEDRI_SERVER_
-
-typedef struct {
-    int	type;		    /* of event */
-    unsigned long serial;   /* # of last request processed by server */
-    Bool send_event;	    /* true if this came frome a SendEvent request */
-    Display *display;	    /* Display the event was read from */
-    Window window;	    /* window of event */
-    Time time;		    /* server timestamp when event happened */
-    int kind;		    /* subtype of event */
-    int arg;
-} XAppleDRINotifyEvent;
-
-_XFUNCPROTOBEGIN
-
-Bool XAppleDRIQueryExtension (Display *dpy, int *event_base, int *error_base);
-
-Bool XAppleDRIQueryVersion (Display *dpy, int *majorVersion,
-			    int *minorVersion, int *patchVersion);
-
-Bool XAppleDRIQueryDirectRenderingCapable (Display *dpy, int screen,
-					   Bool *isCapable);
-
-void *XAppleDRISetSurfaceNotifyHandler (void (*fun) (Display *dpy,
-						     unsigned uid, int kind));
-
-Bool XAppleDRIAuthConnection (Display *dpy, int screen, unsigned int magic);
-
-Bool XAppleDRICreateSurface (Display *dpy, int screen, Drawable drawable,
-			     unsigned int client_id, unsigned int key[2],
-			     unsigned int* uid);
-
-Bool XAppleDRIDestroySurface (Display *dpy, int screen, Drawable drawable);
-
-Bool XAppleDRISynchronizeSurfaces (Display *dpy);
-
-_XFUNCPROTOEND
-
-#endif /* _APPLEDRI_SERVER_ */
-#endif /* _APPLEDRI_H_ */
-
diff --git a/hw/darwin/quartz/appledristr.h b/hw/darwin/quartz/appledristr.h
deleted file mode 100644
index 8649fd3..0000000
--- a/hw/darwin/quartz/appledristr.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Kevin E. Martin <martin at valinux.com>
- *   Jens Owen <jens at valinux.com>
- *   Rickard E. (Rik) Fiath <faith at valinux.com>
- *
- */
-
-#ifndef _APPLEDRISTR_H_
-#define _APPLEDRISTR_H_
-
-#include "appledri.h"
-
-#define APPLEDRINAME "Apple-DRI"
-
-#define APPLE_DRI_MAJOR_VERSION	1	/* current version numbers */
-#define APPLE_DRI_MINOR_VERSION	0
-#define APPLE_DRI_PATCH_VERSION	0
-
-typedef struct _AppleDRIQueryVersion {
-    CARD8	reqType;		/* always DRIReqCode */
-    CARD8	driReqType;		/* always X_DRIQueryVersion */
-    CARD16	length B16;
-} xAppleDRIQueryVersionReq;
-#define sz_xAppleDRIQueryVersionReq	4
-
-typedef struct {
-    BYTE	type;			/* X_Reply */
-    BOOL	pad1;
-    CARD16	sequenceNumber B16;
-    CARD32	length B32;
-    CARD16	majorVersion B16;	/* major version of DRI protocol */
-    CARD16	minorVersion B16;	/* minor version of DRI protocol */
-    CARD32	patchVersion B32;       /* patch version of DRI protocol */
-    CARD32	pad3 B32;
-    CARD32	pad4 B32;
-    CARD32	pad5 B32;
-    CARD32	pad6 B32;
-} xAppleDRIQueryVersionReply;
-#define sz_xAppleDRIQueryVersionReply	32
-
-typedef struct _AppleDRIQueryDirectRenderingCapable {
-    CARD8	reqType;		/* always DRIReqCode */
-    CARD8	driReqType;		/* X_DRIQueryDirectRenderingCapable */
-    CARD16	length B16;
-    CARD32	screen B32;
-} xAppleDRIQueryDirectRenderingCapableReq;
-#define sz_xAppleDRIQueryDirectRenderingCapableReq	8
-
-typedef struct {
-    BYTE	type;			/* X_Reply */
-    BOOL	pad1;
-    CARD16	sequenceNumber B16;
-    CARD32	length B32;
-    BOOL	isCapable;
-    BOOL	pad2;
-    BOOL	pad3;
-    BOOL	pad4;
-    CARD32	pad5 B32;
-    CARD32	pad6 B32;
-    CARD32	pad7 B32;
-    CARD32	pad8 B32;
-    CARD32	pad9 B32;
-} xAppleDRIQueryDirectRenderingCapableReply;
-#define sz_xAppleDRIQueryDirectRenderingCapableReply	32
-
-typedef struct _AppleDRIAuthConnection {
-    CARD8	reqType;		/* always DRIReqCode */
-    CARD8	driReqType;		/* always X_DRICloseConnection */
-    CARD16	length B16;
-    CARD32	screen B32;
-    CARD32      magic B32;
-} xAppleDRIAuthConnectionReq;
-#define sz_xAppleDRIAuthConnectionReq	12
-
-typedef struct {
-    BYTE        type;
-    BOOL        pad1;
-    CARD16      sequenceNumber B16;
-    CARD32      length B32;
-    CARD32      authenticated B32;
-    CARD32      pad2 B32;
-    CARD32      pad3 B32;
-    CARD32      pad4 B32;
-    CARD32      pad5 B32;
-    CARD32      pad6 B32;
-} xAppleDRIAuthConnectionReply;
-#define zx_xAppleDRIAuthConnectionReply  32
-
-typedef struct _AppleDRICreateSurface {
-    CARD8	reqType;		/* always DRIReqCode */
-    CARD8	driReqType;		/* always X_DRICreateSurface */
-    CARD16	length B16;
-    CARD32	screen B32;
-    CARD32	drawable B32;
-    CARD32	client_id B32;
-} xAppleDRICreateSurfaceReq;
-#define sz_xAppleDRICreateSurfaceReq	16
-
-typedef struct {
-    BYTE	type;			/* X_Reply */
-    BOOL	pad1;
-    CARD16	sequenceNumber B16;
-    CARD32	length B32;
-    CARD32	key_0 B32;
-    CARD32	key_1 B32;
-    CARD32	uid B32;
-    CARD32	pad4 B32;
-    CARD32	pad5 B32;
-    CARD32	pad6 B32;
-} xAppleDRICreateSurfaceReply;
-#define sz_xAppleDRICreateSurfaceReply	32
-
-typedef struct _AppleDRIDestroySurface {
-    CARD8	reqType;		/* always DRIReqCode */
-    CARD8	driReqType;		/* always X_DRIDestroySurface */
-    CARD16	length B16;
-    CARD32	screen B32;
-    CARD32	drawable B32;
-} xAppleDRIDestroySurfaceReq;
-#define sz_xAppleDRIDestroySurfaceReq	12
-
-typedef struct _AppleDRINotify {
-	BYTE	type;		/* always eventBase + event type */
-	BYTE	kind;
-	CARD16	sequenceNumber B16;
-	Time	time B32;	/* time of change */
-	CARD16	pad1 B16;
-	CARD32	arg B32;
-	CARD32	pad3 B32;
-} xAppleDRINotifyEvent;
-#define sz_xAppleDRINotifyEvent	20
-
-#ifdef _APPLEDRI_SERVER_
-
-void AppleDRISendEvent (
-#if NeedFunctionPrototypes
-    int			/* type */,
-    unsigned int	/* mask */,
-    int			/* which */,
-    int			/* arg */
-#endif
-);
-
-#endif /* _APPLEDRI_SERVER_ */
-#endif /* _APPLEDRISTR_H_ */
diff --git a/hw/darwin/quartz/dri.c b/hw/darwin/quartz/dri.c
deleted file mode 100644
index e5591ab..0000000
--- a/hw/darwin/quartz/dri.c
+++ /dev/null
@@ -1,760 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Jens Owen <jens at valinux.com>
- *   Rickard E. (Rik) Faith <faith at valinux.com>
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifdef XFree86LOADER
-#include "xf86.h"
-#include "xf86_ansic.h"
-#else
-#include <sys/time.h>
-#include <unistd.h>
-#endif
-
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "dixstruct.h"
-#include "extnsionst.h"
-#include "colormapst.h"
-#include "cursorstr.h"
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "servermd.h"
-#define _APPLEDRI_SERVER_
-#include "appledristr.h"
-#include "swaprep.h"
-#include "dri.h"
-#include "dristruct.h"
-#include "mi.h"
-#include "mipointer.h"
-#include "rootless.h"
-#include "x-hash.h"
-#include "x-hook.h"
-
-#include <AvailabilityMacros.h>
-
-static int DRIScreenPrivIndex = -1;
-static int DRIWindowPrivIndex = -1;
-static int DRIPixmapPrivIndex = -1;
-
-static RESTYPE DRIDrawablePrivResType;
-
-static x_hash_table *surface_hash;      /* maps surface ids -> drawablePrivs */
-
-/* FIXME: don't hardcode this? */
-#define CG_INFO_FILE "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/Info-macos.plist"
-
-/* Corresponds to SU Jaguar Green */
-#define CG_REQUIRED_MAJOR 1
-#define CG_REQUIRED_MINOR 157
-#define CG_REQUIRED_MICRO 11
-
-/* Returns version as major.minor.micro in 10.10.10 fixed form */
-static unsigned int
-get_cg_version (void)
-{
-    static unsigned int version;
-
-    FILE *fh;
-    char *ptr;
-
-    if (version != 0)
-        return version;
-
-    /* I tried CFBundleGetVersion, but it returns zero, so.. */
-
-    fh = fopen (CG_INFO_FILE, "r");
-    if (fh != NULL)
-    {
-        char buf[256];
-
-        while (fgets (buf, sizeof (buf), fh) != NULL)
-        {
-            unsigned char c;
-
-            if (!strstr (buf, "<key>CFBundleShortVersionString</key>")
-                || fgets (buf, sizeof (buf), fh) == NULL)
-            {
-                continue;
-            }
-
-            ptr = strstr (buf, "<string>");
-            if (ptr == NULL)
-                continue;
-
-            ptr += strlen ("<string>");
-
-            /* Now PTR points to "MAJOR.MINOR.MICRO". */
-
-            version = 0;
-
-        again:
-            switch ((c = *ptr++))
-            {
-            case '.':
-                version = version * 1024;
-                goto again;
-
-            case '0': case '1': case '2': case '3': case '4':
-            case '5': case '6': case '7': case '8': case '9':
-                version = ((version & ~0x3ff)
-                          + (version & 0x3ff) * 10 + (c - '0'));
-                goto again;
-            }
-            break;
-        }
-
-        fclose (fh);
-    }
-
-    return version;
-}
-
-static Bool
-test_cg_version (unsigned int major, unsigned int minor, unsigned int micro)
-{
-    unsigned int cg_ver = get_cg_version ();
-
-    unsigned int cg_major = (cg_ver >> 20) & 0x3ff;
-    unsigned int cg_minor = (cg_ver >> 10) & 0x3ff;
-    unsigned int cg_micro =  cg_ver        & 0x3ff;
-
-    if (cg_major > major)
-        return TRUE;
-    else if (cg_major < major)
-        return FALSE;
-
-    /* cg_major == major */
-
-    if (cg_minor > minor)
-        return TRUE;
-    else if (cg_minor < minor)
-        return FALSE;
-
-    /* cg_minor == minor */
-
-    if (cg_micro < micro)
-        return FALSE;
-
-    return TRUE;
-}
-
-Bool
-DRIScreenInit(ScreenPtr pScreen)
-{
-    DRIScreenPrivPtr    pDRIPriv;
-    int                 i;
-
-    pDRIPriv = (DRIScreenPrivPtr) xcalloc(1, sizeof(DRIScreenPrivRec));
-    if (!pDRIPriv) {
-        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
-        return FALSE;
-    }
-
-    pScreen->devPrivates[DRIScreenPrivIndex].ptr = (pointer) pDRIPriv;
-    pDRIPriv->directRenderingSupport = TRUE;
-    pDRIPriv->nrWindows = 0;
-
-    /* Need recent cg for window access update */
-    if (!test_cg_version (CG_REQUIRED_MAJOR,
-                          CG_REQUIRED_MINOR,
-                          CG_REQUIRED_MICRO))
-    {
-        ErrorF ("[DRI] disabled direct rendering; requires CoreGraphics %d.%d.%d\n",
-                CG_REQUIRED_MAJOR, CG_REQUIRED_MINOR, CG_REQUIRED_MICRO);
-
-        pDRIPriv->directRenderingSupport = FALSE;
-
-        /* Note we don't nuke the dri private, since we need it for
-           managing indirect surfaces. */
-    }
-
-    /* Initialize drawable tables */
-    for (i = 0; i < DRI_MAX_DRAWABLES; i++) {
-        pDRIPriv->DRIDrawables[i] = NULL;
-    }
-
-    return TRUE;
-}
-
-Bool
-DRIFinishScreenInit(ScreenPtr pScreen)
-{
-    DRIScreenPrivPtr  pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    /* Allocate zero sized private area for each window. Should a window
-     * become a DRI window, we'll hang a DRIWindowPrivateRec off of this
-     * private index.
-     */
-    if (!AllocateWindowPrivate(pScreen, DRIWindowPrivIndex, 0))
-        return FALSE;
-
-    /* Wrap DRI support */
-    pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
-    pScreen->ValidateTree = DRIValidateTree;
-
-    pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
-    pScreen->PostValidateTree = DRIPostValidateTree;
-
-    pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
-    pScreen->WindowExposures = DRIWindowExposures;
-
-    pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
-    pScreen->CopyWindow = DRICopyWindow;
-
-    pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
-    pScreen->ClipNotify = DRIClipNotify;
-
-    //    ErrorF("[DRI] screen %d installation complete\n", pScreen->myNum);
-
-    return TRUE;
-}
-
-void
-DRICloseScreen(ScreenPtr pScreen)
-{
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    if (pDRIPriv && pDRIPriv->directRenderingSupport) {
-        xfree(pDRIPriv);
-        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
-    }
-}
-
-Bool
-DRIExtensionInit(void)
-{
-    static unsigned long DRIGeneration = 0;
-
-    if (DRIGeneration != serverGeneration) {
-        if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-        DRIGeneration = serverGeneration;
-    }
-
-    /*
-     * Allocate a window private index with a zero sized private area for
-     * each window, then should a window become a DRI window, we'll hang
-     * a DRIWindowPrivateRec off of this private index. Do same for pixmaps.
-     */
-    if ((DRIWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
-        return FALSE;
-    if ((DRIPixmapPrivIndex = AllocatePixmapPrivateIndex()) < 0)
-        return FALSE;
-
-    DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete);
-
-    return TRUE;
-}
-
-void
-DRIReset(void)
-{
-    /*
-     * This stub routine is called when the X Server recycles, resources
-     * allocated by DRIExtensionInit need to be managed here.
-     *
-     * Currently this routine is a stub because all the interesting resources
-     * are managed via the screen init process.
-     */
-}
-
-Bool
-DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool* isCapable)
-{
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    if (pDRIPriv)
-        *isCapable = pDRIPriv->directRenderingSupport;
-    else
-        *isCapable = FALSE;
-
-    return TRUE;
-}
-
-Bool
-DRIAuthConnection(ScreenPtr pScreen, unsigned int magic)
-{
-#if 0
-    /* FIXME: something? */
-
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    if (drmAuthMagic(pDRIPriv->drmFD, magic)) return FALSE;
-#endif
-    return TRUE;
-}
-
-static void
-DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw)
-{
-    xp_window_changes wc;
-    unsigned int flags = 0;
-
-    if (pDRIDrawablePriv->sid == 0)
-        return;
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
-    wc.depth = (pDraw->bitsPerPixel == 32 ? XP_DEPTH_ARGB8888
-                : pDraw->bitsPerPixel == 16 ? XP_DEPTH_RGB555 : XP_DEPTH_NIL);
-    if (wc.depth != XP_DEPTH_NIL)
-        flags |= XP_DEPTH;
-#endif
-
-    if (pDraw->type == DRAWABLE_WINDOW) {
-        WindowPtr pWin = (WindowPtr) pDraw;
-        WindowPtr pTopWin = TopLevelParent(pWin);
-
-        wc.x = pWin->drawable.x - (pTopWin->drawable.x - pTopWin->borderWidth);
-        wc.y = pWin->drawable.y - (pTopWin->drawable.y - pTopWin->borderWidth);
-        wc.width = pWin->drawable.width + 2 * pWin->borderWidth;
-        wc.height = pWin->drawable.height + 2 * pWin->borderWidth;
-        wc.bit_gravity = XP_GRAVITY_NONE;
-
-        wc.shape_nrects = REGION_NUM_RECTS(&pWin->clipList);
-        wc.shape_rects = REGION_RECTS(&pWin->clipList);
-        wc.shape_tx = - (pTopWin->drawable.x - pTopWin->borderWidth);
-        wc.shape_ty = - (pTopWin->drawable.y - pTopWin->borderWidth);
-
-        flags |= XP_BOUNDS | XP_SHAPE;
-
-    } else if (pDraw->type == DRAWABLE_PIXMAP) {
-        wc.x = 0;
-        wc.y = 0;
-        wc.width = pDraw->width;
-        wc.height = pDraw->height;
-        wc.bit_gravity = XP_GRAVITY_NONE;
-        flags |= XP_BOUNDS;
-    }
-
-    xp_configure_surface(pDRIDrawablePriv->sid, flags, &wc);
-}
-
-Bool
-DRICreateSurface(ScreenPtr pScreen, Drawable id,
-                 DrawablePtr pDrawable, xp_client_id client_id,
-                 xp_surface_id *surface_id, unsigned int ret_key[2],
-                 void (*notify) (void *arg, void *data), void *notify_data)
-{
-    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    DRIDrawablePrivPtr  pDRIDrawablePriv;
-    xp_window_id        wid = 0;
-
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-        WindowPtr pWin = (WindowPtr)pDrawable;
-
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
-        if (pDRIDrawablePriv == NULL) {
-            xp_error err;
-            xp_window_changes wc;
-
-            /* allocate a DRI Window Private record */
-            if (!(pDRIDrawablePriv = xalloc(sizeof(DRIDrawablePrivRec)))) {
-                return FALSE;
-            }
-
-            pDRIDrawablePriv->pDraw = pDrawable;
-            pDRIDrawablePriv->pScreen = pScreen;
-            pDRIDrawablePriv->refCount = 0;
-            pDRIDrawablePriv->drawableIndex = -1;
-            pDRIDrawablePriv->notifiers = NULL;
-
-            /* find the physical window */
-            wid = (xp_window_id) RootlessFrameForWindow(pWin, TRUE);
-            if (wid == 0) {
-                xfree(pDRIDrawablePriv);
-                return FALSE;
-            }
-
-            /* allocate the physical surface */
-            err = xp_create_surface(wid, &pDRIDrawablePriv->sid);
-            if (err != Success) {
-                xfree(pDRIDrawablePriv);
-                return FALSE;
-            }
-
-            /* Make it visible */
-            wc.stack_mode = XP_MAPPED_ABOVE;
-            wc.sibling = 0;
-            err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc);
-            if (err != Success)
-            {
-                xp_destroy_surface(pDRIDrawablePriv->sid);
-                xfree(pDRIDrawablePriv);
-                return FALSE;
-            }
-
-            /* save private off of preallocated index */
-            pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv;
-        }
-    }
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
-    else if (pDrawable->type == DRAWABLE_PIXMAP) {
-        PixmapPtr pPix = (PixmapPtr)pDrawable;
-
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
-        if (pDRIDrawablePriv == NULL) {
-            xp_error err;
-
-            /* allocate a DRI Window Private record */
-            if (!(pDRIDrawablePriv = xcalloc(1, sizeof(DRIDrawablePrivRec)))) {
-                return FALSE;
-            }
-
-            pDRIDrawablePriv->pDraw = pDrawable;
-            pDRIDrawablePriv->pScreen = pScreen;
-            pDRIDrawablePriv->refCount = 0;
-            pDRIDrawablePriv->drawableIndex = -1;
-            pDRIDrawablePriv->notifiers = NULL;
-
-            /* Passing a null window id to Xplugin in 10.3+ asks for
-               an accelerated offscreen surface. */
-
-            err = xp_create_surface(0, &pDRIDrawablePriv->sid);
-            if (err != Success) {
-                xfree(pDRIDrawablePriv);
-                return FALSE;
-            }
-
-            /* save private off of preallocated index */
-            pPix->devPrivates[DRIPixmapPrivIndex].ptr = (pointer)pDRIDrawablePriv;
-        }
-    }
-#endif
-
-    else { /* for GLX 1.3, a PBuffer */
-        /* NOT_DONE */
-        return FALSE;
-    }
-
-    /* Finish initialization of new surfaces */
-    if (pDRIDrawablePriv->refCount == 0) {
-        unsigned int key[2] = {0};
-        xp_error err;
-
-        /* try to give the client access to the surface */
-        if (client_id != 0 && wid != 0)
-        {
-            err = xp_export_surface(wid, pDRIDrawablePriv->sid,
-                                    client_id, key);
-            if (err != Success) {
-                xp_destroy_surface(pDRIDrawablePriv->sid);
-                xfree(pDRIDrawablePriv);
-                return FALSE;
-            }
-        }
-
-        pDRIDrawablePriv->key[0] = key[0];
-        pDRIDrawablePriv->key[1] = key[1];
-
-        ++pDRIPriv->nrWindows;
-
-        /* and stash it by surface id */
-        if (surface_hash == NULL)
-            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
-        x_hash_table_insert(surface_hash,
-                            (void *) pDRIDrawablePriv->sid, pDRIDrawablePriv);
-
-        /* track this in case this window is destroyed */
-        AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable);
-
-        /* Initialize shape */
-        DRIUpdateSurface(pDRIDrawablePriv, pDrawable);
-    }
-
-    pDRIDrawablePriv->refCount++;
-
-    *surface_id = pDRIDrawablePriv->sid;
-
-    if (ret_key != NULL) {
-        ret_key[0] = pDRIDrawablePriv->key[0];
-        ret_key[1] = pDRIDrawablePriv->key[1];
-    }
-
-    if (notify != NULL) {
-        pDRIDrawablePriv->notifiers = x_hook_add(pDRIDrawablePriv->notifiers,
-                                                 notify, notify_data);
-    }
-
-    return TRUE;
-}
-
-Bool
-DRIDestroySurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable,
-                  void (*notify) (void *, void *), void *notify_data)
-{
-    DRIDrawablePrivPtr  pDRIDrawablePriv;
-
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW((WindowPtr)pDrawable);
-    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP((PixmapPtr)pDrawable);
-    } else {
-        return FALSE;
-    }
-
-    if (pDRIDrawablePriv != NULL) {
-        if (notify != NULL) {
-            pDRIDrawablePriv->notifiers = x_hook_remove(pDRIDrawablePriv->notifiers,
-                                                        notify, notify_data);
-        }
-        if (--pDRIDrawablePriv->refCount <= 0) {
-            /* This calls back to DRIDrawablePrivDelete
-               which frees the private area */
-            FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
-        }
-    }
-
-    return TRUE;
-}
-
-Bool
-DRIDrawablePrivDelete(pointer pResource, XID id)
-{
-    DrawablePtr         pDrawable = (DrawablePtr)pResource;
-    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen);
-    DRIDrawablePrivPtr  pDRIDrawablePriv = NULL;
-    WindowPtr           pWin = NULL;
-    PixmapPtr           pPix = NULL;
-
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-        pWin = (WindowPtr)pDrawable;
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
-    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
-        pPix = (PixmapPtr)pDrawable;
-        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
-    }
-
-    if (pDRIDrawablePriv == NULL)
-        return FALSE;
-
-    if (pDRIDrawablePriv->drawableIndex != -1) {
-        /* release drawable table entry */
-        pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
-    }
-
-    if (pDRIDrawablePriv->sid != 0) {
-        xp_destroy_surface(pDRIDrawablePriv->sid);
-        x_hash_table_remove(surface_hash, (void *) pDRIDrawablePriv->sid);
-    }
-
-    if (pDRIDrawablePriv->notifiers != NULL)
-        x_hook_free(pDRIDrawablePriv->notifiers);
-
-    xfree(pDRIDrawablePriv);
-
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-        pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
-    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
-        pPix->devPrivates[DRIPixmapPrivIndex].ptr = NULL;
-    }
-
-    --pDRIPriv->nrWindows;
-
-    return TRUE;
-}
-
-void
-DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
-
-    if (pDRIDrawablePriv) {
-        /* FIXME: something? */
-    }
-
-    pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
-
-    (*pScreen->WindowExposures)(pWin, prgn, bsreg);
-
-    pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
-    pScreen->WindowExposures = DRIWindowExposures;
-}
-
-void
-DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    DRIDrawablePrivPtr pDRIDrawablePriv;
-
-    if (pDRIPriv->nrWindows > 0) {
-       pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
-       if (pDRIDrawablePriv != NULL) {
-            DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
-       }
-    }
-
-    /* unwrap */
-    pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
-
-    /* call lower layers */
-    (*pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc);
-
-    /* rewrap */
-    pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
-    pScreen->CopyWindow = DRICopyWindow;
-}
-
-int
-DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen = pParent->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    int returnValue;
-
-    /* unwrap */
-    pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
-
-    /* call lower layers */
-    returnValue = (*pScreen->ValidateTree)(pParent, pChild, kind);
-
-    /* rewrap */
-    pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
-    pScreen->ValidateTree = DRIValidateTree;
-
-    return returnValue;
-}
-
-void
-DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen;
-    DRIScreenPrivPtr pDRIPriv;
-
-    if (pParent) {
-        pScreen = pParent->drawable.pScreen;
-    } else {
-        pScreen = pChild->drawable.pScreen;
-    }
-    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    if (pDRIPriv->wrap.PostValidateTree) {
-        /* unwrap */
-        pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
-
-        /* call lower layers */
-        (*pScreen->PostValidateTree)(pParent, pChild, kind);
-
-        /* rewrap */
-        pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
-        pScreen->PostValidateTree = DRIPostValidateTree;
-    }
-}
-
-void
-DRIClipNotify(WindowPtr pWin, int dx, int dy)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    DRIDrawablePrivPtr  pDRIDrawablePriv;
-
-    if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
-        DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
-    }
-
-    if (pDRIPriv->wrap.ClipNotify) {
-        pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify;
-
-        (*pScreen->ClipNotify)(pWin, dx, dy);
-
-        pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
-        pScreen->ClipNotify = DRIClipNotify;
-    }
-}
-
-/* This lets us get at the unwrapped functions so that they can correctly
- * call the lower level functions, and choose whether they will be
- * called at every level of recursion (eg in validatetree).
- */
-DRIWrappedFuncsRec *
-DRIGetWrappedFuncs(ScreenPtr pScreen)
-{
-    return &(DRI_SCREEN_PRIV(pScreen)->wrap);
-}
-
-void
-DRIQueryVersion(int *majorVersion,
-                int *minorVersion,
-                int *patchVersion)
-{
-    *majorVersion = APPLE_DRI_MAJOR_VERSION;
-    *minorVersion = APPLE_DRI_MINOR_VERSION;
-    *patchVersion = APPLE_DRI_PATCH_VERSION;
-}
-
-void
-DRISurfaceNotify(xp_surface_id id, int kind)
-{
-    DRIDrawablePrivPtr pDRIDrawablePriv = NULL;
-    DRISurfaceNotifyArg arg;
-
-    arg.id = id;
-    arg.kind = kind;
-
-    if (surface_hash != NULL)
-    {
-        pDRIDrawablePriv = x_hash_table_lookup(surface_hash,
-                                               (void *) id, NULL);
-    }
-
-    if (pDRIDrawablePriv == NULL)
-        return;
-
-    if (kind == AppleDRISurfaceNotifyDestroyed)
-    {
-        pDRIDrawablePriv->sid = 0;
-        x_hash_table_remove(surface_hash, (void *) id);
-    }
-
-    x_hook_run(pDRIDrawablePriv->notifiers, &arg);
-
-    if (kind == AppleDRISurfaceNotifyDestroyed)
-    {
-        /* Kill off the handle. */
-
-        FreeResourceByType(pDRIDrawablePriv->pDraw->id,
-                           DRIDrawablePrivResType, FALSE);
-    }
-}
diff --git a/hw/darwin/quartz/dri.h b/hw/darwin/quartz/dri.h
deleted file mode 100644
index cf2638a..0000000
--- a/hw/darwin/quartz/dri.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Jens Owen <jens at precisioninsight.com>
- *
- */
-
-/* Prototypes for AppleDRI functions */
-
-#ifndef _DRI_H_
-#define _DRI_H_
-
-#include <X11/Xdefs.h>
-#include "scrnintstr.h"
-#define _APPLEDRI_SERVER_
-#include "appledri.h"
-#include "Xplugin.h"
-
-typedef void (*ClipNotifyPtr)( WindowPtr, int, int );
-
-
-/*
- * These functions can be wrapped by the DRI.  Each of these have
- * generic default funcs (initialized in DRICreateInfoRec) and can be
- * overridden by the driver in its [driver]DRIScreenInit function.
- */
-typedef struct {
-    WindowExposuresProcPtr       WindowExposures;
-    CopyWindowProcPtr            CopyWindow;
-    ValidateTreeProcPtr          ValidateTree;
-    PostValidateTreeProcPtr      PostValidateTree;
-    ClipNotifyProcPtr            ClipNotify;
-} DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;
-
-typedef struct {
-    xp_surface_id id;
-    int kind;
-} DRISurfaceNotifyArg;
-
-extern Bool DRIScreenInit(ScreenPtr pScreen);
-
-extern Bool DRIFinishScreenInit(ScreenPtr pScreen);
-
-extern void DRICloseScreen(ScreenPtr pScreen);
-
-extern Bool DRIExtensionInit(void);
-
-extern void DRIReset(void);
-
-extern Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen,
-                                           Bool *isCapable);
-
-extern Bool DRIAuthConnection(ScreenPtr pScreen, unsigned int magic);
-
-extern Bool DRICreateSurface(ScreenPtr pScreen,
-                             Drawable id,
-                             DrawablePtr pDrawable,
-                             xp_client_id client_id,
-                             xp_surface_id *surface_id,
-                             unsigned int key[2],
-                             void (*notify) (void *arg, void *data),
-                             void *notify_data);
-
-extern Bool DRIDestroySurface(ScreenPtr pScreen,
-                             Drawable id,
-                             DrawablePtr pDrawable,
-                             void (*notify) (void *arg, void *data),
-                             void *notify_data);
-
-extern Bool DRIDrawablePrivDelete(pointer pResource,
-                                  XID id);
-
-extern DRIWrappedFuncsRec *DRIGetWrappedFuncs(ScreenPtr pScreen);
-
-extern void DRICopyWindow(WindowPtr pWin,
-                          DDXPointRec ptOldOrg,
-                          RegionPtr prgnSrc);
-
-extern int DRIValidateTree(WindowPtr pParent,
-                           WindowPtr pChild,
-                           VTKind    kind);
-
-extern void DRIPostValidateTree(WindowPtr pParent,
-                                WindowPtr pChild,
-                                VTKind    kind);
-
-extern void DRIClipNotify(WindowPtr pWin,
-                          int dx,
-                          int dy);
-
-extern void DRIWindowExposures(WindowPtr pWin,
-                              RegionPtr prgn,
-                              RegionPtr bsreg);
-
-extern void DRISurfaceNotify (xp_surface_id id, int kind);
-
-extern void DRIQueryVersion(int *majorVersion,
-                            int *minorVersion,
-                            int *patchVersion);
-
-#endif
diff --git a/hw/darwin/quartz/dristruct.h b/hw/darwin/quartz/dristruct.h
deleted file mode 100644
index 9a3d01c..0000000
--- a/hw/darwin/quartz/dristruct.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright (c) 2002 Apple Computer, Inc.
-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, sub license, 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 (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Jens Owen <jens at precisioninsight.com>
- *
- */
-
-#ifndef DRI_STRUCT_H
-#define DRI_STRUCT_H
-
-#include "dri.h"
-#include "x-list.h"
-
-#define DRI_MAX_DRAWABLES 256
-
-#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
-    ((DRIWindowPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))
-
-#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
-    ((DRIPixmapPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIPixmapPrivIndex].ptr)))
-
-typedef struct _DRIDrawablePrivRec
-{
-    xp_surface_id   sid;
-    int             drawableIndex;
-    DrawablePtr     pDraw;
-    ScreenPtr       pScreen;
-    int             refCount;
-    unsigned int    key[2];
-    x_list          *notifiers;     /* list of (FUN . DATA) */
-} DRIDrawablePrivRec, *DRIDrawablePrivPtr;
-
-#define DRI_SCREEN_PRIV(pScreen) \
-    ((DRIScreenPrivIndex < 0) ? \
-     NULL : \
-     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))
-
-#define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
-    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))
-
-
-typedef struct _DRIScreenPrivRec
-{
-    Bool                directRenderingSupport;
-    int                 nrWindows;
-    DRIWrappedFuncsRec  wrap;
-    DrawablePtr         DRIDrawables[DRI_MAX_DRAWABLES];
-} DRIScreenPrivRec, *DRIScreenPrivPtr;
-
-#endif /* DRI_STRUCT_H */
diff --git a/hw/darwin/quartz/x-hash.c b/hw/darwin/quartz/x-hash.c
deleted file mode 100644
index 55d28ba..0000000
--- a/hw/darwin/quartz/x-hash.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/* x-hash.c - basic hash tables
-
-   Copyright (c) 2002 Apple Computer, Inc. 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 "x-hash.h"
-#include "x-list.h"
-#include <stdlib.h>
-#include <assert.h>
-
-struct x_hash_table_struct {
-    unsigned int bucket_index;
-    unsigned int total_keys;
-    x_list **buckets;
-
-    x_hash_fun *hash_key;
-    x_compare_fun *compare_keys;
-    x_destroy_fun *destroy_key;
-    x_destroy_fun *destroy_value;
-};
-
-#define ITEM_NEW(k, v) X_PFX (list_prepend) ((x_list *) (k), v)
-#define ITEM_FREE(i) X_PFX (list_free_1) (i)
-#define ITEM_KEY(i) ((void *) (i)->next)
-#define ITEM_VALUE(i) ((i)->data)
-
-#define SPLIT_THRESHOLD_FACTOR 2
-
-/* http://planetmath.org/?op=getobj&from=objects&name=GoodHashTablePrimes */
-static const unsigned int bucket_sizes[] = {
-    29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157,
-    98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917,
-    25165843, 50331653, 100663319, 201326611, 402653189, 805306457,
-    1610612741
-};
-
-#define N_BUCKET_SIZES (sizeof (bucket_sizes) / sizeof (bucket_sizes[0]))
-
-static inline unsigned int
-hash_table_total_buckets (x_hash_table *h)
-{
-    return bucket_sizes[h->bucket_index];
-}
-
-static inline void
-hash_table_destroy_item (x_hash_table *h, void *k, void *v)
-{
-    if (h->destroy_key != 0)
-        (*h->destroy_key) (k);
-
-    if (h->destroy_value != 0)
-        (*h->destroy_value) (v);
-}
-
-static inline unsigned int
-hash_table_hash_key (x_hash_table *h, void *k)
-{
-    if (h->hash_key != 0)
-        return (*h->hash_key) (k);
-    else
-        return (unsigned int) k;
-}
-
-static inline int
-hash_table_compare_keys (x_hash_table *h, void *k1, void *k2)
-{
-    if (h->compare_keys == 0)
-        return k1 == k2;
-    else
-        return (*h->compare_keys) (k1, k2) == 0;
-}
-
-static void
-hash_table_split (x_hash_table *h)
-{
-    x_list **new, **old;
-    x_list *node, *item, *next;
-    int new_size, old_size;
-    unsigned int b;
-    int i;
-
-    if (h->bucket_index == N_BUCKET_SIZES - 1)
-        return;
-
-    old_size = hash_table_total_buckets (h);
-    old = h->buckets;
-
-    h->bucket_index++;
-
-    new_size = hash_table_total_buckets (h);
-    new = calloc (new_size, sizeof (x_list *));
-
-    if (new == 0)
-    {
-        h->bucket_index--;
-        return;
-    }
-
-    for (i = 0; i < old_size; i++)
-    {
-        for (node = old[i]; node != 0; node = next)
-        {
-            next = node->next;
-            item = node->data;
-
-            b = hash_table_hash_key (h, ITEM_KEY (item)) % new_size;
-
-            node->next = new[b];
-            new[b] = node;
-        }
-    }
-
-    h->buckets = new;
-    free (old);
-}
-
-X_EXTERN x_hash_table *
-X_PFX (hash_table_new) (x_hash_fun *hash,
-                        x_compare_fun *compare,
-                        x_destroy_fun *key_destroy,
-                        x_destroy_fun *value_destroy)
-{
-    x_hash_table *h;
-
-    h = calloc (1, sizeof (x_hash_table));
-    if (h == 0)
-        return 0;
-
-    h->bucket_index = 0;
-    h->buckets = calloc (hash_table_total_buckets (h), sizeof (x_list *));
-
-    if (h->buckets == 0)
-    {
-        free (h);
-        return 0;
-    }
-    
-    h->hash_key = hash;
-    h->compare_keys = compare;
-    h->destroy_key = key_destroy;
-    h->destroy_value = value_destroy;
-
-    return h;
-}
-
-X_EXTERN void
-X_PFX (hash_table_free) (x_hash_table *h)
-{
-    int n, i;
-    x_list *node, *item;
-
-    assert (h != NULL);
-
-    n = hash_table_total_buckets (h);
-
-    for (i = 0; i < n; i++)
-    {
-        for (node = h->buckets[i]; node != 0; node = node->next)
-        {
-            item = node->data;
-            hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item));
-            ITEM_FREE (item);
-        }
-        X_PFX (list_free) (h->buckets[i]);
-    }
-
-    free (h->buckets);
-    free (h);
-}
-
-X_EXTERN unsigned int
-X_PFX (hash_table_size) (x_hash_table *h)
-{
-    assert (h != NULL);
-
-    return h->total_keys;
-}
-
-static void
-hash_table_modify (x_hash_table *h, void *k, void *v, int replace)
-{
-    unsigned int hash_value;
-    x_list *node, *item;
-
-    assert (h != NULL);
-
-    hash_value = hash_table_hash_key (h, k);
-
-    for (node = h->buckets[hash_value % hash_table_total_buckets (h)];
-         node != 0; node = node->next)
-    {
-        item = node->data;
-
-        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
-        {
-            if (replace)
-            {
-                hash_table_destroy_item (h, ITEM_KEY (item),
-                                         ITEM_VALUE (item));
-                item->next = k;
-                ITEM_VALUE (item) = v;
-            }
-            else
-            {
-                hash_table_destroy_item (h, k, ITEM_VALUE (item));
-                ITEM_VALUE (item) = v;
-            }
-            return;
-        }
-    }
-
-    /* Key isn't already in the table. Insert it. */
-
-    if (h->total_keys + 1
-        > hash_table_total_buckets (h) * SPLIT_THRESHOLD_FACTOR)
-    {
-        hash_table_split (h);
-    }
-
-    hash_value = hash_value % hash_table_total_buckets (h);
-    h->buckets[hash_value] = X_PFX (list_prepend) (h->buckets[hash_value],
-                                                   ITEM_NEW (k, v));
-    h->total_keys++;
-}
-
-X_EXTERN void
-X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v)
-{
-    hash_table_modify (h, k, v, 0);
-}
-
-X_EXTERN void
-X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v)
-{
-    hash_table_modify (h, k, v, 1);
-}
-
-X_EXTERN void
-X_PFX (hash_table_remove) (x_hash_table *h, void *k)
-{
-    unsigned int hash_value;
-    x_list **ptr, *item;
-
-    assert (h != NULL);
-
-    hash_value = hash_table_hash_key (h, k);
-
-    for (ptr = &h->buckets[hash_value % hash_table_total_buckets (h)];
-         *ptr != 0; ptr = &((*ptr)->next))
-    {
-        item = (*ptr)->data;
-
-        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
-        {
-            hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item));
-            ITEM_FREE (item);
-            item = *ptr;
-            *ptr = item->next;
-            X_PFX (list_free_1) (item);
-            h->total_keys--;
-            return;
-        }
-    }
-}
-
-X_EXTERN void *
-X_PFX (hash_table_lookup) (x_hash_table *h, void *k, void **k_ret)
-{
-    unsigned int hash_value;
-    x_list *node, *item;
-
-    assert (h != NULL);
-
-    hash_value = hash_table_hash_key (h, k);
-
-    for (node = h->buckets[hash_value % hash_table_total_buckets (h)];
-         node != 0; node = node->next)
-    {
-        item = node->data;
-
-        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
-        {
-            if (k_ret != 0)
-            *k_ret = ITEM_KEY (item);
-
-            return ITEM_VALUE (item);
-        }
-    }
-
-    if (k_ret != 0)
-        *k_ret = 0;
-
-    return 0;
-}
-
-X_EXTERN void
-X_PFX (hash_table_foreach) (x_hash_table *h,
-                            x_hash_foreach_fun *fun, void *data)
-{
-    int i, n;
-    x_list *node, *item;
-
-    assert (h != NULL);
-
-    n = hash_table_total_buckets (h);
-
-    for (i = 0; i < n; i++)
-    {
-        for (node = h->buckets[i]; node != 0; node = node->next)
-        {
-            item = node->data;
-            (*fun) (ITEM_KEY (item), ITEM_VALUE (item), data);
-        }
-    }
-}
diff --git a/hw/darwin/quartz/x-hash.h b/hw/darwin/quartz/x-hash.h
deleted file mode 100644
index 3456dbe..0000000
--- a/hw/darwin/quartz/x-hash.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* x-hash.h -- basic hash table class
-
-   Copyright (c) 2002 Apple Computer, Inc. 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 X_HASH_H
-#define X_HASH_H 1
-
-typedef struct x_hash_table_struct x_hash_table;
-
-typedef int (x_compare_fun) (const void *a, const void *b);
-typedef unsigned int (x_hash_fun) (const void *k);
-typedef void (x_destroy_fun) (void *x);
-typedef void (x_hash_foreach_fun) (void *k, void *v, void *data);
-
-/* for X_PFX and X_EXTERN */
-#include "x-list.h"
-
-X_EXTERN x_hash_table *X_PFX (hash_table_new) (x_hash_fun *hash,
-					       x_compare_fun *compare,
-					       x_destroy_fun *key_destroy,
-					       x_destroy_fun *value_destroy);
-X_EXTERN void X_PFX (hash_table_free) (x_hash_table *h);
-
-X_EXTERN unsigned int X_PFX (hash_table_size) (x_hash_table *h);
-
-X_EXTERN void X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v);
-X_EXTERN void X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v);
-X_EXTERN void X_PFX (hash_table_remove) (x_hash_table *h, void *k);
-X_EXTERN void *X_PFX (hash_table_lookup) (x_hash_table *h,
-					  void *k, void **k_ret);
-X_EXTERN void X_PFX (hash_table_foreach) (x_hash_table *h,
-					  x_hash_foreach_fun *fun,
-					  void *data);
-
-#endif /* X_HASH_H */
diff --git a/hw/darwin/quartz/x-hook.c b/hw/darwin/quartz/x-hook.c
deleted file mode 100644
index bb873bb..0000000
--- a/hw/darwin/quartz/x-hook.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* x-hook.c
-
-   Copyright (c) 2003 Apple Computer, Inc. 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 "x-hook.h"
-#include <stdlib.h>
-#include <assert.h>
-
-#define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d))
-#define CELL_FREE(c)  X_PFX (list_free_1) (c)
-#define CELL_FUN(c)   ((x_hook_function *) ((c)->next))
-#define CELL_DATA(c)  ((c)->data)
-
-X_EXTERN x_list *
-X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data)
-{
-    return X_PFX (list_prepend) (lst, CELL_NEW (fun, data));
-}
-
-X_EXTERN x_list *
-X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data)
-{
-    x_list *node, *cell;
-    x_list *to_delete = NULL;
-
-    for (node = lst; node != NULL; node = node->next)
-    {
-	cell = node->data;
-	if (CELL_FUN (cell) == fun && CELL_DATA (cell) == data)
-	    to_delete = X_PFX (list_prepend) (to_delete, cell);
-    }
-
-    for (node = to_delete; node != NULL; node = node->next)
-    {
-	cell = node->data;
-	lst = X_PFX (list_remove) (lst, cell);
-	CELL_FREE (cell);
-    }
-
-    X_PFX (list_free) (to_delete);
-    return lst;
-}
-
-X_EXTERN void
-X_PFX (hook_run) (x_list *lst, void *arg)
-{
-    x_list *node, *cell;
-    x_hook_function **fun;
-    void **data;
-    int length, i;
-
-    length = X_PFX (list_length) (lst);
-    fun = alloca (sizeof (x_hook_function *) * length);
-    data = alloca (sizeof (void *) * length);
-
-    for (i = 0, node = lst; node != NULL; node = node->next, i++)
-    {
-	cell = node->data;
-	fun[i] = CELL_FUN (cell);
-	data[i] = CELL_DATA (cell);
-    }
-
-    for (i = 0; i < length; i++)
-    {
-	(*fun[i]) (arg, data[i]);
-    }
-}
-
-X_EXTERN void
-X_PFX (hook_free) (x_list *lst)
-{
-    x_list *node;
-
-    for (node = lst; node != NULL; node = node->next)
-    {
-	CELL_FREE (node->data);
-    }
-
-    X_PFX (list_free) (lst);
-}
diff --git a/hw/darwin/quartz/x-hook.h b/hw/darwin/quartz/x-hook.h
deleted file mode 100644
index 392352d..0000000
--- a/hw/darwin/quartz/x-hook.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* x-hook.h -- lists of function,data pairs to call.
-
-   Copyright (c) 2003 Apple Computer, Inc. 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 X_HOOK_H
-#define X_HOOK_H 1
-
-#include "x-list.h"
-
-typedef void x_hook_function (void *arg, void *data);
-
-X_EXTERN x_list *X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data);
-X_EXTERN x_list *X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data);
-X_EXTERN void X_PFX (hook_run) (x_list *lst, void *arg);
-X_EXTERN void X_PFX (hook_free) (x_list *lst);
-
-#endif /* X_HOOK_H */
diff --git a/hw/darwin/quartz/x-list.c b/hw/darwin/quartz/x-list.c
deleted file mode 100644
index 3596dd3..0000000
--- a/hw/darwin/quartz/x-list.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/* x-list.c
-
-   Copyright (c) 2002 Apple Computer, Inc. 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 "x-list.h"
-#include <stdlib.h>
-#include <assert.h>
-#include <pthread.h>
-
-/* Allocate in ~4k blocks */
-#define NODES_PER_BLOCK 508
-
-typedef struct x_list_block_struct x_list_block;
-
-struct x_list_block_struct {
-    x_list l[NODES_PER_BLOCK];
-};
-
-static x_list *freelist;
-
-static pthread_mutex_t freelist_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static inline void
-list_free_1 (x_list *node)
-{
-    node->next = freelist;
-    freelist = node;
-}
-
-X_EXTERN void
-X_PFX (list_free_1) (x_list *node)
-{
-    assert (node != NULL);
-
-    pthread_mutex_lock (&freelist_lock);
-
-    list_free_1 (node);
-
-    pthread_mutex_unlock (&freelist_lock);
-}
-
-X_EXTERN void
-X_PFX (list_free) (x_list *lst)
-{
-    x_list *next;
-
-    pthread_mutex_lock (&freelist_lock);
-
-    for (; lst != NULL; lst = next)
-    {
-        next = lst->next;
-        list_free_1 (lst);
-    }
-
-    pthread_mutex_unlock (&freelist_lock);
-}
-
-X_EXTERN x_list *
-X_PFX (list_prepend) (x_list *lst, void *data)
-{
-    x_list *node;
-
-    pthread_mutex_lock (&freelist_lock);
-
-    if (freelist == NULL)
-    {
-        x_list_block *b;
-        int i;
-
-        b = malloc (sizeof (x_list_block));
-
-        for (i = 0; i < NODES_PER_BLOCK - 1; i++)
-            b->l[i].next = &(b->l[i+1]);
-        b->l[i].next = NULL;
-
-        freelist = b->l;
-    }
-
-    node = freelist;
-    freelist = node->next;
-
-    pthread_mutex_unlock (&freelist_lock);
-
-    node->next = lst;
-    node->data = data;
-
-    return node;
-}
-
-X_EXTERN x_list *
-X_PFX (list_append) (x_list *lst, void *data)
-{
-    x_list *head = lst;
-
-    if (lst == NULL)
-        return X_PFX (list_prepend) (NULL, data);
-
-    while (lst->next != NULL)
-        lst = lst->next;
-
-    lst->next = X_PFX (list_prepend) (NULL, data);
-
-    return head;
-}
-
-X_EXTERN x_list *
-X_PFX (list_reverse) (x_list *lst)
-{
-    x_list *head = NULL, *next;
-    
-    while (lst != NULL)
-    {
-        next = lst->next;
-        lst->next = head;
-        head = lst;
-        lst = next;
-    }
-
-    return head;
-}
-
-X_EXTERN x_list *
-X_PFX (list_find) (x_list *lst, void *data)
-{
-    for (; lst != NULL; lst = lst->next)
-    {
-        if (lst->data == data)
-            return lst;
-    }
-
-    return NULL;
-}
-
-X_EXTERN x_list *
-X_PFX (list_nth) (x_list *lst, int n)
-{
-    while (n-- > 0 && lst != NULL)
-        lst = lst->next;
-
-    return lst;
-}
-
-X_EXTERN x_list *
-X_PFX (list_pop) (x_list *lst, void **data_ret)
-{
-    void *data = NULL;
-
-    if (lst != NULL)
-    {
-        x_list *tem = lst;
-        data = lst->data;
-        lst = lst->next;
-        X_PFX (list_free_1) (tem);
-    }
-
-    if (data_ret != NULL)
-        *data_ret = data;
-
-    return lst;
-}
-
-X_EXTERN x_list *
-X_PFX (list_filter) (x_list *lst,
-                     int (*pred) (void *item, void *data), void *data)
-{
-    x_list *ret = NULL, *node;
-
-    for (node = lst; node != NULL; node = node->next)
-    {
-        if ((*pred) (node->data, data))
-            ret = X_PFX (list_prepend) (ret, node->data);
-    }
-
-    return X_PFX (list_reverse) (ret);
-}
-
-X_EXTERN x_list *
-X_PFX (list_map) (x_list *lst,
-                  void *(*fun) (void *item, void *data), void *data)
-{
-    x_list *ret = NULL, *node;
-
-    for (node = lst; node != NULL; node = node->next)
-    {
-        X_PFX (list_prepend) (ret, fun (node->data, data));
-    }
-
-    return X_PFX (list_reverse) (ret);
-}
-
-X_EXTERN x_list *
-X_PFX (list_copy) (x_list *lst)
-{
-    x_list *copy = NULL;
-
-    for (; lst != NULL; lst = lst->next)
-    {
-        copy = X_PFX (list_prepend) (copy, lst->data);
-    }
-
-    return X_PFX (list_reverse) (copy);
-}
-
-X_EXTERN x_list *
-X_PFX (list_remove) (x_list *lst, void *data)
-{
-    x_list **ptr, *node;
-
-    for (ptr = &lst; *ptr != NULL;)
-    {
-        node = *ptr;
-
-        if (node->data == data)
-        {
-            *ptr = node->next;
-            X_PFX (list_free_1) (node);
-        }
-        else
-            ptr = &((*ptr)->next);
-    }
-
-    return lst;
-}
-
-X_EXTERN unsigned int
-X_PFX (list_length) (x_list *lst)
-{
-    unsigned int n;
-
-    n = 0;
-    for (; lst != NULL; lst = lst->next)
-        n++;
-
-    return n;
-}
-
-X_EXTERN void
-X_PFX (list_foreach) (x_list *lst,
-                      void (*fun) (void *data, void *user_data),
-                      void *user_data)
-{
-    for (; lst != NULL; lst = lst->next)
-    {
-        (*fun) (lst->data, user_data);
-    }
-}
-
-static x_list *
-list_sort_1 (x_list *lst, int length,
-             int (*less) (const void *, const void *))
-{
-    x_list *mid, *ptr;
-    x_list *out_head, *out;
-    int mid_point, i;
-
-    /* This is a standard (stable) list merge sort */
-
-    if (length < 2)
-        return lst;
-
-    /* Calculate the halfway point. Split the list into two sub-lists. */
-
-    mid_point = length / 2;
-    ptr = lst;
-    for (i = mid_point - 1; i > 0; i--)
-        ptr = ptr->next;
-    mid = ptr->next;
-    ptr->next = NULL;
-
-    /* Sort each sub-list. */
-
-    lst = list_sort_1 (lst, mid_point, less);
-    mid = list_sort_1 (mid, length - mid_point, less);
-
-    /* Then merge them back together. */
-
-    assert (lst != NULL && mid != NULL);
-
-    if ((*less) (mid->data, lst->data))
-        out = out_head = mid, mid = mid->next;
-    else
-        out = out_head = lst, lst = lst->next;
-
-    while (lst != NULL && mid != NULL)
-    {
-        if ((*less) (mid->data, lst->data))
-            out = out->next = mid, mid = mid->next;
-        else
-            out = out->next = lst, lst = lst->next;
-    }
-
-    if (lst != NULL)
-        out->next = lst;
-    else
-        out->next = mid;
-
-    return out_head;
-}
-
-X_EXTERN x_list *
-X_PFX (list_sort) (x_list *lst, int (*less) (const void *, const void *))
-{
-    int length;
-
-    length = X_PFX (list_length) (lst);
-
-    return list_sort_1 (lst, length, less);
-}
diff --git a/hw/darwin/quartz/x-list.h b/hw/darwin/quartz/x-list.h
deleted file mode 100644
index 04af024..0000000
--- a/hw/darwin/quartz/x-list.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* x-list.h -- simple list type
-
-   Copyright (c) 2002 Apple Computer, Inc. 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 X_LIST_H
-#define X_LIST_H 1
-
-/* This is just a cons. */
-
-typedef struct x_list_struct x_list;
-
-struct x_list_struct {
-    void *data;
-    x_list *next;
-};
-
-#ifndef X_PFX
-# define X_PFX(x) x_ ## x
-#endif
-
-#ifndef X_EXTERN
-# define X_EXTERN __private_extern__
-#endif
-
-X_EXTERN void X_PFX (list_free_1) (x_list *node);
-X_EXTERN x_list *X_PFX (list_prepend) (x_list *lst, void *data);
-
-X_EXTERN x_list *X_PFX (list_append) (x_list *lst, void *data);
-X_EXTERN x_list *X_PFX (list_remove) (x_list *lst, void *data);
-X_EXTERN void X_PFX (list_free) (x_list *lst);
-X_EXTERN x_list *X_PFX (list_pop) (x_list *lst, void **data_ret);
-
-X_EXTERN x_list *X_PFX (list_copy) (x_list *lst);
-X_EXTERN x_list *X_PFX (list_reverse) (x_list *lst);
-X_EXTERN x_list *X_PFX (list_find) (x_list *lst, void *data);
-X_EXTERN x_list *X_PFX (list_nth) (x_list *lst, int n);
-X_EXTERN x_list *X_PFX (list_filter) (x_list *src,
-                                      int (*pred) (void *item, void *data),
-                                      void *data);
-X_EXTERN x_list *X_PFX (list_map) (x_list *src,
-                                   void *(*fun) (void *item, void *data),
-                                   void *data);
-
-X_EXTERN unsigned int X_PFX (list_length) (x_list *lst);
-X_EXTERN void X_PFX (list_foreach) (x_list *lst, void (*fun)
-                                    (void *data, void *user_data),
-                                    void *user_data);
-
-X_EXTERN x_list *X_PFX (list_sort) (x_list *lst, int (*less) (const void *,
-                                    const void *));
-
-#endif /* X_LIST_H */
diff --git a/hw/darwin/quartz/xpr.h b/hw/darwin/quartz/xpr.h
deleted file mode 100644
index ddc6d0c..0000000
--- a/hw/darwin/quartz/xpr.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Xplugin rootless implementation
- *
- * Copyright (c) 2003 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 XPR_H
-#define XPR_H
-
-#include "screenint.h"
-
-extern Bool QuartzModeBundleInit(void);
-
-void AppleDRIExtensionInit(void);
-void xprAppleWMInit(void);
-Bool xprInit(ScreenPtr pScreen);
-Bool xprIsX11Window(void *nsWindow, int windowNumber);
-
-void xprHideWindows(Bool hide);
-
-Bool QuartzInitCursor(ScreenPtr pScreen);
-void QuartzSuspendXCursor(ScreenPtr pScreen);
-void QuartzResumeXCursor(ScreenPtr pScreen, int x, int y);
-
-#endif /* XPR_H */
diff --git a/hw/darwin/quartz/xpr/Xplugin.h b/hw/darwin/quartz/xpr/Xplugin.h
new file mode 100644
index 0000000..a10b1b8
--- /dev/null
+++ b/hw/darwin/quartz/xpr/Xplugin.h
@@ -0,0 +1,589 @@
+/* Xplugin.h -- windowing API for rootless X11 server
+
+   Copyright (c) 2002 Apple Computer, Inc. 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.
+
+   Note that these interfaces are provided solely for the use of the
+   X11 server. Any other uses are unsupported and strongly discouraged. */
+
+#ifndef XPLUGIN_H
+#define XPLUGIN_H 1
+
+#include <stdint.h>
+
+/* By default we use the X server definition of BoxRec to define xp_box,
+   so that the compiler can silently convert between the two. But if
+   XP_NO_X_HEADERS is defined, we'll define it ourselves. */
+
+#ifndef XP_NO_X_HEADERS
+# include "miscstruct.h"
+  typedef BoxRec xp_box;
+#else
+  struct xp_box_struct {
+      short x1, y1, x2, y2;
+  };
+  typedef struct xp_box_struct xp_box;
+#endif
+
+typedef unsigned int xp_resource_id;
+typedef xp_resource_id xp_window_id;
+typedef xp_resource_id xp_surface_id;
+typedef unsigned int xp_client_id;
+typedef unsigned int xp_request_type;
+typedef int xp_error;
+typedef int xp_bool;
+
+
+/* Error codes that the functions declared here may return. They all
+   numerically match their X equivalents, i.e. the XP_ can be dropped
+   if <X11/X.h> has been included. */
+
+enum xp_error_enum {
+    XP_Success			= 0,
+    XP_BadRequest		= 1,
+    XP_BadValue			= 2,
+    XP_BadWindow		= 3,
+    XP_BadMatch			= 8,
+    XP_BadAccess		= 10,
+    XP_BadImplementation	= 17,
+};    
+
+
+/* Event types generated by the plugin. */
+
+enum xp_event_type_enum {
+    /* The global display configuration changed somehow. */
+    XP_EVENT_DISPLAY_CHANGED	= 1 << 0,
+
+    /* A window changed state. Argument is xp_window_state_event */
+    XP_EVENT_WINDOW_STATE_CHANGED = 1 << 1,
+
+    /* An async request encountered an error. Argument is of type
+       xp_async_error_event */
+    XP_EVENT_ASYNC_ERROR	= 1 << 2,
+
+    /* Sent when a surface is destroyed as a side effect of destroying
+       a window. Arg is of type xp_surface_id. */
+    XP_EVENT_SURFACE_DESTROYED	= 1 << 3,
+
+    /* Sent when any GL contexts pointing at the given surface need to
+       call xp_update_gl_context () to refresh their state (because the
+       window moved or was resized. Arg is of type xp_surface_id. */
+    XP_EVENT_SURFACE_CHANGED	= 1 << 4,
+
+    /* Sent when a window has been moved. Arg is of type xp_window_id. */
+    XP_EVENT_WINDOW_MOVED	= 1 << 5,
+};
+
+/* Function type used to receive events. */
+
+typedef void (xp_event_fun) (unsigned int type, const void *arg,
+			     unsigned int arg_size, void *user_data);
+
+
+/* Operation types. Used when reporting errors asynchronously. */
+
+enum xp_request_type_enum {
+    XP_REQUEST_NIL = 0,
+    XP_REQUEST_DESTROY_WINDOW = 1,
+    XP_REQUEST_CONFIGURE_WINDOW = 2,
+    XP_REQUEST_FLUSH_WINDOW = 3,
+    XP_REQUEST_COPY_WINDOW = 4,
+    XP_REQUEST_UNLOCK_WINDOW = 5,
+    XP_REQUEST_DISABLE_UPDATE = 6,
+    XP_REQUEST_REENABLE_UPDATE = 7,
+    XP_REQUEST_HIDE_CURSOR = 8,
+    XP_REQUEST_SHOW_CURSOR = 9,
+    XP_REQUEST_FRAME_DRAW = 10,
+};
+
+/* Structure used to report an error asynchronously. Passed as the "arg"
+   of an XP_EVENT_ASYNC_ERROR event. */
+
+struct xp_async_error_event_struct {
+    xp_request_type request_type;
+    xp_resource_id id;
+    xp_error error;
+};
+
+typedef struct xp_async_error_event_struct xp_async_error_event;
+
+
+/* Possible window states. */
+
+enum xp_window_state_enum {
+    /* The window is not in the global list of possibly-visible windows. */
+    XP_WINDOW_STATE_OFFSCREEN	= 1 << 0,
+
+    /* Parts of the window may be obscured by other windows. */
+    XP_WINDOW_STATE_OBSCURED	= 1 << 1,
+};
+
+/* Structure passed as argument of an XP_EVENT_WINDOW_STATE_CHANGED event. */
+
+struct xp_window_state_event_struct {
+    xp_window_id id;
+    unsigned int state;
+};
+
+typedef struct xp_window_state_event_struct xp_window_state_event;
+
+
+/* Function type used to supply a colormap for indexed drawables. */
+
+typedef xp_error (xp_colormap_fun) (void *data, int first_color,
+				    int n_colors, uint32_t *colors);
+
+
+/* Window attributes structure. Used when creating and configuring windows.
+   Also used when configuring surfaces attached to windows. Functions that
+   take one of these structures also take a bit mask defining which
+   fields are set to meaningful values. */
+
+enum xp_window_changes_enum {
+    XP_ORIGIN			= 1 << 0,
+    XP_SIZE			= 1 << 1,
+    XP_BOUNDS			= XP_ORIGIN | XP_SIZE,
+    XP_SHAPE			= 1 << 2,
+    XP_STACKING			= 1 << 3,
+    XP_DEPTH			= 1 << 4,
+    XP_COLORMAP			= 1 << 5,
+    XP_WINDOW_LEVEL		= 1 << 6,
+};
+
+struct xp_window_changes_struct {
+    /* XP_ORIGIN */
+    int x, y;
+
+    /* XP_SIZE */
+    unsigned int width, height;
+    int bit_gravity;			/* how to resize the backing store */
+
+    /* XP_SHAPE */
+    int shape_nrects;			/* -1 = remove shape */
+    xp_box *shape_rects;
+    int shape_tx, shape_ty;		/* translation for shape */
+
+    /* XP_STACKING */
+    int stack_mode;
+    xp_window_id sibling;		/* may be zero; in ABOVE/BELOW modes
+					   it may specify a relative window */
+    /* XP_DEPTH, window-only */
+    unsigned int depth;
+
+    /* XP_COLORMAP, window-only */
+    xp_colormap_fun *colormap;
+    void *colormap_data;
+
+    /* XP_WINDOW_LEVEL, window-only */
+    int window_level;
+};
+
+typedef struct xp_window_changes_struct xp_window_changes;
+
+/* Values for bit_gravity field */
+
+enum xp_bit_gravity_enum {
+    XP_GRAVITY_NONE		= 0,	/* no gravity, fill everything */
+    XP_GRAVITY_NORTH_WEST	= 1,	/* anchor to top-left corner */
+    XP_GRAVITY_NORTH_EAST	= 2,	/* anchor to top-right corner */
+    XP_GRAVITY_SOUTH_EAST	= 3,	/* anchor to bottom-right corner */
+    XP_GRAVITY_SOUTH_WEST	= 4,	/* anchor to bottom-left corner */
+};
+
+/* Values for stack_mode field */
+
+enum xp_window_stack_mode_enum {
+    XP_UNMAPPED			= 0,	/* remove the window */
+    XP_MAPPED_ABOVE		= 1,	/* display the window on top */
+    XP_MAPPED_BELOW		= 2,	/* display the window at bottom */
+};
+
+/* Data formats for depth field and composite functions */
+
+enum xp_depth_enum {
+    XP_DEPTH_NIL = 0,			/* null source when compositing */
+    XP_DEPTH_ARGB8888,
+    XP_DEPTH_RGB555,
+    XP_DEPTH_A8,			/* for masks when compositing */
+    XP_DEPTH_INDEX8,
+};
+
+/* Options that may be passed to the xp_init () function. */
+
+enum xp_init_options_enum {
+    /* Don't mark that this process can be in the foreground. */
+    XP_IN_BACKGROUND		= 1 << 0,
+
+    /* Deliver background pointer events to this process. */
+    XP_BACKGROUND_EVENTS	= 1 << 1,
+};
+
+
+
+/* Miscellaneous functions */
+
+/* Initialize the plugin library. Only the copy/fill/composite functions
+   may be called without having previously called xp_init () */
+
+extern xp_error xp_init (unsigned int options);
+
+/* Sets the current set of requested notifications to MASK. When any of
+   these arrive, CALLBACK will be invoked with CALLBACK-DATA. Note that
+   calling this function cancels any previously requested notifications
+   that aren't set in MASK. */
+
+extern xp_error xp_select_events (unsigned int mask,
+				  xp_event_fun *callback,
+				  void *callback_data);
+
+/* Waits for all initiated operations to complete. */
+
+extern xp_error xp_synchronize (void);
+
+/* Causes any display update initiated through the plugin libary to be
+   queued until update is reenabled. Note that calls to these functions
+   nest. */
+  
+extern xp_error xp_disable_update (void);
+extern xp_error xp_reenable_update (void);
+
+
+
+/* Cursor functions. */
+
+/* Installs the specified cursor. ARGB-DATA should point to 32-bit
+   premultiplied big-endian ARGB data. The HOT-X,HOT-Y parameters
+   specify the offset to the cursor's hot spot from its top-left
+   corner. */
+
+extern xp_error xp_set_cursor (unsigned int width, unsigned int height,
+			       unsigned int hot_x, unsigned int hot_y,
+			       const uint32_t *argb_data,
+			       unsigned int rowbytes);
+
+/* Hide and show the cursor if it's owned by the current process. Calls
+   to these functions nest. */
+
+extern xp_error xp_hide_cursor (void);
+extern xp_error xp_show_cursor (void);
+
+
+
+/* Window functions. */
+
+/* Create a new window as defined by MASK and VALUES. MASK must contain
+   XP_BOUNDS or an error is raised. The id of the newly created window
+   is stored in *RET-ID if this function returns XP_Success. */
+
+extern xp_error xp_create_window (unsigned int mask,
+				  const xp_window_changes *values,
+				  xp_window_id *ret_id);
+
+/* Destroys the window identified by ID. */
+
+extern xp_error xp_destroy_window (xp_window_id id);
+
+/* Reconfigures the given window according to MASK and VALUES. */
+
+extern xp_error xp_configure_window (xp_window_id id, unsigned int mask,
+				     const xp_window_changes *values);
+
+
+/* Returns true if NATIVE-ID is a window created by the plugin library.
+   If so and RET-ID is non-null, stores the id of the window in *RET-ID. */
+
+extern xp_bool xp_lookup_native_window (unsigned int native_id,
+					xp_window_id *ret_id);
+
+/* If ID names a window created by the plugin library, stores it's native
+   window id in *RET-NATIVE-ID. */
+
+extern xp_error xp_get_native_window (xp_window_id id,
+				      unsigned int *ret_native_id);
+
+
+/* Locks the rectangle IN-RECT (or, if null, the entire window) of the
+   given window's backing store. Any other non-null parameters are filled
+   in as follows:
+
+   DEPTH = format of returned data. Currently either XP_DEPTH_ARGB8888
+   or XP_DEPTH_RGB565 (possibly with 8 bit planar alpha). Data is
+   always stored in native byte order.
+
+   BITS[0] = pointer to top-left pixel of locked color data
+   BITS[1] = pointer to top-left of locked alpha data, or null if window
+   has no alpha. If the alpha data is meshed, then BITS[1] = BITS[0].
+
+   ROWBYTES[0,1] = size in bytes of each row of color,alpha data
+
+   OUT-RECT = rectangle specifying the current position and size of the
+   locked region relative to the window origin.
+
+   Note that an error is raised when trying to lock an already locked
+   window. While the window is locked, the only operations that may
+   be performed on it are to modify, access or flush its marked region. */
+
+extern xp_error xp_lock_window (xp_window_id id,
+				const xp_box *in_rect,
+				unsigned int *depth,
+				void *bits[2],
+				unsigned int rowbytes[2],
+				xp_box *out_rect);
+
+/* Mark that the region specified by SHAPE-NRECTS, SHAPE-RECTS,
+   SHAPE-TX, and SHAPE-TY in the specified window has been updated, and
+   will need to subsequently be redisplayed. */
+
+extern xp_error xp_mark_window (xp_window_id id, int shape_nrects,
+				const xp_box *shape_rects,
+				int shape_tx, int shape_ty);
+
+/* Unlocks the specified window. If FLUSH is true, then any marked
+   regions are immediately redisplayed. Note that it's an error to
+   unlock an already unlocked window. */
+
+extern xp_error xp_unlock_window (xp_window_id id, xp_bool flush);
+
+/* If anything is marked in the given window for redisplay, do it now. */
+
+extern xp_error xp_flush_window (xp_window_id id);
+
+/* Moves the contents of the region DX,DY pixels away from that specified
+   by DST_RECTS and DST_NRECTS in the window with SRC-ID to the
+   destination region in the window DST-ID. Note that currently source
+   and destination windows must be the same. */
+
+extern xp_error xp_copy_window (xp_window_id src_id, xp_window_id dst_id,
+				int dst_nrects, const xp_box *dst_rects,
+				int dx, int dy);
+
+/* Returns true if the given window has any regions marked for
+   redisplay. */
+
+extern xp_bool xp_is_window_marked (xp_window_id id);
+
+/* If successful returns a superset of the region marked for update in
+   the given window. Use xp_free_region () to release the returned data. */
+
+extern xp_error xp_get_marked_shape (xp_window_id id,
+				     int *ret_nrects, xp_box **ret_rects);
+
+extern void xp_free_shape (int nrects, xp_box *rects);
+
+/* Searches for the first window below ABOVE-ID containing the point X,Y,
+   and returns it's window id in *RET-ID. If no window is found, *RET-ID
+   is set to zero. If ABOVE-ID is zero, finds the topmost window
+   containing the given point. */
+
+extern xp_error xp_find_window (int x, int y, xp_window_id above_id,
+				xp_window_id *ret_id);
+
+/* Returns the current origin and size of the window ID in *BOUNDS-RET if
+   successful. */
+extern xp_error xp_get_window_bounds (xp_window_id id, xp_box *bounds_ret);
+
+
+
+/* Window surface functions. */
+
+/* Create a new VRAM surface on the specified window. If successful,
+   returns the identifier of the new surface in *RET-SID. */
+
+extern xp_error xp_create_surface (xp_window_id id, xp_surface_id *ret_sid);
+
+/* Destroys the specified surface. */
+
+extern xp_error xp_destroy_surface (xp_surface_id sid);
+
+/* Reconfigures the specified surface as defined by MASK and VALUES.
+   Note that specifying XP_DEPTH is an error. */
+
+extern xp_error xp_configure_surface (xp_surface_id sid, unsigned int mask,
+				      const xp_window_changes *values);
+
+/* If successful, places the client identifier of the current process
+   in *RET-CLIENT. */
+
+extern xp_error xp_get_client_id (xp_client_id *ret_client);
+
+/* Given a valid window,surface combination created by the current
+   process, attempts to allow the specified external client access
+   to that surface. If successful, returns two integers in RET-KEY
+   which the client can use to import the surface into their process. */
+
+extern xp_error xp_export_surface (xp_window_id wid, xp_surface_id sid,
+				   xp_client_id client,
+				   unsigned int ret_key[2]);
+
+/* Given a two integer key returned from xp_export_surface (), tries
+   to import the surface into the current process. If successful the
+   local surface identifier is stored in *SID-RET. */
+
+extern xp_error xp_import_surface (const unsigned int key[2],
+				   xp_surface_id *sid_ret);
+
+/* If successful, stores the number of surfaces attached to the
+   specified window in *RET. */
+
+extern xp_error xp_get_window_surface_count (xp_window_id id,
+					     unsigned int *ret);
+
+/* Attaches the CGLContextObj CGL-CTX to the specified surface. */
+
+extern xp_error xp_attach_gl_context (void *cgl_ctx, xp_surface_id sid);
+
+/* Updates the CGLContextObj CGL-CTX to reflect any recent changes to
+   the surface it's attached to. */
+
+extern xp_error xp_update_gl_context (void *cgl_ctx);
+
+
+
+/* Window frame functions. */
+
+/* Possible arguments to xp_frame_get_rect (). */
+
+enum xp_frame_rect_enum {
+    XP_FRAME_RECT_TITLEBAR		= 1,
+    XP_FRAME_RECT_TRACKING		= 2,
+    XP_FRAME_RECT_GROWBOX		= 3,
+};
+
+/* Classes of window frame. */
+
+enum xp_frame_class_enum {
+    XP_FRAME_CLASS_DOCUMENT		= 1 << 0,
+    XP_FRAME_CLASS_DIALOG		= 1 << 1,
+    XP_FRAME_CLASS_MODAL_DIALOG		= 1 << 2,
+    XP_FRAME_CLASS_SYSTEM_MODAL_DIALOG	= 1 << 3,
+    XP_FRAME_CLASS_UTILITY		= 1 << 4,
+    XP_FRAME_CLASS_TOOLBAR		= 1 << 5,
+    XP_FRAME_CLASS_MENU			= 1 << 6,
+    XP_FRAME_CLASS_SPLASH		= 1 << 7,
+    XP_FRAME_CLASS_BORDERLESS		= 1 << 8,
+};
+
+/* Attributes of window frames. */
+
+enum xp_frame_attr_enum {
+    XP_FRAME_ACTIVE			= 0x0001,
+    XP_FRAME_URGENT			= 0x0002,
+    XP_FRAME_TITLE			= 0x0004,
+    XP_FRAME_PRELIGHT			= 0x0008,
+    XP_FRAME_SHADED			= 0x0010,
+    XP_FRAME_CLOSE_BOX			= 0x0100,
+    XP_FRAME_COLLAPSE			= 0x0200,
+    XP_FRAME_ZOOM			= 0x0400,
+    XP_FRAME_ANY_BUTTON			= 0x0700,
+    XP_FRAME_CLOSE_BOX_CLICKED		= 0x0800,
+    XP_FRAME_COLLAPSE_BOX_CLICKED	= 0x1000,
+    XP_FRAME_ZOOM_BOX_CLICKED		= 0x2000,
+    XP_FRAME_ANY_CLICKED		= 0x3800,
+    XP_FRAME_GROW_BOX			= 0x4000,
+};
+
+#define XP_FRAME_ATTR_IS_SET(a,b)	(((a) & (b)) == (b))
+#define XP_FRAME_ATTR_IS_CLICKED(a,m)	((a) & ((m) << 3))
+#define XP_FRAME_ATTR_SET_CLICKED(a,m)	((a) |= ((m) << 3))
+#define XP_FRAME_ATTR_UNSET_CLICKED(a,m) ((a) &= ~((m) << 3))
+
+#define XP_FRAME_POINTER_ATTRS		(XP_FRAME_PRELIGHT		\
+					 | XP_FRAME_ANY_BUTTON		\
+					 | XP_FRAME_ANY_CLICKED)
+
+extern xp_error xp_frame_get_rect (int type, int class, const xp_box *outer,
+				   const xp_box *inner, xp_box *ret);
+extern xp_error xp_frame_hit_test (int class, int x, int y,
+				   const xp_box *outer,
+				   const xp_box *inner, int *ret);
+extern xp_error xp_frame_draw (xp_window_id wid, int class, unsigned int attr,
+			       const xp_box *outer, const xp_box *inner,
+			       unsigned int title_len,
+			       const unsigned char *title_bytes);
+
+
+
+/* Memory manipulation functions. */
+
+enum xp_composite_op_enum {
+    XP_COMPOSITE_SRC = 0,
+    XP_COMPOSITE_OVER,
+};
+
+#define XP_COMPOSITE_FUNCTION(op, src_depth, mask_depth, dest_depth) \
+    (((op) << 24) | ((src_depth) << 16) \
+     | ((mask_depth) << 8) | ((dest_depth) << 0))
+
+#define XP_COMPOSITE_FUNCTION_OP(f)         (((f) >> 24) & 255)
+#define XP_COMPOSITE_FUNCTION_SRC_DEPTH(f)  (((f) >> 16) & 255)
+#define XP_COMPOSITE_FUNCTION_MASK_DEPTH(f) (((f) >>  8) & 255)
+#define XP_COMPOSITE_FUNCTION_DEST_DEPTH(f) (((f) >>  0) & 255)
+
+/* Composite WIDTH by HEIGHT pixels from source and mask to destination
+   using a specified function (if source and destination overlap,
+   undefined behavior results).
+
+   For SRC and DEST, the first element of the array is the color data. If
+   the second element is non-null it implies that there is alpha data
+   (which may be meshed or planar). Data without alpha is assumed to be
+   opaque.
+
+   Passing a null SRC-ROWBYTES pointer implies that the data SRC points
+   to is a single element.
+
+   Operations that are not supported will return XP_BadImplementation. */
+
+extern xp_error xp_composite_pixels (unsigned int width, unsigned int height,
+				     unsigned int function,
+				     void *src[2], unsigned int src_rowbytes[2],
+				     void *mask, unsigned int mask_rowbytes,
+				     void *dest[2], unsigned int dest_rowbytes[2]);
+
+/* Fill HEIGHT rows of data starting at DST. Each row will have WIDTH
+   bytes filled with the 32-bit pattern VALUE. Each row is DST-ROWBYTES
+   wide in total. */
+
+extern void xp_fill_bytes (unsigned int width,
+			   unsigned int height, uint32_t value,
+			   void *dst, unsigned int dst_rowbytes);
+
+/* Copy HEIGHT rows of bytes from SRC to DST. Each row will have WIDTH
+   bytes copied. SRC and DST may overlap, and the right thing will happen. */
+
+extern void xp_copy_bytes (unsigned int width, unsigned int height,
+			   const void *src, unsigned int src_rowbytes,
+			   void *dst, unsigned int dst_rowbytes);
+
+/* Suggestions for the minimum number of bytes or pixels for which it
+   makes sense to use some of the xp_ functions */
+
+extern unsigned int xp_fill_bytes_threshold, xp_copy_bytes_threshold,
+    xp_composite_area_threshold, xp_scroll_area_threshold;
+
+
+#endif /* XPLUGIN_H */
diff --git a/hw/darwin/quartz/xpr/appledri.c b/hw/darwin/quartz/xpr/appledri.c
new file mode 100644
index 0000000..8178261
--- /dev/null
+++ b/hw/darwin/quartz/xpr/appledri.c
@@ -0,0 +1,353 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Kevin E. Martin <martin at valinux.com>
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Faith <faith at valinux.com>
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define _APPLEDRI_SERVER_
+#include "appledristr.h"
+#include "swaprep.h"
+#include "dri.h"
+#include "dristruct.h"
+
+static int DRIErrorBase = 0;
+
+static DISPATCH_PROC(ProcAppleDRIDispatch);
+static DISPATCH_PROC(SProcAppleDRIDispatch);
+
+static void AppleDRIResetProc(ExtensionEntry* extEntry);
+
+static unsigned char DRIReqCode = 0;
+static int DRIEventBase = 0;
+
+static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
+
+typedef struct _DRIEvent *DRIEventPtr;
+typedef struct _DRIEvent {
+    DRIEventPtr     next;
+    ClientPtr       client;
+    XID             clientResource;
+    unsigned int    mask;
+} DRIEventRec;
+
+
+void
+AppleDRIExtensionInit(void)
+{
+    ExtensionEntry* extEntry;
+
+    if (DRIExtensionInit() &&
+        (extEntry = AddExtension(APPLEDRINAME,
+                                 AppleDRINumberEvents,
+                                 AppleDRINumberErrors,
+                                 ProcAppleDRIDispatch,
+                                 SProcAppleDRIDispatch,
+                                 AppleDRIResetProc,
+                                 StandardMinorOpcode))) {
+        DRIReqCode = (unsigned char)extEntry->base;
+        DRIErrorBase = extEntry->errorBase;
+        DRIEventBase = extEntry->eventBase;
+        EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
+    }
+}
+
+/*ARGSUSED*/
+static void
+AppleDRIResetProc (
+    ExtensionEntry* extEntry
+)
+{
+    DRIReset();
+}
+
+static int
+ProcAppleDRIQueryVersion(
+    register ClientPtr client
+)
+{
+    xAppleDRIQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = APPLE_DRI_MAJOR_VERSION;
+    rep.minorVersion = APPLE_DRI_MINOR_VERSION;
+    rep.patchVersion = APPLE_DRI_PATCH_VERSION;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+
+/* surfaces */
+
+static int
+ProcAppleDRIQueryDirectRenderingCapable(
+    register ClientPtr client
+)
+{
+    xAppleDRIQueryDirectRenderingCapableReply rep;
+    Bool isCapable;
+
+    REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
+    REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen], 
+                                         &isCapable)) {
+        return BadValue;
+    }
+    rep.isCapable = isCapable;
+
+    if (!LocalClient(client))
+        rep.isCapable = 0;
+
+    WriteToClient(client, 
+        sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcAppleDRIAuthConnection(
+    register ClientPtr client
+)
+{
+    xAppleDRIAuthConnectionReply rep;
+    
+    REQUEST(xAppleDRIAuthConnectionReq);
+    REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.authenticated = 1;
+
+    if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
+        ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic);
+        rep.authenticated = 0;
+    }
+    WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static void surface_notify(
+    void *_arg,
+    void *data
+)
+{
+    DRISurfaceNotifyArg *arg = _arg;
+    int client_index = (int) data;
+    ClientPtr client;
+    xAppleDRINotifyEvent se;
+
+    if (client_index < 0 || client_index >= currentMaxClients)
+        return;
+
+    client = clients[client_index];
+    if (client == NULL || client == serverClient || client->clientGone)
+        return;
+
+    se.type = DRIEventBase + AppleDRISurfaceNotify;
+    se.kind = arg->kind;
+    se.arg = arg->id;
+    se.sequenceNumber = client->sequence;
+    se.time = currentTime.milliseconds;
+    WriteEventsToClient (client, 1, (xEvent *) &se);
+}
+
+static int
+ProcAppleDRICreateSurface(
+    ClientPtr client
+)
+{
+    xAppleDRICreateSurfaceReply rep;
+    DrawablePtr pDrawable;
+    xp_surface_id sid;
+    unsigned int key[2];
+
+    REQUEST(xAppleDRICreateSurfaceReq);
+    REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
+                                                (Drawable)stuff->drawable,
+                                                client, 
+                                                SecurityReadAccess))) {
+        return BadValue;
+    }
+
+    rep.key_0 = rep.key_1 = rep.uid = 0;
+
+    if (!DRICreateSurface( screenInfo.screens[stuff->screen],
+                           (Drawable)stuff->drawable, pDrawable,
+                           stuff->client_id, &sid, key,
+                           surface_notify, (void *) client->index)) {
+        return BadValue;
+    }
+
+    rep.key_0 = key[0];
+    rep.key_1 = key[1];
+    rep.uid = sid;
+
+    WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcAppleDRIDestroySurface(
+    register ClientPtr client
+)
+{
+    REQUEST(xAppleDRIDestroySurfaceReq);
+    DrawablePtr pDrawable;
+    REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
+
+    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
+                                                (Drawable)stuff->drawable,
+                                                client, 
+                                                SecurityReadAccess))) {
+        return BadValue;
+    }
+
+    if (!DRIDestroySurface( screenInfo.screens[stuff->screen], 
+                            (Drawable)stuff->drawable,
+                            pDrawable, NULL, NULL)) {
+        return BadValue;
+    }
+
+    return (client->noClientException);
+}
+
+
+/* dispatch */
+
+static int
+ProcAppleDRIDispatch (
+    register ClientPtr client
+)
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+    case X_AppleDRIQueryVersion:
+        return ProcAppleDRIQueryVersion(client);
+    case X_AppleDRIQueryDirectRenderingCapable:
+        return ProcAppleDRIQueryDirectRenderingCapable(client);
+    }
+
+    if (!LocalClient(client))
+        return DRIErrorBase + AppleDRIClientNotLocal;
+
+    switch (stuff->data)
+    {
+    case X_AppleDRIAuthConnection:
+        return ProcAppleDRIAuthConnection(client);
+    case X_AppleDRICreateSurface:
+        return ProcAppleDRICreateSurface(client);
+    case X_AppleDRIDestroySurface:
+        return ProcAppleDRIDestroySurface(client);
+    default:
+        return BadRequest;
+    }
+}
+
+static void
+SNotifyEvent(
+    xAppleDRINotifyEvent *from,
+    xAppleDRINotifyEvent *to
+)
+{
+    to->type = from->type;
+    to->kind = from->kind;
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswapl (from->time, to->time);
+    cpswapl (from->arg, to->arg);
+}
+
+static int
+SProcAppleDRIQueryVersion(
+    register ClientPtr client
+)
+{
+    register int n;
+    REQUEST(xAppleDRIQueryVersionReq);
+    swaps(&stuff->length, n);
+    return ProcAppleDRIQueryVersion(client);
+}
+
+static int
+SProcAppleDRIDispatch (
+    register ClientPtr client
+)
+{
+    REQUEST(xReq);
+
+    /* It is bound to be non-local when there is byte swapping */
+    if (!LocalClient(client))
+        return DRIErrorBase + AppleDRIClientNotLocal;
+
+    /* only local clients are allowed DRI access */
+    switch (stuff->data)
+    {
+    case X_AppleDRIQueryVersion:
+        return SProcAppleDRIQueryVersion(client);
+    default:
+        return BadRequest;
+    }
+}
diff --git a/hw/darwin/quartz/xpr/appledri.h b/hw/darwin/quartz/xpr/appledri.h
new file mode 100644
index 0000000..c4e43be
--- /dev/null
+++ b/hw/darwin/quartz/xpr/appledri.h
@@ -0,0 +1,106 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Kevin E. Martin <martin at valinux.com>
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Faith <faith at valinux.com>
+ *
+ */
+
+#ifndef _APPLEDRI_H_
+#define _APPLEDRI_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_AppleDRIQueryVersion			0
+#define X_AppleDRIQueryDirectRenderingCapable	1
+#define X_AppleDRICreateSurface			2
+#define X_AppleDRIDestroySurface		3
+#define X_AppleDRIAuthConnection                4
+/* Requests up to and including 18 were used in a previous version */
+
+/* Events */
+#define AppleDRIObsoleteEvent1		0
+#define AppleDRIObsoleteEvent2		1
+#define AppleDRIObsoleteEvent3		2
+#define AppleDRISurfaceNotify		3
+#define AppleDRINumberEvents		4
+
+/* Errors */
+#define AppleDRIClientNotLocal		0
+#define AppleDRIOperationNotSupported	1
+#define AppleDRINumberErrors		(AppleDRIOperationNotSupported + 1)
+
+/* Kinds of SurfaceNotify events: */
+#define AppleDRISurfaceNotifyChanged	0
+#define AppleDRISurfaceNotifyDestroyed	1
+
+#ifndef _APPLEDRI_SERVER_
+
+typedef struct {
+    int	type;		    /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    Bool send_event;	    /* true if this came frome a SendEvent request */
+    Display *display;	    /* Display the event was read from */
+    Window window;	    /* window of event */
+    Time time;		    /* server timestamp when event happened */
+    int kind;		    /* subtype of event */
+    int arg;
+} XAppleDRINotifyEvent;
+
+_XFUNCPROTOBEGIN
+
+Bool XAppleDRIQueryExtension (Display *dpy, int *event_base, int *error_base);
+
+Bool XAppleDRIQueryVersion (Display *dpy, int *majorVersion,
+			    int *minorVersion, int *patchVersion);
+
+Bool XAppleDRIQueryDirectRenderingCapable (Display *dpy, int screen,
+					   Bool *isCapable);
+
+void *XAppleDRISetSurfaceNotifyHandler (void (*fun) (Display *dpy,
+						     unsigned uid, int kind));
+
+Bool XAppleDRIAuthConnection (Display *dpy, int screen, unsigned int magic);
+
+Bool XAppleDRICreateSurface (Display *dpy, int screen, Drawable drawable,
+			     unsigned int client_id, unsigned int key[2],
+			     unsigned int* uid);
+
+Bool XAppleDRIDestroySurface (Display *dpy, int screen, Drawable drawable);
+
+Bool XAppleDRISynchronizeSurfaces (Display *dpy);
+
+_XFUNCPROTOEND
+
+#endif /* _APPLEDRI_SERVER_ */
+#endif /* _APPLEDRI_H_ */
+
diff --git a/hw/darwin/quartz/xpr/appledristr.h b/hw/darwin/quartz/xpr/appledristr.h
new file mode 100644
index 0000000..8649fd3
--- /dev/null
+++ b/hw/darwin/quartz/xpr/appledristr.h
@@ -0,0 +1,175 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Kevin E. Martin <martin at valinux.com>
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Fiath <faith at valinux.com>
+ *
+ */
+
+#ifndef _APPLEDRISTR_H_
+#define _APPLEDRISTR_H_
+
+#include "appledri.h"
+
+#define APPLEDRINAME "Apple-DRI"
+
+#define APPLE_DRI_MAJOR_VERSION	1	/* current version numbers */
+#define APPLE_DRI_MINOR_VERSION	0
+#define APPLE_DRI_PATCH_VERSION	0
+
+typedef struct _AppleDRIQueryVersion {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRIQueryVersion */
+    CARD16	length B16;
+} xAppleDRIQueryVersionReq;
+#define sz_xAppleDRIQueryVersionReq	4
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    CARD16	majorVersion B16;	/* major version of DRI protocol */
+    CARD16	minorVersion B16;	/* minor version of DRI protocol */
+    CARD32	patchVersion B32;       /* patch version of DRI protocol */
+    CARD32	pad3 B32;
+    CARD32	pad4 B32;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+} xAppleDRIQueryVersionReply;
+#define sz_xAppleDRIQueryVersionReply	32
+
+typedef struct _AppleDRIQueryDirectRenderingCapable {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* X_DRIQueryDirectRenderingCapable */
+    CARD16	length B16;
+    CARD32	screen B32;
+} xAppleDRIQueryDirectRenderingCapableReq;
+#define sz_xAppleDRIQueryDirectRenderingCapableReq	8
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    BOOL	isCapable;
+    BOOL	pad2;
+    BOOL	pad3;
+    BOOL	pad4;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+    CARD32	pad7 B32;
+    CARD32	pad8 B32;
+    CARD32	pad9 B32;
+} xAppleDRIQueryDirectRenderingCapableReply;
+#define sz_xAppleDRIQueryDirectRenderingCapableReply	32
+
+typedef struct _AppleDRIAuthConnection {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRICloseConnection */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32      magic B32;
+} xAppleDRIAuthConnectionReq;
+#define sz_xAppleDRIAuthConnectionReq	12
+
+typedef struct {
+    BYTE        type;
+    BOOL        pad1;
+    CARD16      sequenceNumber B16;
+    CARD32      length B32;
+    CARD32      authenticated B32;
+    CARD32      pad2 B32;
+    CARD32      pad3 B32;
+    CARD32      pad4 B32;
+    CARD32      pad5 B32;
+    CARD32      pad6 B32;
+} xAppleDRIAuthConnectionReply;
+#define zx_xAppleDRIAuthConnectionReply  32
+
+typedef struct _AppleDRICreateSurface {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRICreateSurface */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32	drawable B32;
+    CARD32	client_id B32;
+} xAppleDRICreateSurfaceReq;
+#define sz_xAppleDRICreateSurfaceReq	16
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    CARD32	key_0 B32;
+    CARD32	key_1 B32;
+    CARD32	uid B32;
+    CARD32	pad4 B32;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+} xAppleDRICreateSurfaceReply;
+#define sz_xAppleDRICreateSurfaceReply	32
+
+typedef struct _AppleDRIDestroySurface {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRIDestroySurface */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32	drawable B32;
+} xAppleDRIDestroySurfaceReq;
+#define sz_xAppleDRIDestroySurfaceReq	12
+
+typedef struct _AppleDRINotify {
+	BYTE	type;		/* always eventBase + event type */
+	BYTE	kind;
+	CARD16	sequenceNumber B16;
+	Time	time B32;	/* time of change */
+	CARD16	pad1 B16;
+	CARD32	arg B32;
+	CARD32	pad3 B32;
+} xAppleDRINotifyEvent;
+#define sz_xAppleDRINotifyEvent	20
+
+#ifdef _APPLEDRI_SERVER_
+
+void AppleDRISendEvent (
+#if NeedFunctionPrototypes
+    int			/* type */,
+    unsigned int	/* mask */,
+    int			/* which */,
+    int			/* arg */
+#endif
+);
+
+#endif /* _APPLEDRI_SERVER_ */
+#endif /* _APPLEDRISTR_H_ */
diff --git a/hw/darwin/quartz/xpr/dri.c b/hw/darwin/quartz/xpr/dri.c
new file mode 100644
index 0000000..e5591ab
--- /dev/null
+++ b/hw/darwin/quartz/xpr/dri.c
@@ -0,0 +1,760 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Faith <faith at valinux.com>
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifdef XFree86LOADER
+#include "xf86.h"
+#include "xf86_ansic.h"
+#else
+#include <sys/time.h>
+#include <unistd.h>
+#endif
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "servermd.h"
+#define _APPLEDRI_SERVER_
+#include "appledristr.h"
+#include "swaprep.h"
+#include "dri.h"
+#include "dristruct.h"
+#include "mi.h"
+#include "mipointer.h"
+#include "rootless.h"
+#include "x-hash.h"
+#include "x-hook.h"
+
+#include <AvailabilityMacros.h>
+
+static int DRIScreenPrivIndex = -1;
+static int DRIWindowPrivIndex = -1;
+static int DRIPixmapPrivIndex = -1;
+
+static RESTYPE DRIDrawablePrivResType;
+
+static x_hash_table *surface_hash;      /* maps surface ids -> drawablePrivs */
+
+/* FIXME: don't hardcode this? */
+#define CG_INFO_FILE "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/Info-macos.plist"
+
+/* Corresponds to SU Jaguar Green */
+#define CG_REQUIRED_MAJOR 1
+#define CG_REQUIRED_MINOR 157
+#define CG_REQUIRED_MICRO 11
+
+/* Returns version as major.minor.micro in 10.10.10 fixed form */
+static unsigned int
+get_cg_version (void)
+{
+    static unsigned int version;
+
+    FILE *fh;
+    char *ptr;
+
+    if (version != 0)
+        return version;
+
+    /* I tried CFBundleGetVersion, but it returns zero, so.. */
+
+    fh = fopen (CG_INFO_FILE, "r");
+    if (fh != NULL)
+    {
+        char buf[256];
+
+        while (fgets (buf, sizeof (buf), fh) != NULL)
+        {
+            unsigned char c;
+
+            if (!strstr (buf, "<key>CFBundleShortVersionString</key>")
+                || fgets (buf, sizeof (buf), fh) == NULL)
+            {
+                continue;
+            }
+
+            ptr = strstr (buf, "<string>");
+            if (ptr == NULL)
+                continue;
+
+            ptr += strlen ("<string>");
+
+            /* Now PTR points to "MAJOR.MINOR.MICRO". */
+
+            version = 0;
+
+        again:
+            switch ((c = *ptr++))
+            {
+            case '.':
+                version = version * 1024;
+                goto again;
+
+            case '0': case '1': case '2': case '3': case '4':
+            case '5': case '6': case '7': case '8': case '9':
+                version = ((version & ~0x3ff)
+                          + (version & 0x3ff) * 10 + (c - '0'));
+                goto again;
+            }
+            break;
+        }
+
+        fclose (fh);
+    }
+
+    return version;
+}
+
+static Bool
+test_cg_version (unsigned int major, unsigned int minor, unsigned int micro)
+{
+    unsigned int cg_ver = get_cg_version ();
+
+    unsigned int cg_major = (cg_ver >> 20) & 0x3ff;
+    unsigned int cg_minor = (cg_ver >> 10) & 0x3ff;
+    unsigned int cg_micro =  cg_ver        & 0x3ff;
+
+    if (cg_major > major)
+        return TRUE;
+    else if (cg_major < major)
+        return FALSE;
+
+    /* cg_major == major */
+
+    if (cg_minor > minor)
+        return TRUE;
+    else if (cg_minor < minor)
+        return FALSE;
+
+    /* cg_minor == minor */
+
+    if (cg_micro < micro)
+        return FALSE;
+
+    return TRUE;
+}
+
+Bool
+DRIScreenInit(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr    pDRIPriv;
+    int                 i;
+
+    pDRIPriv = (DRIScreenPrivPtr) xcalloc(1, sizeof(DRIScreenPrivRec));
+    if (!pDRIPriv) {
+        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+        return FALSE;
+    }
+
+    pScreen->devPrivates[DRIScreenPrivIndex].ptr = (pointer) pDRIPriv;
+    pDRIPriv->directRenderingSupport = TRUE;
+    pDRIPriv->nrWindows = 0;
+
+    /* Need recent cg for window access update */
+    if (!test_cg_version (CG_REQUIRED_MAJOR,
+                          CG_REQUIRED_MINOR,
+                          CG_REQUIRED_MICRO))
+    {
+        ErrorF ("[DRI] disabled direct rendering; requires CoreGraphics %d.%d.%d\n",
+                CG_REQUIRED_MAJOR, CG_REQUIRED_MINOR, CG_REQUIRED_MICRO);
+
+        pDRIPriv->directRenderingSupport = FALSE;
+
+        /* Note we don't nuke the dri private, since we need it for
+           managing indirect surfaces. */
+    }
+
+    /* Initialize drawable tables */
+    for (i = 0; i < DRI_MAX_DRAWABLES; i++) {
+        pDRIPriv->DRIDrawables[i] = NULL;
+    }
+
+    return TRUE;
+}
+
+Bool
+DRIFinishScreenInit(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr  pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    /* Allocate zero sized private area for each window. Should a window
+     * become a DRI window, we'll hang a DRIWindowPrivateRec off of this
+     * private index.
+     */
+    if (!AllocateWindowPrivate(pScreen, DRIWindowPrivIndex, 0))
+        return FALSE;
+
+    /* Wrap DRI support */
+    pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
+    pScreen->ValidateTree = DRIValidateTree;
+
+    pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
+    pScreen->PostValidateTree = DRIPostValidateTree;
+
+    pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
+    pScreen->WindowExposures = DRIWindowExposures;
+
+    pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
+    pScreen->CopyWindow = DRICopyWindow;
+
+    pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
+    pScreen->ClipNotify = DRIClipNotify;
+
+    //    ErrorF("[DRI] screen %d installation complete\n", pScreen->myNum);
+
+    return TRUE;
+}
+
+void
+DRICloseScreen(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    if (pDRIPriv && pDRIPriv->directRenderingSupport) {
+        xfree(pDRIPriv);
+        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+    }
+}
+
+Bool
+DRIExtensionInit(void)
+{
+    static unsigned long DRIGeneration = 0;
+
+    if (DRIGeneration != serverGeneration) {
+        if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
+            return FALSE;
+        DRIGeneration = serverGeneration;
+    }
+
+    /*
+     * Allocate a window private index with a zero sized private area for
+     * each window, then should a window become a DRI window, we'll hang
+     * a DRIWindowPrivateRec off of this private index. Do same for pixmaps.
+     */
+    if ((DRIWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
+        return FALSE;
+    if ((DRIPixmapPrivIndex = AllocatePixmapPrivateIndex()) < 0)
+        return FALSE;
+
+    DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete);
+
+    return TRUE;
+}
+
+void
+DRIReset(void)
+{
+    /*
+     * This stub routine is called when the X Server recycles, resources
+     * allocated by DRIExtensionInit need to be managed here.
+     *
+     * Currently this routine is a stub because all the interesting resources
+     * are managed via the screen init process.
+     */
+}
+
+Bool
+DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool* isCapable)
+{
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    if (pDRIPriv)
+        *isCapable = pDRIPriv->directRenderingSupport;
+    else
+        *isCapable = FALSE;
+
+    return TRUE;
+}
+
+Bool
+DRIAuthConnection(ScreenPtr pScreen, unsigned int magic)
+{
+#if 0
+    /* FIXME: something? */
+
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    if (drmAuthMagic(pDRIPriv->drmFD, magic)) return FALSE;
+#endif
+    return TRUE;
+}
+
+static void
+DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw)
+{
+    xp_window_changes wc;
+    unsigned int flags = 0;
+
+    if (pDRIDrawablePriv->sid == 0)
+        return;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+    wc.depth = (pDraw->bitsPerPixel == 32 ? XP_DEPTH_ARGB8888
+                : pDraw->bitsPerPixel == 16 ? XP_DEPTH_RGB555 : XP_DEPTH_NIL);
+    if (wc.depth != XP_DEPTH_NIL)
+        flags |= XP_DEPTH;
+#endif
+
+    if (pDraw->type == DRAWABLE_WINDOW) {
+        WindowPtr pWin = (WindowPtr) pDraw;
+        WindowPtr pTopWin = TopLevelParent(pWin);
+
+        wc.x = pWin->drawable.x - (pTopWin->drawable.x - pTopWin->borderWidth);
+        wc.y = pWin->drawable.y - (pTopWin->drawable.y - pTopWin->borderWidth);
+        wc.width = pWin->drawable.width + 2 * pWin->borderWidth;
+        wc.height = pWin->drawable.height + 2 * pWin->borderWidth;
+        wc.bit_gravity = XP_GRAVITY_NONE;
+
+        wc.shape_nrects = REGION_NUM_RECTS(&pWin->clipList);
+        wc.shape_rects = REGION_RECTS(&pWin->clipList);
+        wc.shape_tx = - (pTopWin->drawable.x - pTopWin->borderWidth);
+        wc.shape_ty = - (pTopWin->drawable.y - pTopWin->borderWidth);
+
+        flags |= XP_BOUNDS | XP_SHAPE;
+
+    } else if (pDraw->type == DRAWABLE_PIXMAP) {
+        wc.x = 0;
+        wc.y = 0;
+        wc.width = pDraw->width;
+        wc.height = pDraw->height;
+        wc.bit_gravity = XP_GRAVITY_NONE;
+        flags |= XP_BOUNDS;
+    }
+
+    xp_configure_surface(pDRIDrawablePriv->sid, flags, &wc);
+}
+
+Bool
+DRICreateSurface(ScreenPtr pScreen, Drawable id,
+                 DrawablePtr pDrawable, xp_client_id client_id,
+                 xp_surface_id *surface_id, unsigned int ret_key[2],
+                 void (*notify) (void *arg, void *data), void *notify_data)
+{
+    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+    DRIDrawablePrivPtr  pDRIDrawablePriv;
+    xp_window_id        wid = 0;
+
+    if (pDrawable->type == DRAWABLE_WINDOW) {
+        WindowPtr pWin = (WindowPtr)pDrawable;
+
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+        if (pDRIDrawablePriv == NULL) {
+            xp_error err;
+            xp_window_changes wc;
+
+            /* allocate a DRI Window Private record */
+            if (!(pDRIDrawablePriv = xalloc(sizeof(DRIDrawablePrivRec)))) {
+                return FALSE;
+            }
+
+            pDRIDrawablePriv->pDraw = pDrawable;
+            pDRIDrawablePriv->pScreen = pScreen;
+            pDRIDrawablePriv->refCount = 0;
+            pDRIDrawablePriv->drawableIndex = -1;
+            pDRIDrawablePriv->notifiers = NULL;
+
+            /* find the physical window */
+            wid = (xp_window_id) RootlessFrameForWindow(pWin, TRUE);
+            if (wid == 0) {
+                xfree(pDRIDrawablePriv);
+                return FALSE;
+            }
+
+            /* allocate the physical surface */
+            err = xp_create_surface(wid, &pDRIDrawablePriv->sid);
+            if (err != Success) {
+                xfree(pDRIDrawablePriv);
+                return FALSE;
+            }
+
+            /* Make it visible */
+            wc.stack_mode = XP_MAPPED_ABOVE;
+            wc.sibling = 0;
+            err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc);
+            if (err != Success)
+            {
+                xp_destroy_surface(pDRIDrawablePriv->sid);
+                xfree(pDRIDrawablePriv);
+                return FALSE;
+            }
+
+            /* save private off of preallocated index */
+            pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv;
+        }
+    }
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+    else if (pDrawable->type == DRAWABLE_PIXMAP) {
+        PixmapPtr pPix = (PixmapPtr)pDrawable;
+
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
+        if (pDRIDrawablePriv == NULL) {
+            xp_error err;
+
+            /* allocate a DRI Window Private record */
+            if (!(pDRIDrawablePriv = xcalloc(1, sizeof(DRIDrawablePrivRec)))) {
+                return FALSE;
+            }
+
+            pDRIDrawablePriv->pDraw = pDrawable;
+            pDRIDrawablePriv->pScreen = pScreen;
+            pDRIDrawablePriv->refCount = 0;
+            pDRIDrawablePriv->drawableIndex = -1;
+            pDRIDrawablePriv->notifiers = NULL;
+
+            /* Passing a null window id to Xplugin in 10.3+ asks for
+               an accelerated offscreen surface. */
+
+            err = xp_create_surface(0, &pDRIDrawablePriv->sid);
+            if (err != Success) {
+                xfree(pDRIDrawablePriv);
+                return FALSE;
+            }
+
+            /* save private off of preallocated index */
+            pPix->devPrivates[DRIPixmapPrivIndex].ptr = (pointer)pDRIDrawablePriv;
+        }
+    }
+#endif
+
+    else { /* for GLX 1.3, a PBuffer */
+        /* NOT_DONE */
+        return FALSE;
+    }
+
+    /* Finish initialization of new surfaces */
+    if (pDRIDrawablePriv->refCount == 0) {
+        unsigned int key[2] = {0};
+        xp_error err;
+
+        /* try to give the client access to the surface */
+        if (client_id != 0 && wid != 0)
+        {
+            err = xp_export_surface(wid, pDRIDrawablePriv->sid,
+                                    client_id, key);
+            if (err != Success) {
+                xp_destroy_surface(pDRIDrawablePriv->sid);
+                xfree(pDRIDrawablePriv);
+                return FALSE;
+            }
+        }
+
+        pDRIDrawablePriv->key[0] = key[0];
+        pDRIDrawablePriv->key[1] = key[1];
+
+        ++pDRIPriv->nrWindows;
+
+        /* and stash it by surface id */
+        if (surface_hash == NULL)
+            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
+        x_hash_table_insert(surface_hash,
+                            (void *) pDRIDrawablePriv->sid, pDRIDrawablePriv);
+
+        /* track this in case this window is destroyed */
+        AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable);
+
+        /* Initialize shape */
+        DRIUpdateSurface(pDRIDrawablePriv, pDrawable);
+    }
+
+    pDRIDrawablePriv->refCount++;
+
+    *surface_id = pDRIDrawablePriv->sid;
+
+    if (ret_key != NULL) {
+        ret_key[0] = pDRIDrawablePriv->key[0];
+        ret_key[1] = pDRIDrawablePriv->key[1];
+    }
+
+    if (notify != NULL) {
+        pDRIDrawablePriv->notifiers = x_hook_add(pDRIDrawablePriv->notifiers,
+                                                 notify, notify_data);
+    }
+
+    return TRUE;
+}
+
+Bool
+DRIDestroySurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable,
+                  void (*notify) (void *, void *), void *notify_data)
+{
+    DRIDrawablePrivPtr  pDRIDrawablePriv;
+
+    if (pDrawable->type == DRAWABLE_WINDOW) {
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW((WindowPtr)pDrawable);
+    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP((PixmapPtr)pDrawable);
+    } else {
+        return FALSE;
+    }
+
+    if (pDRIDrawablePriv != NULL) {
+        if (notify != NULL) {
+            pDRIDrawablePriv->notifiers = x_hook_remove(pDRIDrawablePriv->notifiers,
+                                                        notify, notify_data);
+        }
+        if (--pDRIDrawablePriv->refCount <= 0) {
+            /* This calls back to DRIDrawablePrivDelete
+               which frees the private area */
+            FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
+        }
+    }
+
+    return TRUE;
+}
+
+Bool
+DRIDrawablePrivDelete(pointer pResource, XID id)
+{
+    DrawablePtr         pDrawable = (DrawablePtr)pResource;
+    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen);
+    DRIDrawablePrivPtr  pDRIDrawablePriv = NULL;
+    WindowPtr           pWin = NULL;
+    PixmapPtr           pPix = NULL;
+
+    if (pDrawable->type == DRAWABLE_WINDOW) {
+        pWin = (WindowPtr)pDrawable;
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
+        pPix = (PixmapPtr)pDrawable;
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
+    }
+
+    if (pDRIDrawablePriv == NULL)
+        return FALSE;
+
+    if (pDRIDrawablePriv->drawableIndex != -1) {
+        /* release drawable table entry */
+        pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
+    }
+
+    if (pDRIDrawablePriv->sid != 0) {
+        xp_destroy_surface(pDRIDrawablePriv->sid);
+        x_hash_table_remove(surface_hash, (void *) pDRIDrawablePriv->sid);
+    }
+
+    if (pDRIDrawablePriv->notifiers != NULL)
+        x_hook_free(pDRIDrawablePriv->notifiers);
+
+    xfree(pDRIDrawablePriv);
+
+    if (pDrawable->type == DRAWABLE_WINDOW) {
+        pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
+    } else if (pDrawable->type == DRAWABLE_PIXMAP) {
+        pPix->devPrivates[DRIPixmapPrivIndex].ptr = NULL;
+    }
+
+    --pDRIPriv->nrWindows;
+
+    return TRUE;
+}
+
+void
+DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+    DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+
+    if (pDRIDrawablePriv) {
+        /* FIXME: something? */
+    }
+
+    pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
+
+    (*pScreen->WindowExposures)(pWin, prgn, bsreg);
+
+    pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
+    pScreen->WindowExposures = DRIWindowExposures;
+}
+
+void
+DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+    DRIDrawablePrivPtr pDRIDrawablePriv;
+
+    if (pDRIPriv->nrWindows > 0) {
+       pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+       if (pDRIDrawablePriv != NULL) {
+            DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
+       }
+    }
+
+    /* unwrap */
+    pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
+
+    /* call lower layers */
+    (*pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc);
+
+    /* rewrap */
+    pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
+    pScreen->CopyWindow = DRICopyWindow;
+}
+
+int
+DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
+{
+    ScreenPtr pScreen = pParent->drawable.pScreen;
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+    int returnValue;
+
+    /* unwrap */
+    pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
+
+    /* call lower layers */
+    returnValue = (*pScreen->ValidateTree)(pParent, pChild, kind);
+
+    /* rewrap */
+    pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
+    pScreen->ValidateTree = DRIValidateTree;
+
+    return returnValue;
+}
+
+void
+DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
+{
+    ScreenPtr pScreen;
+    DRIScreenPrivPtr pDRIPriv;
+
+    if (pParent) {
+        pScreen = pParent->drawable.pScreen;
+    } else {
+        pScreen = pChild->drawable.pScreen;
+    }
+    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    if (pDRIPriv->wrap.PostValidateTree) {
+        /* unwrap */
+        pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
+
+        /* call lower layers */
+        (*pScreen->PostValidateTree)(pParent, pChild, kind);
+
+        /* rewrap */
+        pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
+        pScreen->PostValidateTree = DRIPostValidateTree;
+    }
+}
+
+void
+DRIClipNotify(WindowPtr pWin, int dx, int dy)
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+    DRIDrawablePrivPtr  pDRIDrawablePriv;
+
+    if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
+        DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
+    }
+
+    if (pDRIPriv->wrap.ClipNotify) {
+        pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify;
+
+        (*pScreen->ClipNotify)(pWin, dx, dy);
+
+        pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
+        pScreen->ClipNotify = DRIClipNotify;
+    }
+}
+
+/* This lets us get at the unwrapped functions so that they can correctly
+ * call the lower level functions, and choose whether they will be
+ * called at every level of recursion (eg in validatetree).
+ */
+DRIWrappedFuncsRec *
+DRIGetWrappedFuncs(ScreenPtr pScreen)
+{
+    return &(DRI_SCREEN_PRIV(pScreen)->wrap);
+}
+
+void
+DRIQueryVersion(int *majorVersion,
+                int *minorVersion,
+                int *patchVersion)
+{
+    *majorVersion = APPLE_DRI_MAJOR_VERSION;
+    *minorVersion = APPLE_DRI_MINOR_VERSION;
+    *patchVersion = APPLE_DRI_PATCH_VERSION;
+}
+
+void
+DRISurfaceNotify(xp_surface_id id, int kind)
+{
+    DRIDrawablePrivPtr pDRIDrawablePriv = NULL;
+    DRISurfaceNotifyArg arg;
+
+    arg.id = id;
+    arg.kind = kind;
+
+    if (surface_hash != NULL)
+    {
+        pDRIDrawablePriv = x_hash_table_lookup(surface_hash,
+                                               (void *) id, NULL);
+    }
+
+    if (pDRIDrawablePriv == NULL)
+        return;
+
+    if (kind == AppleDRISurfaceNotifyDestroyed)
+    {
+        pDRIDrawablePriv->sid = 0;
+        x_hash_table_remove(surface_hash, (void *) id);
+    }
+
+    x_hook_run(pDRIDrawablePriv->notifiers, &arg);
+
+    if (kind == AppleDRISurfaceNotifyDestroyed)
+    {
+        /* Kill off the handle. */
+
+        FreeResourceByType(pDRIDrawablePriv->pDraw->id,
+                           DRIDrawablePrivResType, FALSE);
+    }
+}
diff --git a/hw/darwin/quartz/xpr/dri.h b/hw/darwin/quartz/xpr/dri.h
new file mode 100644
index 0000000..cf2638a
--- /dev/null
+++ b/hw/darwin/quartz/xpr/dri.h
@@ -0,0 +1,128 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Jens Owen <jens at precisioninsight.com>
+ *
+ */
+
+/* Prototypes for AppleDRI functions */
+
+#ifndef _DRI_H_
+#define _DRI_H_
+
+#include <X11/Xdefs.h>
+#include "scrnintstr.h"
+#define _APPLEDRI_SERVER_
+#include "appledri.h"
+#include "Xplugin.h"
+
+typedef void (*ClipNotifyPtr)( WindowPtr, int, int );
+
+
+/*
+ * These functions can be wrapped by the DRI.  Each of these have
+ * generic default funcs (initialized in DRICreateInfoRec) and can be
+ * overridden by the driver in its [driver]DRIScreenInit function.
+ */
+typedef struct {
+    WindowExposuresProcPtr       WindowExposures;
+    CopyWindowProcPtr            CopyWindow;
+    ValidateTreeProcPtr          ValidateTree;
+    PostValidateTreeProcPtr      PostValidateTree;
+    ClipNotifyProcPtr            ClipNotify;
+} DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;
+
+typedef struct {
+    xp_surface_id id;
+    int kind;
+} DRISurfaceNotifyArg;
+
+extern Bool DRIScreenInit(ScreenPtr pScreen);
+
+extern Bool DRIFinishScreenInit(ScreenPtr pScreen);
+
+extern void DRICloseScreen(ScreenPtr pScreen);
+
+extern Bool DRIExtensionInit(void);
+
+extern void DRIReset(void);
+
+extern Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen,
+                                           Bool *isCapable);
+
+extern Bool DRIAuthConnection(ScreenPtr pScreen, unsigned int magic);
+
+extern Bool DRICreateSurface(ScreenPtr pScreen,
+                             Drawable id,
+                             DrawablePtr pDrawable,
+                             xp_client_id client_id,
+                             xp_surface_id *surface_id,
+                             unsigned int key[2],
+                             void (*notify) (void *arg, void *data),
+                             void *notify_data);
+
+extern Bool DRIDestroySurface(ScreenPtr pScreen,
+                             Drawable id,
+                             DrawablePtr pDrawable,
+                             void (*notify) (void *arg, void *data),
+                             void *notify_data);
+
+extern Bool DRIDrawablePrivDelete(pointer pResource,
+                                  XID id);
+
+extern DRIWrappedFuncsRec *DRIGetWrappedFuncs(ScreenPtr pScreen);
+
+extern void DRICopyWindow(WindowPtr pWin,
+                          DDXPointRec ptOldOrg,
+                          RegionPtr prgnSrc);
+
+extern int DRIValidateTree(WindowPtr pParent,
+                           WindowPtr pChild,
+                           VTKind    kind);
+
+extern void DRIPostValidateTree(WindowPtr pParent,
+                                WindowPtr pChild,
+                                VTKind    kind);
+
+extern void DRIClipNotify(WindowPtr pWin,
+                          int dx,
+                          int dy);
+
+extern void DRIWindowExposures(WindowPtr pWin,
+                              RegionPtr prgn,
+                              RegionPtr bsreg);
+
+extern void DRISurfaceNotify (xp_surface_id id, int kind);
+
+extern void DRIQueryVersion(int *majorVersion,
+                            int *minorVersion,
+                            int *patchVersion);
+
+#endif
diff --git a/hw/darwin/quartz/xpr/dristruct.h b/hw/darwin/quartz/xpr/dristruct.h
new file mode 100644
index 0000000..9a3d01c
--- /dev/null
+++ b/hw/darwin/quartz/xpr/dristruct.h
@@ -0,0 +1,81 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright (c) 2002 Apple Computer, Inc.
+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, sub license, 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 (including the
+next paragraph) 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Jens Owen <jens at precisioninsight.com>
+ *
+ */
+
+#ifndef DRI_STRUCT_H
+#define DRI_STRUCT_H
+
+#include "dri.h"
+#include "x-list.h"
+
+#define DRI_MAX_DRAWABLES 256
+
+#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
+    ((DRIWindowPrivIndex < 0) ? \
+     NULL : \
+     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))
+
+#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
+    ((DRIPixmapPrivIndex < 0) ? \
+     NULL : \
+     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIPixmapPrivIndex].ptr)))
+
+typedef struct _DRIDrawablePrivRec
+{
+    xp_surface_id   sid;
+    int             drawableIndex;
+    DrawablePtr     pDraw;
+    ScreenPtr       pScreen;
+    int             refCount;
+    unsigned int    key[2];
+    x_list          *notifiers;     /* list of (FUN . DATA) */
+} DRIDrawablePrivRec, *DRIDrawablePrivPtr;
+
+#define DRI_SCREEN_PRIV(pScreen) \
+    ((DRIScreenPrivIndex < 0) ? \
+     NULL : \
+     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))
+
+#define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
+    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))
+
+
+typedef struct _DRIScreenPrivRec
+{
+    Bool                directRenderingSupport;
+    int                 nrWindows;
+    DRIWrappedFuncsRec  wrap;
+    DrawablePtr         DRIDrawables[DRI_MAX_DRAWABLES];
+} DRIScreenPrivRec, *DRIScreenPrivPtr;
+
+#endif /* DRI_STRUCT_H */
diff --git a/hw/darwin/quartz/xpr/x-hash.c b/hw/darwin/quartz/xpr/x-hash.c
new file mode 100644
index 0000000..55d28ba
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-hash.c
@@ -0,0 +1,343 @@
+/* x-hash.c - basic hash tables
+
+   Copyright (c) 2002 Apple Computer, Inc. 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 "x-hash.h"
+#include "x-list.h"
+#include <stdlib.h>
+#include <assert.h>
+
+struct x_hash_table_struct {
+    unsigned int bucket_index;
+    unsigned int total_keys;
+    x_list **buckets;
+
+    x_hash_fun *hash_key;
+    x_compare_fun *compare_keys;
+    x_destroy_fun *destroy_key;
+    x_destroy_fun *destroy_value;
+};
+
+#define ITEM_NEW(k, v) X_PFX (list_prepend) ((x_list *) (k), v)
+#define ITEM_FREE(i) X_PFX (list_free_1) (i)
+#define ITEM_KEY(i) ((void *) (i)->next)
+#define ITEM_VALUE(i) ((i)->data)
+
+#define SPLIT_THRESHOLD_FACTOR 2
+
+/* http://planetmath.org/?op=getobj&from=objects&name=GoodHashTablePrimes */
+static const unsigned int bucket_sizes[] = {
+    29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157,
+    98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917,
+    25165843, 50331653, 100663319, 201326611, 402653189, 805306457,
+    1610612741
+};
+
+#define N_BUCKET_SIZES (sizeof (bucket_sizes) / sizeof (bucket_sizes[0]))
+
+static inline unsigned int
+hash_table_total_buckets (x_hash_table *h)
+{
+    return bucket_sizes[h->bucket_index];
+}
+
+static inline void
+hash_table_destroy_item (x_hash_table *h, void *k, void *v)
+{
+    if (h->destroy_key != 0)
+        (*h->destroy_key) (k);
+
+    if (h->destroy_value != 0)
+        (*h->destroy_value) (v);
+}
+
+static inline unsigned int
+hash_table_hash_key (x_hash_table *h, void *k)
+{
+    if (h->hash_key != 0)
+        return (*h->hash_key) (k);
+    else
+        return (unsigned int) k;
+}
+
+static inline int
+hash_table_compare_keys (x_hash_table *h, void *k1, void *k2)
+{
+    if (h->compare_keys == 0)
+        return k1 == k2;
+    else
+        return (*h->compare_keys) (k1, k2) == 0;
+}
+
+static void
+hash_table_split (x_hash_table *h)
+{
+    x_list **new, **old;
+    x_list *node, *item, *next;
+    int new_size, old_size;
+    unsigned int b;
+    int i;
+
+    if (h->bucket_index == N_BUCKET_SIZES - 1)
+        return;
+
+    old_size = hash_table_total_buckets (h);
+    old = h->buckets;
+
+    h->bucket_index++;
+
+    new_size = hash_table_total_buckets (h);
+    new = calloc (new_size, sizeof (x_list *));
+
+    if (new == 0)
+    {
+        h->bucket_index--;
+        return;
+    }
+
+    for (i = 0; i < old_size; i++)
+    {
+        for (node = old[i]; node != 0; node = next)
+        {
+            next = node->next;
+            item = node->data;
+
+            b = hash_table_hash_key (h, ITEM_KEY (item)) % new_size;
+
+            node->next = new[b];
+            new[b] = node;
+        }
+    }
+
+    h->buckets = new;
+    free (old);
+}
+
+X_EXTERN x_hash_table *
+X_PFX (hash_table_new) (x_hash_fun *hash,
+                        x_compare_fun *compare,
+                        x_destroy_fun *key_destroy,
+                        x_destroy_fun *value_destroy)
+{
+    x_hash_table *h;
+
+    h = calloc (1, sizeof (x_hash_table));
+    if (h == 0)
+        return 0;
+
+    h->bucket_index = 0;
+    h->buckets = calloc (hash_table_total_buckets (h), sizeof (x_list *));
+
+    if (h->buckets == 0)
+    {
+        free (h);
+        return 0;
+    }
+    
+    h->hash_key = hash;
+    h->compare_keys = compare;
+    h->destroy_key = key_destroy;
+    h->destroy_value = value_destroy;
+
+    return h;
+}
+
+X_EXTERN void
+X_PFX (hash_table_free) (x_hash_table *h)
+{
+    int n, i;
+    x_list *node, *item;
+
+    assert (h != NULL);
+
+    n = hash_table_total_buckets (h);
+
+    for (i = 0; i < n; i++)
+    {
+        for (node = h->buckets[i]; node != 0; node = node->next)
+        {
+            item = node->data;
+            hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item));
+            ITEM_FREE (item);
+        }
+        X_PFX (list_free) (h->buckets[i]);
+    }
+
+    free (h->buckets);
+    free (h);
+}
+
+X_EXTERN unsigned int
+X_PFX (hash_table_size) (x_hash_table *h)
+{
+    assert (h != NULL);
+
+    return h->total_keys;
+}
+
+static void
+hash_table_modify (x_hash_table *h, void *k, void *v, int replace)
+{
+    unsigned int hash_value;
+    x_list *node, *item;
+
+    assert (h != NULL);
+
+    hash_value = hash_table_hash_key (h, k);
+
+    for (node = h->buckets[hash_value % hash_table_total_buckets (h)];
+         node != 0; node = node->next)
+    {
+        item = node->data;
+
+        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
+        {
+            if (replace)
+            {
+                hash_table_destroy_item (h, ITEM_KEY (item),
+                                         ITEM_VALUE (item));
+                item->next = k;
+                ITEM_VALUE (item) = v;
+            }
+            else
+            {
+                hash_table_destroy_item (h, k, ITEM_VALUE (item));
+                ITEM_VALUE (item) = v;
+            }
+            return;
+        }
+    }
+
+    /* Key isn't already in the table. Insert it. */
+
+    if (h->total_keys + 1
+        > hash_table_total_buckets (h) * SPLIT_THRESHOLD_FACTOR)
+    {
+        hash_table_split (h);
+    }
+
+    hash_value = hash_value % hash_table_total_buckets (h);
+    h->buckets[hash_value] = X_PFX (list_prepend) (h->buckets[hash_value],
+                                                   ITEM_NEW (k, v));
+    h->total_keys++;
+}
+
+X_EXTERN void
+X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v)
+{
+    hash_table_modify (h, k, v, 0);
+}
+
+X_EXTERN void
+X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v)
+{
+    hash_table_modify (h, k, v, 1);
+}
+
+X_EXTERN void
+X_PFX (hash_table_remove) (x_hash_table *h, void *k)
+{
+    unsigned int hash_value;
+    x_list **ptr, *item;
+
+    assert (h != NULL);
+
+    hash_value = hash_table_hash_key (h, k);
+
+    for (ptr = &h->buckets[hash_value % hash_table_total_buckets (h)];
+         *ptr != 0; ptr = &((*ptr)->next))
+    {
+        item = (*ptr)->data;
+
+        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
+        {
+            hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item));
+            ITEM_FREE (item);
+            item = *ptr;
+            *ptr = item->next;
+            X_PFX (list_free_1) (item);
+            h->total_keys--;
+            return;
+        }
+    }
+}
+
+X_EXTERN void *
+X_PFX (hash_table_lookup) (x_hash_table *h, void *k, void **k_ret)
+{
+    unsigned int hash_value;
+    x_list *node, *item;
+
+    assert (h != NULL);
+
+    hash_value = hash_table_hash_key (h, k);
+
+    for (node = h->buckets[hash_value % hash_table_total_buckets (h)];
+         node != 0; node = node->next)
+    {
+        item = node->data;
+
+        if (hash_table_compare_keys (h, ITEM_KEY (item), k))
+        {
+            if (k_ret != 0)
+            *k_ret = ITEM_KEY (item);
+
+            return ITEM_VALUE (item);
+        }
+    }
+
+    if (k_ret != 0)
+        *k_ret = 0;
+
+    return 0;
+}
+
+X_EXTERN void
+X_PFX (hash_table_foreach) (x_hash_table *h,
+                            x_hash_foreach_fun *fun, void *data)
+{
+    int i, n;
+    x_list *node, *item;
+
+    assert (h != NULL);
+
+    n = hash_table_total_buckets (h);
+
+    for (i = 0; i < n; i++)
+    {
+        for (node = h->buckets[i]; node != 0; node = node->next)
+        {
+            item = node->data;
+            (*fun) (ITEM_KEY (item), ITEM_VALUE (item), data);
+        }
+    }
+}
diff --git a/hw/darwin/quartz/xpr/x-hash.h b/hw/darwin/quartz/xpr/x-hash.h
new file mode 100644
index 0000000..3456dbe
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-hash.h
@@ -0,0 +1,60 @@
+/* x-hash.h -- basic hash table class
+
+   Copyright (c) 2002 Apple Computer, Inc. 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 X_HASH_H
+#define X_HASH_H 1
+
+typedef struct x_hash_table_struct x_hash_table;
+
+typedef int (x_compare_fun) (const void *a, const void *b);
+typedef unsigned int (x_hash_fun) (const void *k);
+typedef void (x_destroy_fun) (void *x);
+typedef void (x_hash_foreach_fun) (void *k, void *v, void *data);
+
+/* for X_PFX and X_EXTERN */
+#include "x-list.h"
+
+X_EXTERN x_hash_table *X_PFX (hash_table_new) (x_hash_fun *hash,
+					       x_compare_fun *compare,
+					       x_destroy_fun *key_destroy,
+					       x_destroy_fun *value_destroy);
+X_EXTERN void X_PFX (hash_table_free) (x_hash_table *h);
+
+X_EXTERN unsigned int X_PFX (hash_table_size) (x_hash_table *h);
+
+X_EXTERN void X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v);
+X_EXTERN void X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v);
+X_EXTERN void X_PFX (hash_table_remove) (x_hash_table *h, void *k);
+X_EXTERN void *X_PFX (hash_table_lookup) (x_hash_table *h,
+					  void *k, void **k_ret);
+X_EXTERN void X_PFX (hash_table_foreach) (x_hash_table *h,
+					  x_hash_foreach_fun *fun,
+					  void *data);
+
+#endif /* X_HASH_H */
diff --git a/hw/darwin/quartz/xpr/x-hook.c b/hw/darwin/quartz/xpr/x-hook.c
new file mode 100644
index 0000000..bb873bb
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-hook.c
@@ -0,0 +1,109 @@
+/* x-hook.c
+
+   Copyright (c) 2003 Apple Computer, Inc. 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 "x-hook.h"
+#include <stdlib.h>
+#include <assert.h>
+
+#define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d))
+#define CELL_FREE(c)  X_PFX (list_free_1) (c)
+#define CELL_FUN(c)   ((x_hook_function *) ((c)->next))
+#define CELL_DATA(c)  ((c)->data)
+
+X_EXTERN x_list *
+X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data)
+{
+    return X_PFX (list_prepend) (lst, CELL_NEW (fun, data));
+}
+
+X_EXTERN x_list *
+X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data)
+{
+    x_list *node, *cell;
+    x_list *to_delete = NULL;
+
+    for (node = lst; node != NULL; node = node->next)
+    {
+	cell = node->data;
+	if (CELL_FUN (cell) == fun && CELL_DATA (cell) == data)
+	    to_delete = X_PFX (list_prepend) (to_delete, cell);
+    }
+
+    for (node = to_delete; node != NULL; node = node->next)
+    {
+	cell = node->data;
+	lst = X_PFX (list_remove) (lst, cell);
+	CELL_FREE (cell);
+    }
+
+    X_PFX (list_free) (to_delete);
+    return lst;
+}
+
+X_EXTERN void
+X_PFX (hook_run) (x_list *lst, void *arg)
+{
+    x_list *node, *cell;
+    x_hook_function **fun;
+    void **data;
+    int length, i;
+
+    length = X_PFX (list_length) (lst);
+    fun = alloca (sizeof (x_hook_function *) * length);
+    data = alloca (sizeof (void *) * length);
+
+    for (i = 0, node = lst; node != NULL; node = node->next, i++)
+    {
+	cell = node->data;
+	fun[i] = CELL_FUN (cell);
+	data[i] = CELL_DATA (cell);
+    }
+
+    for (i = 0; i < length; i++)
+    {
+	(*fun[i]) (arg, data[i]);
+    }
+}
+
+X_EXTERN void
+X_PFX (hook_free) (x_list *lst)
+{
+    x_list *node;
+
+    for (node = lst; node != NULL; node = node->next)
+    {
+	CELL_FREE (node->data);
+    }
+
+    X_PFX (list_free) (lst);
+}
diff --git a/hw/darwin/quartz/xpr/x-hook.h b/hw/darwin/quartz/xpr/x-hook.h
new file mode 100644
index 0000000..392352d
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-hook.h
@@ -0,0 +1,42 @@
+/* x-hook.h -- lists of function,data pairs to call.
+
+   Copyright (c) 2003 Apple Computer, Inc. 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 X_HOOK_H
+#define X_HOOK_H 1
+
+#include "x-list.h"
+
+typedef void x_hook_function (void *arg, void *data);
+
+X_EXTERN x_list *X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data);
+X_EXTERN x_list *X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data);
+X_EXTERN void X_PFX (hook_run) (x_list *lst, void *arg);
+X_EXTERN void X_PFX (hook_free) (x_list *lst);
+
+#endif /* X_HOOK_H */
diff --git a/hw/darwin/quartz/xpr/x-list.c b/hw/darwin/quartz/xpr/x-list.c
new file mode 100644
index 0000000..3596dd3
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-list.c
@@ -0,0 +1,337 @@
+/* x-list.c
+
+   Copyright (c) 2002 Apple Computer, Inc. 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 "x-list.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <pthread.h>
+
+/* Allocate in ~4k blocks */
+#define NODES_PER_BLOCK 508
+
+typedef struct x_list_block_struct x_list_block;
+
+struct x_list_block_struct {
+    x_list l[NODES_PER_BLOCK];
+};
+
+static x_list *freelist;
+
+static pthread_mutex_t freelist_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static inline void
+list_free_1 (x_list *node)
+{
+    node->next = freelist;
+    freelist = node;
+}
+
+X_EXTERN void
+X_PFX (list_free_1) (x_list *node)
+{
+    assert (node != NULL);
+
+    pthread_mutex_lock (&freelist_lock);
+
+    list_free_1 (node);
+
+    pthread_mutex_unlock (&freelist_lock);
+}
+
+X_EXTERN void
+X_PFX (list_free) (x_list *lst)
+{
+    x_list *next;
+
+    pthread_mutex_lock (&freelist_lock);
+
+    for (; lst != NULL; lst = next)
+    {
+        next = lst->next;
+        list_free_1 (lst);
+    }
+
+    pthread_mutex_unlock (&freelist_lock);
+}
+
+X_EXTERN x_list *
+X_PFX (list_prepend) (x_list *lst, void *data)
+{
+    x_list *node;
+
+    pthread_mutex_lock (&freelist_lock);
+
+    if (freelist == NULL)
+    {
+        x_list_block *b;
+        int i;
+
+        b = malloc (sizeof (x_list_block));
+
+        for (i = 0; i < NODES_PER_BLOCK - 1; i++)
+            b->l[i].next = &(b->l[i+1]);
+        b->l[i].next = NULL;
+
+        freelist = b->l;
+    }
+
+    node = freelist;
+    freelist = node->next;
+
+    pthread_mutex_unlock (&freelist_lock);
+
+    node->next = lst;
+    node->data = data;
+
+    return node;
+}
+
+X_EXTERN x_list *
+X_PFX (list_append) (x_list *lst, void *data)
+{
+    x_list *head = lst;
+
+    if (lst == NULL)
+        return X_PFX (list_prepend) (NULL, data);
+
+    while (lst->next != NULL)
+        lst = lst->next;
+
+    lst->next = X_PFX (list_prepend) (NULL, data);
+
+    return head;
+}
+
+X_EXTERN x_list *
+X_PFX (list_reverse) (x_list *lst)
+{
+    x_list *head = NULL, *next;
+    
+    while (lst != NULL)
+    {
+        next = lst->next;
+        lst->next = head;
+        head = lst;
+        lst = next;
+    }
+
+    return head;
+}
+
+X_EXTERN x_list *
+X_PFX (list_find) (x_list *lst, void *data)
+{
+    for (; lst != NULL; lst = lst->next)
+    {
+        if (lst->data == data)
+            return lst;
+    }
+
+    return NULL;
+}
+
+X_EXTERN x_list *
+X_PFX (list_nth) (x_list *lst, int n)
+{
+    while (n-- > 0 && lst != NULL)
+        lst = lst->next;
+
+    return lst;
+}
+
+X_EXTERN x_list *
+X_PFX (list_pop) (x_list *lst, void **data_ret)
+{
+    void *data = NULL;
+
+    if (lst != NULL)
+    {
+        x_list *tem = lst;
+        data = lst->data;
+        lst = lst->next;
+        X_PFX (list_free_1) (tem);
+    }
+
+    if (data_ret != NULL)
+        *data_ret = data;
+
+    return lst;
+}
+
+X_EXTERN x_list *
+X_PFX (list_filter) (x_list *lst,
+                     int (*pred) (void *item, void *data), void *data)
+{
+    x_list *ret = NULL, *node;
+
+    for (node = lst; node != NULL; node = node->next)
+    {
+        if ((*pred) (node->data, data))
+            ret = X_PFX (list_prepend) (ret, node->data);
+    }
+
+    return X_PFX (list_reverse) (ret);
+}
+
+X_EXTERN x_list *
+X_PFX (list_map) (x_list *lst,
+                  void *(*fun) (void *item, void *data), void *data)
+{
+    x_list *ret = NULL, *node;
+
+    for (node = lst; node != NULL; node = node->next)
+    {
+        X_PFX (list_prepend) (ret, fun (node->data, data));
+    }
+
+    return X_PFX (list_reverse) (ret);
+}
+
+X_EXTERN x_list *
+X_PFX (list_copy) (x_list *lst)
+{
+    x_list *copy = NULL;
+
+    for (; lst != NULL; lst = lst->next)
+    {
+        copy = X_PFX (list_prepend) (copy, lst->data);
+    }
+
+    return X_PFX (list_reverse) (copy);
+}
+
+X_EXTERN x_list *
+X_PFX (list_remove) (x_list *lst, void *data)
+{
+    x_list **ptr, *node;
+
+    for (ptr = &lst; *ptr != NULL;)
+    {
+        node = *ptr;
+
+        if (node->data == data)
+        {
+            *ptr = node->next;
+            X_PFX (list_free_1) (node);
+        }
+        else
+            ptr = &((*ptr)->next);
+    }
+
+    return lst;
+}
+
+X_EXTERN unsigned int
+X_PFX (list_length) (x_list *lst)
+{
+    unsigned int n;
+
+    n = 0;
+    for (; lst != NULL; lst = lst->next)
+        n++;
+
+    return n;
+}
+
+X_EXTERN void
+X_PFX (list_foreach) (x_list *lst,
+                      void (*fun) (void *data, void *user_data),
+                      void *user_data)
+{
+    for (; lst != NULL; lst = lst->next)
+    {
+        (*fun) (lst->data, user_data);
+    }
+}
+
+static x_list *
+list_sort_1 (x_list *lst, int length,
+             int (*less) (const void *, const void *))
+{
+    x_list *mid, *ptr;
+    x_list *out_head, *out;
+    int mid_point, i;
+
+    /* This is a standard (stable) list merge sort */
+
+    if (length < 2)
+        return lst;
+
+    /* Calculate the halfway point. Split the list into two sub-lists. */
+
+    mid_point = length / 2;
+    ptr = lst;
+    for (i = mid_point - 1; i > 0; i--)
+        ptr = ptr->next;
+    mid = ptr->next;
+    ptr->next = NULL;
+
+    /* Sort each sub-list. */
+
+    lst = list_sort_1 (lst, mid_point, less);
+    mid = list_sort_1 (mid, length - mid_point, less);
+
+    /* Then merge them back together. */
+
+    assert (lst != NULL && mid != NULL);
+
+    if ((*less) (mid->data, lst->data))
+        out = out_head = mid, mid = mid->next;
+    else
+        out = out_head = lst, lst = lst->next;
+
+    while (lst != NULL && mid != NULL)
+    {
+        if ((*less) (mid->data, lst->data))
+            out = out->next = mid, mid = mid->next;
+        else
+            out = out->next = lst, lst = lst->next;
+    }
+
+    if (lst != NULL)
+        out->next = lst;
+    else
+        out->next = mid;
+
+    return out_head;
+}
+
+X_EXTERN x_list *
+X_PFX (list_sort) (x_list *lst, int (*less) (const void *, const void *))
+{
+    int length;
+
+    length = X_PFX (list_length) (lst);
+
+    return list_sort_1 (lst, length, less);
+}
diff --git a/hw/darwin/quartz/xpr/x-list.h b/hw/darwin/quartz/xpr/x-list.h
new file mode 100644
index 0000000..04af024
--- /dev/null
+++ b/hw/darwin/quartz/xpr/x-list.h
@@ -0,0 +1,77 @@
+/* x-list.h -- simple list type
+
+   Copyright (c) 2002 Apple Computer, Inc. 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 X_LIST_H
+#define X_LIST_H 1
+
+/* This is just a cons. */
+
+typedef struct x_list_struct x_list;
+
+struct x_list_struct {
+    void *data;
+    x_list *next;
+};
+
+#ifndef X_PFX
+# define X_PFX(x) x_ ## x
+#endif
+
+#ifndef X_EXTERN
+# define X_EXTERN __private_extern__
+#endif
+
+X_EXTERN void X_PFX (list_free_1) (x_list *node);
+X_EXTERN x_list *X_PFX (list_prepend) (x_list *lst, void *data);
+
+X_EXTERN x_list *X_PFX (list_append) (x_list *lst, void *data);
+X_EXTERN x_list *X_PFX (list_remove) (x_list *lst, void *data);
+X_EXTERN void X_PFX (list_free) (x_list *lst);
+X_EXTERN x_list *X_PFX (list_pop) (x_list *lst, void **data_ret);
+
+X_EXTERN x_list *X_PFX (list_copy) (x_list *lst);
+X_EXTERN x_list *X_PFX (list_reverse) (x_list *lst);
+X_EXTERN x_list *X_PFX (list_find) (x_list *lst, void *data);
+X_EXTERN x_list *X_PFX (list_nth) (x_list *lst, int n);
+X_EXTERN x_list *X_PFX (list_filter) (x_list *src,
+                                      int (*pred) (void *item, void *data),
+                                      void *data);
+X_EXTERN x_list *X_PFX (list_map) (x_list *src,
+                                   void *(*fun) (void *item, void *data),
+                                   void *data);
+
+X_EXTERN unsigned int X_PFX (list_length) (x_list *lst);
+X_EXTERN void X_PFX (list_foreach) (x_list *lst, void (*fun)
+                                    (void *data, void *user_data),
+                                    void *user_data);
+
+X_EXTERN x_list *X_PFX (list_sort) (x_list *lst, int (*less) (const void *,
+                                    const void *));
+
+#endif /* X_LIST_H */
diff --git a/hw/darwin/quartz/xpr/xpr.h b/hw/darwin/quartz/xpr/xpr.h
new file mode 100644
index 0000000..ddc6d0c
--- /dev/null
+++ b/hw/darwin/quartz/xpr/xpr.h
@@ -0,0 +1,47 @@
+/*
+ * Xplugin rootless implementation
+ *
+ * Copyright (c) 2003 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 XPR_H
+#define XPR_H
+
+#include "screenint.h"
+
+extern Bool QuartzModeBundleInit(void);
+
+void AppleDRIExtensionInit(void);
+void xprAppleWMInit(void);
+Bool xprInit(ScreenPtr pScreen);
+Bool xprIsX11Window(void *nsWindow, int windowNumber);
+
+void xprHideWindows(Bool hide);
+
+Bool QuartzInitCursor(ScreenPtr pScreen);
+void QuartzSuspendXCursor(ScreenPtr pScreen);
+void QuartzResumeXCursor(ScreenPtr pScreen, int x, int y);
+
+#endif /* XPR_H */
diff --git a/hw/darwin/quartz/xpr/xprAppleWM.c b/hw/darwin/quartz/xpr/xprAppleWM.c
new file mode 100644
index 0000000..5539c51
--- /dev/null
+++ b/hw/darwin/quartz/xpr/xprAppleWM.c
@@ -0,0 +1,100 @@
+/*
+ * Xplugin rootless implementation functions for AppleWM extension
+ *
+ * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003 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 "xpr.h"
+#include "quartz/applewmExt.h"
+#include "rootless.h"
+#include "Xplugin.h"
+#include <X11/X.h>
+
+static int xprSetWindowLevel(
+    WindowPtr pWin,
+    int level)
+{
+    xp_window_id wid;
+    xp_window_changes wc;
+
+    wid = (xp_window_id) RootlessFrameForWindow (pWin, TRUE);
+    if (wid == 0)
+        return BadWindow;
+
+    RootlessStopDrawing (pWin, FALSE);
+
+    wc.window_level = level;
+    if (xp_configure_window (wid, XP_WINDOW_LEVEL, &wc) != Success) {
+        return BadValue;
+    }
+
+    return Success;
+}
+
+
+static int xprFrameDraw(
+    WindowPtr pWin,
+    int class,
+    unsigned int attr,
+    const BoxRec *outer,
+    const BoxRec *inner,
+    unsigned int title_len,
+    const unsigned char *title_bytes)
+{
+    xp_window_id wid;
+
+    wid = (xp_window_id) RootlessFrameForWindow (pWin, FALSE);
+    if (wid == 0)
+        return BadWindow;
+
+    if (xp_frame_draw (wid, class, attr, outer, inner,
+                       title_len, title_bytes) != Success)
+    {
+        return BadValue;
+    }
+
+    return Success;
+}
+
+
+static AppleWMProcsRec xprAppleWMProcs = {
+    xp_disable_update,
+    xp_reenable_update,
+    xprSetWindowLevel,
+    xp_frame_get_rect,
+    xp_frame_hit_test,
+    xprFrameDraw
+};
+
+
+void xprAppleWMInit(void)
+{
+    AppleWMExtensionInit(&xprAppleWMProcs);
+}
diff --git a/hw/darwin/quartz/xpr/xprCursor.c b/hw/darwin/quartz/xpr/xprCursor.c
new file mode 100644
index 0000000..160b5d9
--- /dev/null
+++ b/hw/darwin/quartz/xpr/xprCursor.c
@@ -0,0 +1,431 @@
+/**************************************************************
+ *
+ * Xplugin cursor support
+ *
+ * Copyright (c) 2001 Torrey T. Lyons and Greg Parker.
+ * Copyright (c) 2002 Apple Computer, Inc.
+ *                 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 "quartz/quartzCommon.h"
+#include "xpr.h"
+#include "darwin.h"
+#include "Xplugin.h"
+
+#include "mi.h"
+#include "scrnintstr.h"
+#include "cursorstr.h"
+#include "mipointrst.h"
+#include "windowstr.h"
+#include "globals.h"
+#include "servermd.h"
+#include "dixevents.h"
+
+typedef struct {
+    int                     cursorVisible;
+    QueryBestSizeProcPtr    QueryBestSize;
+    miPointerSpriteFuncPtr  spriteFuncs;
+} QuartzCursorScreenRec, *QuartzCursorScreenPtr;
+
+static int darwinCursorScreenIndex = -1;
+static unsigned long darwinCursorGeneration = 0;
+
+#define CURSOR_PRIV(pScreen) \
+    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
+
+
+static Bool
+load_cursor(CursorPtr src, int screen)
+{
+    uint32_t *data;
+    uint32_t rowbytes;
+    int width, height;
+    int hot_x, hot_y;
+
+    uint32_t fg_color, bg_color;
+    uint8_t *srow, *sptr;
+    uint8_t *mrow, *mptr;
+    uint32_t *drow, *dptr;
+    unsigned xcount, ycount;
+
+    xp_error err;
+
+    width = src->bits->width;
+    height = src->bits->height;
+    hot_x = src->bits->xhot;
+    hot_y = src->bits->yhot;
+
+#ifdef ARGB_CURSOR
+    if (src->bits->argb != NULL)
+    {
+#if BITMAP_BIT_ORDER == MSBFirst
+        rowbytes = src->bits->width * sizeof (CARD32);
+        data = (uint32_t *) src->bits->argb;
+#else
+        const uint32_t *be_data=(uint32_t *) src->bits->argb;
+        unsigned i;
+        rowbytes = src->bits->width * sizeof (CARD32);
+        data=alloca (rowbytes * src->bits->height);
+        for(i=0;i<(src->bits->width*src->bits->height);i++)
+            data[i]=ntohl(be_data[i]);
+#endif
+    }
+    else
+#endif
+    {
+        fg_color = 0xFF00 | (src->foreRed >> 8);
+        fg_color <<= 16;
+        fg_color |= src->foreGreen & 0xFF00;
+        fg_color |= src->foreBlue >> 8;
+
+        bg_color = 0xFF00 | (src->backRed >> 8);
+        bg_color <<= 16;
+        bg_color |= src->backGreen & 0xFF00;
+        bg_color |= src->backBlue >> 8;
+
+        fg_color = htonl(fg_color);
+        bg_color = htonl(bg_color);
+
+        /* round up to 8 pixel boundary so we can convert whole bytes */
+        rowbytes = ((src->bits->width * 4) + 31) & ~31;
+        data = alloca(rowbytes * src->bits->height);
+
+        if (!src->bits->emptyMask)
+        {
+            ycount = src->bits->height;
+            srow = src->bits->source; mrow = src->bits->mask;
+            drow = data;
+
+            while (ycount-- > 0)
+            {
+                xcount = (src->bits->width + 7) / 8;
+                sptr = srow; mptr = mrow;
+                dptr = drow;
+
+                while (xcount-- > 0)
+                {
+                    uint8_t s, m;
+                    int i;
+
+                    s = *sptr++; m = *mptr++;
+                    for (i = 0; i < 8; i++)
+                    {
+#if BITMAP_BIT_ORDER == MSBFirst
+                        if (m & 128)
+                            *dptr++ = (s & 128) ? fg_color : bg_color;
+                        else
+                            *dptr++ = 0;
+                        s <<= 1; m <<= 1;
+#else
+                        if (m & 1)
+                            *dptr++ = (s & 1) ? fg_color : bg_color;
+                        else
+                            *dptr++ = 0;
+                        s >>= 1; m >>= 1;
+#endif
+                    }
+                }
+
+                srow += BitmapBytePad(src->bits->width);
+                mrow += BitmapBytePad(src->bits->width);
+                drow = (uint32_t *) ((char *) drow + rowbytes);
+            }
+        }
+        else
+        {
+            memset(data, 0, src->bits->height * rowbytes);
+        }
+    }
+
+    err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes);
+    return err == Success;
+}
+
+
+/*
+===========================================================================
+
+ Pointer sprite functions
+
+===========================================================================
+*/
+
+/*
+ * QuartzRealizeCursor
+ *  Convert the X cursor representation to native format if possible.
+ */
+static Bool
+QuartzRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
+{
+    if(pCursor == NULL || pCursor->bits == NULL)
+        return FALSE;
+
+    /* FIXME: cache ARGB8888 representation? */
+
+    return TRUE;
+}
+
+
+/*
+ * QuartzUnrealizeCursor
+ *  Free the storage space associated with a realized cursor.
+ */
+static Bool
+QuartzUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
+{
+    return TRUE;
+}
+
+
+/*
+ * QuartzSetCursor
+ *  Set the cursor sprite and position.
+ */
+static void
+QuartzSetCursor(ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
+{
+    QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+
+    if (!quartzServerVisible)
+        return;
+
+    if (pCursor == NULL)
+    {
+        if (ScreenPriv->cursorVisible)
+        {
+            xp_hide_cursor();
+            ScreenPriv->cursorVisible = FALSE;
+        }
+    }
+    else
+    {
+        load_cursor(pCursor, pScreen->myNum);
+
+        if (!ScreenPriv->cursorVisible)
+        {
+            xp_show_cursor();
+            ScreenPriv->cursorVisible = TRUE;
+        }
+    }
+}
+
+
+/*
+ * QuartzMoveCursor
+ *  Move the cursor. This is a noop for us.
+ */
+static void
+QuartzMoveCursor(ScreenPtr pScreen, int x, int y)
+{
+}
+
+
+static miPointerSpriteFuncRec quartzSpriteFuncsRec = {
+    QuartzRealizeCursor,
+    QuartzUnrealizeCursor,
+    QuartzSetCursor,
+    QuartzMoveCursor
+};
+
+
+/*
+===========================================================================
+
+ Pointer screen functions
+
+===========================================================================
+*/
+
+/*
+ * QuartzCursorOffScreen
+ */
+static Bool
+QuartzCursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
+{
+    return FALSE;
+}
+
+
+/*
+ * QuartzCrossScreen
+ */
+static void
+QuartzCrossScreen(ScreenPtr pScreen, Bool entering)
+{
+    return;
+}
+
+
+/*
+ * QuartzWarpCursor
+ *  Change the cursor position without generating an event or motion history.
+ *  The input coordinates (x,y) are in pScreen-local X11 coordinates.
+ *
+ */
+static void
+QuartzWarpCursor(ScreenPtr pScreen, int x, int y)
+{
+    static Bool neverMoved = TRUE;
+
+    if (neverMoved)
+    {
+        /* Don't move the cursor the first time. This is the
+           jump-to-center initialization, and it's annoying. */
+        neverMoved = FALSE;
+        return;
+    }
+
+    if (quartzServerVisible)
+    {
+        int sx, sy;
+
+        sx = dixScreenOrigins[pScreen->myNum].x + darwinMainScreenX;
+        sy = dixScreenOrigins[pScreen->myNum].y + darwinMainScreenY;
+
+        CGWarpMouseCursorPosition(CGPointMake(sx + x, sy + y));
+    }
+
+    miPointerWarpCursor(pScreen, x, y);
+    miPointerUpdate();
+}
+
+
+static miPointerScreenFuncRec quartzScreenFuncsRec = {
+    QuartzCursorOffScreen,
+    QuartzCrossScreen,
+    QuartzWarpCursor,
+    DarwinEQPointerPost,
+    DarwinEQSwitchScreen
+};
+
+
+/*
+===========================================================================
+
+ Other screen functions
+
+===========================================================================
+*/
+
+/*
+ * QuartzCursorQueryBestSize
+ *  Handle queries for best cursor size
+ */
+static void
+QuartzCursorQueryBestSize(int class, unsigned short *width,
+                          unsigned short *height, ScreenPtr pScreen)
+{
+    QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+
+    if (class == CursorShape)
+    {
+        /* FIXME: query window server? */
+        *width = 32;
+        *height = 32;
+    }
+    else
+    {
+        (*ScreenPriv->QueryBestSize)(class, width, height, pScreen);
+    }
+}
+
+/*
+ * QuartzInitCursor
+ *  Initialize cursor support
+ */
+Bool
+QuartzInitCursor(ScreenPtr pScreen)
+{
+    QuartzCursorScreenPtr ScreenPriv;
+    miPointerScreenPtr PointPriv;
+
+    /* initialize software cursor handling (always needed as backup) */
+    if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
+        return FALSE;
+
+    /* allocate private storage for this screen's QuickDraw cursor info */
+    if (darwinCursorGeneration != serverGeneration)
+    {
+        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
+            return FALSE;
+
+        darwinCursorGeneration = serverGeneration;
+    }
+
+    ScreenPriv = xcalloc(1, sizeof(QuartzCursorScreenRec));
+    if (ScreenPriv == NULL)
+        return FALSE;
+
+    /* CURSOR_PRIV(pScreen) = ScreenPriv; */
+    pScreen->devPrivates[darwinCursorScreenIndex].ptr = ScreenPriv;
+
+    /* override some screen procedures */
+    ScreenPriv->QueryBestSize = pScreen->QueryBestSize;
+    pScreen->QueryBestSize = QuartzCursorQueryBestSize;
+
+    PointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr;
+
+    ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
+    PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
+
+    ScreenPriv->cursorVisible = TRUE;
+    return TRUE;
+}
+
+
+/*
+ * QuartzSuspendXCursor
+ *  X server is hiding. Restore the Aqua cursor.
+ */
+void
+QuartzSuspendXCursor(ScreenPtr pScreen)
+{
+}
+
+
+/*
+ * QuartzResumeXCursor
+ *  X server is showing. Restore the X cursor.
+ */
+void
+QuartzResumeXCursor(ScreenPtr pScreen, int x, int y)
+{
+    WindowPtr pWin;
+    CursorPtr pCursor;
+
+    pWin = GetSpriteWindow();
+    if (pWin->drawable.pScreen != pScreen)
+        return;
+
+    pCursor = GetSpriteCursor();
+    if (pCursor == NULL)
+        return;
+
+    QuartzSetCursor(pScreen, pCursor, x, y);
+}
diff --git a/hw/darwin/quartz/xpr/xprFrame.c b/hw/darwin/quartz/xpr/xprFrame.c
new file mode 100644
index 0000000..3245da0
--- /dev/null
+++ b/hw/darwin/quartz/xpr/xprFrame.c
@@ -0,0 +1,538 @@
+/*
+ * Xplugin rootless implementation frame functions
+ *
+ * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003 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 <unistd.h>
+#include "xpr.h"
+#include "rootlessCommon.h"
+#include "Xplugin.h"
+#include "x-hash.h"
+#include "x-list.h"
+#include "quartz/applewmExt.h"
+
+#include "propertyst.h"
+#include "dix.h"
+#include <X11/Xatom.h>
+#include "windowstr.h"
+
+#include <pthread.h>
+
+#define DEFINE_ATOM_HELPER(func,atom_name)                      \
+static Atom func (void) {                                       \
+    static int generation;                                      \
+    static Atom atom;                                           \
+    if (generation != serverGeneration) {                       \
+        generation = serverGeneration;                          \
+        atom = MakeAtom (atom_name, strlen (atom_name), TRUE);  \
+    }                                                           \
+    return atom;                                                \
+}
+
+DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
+
+/* Maps xp_window_id -> RootlessWindowRec */
+static x_hash_table *window_hash;
+static pthread_mutex_t window_hash_mutex;
+
+static Bool no_configure_window;
+
+
+static inline xp_error
+xprConfigureWindow(xp_window_id id, unsigned int mask,
+                   const xp_window_changes *values)
+{
+  //  ErrorF("xprConfigureWindow()\n");
+    if (!no_configure_window)
+        return xp_configure_window(id, mask, values);
+    else
+        return XP_Success;
+}
+
+
+static void
+xprSetNativeProperty(RootlessWindowPtr pFrame)
+{
+    xp_error err;
+    unsigned int native_id;
+    long data;
+
+    err = xp_get_native_window((xp_window_id) pFrame->wid, &native_id);
+    if (err == Success)
+    {
+        /* FIXME: move this to AppleWM extension */
+
+        data = native_id;
+        ChangeWindowProperty(pFrame->win, xa_native_window_id(),
+                             XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
+    }
+}
+
+
+/*
+ * Create and display a new frame.
+ */
+Bool
+xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
+               int newX, int newY, RegionPtr pShape)
+{
+    WindowPtr pWin = pFrame->win;
+    xp_window_changes wc;
+    unsigned int mask = 0;
+    xp_error err;
+
+    wc.x = newX;
+    wc.y = newY;
+    wc.width = pFrame->width;
+    wc.height = pFrame->height;
+    wc.bit_gravity = XP_GRAVITY_NONE;
+    mask |= XP_BOUNDS;
+
+    if (pWin->drawable.depth == 8)
+    {
+        wc.depth = XP_DEPTH_INDEX8;
+#if 0
+        wc.colormap = xprColormapCallback;
+        wc.colormap_data = pScreen;
+        mask |= XP_COLORMAP;
+#endif
+    }
+    else if (pWin->drawable.depth == 15)
+        wc.depth = XP_DEPTH_RGB555;
+    else if (pWin->drawable.depth == 24)
+        wc.depth = XP_DEPTH_ARGB8888;
+    else
+        wc.depth = XP_DEPTH_NIL;
+    mask |= XP_DEPTH;
+
+    if (pShape != NULL)
+    {
+        wc.shape_nrects = REGION_NUM_RECTS(pShape);
+        wc.shape_rects = REGION_RECTS(pShape);
+        wc.shape_tx = wc.shape_ty = 0;
+        mask |= XP_SHAPE;
+    }
+
+    err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid);
+
+    if (err != Success)
+    {
+        return FALSE;
+    }
+
+    if (window_hash == NULL)
+    {
+        window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
+        pthread_mutex_init(&window_hash_mutex, NULL);
+    }
+
+    pthread_mutex_lock(&window_hash_mutex);
+    x_hash_table_insert(window_hash, pFrame->wid, pFrame);
+    pthread_mutex_unlock(&window_hash_mutex);
+
+    xprSetNativeProperty(pFrame);
+
+    return TRUE;
+}
+
+
+/*
+ * Destroy a frame.
+ */
+void
+xprDestroyFrame(RootlessFrameID wid)
+{
+    pthread_mutex_lock(&window_hash_mutex);
+    x_hash_table_remove(window_hash, wid);
+    pthread_mutex_unlock(&window_hash_mutex);
+
+    xp_destroy_window((xp_window_id) wid);
+}
+
+
+/*
+ * Move a frame on screen.
+ */
+void
+xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
+{
+    xp_window_changes wc;
+
+    wc.x = newX;
+    wc.y = newY;
+    //    ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, newY);
+    xprConfigureWindow((xp_window_id) wid, XP_ORIGIN, &wc);
+}
+
+
+/*
+ * Resize and move a frame.
+ */
+void
+xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
+               int newX, int newY, unsigned int newW, unsigned int newH,
+               unsigned int gravity)
+{
+    xp_window_changes wc;
+
+    wc.x = newX;
+    wc.y = newY;
+    wc.width = newW;
+    wc.height = newH;
+    wc.bit_gravity = gravity;
+
+    /* It's unlikely that being async will save us anything here.
+       But it can't hurt. */
+
+    xprConfigureWindow((xp_window_id) wid, XP_BOUNDS, &wc);
+}
+
+
+/*
+ * Change frame stacking.
+ */
+void
+xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid)
+{
+    xp_window_changes wc;
+
+    /* Stack frame below nextWid it if it exists, or raise
+       frame above everything otherwise. */
+
+    if (nextWid == NULL)
+    {
+        wc.stack_mode = XP_MAPPED_ABOVE;
+        wc.sibling = 0;
+    }
+    else
+    {
+        wc.stack_mode = XP_MAPPED_BELOW;
+        wc.sibling = (xp_window_id) nextWid;
+    }
+
+    xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
+}
+
+
+/*
+ * Change the frame's shape.
+ */
+void
+xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
+{
+    xp_window_changes wc;
+
+    if (pShape != NULL)
+    {
+        wc.shape_nrects = REGION_NUM_RECTS(pShape);
+        wc.shape_rects = REGION_RECTS(pShape);
+    }
+    else
+    {
+        wc.shape_nrects = -1;
+        wc.shape_rects = NULL;
+    }
+
+    wc.shape_tx = wc.shape_ty = 0;
+
+    xprConfigureWindow((xp_window_id) wid, XP_SHAPE, &wc);
+}
+
+
+/*
+ * Unmap a frame.
+ */
+void
+xprUnmapFrame(RootlessFrameID wid)
+{
+    xp_window_changes wc;
+
+    wc.stack_mode = XP_UNMAPPED;
+    wc.sibling = 0;
+
+    xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
+}
+
+
+/*
+ * Start drawing to a frame.
+ *  Prepare for direct access to its backing buffer.
+ */
+void
+xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
+{
+    void *data[2];
+    unsigned int rowbytes[2];
+    xp_error err;
+
+    err = xp_lock_window((xp_window_id) wid, NULL, NULL, data, rowbytes, NULL);
+    if (err != Success)
+        FatalError("Could not lock window %i for drawing.", (int) wid);
+
+    *pixelData = data[0];
+    *bytesPerRow = rowbytes[0];
+}
+
+
+/*
+ * Stop drawing to a frame.
+ */
+void
+xprStopDrawing(RootlessFrameID wid, Bool flush)
+{
+    xp_unlock_window((xp_window_id) wid, flush);
+}
+
+
+/*
+ * Flush drawing updates to the screen.
+ */
+void
+xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
+{
+    xp_flush_window((xp_window_id) wid);
+}
+
+
+/*
+ * Mark damaged rectangles as requiring redisplay to screen.
+ */
+void
+xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
+               int shift_x, int shift_y)
+{
+    xp_mark_window((xp_window_id) wid, nrects, rects, shift_x, shift_y);
+}
+
+
+/*
+ * Called after the window associated with a frame has been switched
+ * to a new top-level parent.
+ */
+void
+xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
+{
+    DeleteProperty(oldWin, xa_native_window_id());
+
+    xprSetNativeProperty(pFrame);
+}
+
+
+/*
+ * Called to check if the frame should be reordered when it is restacked.
+ */
+Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
+{
+    WindowPtr pWin = pFrame->win;
+
+    return AppleWMDoReorderWindow(pWin);
+}
+
+
+/*
+ * Copy area in frame to another part of frame.
+ *  Used to accelerate scrolling.
+ */
+void
+xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
+              int dx, int dy)
+{
+    xp_copy_window((xp_window_id) wid, (xp_window_id) wid,
+                   dstNrects, dstRects, dx, dy);
+}
+
+
+static RootlessFrameProcsRec xprRootlessProcs = {
+    xprCreateFrame,
+    xprDestroyFrame,
+    xprMoveFrame,
+    xprResizeFrame,
+    xprRestackFrame,
+    xprReshapeFrame,
+    xprUnmapFrame,
+    xprStartDrawing,
+    xprStopDrawing,
+    xprUpdateRegion,
+    xprDamageRects,
+    xprSwitchWindow,
+    xprDoReorderWindow,
+    xp_copy_bytes,
+    xp_fill_bytes,
+    xp_composite_pixels,
+    xprCopyWindow
+};
+
+
+/*
+ * Initialize XPR implementation
+ */
+Bool
+xprInit(ScreenPtr pScreen)
+{
+    RootlessInit(pScreen, &xprRootlessProcs);
+
+    if(!access("/tmp/disable_fb.txt", F_OK)) {
+      // always use the xp functions, dammit
+      fprintf(stderr,"setting rootless thresholds to zero to disable fb usage\n");
+      rootless_CopyBytes_threshold = 0;
+      rootless_FillBytes_threshold = 0;
+      rootless_CompositePixels_threshold = 0;
+      rootless_CopyWindow_threshold = 0;
+    } else {
+      rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
+      rootless_FillBytes_threshold = xp_fill_bytes_threshold;
+      rootless_CompositePixels_threshold = xp_composite_area_threshold;
+      rootless_CopyWindow_threshold = xp_scroll_area_threshold;
+    }
+
+    no_configure_window = FALSE;
+
+    return TRUE;
+}
+
+
+/*
+ * Given the id of a physical window, try to find the top-level (or root)
+ * X window that it represents.
+ */
+WindowPtr
+xprGetXWindow(xp_window_id wid)
+{
+    RootlessWindowRec *winRec;
+
+    if (window_hash == NULL)
+        return NULL;
+
+    winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
+
+    return winRec != NULL ? winRec->win : NULL;
+}
+
+/*
+ * Given the id of a physical window, try to find the top-level (or root)
+ * X window that it represents.
+ */
+WindowPtr
+xprGetXWindowFromAppKit(int windowNumber)
+{
+    RootlessWindowRec *winRec;
+    Bool ret;
+    xp_window_id wid;
+
+    if (window_hash == NULL)
+        return FALSE;
+
+    /* need to lock, since this function can be called by any thread */
+
+    pthread_mutex_lock(&window_hash_mutex);
+
+    if (xp_lookup_native_window(windowNumber, &wid))
+        ret = xprGetXWindow(wid) != NULL;
+    else
+        ret = FALSE;
+
+    pthread_mutex_unlock(&window_hash_mutex);
+
+    if (!ret) return NULL;
+    winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
+
+    return winRec != NULL ? winRec->win : NULL;
+}
+
+
+/*
+ * The windowNumber is an AppKit window number. Returns TRUE if xpr is
+ * displaying a window with that number.
+ */
+Bool
+xprIsX11Window(void *nsWindow, int windowNumber)
+{
+    Bool ret;
+    xp_window_id wid;
+
+    if (window_hash == NULL)
+        return FALSE;
+
+    /* need to lock, since this function can be called by any thread */
+
+    pthread_mutex_lock(&window_hash_mutex);
+
+    if (xp_lookup_native_window(windowNumber, &wid))
+        ret = xprGetXWindow(wid) != NULL;
+    else
+        ret = FALSE;
+
+    pthread_mutex_unlock(&window_hash_mutex);
+
+    return ret;
+}
+
+
+/*
+ * xprHideWindows
+ *  Hide or unhide all top level windows. This is called for application hide/
+ *  unhide events if the window manager is not Apple-WM aware. Xplugin windows
+ *  do not hide or unhide themselves.
+ */
+void
+xprHideWindows(Bool hide)
+{
+    int screen;
+    WindowPtr pRoot, pWin;
+
+    for (screen = 0; screen < screenInfo.numScreens; screen++) {
+        pRoot = WindowTable[screenInfo.screens[screen]->myNum];
+        RootlessFrameID prevWid = NULL;
+
+        for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib) {
+            RootlessWindowRec *winRec = WINREC(pWin);
+
+            if (winRec != NULL) {
+                if (hide) {
+                    xprUnmapFrame(winRec->wid);
+                } else {
+                    BoxRec box;
+
+                    xprRestackFrame(winRec->wid, prevWid);
+                    prevWid = winRec->wid;
+
+                    box.x1 = 0;
+                    box.y1 = 0;
+                    box.x2 = winRec->width;
+                    box.y2 = winRec->height;
+
+                    xprDamageRects(winRec->wid, 1, &box, 0, 0);
+                    RootlessQueueRedisplay(screenInfo.screens[screen]);
+                }
+            }
+        }
+    }
+}
diff --git a/hw/darwin/quartz/xpr/xprScreen.c b/hw/darwin/quartz/xpr/xprScreen.c
new file mode 100644
index 0000000..13bff50
--- /dev/null
+++ b/hw/darwin/quartz/xpr/xprScreen.c
@@ -0,0 +1,416 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "quartz/quartzCommon.h"
+#include "quartz/quartz.h"
+#include "xpr.h"
+#include "quartz/pseudoramiX.h"
+#include "darwin.h"
+#include "rootless.h"
+#include "safeAlpha/safeAlpha.h"
+#include "dri.h"
+#include "globals.h"
+#include "Xplugin.h"
+#include "quartz/applewmExt.h"
+
+// From xprFrame.c
+WindowPtr xprGetXWindow(xp_window_id wid);
+
+#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");
+      QuartzMessageServerThread(kXDarwinDisplayChanged, 0);
+      break;
+
+    case XP_EVENT_WINDOW_STATE_CHANGED:
+      DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED\n");
+      if (arg_size >= sizeof(xp_window_state_event)) {
+	const xp_window_state_event *ws_arg = arg;
+	
+	QuartzMessageServerThread(kXDarwinWindowState, 2,
+				  ws_arg->id, ws_arg->state);
+      }
+      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;
+	WindowPtr pWin = xprGetXWindow(id);
+	QuartzMessageServerThread(kXDarwinWindowMoved, 1, pWin);
+      }
+      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;
+    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);
+
+    /* Remove menubar to help standard X11 window managers. */
+
+    if (frame.origin.x == 0 && frame.origin.y == 0)
+    {
+        frame.origin.y += aquaMenuBarHeight;
+        frame.size.height -= aquaMenuBarHeight;
+    }
+
+    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;
+
+    /* Tell PseudoramiX about the real screens. */
+    for (i = 0; i < displayCount; i++)
+    {
+        CGDirectDisplayID dpy = displayList[i];
+
+        frame = displayScreenBounds(dpy);
+
+	/*        ErrorF("PseudoramiX screen %d added: %dx%d @ (%d,%d).\n", i,
+               (int)frame.size.width, (int)frame.size.height,
+               (int)frame.origin.x, (int)frame.origin.y); */
+
+        frame.origin.x -= unionRect.origin.x;
+        frame.origin.y -= unionRect.origin.y;
+
+	/*        ErrorF("PseudoramiX screen %d placed at X11 coordinate (%d,%d).\n",
+		  i, (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;
+
+    //    ErrorF("Display mode: Rootless Quartz -- Xplugin implementation\n");
+
+    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
+                     | XP_EVENT_SURFACE_CHANGED
+                     | XP_EVENT_SURFACE_DESTROYED,
+                     eventHandler, NULL);
+
+    AppleDRIExtensionInit();
+    xprAppleWMInit();
+}
+
+/*
+ * xprAddScreen
+ *  Init the framebuffer and record pixmap parameters for the screen.
+ */
+static Bool
+xprAddScreen(int index, ScreenPtr pScreen)
+{
+    DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
+
+    /* If no specific depth chosen, look for the depth of the main display.
+       Else if 16bpp specified, use that. Else use 32bpp. */
+
+    dfb->colorType = TrueColor;
+    dfb->bitsPerComponent = 8;
+    dfb->bitsPerPixel = 32;
+    dfb->colorBitsPerPixel = 24;
+
+    if (darwinDesiredDepth == -1)
+    {
+        dfb->bitsPerComponent = CGDisplayBitsPerSample(kCGDirectMainDisplay);
+        dfb->bitsPerPixel = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
+        dfb->colorBitsPerPixel =
+                CGDisplaySamplesPerPixel(kCGDirectMainDisplay) *
+                dfb->bitsPerComponent;
+    }
+    else if (darwinDesiredDepth == 15)
+    {
+        dfb->bitsPerComponent = 5;
+        dfb->bitsPerPixel = 16;
+        dfb->colorBitsPerPixel = 15;
+    }
+    else if (darwinDesiredDepth == 8)
+    {
+        dfb->colorType = PseudoColor;
+        dfb->bitsPerComponent = 8;
+        dfb->bitsPerPixel = 8;
+        dfb->colorBitsPerPixel = 8;
+    }
+
+    if (noPseudoramiXExtension)
+    {
+        CGDirectDisplayID dpy;
+        CGRect frame;
+
+        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)
+{
+    // Add alpha protecting replacements for fb screen functions
+    pScreen->PaintWindowBackground = SafeAlphaPaintWindow;
+    pScreen->PaintWindowBorder = SafeAlphaPaintWindow;
+
+#ifdef RENDER
+    {
+        PictureScreenPtr ps = GetPictureScreen(pScreen);
+        ps->Composite = SafeAlphaComposite;
+    }
+#endif /* RENDER */
+
+    // Initialize accelerated rootless drawing
+    // Note that this must be done before DamageSetup().
+    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,
+    NULL,               // No need to update cursor
+    QuartzSuspendXCursor,
+    QuartzResumeXCursor,
+    NULL,               // No capture or release in rootless mode
+    NULL,
+    NULL,               // Xplugin sends screen change events directly
+    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;
+}
diff --git a/hw/darwin/quartz/xprAppleWM.c b/hw/darwin/quartz/xprAppleWM.c
deleted file mode 100644
index 5539c51..0000000
--- a/hw/darwin/quartz/xprAppleWM.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Xplugin rootless implementation functions for AppleWM extension
- *
- * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
- * Copyright (c) 2003 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 "xpr.h"
-#include "quartz/applewmExt.h"
-#include "rootless.h"
-#include "Xplugin.h"
-#include <X11/X.h>
-
-static int xprSetWindowLevel(
-    WindowPtr pWin,
-    int level)
-{
-    xp_window_id wid;
-    xp_window_changes wc;
-
-    wid = (xp_window_id) RootlessFrameForWindow (pWin, TRUE);
-    if (wid == 0)
-        return BadWindow;
-
-    RootlessStopDrawing (pWin, FALSE);
-
-    wc.window_level = level;
-    if (xp_configure_window (wid, XP_WINDOW_LEVEL, &wc) != Success) {
-        return BadValue;
-    }
-
-    return Success;
-}
-
-
-static int xprFrameDraw(
-    WindowPtr pWin,
-    int class,
-    unsigned int attr,
-    const BoxRec *outer,
-    const BoxRec *inner,
-    unsigned int title_len,
-    const unsigned char *title_bytes)
-{
-    xp_window_id wid;
-
-    wid = (xp_window_id) RootlessFrameForWindow (pWin, FALSE);
-    if (wid == 0)
-        return BadWindow;
-
-    if (xp_frame_draw (wid, class, attr, outer, inner,
-                       title_len, title_bytes) != Success)
-    {
-        return BadValue;
-    }
-
-    return Success;
-}
-
-
-static AppleWMProcsRec xprAppleWMProcs = {
-    xp_disable_update,
-    xp_reenable_update,
-    xprSetWindowLevel,
-    xp_frame_get_rect,
-    xp_frame_hit_test,
-    xprFrameDraw
-};
-
-
-void xprAppleWMInit(void)
-{
-    AppleWMExtensionInit(&xprAppleWMProcs);
-}
diff --git a/hw/darwin/quartz/xprCursor.c b/hw/darwin/quartz/xprCursor.c
deleted file mode 100644
index 160b5d9..0000000
--- a/hw/darwin/quartz/xprCursor.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/**************************************************************
- *
- * Xplugin cursor support
- *
- * Copyright (c) 2001 Torrey T. Lyons and Greg Parker.
- * Copyright (c) 2002 Apple Computer, Inc.
- *                 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 "quartz/quartzCommon.h"
-#include "xpr.h"
-#include "darwin.h"
-#include "Xplugin.h"
-
-#include "mi.h"
-#include "scrnintstr.h"
-#include "cursorstr.h"
-#include "mipointrst.h"
-#include "windowstr.h"
-#include "globals.h"
-#include "servermd.h"
-#include "dixevents.h"
-
-typedef struct {
-    int                     cursorVisible;
-    QueryBestSizeProcPtr    QueryBestSize;
-    miPointerSpriteFuncPtr  spriteFuncs;
-} QuartzCursorScreenRec, *QuartzCursorScreenPtr;
-
-static int darwinCursorScreenIndex = -1;
-static unsigned long darwinCursorGeneration = 0;
-
-#define CURSOR_PRIV(pScreen) \
-    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
-
-
-static Bool
-load_cursor(CursorPtr src, int screen)
-{
-    uint32_t *data;
-    uint32_t rowbytes;
-    int width, height;
-    int hot_x, hot_y;
-
-    uint32_t fg_color, bg_color;
-    uint8_t *srow, *sptr;
-    uint8_t *mrow, *mptr;
-    uint32_t *drow, *dptr;
-    unsigned xcount, ycount;
-
-    xp_error err;
-
-    width = src->bits->width;
-    height = src->bits->height;
-    hot_x = src->bits->xhot;
-    hot_y = src->bits->yhot;
-
-#ifdef ARGB_CURSOR
-    if (src->bits->argb != NULL)
-    {
-#if BITMAP_BIT_ORDER == MSBFirst
-        rowbytes = src->bits->width * sizeof (CARD32);
-        data = (uint32_t *) src->bits->argb;
-#else
-        const uint32_t *be_data=(uint32_t *) src->bits->argb;
-        unsigned i;
-        rowbytes = src->bits->width * sizeof (CARD32);
-        data=alloca (rowbytes * src->bits->height);
-        for(i=0;i<(src->bits->width*src->bits->height);i++)
-            data[i]=ntohl(be_data[i]);
-#endif
-    }
-    else
-#endif
-    {
-        fg_color = 0xFF00 | (src->foreRed >> 8);
-        fg_color <<= 16;
-        fg_color |= src->foreGreen & 0xFF00;
-        fg_color |= src->foreBlue >> 8;
-
-        bg_color = 0xFF00 | (src->backRed >> 8);
-        bg_color <<= 16;
-        bg_color |= src->backGreen & 0xFF00;
-        bg_color |= src->backBlue >> 8;
-
-        fg_color = htonl(fg_color);
-        bg_color = htonl(bg_color);
-
-        /* round up to 8 pixel boundary so we can convert whole bytes */
-        rowbytes = ((src->bits->width * 4) + 31) & ~31;
-        data = alloca(rowbytes * src->bits->height);
-
-        if (!src->bits->emptyMask)
-        {
-            ycount = src->bits->height;
-            srow = src->bits->source; mrow = src->bits->mask;
-            drow = data;
-
-            while (ycount-- > 0)
-            {
-                xcount = (src->bits->width + 7) / 8;
-                sptr = srow; mptr = mrow;
-                dptr = drow;
-
-                while (xcount-- > 0)
-                {
-                    uint8_t s, m;
-                    int i;
-
-                    s = *sptr++; m = *mptr++;
-                    for (i = 0; i < 8; i++)
-                    {
-#if BITMAP_BIT_ORDER == MSBFirst
-                        if (m & 128)
-                            *dptr++ = (s & 128) ? fg_color : bg_color;
-                        else
-                            *dptr++ = 0;
-                        s <<= 1; m <<= 1;
-#else
-                        if (m & 1)
-                            *dptr++ = (s & 1) ? fg_color : bg_color;
-                        else
-                            *dptr++ = 0;
-                        s >>= 1; m >>= 1;
-#endif
-                    }
-                }
-
-                srow += BitmapBytePad(src->bits->width);
-                mrow += BitmapBytePad(src->bits->width);
-                drow = (uint32_t *) ((char *) drow + rowbytes);
-            }
-        }
-        else
-        {
-            memset(data, 0, src->bits->height * rowbytes);
-        }
-    }
-
-    err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes);
-    return err == Success;
-}
-
-
-/*
-===========================================================================
-
- Pointer sprite functions
-
-===========================================================================
-*/
-
-/*
- * QuartzRealizeCursor
- *  Convert the X cursor representation to native format if possible.
- */
-static Bool
-QuartzRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
-{
-    if(pCursor == NULL || pCursor->bits == NULL)
-        return FALSE;
-
-    /* FIXME: cache ARGB8888 representation? */
-
-    return TRUE;
-}
-
-
-/*
- * QuartzUnrealizeCursor
- *  Free the storage space associated with a realized cursor.
- */
-static Bool
-QuartzUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
-{
-    return TRUE;
-}
-
-
-/*
- * QuartzSetCursor
- *  Set the cursor sprite and position.
- */
-static void
-QuartzSetCursor(ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
-{
-    QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
-
-    if (!quartzServerVisible)
-        return;
-
-    if (pCursor == NULL)
-    {
-        if (ScreenPriv->cursorVisible)
-        {
-            xp_hide_cursor();
-            ScreenPriv->cursorVisible = FALSE;
-        }
-    }
-    else
-    {
-        load_cursor(pCursor, pScreen->myNum);
-
-        if (!ScreenPriv->cursorVisible)
-        {
-            xp_show_cursor();
-            ScreenPriv->cursorVisible = TRUE;
-        }
-    }
-}
-
-
-/*
- * QuartzMoveCursor
- *  Move the cursor. This is a noop for us.
- */
-static void
-QuartzMoveCursor(ScreenPtr pScreen, int x, int y)
-{
-}
-
-
-static miPointerSpriteFuncRec quartzSpriteFuncsRec = {
-    QuartzRealizeCursor,
-    QuartzUnrealizeCursor,
-    QuartzSetCursor,
-    QuartzMoveCursor
-};
-
-
-/*
-===========================================================================
-
- Pointer screen functions
-
-===========================================================================
-*/
-
-/*
- * QuartzCursorOffScreen
- */
-static Bool
-QuartzCursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
-{
-    return FALSE;
-}
-
-
-/*
- * QuartzCrossScreen
- */
-static void
-QuartzCrossScreen(ScreenPtr pScreen, Bool entering)
-{
-    return;
-}
-
-
-/*
- * QuartzWarpCursor
- *  Change the cursor position without generating an event or motion history.
- *  The input coordinates (x,y) are in pScreen-local X11 coordinates.
- *
- */
-static void
-QuartzWarpCursor(ScreenPtr pScreen, int x, int y)
-{
-    static Bool neverMoved = TRUE;
-
-    if (neverMoved)
-    {
-        /* Don't move the cursor the first time. This is the
-           jump-to-center initialization, and it's annoying. */
-        neverMoved = FALSE;
-        return;
-    }
-
-    if (quartzServerVisible)
-    {
-        int sx, sy;
-
-        sx = dixScreenOrigins[pScreen->myNum].x + darwinMainScreenX;
-        sy = dixScreenOrigins[pScreen->myNum].y + darwinMainScreenY;
-
-        CGWarpMouseCursorPosition(CGPointMake(sx + x, sy + y));
-    }
-
-    miPointerWarpCursor(pScreen, x, y);
-    miPointerUpdate();
-}
-
-
-static miPointerScreenFuncRec quartzScreenFuncsRec = {
-    QuartzCursorOffScreen,
-    QuartzCrossScreen,
-    QuartzWarpCursor,
-    DarwinEQPointerPost,
-    DarwinEQSwitchScreen
-};
-
-
-/*
-===========================================================================
-
- Other screen functions
-
-===========================================================================
-*/
-
-/*
- * QuartzCursorQueryBestSize
- *  Handle queries for best cursor size
- */
-static void
-QuartzCursorQueryBestSize(int class, unsigned short *width,
-                          unsigned short *height, ScreenPtr pScreen)
-{
-    QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
-
-    if (class == CursorShape)
-    {
-        /* FIXME: query window server? */
-        *width = 32;
-        *height = 32;
-    }
-    else
-    {
-        (*ScreenPriv->QueryBestSize)(class, width, height, pScreen);
-    }
-}
-
-/*
- * QuartzInitCursor
- *  Initialize cursor support
- */
-Bool
-QuartzInitCursor(ScreenPtr pScreen)
-{
-    QuartzCursorScreenPtr ScreenPriv;
-    miPointerScreenPtr PointPriv;
-
-    /* initialize software cursor handling (always needed as backup) */
-    if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
-        return FALSE;
-
-    /* allocate private storage for this screen's QuickDraw cursor info */
-    if (darwinCursorGeneration != serverGeneration)
-    {
-        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-
-        darwinCursorGeneration = serverGeneration;
-    }
-
-    ScreenPriv = xcalloc(1, sizeof(QuartzCursorScreenRec));
-    if (ScreenPriv == NULL)
-        return FALSE;
-
-    /* CURSOR_PRIV(pScreen) = ScreenPriv; */
-    pScreen->devPrivates[darwinCursorScreenIndex].ptr = ScreenPriv;
-
-    /* override some screen procedures */
-    ScreenPriv->QueryBestSize = pScreen->QueryBestSize;
-    pScreen->QueryBestSize = QuartzCursorQueryBestSize;
-
-    PointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr;
-
-    ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
-    PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
-
-    ScreenPriv->cursorVisible = TRUE;
-    return TRUE;
-}
-
-
-/*
- * QuartzSuspendXCursor
- *  X server is hiding. Restore the Aqua cursor.
- */
-void
-QuartzSuspendXCursor(ScreenPtr pScreen)
-{
-}
-
-
-/*
- * QuartzResumeXCursor
- *  X server is showing. Restore the X cursor.
- */
-void
-QuartzResumeXCursor(ScreenPtr pScreen, int x, int y)
-{
-    WindowPtr pWin;
-    CursorPtr pCursor;
-
-    pWin = GetSpriteWindow();
-    if (pWin->drawable.pScreen != pScreen)
-        return;
-
-    pCursor = GetSpriteCursor();
-    if (pCursor == NULL)
-        return;
-
-    QuartzSetCursor(pScreen, pCursor, x, y);
-}
diff --git a/hw/darwin/quartz/xprFrame.c b/hw/darwin/quartz/xprFrame.c
deleted file mode 100644
index 3245da0..0000000
--- a/hw/darwin/quartz/xprFrame.c
+++ /dev/null
@@ -1,538 +0,0 @@
-/*
- * Xplugin rootless implementation frame functions
- *
- * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
- * Copyright (c) 2003 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 <unistd.h>
-#include "xpr.h"
-#include "rootlessCommon.h"
-#include "Xplugin.h"
-#include "x-hash.h"
-#include "x-list.h"
-#include "quartz/applewmExt.h"
-
-#include "propertyst.h"
-#include "dix.h"
-#include <X11/Xatom.h>
-#include "windowstr.h"
-
-#include <pthread.h>
-
-#define DEFINE_ATOM_HELPER(func,atom_name)                      \
-static Atom func (void) {                                       \
-    static int generation;                                      \
-    static Atom atom;                                           \
-    if (generation != serverGeneration) {                       \
-        generation = serverGeneration;                          \
-        atom = MakeAtom (atom_name, strlen (atom_name), TRUE);  \
-    }                                                           \
-    return atom;                                                \
-}
-
-DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
-
-/* Maps xp_window_id -> RootlessWindowRec */
-static x_hash_table *window_hash;
-static pthread_mutex_t window_hash_mutex;
-
-static Bool no_configure_window;
-
-
-static inline xp_error
-xprConfigureWindow(xp_window_id id, unsigned int mask,
-                   const xp_window_changes *values)
-{
-  //  ErrorF("xprConfigureWindow()\n");
-    if (!no_configure_window)
-        return xp_configure_window(id, mask, values);
-    else
-        return XP_Success;
-}
-
-
-static void
-xprSetNativeProperty(RootlessWindowPtr pFrame)
-{
-    xp_error err;
-    unsigned int native_id;
-    long data;
-
-    err = xp_get_native_window((xp_window_id) pFrame->wid, &native_id);
-    if (err == Success)
-    {
-        /* FIXME: move this to AppleWM extension */
-
-        data = native_id;
-        ChangeWindowProperty(pFrame->win, xa_native_window_id(),
-                             XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
-    }
-}
-
-
-/*
- * Create and display a new frame.
- */
-Bool
-xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
-               int newX, int newY, RegionPtr pShape)
-{
-    WindowPtr pWin = pFrame->win;
-    xp_window_changes wc;
-    unsigned int mask = 0;
-    xp_error err;
-
-    wc.x = newX;
-    wc.y = newY;
-    wc.width = pFrame->width;
-    wc.height = pFrame->height;
-    wc.bit_gravity = XP_GRAVITY_NONE;
-    mask |= XP_BOUNDS;
-
-    if (pWin->drawable.depth == 8)
-    {
-        wc.depth = XP_DEPTH_INDEX8;
-#if 0
-        wc.colormap = xprColormapCallback;
-        wc.colormap_data = pScreen;
-        mask |= XP_COLORMAP;
-#endif
-    }
-    else if (pWin->drawable.depth == 15)
-        wc.depth = XP_DEPTH_RGB555;
-    else if (pWin->drawable.depth == 24)
-        wc.depth = XP_DEPTH_ARGB8888;
-    else
-        wc.depth = XP_DEPTH_NIL;
-    mask |= XP_DEPTH;
-
-    if (pShape != NULL)
-    {
-        wc.shape_nrects = REGION_NUM_RECTS(pShape);
-        wc.shape_rects = REGION_RECTS(pShape);
-        wc.shape_tx = wc.shape_ty = 0;
-        mask |= XP_SHAPE;
-    }
-
-    err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid);
-
-    if (err != Success)
-    {
-        return FALSE;
-    }
-
-    if (window_hash == NULL)
-    {
-        window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
-        pthread_mutex_init(&window_hash_mutex, NULL);
-    }
-
-    pthread_mutex_lock(&window_hash_mutex);
-    x_hash_table_insert(window_hash, pFrame->wid, pFrame);
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    xprSetNativeProperty(pFrame);
-
-    return TRUE;
-}
-
-
-/*
- * Destroy a frame.
- */
-void
-xprDestroyFrame(RootlessFrameID wid)
-{
-    pthread_mutex_lock(&window_hash_mutex);
-    x_hash_table_remove(window_hash, wid);
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    xp_destroy_window((xp_window_id) wid);
-}
-
-
-/*
- * Move a frame on screen.
- */
-void
-xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
-{
-    xp_window_changes wc;
-
-    wc.x = newX;
-    wc.y = newY;
-    //    ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, newY);
-    xprConfigureWindow((xp_window_id) wid, XP_ORIGIN, &wc);
-}
-
-
-/*
- * Resize and move a frame.
- */
-void
-xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
-               int newX, int newY, unsigned int newW, unsigned int newH,
-               unsigned int gravity)
-{
-    xp_window_changes wc;
-
-    wc.x = newX;
-    wc.y = newY;
-    wc.width = newW;
-    wc.height = newH;
-    wc.bit_gravity = gravity;
-
-    /* It's unlikely that being async will save us anything here.
-       But it can't hurt. */
-
-    xprConfigureWindow((xp_window_id) wid, XP_BOUNDS, &wc);
-}
-
-
-/*
- * Change frame stacking.
- */
-void
-xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid)
-{
-    xp_window_changes wc;
-
-    /* Stack frame below nextWid it if it exists, or raise
-       frame above everything otherwise. */
-
-    if (nextWid == NULL)
-    {
-        wc.stack_mode = XP_MAPPED_ABOVE;
-        wc.sibling = 0;
-    }
-    else
-    {
-        wc.stack_mode = XP_MAPPED_BELOW;
-        wc.sibling = (xp_window_id) nextWid;
-    }
-
-    xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
-}
-
-
-/*
- * Change the frame's shape.
- */
-void
-xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
-{
-    xp_window_changes wc;
-
-    if (pShape != NULL)
-    {
-        wc.shape_nrects = REGION_NUM_RECTS(pShape);
-        wc.shape_rects = REGION_RECTS(pShape);
-    }
-    else
-    {
-        wc.shape_nrects = -1;
-        wc.shape_rects = NULL;
-    }
-
-    wc.shape_tx = wc.shape_ty = 0;
-
-    xprConfigureWindow((xp_window_id) wid, XP_SHAPE, &wc);
-}
-
-
-/*
- * Unmap a frame.
- */
-void
-xprUnmapFrame(RootlessFrameID wid)
-{
-    xp_window_changes wc;
-
-    wc.stack_mode = XP_UNMAPPED;
-    wc.sibling = 0;
-
-    xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
-}
-
-
-/*
- * Start drawing to a frame.
- *  Prepare for direct access to its backing buffer.
- */
-void
-xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
-{
-    void *data[2];
-    unsigned int rowbytes[2];
-    xp_error err;
-
-    err = xp_lock_window((xp_window_id) wid, NULL, NULL, data, rowbytes, NULL);
-    if (err != Success)
-        FatalError("Could not lock window %i for drawing.", (int) wid);
-
-    *pixelData = data[0];
-    *bytesPerRow = rowbytes[0];
-}
-
-
-/*
- * Stop drawing to a frame.
- */
-void
-xprStopDrawing(RootlessFrameID wid, Bool flush)
-{
-    xp_unlock_window((xp_window_id) wid, flush);
-}
-
-
-/*
- * Flush drawing updates to the screen.
- */
-void
-xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
-{
-    xp_flush_window((xp_window_id) wid);
-}
-
-
-/*
- * Mark damaged rectangles as requiring redisplay to screen.
- */
-void
-xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
-               int shift_x, int shift_y)
-{
-    xp_mark_window((xp_window_id) wid, nrects, rects, shift_x, shift_y);
-}
-
-
-/*
- * Called after the window associated with a frame has been switched
- * to a new top-level parent.
- */
-void
-xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
-{
-    DeleteProperty(oldWin, xa_native_window_id());
-
-    xprSetNativeProperty(pFrame);
-}
-
-
-/*
- * Called to check if the frame should be reordered when it is restacked.
- */
-Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
-{
-    WindowPtr pWin = pFrame->win;
-
-    return AppleWMDoReorderWindow(pWin);
-}
-
-
-/*
- * Copy area in frame to another part of frame.
- *  Used to accelerate scrolling.
- */
-void
-xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
-              int dx, int dy)
-{
-    xp_copy_window((xp_window_id) wid, (xp_window_id) wid,
-                   dstNrects, dstRects, dx, dy);
-}
-
-
-static RootlessFrameProcsRec xprRootlessProcs = {
-    xprCreateFrame,
-    xprDestroyFrame,
-    xprMoveFrame,
-    xprResizeFrame,
-    xprRestackFrame,
-    xprReshapeFrame,
-    xprUnmapFrame,
-    xprStartDrawing,
-    xprStopDrawing,
-    xprUpdateRegion,
-    xprDamageRects,
-    xprSwitchWindow,
-    xprDoReorderWindow,
-    xp_copy_bytes,
-    xp_fill_bytes,
-    xp_composite_pixels,
-    xprCopyWindow
-};
-
-
-/*
- * Initialize XPR implementation
- */
-Bool
-xprInit(ScreenPtr pScreen)
-{
-    RootlessInit(pScreen, &xprRootlessProcs);
-
-    if(!access("/tmp/disable_fb.txt", F_OK)) {
-      // always use the xp functions, dammit
-      fprintf(stderr,"setting rootless thresholds to zero to disable fb usage\n");
-      rootless_CopyBytes_threshold = 0;
-      rootless_FillBytes_threshold = 0;
-      rootless_CompositePixels_threshold = 0;
-      rootless_CopyWindow_threshold = 0;
-    } else {
-      rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
-      rootless_FillBytes_threshold = xp_fill_bytes_threshold;
-      rootless_CompositePixels_threshold = xp_composite_area_threshold;
-      rootless_CopyWindow_threshold = xp_scroll_area_threshold;
-    }
-
-    no_configure_window = FALSE;
-
-    return TRUE;
-}
-
-
-/*
- * Given the id of a physical window, try to find the top-level (or root)
- * X window that it represents.
- */
-WindowPtr
-xprGetXWindow(xp_window_id wid)
-{
-    RootlessWindowRec *winRec;
-
-    if (window_hash == NULL)
-        return NULL;
-
-    winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
-
-    return winRec != NULL ? winRec->win : NULL;
-}
-
-/*
- * Given the id of a physical window, try to find the top-level (or root)
- * X window that it represents.
- */
-WindowPtr
-xprGetXWindowFromAppKit(int windowNumber)
-{
-    RootlessWindowRec *winRec;
-    Bool ret;
-    xp_window_id wid;
-
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
-    pthread_mutex_lock(&window_hash_mutex);
-
-    if (xp_lookup_native_window(windowNumber, &wid))
-        ret = xprGetXWindow(wid) != NULL;
-    else
-        ret = FALSE;
-
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    if (!ret) return NULL;
-    winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
-
-    return winRec != NULL ? winRec->win : NULL;
-}
-
-
-/*
- * The windowNumber is an AppKit window number. Returns TRUE if xpr is
- * displaying a window with that number.
- */
-Bool
-xprIsX11Window(void *nsWindow, int windowNumber)
-{
-    Bool ret;
-    xp_window_id wid;
-
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
-    pthread_mutex_lock(&window_hash_mutex);
-
-    if (xp_lookup_native_window(windowNumber, &wid))
-        ret = xprGetXWindow(wid) != NULL;
-    else
-        ret = FALSE;
-
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    return ret;
-}
-
-
-/*
- * xprHideWindows
- *  Hide or unhide all top level windows. This is called for application hide/
- *  unhide events if the window manager is not Apple-WM aware. Xplugin windows
- *  do not hide or unhide themselves.
- */
-void
-xprHideWindows(Bool hide)
-{
-    int screen;
-    WindowPtr pRoot, pWin;
-
-    for (screen = 0; screen < screenInfo.numScreens; screen++) {
-        pRoot = WindowTable[screenInfo.screens[screen]->myNum];
-        RootlessFrameID prevWid = NULL;
-
-        for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib) {
-            RootlessWindowRec *winRec = WINREC(pWin);
-
-            if (winRec != NULL) {
-                if (hide) {
-                    xprUnmapFrame(winRec->wid);
-                } else {
-                    BoxRec box;
-
-                    xprRestackFrame(winRec->wid, prevWid);
-                    prevWid = winRec->wid;
-
-                    box.x1 = 0;
-                    box.y1 = 0;
-                    box.x2 = winRec->width;
-                    box.y2 = winRec->height;
-
-                    xprDamageRects(winRec->wid, 1, &box, 0, 0);
-                    RootlessQueueRedisplay(screenInfo.screens[screen]);
-                }
-            }
-        }
-    }
-}
diff --git a/hw/darwin/quartz/xprScreen.c b/hw/darwin/quartz/xprScreen.c
deleted file mode 100644
index 13bff50..0000000
--- a/hw/darwin/quartz/xprScreen.c
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * 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.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartz/quartzCommon.h"
-#include "quartz/quartz.h"
-#include "xpr.h"
-#include "quartz/pseudoramiX.h"
-#include "darwin.h"
-#include "rootless.h"
-#include "safeAlpha/safeAlpha.h"
-#include "dri.h"
-#include "globals.h"
-#include "Xplugin.h"
-#include "quartz/applewmExt.h"
-
-// From xprFrame.c
-WindowPtr xprGetXWindow(xp_window_id wid);
-
-#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");
-      QuartzMessageServerThread(kXDarwinDisplayChanged, 0);
-      break;
-
-    case XP_EVENT_WINDOW_STATE_CHANGED:
-      DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED\n");
-      if (arg_size >= sizeof(xp_window_state_event)) {
-	const xp_window_state_event *ws_arg = arg;
-	
-	QuartzMessageServerThread(kXDarwinWindowState, 2,
-				  ws_arg->id, ws_arg->state);
-      }
-      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;
-	WindowPtr pWin = xprGetXWindow(id);
-	QuartzMessageServerThread(kXDarwinWindowMoved, 1, pWin);
-      }
-      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;
-    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);
-
-    /* Remove menubar to help standard X11 window managers. */
-
-    if (frame.origin.x == 0 && frame.origin.y == 0)
-    {
-        frame.origin.y += aquaMenuBarHeight;
-        frame.size.height -= aquaMenuBarHeight;
-    }
-
-    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;
-
-    /* Tell PseudoramiX about the real screens. */
-    for (i = 0; i < displayCount; i++)
-    {
-        CGDirectDisplayID dpy = displayList[i];
-
-        frame = displayScreenBounds(dpy);
-
-	/*        ErrorF("PseudoramiX screen %d added: %dx%d @ (%d,%d).\n", i,
-               (int)frame.size.width, (int)frame.size.height,
-               (int)frame.origin.x, (int)frame.origin.y); */
-
-        frame.origin.x -= unionRect.origin.x;
-        frame.origin.y -= unionRect.origin.y;
-
-	/*        ErrorF("PseudoramiX screen %d placed at X11 coordinate (%d,%d).\n",
-		  i, (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;
-
-    //    ErrorF("Display mode: Rootless Quartz -- Xplugin implementation\n");
-
-    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
-                     | XP_EVENT_SURFACE_CHANGED
-                     | XP_EVENT_SURFACE_DESTROYED,
-                     eventHandler, NULL);
-
-    AppleDRIExtensionInit();
-    xprAppleWMInit();
-}
-
-/*
- * xprAddScreen
- *  Init the framebuffer and record pixmap parameters for the screen.
- */
-static Bool
-xprAddScreen(int index, ScreenPtr pScreen)
-{
-    DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
-
-    /* If no specific depth chosen, look for the depth of the main display.
-       Else if 16bpp specified, use that. Else use 32bpp. */
-
-    dfb->colorType = TrueColor;
-    dfb->bitsPerComponent = 8;
-    dfb->bitsPerPixel = 32;
-    dfb->colorBitsPerPixel = 24;
-
-    if (darwinDesiredDepth == -1)
-    {
-        dfb->bitsPerComponent = CGDisplayBitsPerSample(kCGDirectMainDisplay);
-        dfb->bitsPerPixel = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
-        dfb->colorBitsPerPixel =
-                CGDisplaySamplesPerPixel(kCGDirectMainDisplay) *
-                dfb->bitsPerComponent;
-    }
-    else if (darwinDesiredDepth == 15)
-    {
-        dfb->bitsPerComponent = 5;
-        dfb->bitsPerPixel = 16;
-        dfb->colorBitsPerPixel = 15;
-    }
-    else if (darwinDesiredDepth == 8)
-    {
-        dfb->colorType = PseudoColor;
-        dfb->bitsPerComponent = 8;
-        dfb->bitsPerPixel = 8;
-        dfb->colorBitsPerPixel = 8;
-    }
-
-    if (noPseudoramiXExtension)
-    {
-        CGDirectDisplayID dpy;
-        CGRect frame;
-
-        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)
-{
-    // Add alpha protecting replacements for fb screen functions
-    pScreen->PaintWindowBackground = SafeAlphaPaintWindow;
-    pScreen->PaintWindowBorder = SafeAlphaPaintWindow;
-
-#ifdef RENDER
-    {
-        PictureScreenPtr ps = GetPictureScreen(pScreen);
-        ps->Composite = SafeAlphaComposite;
-    }
-#endif /* RENDER */
-
-    // Initialize accelerated rootless drawing
-    // Note that this must be done before DamageSetup().
-    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,
-    NULL,               // No need to update cursor
-    QuartzSuspendXCursor,
-    QuartzResumeXCursor,
-    NULL,               // No capture or release in rootless mode
-    NULL,
-    NULL,               // Xplugin sends screen change events directly
-    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;
-}
commit 9ddf3611712029439268db6de828a4f7fb84b159
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Tue Dec 4 17:34:33 2007 -0800

    Revert "oops, missed a spot"
    
    This reverts commit 03e0788cce1b9578e1f61845fcf2c09f220e175f.

diff --git a/hw/darwin/quartz/X11Controller.h b/hw/darwin/quartz/X11Controller.h
index 74277ea..f1399dc 100644
--- a/hw/darwin/quartz/X11Controller.h
+++ b/hw/darwin/quartz/X11Controller.h
@@ -33,7 +33,7 @@
 #if __OBJC__
 
 #import <Cocoa/Cocoa.h>
-#include "x-list.h"
+#include "xpr/x-list.h"
 
 @interface X11Controller : NSObject
 {
commit 30e4f7489e2e1138e19eb01927059a0f425581eb
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Tue Dec 4 17:34:03 2007 -0800

    Revert "more xpr cleanup"
    
    This reverts commit 17a41dcf77c834149d134d42a09c782150e5d183.

diff --git a/hw/darwin/quartz/xpr/Makefile.am b/hw/darwin/quartz/xpr/Makefile.am
new file mode 100644
index 0000000..8980ad7
--- /dev/null
+++ b/hw/darwin/quartz/xpr/Makefile.am
@@ -0,0 +1,29 @@
+noinst_LIBRARIES = libxpr.a
+AM_CFLAGS =  $(XSERVER_CFLAGS) $(DIX_CFLAGS)
+AM_CPPFLAGS = \
+	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
+	   -I$(top_srcdir)/miext \
+	   -I$(top_srcdir)/miext/rootless \
+	   -I$(top_srcdir)/miext/rootless/safeAlpha
+
+libxpr_a_SOURCES = \
+	appledri.c \
+	dri.c \
+	xprAppleWM.c \
+	xprCursor.c \
+	xprFrame.c \
+	xprScreen.c \
+	x-hash.c \
+	x-hook.c \
+	x-list.c
+
+EXTRA_DIST = \
+	dri.h \
+	dristruct.h \
+	appledri.h \
+	appledristr.h \
+	x-hash.h \
+	x-hook.h \
+	x-list.h \
+	Xplugin.h \
+	xpr.h


More information about the xorg-commit mailing list