[Xquartz-changes] xserver: Branch 'server-1.10-apple' - 27 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Tue Sep 28 10:09:53 PDT 2010


Rebased ref, commits from common ancestor:
commit 5f00548b828332537db7f642e2d83faaecf60162
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Feb 12 19:48:52 2010 -0800

    fb: Revert fb changes that broke XQuartz
    
    http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Fix source pictures getting random transforms after 2d6a8f668342a5190cdf43b5."
    Revert "fb: Adjust transform or composite coordinates for pixman operations"
    
    http://bugs.freedesktop.org/26124
    
    This reverts commit a72c65e9176c51de95db2fdbf4c5d946a4911695.
    This reverts commit a6bd5d2e482a5aa84acb3d4932e2a166d8670ef1.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/fb/fb.h b/fb/fb.h
index c290ebf..10a022c 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -2079,11 +2079,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
 		   FbBits	xor);
 
 extern _X_EXPORT pixman_image_t *
-image_from_pict (PicturePtr	pict,
-		 Bool		has_clip,
-		 int		*xoff,
-		 int		*yoff);
-
+image_from_pict (PicturePtr pict,
+		 Bool       has_clip);
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
 
 #endif /* _FB_H_ */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index f7f1200..5467ee4 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -156,24 +156,19 @@ fbComposite (CARD8      op,
 	     CARD16     height)
 {
     pixman_image_t *src, *mask, *dest;
-    int src_xoff, src_yoff;
-    int msk_xoff, msk_yoff;
-    int dst_xoff, dst_yoff;
     
     miCompositeSourceValidate (pSrc, xSrc - xDst, ySrc - yDst, width, height);
     if (pMask)
 	miCompositeSourceValidate (pMask, xMask - xDst, yMask - yDst, width, height);
     
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    mask = image_from_pict (pMask, FALSE, &msk_xoff, &msk_yoff);
-    dest = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, TRUE);
+    mask = image_from_pict (pMask, TRUE);
+    dest = image_from_pict (pDst, TRUE);
 
     if (src && dest && !(pMask && !mask))
     {
 	pixman_image_composite (op, src, mask, dest,
-				xSrc + src_xoff, ySrc + src_yoff,
-				xMask + msk_xoff, yMask + msk_yoff,
-				xDst + dst_xoff, yDst + dst_yoff,
+				xSrc, ySrc, xMask, yMask, xDst, yDst,
 				width, height);
     }
 
@@ -271,22 +266,22 @@ create_conical_gradient_image (PictGradient *gradient)
 
 static pixman_image_t *
 create_bits_picture (PicturePtr pict,
-		     Bool       has_clip,
-		     int	*xoff,
-		     int	*yoff)
+		     Bool       has_clip)
 {
-    PixmapPtr pixmap;
     FbBits *bits;
     FbStride stride;
-    int bpp;
+    int bpp, xoff, yoff;
     pixman_image_t *image;
     
-    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
-    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
+
+    bits = (FbBits*)((CARD8*)bits +
+		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
+		     (pict->pDrawable->x + xoff) * (bpp / 8));
 
     image = pixman_image_create_bits (
 	pict->format,
-	pixmap->drawable.width, pixmap->drawable.height,
+	pict->pDrawable->width, pict->pDrawable->height,
 	(uint32_t *)bits, stride * sizeof (FbStride));
     
     
@@ -312,55 +307,33 @@ create_bits_picture (PicturePtr pict,
 	if (pict->clientClipType != CT_NONE)
 	    pixman_image_set_has_client_clip (image, TRUE);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
+	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
+	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
     
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map);
+image_from_pict_internal (PicturePtr pict, Bool has_clip, Bool is_alpha_map);
 
 static void
-set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+set_image_properties (pixman_image_t *image, PicturePtr pict, Bool is_alpha_map)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
     
     if (pict->transform)
     {
-	/* For source images, adjust the transform to account
-	 * for the drawable offset within the pixman image,
-	 * then set the offset to 0 as it will be used
-	 * to compute positions within the transformed image.
-	 */
-	if (!has_clip) {
-	    struct pixman_transform	adjusted;
-
-	    adjusted = *pict->transform;
-	    pixman_transform_translate(&adjusted,
-				       NULL,
-				       pixman_int_to_fixed(*xoff),
-				       pixman_int_to_fixed(*yoff));
-	    pixman_image_set_transform (image, &adjusted);
-	    *xoff = 0;
-	    *yoff = 0;
-	} else
-	    pixman_image_set_transform (image, pict->transform);
+	pixman_image_set_transform (
+	    image, (pixman_transform_t *)pict->transform);
     }
     
     switch (pict->repeatType)
@@ -390,8 +363,7 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
      */
     if (pict->alphaMap && !is_alpha_map)
     {
-	int alpha_xoff, alpha_yoff;
-	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff, TRUE);
+	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, TRUE, TRUE);
 	
 	pixman_image_set_alpha_map (
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
@@ -424,7 +396,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+image_from_pict_internal (PicturePtr pict,
+		 Bool has_clip, Bool is_alpha_map)
 {
     pixman_image_t *image = NULL;
 
@@ -433,7 +406,7 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 
     if (pict->pDrawable)
     {
-	image = create_bits_picture (pict, has_clip, xoff, yoff);
+	image = create_bits_picture (pict, has_clip);
     }
     else if (pict->pSourcePict)
     {
@@ -454,19 +427,18 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 	    else if (sp->type == SourcePictTypeConical)
 		image = create_conical_gradient_image (gradient);
 	}
-	*xoff = *yoff = 0;
     }
     
     if (image)
-	set_image_properties (image, pict, has_clip, xoff, yoff, is_alpha_map);
+	set_image_properties (image, pict, is_alpha_map);
     
     return image;
 }
 
 pixman_image_t *
-image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict, Bool has_clip)
 {
-    return image_from_pict_internal (pict, has_clip, xoff, yoff, FALSE);
+    return image_from_pict_internal (pict, has_clip, FALSE);
 }
 
 void
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index 9f5c39f..9c55236 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -38,8 +38,7 @@ fbAddTraps (PicturePtr	pPicture,
 	    int		ntrap,
 	    xTrap	*traps)
 {
-    int image_xoff, image_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &image_xoff, &image_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -55,8 +54,7 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
 		      int	    x_off,
 		      int	    y_off)
 {
-    int	mask_xoff, mask_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &mask_xoff, &mask_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
commit 573c199ee3178cd9132e8df8267175e4af94b915
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

    Workaround the GC clipping problem in miPaintWindow and add some debugging output.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 94258b8..4f25c23 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -521,6 +521,7 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
+#include "../fb/fb.h"
 #endif 
 
 void
@@ -548,24 +549,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool	solid = TRUE;
     DrawablePtr	drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if(!drawable || drawable->type == UNDRAWABLE_WINDOW)
 	return;
-
-    if(IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-    
-        if(pWin->backgroundState == ParentRelative) {
-            if((what == PW_BACKGROUND) || 
-               (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
 #endif
     
     if (what == PW_BACKGROUND)
     {
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+
+	    if(pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	while (pWin->backgroundState == ParentRelative)
 	    pWin = pWin->parent;
 
@@ -587,6 +601,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     {
 	PixmapPtr   pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	tile_x_off = drawable->x;
 	tile_y_off = drawable->y;
 	
@@ -595,6 +621,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	    return;
 	pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
 	drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+	ErrorF("     Draw: %d %d %d %d\n",
+	       drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
 	draw_x_off = pixmap->screen_x;
 	draw_y_off = pixmap->screen_y;
@@ -657,6 +689,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
commit c45bea0c044ad37bedb42209f7e6ea8b587999f0
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue Aug 3 12:51:51 2010 -0700

    XQuartz: RandR: Refactor legacy mode-switching to be better integrated with RandR
    
    Adds three new functions
    void QuartzRandRSetFakeRootless (void);
    void QuartzRandRSetFakeFullscreen (void);
    void QuartzRandRToggleFullscreen (void);
    
    The first two are identical to requesting the fake modes from a RandR client
    The third responds to cmd-alt-a to leave fullscreen or RandR.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 781dccc..8f4f23f 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -370,7 +370,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                     break;
                     
                 case 18: /* ApplicationDidReactivate */
-                    if (XQuartzHasRoot) for_appkit = NO;
+                    if (XQuartzFullscreenVisible) for_appkit = NO;
                     break;
                     
                 case NSApplicationDeactivatedEventType:
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 4332202..74fadf4 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -241,17 +241,17 @@ static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr de
             DEBUG_LOG("kXquartzToggleFullscreen\n");
             if(XQuartzIsRootless)
                 ErrorF("Ignoring kXquartzToggleFullscreen because of rootless mode.");
-            else if (XQuartzHasRoot)
-                QuartzHide();
-            else
-                QuartzShow();
+            else 
+                QuartzRandRToggleFullscreen();
             break;
             
         case kXquartzSetRootless:
             DEBUG_LOG("kXquartzSetRootless\n");
-            QuartzSetRootless(e->data[0]);
-            if (!XQuartzIsRootless && !XQuartzHasRoot)
-                QuartzHide();
+            if(e->data[0]) {
+                QuartzRandRSetFakeRootless();
+            } else {
+                QuartzRandRSetFakeFullscreen(FALSE);
+            }
             break;
             
         case kXquartzSetRootClip:
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index cd90457..e21303c 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -74,7 +74,7 @@ const char             *quartzOpenGLBundle = NULL;
 Bool XQuartzFullscreenDisableHotkeys = TRUE;
 Bool XQuartzOptionSendsAlt = FALSE;
 Bool XQuartzEnableKeyEquivalents = TRUE;
-Bool XQuartzHasRoot = FALSE;
+Bool XQuartzFullscreenVisible = FALSE;
 Bool XQuartzRootlessDefault = TRUE;
 Bool XQuartzIsRootless = TRUE;
 Bool XQuartzServerVisible = FALSE;
@@ -246,44 +246,58 @@ void QuartzUpdateScreens(void) {
     quartzProcs->UpdateScreen(pScreen);
 }
 
-void QuartzSetFullscreen(Bool state) {
+void QuartzShowFullscreen(int state) {
+    int i;
+    
+    DEBUG_LOG("QuartzShowFullscreen: state=%d\n", state);
     
-    DEBUG_LOG("QuartzSetFullscreen: state=%d\n", state);
+    if(XQuartzIsRootless) {
+        ErrorF("QuartzShowFullscreen called while in rootless mode.\n");
+        return;
+    }
     
-    if(XQuartzHasRoot == state)
+    if(XQuartzFullscreenVisible == state)
         return;
     
-    XQuartzHasRoot = state;
+    XQuartzFullscreenVisible = state;
     
     xp_disable_update ();
     
-    if (!XQuartzHasRoot && !XQuartzIsRootless)
+    if (!XQuartzFullscreenVisible)
         RootlessHideAllWindows();
     
-    RootlessUpdateRooted(XQuartzHasRoot);
+    RootlessUpdateRooted(XQuartzFullscreenVisible);
     
-    if (XQuartzHasRoot && !XQuartzIsRootless)
+    if (XQuartzFullscreenVisible) {
         RootlessShowAllWindows ();
-    
-    if (XQuartzHasRoot || XQuartzIsRootless) {
-        RootlessRepositionWindows(screenInfo.screens[0]);
+        for (i=0; i < screenInfo.numScreens; i++) {
+            ScreenPtr pScreen = screenInfo.screens[i];        
+            RootlessRepositionWindows(pScreen);
+            // JH: I don't think this is necessary, but keeping it here as a reminder
+            //RootlessUpdateScreenPixmap(pScreen);
+        }
     }
 
     /* Somehow the menubar manages to interfere with our event stream
      * in fullscreen mode, even though it's not visible. 
      */
-    X11ApplicationShowHideMenubar(!XQuartzHasRoot);
+    X11ApplicationShowHideMenubar(!XQuartzFullscreenVisible);
     
     xp_reenable_update ();
     
     if (XQuartzFullscreenDisableHotkeys)
-        xp_disable_hot_keys(XQuartzHasRoot);
+        xp_disable_hot_keys(XQuartzFullscreenVisible);
 }
 
-void QuartzSetRootless(Bool state) {
+void QuartzSetRootless(Bool state) {    
+    DEBUG_LOG("QuartzSetRootless state=%d\n", state);
+    
     if(XQuartzIsRootless == state)
         return;
     
+    if(state)
+        QuartzShowFullscreen(FALSE);
+    
     XQuartzIsRootless = state;
 
     xp_disable_update();
@@ -291,20 +305,17 @@ void QuartzSetRootless(Bool state) {
     /* When in rootless, the menubar is not part of the screen, so we need to update our screens on toggle */    
     QuartzUpdateScreens();
 
-    if(!XQuartzHasRoot) {
-        if(!XQuartzIsRootless) {
-            RootlessHideAllWindows();
-        } else {
-            RootlessShowAllWindows();
-        }
+    if(XQuartzIsRootless) {
+        RootlessShowAllWindows();
+    } else {
+        RootlessHideAllWindows();
     }
 
-    X11ApplicationShowHideMenubar(!XQuartzHasRoot);
+    X11ApplicationShowHideMenubar(TRUE);
 
     xp_reenable_update();
 
-    if (!XQuartzIsRootless && XQuartzFullscreenDisableHotkeys)
-        xp_disable_hot_keys(XQuartzHasRoot);
+    xp_disable_hot_keys(FALSE);
 }
 
 /*
@@ -327,7 +338,7 @@ void QuartzShow(void) {
     }
     
     if (!XQuartzIsRootless)
-        QuartzSetFullscreen(TRUE);
+        QuartzShowFullscreen(TRUE);
 }
 
 
@@ -348,8 +359,9 @@ void QuartzHide(void)
             }
         }
     }
-    
-    QuartzSetFullscreen(FALSE);
+
+    if(!XQuartzIsRootless)
+        QuartzShowFullscreen(FALSE);
     XQuartzServerVisible = FALSE;
 }
 
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index a0a17cb..7efb7e0 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -115,12 +115,8 @@ typedef struct _QuartzModeProcs {
 
 extern QuartzModeProcsPtr quartzProcs;
 
-extern Bool XQuartzHasRoot;          /* TODO: These two booleans are very similar and */
-extern Bool XQuartzServerVisible;    /* the code that uses them needs to be refactored
-                                      * XQuartzHasRoot is essentially the "saved" XQuartzServerVisible
-                                      * value from when the server was not in rootless mode.
-                                      */
-
+extern Bool XQuartzFullscreenVisible; /* Are the windows visible (predicated on !rootless) */
+extern Bool XQuartzServerVisible;     /* Is the server visible ... TODO: Refactor to "active" */
 extern Bool XQuartzEnableKeyEquivalents;
 extern Bool XQuartzRootlessDefault;  /* Is our default mode rootless? */
 extern Bool XQuartzIsRootless;       /* Is our current mode rootless (or FS)? */
@@ -144,7 +140,7 @@ void QuartzSetRootClip(BOOL enable);
 void QuartzSpaceChanged(uint32_t space_id);
 
 void QuartzSetRootless(Bool state);
-void QuartzSetFullscreen(Bool state);
+void QuartzShowFullscreen(Bool state);
 
 int server_main(int argc, char **argv, char **envp);
 #endif
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index bbeebda..298ec0a 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -62,7 +62,7 @@ static Bool ignore_next_fake_mode_update = FALSE;
 #define CALLBACK_ERROR -1
 
 typedef int (*QuartzModeCallback)
-    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
+    (ScreenPtr, QuartzModeInfoPtr, void *);
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
 
@@ -98,6 +98,7 @@ static void QuartzRandRGetModeInfo (CFDictionaryRef modeRef,
     if (pMode->refresh == 0)
         pMode->refresh = DEFAULT_REFRESH;
     pMode->ref = NULL;
+    pMode->pSize = NULL;
 }
 
 static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
@@ -112,14 +113,13 @@ static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
     return TRUE;
 }
 
-static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
+static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId,
                                 QuartzModeInfoPtr pMode) {
     CFDictionaryRef modeRef = (CFDictionaryRef) pMode->ref;
     return (CGDisplaySwitchToMode(screenId, modeRef) == kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
-                                       CGDirectDisplayID screenId,
                                        QuartzModeCallback callback,
                                        void *data) {
     CFDictionaryRef curModeRef, modeRef;
@@ -127,28 +127,9 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
-    BOOL retval = TRUE;
+    BOOL retval = FALSE;
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-
-    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
-        case CALLBACK_SUCCESS:
-            return TRUE;
-        case CALLBACK_ERROR:
-            return FALSE;
-        case CALLBACK_CONTINUE:
-        default:
-            break;
-    }
-
-    switch(callback(pScreen, screenId, &pQuartzScreen->fullscreenMode, data)) {
-        case CALLBACK_SUCCESS:
-            return TRUE;
-        case CALLBACK_ERROR:
-            return FALSE;
-        case CALLBACK_CONTINUE:
-        default:
-            break;
-    }
+    CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
 
     curModeRef = CGDisplayCurrentMode(screenId);
     if (!curModeRef)
@@ -172,14 +153,37 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
         modeInfo.ref = (void *)modeRef;
-        cb = callback(pScreen, screenId, &modeInfo, data);
-        if (cb == CALLBACK_SUCCESS)
+        cb = callback(pScreen, &modeInfo, data);
+        if (cb == CALLBACK_CONTINUE)
+            retval = TRUE;
+        else if (cb == CALLBACK_SUCCESS)
+            return TRUE;
+        else if (cb == CALLBACK_ERROR)
+            return FALSE;
+    }
+
+    switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+            retval = TRUE;
+        default:
             break;
-        if (cb == CALLBACK_ERROR) {
-            retval = FALSE;
+    }
+
+    switch(callback(pScreen, &pQuartzScreen->fullscreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+            retval = TRUE;
+        default:
             break;
-        }
     }
+
     return retval;
 }
 
@@ -193,6 +197,7 @@ static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef,
     if (pMode->refresh == 0)
         pMode->refresh = DEFAULT_REFRESH;
     pMode->ref = NULL;
+    pMode->pSize = NULL;
 }
 
 static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
@@ -206,7 +211,7 @@ static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
     return TRUE;
 }
 
-static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
+static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId,
                                 QuartzModeInfoPtr pMode) {
     CGDisplayModeRef modeRef = (CGDisplayModeRef) pMode->ref;
     if (!modeRef)
@@ -216,7 +221,6 @@ static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
-                                       CGDirectDisplayID screenId,
                                        QuartzModeCallback callback,
                                        void *data) {
     CGDisplayModeRef curModeRef, modeRef;
@@ -225,29 +229,10 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
-    Bool retval = TRUE;
+    Bool retval = FALSE;
 
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-
-    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
-        case CALLBACK_SUCCESS:
-            return TRUE;
-        case CALLBACK_ERROR:
-            return FALSE;
-        case CALLBACK_CONTINUE:
-        default:
-            break;
-    }
-
-    switch(callback(pScreen, screenId, &pQuartzScreen->fullscreenMode, data)) {
-        case CALLBACK_SUCCESS:
-            return TRUE;
-        case CALLBACK_ERROR:
-            return FALSE;
-        case CALLBACK_CONTINUE:
-        default:
-            break;
-    }
+    CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
 
     curModeRef = CGDisplayCopyDisplayMode(screenId);
     if (!curModeRef)
@@ -277,18 +262,45 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
         modeInfo.ref = modeRef;
-        cb = callback(pScreen, screenId, &modeInfo, data);
-        if (cb == CALLBACK_SUCCESS)
+        cb = callback(pScreen, &modeInfo, data);
+        if (cb == CALLBACK_CONTINUE) {
+            retval = TRUE;
+        } else if (cb == CALLBACK_SUCCESS) {
+            CFRelease(modes);
+            CFRelease(curPixelEnc);
+            return TRUE;
+        } else if (cb == CALLBACK_ERROR) {
+            CFRelease(modes);
+            CFRelease(curPixelEnc);
+            return FALSE;
+        }
+    }
+
+    CFRelease(modes);
+    CFRelease(curPixelEnc);
+
+    switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+            retval = TRUE;
+        default:
             break;
-		if (cb == CALLBACK_ERROR) {
-			retval = FALSE;
+    }
+
+    switch(callback(pScreen, &pQuartzScreen->fullscreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+            retval = TRUE;
+        default:
             break;
-		}
     }
-		
-    CFRelease(modes);
 
-    CFRelease(curPixelEnc);
     return retval;
 }
 
@@ -306,14 +318,15 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
                                      QuartzModeInfoPtr pMode) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     Bool isCurrentMode = QuartzRandRModesEqual(&pQuartzScreen->currentMode, pMode);
-    RRScreenSizePtr pSize = RRRegisterSize(pScreen,
-        pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
-    if (pSize) {
+
+    /* TODO: DPI */
+    pMode->pSize = RRRegisterSize(pScreen, pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
+    if (pMode->pSize) {
         //DEBUG_LOG("registering: %d x %d @ %d %s\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh, isCurrentMode ? "*" : "");
-        RRRegisterRate(pScreen, pSize, pMode->refresh);
+        RRRegisterRate(pScreen, pMode->pSize, pMode->refresh);
 
         if (isCurrentMode)
-            RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pSize);
+            RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pMode->pSize);
 
         return TRUE;
     }
@@ -321,7 +334,6 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
 }
 
 static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
-                                        CGDirectDisplayID screenId,
                                         QuartzModeInfoPtr pMode,
                                         void *data __unused) {
     if(QuartzRandRRegisterMode(pScreen, pMode)) {
@@ -331,40 +343,53 @@ static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
     }
 }
 
+static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL doRegister) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
+
+    if (pQuartzScreen->currentMode.ref && CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) {
+        DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
+    } if (QuartzRandRSetCGMode(screenId, pMode)) {
+        ignore_next_fake_mode_update = TRUE;
+    } else {
+        DEBUG_LOG("Error while requesting CG resolution change.\n");
+        return FALSE;
+    }
+
+    /* If the client requested the fake rootless mode, switch to rootless.
+     * Otherwise, force fullscreen mode.
+     */
+    QuartzSetRootless(pMode->refresh == FAKE_REFRESH_ROOTLESS);
+    if (pMode->refresh != FAKE_REFRESH_ROOTLESS) {
+        QuartzShowFullscreen(TRUE);
+    }
+
+    if(pQuartzScreen->currentMode.ref)
+        CFRelease(pQuartzScreen->currentMode.ref);
+    pQuartzScreen->currentMode = *pMode;
+    CFRetain(pQuartzScreen->currentMode.ref);
+    
+    return TRUE;
+}
+
 static int QuartzRandRSetModeCallback (ScreenPtr pScreen,
-                                       CGDirectDisplayID screenId,
                                        QuartzModeInfoPtr pMode,
                                        void *data) {
     QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
-    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 	
     if (!QuartzRandRModesEqual(pMode, pReqMode))
         return CALLBACK_CONTINUE;  /* continue enumeration */
 
     DEBUG_LOG("Found a match for requested RandR resolution (%dx%d@%d).\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh);
 
-    if (pQuartzScreen->currentMode.ref && CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) {
-        DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
-        return CALLBACK_SUCCESS; /* We don't need to do anything in CG */
-    }
-
-    if (QuartzRandRSetMode(screenId, pMode)) {
-        if(pQuartzScreen->currentMode.ref)
-            CFRelease(pQuartzScreen->currentMode.ref);
-        pQuartzScreen->currentMode = *pMode;
-        CFRetain(pQuartzScreen->currentMode.ref);
-
-        ignore_next_fake_mode_update = TRUE;
+    if(QuartzRandRSetMode(pScreen, pMode, FALSE))
         return CALLBACK_SUCCESS;
-    } else {
-        DEBUG_LOG("Error while requesting CG resolution change.\n");
+    else
         return CALLBACK_ERROR;
-    }
 }
 
 static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-    CGDirectDisplayID screenId;
 
     *rotations = RR_Rotate_0;  /* TODO: support rotation */
 
@@ -381,8 +406,7 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
         return TRUE;
     }
 
-    screenId = pQuartzScreen->displayIDs[0];
-    return QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRRegisterModeCallback, NULL);
+    return QuartzRandREnumerateModes(pScreen, QuartzRandRRegisterModeCallback, NULL);
 }
 
 static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
@@ -390,39 +414,20 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
                                   int                 rate,
                                   RRScreenSizePtr     pSize) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-    CGDirectDisplayID screenId;
     QuartzModeInfo reqMode;
 
     reqMode.width = pSize->width;
     reqMode.height = pSize->height;
     reqMode.refresh = rate;
 
-    /* If the client requested the fake rootless mode, switch to rootless.
-     * Otherwise, force fullscreen mode.
-     * TODO: Refactor all this fullscreen/rootless crap as it is spaghetti
-     *       has redundancies.
-     */
-    QuartzSetRootless(reqMode.refresh == FAKE_REFRESH_ROOTLESS);
-    QuartzSetFullscreen(reqMode.refresh != FAKE_REFRESH_ROOTLESS);
-    if(reqMode.refresh != FAKE_REFRESH_ROOTLESS &&
-       reqMode.refresh != FAKE_REFRESH_FULLSCREEN)
-        QuartzShow();
-
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
-    if (pQuartzScreen->displayCount > 1) {
-        /* RandR operations are not well-defined for an X11 screen spanning
-           multiple CG displays. Do not accept any configuations that differ
-           from the current configuration. */
-        return TRUE;
-    }
 
     /* Do not switch modes if requested mode is equal to current mode. */
     if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->currentMode))
         return TRUE;
         
-    screenId = pQuartzScreen->displayIDs[0];
-    if (QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRSetModeCallback, &reqMode)) {
+    if (QuartzRandREnumerateModes(pScreen, QuartzRandRSetModeCallback, &reqMode)) {
         return TRUE;
     }
     
@@ -499,3 +504,57 @@ Bool QuartzRandRInit (ScreenPtr pScreen) {
     pScrPriv->rrSetConfig = QuartzRandRSetConfig;
     return TRUE;
 }
+
+void QuartzRandRSetFakeRootless (void) {
+    int i;
+    
+    DEBUG_LOG("QuartzRandRSetFakeRootless called.\n");
+    
+    for (i=0; i < screenInfo.numScreens; i++) {
+        ScreenPtr pScreen = screenInfo.screens[i];
+        QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+        QuartzRandRSetMode(pScreen, &pQuartzScreen->rootlessMode, TRUE);
+    }
+}
+
+void QuartzRandRSetFakeFullscreen (BOOL state) {
+    int i;
+
+    DEBUG_LOG("QuartzRandRSetFakeFullscreen called.\n");
+    
+    for (i=0; i < screenInfo.numScreens; i++) {
+        ScreenPtr pScreen = screenInfo.screens[i];
+        QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+        QuartzRandRSetMode(pScreen, &pQuartzScreen->fullscreenMode, TRUE);
+    }
+    
+    QuartzShowFullscreen(state);
+}
+
+/* Toggle fullscreen mode.  If "fake" fullscreen is the current mode,
+ * this will just show/hide the X11 windows.  If we are in a RandR fullscreen
+ * mode, this will toggles us to the default fake mode and hide windows if
+ * it is fullscreen
+ */
+void QuartzRandRToggleFullscreen (void) {
+    ScreenPtr pScreen = screenInfo.screens[0];
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+    if (pQuartzScreen->currentMode.ref == NULL) {
+        ErrorF("Ignoring QuartzRandRToggleFullscreen because don't have a current mode set.\n");
+    } else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_ROOTLESS) {
+        ErrorF("Ignoring QuartzRandRToggleFullscreen because we are in rootless mode.\n");
+    } else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_FULLSCREEN) {
+        /* Legacy fullscreen mode.  Hide/Show */
+        QuartzShowFullscreen(!XQuartzFullscreenVisible);
+    } else {
+        /* RandR fullscreen mode.  Return to default mode and hide if it is fullscreen. */
+        if(XQuartzRootlessDefault) {
+            QuartzRandRSetFakeRootless();
+        } else {
+            QuartzRandRSetFakeFullscreen(FALSE);
+        }
+    }    
+}
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index b2d4d09..fb0ce0c 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -31,9 +31,12 @@
 #ifndef _QUARTZRANDR_H_
 #define _QUARTZRANDR_H_
 
+#include "randrstr.h"
+
 typedef struct {
     size_t width, height;
     int refresh;
+    RRScreenSizePtr pSize;
     void *ref; /* CGDisplayModeRef or CFDictionaryRef */
 } QuartzModeInfo, *QuartzModeInfoPtr;
 
