xserver: Branch 'xorg-server-1.5-apple' - 16 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Sat May 17 14:57:03 PDT 2008


 GL/glx/glxscreens.c                   |   13 +
 composite/compwindow.c                |    4 
 config/hal.c                          |    8 -
 hw/xfree86/fbdevhw/fbdevhw.c          |    4 
 hw/xfree86/modes/xf86Crtc.c           |  267 +++++++++++++++++++++++++---------
 hw/xfree86/modes/xf86RandR12.c        |    4 
 hw/xquartz/X11Application.m           |   29 ++-
 hw/xquartz/darwinEvents.c             |   40 +++--
 hw/xquartz/darwinEvents.h             |    1 
 hw/xquartz/mach-startup/Makefile.am   |    8 -
 hw/xquartz/mach-startup/bundle-main.c |    5 
 hw/xquartz/mach-startup/launchd_fd.c  |   82 ++++++++++
 hw/xquartz/mach-startup/launchd_fd.h  |   36 ++++
 hw/xquartz/mach-startup/stub.c        |    9 -
 hw/xquartz/quartzKeyboard.c           |    4 
 include/os.h                          |    4 
 os/connection.c                       |   64 ++++++++
 os/utils.c                            |    2 
 18 files changed, 470 insertions(+), 114 deletions(-)

New commits:
commit b54b2529add81801764d3b7c118a439c02a5a7ab
Merge: 85a6286... e644d2e...
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat May 17 14:55:45 2008 -0700

    Merge branch 'server-1.5-branch' into xorg-server-1.5-apple

commit 85a6286dcd306fcce73768fc7eb6ab1cd0c6d71d
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat May 17 14:51:09 2008 -0700

    XQuartz: Ok, pass XQUARTZ_USE_XKB since it breaks worse without it... but we have issues when we have the keyboard configs installed... need to figure out what to do there...
    (cherry picked from commit 301262b07024ad960f22d99a1267fe137f5c3fce)

diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index b9d45cb..c75cd1d 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -43,10 +43,7 @@
 // Define this to get a diagnostic output to stderr which is helpful
 // in determining how the X server is interpreting the Darwin keymap.
 #define DUMP_DARWIN_KEYMAP
-
-// This breaks when we actually install xkeyboard-config files to start using it
-// We need to serup keymaps in the configs or something...
-// #define XQUARTZ_USE_XKB 
+#define XQUARTZ_USE_XKB 
 #define HACK_MISSING 1
 #define HACK_KEYPAD 1
 
commit 1f4d224f824782a4941acc82244287bf70f7a6ec
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat May 17 14:55:31 2008 -0700

    XQuartz: Added functionality to add a file descriptor to the connection list after the server is already running.
    (cherry picked from commit 543c2cd68d1ffef65d4644b860faad7191c6b9da)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 50a30fb..1a7d55a 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -38,12 +38,16 @@
 
 #import "X11Application.h"
 
-# include "darwin.h"
-# include "darwinEvents.h"
-# include "quartz.h"
-# define _APPLEWM_SERVER_
-# include "X11/extensions/applewm.h"
-# include "micmap.h"
+#include "darwin.h"
+#include "darwinEvents.h"
+#include "quartz.h"
+#define _APPLEWM_SERVER_
+#include "X11/extensions/applewm.h"
+#include "micmap.h"
+
+#include "os.h"
+#include "mach-startup/launchd_fd.h"
+
 #include <mach/mach.h>
 #include <unistd.h>
 
@@ -783,6 +787,7 @@ environment?", @"Startup xinitrc dialog");
 
 void X11ApplicationMain (int argc, char **argv, char **envp) {
     NSAutoreleasePool *pool;
+    int launchd_fd;
 
 #ifdef DEBUG
     while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
@@ -810,6 +815,14 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
 
     /* Tell the server thread that it can proceed */
     QuartzInitServer(argc, argv, envp);
+    
+#ifndef NEW_LAUNCH_METHOD
+    /* Start listening on the launchd fd */
+    launchd_fd = launchd_display_fd();
+    if(launchd_fd != -1) {
+        DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, launchd_fd);
+    }
+#endif
 
     [NSApp run];
     /* not reached */
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 7376c57..06c5df0 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
 #include   "mi.h"
 #include   "scrnintstr.h"
 #include   "mipointer.h"
+#include   "os.h"
 
 #include "darwin.h"
 #include "quartz.h"
@@ -214,6 +215,16 @@ static void DarwinSimulateMouseClick(
     DarwinUpdateModifiers(KeyPress, modifierMask);
 }
 
+static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
+    size_t i;
+    TA_SERVER();
+
+    for (i=0; i<nevents; i++) {
+        //sleep(20);
+        ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
+    }
+}
+
 /* Generic handler for Xquartz-specifc events.  When possible, these should
    be moved into their own individual functions and set as handlers using
    mieqSetHandler. */
@@ -319,7 +330,8 @@ Bool DarwinEQInit(void) {
     mieqSetHandler(kXquartzControllerNotify, DarwinEventHandler);
     mieqSetHandler(kXquartzPasteboardNotify, DarwinEventHandler);
     mieqSetHandler(kXquartzDisplayChanged, QuartzDisplayChangedHandler);
-
+    mieqSetHandler(kXquartzListenOnOpenFD, kXquartzListenOnOpenFDHandler);
+    
     QuartzModeEQInit();
 
     if (!darwinEvents)
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index a676aeb..58817fb 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -56,6 +56,7 @@ enum {
     kXquartzToggleFullscreen, // Enable/Disable fullscreen mode
     kXquartzSetRootless,      // Set rootless mode
     kXquartzSpaceChanged,     // Spaces changed
+    kXquartzListenOnOpenFD,   // Listen to the launchd fd (passed as arg)
     /*
      * AppleWM events
      */
diff --git a/hw/xquartz/mach-startup/Makefile.am b/hw/xquartz/mach-startup/Makefile.am
index d81caa9..3ed1c1a 100644
--- a/hw/xquartz/mach-startup/Makefile.am
+++ b/hw/xquartz/mach-startup/Makefile.am
@@ -7,7 +7,8 @@ x11appdir = $(APPLE_APPLICATIONS_DIR)/X11.app/Contents/MacOS
 x11app_PROGRAMS = X11
 
 dist_X11_SOURCES = \
-	bundle-main.c
+	bundle-main.c \
+	launchd_fd.c
 
 nodist_X11_SOURCES = \
 	mach_startupServer.c \
@@ -33,7 +34,8 @@ X11_LDFLAGS =  \
 bin_PROGRAMS = Xquartz
 
 dist_Xquartz_SOURCES = \
-	stub.c
+	stub.c \
+	launchd_fd.c
 
 nodist_Xquartz_SOURCES = \
 	mach_startupUser.c
@@ -54,6 +56,7 @@ $(BUILT_SOURCES): mach_startup.defs
 	mig -sheader mach_startupServer.h mach_startup.defs
 
 EXTRA_DIST = \
+	launchd_fd.h \
 	mach_startup.defs \
 	mach_startup_types.h
 
diff --git a/hw/xquartz/mach-startup/launchd_fd.c b/hw/xquartz/mach-startup/launchd_fd.c
new file mode 100644
index 0000000..44a243a
--- /dev/null
+++ b/hw/xquartz/mach-startup/launchd_fd.c
@@ -0,0 +1,82 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <launch.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "launchd_fd.h"
+
+int launchd_display_fd() {
+    launch_data_t sockets_dict, checkin_request, checkin_response;
+    launch_data_t listening_fd_array, listening_fd;
+
+    /* Get launchd fd */
+    if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
+        fprintf(stderr,"launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.\n");
+        return ERROR_FD;
+    }
+    
+    if ((checkin_response = launch_msg(checkin_request)) == NULL) {
+        fprintf(stderr,"launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",strerror(errno));
+        return ERROR_FD;
+    }
+    
+    if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
+        // ignore EACCES, which is common if we weren't started by launchd
+        if (launch_data_get_errno(checkin_response) != EACCES)
+            fprintf(stderr,"launchd check-in failed: %s\n", strerror(launch_data_get_errno(checkin_response)));
+        return ERROR_FD;
+    } 
+    
+    sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS);
+    if (NULL == sockets_dict) {
+        fprintf(stderr,"launchd check-in: no sockets found to answer requests on!\n");
+        return ERROR_FD;
+    }
+    
+    if (launch_data_dict_get_count(sockets_dict) > 1) {
+        fprintf(stderr,"launchd check-in: some sockets will be ignored!\n");
+        return ERROR_FD;
+    }
+    
+    listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
+    if (NULL == listening_fd_array) {
+        fprintf(stderr,"launchd check-in: No known sockets found to answer requests on!\n");
+        return ERROR_FD;
+    }
+    
+    if (launch_data_array_get_count(listening_fd_array)!=1) {
+        fprintf(stderr,"launchd check-in: Expected 1 socket from launchd, got %u)\n",
+                (unsigned)launch_data_array_get_count(listening_fd_array));
+        return ERROR_FD;
+    }
+    
+    listening_fd=launch_data_array_get_index(listening_fd_array, 0);
+    return launch_data_get_fd(listening_fd);
+}
diff --git a/hw/xquartz/mach-startup/launchd_fd.h b/hw/xquartz/mach-startup/launchd_fd.h
new file mode 100644
index 0000000..5083fae
--- /dev/null
+++ b/hw/xquartz/mach-startup/launchd_fd.h
@@ -0,0 +1,36 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#ifndef _XQUARTZ_LAUNCHD_FD_H_
+#define _XQUARTZ_LAUNCHD_FD_H_
+
+#define ERROR_FD -1
+
+int launchd_display_fd(void);
+
+#endif /* _XQUARTZ_LAUNCHD_FD_H_ */
\ No newline at end of file
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index cc0c889..b9d45cb 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -904,7 +904,6 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) {
 	
 	QuartzXkbUpdate(pDev);
 #else
-#error FAIL
     assert( InitKeyboardDeviceStruct( (DevicePtr)pDev, &keySyms,
                                       keyInfo.modMap, QuartzBell,
                                       DarwinChangeKeyboardControl ));
@@ -921,7 +920,6 @@ void DarwinKeyboardReloadHandler(int screenNum, xEventPtr xe, DeviceIntPtr pDev,
 #ifdef XQUARTZ_USE_XKB
 	QuartzXkbUpdate(pDev);
 #else
-#error FAIL
 	if (pDev->key) {
 		if (pDev->key->curKeySyms.map) xfree(pDev->key->curKeySyms.map);
 		if (pDev->key->modifierKeyMap) xfree(pDev->key->modifierKeyMap);
diff --git a/include/os.h b/include/os.h
index 4be6b80..4bc268e 100644
--- a/include/os.h
+++ b/include/os.h
@@ -166,6 +166,10 @@ extern void MakeClientGrabImpervious(ClientPtr /*client*/);
 
 extern void MakeClientGrabPervious(ClientPtr /*client*/);
 
+#ifdef XQUARTZ
+extern void ListenOnOpenFD(int /* fd */);
+#endif
+
 extern void AvailableClientInput(ClientPtr /* client */);
 
 extern CARD32 GetTimeInMillis(void);
diff --git a/os/connection.c b/os/connection.c
index 1ae50fe..fb366a9 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -1300,3 +1300,67 @@ MakeClientGrabPervious(ClientPtr client)
     }
 }
 
+#ifdef XQUARTZ
+/* Add a fd (from launchd) to our listeners */
+_X_EXPORT void ListenOnOpenFD(int fd) {
+    char port[20];
+    XtransConnInfo ciptr, *ciptr2, *ciptr3;
+    int *iptr, *iptr2;
+    
+    /* Sigh for inconsistencies. */  
+    sprintf (port, ":%d", atoi(display));
+
+    /* Make our XtransConnInfo
+     * TRANS_SOCKET_LOCAL_INDEX = 5 from Xtrans.c
+     */
+    ciptr = _XSERVTransReopenCOTSServer(5, fd, port);
+    if(ciptr == NULL) {
+        fprintf(stderr, "Got NULL while trying to Reopen launchd port.\n");
+        return;
+    }
+    
+    /* Allocate space to store it */
+    iptr = (int *) realloc(ListenTransFds, (ListenTransCount + 1) * sizeof (int));
+    
+    if(!iptr) {
+        fprintf(stderr, "Memory allocation error");
+        return;
+    }
+    
+    ciptr2 = (XtransConnInfo *) realloc(ListenTransConns, (ListenTransCount + 1) * sizeof (XtransConnInfo));
+    if(!ciptr2) {
+        fprintf(stderr, "Memory allocation error");
+        if(iptr != ListenTransFds)
+            free(ListenTransFds);
+        return;
+    }
+
+    if(iptr != ListenTransFds) {
+        iptr2 = ListenTransFds;
+        ListenTransFds = iptr;
+        free(iptr2);
+    }
+    
+    if(ciptr2 != ListenTransConns) {
+        ciptr3 = ListenTransConns;
+        ListenTransConns = ciptr2;
+        free(ciptr3);
+    }
+    
+    /* Store it */
+    ListenTransConns[ListenTransCount] = ciptr;
+    ListenTransFds[ListenTransCount] = fd;
+
+    FD_SET(fd, &WellKnownConnections);
+    
+    /* It is always local
+    if (!_XSERVTransIsLocal(ciptr)) {
+    //    DefineSelf (fd);
+    }
+    */
+    
+    /* Increment the count */
+    ListenTransCount++;
+}
+
+#endif
commit 3a0fc76ac75ba3f9b42a4c882b58b638be6d32cf
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu May 15 07:08:21 2008 -0700

    XQuartz: Disable xkb since it doesn't work after getting xkeyboard-config installed
    
    Need to setup configs for the quartz keyboard
    (cherry picked from commit c28fecc621b1803a4d4536afbc724d141de9e6ee)

diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 698f39a..cc0c889 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -43,7 +43,10 @@
 // Define this to get a diagnostic output to stderr which is helpful
 // in determining how the X server is interpreting the Darwin keymap.
 #define DUMP_DARWIN_KEYMAP
-#define XQUARTZ_USE_XKB
+
+// This breaks when we actually install xkeyboard-config files to start using it
+// We need to serup keymaps in the configs or something...
+// #define XQUARTZ_USE_XKB 
 #define HACK_MISSING 1
 #define HACK_KEYPAD 1
 
commit 7d39e7e40092cda5dd1179f54f9cd22b93bf2369
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu May 15 05:49:43 2008 -0700

    XQuartz: Made DarwinSendDDXEvent a little more robust to context switching diring server init.
    (cherry picked from commit 5626b0949b1a6bdd2fa3ec2ef53a688084349b87)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 9367c9f..50a30fb 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -59,11 +59,9 @@
 int X11EnableKeyEquivalents = TRUE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
-extern int darwinFakeButtons, input_check_flag;
+extern int darwinFakeButtons;
 extern Bool enable_stereo;
 
-extern xEvent *darwinEvents;
-
 X11Application *X11App;
 
 #define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 1547094..7376c57 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -76,12 +76,10 @@ in this Software without prior written authorization from The Open Group.
 /* FIXME: Abstract this better */
 void QuartzModeEQInit(void);
 
-int input_check_zero, input_check_flag;
-
 static int old_flags = 0;  // last known modifier state
 
-xEvent *darwinEvents = NULL;
-pthread_mutex_t darwinEvents_mutex = PTHREAD_MUTEX_INITIALIZER;
+static xEvent *darwinEvents = NULL;
+static pthread_mutex_t darwinEvents_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static inline void darwinEvents_lock(void) {
     int err;
@@ -307,11 +305,6 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
 }
 
 Bool DarwinEQInit(void) { 
-    if (!darwinEvents)
-        darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!darwinEvents)
-        FatalError("Couldn't allocate event buffer\n");
-
     mieqInit();
     mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
     mieqSetHandler(kXquartzActivate, DarwinEventHandler);
@@ -328,6 +321,11 @@ Bool DarwinEQInit(void) {
     mieqSetHandler(kXquartzDisplayChanged, QuartzDisplayChangedHandler);
 
     QuartzModeEQInit();
+
+    if (!darwinEvents)
+        darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
+    if (!darwinEvents)
+        FatalError("Couldn't allocate event buffer\n");
     
     return TRUE;
 }
@@ -354,7 +352,6 @@ void ProcessInputEvents(void) {
    Dispatch() event loop to check out event queue */
 static void DarwinPokeEQ(void) {
 	char nullbyte=0;
-	input_check_flag++;
 	//  <daniels> oh, i ... er ... christ.
 	write(darwinEventWriteFD, &nullbyte, 1);
 }
@@ -567,8 +564,13 @@ void DarwinSendDDXEvent(int type, int argc, ...) {
         va_end (args);
     }
 
-    darwinEvents_lock();
+    /* If we're called from something other than the X server thread, we need
+     * to wait for the X server to setup darwinEvents.
+     */
+    while(darwinEvents == NULL) {
+        usleep(250000);
+    }
+
     mieqEnqueue(darwinPointer, &xe);
     DarwinPokeEQ();
-    darwinEvents_unlock();
 }
commit 880a8724988dccb6a661d659cc6dd4274971eb93
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed May 14 01:33:43 2008 -0700

    Xquartz: Xquartz stub now can send Mach IPC to start the server.
    (cherry picked from commit 55a3bca8ea42f8677897f94bf0a429bdc08c6696)

diff --git a/hw/xquartz/mach-startup/Makefile.am b/hw/xquartz/mach-startup/Makefile.am
index ee2cbfe..d81caa9 100644
--- a/hw/xquartz/mach-startup/Makefile.am
+++ b/hw/xquartz/mach-startup/Makefile.am
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	-DBUILD_DATE=\"$(BUILD_DATE)\" \
 	-DXSERVER_VERSION=\"$(VERSION)\"
+#	-DNEW_LAUNCH_METHOD -DNEW_LAUNCH_METHOD_2
 
 x11appdir = $(APPLE_APPLICATIONS_DIR)/X11.app/Contents/MacOS
 x11app_PROGRAMS = X11
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index cd64e42..dd75f02 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -165,10 +165,11 @@ int main(int argc, char **argv, char **envp) {
     mach_port_t mp;
     kern_return_t kr;
 
+    fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
     for(i=1; i < argc; i++) {
+        fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
         if(!strcmp(argv[i], "--listenonly")) {
             listenOnly = TRUE;
-            break;
         }
     }
 
@@ -221,10 +222,12 @@ int main(int argc, char **argv, char **envp) {
     const char *s;
     
     size_t i;
+#ifndef NEW_LAUNCH_METHOD
     fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
     for(i=0; i < argc; i++) {
         fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
     }
+#endif
     
     /* Take care of the case where we're called like a normal DDX */
     if(argc > 1 && argv[1][0] == ':') {
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index fae9720..c53ed53 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -115,6 +115,7 @@ int main(int argc, char **argv, char **envp) {
     mach_port_t mp;
     string_array_t newenvp;
     string_array_t newargv;
+    size_t i;
 #endif
 
     if(argc == 2 && !strcmp(argv[1], "-version")) {
@@ -127,7 +128,6 @@ int main(int argc, char **argv, char **envp) {
 #ifdef NEW_LAUNCH_METHOD_2
     kr = bootstrap_look_up(bootstrap_port, SERVER_BOOTSTRAP_NAME, &mp);
     if(kr != KERN_SUCCESS) {
-        int i;
         set_x11_path();
 
         /* This forking is ugly and will be cleaned up later */
@@ -142,19 +142,20 @@ int main(int argc, char **argv, char **envp) {
             _argv[0] = x11_path;
             _argv[1] = "--listenonly";
             _argv[2] = NULL;
+            fprintf(stderr, "Starting X server: %s --listenonly\n", x11_path);
             return execvp(x11_path, _argv);
         }
 
         /* Try connecting for 10 seconds */
-        for(i=0; i < 20; i++) {
-            usleep(500);
+        for(i=0; i < 40; i++) {
+            usleep(250000);
             kr = bootstrap_look_up(bootstrap_port, SERVER_BOOTSTRAP_NAME, &mp);
             if(kr == KERN_SUCCESS)
                 break;
         }
 
         if(kr != KERN_SUCCESS) {
-            fprintf(stderr, "bootstrap_look_up(): %s\n", bootstrap_strerror(kr));
+            fprintf(stderr, "bootstrap_look_up(): Timed out: %s\n", bootstrap_strerror(kr));
             return EXIT_FAILURE;
         }
     }
commit e644d2e73f72e7a3e1a9525bdde0de2012efec59
Author: James Cloos <cloos at jhcloos.com>
Date:   Mon May 12 03:03:13 2008 -0400

    Prevent the -wm command line option from causing a SEGV
    
    The -wm (when mapped) option for the BackingStore support has been
    causing the server to dereference a NULL pointer.
    
    This has probably been the case since backing store has been
    implemented on top of Composite.
    
    It looks like (some of?) Composite didn’t expect its WIndowPtr
    argument to be the root window.
    
    In Composite’s compCheckRedirect() function we now avoid calling
    compAllocPixmap() and compFreePixmap() when the pWin pointer’s
    parent member is NULL, as is it the case with a server’s root window.
    
    This addresses:
    
    https://bugs.freedesktop.org/show_bug.cgi?id=15878
    
    (cherry picked from commit 04211c3532ca078420e3745a5eac3d9de120bc32)

diff --git a/composite/compwindow.c b/composite/compwindow.c
index c022027..05dc055 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -146,8 +146,8 @@ compCheckRedirect (WindowPtr pWin)
     Bool	    should;
 
     should = pWin->realized && (pWin->drawable.class != InputOnly) &&
-	     (cw != NULL);
-    
+	     (cw != NULL) && (pWin->parent != NULL);
+
     /* Never redirect the overlay window */
     if (cs->pOverlayWin != NULL) {
 	if (pWin == cs->pOverlayWin) {
commit 0230f39fa3b3076b7694b6443a7a3ad8f63f7b55
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 16 10:52:41 2008 -0400

    RANDR 1.1 compat: remove senseless comparison against the virtual size.
    (cherry picked from commit aad1c37b0951eae216ac323c5d8bfc6fbcf096bd)

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 14c2d41..6f8ccdf 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -119,9 +119,7 @@ xf86RandR12GetInfo (ScreenPtr pScreen, Rotation *rotations)
 	    return FALSE;
 	RRRegisterRate (pScreen, pSize, refresh);
 
-	if (xf86ModesEqual(mode, scrp->currentMode) &&
-	    mode->HDisplay == scrp->virtualX &&
-	    mode->VDisplay == scrp->virtualY)
+	if (xf86ModesEqual(mode, scrp->currentMode))
 	{
 	    RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize);
 	}
commit 95985256efa7e86cefe4b1541780eda12c0c8f89
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 16 10:51:32 2008 -0400

    xf86SetDesiredModes(): Skip disabled CRTCs first thing.
    (cherry picked from commit 14726b776d6cebb7d864b6ffa7554e1ce5637d5c)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 57fc2c7..e857b07 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -2188,6 +2188,10 @@ xf86SetDesiredModes (ScrnInfoPtr scrn)
 	xf86OutputPtr	output = NULL;
 	int		o;
 
+	/* Skip disabled CRTCs */
+	if (!crtc->enabled)
+	    continue;
+
 	if (config->output[config->compat_output]->crtc == crtc)
 	    output = config->output[config->compat_output];
 	else
@@ -2199,9 +2203,7 @@ xf86SetDesiredModes (ScrnInfoPtr scrn)
 		    break;
 		}
 	}
-	/*
-	 * Skip disabled crtcs
-	 */
+	/* paranoia */
 	if (!output)
 	    continue;
 
commit bedcf985580e7d6684ee9079fe955b6a7e49ad48
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 16 10:48:00 2008 -0400

    Fix initial mode selection even harder.
    
    The first guess used to be "is the preferred mode for one output the
    preferred mode on all outputs".  Instead, do "find the largest mode that's
    preferred for at least one output and available on all outputs".
    (cherry picked from commit 459f34b089aca4f4eee9752600c3a9e4f4e343ab)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index e6dd2de..57fc2c7 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1751,46 +1751,65 @@ nextEnabledOutput(xf86CrtcConfigPtr config, Bool *enabled, int *index)
 }
 
 static Bool
-xf86TargetExact(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
-		DisplayModePtr *modes, Bool *enabled,
-		int width, int height)
+xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
+		    DisplayModePtr *modes, Bool *enabled,
+		    int width, int height)
 {
-    int o;
-    int pref_width = 0, pref_height = 0;
-    DisplayModePtr *preferred;
+    int o, p;
+    int max_pref_width = 0, max_pref_height = 0;
+    DisplayModePtr *preferred, *preferred_match;
     Bool ret = FALSE;
 
     preferred = xnfcalloc(config->num_output, sizeof(DisplayModePtr));
+    preferred_match = xnfcalloc(config->num_output, sizeof(DisplayModePtr));
+
+    /* Check if the preferred mode is available on all outputs */
+    for (p = -1; nextEnabledOutput(config, enabled, &p); ) {
+	Rotation r = config->output[p]->initial_rotation;
+	DisplayModePtr mode;
+	if ((preferred[p] = xf86OutputHasPreferredMode(config->output[p],
+			width, height))) {
+	    int pref_width = xf86ModeWidth(preferred[p], r);
+	    int pref_height = xf86ModeHeight(preferred[p], r);
+	    Bool all_match = TRUE;
+
+	    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
+		Bool match = FALSE;
+		xf86OutputPtr output = config->output[o];
+		if (o == p)
+		    continue;
 
-    /* Find all the preferred modes; fail if any outputs lack them */
-    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
-	preferred[o] =
-	    xf86OutputHasPreferredMode(config->output[o], width, height);
+		for (mode = output->probed_modes; mode; mode = mode->next) {
+		    Rotation r = output->initial_rotation;
+		    if (xf86ModeWidth(mode, r) == pref_width &&
+			    xf86ModeHeight(mode, r) == pref_height) {
+			preferred[o] = mode;
+			match = TRUE;
+		    }
+		}
 
-	if (!preferred[o])
-	    goto out;
-    }
+		all_match &= match;
+	    }
 
-    /* check that they're all the same size */
-    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
-	Rotation r = config->output[o]->initial_rotation;
-	if (!pref_width) {
-	    pref_width = xf86ModeWidth(preferred[o], r);
-	    pref_height = xf86ModeHeight(preferred[o], r);
-	} else {
-	    if (pref_width != xf86ModeWidth(preferred[o], r))
-		goto out;
-	    if (pref_height != xf86ModeHeight(preferred[o], r))
-		goto out;
+	    if (all_match &&
+		    (pref_width*pref_height > max_pref_width*max_pref_height)) {
+		for (o = -1; nextEnabledOutput(config, enabled, &o); )
+		    preferred_match[o] = preferred[o];
+		max_pref_width = pref_width;
+		max_pref_height = pref_height;
+		ret = TRUE;
+	    }
 	}
     }
 
-    /* oh good, they match.  stash the selected modes and return. */
-    memcpy(modes, preferred, config->num_output * sizeof(DisplayModePtr));
-    ret = TRUE;
+    if (ret) {
+	/* oh good, there is a match.  stash the selected modes and return. */
+	memcpy(modes, preferred_match,
+		config->num_output * sizeof(DisplayModePtr));
+    }
 
-out:
     xfree(preferred);
+    xfree(preferred_match);
     return ret;
 }
 
@@ -2016,7 +2035,7 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
 
     if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
 	xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
-    else if (xf86TargetExact(scrn, config, modes, enabled, width, height))
+    else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
 	xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
     else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
 	xf86DrvMsg(i, X_INFO, "Using fuzzy aspect match for initial modes\n");
@@ -2088,6 +2107,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
 	    crtc->x = output->initial_x;
 	    crtc->y = output->initial_y;
 	    output->crtc = crtc;
+	} else {
+	    output->crtc = NULL;
 	}
     }
     
commit bd50c41f6f479822ec595e02b3ae7a2f6060ba06
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 16 10:31:58 2008 -0400

    Redo RANDR compatibility output selection.
    
    Old logic was just the first one that happened to have an associated
    CRTC.  The new logic tries to find one that's definitely connected, has
    probed modes, and has the largest candidate mode.
    (cherry picked from commit 96111c154713600dd534dd82104ac18b91466202)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 0e6dd63..e6dd2de 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1584,7 +1584,98 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
 _X_EXPORT void
 xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr scrn, int *x, int *y);
 
-_X_EXPORT void
+static DisplayModePtr
+biggestMode(DisplayModePtr a, DisplayModePtr b)
+{
+    int A, B;
+
+    if (!a)
+	return b;
+    if (!b)
+	return a;
+
+    A = a->HDisplay * a->VDisplay;
+    B = b->HDisplay * b->VDisplay;
+
+    if (A > B)
+	return a;
+
+    return b;
+}
+
+static xf86OutputPtr
+SetCompatOutput(xf86CrtcConfigPtr config)
+{
+    xf86OutputPtr output = NULL, test = NULL;
+    DisplayModePtr maxmode = NULL, testmode, mode;
+    int o, compat = -1, count, mincount = 0;
+
+    /* Look for one that's definitely connected */
+    for (o = 0; o < config->num_output; o++)
+    {
+	test = config->output[o];
+	if (!test->crtc)
+	    continue;
+	if (test->status != XF86OutputStatusConnected)
+	    continue;
+	if (!test->probed_modes)
+	    continue;
+
+	testmode = mode = test->probed_modes;
+	for (count = 0; mode; mode = mode->next, count++)
+	    testmode = biggestMode(testmode, mode);
+
+	if (!output) {
+	    output = test;
+	    compat = o;
+	    maxmode = testmode;
+	    mincount = count;
+	} else if (maxmode == biggestMode(maxmode, testmode)) {
+	    output = test;
+	    compat = o;
+	    maxmode = testmode;
+	    mincount = count;
+	} else if ((maxmode->HDisplay == testmode->HDisplay) && 
+		(maxmode->VDisplay == testmode->VDisplay) &&
+		count <= mincount) {
+	    output = test;
+	    compat = o;
+	    maxmode = testmode;
+	    mincount = count;
+	}
+    }
+
+    /* If we didn't find one, take anything we can get */
+    if (!output)
+    {
+	for (o = 0; o < config->num_output; o++)
+	{
+	    test = config->output[o];
+	    if (!test->crtc)
+		continue;
+	    if (!test->probed_modes)
+		continue;
+
+	    if (!output) {
+		output = test;
+		compat = o;
+	    } else if (test->probed_modes->HDisplay < output->probed_modes->HDisplay) {
+		output = test;
+		compat = o;
+	    }
+	}
+    }
+
+    if (compat >= 0) {
+	config->compat_output = compat;
+    } else {
+	/* Don't change the compat output when no valid outputs found */
+	output = config->output[config->compat_output];
+    }
+
+    return output;
+}
+
 xf86SetScrnInfoModes (ScrnInfoPtr scrn)
 {
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
@@ -1592,23 +1683,11 @@ xf86SetScrnInfoModes (ScrnInfoPtr scrn)
     xf86CrtcPtr		crtc;
     DisplayModePtr	last, mode;
 
-    output = config->output[config->compat_output];
-    if (!output->crtc)
-    {
-	int o;
+    output = SetCompatOutput(config);
+
+    if (!output)
+	return; /* punt */
 
-	output = NULL;
-	for (o = 0; o < config->num_output; o++)
-	    if (config->output[o]->crtc)
-	    {
-		config->compat_output = o;
-		output = config->output[o];
-		break;
-	    }
-	/* no outputs are active, punt and leave things as they are */
-	if (!output)
-	    return;
-    }
     crtc = output->crtc;
 
     /* Clear any existing modes from scrn->modes */
@@ -1773,25 +1852,6 @@ bestModeForAspect(xf86CrtcConfigPtr config, Bool *enabled, float aspect)
     return match;
 }
 
-static DisplayModePtr
-biggestMode(DisplayModePtr a, DisplayModePtr b)
-{
-    int A, B;
-
-    if (!a)
-	return b;
-    if (!b)
-	return a;
-
-    A = a->HDisplay * a->VDisplay;
-    B = b->HDisplay * b->VDisplay;
-
-    if (A > B)
-	return a;
-
-    return b;
-}
-
 static Bool
 xf86TargetAspect(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
 		 DisplayModePtr *modes, Bool *enabled,
commit 0b031442fe7a04ac8c935ab5858854436f3f3d3c
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 16 10:25:12 2008 -0400

    Re-add sync range inference from legacy setup to RANDR 1.2.
    (cherry picked from commit a4bbe1c8bca08f3df5ff7e50444af6aef7ec8b25)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2b07421..0e6dd63 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1291,6 +1291,50 @@ preferredMode(ScrnInfoPtr pScrn, xf86OutputPtr output)
     return preferred_mode;
 }
 
+static void
+GuessRangeFromModes(MonPtr mon, DisplayModePtr mode)
+{
+    if (!mon || !mode)
+       return;
+
+    mon->nHsync = 1;
+    mon->hsync[0].lo = 1024.0;
+    mon->hsync[0].hi = 0.0;
+
+    mon->nVrefresh = 1;
+    mon->vrefresh[0].lo = 1024.0;
+    mon->vrefresh[0].hi = 0.0;
+
+    while (mode) {
+	if (!mode->HSync)
+	    mode->HSync = ((float) mode->Clock ) / ((float) mode->HTotal);
+
+	if (!mode->VRefresh)
+	    mode->VRefresh = (1000.0 * ((float) mode->Clock)) / 
+		((float) (mode->HTotal * mode->VTotal));
+
+	if (mode->HSync < mon->hsync[0].lo)
+	    mon->hsync[0].lo = mode->HSync;
+
+	if (mode->HSync > mon->hsync[0].hi)
+	    mon->hsync[0].hi = mode->HSync;
+
+	if (mode->VRefresh < mon->vrefresh[0].lo)
+	    mon->vrefresh[0].lo = mode->VRefresh;
+
+	if (mode->VRefresh > mon->vrefresh[0].hi)
+	    mon->vrefresh[0].hi = mode->VRefresh;
+
+	mode = mode->next;
+    }
+
+    /* stretch out the bottom to fit 640x480 at 60 */
+    if (mon->hsync[0].lo > 31.0)
+       mon->hsync[0].lo = 31.0;
+    if (mon->vrefresh[0].lo > 58.0)
+       mon->vrefresh[0].lo = 58.0;
+}
+
 _X_EXPORT void
 xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
 {
@@ -1408,6 +1452,10 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
 			       OPTUNITS_KHZ, &clock))
 	    max_clock = (int) clock;
 
