xserver: Branch 'xorg-server-1.4-apple'

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Sat Sep 27 15:30:15 PDT 2008


 hw/xquartz/pbproxy/Makefile.am   |    3 +-
 hw/xquartz/pbproxy/app-main.m    |   52 ++++++++++++++++++++++++++++++++++++
 hw/xquartz/pbproxy/main.m        |   56 ++++-----------------------------------
 hw/xquartz/pbproxy/pbproxy.h     |    1 
 hw/xquartz/pbproxy/x-selection.h |    3 ++
 5 files changed, 65 insertions(+), 50 deletions(-)

New commits:
commit c2012138a520560f8a2160518ea73fced410c3b7
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat Sep 27 15:30:10 2008 -0700

    Xquartz: xpbproxy: Split out app-specific stuff to app-main.m in prep for making this into a thread.

diff --git a/hw/xquartz/pbproxy/Makefile.am b/hw/xquartz/pbproxy/Makefile.am
index b316b87..43f7386 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 0000000..b717851
--- /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 32b325f..64b1b32 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 b8fbccb..bd5f65b 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 1bb1f10..f96d6d4 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 */


More information about the xorg-commit mailing list