@@ -57,4 +60,21 @@ void QuartzCopyDisplayIDs(ScreenPtr pScreen,
 Bool QuartzRandRUpdateFakeModes (BOOL force_update);
 Bool QuartzRandRInit (ScreenPtr pScreen);
 
+/* These two functions provide functionality expected by the legacy
+ * mode switching.  They are equivalent to a client requesting one
+ * of the modes corresponding to these "fake" modes.
+ * QuartzRandRSetFakeFullscreen takes an argument which is used to determine
+ * the visibility of the windows after the change.
+ */
+void QuartzRandRSetFakeRootless (void);
+void QuartzRandRSetFakeFullscreen (BOOL state);
+
+
+/* Toggle fullscreen mode.  If "fake" fullscreen is the current mode,
+ * this will just show/hide the X11 windows.  If we are in a RandR fullscreen
+ * mode, this will toggles us to the default fake mode and hide windows if
+ * it is fullscreen
+ */
+void QuartzRandRToggleFullscreen (void);
+
 #endif
commit 229323a19b06f80d9b03f487e598b933b9b31d87
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Jul 26 23:34:49 2010 -0700

    XQuartz: RandR: Don't change the rootless preference when changing RandR mode
    
    Also renames a bunch of other variables for better consistency.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index ce19e03..4621284 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -75,9 +75,6 @@ void X11ApplicationLaunchClient (const char *cmd);
 
 void X11ApplicationMain(int argc, char **argv, char **envp);
 
-extern int X11EnableKeyEquivalents;
-extern int quartzHasRoot, quartzEnableRootless, quartzFullscreenMenu;
-
 #define PREFS_APPSMENU              "apps_menu"
 #define PREFS_FAKEBUTTONS           "enable_fake_buttons"
 #define PREFS_SYSBEEP               "enable_system_beep"
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 36c39e5..781dccc 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -38,6 +38,7 @@
 #import "X11Application.h"
 
 #include "darwin.h"
+#include "quartz.h"
 #include "darwinEvents.h"
 #include "quartzKeyboard.h"
 #include "quartz.h"
@@ -63,9 +64,6 @@ extern int xpbproxy_run (void);
 /* Stuck modifier / button state... force release when we context switch */
 static NSEventType keyState[NUM_KEYCODES];
 
-int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE;
-int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
-
 extern Bool noTestExtensions;
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
@@ -287,23 +285,23 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                         do_swallow = YES;
                         for_x = NO;
 #if XPLUGIN_VERSION >= 1
-                    } else if(X11EnableKeyEquivalents &&
+                    } else if(XQuartzEnableKeyEquivalents &&
                              xp_is_symbolic_hotkey_event([e eventRef])) {
                         swallow_keycode = [e keyCode];
                         do_swallow = YES;
                         for_x = NO;
 #endif
-                    } else if(X11EnableKeyEquivalents &&
+                    } else if(XQuartzEnableKeyEquivalents &&
                               [[self mainMenu] performKeyEquivalent:e]) {
                         swallow_keycode = [e keyCode];
                         do_swallow = YES;
                         for_appkit = NO;
                         for_x = NO;
-                    } else if(!quartzEnableRootless
+                    } else if(!XQuartzIsRootless
                               && ([e modifierFlags] & ALL_KEY_MASKS) == (NSCommandKeyMask | NSAlternateKeyMask)
                               && ([e keyCode] == 0 /*a*/ || [e keyCode] == 53 /*Esc*/)) {
                         /* We have this here to force processing fullscreen 
-                         * toggle even if X11EnableKeyEquivalents is disabled */
+                         * toggle even if XQuartzEnableKeyEquivalents is disabled */
                         swallow_keycode = [e keyCode];
                         do_swallow = YES;
                         for_x = NO;
@@ -372,7 +370,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                     break;
                     
                 case 18: /* ApplicationDidReactivate */
-                    if (quartzHasRoot) for_appkit = NO;
+                    if (XQuartzHasRoot) for_appkit = NO;
                     break;
                     
                 case NSApplicationDeactivatedEventType:
@@ -422,7 +420,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     if ([state boolValue])
         SetSystemUIMode(kUIModeNormal, 0); 
     else
-        SetSystemUIMode(kUIModeAllHidden, quartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation"
+        SetSystemUIMode(kUIModeAllHidden, XQuartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation"
 }
 
 - (void) launch_client:(NSString *)cmd {
@@ -720,18 +718,18 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
     NSString *nsstr;
     const char *tem;
 	
-    quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
-                                       default:quartzUseSysBeep];
-    quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
-                                           default:quartzEnableRootless];
-    quartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU
-                                           default:quartzFullscreenMenu];
-    quartzFullscreenDisableHotkeys = ![self prefs_get_boolean:@PREFS_FULLSCREEN_HOTKEYS
-                                                      default:!quartzFullscreenDisableHotkeys];
+    XQuartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
+                                       default:XQuartzUseSysBeep];
+    XQuartzRootlessDefault = [self prefs_get_boolean:@PREFS_ROOTLESS
+                                           default:XQuartzRootlessDefault];
+    XQuartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU
+                                           default:XQuartzFullscreenMenu];
+    XQuartzFullscreenDisableHotkeys = ![self prefs_get_boolean:@PREFS_FULLSCREEN_HOTKEYS
+                                                      default:!XQuartzFullscreenDisableHotkeys];
     darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS
                                         default:darwinFakeButtons];
-    quartzOptionSendsAlt = [self prefs_get_boolean:@PREFS_OPTION_SENDS_ALT
-                                           default:quartzOptionSendsAlt];
+    XQuartzOptionSendsAlt = [self prefs_get_boolean:@PREFS_OPTION_SENDS_ALT
+                                           default:XQuartzOptionSendsAlt];
 
     if (darwinFakeButtons) {
         const char *fake2, *fake3;
@@ -759,8 +757,8 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
         }
     }
 
-    X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
-                                              default:X11EnableKeyEquivalents];
+    XQuartzEnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
+                                              default:XQuartzEnableKeyEquivalents];
 	
     darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP
                                        default:darwinSyncKeymap];
@@ -1158,7 +1156,7 @@ static inline int ensure_flag(int flags, int device_independent, int device_depe
                 pDev = darwinTabletCurrent;
             }
 
-            if(!quartzServerVisible && noTestExtensions) {
+            if(!XQuartzServerVisible && noTestExtensions) {
 #if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION > 0
 /* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */
                 xp_window_id wid = 0;
@@ -1218,7 +1216,7 @@ static inline int ensure_flag(int flags, int device_independent, int device_depe
             /* If we're in the background, we need to send a MotionNotify event
              * first, since we aren't getting them on background mouse motion
              */
-            if(!quartzServerVisible && noTestExtensions) {
+            if(!XQuartzServerVisible && noTestExtensions) {
                 bgMouseLocationUpdated = FALSE;
                 DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, location.x,
                                         location.y, pressure, tilt.x, tilt.y);
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index d66d039..13b6366 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -609,13 +609,13 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
 }
 
 - (IBAction) enable_fullscreen_changed:sender {
-    int value = ![enable_fullscreen intValue];
+    XQuartzRootlessDefault = ![enable_fullscreen intValue];
 
-    [enable_fullscreen_menu setEnabled:!value];
+    [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
 
-    DarwinSendDDXEvent(kXquartzSetRootless, 1, value);
+    DarwinSendDDXEvent(kXquartzSetRootless, 1, XQuartzRootlessDefault);
 
-    [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:value];
+    [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:XQuartzRootlessDefault];
     [NSApp prefs_synchronize];
 }
 
@@ -638,24 +638,24 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
         darwinFakeButtons = [fake_buttons intValue];
         [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
     } else if(sender == use_sysbeep) {
-        quartzUseSysBeep = [use_sysbeep intValue];
-        [NSApp prefs_set_boolean:@PREFS_SYSBEEP value:quartzUseSysBeep];
+        XQuartzUseSysBeep = [use_sysbeep intValue];
+        [NSApp prefs_set_boolean:@PREFS_SYSBEEP value:XQuartzUseSysBeep];
     } else if(sender == enable_keyequivs) {
-        X11EnableKeyEquivalents =  [enable_keyequivs intValue];
-        [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:X11EnableKeyEquivalents];
+        XQuartzEnableKeyEquivalents =  [enable_keyequivs intValue];
+        [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:XQuartzEnableKeyEquivalents];
     } else if(sender == sync_keymap) {
         darwinSyncKeymap = [sync_keymap intValue];
         [NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
     } else if(sender == enable_fullscreen_menu) {
-        quartzFullscreenMenu = [enable_fullscreen_menu intValue];
-        [NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:quartzFullscreenMenu];
+        XQuartzFullscreenMenu = [enable_fullscreen_menu intValue];
+        [NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:XQuartzFullscreenMenu];
     } else if(sender == option_sends_alt) {
-        BOOL prev_opt_sends_alt = quartzOptionSendsAlt;
+        BOOL prev_opt_sends_alt = XQuartzOptionSendsAlt;
         
-        quartzOptionSendsAlt = [option_sends_alt intValue];
-        [NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:quartzOptionSendsAlt];
+        XQuartzOptionSendsAlt = [option_sends_alt intValue];
+        [NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:XQuartzOptionSendsAlt];
 
-        if(prev_opt_sends_alt != quartzOptionSendsAlt)
+        if(prev_opt_sends_alt != XQuartzOptionSendsAlt)
             QuartsResyncKeymap(TRUE);
     } else if(sender == click_through) {
         [NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:[click_through intValue]];
@@ -701,10 +701,10 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
     BOOL pbproxy_active = [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
     
     [fake_buttons setIntValue:darwinFakeButtons];
-    [use_sysbeep setIntValue:quartzUseSysBeep];
-    [enable_keyequivs setIntValue:X11EnableKeyEquivalents];
+    [use_sysbeep setIntValue:XQuartzUseSysBeep];
+    [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];
     [sync_keymap setIntValue:darwinSyncKeymap];
-    [option_sends_alt setIntValue:quartzOptionSendsAlt];
+    [option_sends_alt setIntValue:XQuartzOptionSendsAlt];
     [click_through setIntValue:[NSApp prefs_get_boolean:@PREFS_CLICK_THROUGH default:NO]];
     [focus_follows_mouse setIntValue:[NSApp prefs_get_boolean:@PREFS_FFM default:NO]];
     [focus_on_new_window setIntValue:[NSApp prefs_get_boolean:@PREFS_FOCUS_ON_NEW_WINDOW default:YES]];
@@ -729,9 +729,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
     [sync_text1 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
     [sync_text2 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
 	
-    [enable_fullscreen setIntValue:!quartzEnableRootless];
-    [enable_fullscreen_menu setEnabled:!quartzEnableRootless];
-    [enable_fullscreen_menu setIntValue:quartzFullscreenMenu];
+    [enable_fullscreen setIntValue:!XQuartzRootlessDefault];
+    [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
+    [enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu];
     
     [prefs_panel makeKeyAndOrderFront:sender];
 }
@@ -752,7 +752,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
   NSMenu *menu = [item menu];
     
   if (item == toggle_fullscreen_item)
-    return !quartzEnableRootless;
+    return !XQuartzIsRootless;
   else if (menu == [X11App windowsMenu] || menu == dock_menu
 	   || (menu == [x11_about_item menu] && [item tag] == 42))
     return (AppleWMSelectedEvents () & AppleWMControllerNotifyMask) != 0;
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 7367068..4332202 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -239,9 +239,9 @@ static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr de
             
         case kXquartzToggleFullscreen:
             DEBUG_LOG("kXquartzToggleFullscreen\n");
-            if(quartzEnableRootless) 
+            if(XQuartzIsRootless)
                 ErrorF("Ignoring kXquartzToggleFullscreen because of rootless mode.");
-            else if (quartzHasRoot)
+            else if (XQuartzHasRoot)
                 QuartzHide();
             else
                 QuartzShow();
@@ -250,7 +250,7 @@ static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr de
         case kXquartzSetRootless:
             DEBUG_LOG("kXquartzSetRootless\n");
             QuartzSetRootless(e->data[0]);
-            if (!quartzEnableRootless && !quartzHasRoot)
+            if (!XQuartzIsRootless && !XQuartzHasRoot)
                 QuartzHide();
             break;
             
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index a52cac9..cd90457 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -66,15 +66,20 @@
 #include <rootlessCommon.h>
 #include <Xplugin.h>
 
-// Shared global variables for Quartz modes
-int                     quartzUseSysBeep = 0;
-int                     quartzServerVisible = FALSE;
 DevPrivateKeyRec        quartzScreenKeyRec;
 int                     aquaMenuBarHeight = 0;
 QuartzModeProcsPtr      quartzProcs = NULL;
 const char             *quartzOpenGLBundle = NULL;
-int                     quartzFullscreenDisableHotkeys = TRUE;
-int                     quartzOptionSendsAlt = FALSE;
+
+Bool XQuartzFullscreenDisableHotkeys = TRUE;
+Bool XQuartzOptionSendsAlt = FALSE;
+Bool XQuartzEnableKeyEquivalents = TRUE;
+Bool XQuartzHasRoot = FALSE;
+Bool XQuartzRootlessDefault = TRUE;
+Bool XQuartzIsRootless = TRUE;
+Bool XQuartzServerVisible = FALSE;
+Bool XQuartzFullscreenMenu = FALSE;
+Bool XQuartzUseSysBeep = FALSE;
 
 /*
 ===========================================================================
@@ -245,61 +250,61 @@ void QuartzSetFullscreen(Bool state) {
     
     DEBUG_LOG("QuartzSetFullscreen: state=%d\n", state);
     
-    if(quartzHasRoot == state)
+    if(XQuartzHasRoot == state)
         return;
     
-    quartzHasRoot = state;
+    XQuartzHasRoot = state;
     
     xp_disable_update ();
     
-    if (!quartzHasRoot && !quartzEnableRootless)
+    if (!XQuartzHasRoot && !XQuartzIsRootless)
         RootlessHideAllWindows();
     
-    RootlessUpdateRooted(quartzHasRoot);
+    RootlessUpdateRooted(XQuartzHasRoot);
     
-    if (quartzHasRoot && !quartzEnableRootless)
+    if (XQuartzHasRoot && !XQuartzIsRootless)
         RootlessShowAllWindows ();
     
-    if (quartzHasRoot || quartzEnableRootless) {
+    if (XQuartzHasRoot || XQuartzIsRootless) {
         RootlessRepositionWindows(screenInfo.screens[0]);
     }
 
     /* Somehow the menubar manages to interfere with our event stream
      * in fullscreen mode, even though it's not visible. 
      */
-    X11ApplicationShowHideMenubar(!quartzHasRoot);
+    X11ApplicationShowHideMenubar(!XQuartzHasRoot);
     
     xp_reenable_update ();
     
-    if (quartzFullscreenDisableHotkeys)
-        xp_disable_hot_keys(quartzHasRoot);
+    if (XQuartzFullscreenDisableHotkeys)
+        xp_disable_hot_keys(XQuartzHasRoot);
 }
 
 void QuartzSetRootless(Bool state) {
-    if(quartzEnableRootless == state)
+    if(XQuartzIsRootless == state)
         return;
     
-    quartzEnableRootless = state;
+    XQuartzIsRootless = state;
 
     xp_disable_update();
 
     /* When in rootless, the menubar is not part of the screen, so we need to update our screens on toggle */    
     QuartzUpdateScreens();
 
-    if(!quartzHasRoot) {
-        if(!quartzEnableRootless) {
+    if(!XQuartzHasRoot) {
+        if(!XQuartzIsRootless) {
             RootlessHideAllWindows();
         } else {
             RootlessShowAllWindows();
         }
     }
 
-    X11ApplicationShowHideMenubar(!quartzHasRoot);
+    X11ApplicationShowHideMenubar(!XQuartzHasRoot);
 
     xp_reenable_update();
 
-    if (!quartzEnableRootless && quartzFullscreenDisableHotkeys)
-        xp_disable_hot_keys(quartzHasRoot);
+    if (!XQuartzIsRootless && XQuartzFullscreenDisableHotkeys)
+        xp_disable_hot_keys(XQuartzHasRoot);
 }
 
 /*
@@ -311,17 +316,17 @@ void QuartzSetRootless(Bool state) {
 void QuartzShow(void) {
     int i;
 
-    if (quartzServerVisible)
+    if (XQuartzServerVisible)
         return;
     
-    quartzServerVisible = TRUE;
+    XQuartzServerVisible = TRUE;
     for (i = 0; i < screenInfo.numScreens; i++) {
         if (screenInfo.screens[i]) {
             quartzProcs->ResumeScreen(screenInfo.screens[i]);
         }
     }
     
-    if (!quartzEnableRootless)
+    if (!XQuartzIsRootless)
         QuartzSetFullscreen(TRUE);
 }
 
@@ -336,7 +341,7 @@ void QuartzHide(void)
 {
     int i;
 
-    if (quartzServerVisible) {
+    if (XQuartzServerVisible) {
         for (i = 0; i < screenInfo.numScreens; i++) {
             if (screenInfo.screens[i]) {
                 quartzProcs->SuspendScreen(screenInfo.screens[i]);
@@ -345,7 +350,7 @@ void QuartzHide(void)
     }
     
     QuartzSetFullscreen(FALSE);
-    quartzServerVisible = FALSE;
+    XQuartzServerVisible = FALSE;
 }
 
 
@@ -358,7 +363,7 @@ void QuartzSetRootClip(
 {
     int i;
 
-    if (!quartzServerVisible)
+    if (!XQuartzServerVisible)
         return;
 
     for (i = 0; i < screenInfo.numScreens; i++) {
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index 1b924e7..a0a17cb 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -35,6 +35,7 @@
 
 #include "screenint.h"
 #include "window.h"
+#include "pixmap.h"
 
 /*------------------------------------------
    Quartz display mode function types
@@ -113,7 +114,20 @@ typedef struct _QuartzModeProcs {
 } QuartzModeProcsRec, *QuartzModeProcsPtr;
 
 extern QuartzModeProcsPtr quartzProcs;
-extern int quartzHasRoot, quartzEnableRootless;
+
+extern Bool XQuartzHasRoot;          /* TODO: These two booleans are very similar and */
+extern Bool XQuartzServerVisible;    /* the code that uses them needs to be refactored
+                                      * XQuartzHasRoot is essentially the "saved" XQuartzServerVisible
+                                      * value from when the server was not in rootless mode.
+                                      */
+
+extern Bool XQuartzEnableKeyEquivalents;
+extern Bool XQuartzRootlessDefault;  /* Is our default mode rootless? */
+extern Bool XQuartzIsRootless;       /* Is our current mode rootless (or FS)? */
+extern Bool XQuartzFullscreenMenu;   /* Show the menu bar (autohide) while in FS */
+extern Bool XQuartzFullscreenDisableHotkeys;
+extern Bool XQuartzOptionSendsAlt;   /* Alt or Mode_switch? */
+extern Bool XQuartzUseSysBeep;       /* Sys beep or our own? */
 
 Bool QuartzAddScreen(int index, ScreenPtr pScreen);
 Bool QuartzSetupScreen(int index, ScreenPtr pScreen);
@@ -129,8 +143,8 @@ void QuartzHide(void);
 void QuartzSetRootClip(BOOL enable);
 void QuartzSpaceChanged(uint32_t space_id);
 
-void QuartzSetFullscreen(Bool state);
 void QuartzSetRootless(Bool state);
+void QuartzSetFullscreen(Bool state);
 
 int server_main(int argc, char **argv, char **envp);
 #endif
diff --git a/hw/xquartz/quartzAudio.c b/hw/xquartz/quartzAudio.c
index 708202b..d0f7c53 100644
--- a/hw/xquartz/quartzAudio.c
+++ b/hw/xquartz/quartzAudio.c
@@ -42,7 +42,7 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
+#include "quartz.h"
 #include "quartzAudio.h"
 
 #include <CoreAudio/CoreAudio.h>
@@ -220,7 +220,7 @@ void DDXRingBell(
     int pitch,          // pitch is Hz
     int duration )      // duration is milliseconds
 {
-    if (quartzUseSysBeep) {
+    if (XQuartzUseSysBeep) {
         if (volume)
             NSBeep();
         return;
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 718df4b..fbfe6f8 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -38,13 +38,7 @@
 #include <X11/Xdefs.h>
 #include "privates.h"
 
-// User preferences used by Quartz modes
-extern int              quartzUseSysBeep;
-extern int              quartzFullscreenDisableHotkeys;
-extern int              quartzOptionSendsAlt;
-
 // Other shared data
-extern int              quartzServerVisible;
 extern DevPrivateKeyRec quartzScreenKeyRec;
 #define quartzScreenKey (&quartzScreenKeyRec)
 extern int              aquaMenuBarHeight;
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 75cf23f..f54c686 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -48,7 +48,7 @@
 #include <sys/stat.h>
 #include <AvailabilityMacros.h>
 
-#include "quartzCommon.h"
+#include "quartz.h"
 #include "darwin.h"
 #include "darwinEvents.h"
 
@@ -262,7 +262,7 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
             case XK_Alt_L:
                 info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i;
                 info->modMap[MIN_KEYCODE + i] = Mod1Mask;
-                if(!quartzOptionSendsAlt)
+                if(!XQuartzOptionSendsAlt)
                     *k = XK_Mode_switch; // Yes, this is ugly.  This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor.
                 break;
 
@@ -272,7 +272,7 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
 #else
                 info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i;
 #endif
-                if(!quartzOptionSendsAlt)
+                if(!XQuartzOptionSendsAlt)
                     *k = XK_Mode_switch; // Yes, this is ugly.  This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor.
                 info->modMap[MIN_KEYCODE + i] = Mod1Mask;
                 break;
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 782aa4d..bbeebda 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -140,7 +140,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
             break;
     }
 
-    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullscreenMode, data)) {
         case CALLBACK_SUCCESS:
             return TRUE;
         case CALLBACK_ERROR:
@@ -239,7 +239,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
             break;
     }
 
-    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullscreenMode, data)) {
         case CALLBACK_SUCCESS:
             return TRUE;
         case CALLBACK_ERROR:
@@ -377,7 +377,7 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
            resolution including/excluding the menu bar. */
 
         QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullscreenMode);
         return TRUE;
     }
 
@@ -434,37 +434,37 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 
     if (pQuartzScreen->displayCount == 1) {
-        if(pQuartzScreen->fullScreenMode.ref)
-            CFRelease(pQuartzScreen->fullScreenMode.ref);
+        if(pQuartzScreen->fullscreenMode.ref)
+            CFRelease(pQuartzScreen->fullscreenMode.ref);
         if(pQuartzScreen->currentMode.ref)
             CFRelease(pQuartzScreen->currentMode.ref);
         
         if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0],
-                                            &pQuartzScreen->fullScreenMode))
+                                            &pQuartzScreen->fullscreenMode))
             return FALSE;
 
-        CFRetain(pQuartzScreen->fullScreenMode.ref);  /* This extra retain is for currentMode's copy */
+        CFRetain(pQuartzScreen->fullscreenMode.ref);  /* This extra retain is for currentMode's copy */
     } else {
-        pQuartzScreen->fullScreenMode.width = pScreen->width;
-        pQuartzScreen->fullScreenMode.height = pScreen->height;
-        if(quartzEnableRootless)
-            pQuartzScreen->fullScreenMode.height += aquaMenuBarHeight;
+        pQuartzScreen->fullscreenMode.width = pScreen->width;
+        pQuartzScreen->fullscreenMode.height = pScreen->height;
+        if(XQuartzIsRootless)
+            pQuartzScreen->fullscreenMode.height += aquaMenuBarHeight;
     }
 
-    pQuartzScreen->fullScreenMode.refresh = FAKE_REFRESH_FULLSCREEN;
+    pQuartzScreen->fullscreenMode.refresh = FAKE_REFRESH_FULLSCREEN;
 
-    pQuartzScreen->rootlessMode = pQuartzScreen->fullScreenMode;
+    pQuartzScreen->rootlessMode = pQuartzScreen->fullscreenMode;
     pQuartzScreen->rootlessMode.refresh = FAKE_REFRESH_ROOTLESS;
     pQuartzScreen->rootlessMode.height -= aquaMenuBarHeight;
 
-    if(quartzEnableRootless) {
+    if(XQuartzIsRootless) {
         pQuartzScreen->currentMode = pQuartzScreen->rootlessMode;
     } else {
-        pQuartzScreen->currentMode = pQuartzScreen->fullScreenMode;
+        pQuartzScreen->currentMode = pQuartzScreen->fullscreenMode;
     }
     
     DEBUG_LOG("rootlessMode: %d x %d\n", (int)pQuartzScreen->rootlessMode.width, (int)pQuartzScreen->rootlessMode.height);
-    DEBUG_LOG("fullScreenMode: %d x %d\n", (int)pQuartzScreen->fullScreenMode.width, (int)pQuartzScreen->fullScreenMode.height);
+    DEBUG_LOG("fullscreenMode: %d x %d\n", (int)pQuartzScreen->fullscreenMode.width, (int)pQuartzScreen->fullscreenMode.height);
     DEBUG_LOG("currentMode: %d x %d\n", (int)pQuartzScreen->currentMode.width, (int)pQuartzScreen->currentMode.height);
     
     return TRUE;
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index 4a7990e..b2d4d09 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -45,7 +45,7 @@ typedef struct {
     // No CG display will be covered by more than one X11 screen.
     int displayCount;
     CGDirectDisplayID *displayIDs;
-    QuartzModeInfo rootlessMode, fullScreenMode, currentMode;
+    QuartzModeInfo rootlessMode, fullscreenMode, currentMode;
 } QuartzScreenRec, *QuartzScreenPtr;
 
 #define QUARTZ_PRIV(pScreen) \
diff --git a/hw/xquartz/xpr/xprAppleWM.c b/hw/xquartz/xpr/xprAppleWM.c
index 4b31e3a..1a3d427 100644
--- a/hw/xquartz/xpr/xprAppleWM.c
+++ b/hw/xquartz/xpr/xprAppleWM.c
@@ -67,7 +67,7 @@ static int xprSetWindowLevel(
     if(!winRec)
         return BadWindow;
     
-    if(quartzEnableRootless)
+    if(XQuartzIsRootless)
         wc.window_level = normal_window_levels[level];
     else
         wc.window_level = rooted_window_levels[level];
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index a106e72..216678e 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -35,7 +35,7 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
+#include "quartz.h"
 #include "xpr.h"
 #include "darwin.h"
 #include "darwinEvents.h"
@@ -226,7 +226,7 @@ QuartzSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
 {
     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
 
-    if (!quartzServerVisible)
+    if (!XQuartzServerVisible)
         return;
 
     if (pCursor == NULL)
@@ -295,7 +295,7 @@ QuartzCrossScreen(ScreenPtr pScreen, Bool entering)
 static void
 QuartzWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
-    if (quartzServerVisible)
+    if (XQuartzServerVisible)
     {
         int sx, sy;
 
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index c78c5bd..8ee3a28 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -171,7 +171,7 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
 
     pFrame->level = !IsRoot (pWin) ? AppleWMWindowLevelNormal : AppleWMNumWindowLevels;
 
-    if(quartzEnableRootless)
+    if(XQuartzIsRootless)
         wc.window_level = normal_window_levels[pFrame->level];
     else
         wc.window_level = rooted_window_levels[pFrame->level];
@@ -285,7 +285,7 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
         RootlessWindowRec *winRec = x_hash_table_lookup(window_hash, wid, NULL);
 
         if(winRec) {
-            if(quartzEnableRootless)
+            if(XQuartzIsRootless)
                 wc.window_level = normal_window_levels[winRec->level];
             else
                 wc.window_level = rooted_window_levels[winRec->level];
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index f7c8642..cba358f 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -158,7 +158,7 @@ displayScreenBounds(CGDirectDisplayID id)
               (int)frame.origin.x, (int)frame.origin.y);
     
     /* Remove menubar to help standard X11 window managers. */
-    if (quartzEnableRootless && 
+    if (XQuartzIsRootless && 
         frame.origin.x == 0 && frame.origin.y == 0) {
         frame.origin.y += aquaMenuBarHeight;
         frame.size.height -= aquaMenuBarHeight;
@@ -274,7 +274,8 @@ xprDisplayInit(void)
     AppleDRIExtensionInit();
     xprAppleWMInit();
 
-    if (!quartzEnableRootless)
+    XQuartzIsRootless = XQuartzRootlessDefault;
+    if (!XQuartzIsRootless)
         RootlessHideAllWindows();
 }
 
commit 721edc69c3597578d3e7f711769ff0195af6068a
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Jul 26 11:45:59 2010 -0700

    XQuartz: RandR: Better handle switching betwen RandR modes that share CG modes
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 65dce22..782aa4d 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -57,9 +57,12 @@ static Bool ignore_next_fake_mode_update = FALSE;
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
 
-typedef Bool (*QuartzModeCallback)
-    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
+#define CALLBACK_SUCCESS 0
+#define CALLBACK_CONTINUE 1
+#define CALLBACK_ERROR -1
 
+typedef int (*QuartzModeCallback)
+    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
 
@@ -97,20 +100,22 @@ static void QuartzRandRGetModeInfo (CFDictionaryRef modeRef,
     pMode->ref = NULL;
 }
 
-static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
+static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
                                            QuartzModeInfoPtr pMode) {
     CFDictionaryRef curModeRef = CGDisplayCurrentMode(screenId);
     if (!curModeRef)
         return FALSE;
 
     QuartzRandRGetModeInfo(curModeRef, pMode);
+    pMode->ref = (void *)curModeRef;
+    CFRetain(pMode->ref);
     return TRUE;
 }
 
 static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
                                 QuartzModeInfoPtr pMode) {
     CFDictionaryRef modeRef = (CFDictionaryRef) pMode->ref;
-    return (CGDisplaySwitchToMode(screenId, modeRef) != kCGErrorSuccess);
+    return (CGDisplaySwitchToMode(screenId, modeRef) == kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -122,6 +127,28 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
+    BOOL retval = TRUE;
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
 
     curModeRef = CGDisplayCurrentMode(screenId);
     if (!curModeRef)
@@ -132,6 +159,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     if (!modes)
         return FALSE;
     for (i = 0; i < CFArrayGetCount(modes); i++) {
+        int cb;
         modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
 
         /* Skip modes that are not usable on the current display or have a
@@ -143,11 +171,16 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
             continue;
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
-        modeInfo.ref = modeRef;
-        if (!callback(pScreen, screenId, &modeInfo, data))
+        modeInfo.ref = (void *)modeRef;
+        cb = callback(pScreen, screenId, &modeInfo, data);
+        if (cb == CALLBACK_SUCCESS)
+            break;
+        if (cb == CALLBACK_ERROR) {
+            retval = FALSE;
             break;
+        }
     }
-    return TRUE;
+    return retval;
 }
 
 #else /* we have the new CG APIs from Snow Leopard */
@@ -162,14 +195,14 @@ static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef,
     pMode->ref = NULL;
 }
 
-static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
-                                           QuartzModeInfoPtr pMode) {
+static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
+                                            QuartzModeInfoPtr pMode) {
     CGDisplayModeRef curModeRef = CGDisplayCopyDisplayMode(screenId);
     if (!curModeRef)
         return FALSE;
 
     QuartzRandRGetModeInfo(curModeRef, pMode);
-    CGDisplayModeRelease(curModeRef);
+    pMode->ref = curModeRef;
     return TRUE;
 }
 
@@ -179,7 +212,7 @@ static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
     if (!modeRef)
         return FALSE;
 
-    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) != kCGErrorSuccess);
+    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) == kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -192,6 +225,29 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
+    Bool retval = TRUE;
+
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
 
     curModeRef = CGDisplayCopyDisplayMode(screenId);
     if (!curModeRef)
@@ -205,6 +261,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
         return FALSE;
     }
     for (i = 0; i < CFArrayGetCount(modes); i++) {
+        int cb;
         modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
 
         /* Skip modes that are not usable on the current display or have a
@@ -220,13 +277,19 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
         modeInfo.ref = modeRef;
-        if (!callback(pScreen, screenId, &modeInfo, data))
+        cb = callback(pScreen, screenId, &modeInfo, data);
+        if (cb == CALLBACK_SUCCESS)
+            break;
+		if (cb == CALLBACK_ERROR) {
+			retval = FALSE;
             break;
+		}
     }
+		
     CFRelease(modes);
 
     CFRelease(curPixelEnc);
-    return TRUE;
+    return retval;
 }
 
 #endif  /* Snow Leopard CoreGraphics APIs */
@@ -246,6 +309,7 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     RRScreenSizePtr pSize = RRRegisterSize(pScreen,
         pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
     if (pSize) {
+        //DEBUG_LOG("registering: %d x %d @ %d %s\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh, isCurrentMode ? "*" : "");
         RRRegisterRate(pScreen, pSize, pMode->refresh);
 
         if (isCurrentMode)
@@ -256,34 +320,46 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     return FALSE;
 }
 
-static Bool QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
+static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
                                         CGDirectDisplayID screenId,
                                         QuartzModeInfoPtr pMode,
                                         void *data __unused) {
-    return QuartzRandRRegisterMode(pScreen, pMode);
+    if(QuartzRandRRegisterMode(pScreen, pMode)) {
+        return CALLBACK_CONTINUE;
+    } else {
+        return CALLBACK_ERROR;
+    }
 }
 
-static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
-                                        CGDirectDisplayID screenId,
-                                        QuartzModeInfoPtr pMode,
-                                        void *data) {
+static int QuartzRandRSetModeCallback (ScreenPtr pScreen,
+                                       CGDirectDisplayID screenId,
+                                       QuartzModeInfoPtr pMode,
+                                       void *data) {
     QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-
+	
     if (!QuartzRandRModesEqual(pMode, pReqMode))
-        return TRUE;  /* continue enumeration */
+        return CALLBACK_CONTINUE;  /* continue enumeration */
+
+    DEBUG_LOG("Found a match for requested RandR resolution (%dx%d@%d).\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh);
 
-    if (pReqMode->ref == pQuartzScreen->currentMode.ref) {
+    if (pQuartzScreen->currentMode.ref && CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) {
         DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
-        return FALSE; /* We don't need to do anything in CG */
+        return CALLBACK_SUCCESS; /* We don't need to do anything in CG */
     }
 
-    if (QuartzRandRSetMode(screenId, pMode) == FALSE) {
+    if (QuartzRandRSetMode(screenId, pMode)) {
+        if(pQuartzScreen->currentMode.ref)
+            CFRelease(pQuartzScreen->currentMode.ref);
+        pQuartzScreen->currentMode = *pMode;
+        CFRetain(pQuartzScreen->currentMode.ref);
+
         ignore_next_fake_mode_update = TRUE;
-        return FALSE;
+        return CALLBACK_SUCCESS;
     } else {
-        return TRUE;
-    };
+        DEBUG_LOG("Error while requesting CG resolution change.\n");
+        return CALLBACK_ERROR;
+    }
 }
 
 static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
@@ -295,17 +371,17 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
 
-    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
-    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
-
     if (pQuartzScreen->displayCount > 1) {
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Create two entries for the current virtual
            resolution including/excluding the menu bar. */
+
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
         return TRUE;
     }
-    screenId = pQuartzScreen->displayIDs[0];
 
+    screenId = pQuartzScreen->displayIDs[0];
     return QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRRegisterModeCallback, NULL);
 }
 
@@ -323,9 +399,14 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
 
     /* If the client requested the fake rootless mode, switch to rootless.
      * Otherwise, force fullscreen mode.
+     * TODO: Refactor all this fullscreen/rootless crap as it is spaghetti
+     *       has redundancies.
      */
-    QuartzSetFullscreen(reqMode.refresh != FAKE_REFRESH_ROOTLESS);
     QuartzSetRootless(reqMode.refresh == FAKE_REFRESH_ROOTLESS);
+    QuartzSetFullscreen(reqMode.refresh != FAKE_REFRESH_ROOTLESS);
+    if(reqMode.refresh != FAKE_REFRESH_ROOTLESS &&
+       reqMode.refresh != FAKE_REFRESH_FULLSCREEN)
+        QuartzShow();
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
@@ -342,12 +423,10 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
         
     screenId = pQuartzScreen->displayIDs[0];
     if (QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRSetModeCallback, &reqMode)) {
-        pQuartzScreen->currentMode = reqMode;
         return TRUE;
     }
     
     DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", (int)reqMode.width, (int)reqMode.height, (int)reqMode.refresh);
-
     return FALSE;
 }
 
@@ -355,9 +434,16 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 
     if (pQuartzScreen->displayCount == 1) {
-        if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
-                                           &pQuartzScreen->fullScreenMode))
+        if(pQuartzScreen->fullScreenMode.ref)
+            CFRelease(pQuartzScreen->fullScreenMode.ref);
+        if(pQuartzScreen->currentMode.ref)
+            CFRelease(pQuartzScreen->currentMode.ref);
+        
+        if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0],
+                                            &pQuartzScreen->fullScreenMode))
             return FALSE;
