summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremy@yuffie.local>2007-12-16 01:12:20 -0800
committerJeremy Huddleston <jeremy@yuffie.local>2007-12-16 01:12:20 -0800
commitcced740b1e1c8220701e59cec1be04498f851296 (patch)
tree8ec8a2cd170282ceef7bc420cbe396db24605a1b
parent3c5ae3a242895f53d4f27fefb785f2725077a55d (diff)
OS-X: Added argv[0] hack for finding Xquartz UI and icon as well as claiming its dock icon
Partially removes need for x11-exec on OS-X. We still need to handle options set in defaults.
-rw-r--r--.gitignore3
-rw-r--r--Makefile.am22
-rw-r--r--configure.ac2
-rw-r--r--launchd/Makefile.am15
-rw-r--r--launchd/x11-exec.c87
-rw-r--r--org.x.X11.plist.cpp (renamed from launchd/org.x.X11.plist.cpp)5
-rw-r--r--xinit.c60
7 files changed, 76 insertions, 118 deletions
diff --git a/.gitignore b/.gitignore
index 6356185..363b8c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,5 +22,4 @@ xinit.1
xinitrc
*~
*.o
-launchd/org.x.X11.plist
-launchd/x11-exec
+org.x.X11.plist
diff --git a/Makefile.am b/Makefile.am
index fe39364..d170510 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,10 @@ bin_SCRIPTS = startx
xinit_CFLAGS = $(XINIT_CFLAGS) -DXINITDIR=\"$(XINITDIR)\" -DBINDIR=\"$(bindir)\"
xinit_LDADD = $(XINIT_LIBS)
+if APPLE
+xinit_LDFLAGS = -framework CoreServices
+endif
+
xinit_SOURCES = \
xinit.c
@@ -54,14 +58,21 @@ PROGCPPDEFS = \
CPP_FILES_FLAGS = \
-DXINITDIR=$(XINITDIR) $(PROGCPPDEFS) -DLIBDIR=$(libdir) \
- -DSHELL_CMD=$(SHELL_CMD) $(STARTX_COOKIE_FLAGS)
+ -DSHELL_CMD=$(SHELL_CMD) $(STARTX_COOKIE_FLAGS) \
+ -D__libexecdir__="$(libexecdir)" \
+ -D__bindir__="$(bindir)"
+
+if LAUNCHD
+launchagents_PRE = org.x.X11.plist.pre
+launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
+endif
xinitrc: xinitrc.cpp Makefile
startx: startx.cpp Makefile
xinitrc_DATA = xinitrc
-CLEANFILES = xinitrc startx $(appman_DATA)
+CLEANFILES = xinitrc startx $(appman_DATA) $(launchagents_DATA)
EXTRA_DIST = xinitrc.cpp startx.cpp $(appman_PRE) \
startx.cmd xinitrc.cmd xinit.def ChangeLog autogen.sh
@@ -72,10 +83,3 @@ ChangeLog:
(GIT_DIR=$(top_srcdir)/.git git-log > .changelog.tmp && mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) || (touch ChangeLog; echo 'git directory not found: installing possibly empty changelog.' >&2)
dist-hook: ChangeLog
-
-if LAUNCHD
-LAUNCHD_SUBDIRS = launchd
-endif
-
-SUBDIRS = $(LAUNCHD_SUBDIRS)
-DIST_SUBDIRS = launchd
diff --git a/configure.ac b/configure.ac
index 1413595..57def24 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
+AM_PROG_CC_C_O
XORG_PROG_RAWCPP
AC_PROG_INSTALL
AC_PATH_PROG(SED,sed)
@@ -175,4 +176,3 @@ XORG_MANPAGE_SECTIONS
XORG_RELEASE_VERSION
AC_OUTPUT([Makefile])
-AC_OUTPUT([launchd/Makefile])
diff --git a/launchd/Makefile.am b/launchd/Makefile.am
deleted file mode 100644
index b841df8..0000000
--- a/launchd/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-if APPLE
-libexec_PROGRAMS = x11-exec
-x11_exec_LDFLAGS = -framework CoreServices
-endif
-
-launchagents_PRE = org.x.X11.plist.pre
-launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
-
-CPP_FILES_FLAGS = \
- -D__libexecdir__="$(libexecdir)" \
- -D__bindir__="$(bindir)"
-
-CLEANFILES = $(launchagents_DATA)
-
-include $(top_srcdir)/cpprules.in
diff --git a/launchd/x11-exec.c b/launchd/x11-exec.c
deleted file mode 100644
index bc1a233..0000000
--- a/launchd/x11-exec.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* x11-exec.c -- Find X11.app by bundle-id and report its path.
- This is so launchd can correctly find X11.app, even if the user moved it.
-
- Copyright (c) 2007 Apple, Inc.
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
-
- Except as contained in this notice, the name(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization. */
-
-#include <CoreServices/CoreServices.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#define kX11AppBundleId "org.x.X11"
-#define kX11AppBundlePath "/Contents/MacOS/X11"
-
-int main(int argc, char **argv) {
- char x11_path[PATH_MAX];
- char** args = NULL;
- CFURLRef appURL = NULL;
- OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL);
-
- switch (osstatus) {
- case noErr:
- if (appURL == NULL) {
- fprintf(stderr, "%s: Invalid response from LSFindApplicationForInfo(%s)\n",
- argv[0], kX11AppBundleId);
- exit(1);
- }
-
- if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
- fprintf(stderr, "%s: Error resolving URL for %s\n", argv[0], kX11AppBundleId);
- exit(2);
- }
-
- strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
- fprintf(stderr, "X11.app = %s\n", x11_path);
-
- args = (char**)malloc(sizeof (char*) * (argc + 1));
- if (args) {
- int i;
- args[0] = x11_path;
- for (i = 1; i < argc; ++i) {
- args[i] = argv[i];
- }
- args[i] = NULL;
- }
-
- execv(x11_path, args);
-
- fprintf(stderr, "Error executing X11.app (%s):", x11_path);
- perror(NULL);
- exit(3);
- break;
- case kLSApplicationNotFoundErr:
- fprintf(stderr, "%s: Unable to find application for %s\n", argv[0], kX11AppBundleId);
- exit(4);
- default:
- fprintf(stderr, "%s: Unable to find application for %s, error code = %d\n",
- argv[0], kX11AppBundleId, (int)osstatus);
- exit(5);
- }
- /* not reached */
-}
-
-
diff --git a/launchd/org.x.X11.plist.cpp b/org.x.X11.plist.cpp
index 6aed8d8..3a76a9d 100644
--- a/launchd/org.x.X11.plist.cpp
+++ b/org.x.X11.plist.cpp
@@ -6,11 +6,10 @@
<string>org.x.X11</string>
<key>ProgramArguments</key>
<array>
+ <string>__bindir__/startx</string>
#ifdef __APPLE__
- <string>__libexecdir__/x11-exec</string>
+ <string>--</string>
<string>-launchd</string>
-#else
- <string>__bindir__/startx</string>
#endif
</array>
<key>Sockets</key>
diff --git a/xinit.c b/xinit.c
index be06ad1..61cd378 100644
--- a/xinit.c
+++ b/xinit.c
@@ -39,6 +39,12 @@ in this Software without prior written authorization from The Open Group.
#include <ctype.h>
#include <stdint.h>
+#ifdef __APPLE__
+#include <CoreServices/CoreServices.h>
+#define kX11AppBundleId "org.x.X11"
+#define kX11AppBundlePath "/Contents/MacOS/X11"
+#endif
+
#ifdef X_POSIX_C_SOURCE
#define _POSIX_C_SOURCE X_POSIX_C_SOURCE
#include <signal.h>
@@ -170,6 +176,9 @@ static char **client = clientargv + 2; /* make sure room for sh .xinitrc args *
static char *displayNum = NULL;
static char *program = NULL;
static Display *xd = NULL; /* server connection */
+#ifdef __APPLE__
+static char x11_path[PATH_MAX];
+#endif
#ifndef SYSV
#if defined(__CYGWIN__) || defined(SVR4) || defined(_POSIX_SOURCE) || defined(CSRG_BASED) || defined(__UNIXOS2__) || defined(Lynx) || defined(__APPLE__)
int status;
@@ -219,11 +228,56 @@ sigUsr1(int sig)
#endif
}
+#ifdef __APPLE__
+static void set_x11_path() {
+ CFURLRef appURL = NULL;
+ OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL);
+
+ switch (osstatus) {
+ case noErr:
+ if (appURL == NULL) {
+ fprintf(stderr, "xinit: Invalid response from LSFindApplicationForInfo(%s)\n",
+ kX11AppBundleId);
+ exit(1);
+ }
+
+ if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
+ fprintf(stderr, "xinit: Error resolving URL for %s\n", kX11AppBundleId);
+ exit(2);
+ }
+
+ strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
+#ifdef DEBUG
+ fprintf(stderr, "xinit: X11.app = %s\n", x11_path);
+#endif
+ break;
+ case kLSApplicationNotFoundErr:
+ fprintf(stderr, "xinit: Unable to find application for %s\n", kX11AppBundleId);
+ exit(4);
+ default:
+ fprintf(stderr, "xinit: Unable to find application for %s, error code = %d\n",
+ kX11AppBundleId, (int)osstatus);
+ exit(5);
+ }
+}
+#endif
+
static void
Execute(char **vec, /* has room from up above */
char **envp)
{
- Execvpe (vec[0], vec, envp);
+ char *file = vec[0];
+#ifdef __APPLE__
+ /* This is ugly, but currently, we need to trick OS-X into thinking X is in
+ * the X11.app bundle. Hopefully UI, icons, etc will eventually be set
+ * by Xquartz, but this is how we're doing it for now. -JH
+ */
+ if(!strcmp(file, "/usr/X11/bin/X") || !strcmp(file, "/usr/X11/bin/Xquartz") || !strcmp(file, "X") || !strcmp(file, "Xquartz")) {
+ vec[0] = x11_path;
+ fprintf(stderr, "xinit: Detected Xquartz startup, setting file=%s, argv[0]=%s\n", file, vec[0]);
+ }
+#endif
+ Execvpe (file, vec, envp);
#ifndef __UNIXOS2__
if (access (vec[0], R_OK) == 0) {
vec--; /* back it up to stuff shell in */
@@ -251,6 +305,10 @@ main(int argc, char *argv[], char *envp[])
int start_of_client_args, start_of_server_args;
struct sigaction sa;
+#ifdef __APPLE__
+ set_x11_path();
+#endif
+
#ifdef __UNIXOS2__
envsave = envp; /* circumvent an EMX problem */