1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* main.m
$Id: main.m,v 1.29 2007-04-07 20:39:03 jharper Exp $
Copyright (c) 2002, 2008 Apple Computer, Inc. All rights reserved. */
#include "pbproxy.h"
#import "x-selection.h"
#include <pthread.h>
#include <X11/extensions/applewm.h>
Display *x_dpy;
int x_apple_wm_event_base, x_apple_wm_error_base;
int x_xfixes_event_base, x_xfixes_error_base;
BOOL have_xfixes;
x_selection *_selection_object;
static int x_io_error_handler (Display *dpy) {
/* We lost our connection to the server. */
TRACE ();
/* TODO: trigger the thread to restart? */
#ifndef INTEGRATED_XPBPROXY
exit(1);
#endif
return 0;
}
static int x_error_handler (Display *dpy, XErrorEvent *errevent) {
return 0;
}
BOOL x_init (void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
x_dpy = XOpenDisplay (NULL);
if (x_dpy == NULL) {
fprintf (stderr, "can't open default display\n");
return FALSE;
}
XSetIOErrorHandler (x_io_error_handler);
XSetErrorHandler (x_error_handler);
if (!XAppleWMQueryExtension (x_dpy, &x_apple_wm_event_base,
&x_apple_wm_error_base)) {
fprintf (stderr, "can't open AppleWM server extension\n");
return FALSE;
}
have_xfixes = XFixesQueryExtension(x_dpy, &x_xfixes_event_base, &x_xfixes_error_base);
XAppleWMSelectInput (x_dpy, AppleWMActivationNotifyMask |
AppleWMPasteboardNotifyMask);
_selection_object = [[x_selection alloc] init];
if(!x_input_register())
return FALSE;
x_input_run();
[pool release];
return TRUE;
}
id x_selection_object (void) {
return _selection_object;
}
Time x_current_timestamp (void) {
/* FIXME: may want to fetch a timestamp from the server.. */
return CurrentTime;
}
void debug_printf (const char *fmt, ...) {
static int spew = -1;
if (spew == -1) {
char *x = getenv ("DEBUG");
spew = (x != NULL && atoi (x) != 0);
}
if (spew) {
va_list args;
va_start(args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
}
|