summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Staplin <gps@Georges-Workstation.local>2008-09-30 23:53:12 -0600
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-10-03 11:14:49 -0700
commit7bb73a9513710feaebc127998950e9f472bfcc0d (patch)
tree923934f69b010a3d791b5737a4f260014e3a3519
parent2a5ce41f0371ad5df52586b8d4072578b6206321 (diff)
XQuartz: pbproxy: Possibly fix a memory leak by using an [NSApp run] loop,
instead of calling CFRunLoopRun() directly. The leak wasn't reproducible on this machine, but someone was able to produce a leak trace with Instruments that indicates it was leaking in the CFRunLoopRun() path. x-input.m: dequeue and ignore events when pbproxy_active is false. x-selection.h: add an is_active method that is used by x-input.m to ignore events. x-selection.m: Handle nearly every preference, except for primary_on_grab, which I don't really understand yet. (cherry picked from commit 4d51ad851e64da83cbdfb0a4a22428418a7bcf75)
-rw-r--r--hw/xquartz/pbproxy/app-main.m14
-rw-r--r--hw/xquartz/pbproxy/x-input.m6
-rw-r--r--hw/xquartz/pbproxy/x-selection.h3
-rw-r--r--hw/xquartz/pbproxy/x-selection.m28
4 files changed, 35 insertions, 16 deletions
diff --git a/hw/xquartz/pbproxy/app-main.m b/hw/xquartz/pbproxy/app-main.m
index 0f2eaf028..7611eefea 100644
--- a/hw/xquartz/pbproxy/app-main.m
+++ b/hw/xquartz/pbproxy/app-main.m
@@ -8,6 +8,7 @@
#include <pthread.h>
#include <unistd.h> /*for getpid*/
+#include <Cocoa/Cocoa.h>
static void signal_handler (int sig) {
_exit(0);
@@ -21,16 +22,9 @@ int main (int argc, const char *argv[]) {
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
- }
+
+ [NSApplication sharedApplication];
+ [NSApp run];
return 0;
}
diff --git a/hw/xquartz/pbproxy/x-input.m b/hw/xquartz/pbproxy/x-input.m
index c5e2b631f..c11ffb382 100644
--- a/hw/xquartz/pbproxy/x-input.m
+++ b/hw/xquartz/pbproxy/x-input.m
@@ -62,7 +62,11 @@ void x_input_run (void) {
XEvent e;
XNextEvent (x_dpy, &e);
-
+
+ /* If pbproxy isn't active (in the preferences), then don't do anything. */
+ if (![x_selection_object() is_active])
+ continue;
+
switch (e.type) {
case SelectionClear:
[x_selection_object () clear_event:&e.xselectionclear];
diff --git a/hw/xquartz/pbproxy/x-selection.h b/hw/xquartz/pbproxy/x-selection.h
index e6535044a..9c408b4ec 100644
--- a/hw/xquartz/pbproxy/x-selection.h
+++ b/hw/xquartz/pbproxy/x-selection.h
@@ -1,7 +1,7 @@
/* x-selection.h -- proxies between NSPasteboard and X11 selections
$Id: x-selection.h,v 1.2 2002-12-13 00:21:00 jharper Exp $
- Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ Copyright (c) 2002, 2008 Apple Computer, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
@@ -102,6 +102,7 @@ struct atom_list {
- (void) copy_completed:(Atom)selection;
- (void) reload_preferences;
+- (BOOL) is_active;
@end
/* main.m */
diff --git a/hw/xquartz/pbproxy/x-selection.m b/hw/xquartz/pbproxy/x-selection.m
index 37b80f886..0997b3a22 100644
--- a/hw/xquartz/pbproxy/x-selection.m
+++ b/hw/xquartz/pbproxy/x-selection.m
@@ -324,8 +324,16 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
DB ("changed pasteboard!\n");
changeCount = countNow;
- XSetSelectionOwner (x_dpy, atoms->primary, _selection_window, CurrentTime);
- [self own_clipboard];
+ if (pbproxy_pasteboard_to_primary)
+ {
+
+ XSetSelectionOwner (x_dpy, atoms->primary, _selection_window, CurrentTime);
+ }
+
+ if (pbproxy_pasteboard_to_clipboard)
+ {
+ [self own_clipboard];
+ }
}
#if 0
@@ -449,7 +457,7 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
TRACE ();
- if (NO == pbproxy_clipboard_to_pasteboard)
+ if (!pbproxy_clipboard_to_pasteboard)
return;
owner = XGetSelectionOwner (x_dpy, atoms->clipboard);
@@ -462,6 +470,11 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
DB ("No clipboard owner.\n");
[self copy_completed:atoms->clipboard];
return;
+ }
+ else if (owner == _selection_window)
+ {
+ [self copy_completed:atoms->clipboard];
+ return;
}
DB ("requesting targets\n");
@@ -1223,9 +1236,16 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
- (void) reload_preferences
{
-
+ if (pbproxy_clipboard_to_pasteboard)
+ {
+ [self claim_clipboard];
+ }
}
+- (BOOL) is_active
+{
+ return pbproxy_active;
+}
/* NSPasteboard-required methods */