XQuartz: pbproxy: SIGHUP reloads preferences.

(cherry picked from commit cbc0935ef74ebd76ed3db16d6ab86043eeed42a3)
This commit is contained in:
Jeremy Huddleston 2008-10-21 11:19:06 -07:00
parent 0b69526217
commit 2d764e21f2
5 changed files with 41 additions and 20 deletions

View File

@ -10,8 +10,16 @@
#include <unistd.h> /*for getpid*/ #include <unistd.h> /*for getpid*/
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
BOOL prefs_reload = NO;
static void signal_handler (int sig) { static void signal_handler (int sig) {
_exit(0); switch(sig) {
case SIGHUP:
prefs_reload = YES;
break;
default:
_exit(EXIT_SUCCESS);
}
} }
int main (int argc, const char *argv[]) { int main (int argc, const char *argv[]) {
@ -19,15 +27,16 @@ int main (int argc, const char *argv[]) {
printf("pid: %u\n", getpid()); printf("pid: %u\n", getpid());
#endif #endif
if(x_init () !=0) if(!x_init())
return 1; return EXIT_FAILURE;
signal (SIGINT, signal_handler); signal (SIGINT, signal_handler);
signal (SIGTERM, signal_handler); signal (SIGTERM, signal_handler);
signal (SIGHUP, signal_handler);
signal (SIGPIPE, SIG_IGN); signal (SIGPIPE, SIG_IGN);
[NSApplication sharedApplication]; [NSApplication sharedApplication];
[NSApp run]; [NSApp run];
return 0; return EXIT_SUCCESS;
} }

View File

@ -34,13 +34,13 @@ static int x_error_handler (Display *dpy, XErrorEvent *errevent) {
return 0; return 0;
} }
int x_init (void) { BOOL x_init (void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
x_dpy = XOpenDisplay (NULL); x_dpy = XOpenDisplay (NULL);
if (x_dpy == NULL) { if (x_dpy == NULL) {
fprintf (stderr, "can't open default display\n"); fprintf (stderr, "can't open default display\n");
return 1; return FALSE;
} }
XSetIOErrorHandler (x_io_error_handler); XSetIOErrorHandler (x_io_error_handler);
@ -49,7 +49,7 @@ int x_init (void) {
if (!XAppleWMQueryExtension (x_dpy, &x_apple_wm_event_base, if (!XAppleWMQueryExtension (x_dpy, &x_apple_wm_event_base,
&x_apple_wm_error_base)) { &x_apple_wm_error_base)) {
fprintf (stderr, "can't open AppleWM server extension\n"); fprintf (stderr, "can't open AppleWM server extension\n");
return 1; return FALSE;
} }
have_xfixes = XFixesQueryExtension(x_dpy, &x_xfixes_event_base, &x_xfixes_error_base); have_xfixes = XFixesQueryExtension(x_dpy, &x_xfixes_event_base, &x_xfixes_error_base);
@ -59,12 +59,13 @@ int x_init (void) {
_selection_object = [[x_selection alloc] init]; _selection_object = [[x_selection alloc] init];
x_input_register (); if(!x_input_register())
x_input_run (); return FALSE;
x_input_run();
[pool release]; [pool release];
return 0; return TRUE;
} }
id x_selection_object (void) { id x_selection_object (void) {

View File

@ -16,12 +16,16 @@
#define DEBUG 0 #define DEBUG 0
#endif #endif
#ifndef INTEGRATED_XPBPROXY
extern BOOL prefs_reload;
#endif
/* from main.m */ /* from main.m */
extern void x_set_is_active (BOOL state); extern void x_set_is_active (BOOL state);
extern BOOL x_get_is_active (void); extern BOOL x_get_is_active (void);
extern id x_selection_object (void); extern id x_selection_object (void);
extern Time x_current_timestamp (void); extern Time x_current_timestamp (void);
extern int x_init (void); extern BOOL x_init (void);
extern Display *x_dpy; extern Display *x_dpy;
extern int x_apple_wm_event_base, x_apple_wm_error_base; extern int x_apple_wm_event_base, x_apple_wm_error_base;
@ -29,7 +33,7 @@ extern int x_xfixes_event_base, x_xfixes_error_base;
extern BOOL have_xfixes; extern BOOL have_xfixes;
/* from x-input.m */ /* from x-input.m */
extern void x_input_register (void); extern BOOL x_input_register (void);
extern void x_input_run (void); extern void x_input_run (void);
#if DEBUG == 0 #if DEBUG == 0

View File

@ -102,7 +102,7 @@ void x_input_run (void) {
[pool release]; [pool release];
} }
static int add_input_socket (int sock, CFOptionFlags callback_types, static BOOL add_input_socket (int sock, CFOptionFlags callback_types,
CFSocketCallBack callback, const CFSocketContext *ctx, CFSocketCallBack callback, const CFSocketContext *ctx,
CFRunLoopSourceRef *cf_source) { CFRunLoopSourceRef *cf_source) {
CFSocketRef cf_sock; CFSocketRef cf_sock;
@ -128,12 +128,18 @@ static int add_input_socket (int sock, CFOptionFlags callback_types,
static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type, static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type,
CFDataRef address, const void *data, void *info) { CFDataRef address, const void *data, void *info) {
x_input_run ();
#ifndef INTEGRATED_XPBPROXY
if(prefs_reload) {
[x_selection_object() reload_preferences];
prefs_reload = NO;
}
#endif
x_input_run();
} }
void x_input_register(void) { BOOL x_input_register(void) {
if (!add_input_socket (ConnectionNumber (x_dpy), kCFSocketReadCallBack, return add_input_socket(ConnectionNumber(x_dpy), kCFSocketReadCallBack,
x_input_callback, NULL, &x_dpy_source)) { x_input_callback, NULL, &x_dpy_source);
exit (1);
}
} }

View File

@ -78,6 +78,7 @@ static struct {
static struct propdata null_propdata = {NULL, 0}; static struct propdata null_propdata = {NULL, 0};
#ifdef DEBUG
static void static void
dump_prefs (FILE *fp) { dump_prefs (FILE *fp) {
fprintf(fp, fprintf(fp,
@ -93,7 +94,7 @@ dump_prefs (FILE *fp) {
pbproxy_prefs.pasteboard_to_primary, pbproxy_prefs.pasteboard_to_primary,
pbproxy_prefs.pasteboard_to_clipboard); pbproxy_prefs.pasteboard_to_clipboard);
} }
#endif
#define APP_PREFS "org.x.X11" #define APP_PREFS "org.x.X11"
static BOOL static BOOL