+	/* If we still don't have a sync range, guess wildly */
+	if (!mon_rec.nHsync || !mon_rec.nVrefresh)
+	    GuessRangeFromModes(&mon_rec, output_modes);
+
 	/*
 	 * These limits will end up setting a 1024x768 at 60Hz mode by default,
 	 * which seems like a fairly good mode to use when nothing else is
commit b053c9768bca21e8df0df37f45465e2e14bc00fc
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Apr 9 13:55:25 2008 -0400

    Default X-SELinux to off.
    
    Applied only to 1.5 branch for purposes of release stability.  Reevaluate
    this when we do 1.6.

diff --git a/os/utils.c b/os/utils.c
index d785d46..f58c763 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -233,7 +233,7 @@ _X_EXPORT Bool noXInputExtension = FALSE;
 _X_EXPORT Bool noXIdleExtension = FALSE;
 #endif
 #ifdef XSELINUX
-_X_EXPORT Bool noSELinuxExtension = FALSE;
+_X_EXPORT Bool noSELinuxExtension = TRUE;
 _X_EXPORT int selinuxEnforcingState = SELINUX_MODE_DEFAULT;
 #endif
 #ifdef XV
commit cfff55a2bb8618867513bd0f3e66d131ed4edaa8
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon May 12 14:53:37 2008 -0400

    Fix fbdevhw initialization for PCI drivers.
    
    graphics/fb%d, not graphics:fb%d.  Thanks sysfs.  Thysfs.
    (cherry picked from commit 86678e7cc2b021851ff508433fa160170f500c51)

diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index a1f6748..4d51422 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -310,12 +310,12 @@ fbdev_open_pci(struct pci_device * pPci, char **namep)
     /* There are two ways to that we can determine which fb device is
      * associated with this PCI device.  The more modern way is to look in
      * the sysfs directory for the PCI device for a file named
-     * "graphics:fb*"
+     * "graphics/fb*"
      */
 
     for (i = 0; i < 8; i++) {
 	sprintf(filename, 
-		"/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics:fb%d",
+		"/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics/fb%d",
 		pPci->domain, pPci->bus, pPci->dev, pPci->func, i);
 
 	fd = open(filename, O_RDONLY, 0);
commit 1bd229d4ac36eaebf921a9b3526acd947ca0bfaf
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon May 5 14:37:07 2008 -0400

    Fix hal shutdown crash.
    
    Removing the device invalidates its ->next pointer.  Copy it aside before
    destroying the device.
    (cherry picked from commit f52f6c5c7efc281f9ac204fbaa4f71383df7463d)

diff --git a/config/hal.c b/config/hal.c
index 1575422..6534408 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -63,7 +63,7 @@ remove_device(DeviceIntPtr dev)
 static void
 device_removed(LibHalContext *ctx, const char *udi)
 {
-    DeviceIntPtr dev;
+    DeviceIntPtr dev, next;
     char *value;
 
     value = xalloc(strlen(udi) + 5); /* "hal:" + NULL */
@@ -71,11 +71,13 @@ device_removed(LibHalContext *ctx, const char *udi)
         return;
     sprintf(value, "hal:%s", udi);
 
-    for (dev = inputInfo.devices; dev; dev = dev->next) {
+    for (dev = inputInfo.devices; dev; dev = next) {
+	next = dev->next;
         if (dev->config_info && strcmp(dev->config_info, value) == 0)
             remove_device(dev);
     }
-    for (dev = inputInfo.off_devices; dev; dev = dev->next) {
+    for (dev = inputInfo.off_devices; dev; dev = next) {
+	next = dev->next;
         if (dev->config_info && strcmp(dev->config_info, value) == 0)
             remove_device(dev);
     }
commit 18a1d643bc82f15ad26059e2a479f5d5dd778343
Author: Hans de Goede <j.w.r.degoede at hhs.nl>
Date:   Wed Apr 23 12:28:30 2008 -0400

    Prefer glxvisuals with stencil buffer for default visuals
    
    The first fbconfig which has a depthbuffer > 0  and doublebuf is choosen
    when associating fbconfigs with the visuals, indepenent of stencil bits.
    This happens to work ok on intel as there all fbconfigs with a
    depthbuffer > 0 also have stencil bits.
    
    This patch fixes this by first trying to get a fbconfig for default X visuals
    with both stencilbuf, depthbuf and doublebuffering, and if that fails fallback
    to trying to get one with only a depthbuf and doublebuffering.
    (cherry picked from commit f6e22d69af6bc8f63c3a46535a09e217696a679f)

diff --git a/GL/glx/glxscreens.c b/GL/glx/glxscreens.c
index 41ee029..5859de0 100644
--- a/GL/glx/glxscreens.c
+++ b/GL/glx/glxscreens.c
@@ -437,6 +437,7 @@ initGlxVisual(VisualPtr visual, __GLXconfig *config)
 typedef struct {
     GLboolean doubleBuffer;
     GLboolean depthBuffer;
+    GLboolean stencilBuffer;
 } FBConfigTemplateRec, *FBConfigTemplatePtr;
 
 static __GLXconfig *
@@ -453,6 +454,8 @@ pickFBConfig(__GLXscreen *pGlxScreen, FBConfigTemplatePtr template, int class)
 	    continue;
 	if ((config->depthBits > 0) != template->depthBuffer)
 	    continue;
+	if ((config->stencilBits > 0) != template->stencilBuffer)
+	    continue;
 
 	return config;
     }
@@ -466,8 +469,9 @@ addMinimalSet(__GLXscreen *pGlxScreen)
     __GLXconfig *config;
     VisualPtr visuals;
     int i, j;
-    FBConfigTemplateRec best = { GL_TRUE, GL_TRUE };
-    FBConfigTemplateRec minimal = { GL_FALSE, GL_FALSE };
+    FBConfigTemplateRec best = { GL_TRUE, GL_TRUE, GL_TRUE };
+    FBConfigTemplateRec good = { GL_TRUE, GL_TRUE, GL_FALSE };
+    FBConfigTemplateRec minimal = { GL_FALSE, GL_FALSE, GL_FALSE };
 
     pGlxScreen->visuals = xcalloc(pGlxScreen->pScreen->numVisuals,
 				  sizeof (__GLXconfig *));
@@ -480,8 +484,11 @@ addMinimalSet(__GLXscreen *pGlxScreen)
     for (i = 0, j = 0; i < pGlxScreen->pScreen->numVisuals; i++) {
 	if (visuals[i].nplanes == 32)
 	    config = pickFBConfig(pGlxScreen, &minimal, visuals[i].class);
-	else
+	else {
 	    config = pickFBConfig(pGlxScreen, &best, visuals[i].class);
+	    if (config == NULL)
+		config = pickFBConfig(pGlxScreen, &good, visuals[i].class);
+        }
 	if (config == NULL)
 	    config = pGlxScreen->fbconfigs;
 	if (config == NULL)


More information about the xorg-commit mailing list