Xquartz: xpbproxy: Split out app-specific stuff to app-main.m in prep for making this into a thread.
(cherry picked from commit c2012138a520560f8a2160518ea73fced410c3b7)
This commit is contained in:
		
							parent
							
								
									5446adebfb
								
							
						
					
					
						commit
						b7ad86ff8a
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,4 +102,7 @@ struct atom_list {
 | 
			
		|||
- (void) copy_completed:(Atom)selection;
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
/* main.m */
 | 
			
		||||
extern x_selection *_selection_object;
 | 
			
		||||
 | 
			
		||||
#endif /* X_SELECTION_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue