summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorGeorge Peter Staplin <gps@Georges-Workstation.local>2008-09-20 17:49:16 -0600
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-09-21 17:40:42 -0700
commit852a0b0dde34e7179394d96d09122b99bf7fe904 (patch)
treefd783a549aa47d755d7401c1e1ec01e24300994e /hw
parent7fa6fc5ad0b12bc52a1c22906709fbb003782d11 (diff)
XQuartz: pbproxy: Add an X error handler that returns 0.
Move the struct atom_list into the x-selection class, so that it's no longer a global variable named atoms. This may ease pthread integration and reduce the chances of symbols conflicting. (cherry picked from commit c1403c713ca80104ae3736bd2ed1eb6ffa5192b6)
Diffstat (limited to 'hw')
-rw-r--r--hw/xquartz/pbproxy/main.m24
-rw-r--r--hw/xquartz/pbproxy/pbproxy.h8
-rw-r--r--hw/xquartz/pbproxy/x-selection.h9
-rw-r--r--hw/xquartz/pbproxy/x-selection.m167
4 files changed, 106 insertions, 102 deletions
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index 7577f7a99..6d4907056 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -14,9 +14,6 @@
Display *x_dpy;
int x_apple_wm_event_base, x_apple_wm_error_base;
-struct atom_list atom_list_inst;
-struct atom_list *atoms = &atom_list_inst;
-
static int x_grab_count;
static Bool x_grab_synced;
@@ -57,6 +54,10 @@ static int x_io_error_handler (Display *dpy) {
return 0;
}
+static int x_error_handler (Display *dpy, XErrorEvent *errevent) {
+ return 0;
+}
+
static void x_init (void) {
x_dpy = XOpenDisplay (NULL);
if (x_dpy == NULL) {
@@ -65,21 +66,8 @@ static void x_init (void) {
}
XSetIOErrorHandler (x_io_error_handler);
- atoms->primary = XInternAtom (x_dpy, "PRIMARY", False);
- atoms->clipboard = XInternAtom (x_dpy, "CLIPBOARD", False);
- atoms->text = XInternAtom (x_dpy, "TEXT", False);
- atoms->utf8_string = XInternAtom (x_dpy, "UTF8_STRING", False);
- atoms->targets = XInternAtom (x_dpy, "TARGETS", False);
- atoms->multiple = XInternAtom (x_dpy, "MULTIPLE", False);
- atoms->cstring = XInternAtom (x_dpy, "CSTRING", False);
- atoms->image_png = XInternAtom (x_dpy, "image/png", False);
- atoms->image_jpeg = XInternAtom (x_dpy, "image/jpeg", False);
- atoms->incr = XInternAtom (x_dpy, "INCR", False);
- atoms->atom = XInternAtom (x_dpy, "ATOM", False);
- atoms->clipboard_manager = XInternAtom (x_dpy, "CLIPBOARD_MANAGER", False);
- atoms->compound_text = XInternAtom (x_dpy, "COMPOUND_TEXT", False);
- atoms->atom_pair = XInternAtom (x_dpy, "ATOM_PAIR", False);
-
+ 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");
diff --git a/hw/xquartz/pbproxy/pbproxy.h b/hw/xquartz/pbproxy/pbproxy.h
index 098e309bc..56111f9be 100644
--- a/hw/xquartz/pbproxy/pbproxy.h
+++ b/hw/xquartz/pbproxy/pbproxy.h
@@ -23,14 +23,6 @@ extern Time x_current_timestamp (void);
extern Display *x_dpy;
extern int x_apple_wm_event_base, x_apple_wm_error_base;
-struct atom_list {
- Atom primary, clipboard, text, utf8_string, string, targets, multiple,
- cstring, image_png, image_jpeg, incr, atom, clipboard_manager,
- compound_text, atom_pair;
-};
-
-extern struct atom_list *atoms;
-
/* from x-input.m */
extern void x_input_register (void);
extern void x_input_run (void);
diff --git a/hw/xquartz/pbproxy/x-selection.h b/hw/xquartz/pbproxy/x-selection.h
index 5e2339831..06910b49b 100644
--- a/hw/xquartz/pbproxy/x-selection.h
+++ b/hw/xquartz/pbproxy/x-selection.h
@@ -40,6 +40,13 @@ struct propdata {
size_t length;
};
+struct atom_list {
+ Atom primary, clipboard, text, utf8_string, string, targets, multiple,
+ cstring, image_png, image_jpeg, incr, atom, clipboard_manager,
+ compound_text, atom_pair;
+};
+
+
@interface x_selection : NSObject
{
@private
@@ -79,6 +86,8 @@ struct propdata {
* CLIPBOARD. It also prevents a race with INCR transfers.
*/
int pending_clipboard;
+
+ struct atom_list atoms[1];
}
- (void) x_active:(Time)timestamp;
diff --git a/hw/xquartz/pbproxy/x-selection.m b/hw/xquartz/pbproxy/x-selection.m
index 2f35fcd1c..350b34798 100644
--- a/hw/xquartz/pbproxy/x-selection.m
+++ b/hw/xquartz/pbproxy/x-selection.m
@@ -85,80 +85,6 @@ free_propdata (struct propdata *pdata)
*pdata = null_propdata;
}
-/* Return True if this is an INCR-style transfer. */
-static Bool
-is_incr_type (XSelectionEvent *e)
-{
- Atom seltype;
- int format;
- unsigned long numitems = 0UL, bytesleft = 0UL;
- unsigned char *chunk;
-
- TRACE ();
-
- if (Success != XGetWindowProperty (x_dpy, e->requestor, e->property,
- /*offset*/ 0L, /*length*/ 4UL,
- /*Delete*/ False,
- AnyPropertyType, &seltype, &format,
- &numitems, &bytesleft, &chunk))
- {
- return False;
- }
-
- if(chunk)
- XFree(chunk);
-
- return (seltype == atoms->incr) ? True : False;
-}
-
-/* This finds the preferred type from a TARGETS list.*/
-static Atom
-find_preferred (struct propdata *pdata)
-{
- Atom a = None;
- size_t i;
- Bool png = False, utf8 = False, string = False;
-
- TRACE ();
-
- if (pdata->length % sizeof (a))
- {
- fprintf(stderr, "Atom list is not a multiple of the size of an atom!\n");
- return None;
- }
-
- for (i = 0; i < pdata->length; i += sizeof (a))
- {
- memcpy (&a, pdata->data + i, sizeof (a));
-
- if (a == atoms->image_png)
- {
- png = True;
- }
- else if (a == atoms->utf8_string)
- {
- utf8 = True;
- }
- else if (a == atoms->string)
- {
- string = True;
- }
- }
-
- /*We prefer PNG over strings, and UTF8 over a Latin-1 string.*/
- if (png)
- return atoms->image_png;
-
- if (utf8)
- return atoms->utf8_string;
-
- if (string)
- return atoms->string;
-
- /* This is evidently something we don't know how to handle.*/
- return None;
-}
-
/*
* Return True if an error occurs. Return False if pdata has data
* and we finished.
@@ -268,6 +194,80 @@ read_prop_32 (Window id, Atom prop, int *nitems_ret)
return (unsigned long *) data;
}
+/* Implementation methods */
+
+/* This finds the preferred type from a TARGETS list.*/
+- (Atom) find_preferred:(struct propdata *)pdata
+{
+ Atom a = None;
+ size_t i;
+ Bool png = False, utf8 = False, string = False;
+
+ TRACE ();
+
+ if (pdata->length % sizeof (a))
+ {
+ fprintf(stderr, "Atom list is not a multiple of the size of an atom!\n");
+ return None;
+ }
+
+ for (i = 0; i < pdata->length; i += sizeof (a))
+ {
+ memcpy (&a, pdata->data + i, sizeof (a));
+
+ if (a == atoms->image_png)
+ {
+ png = True;
+ }
+ else if (a == atoms->utf8_string)
+ {
+ utf8 = True;
+ }
+ else if (a == atoms->string)
+ {
+ string = True;
+ }
+ }
+
+ /*We prefer PNG over strings, and UTF8 over a Latin-1 string.*/
+ if (png)
+ return atoms->image_png;
+
+ if (utf8)
+ return atoms->utf8_string;
+
+ if (string)
+ return atoms->string;
+
+ /* This is evidently something we don't know how to handle.*/
+ return None;
+}
+
+/* Return True if this is an INCR-style transfer. */
+- (Bool) is_incr_type:(XSelectionEvent *)e
+{
+ Atom seltype;
+ int format;
+ unsigned long numitems = 0UL, bytesleft = 0UL;
+ unsigned char *chunk;
+
+ TRACE ();
+
+ if (Success != XGetWindowProperty (x_dpy, e->requestor, e->property,
+ /*offset*/ 0L, /*length*/ 4UL,
+ /*Delete*/ False,
+ AnyPropertyType, &seltype, &format,
+ &numitems, &bytesleft, &chunk))
+ {
+ return False;
+ }
+
+ if(chunk)
+ XFree(chunk);
+
+ return (seltype == atoms->incr) ? True : False;
+}
+
/*
* This should be called after a selection has been copied,
* or when the selection is unfinished before a transfer completes.
@@ -870,7 +870,7 @@ read_prop_32 (Window id, Atom prop, int *nitems_ret)
DB ("e->selection %s\n", XGetAtomName (x_dpy, e->selection));
DB ("e->property %s\n", XGetAtomName (x_dpy, e->property));
- if (is_incr_type (e))
+ if ([self is_incr_type:e])
{
/*
* This is an INCR-style transfer, which means that we
@@ -956,7 +956,7 @@ read_prop_32 (Window id, Atom prop, int *nitems_ret)
TRACE ();
- preferred = find_preferred (pdata);
+ preferred = [self find_preferred:pdata];
if (None == preferred)
{
@@ -1195,6 +1195,21 @@ read_prop_32 (Window id, Atom prop, int *nitems_ret)
if (self == nil)
return nil;
+ atoms->primary = XInternAtom (x_dpy, "PRIMARY", False);
+ atoms->clipboard = XInternAtom (x_dpy, "CLIPBOARD", False);
+ atoms->text = XInternAtom (x_dpy, "TEXT", False);
+ atoms->utf8_string = XInternAtom (x_dpy, "UTF8_STRING", False);
+ atoms->targets = XInternAtom (x_dpy, "TARGETS", False);
+ atoms->multiple = XInternAtom (x_dpy, "MULTIPLE", False);
+ atoms->cstring = XInternAtom (x_dpy, "CSTRING", False);
+ atoms->image_png = XInternAtom (x_dpy, "image/png", False);
+ atoms->image_jpeg = XInternAtom (x_dpy, "image/jpeg", False);
+ atoms->incr = XInternAtom (x_dpy, "INCR", False);
+ atoms->atom = XInternAtom (x_dpy, "ATOM", False);
+ atoms->clipboard_manager = XInternAtom (x_dpy, "CLIPBOARD_MANAGER", False);
+ atoms->compound_text = XInternAtom (x_dpy, "COMPOUND_TEXT", False);
+ atoms->atom_pair = XInternAtom (x_dpy, "ATOM_PAIR", False);
+
_pasteboard = [[NSPasteboard generalPasteboard] retain];
_known_types = [[NSArray arrayWithObject:NSStringPboardType] retain];