+
+        CFRetain(pQuartzScreen->fullScreenMode.ref);  /* This extra retain is for currentMode's copy */
     } else {
         pQuartzScreen->fullScreenMode.width = pScreen->width;
         pQuartzScreen->fullScreenMode.height = pScreen->height;
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index 8ee2818..4a7990e 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -34,7 +34,7 @@
 typedef struct {
     size_t width, height;
     int refresh;
-    const void *ref;
+    void *ref; /* CGDisplayModeRef or CFDictionaryRef */
 } QuartzModeInfo, *QuartzModeInfoPtr;
 
 // Quartz specific per screen storage structure
commit 026a47e21226b64eb9a7624ada3d74c3fe5fa763
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Jul 26 01:17:12 2010 -0700

    XQuartz: RandR: Respond better to resolution changes made outside X
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 7b34b8a..7367068 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -52,6 +52,7 @@ in this Software without prior written authorization from The Open Group.
 #include "darwin.h"
 #include "quartz.h"
 #include "quartzKeyboard.h"
+#include "quartzRandR.h"
 #include "darwinEvents.h"
 
 #include <sys/types.h>
@@ -276,7 +277,12 @@ static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr de
             break;
             
         case kXquartzDisplayChanged:
+            DEBUG_LOG("kXquartzDisplayChanged\n");
             QuartzUpdateScreens();
+#ifdef RANDR
+            /* Update our RandR info */
+            QuartzRandRUpdateFakeModes(TRUE);
+#endif
             break;
             
         default:
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 851e74c..718df4b 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -38,29 +38,6 @@
 #include <X11/Xdefs.h>
 #include "privates.h"
 
-typedef struct {
-    size_t width, height;
-    int refresh;
-    const void *ref;
-} QuartzModeInfo, *QuartzModeInfoPtr;
-
-// Quartz specific per screen storage structure
-typedef struct {
-    // List of CoreGraphics displays that this X11 screen covers.
-    // This is more than one CG display for video mirroring and
-    // rootless PseudoramiX mode.
-    // No CG display will be covered by more than one X11 screen.
-    int displayCount;
-    CGDirectDisplayID *displayIDs;
-    QuartzModeInfo originalMode, fakeMode;
-} QuartzScreenRec, *QuartzScreenPtr;
-
-#define QUARTZ_PRIV(pScreen) \
-    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
-
-void QuartzCopyDisplayIDs(ScreenPtr pScreen,
-                          int displayCount, CGDirectDisplayID *displayIDs);
-
 // User preferences used by Quartz modes
 extern int              quartzUseSysBeep;
 extern int              quartzFullscreenDisableHotkeys;
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index e46e904..65dce22 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -38,6 +38,7 @@
 #include "quartzCommon.h"
 #include "quartzRandR.h"
 #include "quartz.h"
+#include "darwin.h"
 
 #include <AvailabilityMacros.h>
 
@@ -45,6 +46,13 @@
 #include <randrstr.h>
 #include <IOKit/graphics/IOGraphicsTypes.h>
 
+/* TODO: UGLY, find a better way!
+ * We want to ignore kXquartzDisplayChanged which are generated by us
+ */
+static Bool ignore_next_fake_mode_update = FALSE;
+
+#define FAKE_REFRESH_ROOTLESS 1
+#define FAKE_REFRESH_FULLSCREEN 2
 
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
@@ -171,8 +179,7 @@ static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
     if (!modeRef)
         return FALSE;
 
-    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) !=
-            kCGErrorSuccess);
+    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) != kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -227,18 +234,15 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
 static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
                                    QuartzModeInfoPtr pMode2) {
-    if (pMode1->width != pMode2->width)
-        return FALSE;
-    if (pMode1->height != pMode2->height)
-        return FALSE;
-    if (pMode1->refresh != pMode2->refresh)
-        return FALSE;
-    return TRUE;
+    return (pMode1->width == pMode2->width) &&
+           (pMode1->height == pMode2->height) &&
+           (pMode1->refresh == pMode2->refresh);
 }
 
 static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
-                                     QuartzModeInfoPtr pMode,
-                                     Bool isCurrentMode) {
+                                     QuartzModeInfoPtr pMode) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    Bool isCurrentMode = QuartzRandRModesEqual(&pQuartzScreen->currentMode, pMode);
     RRScreenSizePtr pSize = RRRegisterSize(pScreen,
         pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
     if (pSize) {
@@ -252,14 +256,11 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     return FALSE;
 }
 
-static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
+static Bool QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
                                         CGDirectDisplayID screenId,
                                         QuartzModeInfoPtr pMode,
-                                        void *data) {
-    QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
-
-    return QuartzRandRRegisterMode(pScreen, pMode,
-        QuartzRandRModesEqual(pMode, pCurMode));
+                                        void *data __unused) {
+    return QuartzRandRRegisterMode(pScreen, pMode);
 }
 
 static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
@@ -267,73 +268,64 @@ static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
                                         QuartzModeInfoPtr pMode,
                                         void *data) {
     QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 
     if (!QuartzRandRModesEqual(pMode, pReqMode))
         return TRUE;  /* continue enumeration */
 
-    return QuartzRandRSetMode(screenId, pMode);
+    if (pReqMode->ref == pQuartzScreen->currentMode.ref) {
+        DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
+        return FALSE; /* We don't need to do anything in CG */
+    }
+
+    if (QuartzRandRSetMode(screenId, pMode) == FALSE) {
+        ignore_next_fake_mode_update = TRUE;
+        return FALSE;
+    } else {
+        return TRUE;
+    };
 }
 
 static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     CGDirectDisplayID screenId;
-    QuartzModeInfo curMode;
 
     *rotations = RR_Rotate_0;  /* TODO: support rotation */
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
+
+    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
+    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
+
     if (pQuartzScreen->displayCount > 1) {
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Create two entries for the current virtual
            resolution including/excluding the menu bar. */
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode,
-            !quartzHasRoot);
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->originalMode,
-            quartzHasRoot);
         return TRUE;
     }
     screenId = pQuartzScreen->displayIDs[0];
 
-    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
-        return FALSE;
-
-    /* Add a fake mode corresponding to the original resolution excluding the
-       height of the menu bar. */
-    if (!quartzHasRoot &&
-        QuartzRandRModesEqual(&pQuartzScreen->originalMode, &curMode)) {
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, TRUE);
-        curMode = pQuartzScreen->fakeMode;
-    }
-    else
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, FALSE);
-
-    return QuartzRandREnumerateModes(pScreen, screenId,
-        QuartzRandRGetModeCallback, &curMode);
+    return QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRRegisterModeCallback, NULL);
 }
 
 static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
-			          Rotation            randr,
-			          int                 rate,
-			          RRScreenSizePtr     pSize) {
+                                  Rotation            randr,
+                                  int                 rate,
+                                  RRScreenSizePtr     pSize) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     CGDirectDisplayID screenId;
-    QuartzModeInfo reqMode, curMode;
-    Bool rootless = FALSE;
+    QuartzModeInfo reqMode;
 
     reqMode.width = pSize->width;
     reqMode.height = pSize->height;
     reqMode.refresh = rate;
 
-    /* If the client requested the fake screen mode, switch to rootless mode.
-       Switch to fullscreen mode (root window visible) if a real screen mode was
-       requested. */
-    if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->fakeMode)) {
-        rootless = TRUE;
-        reqMode = pQuartzScreen->originalMode;
-    }
-    QuartzSetFullscreen(!rootless);
-    QuartzSetRootless(rootless);
+    /* If the client requested the fake rootless mode, switch to rootless.
+     * Otherwise, force fullscreen mode.
+     */
+    QuartzSetFullscreen(reqMode.refresh != FAKE_REFRESH_ROOTLESS);
+    QuartzSetRootless(reqMode.refresh == FAKE_REFRESH_ROOTLESS);
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
@@ -341,38 +333,80 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Do not accept any configuations that differ
            from the current configuration. */
-        return QuartzRandRModesEqual(&reqMode, &pQuartzScreen->originalMode);
+        return TRUE;
     }
-    screenId = pQuartzScreen->displayIDs[0];
 
     /* Do not switch modes if requested mode is equal to current mode. */
-    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
-        return FALSE;
-    if (QuartzRandRModesEqual(&reqMode, &curMode))
+    if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->currentMode))
         return TRUE;
+        
+    screenId = pQuartzScreen->displayIDs[0];
+    if (QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRSetModeCallback, &reqMode)) {
+        pQuartzScreen->currentMode = reqMode;
+        return TRUE;
+    }
+    
+    DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", (int)reqMode.width, (int)reqMode.height, (int)reqMode.refresh);
 
-    return QuartzRandREnumerateModes(pScreen, screenId,
-        QuartzRandRSetModeCallback, &reqMode);
+    return FALSE;
 }
 
-Bool QuartzRandRInit (ScreenPtr pScreen) {
-    rrScrPrivPtr    pScrPriv;
+static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-    
-    if (!RRScreenInit (pScreen)) return FALSE;
 
     if (pQuartzScreen->displayCount == 1) {
         if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
-                                           &pQuartzScreen->originalMode))
+                                           &pQuartzScreen->fullScreenMode))
             return FALSE;
+    } else {
+        pQuartzScreen->fullScreenMode.width = pScreen->width;
+        pQuartzScreen->fullScreenMode.height = pScreen->height;
+        if(quartzEnableRootless)
+            pQuartzScreen->fullScreenMode.height += aquaMenuBarHeight;
     }
-    else {
-        pQuartzScreen->originalMode.width = pScreen->width;
-        pQuartzScreen->originalMode.height = pScreen->height;
-        pQuartzScreen->originalMode.refresh = DEFAULT_REFRESH;
+
+    pQuartzScreen->fullScreenMode.refresh = FAKE_REFRESH_FULLSCREEN;
+
+    pQuartzScreen->rootlessMode = pQuartzScreen->fullScreenMode;
+    pQuartzScreen->rootlessMode.refresh = FAKE_REFRESH_ROOTLESS;
+    pQuartzScreen->rootlessMode.height -= aquaMenuBarHeight;
+
+    if(quartzEnableRootless) {
+        pQuartzScreen->currentMode = pQuartzScreen->rootlessMode;
+    } else {
+        pQuartzScreen->currentMode = pQuartzScreen->fullScreenMode;
     }
-    pQuartzScreen->fakeMode = pQuartzScreen->originalMode;
-    pQuartzScreen->fakeMode.height -= aquaMenuBarHeight;
+    
+    DEBUG_LOG("rootlessMode: %d x %d\n", (int)pQuartzScreen->rootlessMode.width, (int)pQuartzScreen->rootlessMode.height);
+    DEBUG_LOG("fullScreenMode: %d x %d\n", (int)pQuartzScreen->fullScreenMode.width, (int)pQuartzScreen->fullScreenMode.height);
+    DEBUG_LOG("currentMode: %d x %d\n", (int)pQuartzScreen->currentMode.width, (int)pQuartzScreen->currentMode.height);
+    
+    return TRUE;
+}
+
+Bool QuartzRandRUpdateFakeModes (BOOL force_update) {
+    ScreenPtr pScreen = screenInfo.screens[0];
+    
+    if(ignore_next_fake_mode_update) {
+        DEBUG_LOG("Ignoring update request caused by RandR resolution change.\n");
+        ignore_next_fake_mode_update = FALSE;
+        return TRUE;
+    }
+    
+    if(!_QuartzRandRUpdateFakeModes(pScreen))
+        return FALSE;
+    
+    if(force_update)
+        RRGetInfo(pScreen, TRUE);
+
+    return TRUE;
+}
+
+Bool QuartzRandRInit (ScreenPtr pScreen) {
+    rrScrPrivPtr    pScrPriv;
+    
+    if (!RRScreenInit (pScreen)) return FALSE;
+    if (!_QuartzRandRUpdateFakeModes (pScreen)) return FALSE;
 
     pScrPriv = rrGetScrPriv(pScreen);
     pScrPriv->rrGetInfo = QuartzRandRGetInfo;
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index d57dc3b..8ee2818 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -31,6 +31,30 @@
 #ifndef _QUARTZRANDR_H_
 #define _QUARTZRANDR_H_
 
+typedef struct {
+    size_t width, height;
+    int refresh;
+    const void *ref;
+} QuartzModeInfo, *QuartzModeInfoPtr;
+
+// Quartz specific per screen storage structure
+typedef struct {
+    // List of CoreGraphics displays that this X11 screen covers.
+    // This is more than one CG display for video mirroring and
+    // rootless PseudoramiX mode.
+    // No CG display will be covered by more than one X11 screen.
+    int displayCount;
+    CGDirectDisplayID *displayIDs;
+    QuartzModeInfo rootlessMode, fullScreenMode, currentMode;
+} QuartzScreenRec, *QuartzScreenPtr;
+
+#define QUARTZ_PRIV(pScreen) \
+    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
+
+void QuartzCopyDisplayIDs(ScreenPtr pScreen,
+                          int displayCount, CGDirectDisplayID *displayIDs);
+
+Bool QuartzRandRUpdateFakeModes (BOOL force_update);
 Bool QuartzRandRInit (ScreenPtr pScreen);
 
 #endif
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 4df0373..f7c8642 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -36,6 +36,7 @@
 #include "quartzCommon.h"
 #include "inputstr.h"
 #include "quartz.h"
+#include "quartzRandR.h"
 #include "xpr.h"
 #include "xprEvent.h"
 #include "pseudoramiX.h"
commit 59cd93f48a3a0a34781d4a94a3cd05a575e2d4ba
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sun Jul 25 22:25:49 2010 -0700

    XQuartz: RandR: Use deprecated CG APIs only on Leopard and earlier
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index b3b315c..e46e904 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -1,9 +1,9 @@
 /*
- *
  * Quartz-specific support for the XRandR extension
  *
  * Copyright (c) 2001-2004 Greg Parker and Torrey T. Lyons,
  *               2010      Jan Hauffa.
+ *               2010      Apple Inc.
  *                 All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -39,6 +39,8 @@
 #include "quartzRandR.h"
 #include "quartz.h"
 
+#include <AvailabilityMacros.h>
+
 #include <X11/extensions/randr.h>
 #include <randrstr.h>
 #include <IOKit/graphics/IOGraphicsTypes.h>
@@ -51,7 +53,7 @@ typedef Bool (*QuartzModeCallback)
     (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
 
 
-#if defined(USE_DEPRECATED_CG_API)
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
 
 static long getDictLong (CFDictionaryRef dictRef, CFStringRef key) {
     long value;
@@ -140,7 +142,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     return TRUE;
 }
 
-#else  /* defined(USE_DEPRECATED_CG_API) */
+#else /* we have the new CG APIs from Snow Leopard */
 
 static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef,
                                     QuartzModeInfoPtr pMode) {
@@ -220,7 +222,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     return TRUE;
 }
 
-#endif  /* defined(USE_DEPRECATED_CG_API) */
+#endif  /* Snow Leopard CoreGraphics APIs */
 
 
 static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index 711c3f3..d57dc3b 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -2,6 +2,7 @@
  * quartzRandR.h
  *
  * Copyright (c) 2010 Jan Hauffa.
+ *               2010 Apple Inc.
  *                 All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,6 +28,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
-#define USE_DEPRECATED_CG_API 1
+#ifndef _QUARTZRANDR_H_
+#define _QUARTZRANDR_H_
 
 Bool QuartzRandRInit (ScreenPtr pScreen);
+
+#endif
commit 629c3f473b7415069a87ef4717ec3d701978dc48
Author: Jan Hauffa <hauffa at in.tum.de>
Date:   Fri Jul 16 17:56:44 2010 +0200

    XQuartz: RandR: Remove FAKE_RANDR code.
    
    Signed-off-by: Jan Hauffa <hauffa at in.tum.de>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index a4d7474..a52cac9 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -119,7 +119,7 @@ Bool QuartzSetupScreen(
     if (! quartzProcs->InitCursor(pScreen))
         return FALSE;
 
-#if defined(RANDR) && !defined(FAKE_RANDR)
+#if defined(RANDR)
     if(!QuartzRandRInit(pScreen)) {
         DEBUG_LOG("Failed to init RandR extension.\n");
         return FALSE;
@@ -239,10 +239,6 @@ void QuartzUpdateScreens(void) {
     DeliverEvents(pRoot, &e, 1, NullWindow);
 
     quartzProcs->UpdateScreen(pScreen);
-    
-#ifdef FAKE_RANDR
-    RREditConnectionInfo(pScreen);
-#endif    
 }
 
 void QuartzSetFullscreen(Bool state) {
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index f61ff93..b3b315c 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -39,60 +39,10 @@
 #include "quartzRandR.h"
 #include "quartz.h"
 
-#if defined(FAKE_RANDR)
-#include "scrnintstr.h"
-#include "windowstr.h"
-#else
 #include <X11/extensions/randr.h>
 #include <randrstr.h>
 #include <IOKit/graphics/IOGraphicsTypes.h>
-#endif
-
-
-#if defined(FAKE_RANDR)
-
-static const int padlength[4] = {0, 3, 2, 1};
-
-void
-RREditConnectionInfo (ScreenPtr pScreen)
-{
-    xConnSetup	    *connSetup;
-    char	    *vendor;
-    xPixmapFormat   *formats;
-    xWindowRoot	    *root;
-    xDepth	    *depth;
-    xVisualType	    *visual;
-    int		    screen = 0;
-    int		    d;
-
-    connSetup = (xConnSetup *) ConnectionInfo;
-    vendor = (char *) connSetup + sizeof (xConnSetup);
-    formats = (xPixmapFormat *) ((char *) vendor +
-				 connSetup->nbytesVendor +
-				 padlength[connSetup->nbytesVendor & 3]);
-    root = (xWindowRoot *) ((char *) formats +
-			    sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
-    while (screen != pScreen->myNum)
-    {
-	depth = (xDepth *) ((char *) root + 
-			    sizeof (xWindowRoot));
-	for (d = 0; d < root->nDepths; d++)
-	{
-	    visual = (xVisualType *) ((char *) depth +
-				      sizeof (xDepth));
-	    depth = (xDepth *) ((char *) visual +
-				depth->nVisuals * sizeof (xVisualType));
-	}
-	root = (xWindowRoot *) ((char *) depth);
-	screen++;
-    }
-    root->pixWidth = pScreen->width;
-    root->pixHeight = pScreen->height;
-    root->mmWidth = pScreen->mmWidth;
-    root->mmHeight = pScreen->mmHeight;
-}
 
-#else  /* defined(FAKE_RANDR) */
 
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
@@ -427,5 +377,3 @@ Bool QuartzRandRInit (ScreenPtr pScreen) {
     pScrPriv->rrSetConfig = QuartzRandRSetConfig;
     return TRUE;
 }
-
-#endif  /* defined(FAKE_RANDR) */
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index a190205..711c3f3 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -27,11 +27,6 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
-/*define FAKE_RANDR 1*/
 #define USE_DEPRECATED_CG_API 1
 
-#if defined(FAKE_RANDR)
-void RREditConnectionInfo (ScreenPtr pScreen);
-#else
 Bool QuartzRandRInit (ScreenPtr pScreen);
-#endif
commit 97b5f5306437bfd13390485fc7a58a363c261ec9
Author: Jan Hauffa <hauffa at in.tum.de>
Date:   Fri Jul 16 17:54:55 2010 +0200

    XQuartz: RandR: Toggle rootless mode on XRandR mode switch.
    
    Report a fake screen mode that corresponds to the screen mode at startup of the
    server excluding the height of the menu bar. If a client requests this mode,
    rootless mode is enabled. In all other modes, the root window is shown.
    
    Signed-off-by: Jan Hauffa <hauffa at in.tum.de>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index d0d358b..851e74c 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -38,6 +38,12 @@
 #include <X11/Xdefs.h>
 #include "privates.h"
 
+typedef struct {
+    size_t width, height;
+    int refresh;
+    const void *ref;
+} QuartzModeInfo, *QuartzModeInfoPtr;
+
 // Quartz specific per screen storage structure
 typedef struct {
     // List of CoreGraphics displays that this X11 screen covers.
@@ -46,6 +52,7 @@ typedef struct {
     // No CG display will be covered by more than one X11 screen.
     int displayCount;
     CGDirectDisplayID *displayIDs;
+    QuartzModeInfo originalMode, fakeMode;
 } QuartzScreenRec, *QuartzScreenPtr;
 
 #define QUARTZ_PRIV(pScreen) \
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 6747752..f61ff93 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -37,6 +37,7 @@
 
 #include "quartzCommon.h"
 #include "quartzRandR.h"
+#include "quartz.h"
 
 #if defined(FAKE_RANDR)
 #include "scrnintstr.h"
@@ -96,12 +97,6 @@ RREditConnectionInfo (ScreenPtr pScreen)
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
 
-typedef struct {
-    size_t width, height;
-    int refresh;
-    const void *ref;
-} QuartzModeInfo, *QuartzModeInfoPtr;
-
 typedef Bool (*QuartzModeCallback)
     (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
 
@@ -289,21 +284,30 @@ static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
     return TRUE;
 }
 
-static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
-                                        CGDirectDisplayID screenId,
-                                        QuartzModeInfoPtr pMode,
-                                        void *data) {
-    QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
-
+static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
+                                     QuartzModeInfoPtr pMode,
+                                     Bool isCurrentMode) {
     RRScreenSizePtr pSize = RRRegisterSize(pScreen,
         pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
     if (pSize) {
         RRRegisterRate(pScreen, pSize, pMode->refresh);
 
-        if (QuartzRandRModesEqual(pMode, pCurMode))
+        if (isCurrentMode)
             RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pSize);
+
+        return TRUE;
     }
-    return TRUE;
+    return FALSE;
+}
+
+static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
+                                        CGDirectDisplayID screenId,
+                                        QuartzModeInfoPtr pMode,
+                                        void *data) {
+    QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
+
+    return QuartzRandRRegisterMode(pScreen, pMode,
+        QuartzRandRModesEqual(pMode, pCurMode));
 }
 
 static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
@@ -329,20 +333,29 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
         return FALSE;
     if (pQuartzScreen->displayCount > 1) {
         /* RandR operations are not well-defined for an X11 screen spanning
-           multiple CG displays. Create a single entry for the current virtual
-           resolution. */
-        RRScreenSizePtr pSize = RRRegisterSize(pScreen, pScreen->width,
-            pScreen->height, pScreen->mmWidth, pScreen->mmHeight);
-        if (pSize) {
-            RRRegisterRate(pScreen, pSize, DEFAULT_REFRESH);
-            RRSetCurrentConfig(pScreen, RR_Rotate_0, DEFAULT_REFRESH, pSize);
-        }
+           multiple CG displays. Create two entries for the current virtual
+           resolution including/excluding the menu bar. */
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode,
+            !quartzHasRoot);
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->originalMode,
+            quartzHasRoot);
         return TRUE;
     }
     screenId = pQuartzScreen->displayIDs[0];
 
     if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
         return FALSE;
+
+    /* Add a fake mode corresponding to the original resolution excluding the
+       height of the menu bar. */
+    if (!quartzHasRoot &&
+        QuartzRandRModesEqual(&pQuartzScreen->originalMode, &curMode)) {
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, TRUE);
+        curMode = pQuartzScreen->fakeMode;
+    }
+    else
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, FALSE);
+
     return QuartzRandREnumerateModes(pScreen, screenId,
         QuartzRandRGetModeCallback, &curMode);
 }
@@ -354,6 +367,21 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     CGDirectDisplayID screenId;
     QuartzModeInfo reqMode, curMode;
+    Bool rootless = FALSE;
+
+    reqMode.width = pSize->width;
+    reqMode.height = pSize->height;
+    reqMode.refresh = rate;
+
+    /* If the client requested the fake screen mode, switch to rootless mode.
+       Switch to fullscreen mode (root window visible) if a real screen mode was
+       requested. */
+    if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->fakeMode)) {
+        rootless = TRUE;
+        reqMode = pQuartzScreen->originalMode;
+    }
+    QuartzSetFullscreen(!rootless);
+    QuartzSetRootless(rootless);
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
@@ -361,15 +389,10 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Do not accept any configuations that differ
            from the current configuration. */
-        return ((pSize->width == pScreen->width) &&
-                (pSize->height == pScreen->height));
+        return QuartzRandRModesEqual(&reqMode, &pQuartzScreen->originalMode);
     }
     screenId = pQuartzScreen->displayIDs[0];
 
-    reqMode.width = pSize->width;
-    reqMode.height = pSize->height;
-    reqMode.refresh = rate;
-
     /* Do not switch modes if requested mode is equal to current mode. */
     if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
         return FALSE;
@@ -382,9 +405,23 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
 
 Bool QuartzRandRInit (ScreenPtr pScreen) {
     rrScrPrivPtr    pScrPriv;
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     
     if (!RRScreenInit (pScreen)) return FALSE;
 
+    if (pQuartzScreen->displayCount == 1) {
+        if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
+                                           &pQuartzScreen->originalMode))
+            return FALSE;
+    }
+    else {
+        pQuartzScreen->originalMode.width = pScreen->width;
+        pQuartzScreen->originalMode.height = pScreen->height;
+        pQuartzScreen->originalMode.refresh = DEFAULT_REFRESH;
+    }
+    pQuartzScreen->fakeMode = pQuartzScreen->originalMode;
+    pQuartzScreen->fakeMode.height -= aquaMenuBarHeight;
+
     pScrPriv = rrGetScrPriv(pScreen);
     pScrPriv->rrGetInfo = QuartzRandRGetInfo;
     pScrPriv->rrSetConfig = QuartzRandRSetConfig;
commit 2d411472c2915614bdeb8fdc15d19dae4621444d
Author: Jan Hauffa <hauffa at in.tum.de>
Date:   Fri Jul 16 17:18:03 2010 +0200

    XQuartz: RandR: Implement basic RandR functionality.
    
    Querying and changing of resolution and refresh rate is supported,
    rotation is not implemented yet.
    
    Signed-off-by: Jan Hauffa <hauffa at in.tum.de>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 96b139f..721d272 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -34,6 +34,7 @@ libXquartz_la_SOURCES = \
 	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzStartup.c \
+	quartzRandR.c \
 	threadSafety.c
 
 EXTRA_DIST = \
@@ -49,6 +50,7 @@ EXTRA_DIST = \
 	quartzAudio.h \
 	quartzCommon.h \
 	quartzKeyboard.h \
+	quartzRandR.h \
 	sanitizedCarbon.h \
 	sanitizedCocoa.h \
 	threadSafety.h
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index eee6151..a4d7474 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -35,6 +35,7 @@
 #endif
 
 #include "quartzCommon.h"
+#include "quartzRandR.h"
 #include "inputstr.h"
 #include "quartz.h"
 #include "darwin.h"
@@ -46,7 +47,6 @@
 #include "X11Application.h"
 
 #include <X11/extensions/applewmconst.h>
-#include <X11/extensions/randr.h>
 
 // X headers
 #include "scrnintstr.h"
@@ -56,6 +56,8 @@
 #include "mi.h"
 
 // System headers
