summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-09-27 15:30:10 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-10-03 11:12:57 -0700
commitb7ad86ff8a9115147c0cf02af9e80ec464129392 (patch)
tree1b8730b9577ed248fa63e9543a20adf5f4bd5a2f
parent5446adebfb085dd05471729bf5c55bf820b1cbe3 (diff)
Xquartz: xpbproxy: Split out app-specific stuff to app-main.m in prep for making this into a thread.
(cherry picked from commit c2012138a520560f8a2160518ea73fced410c3b7)
-rw-r--r--hw/xquartz/pbproxy/Makefile.am3
-rw-r--r--hw/xquartz/pbproxy/app-main.m52
-rw-r--r--hw/xquartz/pbproxy/main.m56
-rw-r--r--hw/xquartz/pbproxy/pbproxy.h1
-rw-r--r--hw/xquartz/pbproxy/x-selection.h3
5 files changed, 65 insertions, 50 deletions
diff --git a/hw/xquartz/pbproxy/Makefile.am b/hw/xquartz/pbproxy/Makefile.am
index b316b8741..43f738600 100644
--- a/hw/xquartz/pbproxy/Makefile.am
+++ b/hw/xquartz/pbproxy/Makefile.am
@@ -3,6 +3,7 @@ AM_LDFLAGS=-L/usr/X11/lib -lX11 -lAppleWM -framework AppKit -framework Foundatio
SOURCE_FILES = \
trick_autotools.c \
+ main.m \
x-input.m \
x-selection.m
@@ -12,7 +13,7 @@ libxpbproxy_la_SOURCES = $(SOURCE_FILES)
if !INTEGRATED_XPBPROXY
bin_PROGRAMS = xpbproxy
-xpbproxy_SOURCES = main.m
+xpbproxy_SOURCES = app-main.m
xpbproxy_LDADD = $(top_builddir)/hw/xquartz/pbproxy/libxpbproxy.la
endif
diff --git a/hw/xquartz/pbproxy/app-main.m b/hw/xquartz/pbproxy/app-main.m
new file mode 100644
index 000000000..b7178511e
--- /dev/null
+++ b/hw/xquartz/pbproxy/app-main.m
@@ -0,0 +1,52 @@
+/* main.m
+ $Id: main.m,v 1.29 2007-04-07 20:39:03 jharper Exp $
+
+ Copyright (c) 2002 Apple Computer, Inc. All rights reserved. */
+
+#include "pbproxy.h"
+#import "x-selection.h"
+
+#include <pthread.h>
+#include <unistd.h> /*for getpid*/
+
+#include <X11/extensions/applewm.h>
+
+/* X11 code */
+static void x_shutdown (void) {
+ /*gstaplin: signal_handler() calls this, and I don't think these are async-signal safe. */
+ /*TODO use a socketpair() to trigger a cleanup. This is totally unsafe according to Jordan. It's a segfault waiting to happen on a signal*/
+
+ [_selection_object release];
+ _selection_object = nil;
+
+ XCloseDisplay (x_dpy);
+ x_dpy = NULL;
+ exit(0);
+}
+
+/* Startup */
+static void signal_handler (int sig) {
+ x_shutdown ();
+}
+
+int main (int argc, const char *argv[]) {
+ printf("pid: %u\n", getpid());
+
+ x_init ();
+
+ signal (SIGINT, signal_handler);
+ signal (SIGTERM, signal_handler);
+ signal (SIGPIPE, SIG_IGN);
+
+ while (1) {
+ NS_DURING
+ CFRunLoopRun ();
+ NS_HANDLER
+ NSString *s = [NSString stringWithFormat:@"%@ - %@",
+ [localException name], [localException reason]];
+ fprintf(stderr, "quartz-wm: caught exception: %s\n", [s UTF8String]);
+ NS_ENDHANDLER
+ }
+
+ return 0;
+}
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index 32b325f84..64b1b3201 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -20,11 +20,9 @@ static Bool x_grab_synced;
static BOOL _is_active = YES; /* FIXME: should query server */
/*gstaplin: why? Is there a race?*/
-static x_selection *_selection_object;
+x_selection *_selection_object;
/* X11 code */
-static void x_error_shutdown(void);
-
void x_grab_server (Bool sync) {
if (x_grab_count++ == 0) {
XGrabServer (x_dpy);
@@ -48,8 +46,11 @@ static int x_io_error_handler (Display *dpy) {
/* We lost our connection to the server. */
TRACE ();
-
- x_error_shutdown ();
+
+ /* TODO: tirgger the thread to restart? */
+#ifndef INTEGRATED_XPBPROXY
+ exit(1);
+#endif
return 0;
}
@@ -58,7 +59,7 @@ static int x_error_handler (Display *dpy, XErrorEvent *errevent) {
return 0;
}
-static void x_init (void) {
+void x_init (void) {
x_dpy = XOpenDisplay (NULL);
if (x_dpy == NULL) {
fprintf (stderr, "can't open default display\n");
@@ -86,22 +87,6 @@ static void x_init (void) {
[_selection_object claim_clipboard];
}
-static void x_shutdown (void) {
- /*gstaplin: signal_handler() calls this, and I don't think these are async-signal safe. */
- /*TODO use a socketpair() to trigger a cleanup. This is totally unsafe according to Jordan. It's a segfault waiting to happen on a signal*/
-
- [_selection_object release];
- _selection_object = nil;
-
- XCloseDisplay (x_dpy);
- x_dpy = NULL;
- exit(0);
-}
-
-static void x_error_shutdown (void) {
- exit(1);
-}
-
id x_selection_object (void) {
return _selection_object;
}
@@ -124,33 +109,6 @@ void x_set_is_active (BOOL state) {
_is_active = state;
}
-/* Startup */
-static void signal_handler (int sig) {
- x_shutdown ();
-}
-
-int main (int argc, const char *argv[]) {
- printf("pid: %u\n", getpid());
-
- x_init ();
-
- signal (SIGINT, signal_handler);
- signal (SIGTERM, signal_handler);
- signal (SIGPIPE, SIG_IGN);
-
- while (1) {
- NS_DURING
- CFRunLoopRun ();
- NS_HANDLER
- NSString *s = [NSString stringWithFormat:@"%@ - %@",
- [localException name], [localException reason]];
- fprintf(stderr, "quartz-wm: caught exception: %s\n", [s UTF8String]);
- NS_ENDHANDLER
- }
-
- return 0;
-}
-
void debug_printf (const char *fmt, ...) {
static int spew = -1;
diff --git a/hw/xquartz/pbproxy/pbproxy.h b/hw/xquartz/pbproxy/pbproxy.h
index b8fbccbdf..bd5f65b4f 100644
--- a/hw/xquartz/pbproxy/pbproxy.h
+++ b/hw/xquartz/pbproxy/pbproxy.h
@@ -19,6 +19,7 @@ extern void x_set_is_active (BOOL state);
extern BOOL x_get_is_active (void);
extern id x_selection_object (void);
extern Time x_current_timestamp (void);
+extern void x_init (void);
extern Display *x_dpy;
extern int x_apple_wm_event_base, x_apple_wm_error_base;
diff --git a/hw/xquartz/pbproxy/x-selection.h b/hw/xquartz/pbproxy/x-selection.h
index 1bb1f10f0..f96d6d43b 100644
--- a/hw/xquartz/pbproxy/x-selection.h
+++ b/hw/xquartz/pbproxy/x-selection.h
@@ -102,4 +102,7 @@ struct atom_list {
- (void) copy_completed:(Atom)selection;
@end
+/* main.m */
+extern x_selection *_selection_object;
+
#endif /* X_SELECTION_H */