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.
This commit is contained in:
George Peter Staplin 2008-09-30 23:53:12 -06:00
parent 00ca0f4d83
commit 4d51ad851e
4 changed files with 35 additions and 16 deletions

View File

@ -8,6 +8,7 @@
#include <pthread.h>
#include <unistd.h> /*for getpid*/
#include <Cocoa/Cocoa.h>
static void signal_handler (int sig) {
_exit(0);
@ -22,15 +23,8 @@ int main (int argc, const char *argv[]) {
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;
}

View File

@ -63,6 +63,10 @@ void x_input_run (void) {
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];

View File

@ -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 */

View File

@ -324,9 +324,17 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
DB ("changed pasteboard!\n");
changeCount = countNow;
if (pbproxy_pasteboard_to_primary)
{
XSetSelectionOwner (x_dpy, atoms->primary, _selection_window, CurrentTime);
}
if (pbproxy_pasteboard_to_clipboard)
{
[self own_clipboard];
}
}
#if 0
/*gstaplin: we should perhaps investigate something like this branch above...*/
@ -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);
@ -463,6 +471,11 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
[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 */