+#include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -64,8 +66,6 @@
 #include <rootlessCommon.h>
 #include <Xplugin.h>
 
-#define FAKE_RANDR 1
-
 // Shared global variables for Quartz modes
 int                     quartzUseSysBeep = 0;
 int                     quartzServerVisible = FALSE;
@@ -76,30 +76,6 @@ const char             *quartzOpenGLBundle = NULL;
 int                     quartzFullscreenDisableHotkeys = TRUE;
 int                     quartzOptionSendsAlt = FALSE;
 
-#if defined(RANDR) && !defined(FAKE_RANDR)
-Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
-  return FALSE;
-}
-
-Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
-			       Rotation            randr,
-			       int                 rate,
-			       RRScreenSizePtr     pSize) {
-  return FALSE;
-}
-
-Bool QuartzRandRInit (ScreenPtr pScreen) {
-  rrScrPrivPtr    pScrPriv;
-    
-  if (!RRScreenInit (pScreen)) return FALSE;
-
-  pScrPriv = rrGetScrPriv(pScreen);
-  pScrPriv->rrGetInfo = QuartzRandRGetInfo;
-  pScrPriv->rrSetConfig = QuartzRandRSetConfig;
-  return TRUE;
-}
-#endif
-
 /*
 ===========================================================================
 
@@ -143,6 +119,13 @@ Bool QuartzSetupScreen(
     if (! quartzProcs->InitCursor(pScreen))
         return FALSE;
 
+#if defined(RANDR) && !defined(FAKE_RANDR)
+    if(!QuartzRandRInit(pScreen)) {
+        DEBUG_LOG("Failed to init RandR extension.\n");
+        return FALSE;
+    }
+#endif
+
     return TRUE;
 }
 
@@ -165,11 +148,6 @@ void QuartzInitOutput(
     if (!dixRegisterPrivateKey(&quartzScreenKeyRec, PRIVATE_SCREEN, 0))
 	FatalError("Failed to alloc quartz screen private.\n");
 
-#if defined(RANDR) && !defined(FAKE_RANDR)
-    if(!QuartzRandRInit(pScreen))
-        FatalError("Failed to init RandR extension.\n");
-#endif
-
     // Do display mode specific initialization
     quartzProcs->DisplayInit();
 }
@@ -191,50 +169,6 @@ void QuartzInitInput(
 }
 
 
-#ifdef FAKE_RANDR
-
-static const int padlength[4] = {0, 3, 2, 1};
-
-static void
-RREditConnectionInfo (ScreenPtr pScreen)
-{
-    xConnSetup	    *connSetup;
-    char	    *vendor;
-    xPixmapFormat   *formats;
-    xWindowRoot	    *root;
-    xDepth	    *depth;
-    xVisualType	    *visual;
-    int		    screen = 0;
-    int		    d;
-
-    connSetup = (xConnSetup *) ConnectionInfo;
-    vendor = (char *) connSetup + sizeof (xConnSetup);
-    formats = (xPixmapFormat *) ((char *) vendor +
-				 connSetup->nbytesVendor +
-				 padlength[connSetup->nbytesVendor & 3]);
-    root = (xWindowRoot *) ((char *) formats +
-			    sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
-    while (screen != pScreen->myNum)
-    {
-	depth = (xDepth *) ((char *) root + 
-			    sizeof (xWindowRoot));
-	for (d = 0; d < root->nDepths; d++)
-	{
-	    visual = (xVisualType *) ((char *) depth +
-				      sizeof (xDepth));
-	    depth = (xDepth *) ((char *) visual +
-				depth->nVisuals * sizeof (xVisualType));
-	}
-	root = (xWindowRoot *) ((char *) depth);
-	screen++;
-    }
-    root->pixWidth = pScreen->width;
-    root->pixHeight = pScreen->height;
-    root->mmWidth = pScreen->mmWidth;
-    root->mmHeight = pScreen->mmHeight;
-}
-#endif
-
 void QuartzUpdateScreens(void) {
     ScreenPtr pScreen;
     WindowPtr pRoot;
@@ -255,7 +189,7 @@ void QuartzUpdateScreens(void) {
     pScreen = screenInfo.screens[0];
     
     PseudoramiXResetScreens();
-    quartzProcs->AddPseudoramiXScreens(&x, &y, &width, &height);
+    quartzProcs->AddPseudoramiXScreens(&x, &y, &width, &height, pScreen);
     
     pScreen->x = x;
     pScreen->y = y;
@@ -446,3 +380,19 @@ void QuartzSpaceChanged(uint32_t space_id) {
     /* Do something special here, so we don't depend on quartz-wm for spaces to work... */
     DEBUG_LOG("Space Changed (%u) ... do something interesting...\n", space_id);
 }
+
+/*
+ * QuartzCopyDisplayIDs
+ *  Associate an X11 screen with one or more CoreGraphics display IDs by copying
+ *  the list into a private array. Free the previously copied array, if present.
+ */
+void QuartzCopyDisplayIDs(ScreenPtr pScreen,
+                          int displayCount, CGDirectDisplayID *displayIDs) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    int size = displayCount * sizeof(CGDirectDisplayID);
+
+    free(pQuartzScreen->displayIDs);
+    pQuartzScreen->displayIDs = malloc(size);
+    memcpy(pQuartzScreen->displayIDs, displayIDs, size);
+    pQuartzScreen->displayCount = displayCount;
+}
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index b1a3f31..1b924e7 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -62,7 +62,8 @@ typedef void (*ResumeScreenProc)(ScreenPtr pScreen);
 /*
  * Screen state change support
  */
-typedef void (*AddPseudoramiXScreensProc)(int *x, int *y, int *width, int *height);
+typedef void (*AddPseudoramiXScreensProc)
+    (int *x, int *y, int *width, int *height, ScreenPtr pScreen);
 typedef void (*UpdateScreenProc)(ScreenPtr pScreen);
 
 /*
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index eb761ed..d0d358b 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -51,6 +51,9 @@ typedef struct {
 #define QUARTZ_PRIV(pScreen) \
     ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
 
+void QuartzCopyDisplayIDs(ScreenPtr pScreen,
+                          int displayCount, CGDirectDisplayID *displayIDs);
+
 // User preferences used by Quartz modes
 extern int              quartzUseSysBeep;
 extern int              quartzFullscreenDisableHotkeys;
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
new file mode 100644
index 0000000..6747752
--- /dev/null
+++ b/hw/xquartz/quartzRandR.c
@@ -0,0 +1,394 @@
+/*
+ *
+ * Quartz-specific support for the XRandR extension
+ *
+ * Copyright (c) 2001-2004 Greg Parker and Torrey T. Lyons,
+ *               2010      Jan Hauffa.
+ *                 All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written authorization.
+ */
+
+#include "sanitizedCarbon.h"
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "quartzCommon.h"
+#include "quartzRandR.h"
+
+#if defined(FAKE_RANDR)
+#include "scrnintstr.h"
+#include "windowstr.h"
+#else
+#include <X11/extensions/randr.h>
+#include <randrstr.h>
+#include <IOKit/graphics/IOGraphicsTypes.h>
+#endif
+
+
+#if defined(FAKE_RANDR)
+
+static const int padlength[4] = {0, 3, 2, 1};
+
+void
+RREditConnectionInfo (ScreenPtr pScreen)
+{
+    xConnSetup	    *connSetup;
+    char	    *vendor;
+    xPixmapFormat   *formats;
+    xWindowRoot	    *root;
+    xDepth	    *depth;
+    xVisualType	    *visual;
+    int		    screen = 0;
+    int		    d;
+
+    connSetup = (xConnSetup *) ConnectionInfo;
+    vendor = (char *) connSetup + sizeof (xConnSetup);
+    formats = (xPixmapFormat *) ((char *) vendor +
+				 connSetup->nbytesVendor +
+				 padlength[connSetup->nbytesVendor & 3]);
+    root = (xWindowRoot *) ((char *) formats +
+			    sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
+    while (screen != pScreen->myNum)
+    {
+	depth = (xDepth *) ((char *) root + 
+			    sizeof (xWindowRoot));
+	for (d = 0; d < root->nDepths; d++)
+	{
+	    visual = (xVisualType *) ((char *) depth +
+				      sizeof (xDepth));
+	    depth = (xDepth *) ((char *) visual +
+				depth->nVisuals * sizeof (xVisualType));
+	}
+	root = (xWindowRoot *) ((char *) depth);
+	screen++;
+    }
+    root->pixWidth = pScreen->width;
+    root->pixHeight = pScreen->height;
+    root->mmWidth = pScreen->mmWidth;
+    root->mmHeight = pScreen->mmHeight;
+}
+
+#else  /* defined(FAKE_RANDR) */
+
+#define DEFAULT_REFRESH  60
+#define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
+
+typedef struct {
+    size_t width, height;
+    int refresh;
+    const void *ref;
+} QuartzModeInfo, *QuartzModeInfoPtr;
+
+typedef Bool (*QuartzModeCallback)
+    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
+
+
+#if defined(USE_DEPRECATED_CG_API)
+
+static long getDictLong (CFDictionaryRef dictRef, CFStringRef key) {
+    long value;
+
+    CFNumberRef numRef = (CFNumberRef) CFDictionaryGetValue(dictRef, key);
+    if (!numRef)
+        return 0;
+
+    if (!CFNumberGetValue(numRef, kCFNumberLongType, &value))
+        return 0;
+    return value;
+}
+
+static double getDictDouble (CFDictionaryRef dictRef, CFStringRef key) {
+    double value;
+
+    CFNumberRef numRef = (CFNumberRef) CFDictionaryGetValue(dictRef, key);
+    if (!numRef)
+        return 0.0;
+
+    if (!CFNumberGetValue(numRef, kCFNumberDoubleType, &value))
+        return 0.0;
+    return value;
+}
+
+static void QuartzRandRGetModeInfo (CFDictionaryRef modeRef,
+                                    QuartzModeInfoPtr pMode) {
+    pMode->width = (size_t) getDictLong(modeRef, kCGDisplayWidth);
+    pMode->height = (size_t) getDictLong(modeRef, kCGDisplayHeight);
+    pMode->refresh = (int)(getDictDouble(modeRef, kCGDisplayRefreshRate) + 0.5);
+    if (pMode->refresh == 0)
+        pMode->refresh = DEFAULT_REFRESH;
+    pMode->ref = NULL;
+}
+
+static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
+                                           QuartzModeInfoPtr pMode) {
+    CFDictionaryRef curModeRef = CGDisplayCurrentMode(screenId);
+    if (!curModeRef)
+        return FALSE;
+
+    QuartzRandRGetModeInfo(curModeRef, pMode);
+    return TRUE;
+}
+
+static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
+                                QuartzModeInfoPtr pMode) {
+    CFDictionaryRef modeRef = (CFDictionaryRef) pMode->ref;
+    return (CGDisplaySwitchToMode(screenId, modeRef) != kCGErrorSuccess);
+}
+
+static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
+                                       CGDirectDisplayID screenId,
+                                       QuartzModeCallback callback,
+                                       void *data) {
+    CFDictionaryRef curModeRef, modeRef;
+    long curBpp;
+    CFArrayRef modes;
+    QuartzModeInfo modeInfo;
+    int i;
+
+    curModeRef = CGDisplayCurrentMode(screenId);
+    if (!curModeRef)
+        return FALSE;
+    curBpp = getDictLong(curModeRef, kCGDisplayBitsPerPixel);
+
+    modes = CGDisplayAvailableModes(screenId);
+    if (!modes)
+        return FALSE;
+    for (i = 0; i < CFArrayGetCount(modes); i++) {
+        modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
+
+        /* Skip modes that are not usable on the current display or have a
+           different pixel encoding than the current mode. */
+        if (((unsigned long) getDictLong(modeRef, kCGDisplayIOFlags) &
+             kDisplayModeUsableFlags) != kDisplayModeUsableFlags)
+            continue;
+        if (getDictLong(modeRef, kCGDisplayBitsPerPixel) != curBpp)
+            continue;
+
+        QuartzRandRGetModeInfo(modeRef, &modeInfo);
+        modeInfo.ref = modeRef;
+        if (!callback(pScreen, screenId, &modeInfo, data))
+            break;
+    }
+    return TRUE;
+}
+
+#else  /* defined(USE_DEPRECATED_CG_API) */
+
+static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef,
+                                    QuartzModeInfoPtr pMode) {
+    pMode->width = CGDisplayModeGetWidth(modeRef);
+    pMode->height = CGDisplayModeGetHeight(modeRef);
+    pMode->refresh = (int) (CGDisplayModeGetRefreshRate(modeRef) + 0.5);
+    if (pMode->refresh == 0)
+        pMode->refresh = DEFAULT_REFRESH;
+    pMode->ref = NULL;
+}
+
+static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
+                                           QuartzModeInfoPtr pMode) {
+    CGDisplayModeRef curModeRef = CGDisplayCopyDisplayMode(screenId);
+    if (!curModeRef)
+        return FALSE;
+
+    QuartzRandRGetModeInfo(curModeRef, pMode);
+    CGDisplayModeRelease(curModeRef);
+    return TRUE;
+}
+
+static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
+                                QuartzModeInfoPtr pMode) {
+    CGDisplayModeRef modeRef = (CGDisplayModeRef) pMode->ref;
+    if (!modeRef)
+        return FALSE;
+
+    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) !=
+            kCGErrorSuccess);
+}
+
+static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
+                                       CGDirectDisplayID screenId,
+                                       QuartzModeCallback callback,
+                                       void *data) {
+    CGDisplayModeRef curModeRef, modeRef;
+    CFStringRef curPixelEnc, pixelEnc;
+    CFComparisonResult pixelEncEqual;
+    CFArrayRef modes;
+    QuartzModeInfo modeInfo;
+    int i;
+
+    curModeRef = CGDisplayCopyDisplayMode(screenId);
+    if (!curModeRef)
+        return FALSE;
+    curPixelEnc = CGDisplayModeCopyPixelEncoding(curModeRef);
+    CGDisplayModeRelease(curModeRef);
+
+    modes = CGDisplayCopyAllDisplayModes(screenId, NULL);
+    if (!modes) {
+        CFRelease(curPixelEnc);
+        return FALSE;
+    }
+    for (i = 0; i < CFArrayGetCount(modes); i++) {
+        modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
+
+        /* Skip modes that are not usable on the current display or have a
+           different pixel encoding than the current mode. */
+        if ((CGDisplayModeGetIOFlags(modeRef) & kDisplayModeUsableFlags) !=
+            kDisplayModeUsableFlags)
+            continue;
+        pixelEnc = CGDisplayModeCopyPixelEncoding(modeRef);
+        pixelEncEqual = CFStringCompare(pixelEnc, curPixelEnc, 0);
+        CFRelease(pixelEnc);
+        if (pixelEncEqual != kCFCompareEqualTo)
+            continue;
+
+        QuartzRandRGetModeInfo(modeRef, &modeInfo);
+        modeInfo.ref = modeRef;
+        if (!callback(pScreen, screenId, &modeInfo, data))
+            break;
+    }
+    CFRelease(modes);
+
+    CFRelease(curPixelEnc);
+    return TRUE;
+}
+
+#endif  /* defined(USE_DEPRECATED_CG_API) */
+
+
+static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
+                                   QuartzModeInfoPtr pMode2) {
+    if (pMode1->width != pMode2->width)
+        return FALSE;
+    if (pMode1->height != pMode2->height)
+        return FALSE;
+    if (pMode1->refresh != pMode2->refresh)
+        return FALSE;
+    return TRUE;
+}
+
+static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
+                                        CGDirectDisplayID screenId,
+                                        QuartzModeInfoPtr pMode,
+                                        void *data) {
+    QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
+
+    RRScreenSizePtr pSize = RRRegisterSize(pScreen,
+        pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
+    if (pSize) {
+        RRRegisterRate(pScreen, pSize, pMode->refresh);
+
+        if (QuartzRandRModesEqual(pMode, pCurMode))
+            RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pSize);
+    }
+    return TRUE;
+}
+
+static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
+                                        CGDirectDisplayID screenId,
+                                        QuartzModeInfoPtr pMode,
+                                        void *data) {
+    QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
+
+    if (!QuartzRandRModesEqual(pMode, pReqMode))
+        return TRUE;  /* continue enumeration */
+
+    return QuartzRandRSetMode(screenId, pMode);
+}
+
+static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    CGDirectDisplayID screenId;
+    QuartzModeInfo curMode;
+
+    *rotations = RR_Rotate_0;  /* TODO: support rotation */
+
+    if (pQuartzScreen->displayCount == 0)
+        return FALSE;
+    if (pQuartzScreen->displayCount > 1) {
+        /* RandR operations are not well-defined for an X11 screen spanning
+           multiple CG displays. Create a single entry for the current virtual
+           resolution. */
+        RRScreenSizePtr pSize = RRRegisterSize(pScreen, pScreen->width,
+            pScreen->height, pScreen->mmWidth, pScreen->mmHeight);
+        if (pSize) {
+            RRRegisterRate(pScreen, pSize, DEFAULT_REFRESH);
+            RRSetCurrentConfig(pScreen, RR_Rotate_0, DEFAULT_REFRESH, pSize);
+        }
+        return TRUE;
+    }
+    screenId = pQuartzScreen->displayIDs[0];
+
+    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
+        return FALSE;
+    return QuartzRandREnumerateModes(pScreen, screenId,
+        QuartzRandRGetModeCallback, &curMode);
+}
+
+static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
+			          Rotation            randr,
+			          int                 rate,
+			          RRScreenSizePtr     pSize) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    CGDirectDisplayID screenId;
+    QuartzModeInfo reqMode, curMode;
+
+    if (pQuartzScreen->displayCount == 0)
+        return FALSE;
+    if (pQuartzScreen->displayCount > 1) {
+        /* RandR operations are not well-defined for an X11 screen spanning
+           multiple CG displays. Do not accept any configuations that differ
+           from the current configuration. */
+        return ((pSize->width == pScreen->width) &&
+                (pSize->height == pScreen->height));
+    }
+    screenId = pQuartzScreen->displayIDs[0];
+
+    reqMode.width = pSize->width;
+    reqMode.height = pSize->height;
+    reqMode.refresh = rate;
+
+    /* Do not switch modes if requested mode is equal to current mode. */
+    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
+        return FALSE;
+    if (QuartzRandRModesEqual(&reqMode, &curMode))
+        return TRUE;
+
+    return QuartzRandREnumerateModes(pScreen, screenId,
+        QuartzRandRSetModeCallback, &reqMode);
+}
+
+Bool QuartzRandRInit (ScreenPtr pScreen) {
+    rrScrPrivPtr    pScrPriv;
+    
+    if (!RRScreenInit (pScreen)) return FALSE;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+    pScrPriv->rrGetInfo = QuartzRandRGetInfo;
+    pScrPriv->rrSetConfig = QuartzRandRSetConfig;
+    return TRUE;
+}
+
+#endif  /* defined(FAKE_RANDR) */
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
new file mode 100644
index 0000000..a190205
--- /dev/null
+++ b/hw/xquartz/quartzRandR.h
@@ -0,0 +1,37 @@
+/*
+ * quartzRandR.h
+ *
+ * Copyright (c) 2010 Jan Hauffa.
+ *                 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.
+ */
+
+/*define FAKE_RANDR 1*/
+#define USE_DEPRECATED_CG_API 1
+
+#if defined(FAKE_RANDR)
+void RREditConnectionInfo (ScreenPtr pScreen);
+#else
+Bool QuartzRandRInit (ScreenPtr pScreen);
+#endif
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index c03a82d..4df0373 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -176,7 +176,7 @@ displayScreenBounds(CGDirectDisplayID id)
  *  with PseudoramiX.
  */
 static void
-xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
+xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScreen)
 {
     CGDisplayCount i, displayCount;
     CGDirectDisplayID *displayList = NULL;
@@ -199,6 +199,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
     if(!displayList)
         FatalError("Unable to allocate memory for list of displays.\n");
     CGGetActiveDisplayList(displayCount, displayList, &displayCount);
+    QuartzCopyDisplayIDs(pScreen, displayCount, displayList);
 
     /* Get the union of all screens */
     for (i = 0; i < displayCount; i++) {
@@ -336,6 +337,7 @@ xprAddScreen(int index, ScreenPtr pScreen)
         ErrorF("Warning: noPseudoramiXExtension!\n");
         
         dpy = displayAtIndex(index);
+        QuartzCopyDisplayIDs(pScreen, 1, &dpy);
 
         frame = displayScreenBounds(dpy);
 
@@ -346,7 +348,7 @@ xprAddScreen(int index, ScreenPtr pScreen)
     }
     else
     {
-        xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height);
+        xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height, pScreen);
     }
 
     /* Passing zero width (pitch) makes miCreateScreenResources set the
commit f4926709485c0605f0b1171c84c803b68eebfc38
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue Sep 28 09:48:41 2010 -0700

    XQuartz: Move use of static dispatch procs after declaration
    
    This fixes fallout from cbd4d5dbb70db62ba1cb79c7b904e6fa11f62d7e
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index cd2bdf0..ec20534 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -103,33 +103,6 @@ make_box (int x, int y, int w, int h)
     return r;
 }
 
-void
-AppleWMExtensionInit(
-    AppleWMProcsPtr procsPtr)
-{
-    ExtensionEntry* extEntry;
-
-    ClientType = CreateNewResourceType(WMFreeClient, "WMClient");
-    EventType = CreateNewResourceType(WMFreeEvents, "WMEvent");
-    eventResource = FakeClientID(0);
-
-    if (ClientType && EventType &&
-        (extEntry = AddExtension(APPLEWMNAME,
-                                 AppleWMNumberEvents,
-                                 AppleWMNumberErrors,
-                                 ProcAppleWMDispatch,
-                                 SProcAppleWMDispatch,
-                                 NULL,
-                                 StandardMinorOpcode)))
-    {
-        WMReqCode = (unsigned char)extEntry->base;
-        WMErrorBase = extEntry->errorBase;
-        WMEventBase = extEntry->eventBase;
-        EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
-        appleWMProcs = procsPtr;
-    }
-}
-
 /* Updates the _NATIVE_SCREEN_ORIGIN property on the given root window. */
 void
 AppleWMSetScreenOrigin(
@@ -734,3 +707,30 @@ SProcAppleWMDispatch (
         return BadRequest;
     }
 }
