Apple: Apple launchd cleanup
[free-sw/xcb/libxcb] / src / xcb_util.c
index 7c6a4dd..5bad16a 100644 (file)
@@ -315,11 +315,22 @@ xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
     char *protocol;
     xcb_connection_t *c;
     xcb_auth_info_t auth;
-
-    if(!_xcb_parse_display(displayname, &host, &protocol, &display, screenp))
+    
+    int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
+
+#ifdef HAVE_LAUNCHD
+    if(!displayname)
+        displayname = getenv("DISPLAY");
+    if(displayname && strlen(displayname)>11 && !strncmp(displayname, "/tmp/launch", 11))
+        fd = _xcb_open_unix(NULL, displayname);
+    else
+#endif
+    if(!parsed)
         return (xcb_connection_t *) &error_connection;
-    fd = _xcb_open(host, protocol, display);
+    else
+        fd = _xcb_open(host, protocol, display);
     free(host);
+
     if(fd == -1)
         return (xcb_connection_t *) &error_connection;
 
@@ -340,10 +351,21 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
     char *host;
     char *protocol;
 
-    if(!_xcb_parse_display(displayname, &host, &protocol, &display, screenp))
+    int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
+    
+#ifdef HAVE_LAUNCHD
+    if(!displayname)
+        displayname = getenv("DISPLAY");
+    if(displayname && strlen(displayname)>11 && !strncmp(displayname, "/tmp/launch", 11))
+        fd = _xcb_open_unix(NULL, displayname);
+    else
+#endif
+    if(!parsed)
         return (xcb_connection_t *) &error_connection;
-    fd = _xcb_open(host, protocol, display);
+    else
+        fd = _xcb_open(host, protocol, display);
     free(host);
+
     if(fd == -1)
         return (xcb_connection_t *) &error_connection;