+
+void
+AppleWMExtensionInit(
+    AppleWMProcsPtr procsPtr)
+{
+    ExtensionEntry* extEntry;
+
+    ClientType = CreateNewResourceType(WMFreeClient, "WMClient");
+    EventType = CreateNewResourceType(WMFreeEvents, "WMEvent");
+    eventResource = FakeClientID(0);
+
+    if (ClientType && EventType &&
+        (extEntry = AddExtension(APPLEWMNAME,
+                                 AppleWMNumberEvents,
+                                 AppleWMNumberErrors,
+                                 ProcAppleWMDispatch,
+                                 SProcAppleWMDispatch,
+                                 NULL,
+                                 StandardMinorOpcode)))
+    {
+        WMReqCode = (unsigned char)extEntry->base;
+        WMErrorBase = extEntry->errorBase;
+        WMEventBase = extEntry->eventBase;
+        EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
+        appleWMProcs = procsPtr;
+    }
+}
diff --git a/hw/xquartz/xpr/appledri.c b/hw/xquartz/xpr/appledri.c
index ebd4a43..ff70a38 100644
--- a/hw/xquartz/xpr/appledri.c
+++ b/hw/xquartz/xpr/appledri.c
@@ -76,27 +76,6 @@ typedef struct _DRIEvent {
     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 (
@@ -419,3 +398,23 @@ SProcAppleDRIDispatch (
         return BadRequest;
     }
 }
+
+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;
+    }
+}
commit c36ca7b1862ecd86df089f4e1933379a113928ea
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 25 10:05:10 2010 -0400

    config: remove --with-dri-driver-path option, use dri.pc #29740
    
    The trusted location of the dri driver directory can be obtained
    from the mesa dri.pc pkg-config file.
    
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Acked-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 95f7a76..825eb69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -601,9 +601,6 @@ AC_ARG_ENABLE(pc98,     	AC_HELP_STRING([--enable-pc98], [Enable PC98 support in
 				[SUPPORT_PC98=auto])
 
 dnl GLX build options
-AC_ARG_WITH(dri-driver-path,  AS_HELP_STRING([--with-dri-driver-path=PATH], [Path to DRI drivers (default: ${libdir}/dri)]),
-				[ DRI_DRIVER_PATH="$withval" ],
-				[ DRI_DRIVER_PATH="${libdir}/dri" ])
 AC_ARG_ENABLE(aiglx,          AS_HELP_STRING([--enable-aiglx], [Build accelerated indirect GLX (default: enabled)]),
                                 [AIGLX=$enableval],
                                 [AIGLX=yes])
@@ -1258,7 +1255,8 @@ AC_DEFINE_DIR(COMPILEDDEFAULTFONTPATH, FONTPATH, [Default font path])
 AC_DEFINE_DIR(PCI_TXT_IDS_PATH, PCI_TXT_IDS_DIR, [Default PCI text file ID path])
 AC_DEFINE_DIR(SERVER_MISC_CONFIG_PATH, SERVERCONFIG, [Server miscellaneous config path])
 AC_DEFINE_DIR(BASE_FONT_PATH, FONTROOTDIR, [Default base font path])
-AC_DEFINE_DIR(DRI_DRIVER_PATH, DRI_DRIVER_PATH, [Default DRI driver path])
+dridriverdir=`$PKG_CONFIG --variable=dridriverdir dri`
+AC_DEFINE_DIR(DRI_DRIVER_PATH, dridriverdir, [Default DRI driver path])
 AC_DEFINE_UNQUOTED(XVENDORNAME, ["$VENDOR_NAME"], [Vendor name])
 AC_DEFINE_UNQUOTED(XVENDORNAMESHORT, ["$VENDOR_NAME_SHORT"], [Short vendor name])
 AC_DEFINE_UNQUOTED(XORG_DATE, ["$RELEASE_DATE"], [Vendor release])
commit 5532687a929426c4b1c4667f4591ed362f097c9b
Merge: 9df4fb0... 682a3ee...
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Sep 28 08:15:07 2010 -0700

    Merge remote branch 'ajax/less-loader'

commit 9df4fb0adf66fb82f0c007897d79af0f54a6dad9
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 27 17:06:46 2010 -0400

    xfree86: Add 18bpp support
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 97e5aec..edc8e47 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -776,6 +776,9 @@ xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
 	    scrp->weight.red = scrp->weight.blue = 5;
 	    scrp->weight.green = 6;
 	    break;
+	case 18:
+	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6;
+	    break;
 	case 24:
 	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8;
 	    break;
commit 5c6a2f93ebc16a78093782b442306de23ae94e78
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Sep 27 19:39:23 2010 +0100

    xfree86: Kill pixmapPrivate with a vengeance (v2)
    
    ScrnInfo->pixmapPrivate only existed in order to catch invalid access to
    the framebuffer by making the backing data NULL across the VT switch.
    This was causing more confusion in the higher layers during mode setting
    without any real benefit, so remove it.
    
    v2: Kill ShadowModifyPixmapHeader() as well.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Cc: Julien Cristau <jcristau at debian.org>
    Cc: Andrew Guertin <lists at dolphinling.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 90e0c67..97e5aec 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1180,10 +1180,6 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
     if (enable)
     {
 	/*
-	 * Restore the screen pixmap devPrivate field
-	 */
-	pspix->devPrivate = pScrnInfo->pixmapPrivate;
-	/*
 	 * Restore all of the clip lists on the screen
 	 */
 	if (!xf86Resetting)
@@ -1196,13 +1192,6 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
 	 * Empty all of the clip lists on the screen
 	 */
 	xf86SetRootClip (pScreen, FALSE);
-	/*
-	 * save the screen pixmap devPrivate field and
-	 * replace it with NULL so accidental references
-	 * to the frame buffer are caught
-	 */
-	pScrnInfo->pixmapPrivate = pspix->devPrivate;
-	pspix->devPrivate.ptr = NULL;
     }
 }
 
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index c9b261d..b979884 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -765,7 +765,6 @@ typedef struct _ScrnInfoRec {
 
     /* Allow screens to be enabled/disabled individually */
     Bool		vtSema;
-    DevUnion		pixmapPrivate;		/* saved devPrivate from pixmap */
 
     /* hw cursor moves at SIGIO time */
     Bool		silkenMouse;
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 8a593a7..ba0862a 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -511,7 +511,6 @@ xf86RandR12SetMode (ScreenPtr	    pScreen,
     WindowPtr		pRoot = pScreen->root;
     DisplayModePtr      currentMode = NULL;
     Bool 		ret = TRUE;
-    PixmapPtr 		pspix = NULL;
 
     if (pRoot)
 	(*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
@@ -560,14 +559,6 @@ xf86RandR12SetMode (ScreenPtr	    pScreen,
 	pScreen->mmHeight = oldmmHeight;
         scrp->currentMode = currentMode;
     }
-    /*
-     * Get the new Screen pixmap ptr as SwitchMode might have called
-     * ModifyPixmapHeader and xf86EnableDisableFBAccess will put it back...
-     * Unfortunately.
-     */
-    pspix = (*pScreen->GetScreenPixmap) (pScreen);
-    if (pspix->devPrivate.ptr)
-       scrp->pixmapPrivate = pspix->devPrivate;
 
     /*
      * Make sure the layout is correct
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index 0af53d1..5cc476a 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -36,15 +36,6 @@ static void ShadowCopyWindow(
     RegionPtr prgn 
 );
 static Bool ShadowCreateGC(GCPtr pGC);
-static Bool ShadowModifyPixmapHeader(
-    PixmapPtr pPixmap,
-    int width,
-    int height,
-    int depth,
-    int bitsPerPixel,
-    int devKind,
-    pointer pPixData
-);
 
 static Bool ShadowEnterVT(int index, int flags);
 static void ShadowLeaveVT(int index, int flags);
@@ -189,7 +180,6 @@ ShadowFBInit2 (
     pScreen->CloseScreen = ShadowCloseScreen;
     pScreen->CopyWindow = ShadowCopyWindow;
     pScreen->CreateGC = ShadowCreateGC;
-    pScreen->ModifyPixmapHeader = ShadowModifyPixmapHeader;
 
     pScrn->EnterVT = ShadowEnterVT;
     pScrn->LeaveVT = ShadowLeaveVT;
@@ -310,49 +300,6 @@ ShadowCopyWindow(
     }
 }
 
-static Bool
-ShadowModifyPixmapHeader(
-    PixmapPtr pPixmap,
-    int width,
-    int height,
-    int depth,
-    int bitsPerPixel,
-    int devKind,
-    pointer pPixData
-)
-{
-    ScreenPtr pScreen;
-    ScrnInfoPtr pScrn;
-    ShadowScreenPtr pPriv;
-    Bool retval;
-    PixmapPtr pScreenPix;
-
-    if (!pPixmap)
-	return FALSE;
-
-    pScreen = pPixmap->drawable.pScreen;
-    pScrn = xf86Screens[pScreen->myNum];
-
-    pScreenPix = (*pScreen->GetScreenPixmap)(pScreen);
-    
-    if (pPixmap == pScreenPix && !pScrn->vtSema)
-	pScreenPix->devPrivate = pScrn->pixmapPrivate;
-    
-    pPriv = GET_SCREEN_PRIVATE(pScreen);
-
-    pScreen->ModifyPixmapHeader = pPriv->ModifyPixmapHeader;
-    retval = (*pScreen->ModifyPixmapHeader)(pPixmap,
-	width, height, depth, bitsPerPixel, devKind, pPixData);
-    pScreen->ModifyPixmapHeader = ShadowModifyPixmapHeader;
-
-    if (pPixmap == pScreenPix && !pScrn->vtSema)
-    {
-	pScrn->pixmapPrivate = pScreenPix->devPrivate;
-	pScreenPix->devPrivate.ptr = 0;
-    }
-    return retval;
-}
-
 static void
 ShadowComposite(
     CARD8 op,
commit fdabcec57ae0fdc9910060609bb0848552c1db4d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Sep 27 17:30:13 2010 +0100

    modes: Beware the driver switching root pixmaps
    
    Program received signal SIGSEGV, Segmentation fault.
    0x080d4a2d in xf86RandR12ScreenSetSize (pScreen=0x8dca3a0, width=800,
        height=600, mmWidth=210, mmHeight=157)
        at ../../../../hw/xfree86/modes/xf86RandR12.c:731
    731     ../../../../hw/xfree86/modes/xf86RandR12.c: No such file or directory.
            in ../../../../hw/xfree86/modes/xf86RandR12.c
    (gdb) bt full
        height=600, mmWidth=210, mmHeight=157)
        at ../../../../hw/xfree86/modes/xf86RandR12.c:731
            randrp = 0x8dcae68
            pScrn = 0x8dbeb28
            config = <value optimized out>
            pRoot = 0x8e08e30
            pScrnPix = 0xb6d12008
            ret = 1
            c = <value optimized out>
        mmWidth=210, mmHeight=157) at ../../randr/rrscreen.c:185
    No locals.
        at ../../randr/rrscreen.c:307
            pWin = 0x8e08e30
            pScreen = 0x8dca3a0
            i = <value optimized out>
            rc = 0
    ../../randr/randr.c:485
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Cc: Julien Cristau <jcristau at debian.org>
    Tested-by: Julien Cristau <jcristau at debian.org>
    Cc: Keith Packard <keithp at keithp.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index dd2bdac..8a593a7 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -677,7 +677,7 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
     ScrnInfoPtr		pScrn = XF86SCRNINFO(pScreen);
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
     WindowPtr		pRoot = pScreen->root;
-    PixmapPtr		pScrnPix = (*pScreen->GetScreenPixmap)(pScreen);
+    PixmapPtr		pScrnPix;
     Bool		ret = FALSE;
     int                 c;
 
@@ -714,6 +714,7 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
 	}
     }
 
+    pScrnPix = (*pScreen->GetScreenPixmap)(pScreen);
     pScreen->width = pScrnPix->drawable.width = width;
     pScreen->height = pScrnPix->drawable.height = height;
     randrp->mmWidth = pScreen->mmWidth = mmWidth;
commit 2f0abd7d690c3bcce2a80c093a0880f43e56d8cb
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Thu Sep 23 09:04:11 2010 -0400

    glx: Fix use after free in DrawableGone
    
    (note that nearly identical patches were proposed by Kristian and Chris)
    
    Signed-off-by: Kristian Høgsberg <krh at bitplanet.net>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reported-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Tested-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxext.c b/glx/glxext.c
index e203156..f5ebe4f 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+	next = c->next;
 	if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
 	    int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 		    }
 		}
 	    }
-
-	    if (!c->idExists) {
-		__glXFreeContext(c);
-	    }
 	}
 	if (c->drawPriv == glxPriv)
 	    c->drawPriv = NULL;
 	if (c->readPriv == glxPriv)
 	    c->readPriv = NULL;
+	if (!c->idExists && !c->isCurrent)
+	    __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
commit e416965bfd08dfae5d2b7932b5118efac20546ad
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Sun Jul 18 18:56:02 2010 +0300

    dix: remove proc tables initialization
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 0e5aced..17f308c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -238,7 +238,6 @@ long	    SmartLastPrint;
 #endif
 
 void        Dispatch(void);
-void        InitProcVectors(void);
 
 static int
 SmartScheduleClient (int *clientReady, int nready)
@@ -3387,25 +3386,6 @@ int ProcNoOperation(ClientPtr client)
     return Success;
 }
 
-void
-InitProcVectors(void)
-{
-    int i;
-    for (i = 0; i<256; i++)
-    {
-	if(!ProcVector[i])
-	{
-            ProcVector[i] = SwappedProcVector[i] = ProcBadRequest;
-	    ReplySwapVector[i] = ReplyNotSwappd;
-	}
-    }
-    for(i = LASTEvent; i < 128; i++)
-    {
-	EventSwapVector[i] = NotImplemented;
-    }
-    
-}
-
 /**********************
  * CloseDownClient
  *
diff --git a/dix/main.c b/dix/main.c
index 47a932f..692bec1 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -108,7 +108,6 @@ Equipment Corporation.
 #include "panoramiXsrv.h"
 #else
 #include "dixevents.h"		/* InitEvents() */
-#include "dispatch.h"		/* InitProcVectors() */
 #endif
 
 #ifdef DPMSExtension
@@ -118,8 +117,6 @@ Equipment Corporation.
 
 extern void Dispatch(void);
 
-extern void InitProcVectors(void);
-
 #ifdef XQUARTZ
 #include <pthread.h>
 
@@ -171,7 +168,6 @@ int main(int argc, char *argv[], char *envp[])
 	if(serverGeneration == 1)
 	{
 	    CreateWellKnownSockets();
-	    InitProcVectors();
 	    for (i=1; i<MAXCLIENTS; i++)
 		clients[i] = NullClient;
 	    serverClient = calloc(sizeof(ClientRec), 1);
diff --git a/dix/tables.c b/dix/tables.c
index 5aafb8b..5bd9ea0 100644
--- a/dix/tables.c
+++ b/dix/tables.c
@@ -192,14 +192,142 @@ int (* ProcVector[256]) (
     ProcGetPointerMapping,
     ProcSetModifierMapping,
     ProcGetModifierMapping,
-    0,					/* 120 */
-    0,
-    0,
-    0,
-    0,
-    0,					/* 125 */
-    0,
-    ProcNoOperation    
+    ProcBadRequest,				/* 120 */
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,				/* 125 */
+    ProcBadRequest,
+    ProcNoOperation,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest
 };
 
 int (* SwappedProcVector[256]) (
@@ -326,14 +454,142 @@ int (* SwappedProcVector[256]) (
     SProcSimpleReq,			/* GetPointerMapping, */
     SProcSimpleReq,			/* SetModifierMapping, */
     SProcSimpleReq,			/* GetModifierMapping, */
-    0,					/* 120 */
-    0,
-    0,
-    0,
-    0,
-    0,					/* 125 */
-    0,
-    SProcNoOperation
+    ProcBadRequest,				/* 120 */
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,				/* 125 */
+    ProcBadRequest,
+    SProcNoOperation,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest,
+    ProcBadRequest
 };
 
 EventSwapPtr EventSwapVector[128] =
@@ -373,6 +629,99 @@ EventSwapPtr EventSwapVector[128] =
     SColormapEvent,
     SClientMessageEvent,
     SMappingEvent,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented,
+    NotImplemented
 };
 
 
@@ -506,5 +855,132 @@ ReplySwapPtr ReplySwapVector[256] =
     ReplyNotSwappd,				/* 125 */
     ReplyNotSwappd,				/* 126 */
     ReplyNotSwappd,				/* NoOperation */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
     ReplyNotSwappd
 };
commit cbd4d5dbb70db62ba1cb79c7b904e6fa11f62d7e
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Fri Jul 16 20:19:50 2010 +0300

    xserver: delete pervasively use of DISPATCH_PROC
    
    Some functions had to be moved around due some missing static definitions.
    Another minor clean up like inexistent function declarations and etc were made
    also.
    
    Part of this patch was cooked using:
    sed -i -e '/static DISPATCH_PROC*.*;/d' `git ls-files`
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index ce3734e..a540bcb 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -40,18 +40,8 @@ from The Open Group.
 #include "opaque.h"
 #include "modinit.h"
 
-static DISPATCH_PROC(ProcBigReqDispatch);
-
 void BigReqExtensionInit(INITARGS);
 
-void
-BigReqExtensionInit(INITARGS)
-{
-    AddExtension(XBigReqExtensionName, 0, 0,
-		 ProcBigReqDispatch, ProcBigReqDispatch,
-		 NULL, StandardMinorOpcode);
-}
-
 static int
 ProcBigReqDispatch (ClientPtr client)
 {
@@ -78,3 +68,11 @@ ProcBigReqDispatch (ClientPtr client)
     WriteToClient(client, sizeof(xBigReqEnableReply), (char *)&rep);
     return Success;
 }
+
+void
+BigReqExtensionInit(INITARGS)
+{
+    AddExtension(XBigReqExtensionName, 0, 0,
+		 ProcBigReqDispatch, ProcBigReqDispatch,
+		 NULL, StandardMinorOpcode);
+}
diff --git a/Xext/saver.c b/Xext/saver.c
index 6d91ddf..1888603 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -62,20 +62,6 @@ in this Software without prior written authorization from the X Consortium.
 
 static int ScreenSaverEventBase = 0;
 
-static DISPATCH_PROC(ProcScreenSaverQueryInfo);
-static DISPATCH_PROC(ProcScreenSaverDispatch);
-static DISPATCH_PROC(ProcScreenSaverQueryVersion);
-static DISPATCH_PROC(ProcScreenSaverSelectInput);
-static DISPATCH_PROC(ProcScreenSaverSetAttributes);
-static DISPATCH_PROC(ProcScreenSaverUnsetAttributes);
-static DISPATCH_PROC(ProcScreenSaverSuspend);
-static DISPATCH_PROC(SProcScreenSaverDispatch);
-static DISPATCH_PROC(SProcScreenSaverQueryInfo);
-static DISPATCH_PROC(SProcScreenSaverQueryVersion);
-static DISPATCH_PROC(SProcScreenSaverSelectInput);
-static DISPATCH_PROC(SProcScreenSaverSetAttributes);
-static DISPATCH_PROC(SProcScreenSaverUnsetAttributes);
-static DISPATCH_PROC(SProcScreenSaverSuspend);
 
 static Bool ScreenSaverHandle (
 	ScreenPtr /* pScreen */,
@@ -237,45 +223,6 @@ static DevPrivateKeyRec ScreenPrivateKeyRec;
 
 #define New(t)	(malloc(sizeof (t)))
 
-/****************
- * ScreenSaverExtensionInit
- *
- * Called from InitExtensions in main() or from QueryExtension() if the
- * extension is dynamically loaded.
- *
- ****************/
-
-void
-ScreenSaverExtensionInit(INITARGS)
-{
-    ExtensionEntry *extEntry;
-    int		    i;
-    ScreenPtr	    pScreen;
-
-    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
-	return;
-
-    AttrType = CreateNewResourceType(ScreenSaverFreeAttr, "SaverAttr");
-    SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents,
-					   "SaverEvent");
-    SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend,
-					"SaverSuspend");
-
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	pScreen = screenInfo.screens[i];
-	SetScreenPrivate (pScreen, NULL);
-    }
-    if (AttrType && SaverEventType && SuspendType &&
-	(extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
-				 ProcScreenSaverDispatch, SProcScreenSaverDispatch,
-				 NULL, StandardMinorOpcode)))
-    {
-	ScreenSaverEventBase = extEntry->eventBase;
-	EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent;
-    }
-}
-
 static void
 CheckScreenPrivate (ScreenPtr pScreen)
 {
@@ -1412,7 +1359,7 @@ ProcScreenSaverSuspend (ClientPtr client)
     return Success;
 }
 
-static DISPATCH_PROC((*NormalVector[])) = {
+static int (*NormalVector[]) (ClientPtr /* client */) = {
     ProcScreenSaverQueryVersion,
     ProcScreenSaverQueryInfo,
     ProcScreenSaverSelectInput,
@@ -1513,7 +1460,7 @@ SProcScreenSaverSuspend (ClientPtr client)
     return ProcScreenSaverSuspend (client);
 }
 
-static DISPATCH_PROC((*SwappedVector[])) = {
+static int (*SwappedVector[]) (ClientPtr /* client */) = {
     SProcScreenSaverQueryVersion,
     SProcScreenSaverQueryInfo,
     SProcScreenSaverSelectInput,
@@ -1531,3 +1478,34 @@ SProcScreenSaverDispatch (ClientPtr client)
 	return (*SwappedVector[stuff->data])(client);
     return BadRequest;
 }
+
+void
+ScreenSaverExtensionInit(INITARGS)
+{
+    ExtensionEntry *extEntry;
+    int		    i;
+    ScreenPtr	    pScreen;
+
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    AttrType = CreateNewResourceType(ScreenSaverFreeAttr, "SaverAttr");
+    SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents,
+					   "SaverEvent");
+    SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend,
+					"SaverSuspend");
+
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+	pScreen = screenInfo.screens[i];
+	SetScreenPrivate (pScreen, NULL);
+    }
+    if (AttrType && SaverEventType && SuspendType &&
+	(extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
+				 ProcScreenSaverDispatch, SProcScreenSaverDispatch,
+				 NULL, StandardMinorOpcode)))
+    {
+	ScreenSaverEventBase = extEntry->eventBase;
+	EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent;
+    }
+}
diff --git a/Xext/shape.c b/Xext/shape.c
index ac95328..115fc07 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -68,26 +68,6 @@ static void SShapeNotifyEvent(
  * externally by the Xfixes extension and are now defined in window.h
  */
 
-static DISPATCH_PROC(ProcShapeCombine);
-static DISPATCH_PROC(ProcShapeDispatch);
-static DISPATCH_PROC(ProcShapeGetRectangles);
-static DISPATCH_PROC(ProcShapeInputSelected);
-static DISPATCH_PROC(ProcShapeMask);
-static DISPATCH_PROC(ProcShapeOffset);
-static DISPATCH_PROC(ProcShapeQueryExtents);
-static DISPATCH_PROC(ProcShapeQueryVersion);
-static DISPATCH_PROC(ProcShapeRectangles);
-static DISPATCH_PROC(ProcShapeSelectInput);
-static DISPATCH_PROC(SProcShapeCombine);
-static DISPATCH_PROC(SProcShapeDispatch);
-static DISPATCH_PROC(SProcShapeGetRectangles);
-static DISPATCH_PROC(SProcShapeInputSelected);
-static DISPATCH_PROC(SProcShapeMask);
-static DISPATCH_PROC(SProcShapeOffset);
-static DISPATCH_PROC(SProcShapeQueryExtents);
-static DISPATCH_PROC(SProcShapeQueryVersion);
-static DISPATCH_PROC(SProcShapeRectangles);
-static DISPATCH_PROC(SProcShapeSelectInput);
 
 #ifdef PANORAMIX
 #include "panoramiX.h"
@@ -122,23 +102,6 @@ typedef struct _ShapeEvent {
  *
  ****************/
 
-void
-ShapeExtensionInit(void)
-{
-    ExtensionEntry *extEntry;
-
-    ClientType = CreateNewResourceType(ShapeFreeClient, "ShapeClient");
-    ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent");
-    if (ClientType && ShapeEventType &&
-	(extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0,
-				 ProcShapeDispatch, SProcShapeDispatch,
-				 NULL, StandardMinorOpcode)))
-    {
-	ShapeEventBase = extEntry->eventBase;
-	EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;
-    }
-}
-
 static int
 RegionOperate (
 	ClientPtr client,
@@ -1278,3 +1241,20 @@ SProcShapeDispatch (ClientPtr client)
 	return BadRequest;
     }
 }
+
+void
+ShapeExtensionInit(void)
+{
+    ExtensionEntry *extEntry;
+
+    ClientType = CreateNewResourceType(ShapeFreeClient, "ShapeClient");
+    ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent");
+    if (ClientType && ShapeEventType &&
+	(extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0,
+				 ProcShapeDispatch, SProcShapeDispatch,
+				 NULL, StandardMinorOpcode)))
+    {
+	ShapeEventBase = extEntry->eventBase;
+	EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;
+    }
+}
diff --git a/Xext/shm.c b/Xext/shm.c
index 3230d83..23afe6b 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -120,20 +120,6 @@ static void SShmCompletionEvent(
 
 static Bool ShmDestroyPixmap (PixmapPtr pPixmap);
 
-static DISPATCH_PROC(ProcShmAttach);
-static DISPATCH_PROC(ProcShmCreatePixmap);
-static DISPATCH_PROC(ProcShmDetach);
-static DISPATCH_PROC(ProcShmDispatch);
-static DISPATCH_PROC(ProcShmGetImage);
-static DISPATCH_PROC(ProcShmPutImage);
-static DISPATCH_PROC(ProcShmQueryVersion);
-static DISPATCH_PROC(SProcShmAttach);
-static DISPATCH_PROC(SProcShmCreatePixmap);
-static DISPATCH_PROC(SProcShmDetach);
-static DISPATCH_PROC(SProcShmDispatch);
-static DISPATCH_PROC(SProcShmGetImage);
-static DISPATCH_PROC(SProcShmPutImage);
-static DISPATCH_PROC(SProcShmQueryVersion);
 
 static unsigned char ShmReqCode;
 int ShmCompletionCode;
@@ -254,56 +240,6 @@ ShmRegisterPrivates(void)
     return TRUE;
 }
 
-void
-ShmExtensionInit(INITARGS)
-{
-    ExtensionEntry *extEntry;
-    int i;
-
-#ifdef MUST_CHECK_FOR_SHM_SYSCALL
-    if (!CheckForShmSyscall())
-    {
-	ErrorF("MIT-SHM extension disabled due to lack of kernel support\n");
-	return;
-    }
-#endif
-
-    if (!ShmRegisterPrivates())
-	return;
-
-    sharedPixmaps = xFalse;
-    {
-      sharedPixmaps = xTrue;
-      for (i = 0; i < screenInfo.numScreens; i++)
-      {
-	ShmScrPrivateRec *screen_priv = ShmInitScreenPriv(screenInfo.screens[i]);
-	if (!screen_priv->shmFuncs)
-	    screen_priv->shmFuncs = &miFuncs;
-	if (!screen_priv->shmFuncs->CreatePixmap)
-	    sharedPixmaps = xFalse;
-      }
-      if (sharedPixmaps)
-	for (i = 0; i < screenInfo.numScreens; i++)
-	{
-	    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(screenInfo.screens[i]);
-	    screen_priv->destroyPixmap = screenInfo.screens[i]->DestroyPixmap;
-	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
-	}
-    }
-    ShmSegType = CreateNewResourceType(ShmDetachSegment, "ShmSeg");
-    if (ShmSegType &&
-	(extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors,
-				 ProcShmDispatch, SProcShmDispatch,
-				 ShmResetProc, StandardMinorOpcode)))
-    {
-	ShmReqCode = (unsigned char)extEntry->base;
-	ShmCompletionCode = extEntry->eventBase;
-	BadShmSegCode = extEntry->errorBase;
-	SetResourceTypeErrorValue(ShmSegType, BadShmSegCode);
-	EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
-    }
-}
-
 /*ARGSUSED*/
 static void
 ShmResetProc(ExtensionEntry *extEntry)
@@ -581,6 +517,226 @@ doShmPutImage(DrawablePtr dst, GCPtr pGC,
     }
 }
 
+static int
+ProcShmPutImage(ClientPtr client)
+{
+    GCPtr pGC;
+    DrawablePtr pDraw;
+    long length;
+    ShmDescPtr shmdesc;
+    REQUEST(xShmPutImageReq);
+
+    REQUEST_SIZE_MATCH(xShmPutImageReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
+    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client);
+    if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse))
+	return BadValue;
+    if (stuff->format == XYBitmap)
+    {
+        if (stuff->depth != 1)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, 1);
+    }
+    else if (stuff->format == XYPixmap)
+    {
+        if (pDraw->depth != stuff->depth)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, 1);
+	length *= stuff->depth;
+    }
+    else if (stuff->format == ZPixmap)
+    {
+        if (pDraw->depth != stuff->depth)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, stuff->depth);
+    }
+    else
+    {
+	client->errorValue = stuff->format;
+        return BadValue;
+    }
+
+    /*
+     * There's a potential integer overflow in this check:
+     * VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight,
+     *                client);
+     * the version below ought to avoid it
+     */
+    if (stuff->totalHeight != 0 &&
+	length > (shmdesc->size - stuff->offset)/stuff->totalHeight) {
+	client->errorValue = stuff->totalWidth;
+	return BadValue;
+    }
+    if (stuff->srcX > stuff->totalWidth)
+    {
+	client->errorValue = stuff->srcX;
+	return BadValue;
+    }
+    if (stuff->srcY > stuff->totalHeight)
+    {
+	client->errorValue = stuff->srcY;
+	return BadValue;
+    }
+    if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth)
+    {
+	client->errorValue = stuff->srcWidth;
+	return BadValue;
+    }
+    if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight)
+    {
+	client->errorValue = stuff->srcHeight;
+	return BadValue;
+    }
+
+    if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) ||
+	 ((stuff->format != ZPixmap) &&
+	  (stuff->srcX < screenInfo.bitmapScanlinePad) &&
+	  ((stuff->format == XYBitmap) ||
+	   ((stuff->srcY == 0) &&
+	    (stuff->srcHeight == stuff->totalHeight))))) &&
+	((stuff->srcX + stuff->srcWidth) == stuff->totalWidth))
+	(*pGC->ops->PutImage) (pDraw, pGC, stuff->depth,
+			       stuff->dstX, stuff->dstY,
+			       stuff->totalWidth, stuff->srcHeight,
+			       stuff->srcX, stuff->format,
+			       shmdesc->addr + stuff->offset +
+			       (stuff->srcY * length));
+    else
+	doShmPutImage(pDraw, pGC, stuff->depth, stuff->format,
+		      stuff->totalWidth, stuff->totalHeight,
+		      stuff->srcX, stuff->srcY,
+		      stuff->srcWidth, stuff->srcHeight,
+		      stuff->dstX, stuff->dstY,
+                      shmdesc->addr + stuff->offset);
+
+    if (stuff->sendEvent)
+    {
+	xShmCompletionEvent ev;
+
+	ev.type = ShmCompletionCode;
+	ev.drawable = stuff->drawable;
+	ev.minorEvent = X_ShmPutImage;
+	ev.majorEvent = ShmReqCode;
+	ev.shmseg = stuff->shmseg;
+	ev.offset = stuff->offset;
+	WriteEventsToClient(client, 1, (xEvent *) &ev);
+    }
+
+    return Success;
+}
+
+static int
+ProcShmGetImage(ClientPtr client)
+{
+    DrawablePtr		pDraw;
+    long		lenPer = 0, length;
+    Mask		plane = 0;
+    xShmGetImageReply	xgi;
+    ShmDescPtr		shmdesc;
+    int			n, rc;
+
+    REQUEST(xShmGetImageReq);
+
+    REQUEST_SIZE_MATCH(xShmGetImageReq);
+    if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap))
+    {
+	client->errorValue = stuff->format;
+        return BadValue;
+    }
+    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
+			   DixReadAccess);
+    if (rc != Success)
+	return rc;
+    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
+    if (pDraw->type == DRAWABLE_WINDOW)
+    {
+      if( /* check for being viewable */
+	 !((WindowPtr) pDraw)->realized ||
+	  /* check for being on screen */
+         pDraw->x + stuff->x < 0 ||
+         pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width ||
+         pDraw->y + stuff->y < 0 ||
+         pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height ||
+          /* check for being inside of border */
+         stuff->x < - wBorderWidth((WindowPtr)pDraw) ||
+         stuff->x + (int)stuff->width >
+		wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
+         stuff->y < -wBorderWidth((WindowPtr)pDraw) ||
+         stuff->y + (int)stuff->height >
+		wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height
+        )
+	    return BadMatch;
+	xgi.visual = wVisual(((WindowPtr)pDraw));
+    }
+    else
+    {
+	if (stuff->x < 0 ||
+	    stuff->x+(int)stuff->width > pDraw->width ||
+	    stuff->y < 0 ||
+	    stuff->y+(int)stuff->height > pDraw->height
+	    )
+	    return BadMatch;
+	xgi.visual = None;
+    }
+    xgi.type = X_Reply;
+    xgi.length = 0;
+    xgi.sequenceNumber = client->sequence;
+    xgi.depth = pDraw->depth;
+    if(stuff->format == ZPixmap)
+    {
+	length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
+    }
+    else
+    {
+	lenPer = PixmapBytePad(stuff->width, 1) * stuff->height;
+	plane = ((Mask)1) << (pDraw->depth - 1);
+	/* only planes asked for */
+	length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1)));
+    }
+
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client);
+    xgi.size = length;
+
+    if (length == 0)
+    {
+	/* nothing to do */
+    }
+    else if (stuff->format == ZPixmap)
+    {
+	(*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y,
+				    stuff->width, stuff->height,
+				    stuff->format, stuff->planeMask,
+				    shmdesc->addr + stuff->offset);
+    }
+    else
+    {
+
+	length = stuff->offset;
+        for (; plane; plane >>= 1)
+	{
+	    if (stuff->planeMask & plane)
+	    {
+		(*pDraw->pScreen->GetImage)(pDraw,
+					    stuff->x, stuff->y,
+					    stuff->width, stuff->height,
+					    stuff->format, plane,
+					    shmdesc->addr + length);
+		length += lenPer;
+	    }
+	}
+    }
+
+    if (client->swapped) {
+	swaps(&xgi.sequenceNumber, n);
+	swapl(&xgi.length, n);
+	swapl(&xgi.visual, n);
+	swapl(&xgi.size, n);
+    }
+    WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi);
+
+    return Success;
+}
+
 #ifdef PANORAMIX
 static int 
 ProcPanoramiXShmPutImage(ClientPtr client)
@@ -858,231 +1014,8 @@ CreatePmap:
 
     return result;
 }
-
 #endif
 
-static int
-ProcShmPutImage(ClientPtr client)
-{
-    GCPtr pGC;
-    DrawablePtr pDraw;
-    long length;
-    ShmDescPtr shmdesc;
-    REQUEST(xShmPutImageReq);
-
-    REQUEST_SIZE_MATCH(xShmPutImageReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
-    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client);
-    if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse))
-	return BadValue;
-    if (stuff->format == XYBitmap)
-    {
-        if (stuff->depth != 1)
-            return BadMatch;
-        length = PixmapBytePad(stuff->totalWidth, 1);
-    }
-    else if (stuff->format == XYPixmap)
-    {
-        if (pDraw->depth != stuff->depth)
-            return BadMatch;
-        length = PixmapBytePad(stuff->totalWidth, 1);
-	length *= stuff->depth;
-    }
-    else if (stuff->format == ZPixmap)
-    {
-        if (pDraw->depth != stuff->depth)
-            return BadMatch;
-        length = PixmapBytePad(stuff->totalWidth, stuff->depth);
-    }
-    else
-    {
-	client->errorValue = stuff->format;
-        return BadValue;
-    }
-
-    /* 
-     * There's a potential integer overflow in this check:
-     * VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight,
-     *                client);
-     * the version below ought to avoid it
-     */
-    if (stuff->totalHeight != 0 && 
-	length > (shmdesc->size - stuff->offset)/stuff->totalHeight) {
-	client->errorValue = stuff->totalWidth;
-	return BadValue;
-    }
-    if (stuff->srcX > stuff->totalWidth)
-    {
-	client->errorValue = stuff->srcX;
-	return BadValue;
-    }
-    if (stuff->srcY > stuff->totalHeight)
-    {
-	client->errorValue = stuff->srcY;
-	return BadValue;
-    }
-    if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth)
-    {
-	client->errorValue = stuff->srcWidth;
-	return BadValue;
-    }
-    if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight)
-    {
-	client->errorValue = stuff->srcHeight;
-	return BadValue;
-    }
-
-    if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) ||
-	 ((stuff->format != ZPixmap) &&
-	  (stuff->srcX < screenInfo.bitmapScanlinePad) &&
-	  ((stuff->format == XYBitmap) ||
-	   ((stuff->srcY == 0) &&
-	    (stuff->srcHeight == stuff->totalHeight))))) &&
-	((stuff->srcX + stuff->srcWidth) == stuff->totalWidth))
-	(*pGC->ops->PutImage) (pDraw, pGC, stuff->depth,
-			       stuff->dstX, stuff->dstY,
-			       stuff->totalWidth, stuff->srcHeight, 
-			       stuff->srcX, stuff->format, 
-			       shmdesc->addr + stuff->offset +
-			       (stuff->srcY * length));
-    else
-	doShmPutImage(pDraw, pGC, stuff->depth, stuff->format,
-		      stuff->totalWidth, stuff->totalHeight,
-		      stuff->srcX, stuff->srcY,
-		      stuff->srcWidth, stuff->srcHeight,
-		      stuff->dstX, stuff->dstY,
-                      shmdesc->addr + stuff->offset);
-
-    if (stuff->sendEvent)
-    {
-	xShmCompletionEvent ev;
-
-	ev.type = ShmCompletionCode;
-	ev.drawable = stuff->drawable;
-	ev.minorEvent = X_ShmPutImage;
-	ev.majorEvent = ShmReqCode;
-	ev.shmseg = stuff->shmseg;
-	ev.offset = stuff->offset;
-	WriteEventsToClient(client, 1, (xEvent *) &ev);
-    }
-
-    return Success;
-}
-
-
-
-static int
-ProcShmGetImage(ClientPtr client)
-{
-    DrawablePtr		pDraw;
-    long		lenPer = 0, length;
-    Mask		plane = 0;
-    xShmGetImageReply	xgi;
-    ShmDescPtr		shmdesc;
-    int			n, rc;
-
-    REQUEST(xShmGetImageReq);
-
-    REQUEST_SIZE_MATCH(xShmGetImageReq);
-    if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap))
-    {
-	client->errorValue = stuff->format;
-        return BadValue;
-    }
-    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
-			   DixReadAccess);
-    if (rc != Success)
-	return rc;
-    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
-    if (pDraw->type == DRAWABLE_WINDOW)
-    {
-      if( /* check for being viewable */
-	 !((WindowPtr) pDraw)->realized ||
-	  /* check for being on screen */
-         pDraw->x + stuff->x < 0 ||
- 	 pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width ||
-         pDraw->y + stuff->y < 0 ||
-         pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height ||
-          /* check for being inside of border */
-         stuff->x < - wBorderWidth((WindowPtr)pDraw) ||
-         stuff->x + (int)stuff->width >
-		wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
-         stuff->y < -wBorderWidth((WindowPtr)pDraw) ||
-         stuff->y + (int)stuff->height >
-		wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height
-        )
-	    return BadMatch;
-	xgi.visual = wVisual(((WindowPtr)pDraw));
-    }
-    else
-    {
-	if (stuff->x < 0 ||
-	    stuff->x+(int)stuff->width > pDraw->width ||
-	    stuff->y < 0 ||
-	    stuff->y+(int)stuff->height > pDraw->height
-	    )
-	    return BadMatch;
-	xgi.visual = None;
-    }
-    xgi.type = X_Reply;
-    xgi.length = 0;
-    xgi.sequenceNumber = client->sequence;
-    xgi.depth = pDraw->depth;
-    if(stuff->format == ZPixmap)
-    {
-	length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
-    }
-    else 
-    {
-	lenPer = PixmapBytePad(stuff->width, 1) * stuff->height;
-	plane = ((Mask)1) << (pDraw->depth - 1);
-	/* only planes asked for */
-	length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1)));
-    }
-
-    VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client);
-    xgi.size = length;
-
-    if (length == 0)
-    {
-	/* nothing to do */
-    }
-    else if (stuff->format == ZPixmap)
-    {
-	(*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y,
-				    stuff->width, stuff->height,
-				    stuff->format, stuff->planeMask,
-				    shmdesc->addr + stuff->offset);
-    }
-    else
-    {
-
-	length = stuff->offset;
-        for (; plane; plane >>= 1)
-	{
-	    if (stuff->planeMask & plane)
-	    {
-		(*pDraw->pScreen->GetImage)(pDraw,
-					    stuff->x, stuff->y,
-					    stuff->width, stuff->height,
-					    stuff->format, plane,
-					    shmdesc->addr + length);
-		length += lenPer;
-	    }
-	}
-    }
-    
-    if (client->swapped) {
-    	swaps(&xgi.sequenceNumber, n);
-    	swapl(&xgi.length, n);
-	swapl(&xgi.visual, n);
-	swapl(&xgi.size, n);
-    }
-    WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi);
-
-    return Success;
-}
-
 static PixmapPtr
 fbShmCreatePixmap (ScreenPtr pScreen,
 		   int width, int height, int depth, char *addr)
@@ -1342,3 +1275,53 @@ SProcShmDispatch (ClientPtr client)
 	return BadRequest;
     }
 }
+
+void
+ShmExtensionInit(INITARGS)
+{
+    ExtensionEntry *extEntry;
+    int i;
+
+#ifdef MUST_CHECK_FOR_SHM_SYSCALL
+    if (!CheckForShmSyscall())
+    {
+	ErrorF("MIT-SHM extension disabled due to lack of kernel support\n");
+	return;
+    }
+#endif
+
+    if (!ShmRegisterPrivates())
+	return;
+
+    sharedPixmaps = xFalse;
+    {
+      sharedPixmaps = xTrue;
+      for (i = 0; i < screenInfo.numScreens; i++)
+      {
+	ShmScrPrivateRec *screen_priv = ShmInitScreenPriv(screenInfo.screens[i]);
+	if (!screen_priv->shmFuncs)
+	    screen_priv->shmFuncs = &miFuncs;
+	if (!screen_priv->shmFuncs->CreatePixmap)
+	    sharedPixmaps = xFalse;
+      }
+      if (sharedPixmaps)
+	for (i = 0; i < screenInfo.numScreens; i++)
+	{
+	    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(screenInfo.screens[i]);
+	    screen_priv->destroyPixmap = screenInfo.screens[i]->DestroyPixmap;
+	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
+	}
+    }
+    ShmSegType = CreateNewResourceType(ShmDetachSegment, "ShmSeg");
+    if (ShmSegType &&
+	(extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors,
+				 ProcShmDispatch, SProcShmDispatch,
+				 ShmResetProc, StandardMinorOpcode)))
+    {
+	ShmReqCode = (unsigned char)extEntry->base;
+	ShmCompletionCode = extEntry->eventBase;
+	BadShmSegCode = extEntry->errorBase;
+	SetResourceTypeErrorValue(ShmSegType, BadShmSegCode);
+	EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
+    }
+}
diff --git a/Xext/sync.c b/Xext/sync.c
index a51262a..f23df6c 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -100,36 +100,6 @@ static void SyncInitServerTime(void);
 
 static void SyncInitIdleTime(void);
 
-static DISPATCH_PROC(ProcSyncAwait);
-static DISPATCH_PROC(ProcSyncChangeAlarm);
-static DISPATCH_PROC(ProcSyncChangeCounter);
-static DISPATCH_PROC(ProcSyncCreateAlarm);
-static DISPATCH_PROC(ProcSyncCreateCounter);
-static DISPATCH_PROC(ProcSyncDestroyAlarm);
-static DISPATCH_PROC(ProcSyncDestroyCounter);
-static DISPATCH_PROC(ProcSyncDispatch);
-static DISPATCH_PROC(ProcSyncGetPriority);
-static DISPATCH_PROC(ProcSyncInitialize);
-static DISPATCH_PROC(ProcSyncListSystemCounters);
-static DISPATCH_PROC(ProcSyncQueryAlarm);
-static DISPATCH_PROC(ProcSyncQueryCounter);
-static DISPATCH_PROC(ProcSyncSetCounter);
-static DISPATCH_PROC(ProcSyncSetPriority);
-static DISPATCH_PROC(SProcSyncAwait);
-static DISPATCH_PROC(SProcSyncChangeAlarm);
-static DISPATCH_PROC(SProcSyncChangeCounter);
-static DISPATCH_PROC(SProcSyncCreateAlarm);
-static DISPATCH_PROC(SProcSyncCreateCounter);
-static DISPATCH_PROC(SProcSyncDestroyAlarm);
-static DISPATCH_PROC(SProcSyncDestroyCounter);
-static DISPATCH_PROC(SProcSyncDispatch);
-static DISPATCH_PROC(SProcSyncGetPriority);
-static DISPATCH_PROC(SProcSyncInitialize);
-static DISPATCH_PROC(SProcSyncListSystemCounters);
-static DISPATCH_PROC(SProcSyncQueryAlarm);
-static DISPATCH_PROC(SProcSyncQueryCounter);
-static DISPATCH_PROC(SProcSyncSetCounter);
-static DISPATCH_PROC(SProcSyncSetPriority);
 
 /*  Each counter maintains a simple linked list of triggers that are
  *  interested in the counter.  The two functions below are used to
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 986c870..378afcc 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -46,24 +46,6 @@ from The Open Group.
 #define UINT32_MAX 0xffffffffU
 #endif
 
-static DISPATCH_PROC(ProcXCMiscDispatch);
-static DISPATCH_PROC(ProcXCMiscGetVersion);
-static DISPATCH_PROC(ProcXCMiscGetXIDList);
-static DISPATCH_PROC(ProcXCMiscGetXIDRange);
-static DISPATCH_PROC(SProcXCMiscDispatch);
-static DISPATCH_PROC(SProcXCMiscGetVersion);
-static DISPATCH_PROC(SProcXCMiscGetXIDList);
-static DISPATCH_PROC(SProcXCMiscGetXIDRange);
-
-void XCMiscExtensionInit(INITARGS);
-
-void
-XCMiscExtensionInit(INITARGS)
-{
-    AddExtension(XCMiscExtensionName, 0, 0,
-		 ProcXCMiscDispatch, SProcXCMiscDispatch,
-		 NULL, StandardMinorOpcode);
-}
 
 static int
 ProcXCMiscGetVersion(ClientPtr client)
@@ -215,3 +197,11 @@ SProcXCMiscDispatch (ClientPtr client)
 	return BadRequest;
     }
 }
+
+void
+XCMiscExtensionInit(INITARGS)
+{
+    AddExtension(XCMiscExtensionName, 0, 0,
+		 ProcXCMiscDispatch, SProcXCMiscDispatch,
+		 NULL, StandardMinorOpcode);
+}
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 8f0ddd9..f7dde6e 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -80,12 +80,6 @@ static void XF86BigfontResetProc(
     ExtensionEntry *	/* extEntry */
     );
 
-static DISPATCH_PROC(ProcXF86BigfontDispatch);
-static DISPATCH_PROC(ProcXF86BigfontQueryVersion);
-static DISPATCH_PROC(ProcXF86BigfontQueryFont);
-static DISPATCH_PROC(SProcXF86BigfontDispatch);
-static DISPATCH_PROC(SProcXF86BigfontQueryVersion);
-static DISPATCH_PROC(SProcXF86BigfontQueryFont);
 
 #ifdef HAS_SHM
 
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 7268768..d7d254c 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -84,26 +84,6 @@ static int XTestSwapFakeInput(
         xReq * /* req */
         );
 
-static DISPATCH_PROC(ProcXTestCompareCursor);
-static DISPATCH_PROC(ProcXTestDispatch);
-static DISPATCH_PROC(ProcXTestFakeInput);
-static DISPATCH_PROC(ProcXTestGetVersion);
-static DISPATCH_PROC(ProcXTestGrabControl);
-static DISPATCH_PROC(SProcXTestCompareCursor);
-static DISPATCH_PROC(SProcXTestDispatch);
-static DISPATCH_PROC(SProcXTestFakeInput);
-static DISPATCH_PROC(SProcXTestGetVersion);
-static DISPATCH_PROC(SProcXTestGrabControl);
-
-void
-XTestExtensionInit(INITARGS)
-{
-    AddExtension(XTestExtensionName, 0, 0,
-            ProcXTestDispatch, SProcXTestDispatch,
-            NULL, StandardMinorOpcode);
-
-    xtest_evlist = InitEventList(GetMaximumEventsNum());
-}
 
 static int
 ProcXTestGetVersion(ClientPtr client)
@@ -699,3 +679,12 @@ GetXTestDevice(DeviceIntPtr master)
     return NULL;
 }
 
+void
+XTestExtensionInit(INITARGS)
+{
+    AddExtension(XTestExtensionName, 0, 0,
+            ProcXTestDispatch, SProcXTestDispatch,
+            NULL, StandardMinorOpcode);
+
+    xtest_evlist = InitEventList(GetMaximumEventsNum());
+}
diff --git a/dix/dispatch.h b/dix/dispatch.h
index dd07096..758b83d 100644
--- a/dix/dispatch.h
+++ b/dix/dispatch.h
@@ -36,111 +36,110 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #ifndef DISPATCH_H
 #define DISPATCH_H 1
 
-DISPATCH_PROC(InitClientPrivates);
-DISPATCH_PROC(ProcAllocColor);
-DISPATCH_PROC(ProcAllocColorCells);
-DISPATCH_PROC(ProcAllocColorPlanes);
-DISPATCH_PROC(ProcAllocNamedColor);
-DISPATCH_PROC(ProcBell);
-DISPATCH_PROC(ProcChangeAccessControl);
-DISPATCH_PROC(ProcChangeCloseDownMode);
-DISPATCH_PROC(ProcChangeGC);
-DISPATCH_PROC(ProcChangeHosts);
-DISPATCH_PROC(ProcChangeKeyboardControl);
-DISPATCH_PROC(ProcChangeKeyboardMapping);
-DISPATCH_PROC(ProcChangePointerControl);
-DISPATCH_PROC(ProcChangeProperty);
-DISPATCH_PROC(ProcChangeSaveSet);
-DISPATCH_PROC(ProcChangeWindowAttributes);
-DISPATCH_PROC(ProcCirculateWindow);
-DISPATCH_PROC(ProcClearToBackground);
-DISPATCH_PROC(ProcCloseFont);
-DISPATCH_PROC(ProcConfigureWindow);
-DISPATCH_PROC(ProcConvertSelection);
-DISPATCH_PROC(ProcCopyArea);
-DISPATCH_PROC(ProcCopyColormapAndFree);
-DISPATCH_PROC(ProcCopyGC);
-DISPATCH_PROC(ProcCopyPlane);
-DISPATCH_PROC(ProcCreateColormap);
-DISPATCH_PROC(ProcCreateCursor);
-DISPATCH_PROC(ProcCreateGC);
-DISPATCH_PROC(ProcCreateGlyphCursor);
-DISPATCH_PROC(ProcCreatePixmap);
-DISPATCH_PROC(ProcCreateWindow);
-DISPATCH_PROC(ProcDeleteProperty);
-DISPATCH_PROC(ProcDestroySubwindows);
-DISPATCH_PROC(ProcDestroyWindow);
-DISPATCH_PROC(ProcEstablishConnection);
-DISPATCH_PROC(ProcFillPoly);
-DISPATCH_PROC(ProcForceScreenSaver);
-DISPATCH_PROC(ProcFreeColormap);
-DISPATCH_PROC(ProcFreeColors);
-DISPATCH_PROC(ProcFreeCursor);
-DISPATCH_PROC(ProcFreeGC);
-DISPATCH_PROC(ProcFreePixmap);
-DISPATCH_PROC(ProcGetAtomName);
-DISPATCH_PROC(ProcGetFontPath);
-DISPATCH_PROC(ProcGetGeometry);
-DISPATCH_PROC(ProcGetImage);
-DISPATCH_PROC(ProcGetKeyboardControl);
-DISPATCH_PROC(ProcGetKeyboardMapping);
-DISPATCH_PROC(ProcGetModifierMapping);
-DISPATCH_PROC(ProcGetMotionEvents);
-DISPATCH_PROC(ProcGetPointerControl);
-DISPATCH_PROC(ProcGetPointerMapping);
-DISPATCH_PROC(ProcGetProperty);
-DISPATCH_PROC(ProcGetScreenSaver);
-DISPATCH_PROC(ProcGetSelectionOwner);
-DISPATCH_PROC(ProcGetWindowAttributes);
-DISPATCH_PROC(ProcGrabServer);
-DISPATCH_PROC(ProcImageText16);
-DISPATCH_PROC(ProcImageText8);
-DISPATCH_PROC(ProcInitialConnection);
-DISPATCH_PROC(ProcInstallColormap);
-DISPATCH_PROC(ProcInternAtom);
-DISPATCH_PROC(ProcKillClient);
-DISPATCH_PROC(ProcListExtensions);
-DISPATCH_PROC(ProcListFonts);
-DISPATCH_PROC(ProcListFontsWithInfo);
-DISPATCH_PROC(ProcListHosts);
-DISPATCH_PROC(ProcListInstalledColormaps);
-DISPATCH_PROC(ProcListProperties);
-DISPATCH_PROC(ProcLookupColor);
-DISPATCH_PROC(ProcMapSubwindows);
-DISPATCH_PROC(ProcMapWindow);
-DISPATCH_PROC(ProcNoOperation);
-DISPATCH_PROC(ProcOpenFont);
-DISPATCH_PROC(ProcPolyArc);
-DISPATCH_PROC(ProcPolyFillArc);
-DISPATCH_PROC(ProcPolyFillRectangle);
-DISPATCH_PROC(ProcPolyLine);
-DISPATCH_PROC(ProcPolyPoint);
-DISPATCH_PROC(ProcPolyRectangle);
-DISPATCH_PROC(ProcPolySegment);
-DISPATCH_PROC(ProcPolyText);
-DISPATCH_PROC(ProcPutImage);
-DISPATCH_PROC(ProcQueryBestSize);
-DISPATCH_PROC(ProcQueryColors);
-DISPATCH_PROC(ProcQueryExtension);
-DISPATCH_PROC(ProcQueryFont);
-DISPATCH_PROC(ProcQueryKeymap);
-DISPATCH_PROC(ProcQueryTextExtents);
-DISPATCH_PROC(ProcQueryTree);
-DISPATCH_PROC(ProcReparentWindow);
-DISPATCH_PROC(ProcRotateProperties);
-DISPATCH_PROC(ProcSetClipRectangles);
-DISPATCH_PROC(ProcSetDashes);
-DISPATCH_PROC(ProcSetFontPath);
-DISPATCH_PROC(ProcSetModifierMapping);
-DISPATCH_PROC(ProcSetPointerMapping);
-DISPATCH_PROC(ProcSetScreenSaver);
-DISPATCH_PROC(ProcSetSelectionOwner);
-DISPATCH_PROC(ProcStoreColors);
-DISPATCH_PROC(ProcStoreNamedColor);
-DISPATCH_PROC(ProcTranslateCoords);
-DISPATCH_PROC(ProcUngrabServer);
-DISPATCH_PROC(ProcUninstallColormap);
-DISPATCH_PROC(ProcUnmapSubwindows);
-DISPATCH_PROC(ProcUnmapWindow);
+int ProcAllocColor(ClientPtr /* client */);
+int ProcAllocColorCells(ClientPtr /* client */);
+int ProcAllocColorPlanes(ClientPtr /* client */);
+int ProcAllocNamedColor(ClientPtr /* client */);
+int ProcBell(ClientPtr /* client */);
+int ProcChangeAccessControl(ClientPtr /* client */);
+int ProcChangeCloseDownMode(ClientPtr /* client */);
+int ProcChangeGC(ClientPtr /* client */);
+int ProcChangeHosts(ClientPtr /* client */);
+int ProcChangeKeyboardControl(ClientPtr /* client */);
+int ProcChangeKeyboardMapping(ClientPtr /* client */);
+int ProcChangePointerControl(ClientPtr /* client */);
+int ProcChangeProperty(ClientPtr /* client */);
+int ProcChangeSaveSet(ClientPtr /* client */);
+int ProcChangeWindowAttributes(ClientPtr /* client */);
+int ProcCirculateWindow(ClientPtr /* client */);
+int ProcClearToBackground(ClientPtr /* client */);
+int ProcCloseFont(ClientPtr /* client */);
+int ProcConfigureWindow(ClientPtr /* client */);
+int ProcConvertSelection(ClientPtr /* client */);
+int ProcCopyArea(ClientPtr /* client */);
+int ProcCopyColormapAndFree(ClientPtr /* client */);
+int ProcCopyGC(ClientPtr /* client */);
+int ProcCopyPlane(ClientPtr /* client */);
+int ProcCreateColormap(ClientPtr /* client */);
+int ProcCreateCursor(ClientPtr /* client */);
+int ProcCreateGC(ClientPtr /* client */);
+int ProcCreateGlyphCursor(ClientPtr /* client */);
+int ProcCreatePixmap(ClientPtr /* client */);
+int ProcCreateWindow(ClientPtr /* client */);
+int ProcDeleteProperty(ClientPtr /* client */);
+int ProcDestroySubwindows(ClientPtr /* client */);
+int ProcDestroyWindow(ClientPtr /* client */);
+int ProcEstablishConnection(ClientPtr /* client */);
+int ProcFillPoly(ClientPtr /* client */);
+int ProcForceScreenSaver(ClientPtr /* client */);
+int ProcFreeColormap(ClientPtr /* client */);
+int ProcFreeColors(ClientPtr /* client */);
+int ProcFreeCursor(ClientPtr /* client */);
+int ProcFreeGC(ClientPtr /* client */);
+int ProcFreePixmap(ClientPtr /* client */);
+int ProcGetAtomName(ClientPtr /* client */);
+int ProcGetFontPath(ClientPtr /* client */);
+int ProcGetGeometry(ClientPtr /* client */);
+int ProcGetImage(ClientPtr /* client */);
+int ProcGetKeyboardControl(ClientPtr /* client */);
+int ProcGetKeyboardMapping(ClientPtr /* client */);
+int ProcGetModifierMapping(ClientPtr /* client */);
+int ProcGetMotionEvents(ClientPtr /* client */);
+int ProcGetPointerControl(ClientPtr /* client */);
+int ProcGetPointerMapping(ClientPtr /* client */);
+int ProcGetProperty(ClientPtr /* client */);
+int ProcGetScreenSaver(ClientPtr /* client */);
+int ProcGetSelectionOwner(ClientPtr /* client */);
+int ProcGetWindowAttributes(ClientPtr /* client */);
+int ProcGrabServer(ClientPtr /* client */);
+int ProcImageText16(ClientPtr /* client */);
+int ProcImageText8(ClientPtr /* client */);
+int ProcInitialConnection(ClientPtr /* client */);
+int ProcInstallColormap(ClientPtr /* client */);
+int ProcInternAtom(ClientPtr /* client */);
+int ProcKillClient(ClientPtr /* client */);
+int ProcListExtensions(ClientPtr /* client */);
+int ProcListFonts(ClientPtr /* client */);
+int ProcListFontsWithInfo(ClientPtr /* client */);
+int ProcListHosts(ClientPtr /* client */);
+int ProcListInstalledColormaps(ClientPtr /* client */);
+int ProcListProperties(ClientPtr /* client */);
+int ProcLookupColor(ClientPtr /* client */);
+int ProcMapSubwindows(ClientPtr /* client */);
+int ProcMapWindow(ClientPtr /* client */);
+int ProcNoOperation(ClientPtr /* client */);
+int ProcOpenFont(ClientPtr /* client */);
+int ProcPolyArc(ClientPtr /* client */);
+int ProcPolyFillArc(ClientPtr /* client */);
+int ProcPolyFillRectangle(ClientPtr /* client */);
+int ProcPolyLine(ClientPtr /* client */);
+int ProcPolyPoint(ClientPtr /* client */);
+int ProcPolyRectangle(ClientPtr /* client */);
+int ProcPolySegment(ClientPtr /* client */);
+int ProcPolyText(ClientPtr /* client */);
+int ProcPutImage(ClientPtr /* client */);
+int ProcQueryBestSize(ClientPtr /* client */);
+int ProcQueryColors(ClientPtr /* client */);
+int ProcQueryExtension(ClientPtr /* client */);
+int ProcQueryFont(ClientPtr /* client */);
+int ProcQueryKeymap(ClientPtr /* client */);
+int ProcQueryTextExtents(ClientPtr /* client */);
+int ProcQueryTree(ClientPtr /* client */);
+int ProcReparentWindow(ClientPtr /* client */);
+int ProcRotateProperties(ClientPtr /* client */);
+int ProcSetClipRectangles(ClientPtr /* client */);
+int ProcSetDashes(ClientPtr /* client */);
+int ProcSetFontPath(ClientPtr /* client */);
+int ProcSetModifierMapping(ClientPtr /* client */);
+int ProcSetPointerMapping(ClientPtr /* client */);
+int ProcSetScreenSaver(ClientPtr /* client */);
+int ProcSetSelectionOwner(ClientPtr /* client */);
+int ProcStoreColors(ClientPtr /* client */);
+int ProcStoreNamedColor(ClientPtr /* client */);
+int ProcTranslateCoords(ClientPtr /* client */);
+int ProcUngrabServer(ClientPtr /* client */);
+int ProcUninstallColormap(ClientPtr /* client */);
+int ProcUnmapSubwindows(ClientPtr /* client */);
+int ProcUnmapWindow(ClientPtr /* client */);
 
 #endif /* DISPATCH_H */
diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 5718b6a..1dee077 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -69,39 +69,7 @@ extern void DMXExtensionInit(void);
 
 static unsigned char DMXCode;
 
-static DISPATCH_PROC(ProcDMXDispatch);
-static DISPATCH_PROC(ProcDMXQueryVersion);
-static DISPATCH_PROC(ProcDMXSync);
-static DISPATCH_PROC(ProcDMXForceWindowCreation);
-static DISPATCH_PROC(ProcDMXGetScreenCount);
-static DISPATCH_PROC(ProcDMXGetScreenAttributes);
-static DISPATCH_PROC(ProcDMXChangeScreensAttributes);
-static DISPATCH_PROC(ProcDMXAddScreen);
-static DISPATCH_PROC(ProcDMXRemoveScreen);
-static DISPATCH_PROC(ProcDMXGetWindowAttributes);
-static DISPATCH_PROC(ProcDMXGetDesktopAttributes);
-static DISPATCH_PROC(ProcDMXChangeDesktopAttributes);
-static DISPATCH_PROC(ProcDMXGetInputCount);
-static DISPATCH_PROC(ProcDMXGetInputAttributes);
-static DISPATCH_PROC(ProcDMXAddInput);
-static DISPATCH_PROC(ProcDMXRemoveInput);
-
-static DISPATCH_PROC(SProcDMXDispatch);
-static DISPATCH_PROC(SProcDMXQueryVersion);
-static DISPATCH_PROC(SProcDMXSync);
-static DISPATCH_PROC(SProcDMXForceWindowCreation);
-static DISPATCH_PROC(SProcDMXGetScreenCount);
-static DISPATCH_PROC(SProcDMXGetScreenAttributes);
-static DISPATCH_PROC(SProcDMXChangeScreensAttributes);
-static DISPATCH_PROC(SProcDMXAddScreen);
-static DISPATCH_PROC(SProcDMXRemoveScreen);
-static DISPATCH_PROC(SProcDMXGetWindowAttributes);
-static DISPATCH_PROC(SProcDMXGetDesktopAttributes);
-static DISPATCH_PROC(SProcDMXChangeDesktopAttributes);
-static DISPATCH_PROC(SProcDMXGetInputCount);
-static DISPATCH_PROC(SProcDMXGetInputAttributes);
-static DISPATCH_PROC(SProcDMXAddInput);
-static DISPATCH_PROC(SProcDMXRemoveInput);
+
 
 static int _DMXXineramaActive(void)
 {
@@ -111,17 +79,6 @@ static int _DMXXineramaActive(void)
     return 0;
 }
 
-/** Initialize the extension. */
-void DMXExtensionInit(void)
-{
-    ExtensionEntry *extEntry;
-    
-    if ((extEntry = AddExtension(DMX_EXTENSION_NAME, 0, 0,
-                                 ProcDMXDispatch, SProcDMXDispatch,
-                                 NULL, StandardMinorOpcode)))
-	DMXCode = extEntry->base;
-}
-
 static void dmxSetScreenAttribute(int bit, DMXScreenAttributesPtr attr,
                                   CARD32 value)
 {
@@ -1125,3 +1082,14 @@ static int SProcDMXDispatch (ClientPtr client)
     default:                        return BadRequest;
     }
 }
+
+/** Initialize the extension. */
+void DMXExtensionInit(void)
+{
+    ExtensionEntry *extEntry;
+    
+    if ((extEntry = AddExtension(DMX_EXTENSION_NAME, 0, 0,
+                                 ProcDMXDispatch, SProcDMXDispatch,
+                                 NULL, StandardMinorOpcode)))
+	DMXCode = extEntry->base;
+}
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index ce584b0..8874a43 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -72,23 +72,7 @@ typedef EphyrDRIScreenPrivRec* EphyrDRIScreenPrivPtr;
 
 static int DRIErrorBase;
 
-static DISPATCH_PROC(ProcXF86DRIQueryVersion);
-static DISPATCH_PROC(ProcXF86DRIQueryDirectRenderingCapable);
-static DISPATCH_PROC(ProcXF86DRIOpenConnection);
-static DISPATCH_PROC(ProcXF86DRICloseConnection);
-static DISPATCH_PROC(ProcXF86DRIGetClientDriverName);
-static DISPATCH_PROC(ProcXF86DRICreateContext);
-static DISPATCH_PROC(ProcXF86DRIDestroyContext);
-static DISPATCH_PROC(ProcXF86DRICreateDrawable);
-static DISPATCH_PROC(ProcXF86DRIDestroyDrawable);
-static DISPATCH_PROC(ProcXF86DRIGetDrawableInfo);
-static DISPATCH_PROC(ProcXF86DRIGetDeviceInfo);
-static DISPATCH_PROC(ProcXF86DRIDispatch);
-static DISPATCH_PROC(ProcXF86DRIAuthConnection);
-
-static DISPATCH_PROC(SProcXF86DRIQueryVersion);
-static DISPATCH_PROC(SProcXF86DRIQueryDirectRenderingCapable);
-static DISPATCH_PROC(SProcXF86DRIDispatch);
+
 
 static Bool ephyrDRIScreenInit (ScreenPtr a_screen) ;
 static Bool ephyrDRICreateWindow (WindowPtr a_win) ;
@@ -119,65 +103,6 @@ static DevPrivateKeyRec ephyrDRIScreenKeyRec;
 #define GET_EPHYR_DRI_SCREEN_PRIV(screen) ((EphyrDRIScreenPrivPtr) \
     dixLookupPrivate(&(screen)->devPrivates, ephyrDRIScreenKey))
 
-
-Bool
-ephyrDRIExtensionInit (ScreenPtr a_screen)
-{
-    Bool is_ok=FALSE ;
-    ExtensionEntry* extEntry=NULL;
-    EphyrDRIScreenPrivPtr screen_priv=NULL ;
-
-    EPHYR_LOG ("enter\n") ;
-    if (!hostx_has_dri ()) {
-        EPHYR_LOG ("host does not have DRI extension\n") ;
-        goto out ;
-    }
-    EPHYR_LOG ("host X does have DRI extension\n") ;
-    if (!hostx_has_xshape ()) {
-        EPHYR_LOG ("host does not have XShape extension\n") ;
-        goto out ;
-    }
-    EPHYR_LOG ("host X does have XShape extension\n") ;
-
-#ifdef XF86DRI_EVENTS
-    EventType = CreateNewResourceType (XF86DRIFreeEvents, "DRIEvents");
-    if (!EventType) {
-        EPHYR_LOG_ERROR ("failed to register DRI event resource type\n") ;
-        goto out ;
-    }
-#endif
-
-    if ((extEntry = AddExtension(XF86DRINAME,
-				 XF86DRINumberEvents,
-				 XF86DRINumberErrors,
-				 ProcXF86DRIDispatch,
-				 SProcXF86DRIDispatch,
-				 NULL,
-				 StandardMinorOpcode))) {
-	DRIReqCode = (unsigned char)extEntry->base;
-	DRIErrorBase = extEntry->errorBase;
-    } else {
-        EPHYR_LOG_ERROR ("failed to register DRI extension\n") ;
-        goto out ;
-    }
-    screen_priv = calloc(1, sizeof (EphyrDRIScreenPrivRec)) ;
-    if (!screen_priv) {
-        EPHYR_LOG_ERROR ("failed to allocate screen_priv\n") ;
-        goto out ;
-    }
-    dixSetPrivate(&a_screen->devPrivates, ephyrDRIScreenKey, screen_priv);
-
-    if (!ephyrDRIScreenInit (a_screen)) {
-        EPHYR_LOG_ERROR ("ephyrDRIScreenInit() failed\n") ;
-        goto out ;
-    }
-    EphyrMirrorHostVisuals (a_screen) ;
-    is_ok=TRUE ;
-out:
-    EPHYR_LOG ("leave\n") ;
-    return is_ok ;
-}
-
 static Bool
 ephyrDRIScreenInit (ScreenPtr a_screen)
 {
@@ -1428,3 +1353,61 @@ SProcXF86DRIDispatch (register ClientPtr client)
         }
     }
 }
+
+Bool
+ephyrDRIExtensionInit (ScreenPtr a_screen)
+{
+    Bool is_ok=FALSE ;
+    ExtensionEntry* extEntry=NULL;
+    EphyrDRIScreenPrivPtr screen_priv=NULL ;
+
+    EPHYR_LOG ("enter\n") ;
+    if (!hostx_has_dri ()) {
+        EPHYR_LOG ("host does not have DRI extension\n") ;
+        goto out ;
+    }
+    EPHYR_LOG ("host X does have DRI extension\n") ;
+    if (!hostx_has_xshape ()) {
+        EPHYR_LOG ("host does not have XShape extension\n") ;
+        goto out ;
+    }
+    EPHYR_LOG ("host X does have XShape extension\n") ;
+
+#ifdef XF86DRI_EVENTS
+    EventType = CreateNewResourceType (XF86DRIFreeEvents, "DRIEvents");
+    if (!EventType) {
+        EPHYR_LOG_ERROR ("failed to register DRI event resource type\n") ;
+        goto out ;
+    }
+#endif
+
+    if ((extEntry = AddExtension(XF86DRINAME,
+				 XF86DRINumberEvents,
+				 XF86DRINumberErrors,
+				 ProcXF86DRIDispatch,
+				 SProcXF86DRIDispatch,
+				 NULL,
+				 StandardMinorOpcode))) {
+	DRIReqCode = (unsigned char)extEntry->base;
+	DRIErrorBase = extEntry->errorBase;
+    } else {
+        EPHYR_LOG_ERROR ("failed to register DRI extension\n") ;
+        goto out ;
+    }
+    screen_priv = calloc(1, sizeof (EphyrDRIScreenPrivRec)) ;
+    if (!screen_priv) {
+        EPHYR_LOG_ERROR ("failed to allocate screen_priv\n") ;
+        goto out ;
+    }
+    dixSetPrivate(&a_screen->devPrivates, ephyrDRIScreenKey, screen_priv);
+
+    if (!ephyrDRIScreenInit (a_screen)) {
+        EPHYR_LOG_ERROR ("ephyrDRIScreenInit() failed\n") ;
+        goto out ;
+    }
+    EphyrMirrorHostVisuals (a_screen) ;
+    is_ok=TRUE ;
+out:
+    EPHYR_LOG ("leave\n") ;
+    return is_ok ;
+}
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index d93e63a..cce19f7 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -4,7 +4,7 @@ extsmoduledir = $(moduledir)/extensions
 extsmodule_LTLIBRARIES = libextmod.la
 
 if DGA
-DGA_SRCS = xf86dga2.c dgaproc.h xf86dgaext.h
+DGA_SRCS = xf86dga2.c dgaproc.h
 endif
 
 if XV
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index e522b5c..ca5d519 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -25,7 +25,6 @@
 #include <X11/extensions/xf86dgaproto.h>
 #include "swaprep.h"
 #include "dgaproc.h"
-#include "xf86dgaext.h"
 #include "protocol-versions.h"
 
 #include <string.h>
@@ -34,24 +33,6 @@
 
 #define DGA_PROTOCOL_OLD_SUPPORT 1
 
-static DISPATCH_PROC(ProcXDGADispatch);
-static DISPATCH_PROC(SProcXDGADispatch);
-static DISPATCH_PROC(ProcXDGAQueryVersion);
-static DISPATCH_PROC(ProcXDGAQueryModes);
-static DISPATCH_PROC(ProcXDGASetMode);
-static DISPATCH_PROC(ProcXDGAOpenFramebuffer);
-static DISPATCH_PROC(ProcXDGACloseFramebuffer);
-static DISPATCH_PROC(ProcXDGASetViewport);
-static DISPATCH_PROC(ProcXDGAInstallColormap);
-static DISPATCH_PROC(ProcXDGASelectInput);
-static DISPATCH_PROC(ProcXDGAFillRectangle);
-static DISPATCH_PROC(ProcXDGACopyArea);
-static DISPATCH_PROC(ProcXDGACopyTransparentArea);
-static DISPATCH_PROC(ProcXDGAGetViewportStatus);
-static DISPATCH_PROC(ProcXDGASync);
-static DISPATCH_PROC(ProcXDGASetClientVersion);
-static DISPATCH_PROC(ProcXDGAChangePixmapMode);
-static DISPATCH_PROC(ProcXDGACreateColormap);
 
 static void XDGAResetProc(ExtensionEntry *extEntry);
 
@@ -85,36 +66,6 @@ typedef struct {
     dixSetPrivate(&(c)->devPrivates, DGAClientPrivateKey, p)
 
 
-void
-XFree86DGAExtensionInit(INITARGS)
-{
-    ExtensionEntry* extEntry;
-
-    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
-	return;
-
-    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
-	return;
-
-    if ((extEntry = AddExtension(XF86DGANAME,
-				XF86DGANumberEvents,
-				XF86DGANumberErrors,
-				ProcXDGADispatch,
-				SProcXDGADispatch,
-				XDGAResetProc,
-				StandardMinorOpcode))) {
-	int i;
-
-	DGAReqCode = (unsigned char)extEntry->base;
-	DGAErrorBase = extEntry->errorBase;
-	DGAEventBase = extEntry->eventBase;
-	for (i = KeyPress; i <= MotionNotify; i++)
-	    SetCriticalEvent (DGAEventBase + i);
-    }
-}
-
-
-
 static void
 XDGAResetProc (ExtensionEntry *extEntry)
 {
@@ -663,15 +614,6 @@ ProcXDGACreateColormap(ClientPtr client)
 
 #ifdef DGA_PROTOCOL_OLD_SUPPORT
 
-static DISPATCH_PROC(ProcXF86DGADirectVideo);
-static DISPATCH_PROC(ProcXF86DGAGetVidPage);
-static DISPATCH_PROC(ProcXF86DGAGetVideoLL);
-static DISPATCH_PROC(ProcXF86DGAGetViewPortSize);
-static DISPATCH_PROC(ProcXF86DGASetVidPage);
-static DISPATCH_PROC(ProcXF86DGASetViewPort);
-static DISPATCH_PROC(ProcXF86DGAInstallColormap);
-static DISPATCH_PROC(ProcXF86DGAQueryDirectVideo);
-static DISPATCH_PROC(ProcXF86DGAViewPortChanged);
 
 
 static int
@@ -1063,3 +1005,31 @@ XFree86DGARegister(INITARGS)
 {
   XDGAEventBase = &DGAEventBase;
 }
+
+void
+XFree86DGAExtensionInit(INITARGS)
+{
+    ExtensionEntry* extEntry;
+
+    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    if ((extEntry = AddExtension(XF86DGANAME,
+				XF86DGANumberEvents,
+				XF86DGANumberErrors,
+				ProcXDGADispatch,
+				SProcXDGADispatch,
+				XDGAResetProc,
+				StandardMinorOpcode))) {
+	int i;
+
+	DGAReqCode = (unsigned char)extEntry->base;
+	DGAErrorBase = extEntry->errorBase;
+	DGAEventBase = extEntry->eventBase;
+	for (i = KeyPress; i <= MotionNotify; i++)
+	    SetCriticalEvent (DGAEventBase + i);
+    }
+}
diff --git a/hw/xfree86/dixmods/extmod/xf86dgaext.h b/hw/xfree86/dixmods/extmod/xf86dgaext.h
deleted file mode 100644
index 2b17373..0000000
--- a/hw/xfree86/dixmods/extmod/xf86dgaext.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef _XF86DGAEXT_H_
-#define _XF86DGAEXT_H_
-
-extern DISPATCH_PROC(ProcXF86DGADispatch);
-
-#endif /* _XF86DGAEXT_H_ */
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 0001c9e..4737f2d 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -65,48 +65,6 @@ typedef struct {
 #define VM_SETPRIV(c,p) \
     dixSetPrivate(&(c)->devPrivates, VidModeClientPrivateKey, p)
 
-static DISPATCH_PROC(ProcXF86VidModeDispatch);
-static DISPATCH_PROC(ProcXF86VidModeGetAllModeLines);
-static DISPATCH_PROC(ProcXF86VidModeGetModeLine);
-static DISPATCH_PROC(ProcXF86VidModeGetMonitor);
-static DISPATCH_PROC(ProcXF86VidModeLockModeSwitch);
-static DISPATCH_PROC(ProcXF86VidModeAddModeLine);
-static DISPATCH_PROC(ProcXF86VidModeDeleteModeLine);
-static DISPATCH_PROC(ProcXF86VidModeModModeLine);
-static DISPATCH_PROC(ProcXF86VidModeValidateModeLine);
-static DISPATCH_PROC(ProcXF86VidModeQueryVersion);
-static DISPATCH_PROC(ProcXF86VidModeSwitchMode);
-static DISPATCH_PROC(ProcXF86VidModeSwitchToMode);
-static DISPATCH_PROC(ProcXF86VidModeGetViewPort);
-static DISPATCH_PROC(ProcXF86VidModeSetViewPort);
-static DISPATCH_PROC(ProcXF86VidModeGetDotClocks);
-static DISPATCH_PROC(ProcXF86VidModeSetGamma);
-static DISPATCH_PROC(ProcXF86VidModeGetGamma);
-static DISPATCH_PROC(ProcXF86VidModeSetClientVersion);
-static DISPATCH_PROC(ProcXF86VidModeGetGammaRamp);
-static DISPATCH_PROC(ProcXF86VidModeSetGammaRamp);
-static DISPATCH_PROC(ProcXF86VidModeGetGammaRampSize);
-static DISPATCH_PROC(SProcXF86VidModeDispatch);
-static DISPATCH_PROC(SProcXF86VidModeGetAllModeLines);
-static DISPATCH_PROC(SProcXF86VidModeGetModeLine);
-static DISPATCH_PROC(SProcXF86VidModeGetMonitor);
-static DISPATCH_PROC(SProcXF86VidModeLockModeSwitch);
-static DISPATCH_PROC(SProcXF86VidModeAddModeLine);
-static DISPATCH_PROC(SProcXF86VidModeDeleteModeLine);
-static DISPATCH_PROC(SProcXF86VidModeModModeLine);
-static DISPATCH_PROC(SProcXF86VidModeValidateModeLine);
-static DISPATCH_PROC(SProcXF86VidModeQueryVersion);
-static DISPATCH_PROC(SProcXF86VidModeSwitchMode);
-static DISPATCH_PROC(SProcXF86VidModeSwitchToMode);
-static DISPATCH_PROC(SProcXF86VidModeGetViewPort);
-static DISPATCH_PROC(SProcXF86VidModeSetViewPort);
-static DISPATCH_PROC(SProcXF86VidModeGetDotClocks);
-static DISPATCH_PROC(SProcXF86VidModeSetGamma);
-static DISPATCH_PROC(SProcXF86VidModeGetGamma);
-static DISPATCH_PROC(SProcXF86VidModeSetClientVersion);
-static DISPATCH_PROC(SProcXF86VidModeGetGammaRamp);
-static DISPATCH_PROC(SProcXF86VidModeSetGammaRamp);
-static DISPATCH_PROC(SProcXF86VidModeGetGammaRampSize);
 
 #if 0
 static unsigned char XF86VidModeReqCode = 0;
@@ -159,58 +117,6 @@ static DevPrivateKeyRec ScreenPrivateKeyRec;
 # define DEBUG_P(x) /**/
 #endif
 
-void
-XFree86VidModeExtensionInit(void)
-{
-    ExtensionEntry* extEntry;
-    ScreenPtr pScreen;
-    int		    i;
-    Bool	    enabled = FALSE;
-
-    DEBUG_P("XFree86VidModeExtensionInit");
-
-    if (!dixRegisterPrivateKey(&VidModeClientPrivateKeyRec, PRIVATE_CLIENT, 0))
-	return;
-#ifdef XF86VIDMODE_EVENTS
-    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
-	return;
-#endif
-
-#ifdef XF86VIDMODE_EVENTS
-    EventType = CreateNewResourceType(XF86VidModeFreeEvents, "VidModeEvent");
-#endif
-
-    for(i = 0; i < screenInfo.numScreens; i++) {
-        pScreen = screenInfo.screens[i];
-	if (VidModeExtensionInit(pScreen))
-	    enabled = TRUE;
-    }
-    /* This means that the DDX doesn't want the vidmode extension enabled */
-    if (!enabled)
-	return;
-
-    if (
-#ifdef XF86VIDMODE_EVENTS
-        EventType &&
-#endif
-	(extEntry = AddExtension(XF86VIDMODENAME,
-				XF86VidModeNumberEvents,
-				XF86VidModeNumberErrors,
-				ProcXF86VidModeDispatch,
-				SProcXF86VidModeDispatch,
-				NULL,
-				StandardMinorOpcode))) {
-#if 0
-	XF86VidModeReqCode = (unsigned char)extEntry->base;
-#endif
-	VidModeErrorBase = extEntry->errorBase;
-#ifdef XF86VIDMODE_EVENTS
-	XF86VidModeEventBase = extEntry->eventBase;
-	EventSwapVector[XF86VidModeEventBase] = (EventSwapPtr)SXF86VidModeNotifyEvent;
-#endif
-    }
-}
-
 static int
 ClientMajorVersion(ClientPtr client)
 {
@@ -2166,3 +2072,55 @@ SProcXF86VidModeDispatch(ClientPtr client)
 	    return VidModeErrorBase + XF86VidModeClientNotLocal;
     }
 }
+
+void
+XFree86VidModeExtensionInit(void)
+{
+    ExtensionEntry* extEntry;
+    ScreenPtr pScreen;
+    int		    i;
+    Bool	    enabled = FALSE;
+
+    DEBUG_P("XFree86VidModeExtensionInit");
+
+    if (!dixRegisterPrivateKey(&VidModeClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+#ifdef XF86VIDMODE_EVENTS
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+#endif
+
+#ifdef XF86VIDMODE_EVENTS
+    EventType = CreateNewResourceType(XF86VidModeFreeEvents, "VidModeEvent");
+#endif
+
+    for(i = 0; i < screenInfo.numScreens; i++) {
+        pScreen = screenInfo.screens[i];
+	if (VidModeExtensionInit(pScreen))
+	    enabled = TRUE;
+    }
+    /* This means that the DDX doesn't want the vidmode extension enabled */
+    if (!enabled)
+	return;
+
+    if (
+#ifdef XF86VIDMODE_EVENTS
+        EventType &&
+#endif
+	(extEntry = AddExtension(XF86VIDMODENAME,
+				XF86VidModeNumberEvents,
+				XF86VidModeNumberErrors,
+				ProcXF86VidModeDispatch,
+				SProcXF86VidModeDispatch,
+				NULL,
+				StandardMinorOpcode))) {
+#if 0
+	XF86VidModeReqCode = (unsigned char)extEntry->base;
+#endif
+	VidModeErrorBase = extEntry->errorBase;
+#ifdef XF86VIDMODE_EVENTS
+	XF86VidModeEventBase = extEntry->eventBase;
+	EventSwapVector[XF86VidModeEventBase] = (EventSwapPtr)SXF86VidModeNotifyEvent;
+#endif
+    }
+}
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index f32565d..20baa24 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -64,23 +64,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static int DRIErrorBase;
 
-static DISPATCH_PROC(ProcXF86DRIQueryVersion);
-static DISPATCH_PROC(ProcXF86DRIQueryDirectRenderingCapable);
-static DISPATCH_PROC(ProcXF86DRIOpenConnection);
-static DISPATCH_PROC(ProcXF86DRICloseConnection);
-static DISPATCH_PROC(ProcXF86DRIGetClientDriverName);
-static DISPATCH_PROC(ProcXF86DRICreateContext);
-static DISPATCH_PROC(ProcXF86DRIDestroyContext);
-static DISPATCH_PROC(ProcXF86DRICreateDrawable);
-static DISPATCH_PROC(ProcXF86DRIDestroyDrawable);
-static DISPATCH_PROC(ProcXF86DRIGetDrawableInfo);
-static DISPATCH_PROC(ProcXF86DRIGetDeviceInfo);
-static DISPATCH_PROC(ProcXF86DRIDispatch);
-static DISPATCH_PROC(ProcXF86DRIAuthConnection);
-
-static DISPATCH_PROC(SProcXF86DRIQueryVersion);
-static DISPATCH_PROC(SProcXF86DRIQueryDirectRenderingCapable);
-static DISPATCH_PROC(SProcXF86DRIDispatch);
+
 
 static void XF86DRIResetProc(ExtensionEntry* extEntry);
 
@@ -88,32 +72,6 @@ static unsigned char DRIReqCode = 0;
 
 extern void XFree86DRIExtensionInit(void);
 
-void
-XFree86DRIExtensionInit(void)
-{
-    ExtensionEntry* extEntry;
-
-#ifdef XF86DRI_EVENTS
-    EventType = CreateNewResourceType(XF86DRIFreeEvents, "DRIEvent");
-#endif
-
-    if (
-	DRIExtensionInit() &&
-#ifdef XF86DRI_EVENTS
-        EventType && ScreenPrivateIndex != -1 &&
-#endif
-	(extEntry = AddExtension(XF86DRINAME,
-				 XF86DRINumberEvents,
-				 XF86DRINumberErrors,
-				 ProcXF86DRIDispatch,
-				 SProcXF86DRIDispatch,
-				 XF86DRIResetProc,
-				 StandardMinorOpcode))) {
-	DRIReqCode = (unsigned char)extEntry->base;
-	DRIErrorBase = extEntry->errorBase;
-    }
-}
-
 /*ARGSUSED*/
 static void
 XF86DRIResetProc (
@@ -677,3 +635,29 @@ SProcXF86DRIDispatch (
 	return DRIErrorBase + XF86DRIClientNotLocal;
     }
 }
+
+void
+XFree86DRIExtensionInit(void)
+{
+    ExtensionEntry* extEntry;
+
+#ifdef XF86DRI_EVENTS
+    EventType = CreateNewResourceType(XF86DRIFreeEvents, "DRIEvent");
+#endif
+
+    if (
+	DRIExtensionInit() &&
+#ifdef XF86DRI_EVENTS
+        EventType && ScreenPrivateIndex != -1 &&
+#endif
+	(extEntry = AddExtension(XF86DRINAME,
+				 XF86DRINumberEvents,
+				 XF86DRINumberErrors,
+				 ProcXF86DRIDispatch,
+				 SProcXF86DRIDispatch,
+				 XF86DRIResetProc,
+				 StandardMinorOpcode))) {
+	DRIReqCode = (unsigned char)extEntry->base;
+	DRIErrorBase = extEntry->errorBase;
+    }
+}
diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index 1c77ad9..cd2bdf0 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -70,8 +70,6 @@ static AppleWMProcsPtr appleWMProcs;
 
 static int WMErrorBase;
 
-static DISPATCH_PROC(ProcAppleWMDispatch);
-static DISPATCH_PROC(SProcAppleWMDispatch);
 
 static unsigned char WMReqCode = 0;
 static int WMEventBase = 0;
diff --git a/hw/xquartz/xpr/appledri.c b/hw/xquartz/xpr/appledri.c
index 3afe244..ebd4a43 100644
--- a/hw/xquartz/xpr/appledri.c
+++ b/hw/xquartz/xpr/appledri.c
@@ -59,8 +59,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static int DRIErrorBase = 0;
 
-static DISPATCH_PROC(ProcAppleDRIDispatch);
-static DISPATCH_PROC(SProcAppleDRIDispatch);
 
 static void AppleDRIResetProc(ExtensionEntry* extEntry);
 static int ProcAppleDRICreatePixmap(ClientPtr client);
diff --git a/hw/xwin/InitInput.c b/hw/xwin/InitInput.c
index 705e618..0ffa940 100644
--- a/hw/xwin/InitInput.c
+++ b/hw/xwin/InitInput.c
@@ -39,9 +39,9 @@
  */
 
 #ifdef XWIN_CLIPBOARD
-DISPATCH_PROC(winProcEstablishConnection);
-DISPATCH_PROC(winProcQueryTree);
-DISPATCH_PROC(winProcSetSelectionOwner);
+int winProcEstablishConnection(ClientPtr /* client */);
+int winProcQueryTree(ClientPtr /* client */);
+int winProcSetSelectionOwner(ClientPtr /* client */);
 #endif
 
 
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index bec63ac..d74cd03 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -41,7 +41,7 @@
 
 typedef int (*winDispatchProcPtr) (ClientPtr);
 
-DISPATCH_PROC(winProcSetSelectionOwner);
+int winProcSetSelectionOwner(ClientPtr /* client */);
 
 
 /*
diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index 658d050..bdacefb 100755
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -52,9 +52,9 @@
  * Local function prototypes
  */
 
-DISPATCH_PROC(winProcEstablishConnection);
-DISPATCH_PROC(winProcQueryTree);
-DISPATCH_PROC(winProcSetSelectionOwner);
+int winProcEstablishConnection(ClientPtr /* client */);
+int winProcQueryTree(ClientPtr /* client */);
+int winProcSetSelectionOwner(ClientPtr /* client */);
 
 
 /*
diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index 34d7f4b..ca3dbc3 100755
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -45,8 +45,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static int WMErrorBase;
 
-static DISPATCH_PROC(ProcWindowsWMDispatch);
-static DISPATCH_PROC(SProcWindowsWMDispatch);
 
 static unsigned char WMReqCode = 0;
 static int WMEventBase = 0;
commit 682a3ee60867da027fe1bcda0c8587dd3db9d58e
Author: Adam Jackson <ajax at redhat.com>
Date:   Sat Sep 18 07:27:13 2010 -0400

    xfree86: Remove useless module setup functions where appropriate
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index f50d562..a5b59e7 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -21,8 +21,6 @@
 
 #define PAGE_MASK               (~(getpagesize() - 1))
 
-static MODULESETUPPROTO(fbdevhwSetup);
-
 static XF86ModuleVersionInfo fbdevHWVersRec =
 {
 	"fbdevhw",
@@ -39,16 +37,10 @@ static XF86ModuleVersionInfo fbdevHWVersRec =
 
 _X_EXPORT XF86ModuleData fbdevhwModuleData = {
     &fbdevHWVersRec,
-    fbdevhwSetup,
+    NULL,
     NULL
 };
 
-static pointer
-fbdevhwSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    return (pointer)1;
-}
-
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/mman.h>
diff --git a/hw/xfree86/i2c/bt829_module.c b/hw/xfree86/i2c/bt829_module.c
index c885b8e..d87dfa7 100644
--- a/hw/xfree86/i2c/bt829_module.c
+++ b/hw/xfree86/i2c/bt829_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(bt829Setup);
-
 static XF86ModuleVersionInfo bt829VersRec =
 {
         "bt829",
@@ -20,9 +18,4 @@ static XF86ModuleVersionInfo bt829VersRec =
         {0,0,0,0}
 };
  
-_X_EXPORT XF86ModuleData bt829ModuleData = { &bt829VersRec, bt829Setup, NULL }; 
-
-static pointer
-bt829Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
+_X_EXPORT XF86ModuleData bt829ModuleData = { &bt829VersRec, NULL, NULL }; 
diff --git a/hw/xfree86/i2c/fi1236_module.c b/hw/xfree86/i2c/fi1236_module.c
index 4016ad0..a63f922 100644
--- a/hw/xfree86/i2c/fi1236_module.c
+++ b/hw/xfree86/i2c/fi1236_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(fi1236Setup);
-
 static XF86ModuleVersionInfo fi1236VersRec =
 {
         "fi1236",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo fi1236VersRec =
  
 _X_EXPORT XF86ModuleData fi1236ModuleData = {
         &fi1236VersRec,
-        fi1236Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-fi1236Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/i2c/msp3430_module.c b/hw/xfree86/i2c/msp3430_module.c
index 66b14a2..2ebf1f7 100644
--- a/hw/xfree86/i2c/msp3430_module.c
+++ b/hw/xfree86/i2c/msp3430_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(msp3430Setup);
-
 static XF86ModuleVersionInfo msp3430VersRec =
 {
         "msp3430",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo msp3430VersRec =
  
 _X_EXPORT XF86ModuleData msp3430ModuleData = {
         &msp3430VersRec,
-        msp3430Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-msp3430Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/i2c/tda8425_module.c b/hw/xfree86/i2c/tda8425_module.c
index 7906e5e..ef301b7 100644
--- a/hw/xfree86/i2c/tda8425_module.c
+++ b/hw/xfree86/i2c/tda8425_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(tda8425Setup);
-
 static XF86ModuleVersionInfo tda8425VersRec =
 {
         "tda8425",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo tda8425VersRec =
  
 _X_EXPORT XF86ModuleData tda8425ModuleData = {
         &tda8425VersRec,
-        tda8425Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-tda8425Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/i2c/tda9850_module.c b/hw/xfree86/i2c/tda9850_module.c
index 84f7e86..8256e78 100644
--- a/hw/xfree86/i2c/tda9850_module.c
+++ b/hw/xfree86/i2c/tda9850_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(tda9850Setup);
-
 static XF86ModuleVersionInfo tda9850VersRec =
 {
         "tda9850",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo tda9850VersRec =
  
 _X_EXPORT XF86ModuleData tda9850ModuleData = {
         &tda9850VersRec,
-        tda9850Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-tda9850Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/i2c/tda9885_module.c b/hw/xfree86/i2c/tda9885_module.c
index 0ce85bb..3394c18 100644
--- a/hw/xfree86/i2c/tda9885_module.c
+++ b/hw/xfree86/i2c/tda9885_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(tda9885Setup);
-
 static XF86ModuleVersionInfo tda9885VersRec =
 {
         "tda9885",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo tda9885VersRec =
  
 _X_EXPORT XF86ModuleData tda9885ModuleData = {
         &tda9885VersRec,
-        tda9885Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-tda9885Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/i2c/uda1380_module.c b/hw/xfree86/i2c/uda1380_module.c
index 895f8c6..67b623e 100644
--- a/hw/xfree86/i2c/uda1380_module.c
+++ b/hw/xfree86/i2c/uda1380_module.c
@@ -4,8 +4,6 @@
 
 #include "xf86Module.h"
 
-static MODULESETUPPROTO(uda1380Setup);
-
 static XF86ModuleVersionInfo uda1380VersRec =
 {
         "uda1380",
@@ -22,11 +20,6 @@ static XF86ModuleVersionInfo uda1380VersRec =
  
 _X_EXPORT XF86ModuleData uda1380ModuleData = {
         &uda1380VersRec,
-        uda1380Setup,
+        NULL,
         NULL
 }; 
-
-static pointer
-uda1380Setup(pointer module, pointer opts, int *errmaj, int *errmin) {
-   return (pointer)1;
-}
diff --git a/hw/xfree86/int10/xf86int10module.c b/hw/xfree86/int10/xf86int10module.c
index b4e5865..41e349e 100644
--- a/hw/xfree86/int10/xf86int10module.c
+++ b/hw/xfree86/int10/xf86int10module.c
@@ -22,8 +22,6 @@
 #define combine(a,b) concat(a,b)
 #define NAME(x) combine(MOD_NAME,x)
 
-static MODULESETUPPROTO(NAME(Setup));
-
 static XF86ModuleVersionInfo NAME(VersRec) =
 {
     STRING(NAME( )),
@@ -40,25 +38,6 @@ static XF86ModuleVersionInfo NAME(VersRec) =
 
 _X_EXPORT XF86ModuleData NAME(ModuleData) = {
     &NAME(VersRec),
-    NAME(Setup),
+    NULL,
     NULL
 };
-
-static pointer
-NAME(Setup)(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    static Bool setupDone = FALSE;
-    
-    if (!setupDone) {
-	setupDone = TRUE;
-	/*
-	 * Tell the loader about symbols from other modules that this module
-	 * might refer to.
-	 */
-    } 
-    /*
-     * The return value must be non-NULL on success even though there
-     * is no TearDownProc.
-     */
-    return (pointer)1;
-}
diff --git a/hw/xfree86/vbe/vbe_module.c b/hw/xfree86/vbe/vbe_module.c
index cf37ef9..e8f2e74 100644
--- a/hw/xfree86/vbe/vbe_module.c
+++ b/hw/xfree86/vbe/vbe_module.c
@@ -6,8 +6,6 @@
 #include "xf86str.h"
 #include "vbe.h"
 
-static MODULESETUPPROTO(vbeSetup);
-
 static XF86ModuleVersionInfo vbeVersRec =
 {
     "vbe",
@@ -22,10 +20,4 @@ static XF86ModuleVersionInfo vbeVersRec =
     {0,0,0,0}
 };
 
-_X_EXPORT XF86ModuleData vbeModuleData = { &vbeVersRec, vbeSetup, NULL };
-
-static pointer
-vbeSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    return (pointer)1;
-}
+_X_EXPORT XF86ModuleData vbeModuleData = { &vbeVersRec, NULL, NULL };
commit 6130170e7e9b64c611ee942ec3455dd1a185193d
Author: Adam Jackson <ajax at redhat.com>
Date:   Sat Sep 18 06:41:35 2010 -0400

    xfree86: Remove unused refcounting from input drivers
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 90e0c67..0172ace 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -125,7 +125,6 @@ xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags)
 				xnfalloc(sizeof(InputDriverRec));
     *xf86InputDriverList[xf86NumInputDrivers - 1] = *driver;
     xf86InputDriverList[xf86NumInputDrivers - 1]->module = module;
-    xf86InputDriverList[xf86NumInputDrivers - 1]->refCount = 0;
 }
 
 void
@@ -284,7 +283,6 @@ xf86AllocateInput(InputDriverPtr drv, int flags)
 	return NULL;
 
     new->drv = drv;
-    drv->refCount++;
     new->module = DuplicateModule(drv->module, NULL);
 
     for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next)
@@ -320,9 +318,6 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
     if (pInp->module)
 	UnloadModule(pInp->module);
 
-    if (pInp->drv)
-	pInp->drv->refCount--;
-
     /* This should *really* be handled in drv->UnInit(dev) call instead, but
      * if the driver forgets about it make sure we free it or at least crash
      * with flying colors */
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 20a3f1b..7b60cdf 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -103,7 +103,6 @@ typedef struct _InputDriverRec {
 				      struct _LocalDeviceRec *pInfo,
 				      int flags);
     pointer		    module;
-    int			    refCount;
 } InputDriverRec, *InputDriverPtr;
 
 /* This is to input devices what the ScrnInfoRec is to screens. */
commit ab7f057ce9df4e905b12cebc1e587b9a7f200418
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 11:19:17 2010 -0400

    loader: Remove a silly layer of reference counting
    
    libdl will refcount objects for us just fine, thanks.
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index 22d8273..8921831 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -96,41 +96,6 @@
 
 extern void *xorg_symbols[];
 
-#define MAX_HANDLE 256
-static int refCount[MAX_HANDLE];
-
-/* Prototypes for static functions. */
-static loaderPtr listHead = NULL;
-
-static loaderPtr
-_LoaderListPush(void)
-{
-    loaderPtr item = calloc(1, sizeof(struct _loader));
-
-    item->next = listHead;
-    listHead = item;
-
-    return item;
-}
-
-static loaderPtr
-_LoaderListPop(int handle)
-{
-    loaderPtr item = listHead;
-    loaderPtr *bptr = &listHead;	/* pointer to previous node */
-
-    while (item) {
-	if (item->handle == handle) {
-	    *bptr = item->next;	/* remove this from the list */
-	    return item;
-	}
-	bptr = &(item->next);
-	item = item->next;
-    }
-
-    return 0;
-}
-
 void
 LoaderInit(void)
 {
@@ -171,130 +136,41 @@ LoaderInit(void)
 #endif
 }
 
-static void *
-do_dlopen(loaderPtr modrec, int flags)
-{
-    void *dlfile;
-    int dlopen_flags;
-
-    if (flags & LD_FLAG_GLOBAL)
-	dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL;
-    else
-	dlopen_flags = DLOPEN_LAZY;
-
-    dlfile = dlopen(modrec->name, dlopen_flags);
-
-    if (dlfile == NULL) {
-	ErrorF("dlopen: %s\n", dlerror());
-	return NULL;
-    }
-
-    return dlfile;
-}
-
 /* Public Interface to the loader. */
 
-int
-LoaderOpen(const char *module, int *errmaj, int *errmin, int *wasLoaded,
-           int flags)
+void *
+LoaderOpen(const char *module, int *errmaj, int *errmin)
 {
-    loaderPtr tmp;
-    int new_handle;
+    void *ret;
 
 #if defined(DEBUG)
     ErrorF("LoaderOpen(%s)\n", module);
 #endif
 
-    /* Is the module already loaded? */
-    tmp = listHead;
-    while (tmp) {
-#ifdef DEBUGLIST
-        ErrorF("strcmp(%x(%s),{%x} %x(%s))\n", module, module,
-               &(tmp->name), tmp->name, tmp->name);
-#endif
-        if (!strcmp(module, tmp->name)) {
-            refCount[tmp->handle]++;
-            if (wasLoaded)
-                *wasLoaded = 1;
-            xf86MsgVerb(X_INFO, 2, "Reloading %s\n", module);
-            return tmp->handle;
-        }
-        tmp = tmp->next;
-    }
-
-    /*
-     * OK, it's a new one. Add it.
-     */
     xf86Msg(X_INFO, "Loading %s\n", module);
-    if (wasLoaded)
-	*wasLoaded = 0;
-
-    /*
-     * Find a free handle.
-     */
-    new_handle = 1;
-    while (new_handle < MAX_HANDLE && refCount[new_handle])
-	new_handle++;
-
-    if (new_handle == MAX_HANDLE) {
-	xf86Msg(X_ERROR, "Out of loader space\n");	/* XXX */
-	if (errmaj)
-	    *errmaj = LDR_NOSPACE;
-	if (errmin)
-	    *errmin = LDR_NOSPACE;
-	return -1;
-    }
 
-    refCount[new_handle] = 1;
-
-    tmp = _LoaderListPush();
-    tmp->name = strdup(module);
-    tmp->handle = new_handle;
-
-    if ((tmp->private = do_dlopen(tmp, flags)) == NULL) {
-	xf86Msg(X_ERROR, "Failed to load %s\n", module);
-	_LoaderListPop(new_handle);
-	refCount[new_handle] = 0;
+    if (!(ret = dlopen(module, DLOPEN_LAZY | DLOPEN_GLOBAL))) {
+	xf86Msg(X_ERROR, "Failed to load %s: %s\n", module, dlerror());
 	if (errmaj)
 	    *errmaj = LDR_NOLOAD;
 	if (errmin)
 	    *errmin = LDR_NOLOAD;
-	return -1;
+	return NULL;
     }
 
-    return new_handle;
-}
-
-int
-LoaderHandleOpen(int handle)
-{
-    if (handle < 0 || handle >= MAX_HANDLE)
-	return -1;
-
-    if (!refCount[handle])
-	return -1;
-
-    refCount[handle]++;
-    return handle;
+    return ret;
 }
 
 void *
 LoaderSymbol(const char *name)
 {
     static void *global_scope = NULL;
-    loaderPtr l;
     void *p;
 
     p = dlsym(RTLD_DEFAULT, name);
     if (p != NULL)
 	return p;
 
-    for (l = listHead; l != NULL; l = l->next) {
-        p = dlsym(l->private, name);
-	if (p)
-	    return p;
-    }
-
     if (!global_scope)
 	global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
 
@@ -304,32 +180,11 @@ LoaderSymbol(const char *name)
     return NULL;
 }
 
-int
-LoaderUnload(int handle)
+void
+LoaderUnload(const char *name, void *handle)
 {
-    loaderRec fakeHead;
-    loaderPtr tmp = &fakeHead;
-
-    if (handle < 0 || handle >= MAX_HANDLE)
-	return -1;
-
-    /*
-     * check the reference count, only free it if it goes to zero
-     */
-    if (--refCount[handle])
-	return 0;
-    /*
-     * find the loaderRecs associated with this handle.
-     */
-
-    while ((tmp = _LoaderListPop(handle)) != NULL) {
-	xf86Msg(X_INFO, "Unloading %s\n", tmp->name);
-	dlclose(tmp->private);
-	free(tmp->name);
-	free(tmp);
-    }
-
-    return 0;
+    xf86Msg(X_INFO, "Unloading %s\n", name);
+    dlclose(handle);
 }
 
 unsigned long LoaderOptions = 0;
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 4bb571e..edea911 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -57,21 +57,6 @@
 #include <X11/Xfuncproto.h>
 #include <X11/Xmd.h>
 
-/* LoadModule proc flags; LD_FLAG_GLOBAL adds symbols to global
- * namespace, default is to keep symbols local to module. */
-#define LD_FLAG_GLOBAL 1
-
-typedef struct _loader *loaderPtr;
-
-/* Each module loaded has a loaderRec */
-typedef struct _loader {
-    int handle;			/* Unique id used to remove symbols from
-				 * this module when it is unloaded */
-    char *name;
-    void *private;		/* format specific data */
-    loaderPtr next;
-} loaderRec;
-
 /* Compiled-in version information */
 typedef struct {
     int xf86Version;
@@ -86,7 +71,6 @@ extern const ModuleVersions LoaderVersionInfo;
 extern unsigned long LoaderOptions;
 
 /* Internal Functions */
-int LoaderOpen(const char *, int *, int *, int *, int);
-int LoaderHandleOpen(int);
+void * LoaderOpen(const char *, int *, int *);
 
 #endif /* _LOADER_H */
diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index a7925ec..0b67c5f 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -60,7 +60,8 @@ typedef struct module_desc {
     struct module_desc *sib;
     struct module_desc *parent;
     char *name;
-    int handle;
+    char *path;
+    void *handle;
     ModuleSetupProc SetupProc;
     ModuleTearDownProc TearDownProc;
     void *TearDownData;		/* returned from SetupProc */
@@ -81,7 +82,7 @@ void UnloadDriver(ModuleDescPtr);
 void LoaderSetPath(const char *path);
 void LoaderSortExtensions(void);
 
-int LoaderUnload(int);
+void LoaderUnload(const char *, void *);
 unsigned long LoaderGetModuleVersion(ModuleDescPtr mod);
 
 void LoaderResetOptions(void);
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index e41e0c8..6e65227 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -83,8 +83,7 @@ static char *LoaderGetCanonicalName(const char *, PatternPtr);
 static void RemoveChild(ModuleDescPtr);
 static ModuleDescPtr doLoadModule(const char *, const char *, const char **,
 				  const char **, pointer,
-				  const XF86ModReqInfo *, int *, int *,
-				  int flags);
+				  const XF86ModReqInfo *, int *, int *);
 
 const ModuleVersions LoaderVersionInfo = {
     XORG_VERSION_CURRENT,
@@ -765,7 +764,7 @@ LoadSubModule(pointer _parent, const char *module,
     }
 
     submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
-			  modreq, errmaj, errmin, LD_FLAG_GLOBAL);
+			  modreq, errmaj, errmin);
     if (submod && submod != (ModuleDescPtr) 1) {
 	parent->child = AddSibling(parent->child, submod);
 	submod->parent = parent;
@@ -776,18 +775,10 @@ LoadSubModule(pointer _parent, const char *module,
 static ModuleDescPtr
 NewModuleDesc(const char *name)
 {
-    ModuleDescPtr mdp = malloc(sizeof(ModuleDesc));
+    ModuleDescPtr mdp = calloc(1, sizeof(ModuleDesc));
 
-    if (mdp) {
-	mdp->child = NULL;
-	mdp->sib = NULL;
-	mdp->parent = NULL;
+    if (mdp)
 	mdp->name = xstrdup(name);
-	mdp->handle = -1;
-	mdp->SetupProc = NULL;
-	mdp->TearDownProc = NULL;
-	mdp->TearDownData = NULL;
-    }
 
     return mdp;
 }
@@ -796,6 +787,7 @@ ModuleDescPtr
 DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
 {
     ModuleDescPtr ret;
+    int errmaj, errmin;
 
     if (!mod)
 	return NULL;
@@ -804,10 +796,11 @@ DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
     if (ret == NULL)
 	return NULL;
 
-    if (LoaderHandleOpen(mod->handle) == -1)
-	return NULL;
+    if (!(ret->handle = LoaderOpen(mod->path, &errmaj, &errmin))) {
+        free(ret);
+        return NULL;
+    }
 
-    ret->handle = mod->handle;
     ret->SetupProc = mod->SetupProc;
     ret->TearDownProc = mod->TearDownProc;
     ret->TearDownData = NULL;
@@ -815,6 +808,7 @@ DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
     ret->sib = DuplicateModule(mod->sib, parent);
     ret->parent = parent;
     ret->VersionInfo = mod->VersionInfo;
+    ret->path = strdup(mod->path);
 
     return ret;
 }
@@ -830,7 +824,7 @@ static ModuleDescPtr
 doLoadModule(const char *module, const char *path, const char **subdirlist,
 	     const char **patternlist, pointer options,
 	     const XF86ModReqInfo * modreq,
-	     int *errmaj, int *errmin, int flags)
+	     int *errmaj, int *errmin)
 {
     XF86ModuleData *initdata = NULL;
     char **pathlist = NULL;
@@ -839,7 +833,6 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
     char **path_elem = NULL;
     char *p = NULL;
     ModuleDescPtr ret = NULL;
-    int wasLoaded = 0;
     PatternPtr patterns = NULL;
     int noncanonical = 0;
     char *m = NULL;
@@ -926,9 +919,10 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
 	    *errmin = 0;
 	goto LoadModule_fail;
     }
-    ret->handle = LoaderOpen(found, errmaj, errmin, &wasLoaded, flags);
+    ret->handle = LoaderOpen(found, errmaj, errmin);
     if (ret->handle < 0)
 	goto LoadModule_fail;
+    ret->path = strdup(found);
 
     /* drop any explicit suffix from the module name */
     p = strchr(name, '.');
@@ -959,26 +953,24 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
 	setup = initdata->setup;
 	teardown = initdata->teardown;
 
-	if (!wasLoaded) {
-	    if (vers) {
-		if (!CheckVersion(module, vers, modreq)) {
-		    if (errmaj)
-			*errmaj = LDR_MISMATCH;
-		    if (errmin)
-			*errmin = 0;
-		    goto LoadModule_fail;
-		}
-	    } else {
-		xf86Msg(X_ERROR,
-			"LoadModule: Module %s does not supply"
-			" version information\n", module);
-		if (errmaj)
-		    *errmaj = LDR_INVALID;
-		if (errmin)
-		    *errmin = 0;
-		goto LoadModule_fail;
-	    }
-	}
+        if (vers) {
+            if (!CheckVersion(module, vers, modreq)) {
+                if (errmaj)
+                    *errmaj = LDR_MISMATCH;
+                if (errmin)
+                    *errmin = 0;
+                goto LoadModule_fail;
+            }
+        } else {
+            xf86Msg(X_ERROR,
+                    "LoadModule: Module %s does not supply"
+                    " version information\n", module);
+            if (errmaj)
+                *errmaj = LDR_INVALID;
+            if (errmin)
+                *errmin = 0;
+            goto LoadModule_fail;
+        }
 	if (setup)
 	    ret->SetupProc = setup;
 	if (teardown)
@@ -1066,7 +1058,7 @@ LoadModule(const char *module, const char *path, const char **subdirlist,
 	   const XF86ModReqInfo * modreq, int *errmaj, int *errmin)
 {
   return doLoadModule(module, path, subdirlist, patternlist, options,
-		      modreq, errmaj, errmin, LD_FLAG_GLOBAL);
+		      modreq, errmaj, errmin);
 }
 
 void
@@ -1088,12 +1080,13 @@ UnloadModuleOrDriver(ModuleDescPtr mod)
 
     if ((mod->TearDownProc) && (mod->TearDownData))
 	mod->TearDownProc(mod->TearDownData);
-    LoaderUnload(mod->handle);
+    LoaderUnload(mod->name, mod->handle);
 
     if (mod->child)
 	UnloadModuleOrDriver(mod->child);
     if (mod->sib)
 	UnloadModuleOrDriver(mod->sib);
+    free(mod->path);
     free(mod->name);
     free(mod);
 }
@@ -1110,13 +1103,14 @@ UnloadSubModule(pointer _mod)
 
     if ((mod->TearDownProc) && (mod->TearDownData))
 	mod->TearDownProc(mod->TearDownData);
-    LoaderUnload(mod->handle);
+    LoaderUnload(mod->name, mod->handle);
 
     RemoveChild(mod);
 
     if (mod->child)
 	UnloadModuleOrDriver(mod->child);
 
+    free(mod->path);
     free(mod->name);
     free(mod);
 }
commit 0438002cd238011f33dbf176c555de5e380ba77e
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 09:13:04 2010 -0400

    loader: include cleanup
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index baadbc4..22d8273 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -54,18 +54,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#if defined(UseMMAP) || (defined(linux) && defined(__ia64__))
-#include <sys/mman.h>
-#endif
 #include <unistd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
-#if defined(linux) && \
-    (defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \
-    || defined(__amd64__))
-#include <malloc.h>
-#endif
 #include <stdarg.h>
 
 #include "os.h"
commit 2f003fe49697f8343c052dff2b3752eace814ea7
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 09:02:13 2010 -0400

    loader: Remove the handle field from LoaderOpen
    
    This was always 0 from all the callers.
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index 878cb39..baadbc4 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -174,7 +174,7 @@ LoaderInit(void)
 	    path = uwcrtpath; /* fallback: try to get libcrt.a from the uccs */
 	else
 	    path = xcrtpath; /* get the libcrt.a we compiled with */
-	LoaderOpen (path, 0, &errmaj, &errmin, &wasLoaded);
+	LoaderOpen (path, &errmaj, &errmin, &wasLoaded, 0);
     }
 #endif
 }
@@ -203,8 +203,8 @@ do_dlopen(loaderPtr modrec, int flags)
 /* Public Interface to the loader. */
 
 int
-LoaderOpen(const char *module, int handle,
-	   int *errmaj, int *errmin, int *wasLoaded, int flags)
+LoaderOpen(const char *module, int *errmaj, int *errmin, int *wasLoaded,
+           int flags)
 {
     loaderPtr tmp;
     int new_handle;
@@ -214,22 +214,20 @@ LoaderOpen(const char *module, int handle,
 #endif
 
     /* Is the module already loaded? */
-    if (handle >= 0) {
-	tmp = listHead;
-	while (tmp) {
+    tmp = listHead;
+    while (tmp) {
 #ifdef DEBUGLIST
-	    ErrorF("strcmp(%x(%s),{%x} %x(%s))\n", module, module,
-		   &(tmp->name), tmp->name, tmp->name);
+        ErrorF("strcmp(%x(%s),{%x} %x(%s))\n", module, module,
+               &(tmp->name), tmp->name, tmp->name);
 #endif
-	    if (!strcmp(module, tmp->name)) {
-		refCount[tmp->handle]++;
-		if (wasLoaded)
-		    *wasLoaded = 1;
-		xf86MsgVerb(X_INFO, 2, "Reloading %s\n", module);
-		return tmp->handle;
-	    }
-	    tmp = tmp->next;
-	}
+        if (!strcmp(module, tmp->name)) {
+            refCount[tmp->handle]++;
+            if (wasLoaded)
+                *wasLoaded = 1;
+            xf86MsgVerb(X_INFO, 2, "Reloading %s\n", module);
+            return tmp->handle;
+        }
+        tmp = tmp->next;
     }
 
     /*
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 9dfc307..4bb571e 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -86,7 +86,7 @@ extern const ModuleVersions LoaderVersionInfo;
 extern unsigned long LoaderOptions;
 
 /* Internal Functions */
-int LoaderOpen(const char *, int, int *, int *, int *, int);
+int LoaderOpen(const char *, int *, int *, int *, int);
 int LoaderHandleOpen(int);
 
 #endif /* _LOADER_H */
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index a9d04b8..e41e0c8 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -926,7 +926,7 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
 	    *errmin = 0;
 	goto LoadModule_fail;
     }
-    ret->handle = LoaderOpen(found, 0, errmaj, errmin, &wasLoaded, flags);
+    ret->handle = LoaderOpen(found, errmaj, errmin, &wasLoaded, flags);
     if (ret->handle < 0)
 	goto LoadModule_fail;
 
commit 09929da50503b559459f5b722c11647c47857fdb
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 08:16:51 2010 -0400

    loader: Remove unused canonical name field
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index 580d059..878cb39 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -174,7 +174,7 @@ LoaderInit(void)
 	    path = uwcrtpath; /* fallback: try to get libcrt.a from the uccs */
 	else
 	    path = xcrtpath; /* get the libcrt.a we compiled with */
-	LoaderOpen (path, "libcrt", 0, &errmaj, &errmin, &wasLoaded);
+	LoaderOpen (path, 0, &errmaj, &errmin, &wasLoaded);
     }
 #endif
 }
@@ -203,7 +203,7 @@ do_dlopen(loaderPtr modrec, int flags)
 /* Public Interface to the loader. */
 
 int
-LoaderOpen(const char *module, const char *cname, int handle,
+LoaderOpen(const char *module, int handle,
 	   int *errmaj, int *errmin, int *wasLoaded, int flags)
 {
     loaderPtr tmp;
@@ -259,7 +259,6 @@ LoaderOpen(const char *module, const char *cname, int handle,
 
     tmp = _LoaderListPush();
     tmp->name = strdup(module);
-    tmp->cname = strdup(cname);
     tmp->handle = new_handle;
 
     if ((tmp->private = do_dlopen(tmp, flags)) == NULL) {
@@ -337,7 +336,6 @@ LoaderUnload(int handle)
 	xf86Msg(X_INFO, "Unloading %s\n", tmp->name);
 	dlclose(tmp->private);
 	free(tmp->name);
-	free(tmp->cname);
 	free(tmp);
     }
 
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 42e1518..9dfc307 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -68,7 +68,6 @@ typedef struct _loader {
     int handle;			/* Unique id used to remove symbols from
 				 * this module when it is unloaded */
     char *name;
-    char *cname;
     void *private;		/* format specific data */
     loaderPtr next;
 } loaderRec;
@@ -87,7 +86,7 @@ extern const ModuleVersions LoaderVersionInfo;
 extern unsigned long LoaderOptions;
 
 /* Internal Functions */
-int LoaderOpen(const char *, const char *, int, int *, int *, int *, int);
+int LoaderOpen(const char *, int, int *, int *, int *, int);
 int LoaderHandleOpen(int);
 
 #endif /* _LOADER_H */
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 615e8c6..a9d04b8 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -926,8 +926,7 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
 	    *errmin = 0;
 	goto LoadModule_fail;
     }
-    ret->handle = LoaderOpen(found, name, 0,
-			     errmaj, errmin, &wasLoaded, flags);
+    ret->handle = LoaderOpen(found, 0, errmaj, errmin, &wasLoaded, flags);
     if (ret->handle < 0)
 	goto LoadModule_fail;
 
commit 3a26e7f459764d4aee71b2d7e25b113b729b94ac
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 07:55:48 2010 -0400

    loader: Remove unused module serial number
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index d51ea92..580d059 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -107,8 +107,6 @@ extern void *xorg_symbols[];
 #define MAX_HANDLE 256
 static int refCount[MAX_HANDLE];
 
-static int moduleseq = 0;
-
 /* Prototypes for static functions. */
 static loaderPtr listHead = NULL;
 
@@ -263,7 +261,6 @@ LoaderOpen(const char *module, const char *cname, int handle,
     tmp->name = strdup(module);
     tmp->cname = strdup(cname);
     tmp->handle = new_handle;
-    tmp->module = moduleseq++;
 
     if ((tmp->private = do_dlopen(tmp, flags)) == NULL) {
 	xf86Msg(X_ERROR, "Failed to load %s\n", module);
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 9695c6c..42e1518 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -67,7 +67,6 @@ typedef struct _loader *loaderPtr;
 typedef struct _loader {
     int handle;			/* Unique id used to remove symbols from
 				 * this module when it is unloaded */
-    int module;			/* Unique id to identify compilation units */
     char *name;
     char *cname;
     void *private;		/* format specific data */
commit 2a24a013bf3f554bb03c0f5af155d23dbb27b599
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 17 07:32:17 2010 -0400

    loader: Merge dlloader directly into the loader
    
    This lets us drop some double-tracking of loaded modules too.  If your
    OS is too lame to have libdl, fix that first.
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index d3c17d1..2bac89a 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -8,7 +8,6 @@ INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(top_srcdir)/miext/cw \
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
 EXTRA_DIST = \
-	dlloader.h \
 	loader.h \
 	loaderProcs.h \
 	sdksyms.sh
@@ -18,7 +17,6 @@ libloader_la_SOURCES = \
 	loaderProcs.h \
 	loadext.c \
         loadmod.c \
-        dlloader.c \
 	os.c \
 	sdksyms.c
 libloader_la_LIBADD = $(DLOPEN_LIBS)
diff --git a/hw/xfree86/loader/dlloader.c b/hw/xfree86/loader/dlloader.c
deleted file mode 100644
index 18dcb76..0000000
--- a/hw/xfree86/loader/dlloader.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 1997 The XFree86 Project, Inc.
- *
- * 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, and that the name of the
- * XFree86 Project, Inc. not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission.  The Xfree86 Project, Inc. makes no
- * representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied
- * warranty.
- *
- * THE XFREE86 PROJECT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE XFREE86 PROJECT, INC. BE LIABLE
- * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Once upon a time, X had multiple loader backends, three of which were
- * essentially libdl reimplementations.  This was nonsense so we chucked
- * it, but we still retain the factorization between loader API and
- * platform implementation.  This file is the libdl implementation, and
- * currently the only backend.  If you find yourself porting to a platform
- * without working libdl - hpux, win32, some forsaken a.out host, etc. -
- * make a new backend rather than hacking up this file.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <dlfcn.h>
-
-#include <X11/Xos.h>
-#include "os.h"
-
-#include "loader.h"
-#include "dlloader.h"
-
-#if defined(DL_LAZY)
-#define DLOPEN_LAZY DL_LAZY
-#elif defined(RTLD_LAZY)
-#define DLOPEN_LAZY RTLD_LAZY
-#elif defined(__FreeBSD__)
-#define DLOPEN_LAZY 1
-#else
-#define DLOPEN_LAZY 0
-#endif
-
-#if defined(LD_GLOBAL)
-#define DLOPEN_GLOBAL LD_GLOBAL
-#elif defined(RTLD_GLOBAL)
-#define DLOPEN_GLOBAL RTLD_GLOBAL
-#else
-#define DLOPEN_GLOBAL 0
-#endif
-
-#if defined(CSRG_BASED) && !defined(__ELF__)
-#define DLSYM_PREFIX "_"
-#else
-#define DLSYM_PREFIX ""
-#endif
-
-/* Hooray, yet another open coded linked list! FIXME */
-typedef struct DLModuleList {
-    void *module;
-    struct DLModuleList *next;
-} DLModuleList;
-
-static DLModuleList *dlModuleList = NULL;
-
-static void *
-DLFindSymbolLocal(pointer module, const char *name)
-{
-    void *p;
-    char *n;
-
-    static const char symPrefix[] = DLSYM_PREFIX;
-
-    if (sizeof(symPrefix) > 1) {
-	n = malloc(strlen(symPrefix) + strlen(name) + 1);
-	sprintf(n, "%s%s", symPrefix, name);
-	name = n;
-    }
-
-    p = dlsym(module, name);
-
-    if (sizeof(symPrefix) > 1)
-	free(n);
-
-    return p;
-}
-
-static void *global_scope = NULL;
-
-void *
-DLFindSymbol(const char *name)
-{
-    DLModuleList *l;
-    void *p;
-
-    p = dlsym(RTLD_DEFAULT, name);
-    if (p != NULL)
-	return p;
-
-    for (l = dlModuleList; l != NULL; l = l->next) {
-        p = DLFindSymbolLocal(l->module, name);
-	if (p)
-	    return p;
-    }
-
-    if (!global_scope)
-	global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
-
-    if (global_scope)
-	return DLFindSymbolLocal(global_scope, name);
-
-    return NULL;
-}
-
-void *
-DLLoadModule(loaderPtr modrec, int flags)
-{
-    void * dlfile;
-    DLModuleList *l;
-    int dlopen_flags;
-
-    if (flags & LD_FLAG_GLOBAL)
-	dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL;
-    else
-	dlopen_flags = DLOPEN_LAZY;
-    dlfile = dlopen(modrec->name, dlopen_flags);
-    if (dlfile == NULL) {
-	ErrorF("dlopen: %s\n", dlerror());
-	return NULL;
-    }
-
-    l = malloc(sizeof(DLModuleList));
-    l->module = dlfile;
-    l->next = dlModuleList;
-    dlModuleList = l;
-
-    return (void *)dlfile;
-}
-
-void
-DLUnloadModule(void *modptr)
-{
-    DLModuleList *l, *p;
-
-    /* remove it from dlModuleList. */
-    if (dlModuleList->module == modptr) {
-	l = dlModuleList;
-	dlModuleList = l->next;
-	free(l);
-    } else {
-	p = dlModuleList;
-	for (l = dlModuleList->next; l != NULL; l = l->next) {
-	    if (l->module == modptr) {
-		p->next = l->next;
-		free(l);
-		break;
-	    }
-	    p = l;
-	}
-    }
-    dlclose(modptr);
-}
diff --git a/hw/xfree86/loader/dlloader.h b/hw/xfree86/loader/dlloader.h
deleted file mode 100644
index 8ae610f..0000000
--- a/hw/xfree86/loader/dlloader.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 1997 Metro Link, Inc.
- * 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, and that the name of Metro Link, Inc. not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Metro Link, Inc. makes no
- * representations about the suitability of this software for any purpose.
- *  It is provided "as is" without express or implied warranty.
- *
- * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#ifndef _DLLOADER_H
-#define _DLLOADER_H
-
-extern void *DLLoadModule(loaderPtr, int flags);
-extern void DLUnloadModule(void *);
-extern void *DLFindSymbol(const char *name);
-
-#endif
diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index e043bb2..d51ea92 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -75,6 +75,33 @@
 #include "xf86Priv.h"
 #include "compiler.h"
 
+#ifdef HAVE_DLFCN_H
+
+#include <dlfcn.h>
+#include <X11/Xos.h>
+
+#if defined(DL_LAZY)
+#define DLOPEN_LAZY DL_LAZY
+#elif defined(RTLD_LAZY)
+#define DLOPEN_LAZY RTLD_LAZY
+#elif defined(__FreeBSD__)
+#define DLOPEN_LAZY 1
+#else
+#define DLOPEN_LAZY 0
+#endif
+
+#if defined(LD_GLOBAL)
+#define DLOPEN_GLOBAL LD_GLOBAL
+#elif defined(RTLD_GLOBAL)
+#define DLOPEN_GLOBAL RTLD_GLOBAL
+#else
+#define DLOPEN_GLOBAL 0
+#endif
+
+#else
+#error i have no dynamic linker and i must scream
+#endif
+
 extern void *xorg_symbols[];
 
 #define MAX_HANDLE 256
@@ -154,6 +181,27 @@ LoaderInit(void)
 #endif
 }
 
+static void *
+do_dlopen(loaderPtr modrec, int flags)
+{
+    void *dlfile;
+    int dlopen_flags;
+
+    if (flags & LD_FLAG_GLOBAL)
+	dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL;
+    else
+	dlopen_flags = DLOPEN_LAZY;
+
+    dlfile = dlopen(modrec->name, dlopen_flags);
+
+    if (dlfile == NULL) {
+	ErrorF("dlopen: %s\n", dlerror());
+	return NULL;
+    }
+
+    return dlfile;
+}
+
 /* Public Interface to the loader. */
 
 int
@@ -217,7 +265,7 @@ LoaderOpen(const char *module, const char *cname, int handle,
     tmp->handle = new_handle;
     tmp->module = moduleseq++;
 
-    if ((tmp->private = DLLoadModule(tmp, flags)) == NULL) {
+    if ((tmp->private = do_dlopen(tmp, flags)) == NULL) {
 	xf86Msg(X_ERROR, "Failed to load %s\n", module);
 	_LoaderListPop(new_handle);
 	refCount[new_handle] = 0;
@@ -245,9 +293,29 @@ LoaderHandleOpen(int handle)
 }
 
 void *
-LoaderSymbol(const char *sym)
+LoaderSymbol(const char *name)
 {
-    return (DLFindSymbol(sym));
+    static void *global_scope = NULL;
+    loaderPtr l;
+    void *p;
+
+    p = dlsym(RTLD_DEFAULT, name);
+    if (p != NULL)
+	return p;
+
+    for (l = listHead; l != NULL; l = l->next) {
+        p = dlsym(l->private, name);
+	if (p)
+	    return p;
+    }
+
+    if (!global_scope)
+	global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
+
+    if (global_scope)
+	return dlsym(global_scope, name);
+
+    return NULL;
 }
 
 int
@@ -270,7 +338,7 @@ LoaderUnload(int handle)
 
     while ((tmp = _LoaderListPop(handle)) != NULL) {
 	xf86Msg(X_INFO, "Unloading %s\n", tmp->name);
-	DLUnloadModule(tmp->private);
+	dlclose(tmp->private);
 	free(tmp->name);
 	free(tmp->cname);
 	free(tmp);
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 6121e02..9695c6c 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -91,7 +91,4 @@ extern unsigned long LoaderOptions;
 int LoaderOpen(const char *, const char *, int, int *, int *, int *, int);
 int LoaderHandleOpen(int);
 
-/* Loader backends. */
-#include "dlloader.h"
-
 #endif /* _LOADER_H */


More information about the Xquartz-changes mailing list