mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 11:10:47 +00:00
Update pasteboard server.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13071 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0148789b5a
commit
04a4bf656f
2 changed files with 197 additions and 147 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
* Source/NSPasteboard.m: Start gpbs for other server automatically.
|
* Source/NSPasteboard.m: Start gpbs for other server automatically.
|
||||||
Improve log messages.
|
Improve log messages.
|
||||||
|
* Tools/gpbs.m copied in fron gpbs.
|
||||||
|
|
||||||
2002-03-09 Richard Frith-Macdonald <rfm@gnu.org>
|
2002-03-09 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
343
Tools/gpbs.m
343
Tools/gpbs.m
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
gpbs.m
|
gpbs.m
|
||||||
|
|
||||||
GNUstep pasteboard server
|
GNUstep pasteboard server
|
||||||
|
@ -7,47 +7,35 @@
|
||||||
|
|
||||||
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
Date: August 1997
|
Date: August 1997
|
||||||
|
|
||||||
This file is part of the GNUstep Project
|
This file is part of the GNUstep Project
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public
|
You should have received a copy of the GNU General Public
|
||||||
License along with this library; see the file COPYING.LIB.
|
License along with this library; see the file COPYING.LIB.
|
||||||
If not, write to the Free Software Foundation,
|
If not, write to the Free Software Foundation,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gnustep/gui/config.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <Foundation/NSString.h>
|
|
||||||
#include <Foundation/NSData.h>
|
|
||||||
#include <Foundation/NSNotification.h>
|
|
||||||
#include <Foundation/NSConnection.h>
|
|
||||||
#include <Foundation/NSDistantObject.h>
|
|
||||||
#include <Foundation/NSArray.h>
|
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
|
||||||
#include <Foundation/NSDate.h>
|
|
||||||
#include <Foundation/NSDictionary.h>
|
|
||||||
#include <Foundation/NSException.h>
|
|
||||||
#include <Foundation/NSRunLoop.h>
|
|
||||||
#include <Foundation/NSTimer.h>
|
|
||||||
#include <Foundation/NSValue.h>
|
|
||||||
#include <Foundation/NSException.h>
|
|
||||||
#include <Foundation/NSLock.h>
|
|
||||||
#include <Foundation/NSObjCRuntime.h>
|
|
||||||
#include <AppKit/NSPasteboard.h>
|
#include <AppKit/NSPasteboard.h>
|
||||||
|
#include <AppKit/GSPasteboardServer.h>
|
||||||
#include <gnustep/gui/GSPasteboardServer.h>
|
|
||||||
|
|
||||||
#include "wgetopt.h"
|
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
@class PasteboardServer;
|
@class PasteboardServer;
|
||||||
|
@class PasteboardObject;
|
||||||
|
|
||||||
|
@protocol XPb
|
||||||
|
+ (id) ownerByOsPb: (NSString*)p;
|
||||||
|
@end
|
||||||
|
static Class xPbClass;
|
||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
@ -59,15 +47,19 @@ NSConnection *conn = nil;
|
||||||
NSLock *dictionary_lock = nil;
|
NSLock *dictionary_lock = nil;
|
||||||
NSMutableDictionary *pasteboards = nil;
|
NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
|
@interface NSPasteboard (GNULocal)
|
||||||
|
+ (void) _localServer: (id<GSPasteboardSvr>)s;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface PasteboardData: NSObject
|
@interface PasteboardData: NSObject
|
||||||
{
|
{
|
||||||
NSData* data;
|
NSData *data;
|
||||||
NSString* type;
|
NSString *type;
|
||||||
id owner;
|
id owner;
|
||||||
id pboard;
|
id pboard;
|
||||||
BOOL wantsChangedOwner;
|
BOOL wantsChangedOwner;
|
||||||
BOOL hasGNUDataForType;
|
BOOL hasGNUDataForType;
|
||||||
BOOL hasStdDataForType;
|
BOOL hasStdDataForType;
|
||||||
}
|
}
|
||||||
+ (PasteboardData*) newWithType: (NSString*)aType
|
+ (PasteboardData*) newWithType: (NSString*)aType
|
||||||
owner: (id)anObject
|
owner: (id)anObject
|
||||||
|
@ -98,9 +90,9 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
if (d)
|
if (d)
|
||||||
{
|
{
|
||||||
d->type = [aType retain];
|
d->type = RETAIN(aType);
|
||||||
d->owner = [anObject retain];
|
d->owner = RETAIN(anObject);
|
||||||
d->pboard = [anotherObject retain];
|
d->pboard = RETAIN(anotherObject);
|
||||||
d->wantsChangedOwner = wants;
|
d->wantsChangedOwner = wants;
|
||||||
d->hasStdDataForType = StdData;
|
d->hasStdDataForType = StdData;
|
||||||
d->hasGNUDataForType = GNUData;
|
d->hasGNUDataForType = GNUData;
|
||||||
|
@ -117,20 +109,20 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
o = owner;
|
o = owner;
|
||||||
owner = nil;
|
owner = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
o = pboard;
|
o = pboard;
|
||||||
pboard = nil;
|
pboard = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
ourConnection = YES;
|
ourConnection = YES;
|
||||||
}
|
}
|
||||||
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c)
|
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c)
|
||||||
{
|
{
|
||||||
o = owner;
|
o = owner;
|
||||||
owner = nil;
|
owner = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
o = pboard;
|
o = pboard;
|
||||||
pboard = nil;
|
pboard = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
ourConnection = YES;
|
ourConnection = YES;
|
||||||
}
|
}
|
||||||
return ourConnection;
|
return ourConnection;
|
||||||
|
@ -138,10 +130,10 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[type release];
|
RELEASE(type);
|
||||||
[data release];
|
RELEASE(data);
|
||||||
[owner release];
|
RELEASE(owner);
|
||||||
[pboard release];
|
RELEASE(pboard);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +153,17 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
- (NSData*) newDataWithVersion: (int)version
|
- (NSData*) newDataWithVersion: (int)version
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* If the owner of this item is an X window - we can't use the data from
|
||||||
|
* the last time the selection was accessed because the X window may have
|
||||||
|
* changed it's selection without telling us - isn't X wonderful :-(
|
||||||
|
*/
|
||||||
|
if (data != nil && owner != nil
|
||||||
|
&& [owner isProxy] == NO && [owner isKindOfClass: xPbClass] == YES)
|
||||||
|
{
|
||||||
|
DESTROY(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (data == nil && (owner && pboard))
|
if (data == nil && (owner && pboard))
|
||||||
{
|
{
|
||||||
if (hasGNUDataForType)
|
if (hasGNUDataForType)
|
||||||
|
@ -194,9 +197,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
NSLog(@"set data for %x\n", (unsigned)self);
|
NSLog(@"set data for %x\n", (unsigned)self);
|
||||||
}
|
}
|
||||||
[d retain];
|
ASSIGN(data, d);
|
||||||
[data release];
|
|
||||||
data = d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) type
|
- (id) type
|
||||||
|
@ -211,18 +212,18 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface PasteboardEntry: NSObject
|
@interface PasteboardEntry: NSObject
|
||||||
{
|
{
|
||||||
int refNum;
|
int refNum;
|
||||||
BOOL hasBeenFiltered;
|
id owner;
|
||||||
id owner;
|
id pboard;
|
||||||
id pboard;
|
NSMutableArray *items;
|
||||||
NSMutableArray *items;
|
BOOL hasBeenFiltered;
|
||||||
BOOL wantsChangedOwner;
|
BOOL wantsChangedOwner;
|
||||||
BOOL hasGNUDataForType;
|
BOOL hasGNUDataForType;
|
||||||
BOOL hasStdDataForType;
|
BOOL hasStdDataForType;
|
||||||
}
|
}
|
||||||
+ (PasteboardEntry*) newWithTypes: (NSArray*)someTypes
|
+ (PasteboardEntry*) newWithTypes: (NSArray*)someTypes
|
||||||
owner: (id)anOwner
|
owner: (id)anOwner
|
||||||
|
@ -233,6 +234,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
- (BOOL) hasBeenFiltered;
|
- (BOOL) hasBeenFiltered;
|
||||||
- (PasteboardData*) itemForType: (NSString*)type;
|
- (PasteboardData*) itemForType: (NSString*)type;
|
||||||
- (void) lostOwnership;
|
- (void) lostOwnership;
|
||||||
|
- (id) owner;
|
||||||
- (int) refNum;
|
- (int) refNum;
|
||||||
- (NSArray*) types;
|
- (NSArray*) types;
|
||||||
@end
|
@end
|
||||||
|
@ -250,8 +252,8 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
e->owner = [anOwner retain];
|
e->owner = RETAIN(anOwner);
|
||||||
e->pboard = [aPboard retain];
|
e->pboard = RETAIN(aPboard);
|
||||||
|
|
||||||
if (anOwner && [anOwner respondsToSelector:
|
if (anOwner && [anOwner respondsToSelector:
|
||||||
@selector(pasteboardChangedOwner:)])
|
@selector(pasteboardChangedOwner:)])
|
||||||
|
@ -282,7 +284,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
hasStdDataForType: e->hasStdDataForType
|
hasStdDataForType: e->hasStdDataForType
|
||||||
hasGNUDataForType: e->hasGNUDataForType];
|
hasGNUDataForType: e->hasGNUDataForType];
|
||||||
[e->items addObject: d];
|
[e->items addObject: d];
|
||||||
[d release];
|
RELEASE(d);
|
||||||
}
|
}
|
||||||
e->refNum = count;
|
e->refNum = count;
|
||||||
if (verbose > 1)
|
if (verbose > 1)
|
||||||
|
@ -331,7 +333,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
hasStdDataForType: StdData
|
hasStdDataForType: StdData
|
||||||
hasGNUDataForType: GNUData];
|
hasGNUDataForType: GNUData];
|
||||||
[items addObject: d];
|
[items addObject: d];
|
||||||
[d release];
|
RELEASE(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (verbose > 1)
|
if (verbose > 1)
|
||||||
|
@ -350,10 +352,10 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
o = owner;
|
o = owner;
|
||||||
owner = nil;
|
owner = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
o = pboard;
|
o = pboard;
|
||||||
pboard = nil;
|
pboard = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
ourConnection = YES;
|
ourConnection = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,10 +363,10 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
o = owner;
|
o = owner;
|
||||||
owner = nil;
|
owner = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
o = pboard;
|
o = pboard;
|
||||||
pboard = nil;
|
pboard = nil;
|
||||||
[o release];
|
RELEASE(o);
|
||||||
ourConnection = YES;
|
ourConnection = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,9 +388,9 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[owner release];
|
RELEASE(owner);
|
||||||
[pboard release];
|
RELEASE(pboard);
|
||||||
[items release];
|
RELEASE(items);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +433,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
PasteboardData *d = [items objectAtIndex: i];
|
PasteboardData *d = [items objectAtIndex: i];
|
||||||
|
|
||||||
if ([d wantsChangedOwner] == YES && [d owner] != nil
|
if ([d wantsChangedOwner] == YES && [d owner] != nil
|
||||||
&& [a containsObject: [d owner]] == NO)
|
&& [a indexOfObjectIdenticalTo: [d owner]] == NSNotFound)
|
||||||
{
|
{
|
||||||
[a addObject: [d owner]];
|
[a addObject: [d owner]];
|
||||||
}
|
}
|
||||||
|
@ -442,19 +444,19 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
[owner pasteboardChangedOwner: pboard];
|
[owner pasteboardChangedOwner: pboard];
|
||||||
if (owner != nil)
|
if (owner != nil)
|
||||||
{
|
{
|
||||||
[a removeObject: owner];
|
[a removeObjectIdenticalTo: owner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < [items count] && [a count] > 0; i++)
|
for (i = 0; i < [items count] && [a count] > 0; i++)
|
||||||
{
|
{
|
||||||
PasteboardData *d = [items objectAtIndex:i];
|
PasteboardData *d = [items objectAtIndex: i];
|
||||||
id o = [d owner];
|
id o = [d owner];
|
||||||
|
|
||||||
if (o != nil && [a containsObject: o])
|
if (o != nil && [a containsObject: o])
|
||||||
{
|
{
|
||||||
[o pasteboardChangedOwner: [d pboard]];
|
[o pasteboardChangedOwner: [d pboard]];
|
||||||
[a removeObject: o];
|
[a removeObjectIdenticalTo: o];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,6 +468,11 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) owner
|
||||||
|
{
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
- (int) refNum
|
- (int) refNum
|
||||||
{
|
{
|
||||||
return refNum;
|
return refNum;
|
||||||
|
@ -478,7 +485,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
for (i = 0; i < [items count]; i++)
|
for (i = 0; i < [items count]; i++)
|
||||||
{
|
{
|
||||||
PasteboardData* d = [items objectAtIndex:i];
|
PasteboardData* d = [items objectAtIndex: i];
|
||||||
[t addObject: [d type]];
|
[t addObject: [d type]];
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -486,15 +493,15 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface PasteboardObject: NSObject <GSPasteboardObj>
|
@interface PasteboardObject: NSObject <GSPasteboardObj>
|
||||||
{
|
{
|
||||||
NSString *name;
|
NSString *name;
|
||||||
int nextCount;
|
int nextCount;
|
||||||
unsigned histLength;
|
unsigned histLength;
|
||||||
NSMutableArray *history;
|
NSMutableArray *history;
|
||||||
PasteboardEntry *current;
|
PasteboardEntry *current;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (PasteboardObject*) pasteboardWithName: (NSString*)name;
|
+ (PasteboardObject*) pasteboardWithName: (NSString*)name;
|
||||||
|
@ -504,12 +511,12 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
pasteboard: (id)pboard
|
pasteboard: (id)pboard
|
||||||
oldCount: (int)count;
|
oldCount: (int)count;
|
||||||
- (NSString*) availableTypeFromArray: (NSArray*)types
|
- (NSString*) availableTypeFromArray: (NSArray*)types
|
||||||
changeCount: (int*)count;
|
changeCount: (int*)count;
|
||||||
- (int) changeCount;
|
- (int) changeCount;
|
||||||
- (BOOL) checkConnection: (NSConnection*)c;
|
- (BOOL) checkConnection: (NSConnection*)c;
|
||||||
- (NSData*) dataForType: (NSString*)type
|
- (NSData*) dataForType: (NSString*)type
|
||||||
oldCount: (int)count
|
oldCount: (int)count
|
||||||
mustBeCurrent: (BOOL)flag;
|
mustBeCurrent: (BOOL)flag;
|
||||||
- (int) declareTypes: (NSArray*)types
|
- (int) declareTypes: (NSArray*)types
|
||||||
owner: (id)owner
|
owner: (id)owner
|
||||||
pasteboard: (id)pboard;
|
pasteboard: (id)pboard;
|
||||||
|
@ -529,7 +536,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
pasteboards = [[NSMutableDictionary alloc] initWithCapacity:8];
|
pasteboards = [[NSMutableDictionary alloc] initWithCapacity: 8];
|
||||||
dictionary_lock = [[NSLock alloc] init];
|
dictionary_lock = [[NSLock alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +549,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
while (aName == nil)
|
while (aName == nil)
|
||||||
{
|
{
|
||||||
aName = [NSString stringWithFormat: @"%dlocalName", number++];
|
aName = [NSString stringWithFormat: @"%dlocalName", number++];
|
||||||
if ([pasteboards objectForKey:aName] == nil)
|
if ([pasteboards objectForKey: aName] == nil)
|
||||||
{
|
{
|
||||||
break; // This name is unique.
|
break; // This name is unique.
|
||||||
}
|
}
|
||||||
|
@ -556,13 +563,13 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
if (pb == nil)
|
if (pb == nil)
|
||||||
{
|
{
|
||||||
pb = [PasteboardObject alloc];
|
pb = [PasteboardObject alloc];
|
||||||
pb->name = [aName retain];
|
pb->name = RETAIN(aName);
|
||||||
pb->nextCount = 1;
|
pb->nextCount = 1;
|
||||||
pb->histLength = 1;
|
pb->histLength = 1;
|
||||||
pb->history = [[NSMutableArray alloc] initWithCapacity:2];
|
pb->history = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||||
pb->current = nil;
|
pb->current = nil;
|
||||||
[pasteboards setObject: pb forKey: aName];
|
[pasteboards setObject: pb forKey: aName];
|
||||||
[pb autorelease];
|
AUTORELEASE(pb);
|
||||||
}
|
}
|
||||||
[dictionary_lock unlock];
|
[dictionary_lock unlock];
|
||||||
return pb;
|
return pb;
|
||||||
|
@ -573,11 +580,22 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
pasteboard: (NSPasteboard*)pb
|
pasteboard: (NSPasteboard*)pb
|
||||||
oldCount: (int)count
|
oldCount: (int)count
|
||||||
{
|
{
|
||||||
PasteboardEntry *e = [self entryByCount:count];
|
PasteboardEntry *e = [self entryByCount: count];
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
id x = [xPbClass ownerByOsPb: name];
|
||||||
|
|
||||||
[e addTypes: types owner: owner pasteboard: pb];
|
[e addTypes: types owner: owner pasteboard: pb];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there is an X pasteboard corresponding to this pasteboard, and the
|
||||||
|
* X system doesn't currently own the pasteboard, we must inform it of
|
||||||
|
* the change in the types of data supplied by this pasteboard.
|
||||||
|
* We do this by simulating a change of pasteboard ownership.
|
||||||
|
*/
|
||||||
|
if (x != owner && x != nil)
|
||||||
|
[x pasteboardChangedOwner: pb];
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -594,7 +612,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e = [self entryByCount:*count];
|
e = [self entryByCount: *count];
|
||||||
}
|
}
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
@ -603,7 +621,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
*count = [e refNum];
|
*count = [e refNum];
|
||||||
for (i = 0; i < [types count]; i++)
|
for (i = 0; i < [types count]; i++)
|
||||||
{
|
{
|
||||||
NSString* key = [types objectAtIndex:i];
|
NSString* key = [types objectAtIndex: i];
|
||||||
|
|
||||||
if ([e itemForType: key] != nil)
|
if ([e itemForType: key] != nil)
|
||||||
{
|
{
|
||||||
|
@ -650,11 +668,12 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e = [self entryByCount:count];
|
e = [self entryByCount: count];
|
||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
NSLog(@"get data for type '%@' version %d\n", type, e ? [e refNum] : -1);
|
NSLog(@"%@ get data for type '%@' version %d\n",
|
||||||
|
self, type, e ? [e refNum] : -1);
|
||||||
}
|
}
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
@ -665,13 +684,13 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
return [d newDataWithVersion: [e refNum]];
|
return [d newDataWithVersion: [e refNum]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[name release];
|
RELEASE(name);
|
||||||
[history release];
|
RELEASE(history);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,20 +698,42 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
owner: (id)owner
|
owner: (id)owner
|
||||||
pasteboard: (NSPasteboard*)pb
|
pasteboard: (NSPasteboard*)pb
|
||||||
{
|
{
|
||||||
PasteboardEntry *old = [current retain];
|
PasteboardEntry *old = RETAIN(current);
|
||||||
|
id x = [xPbClass ownerByOsPb: name];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If neither the new nor the old owner of the pasteboard is the X
|
||||||
|
* pasteboard owner corresponding to this pasteboard, we will need
|
||||||
|
* to inform the X owner of the change of ownership.
|
||||||
|
*/
|
||||||
|
if (x == owner)
|
||||||
|
x = nil;
|
||||||
|
else if (x == [old owner])
|
||||||
|
x = nil;
|
||||||
|
|
||||||
current = [PasteboardEntry newWithTypes: types
|
current = [PasteboardEntry newWithTypes: types
|
||||||
owner: owner
|
owner: owner
|
||||||
pboard: pb
|
pboard: pb
|
||||||
ref: nextCount++];
|
ref: nextCount++];
|
||||||
[history addObject: current];
|
[history addObject: current];
|
||||||
[current release];
|
RELEASE(current);
|
||||||
if ([history count] > histLength)
|
if ([history count] > histLength)
|
||||||
{
|
{
|
||||||
[history removeObjectAtIndex: 0];
|
[history removeObjectAtIndex: 0];
|
||||||
}
|
}
|
||||||
[old lostOwnership];
|
[old lostOwnership];
|
||||||
[old release];
|
RELEASE(old);
|
||||||
|
/*
|
||||||
|
* If there is an interested X pasteboard - inform it of the ownership
|
||||||
|
* change.
|
||||||
|
*/
|
||||||
|
if (x != nil)
|
||||||
|
[x pasteboardChangedOwner: pb];
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
NSLog(@"%@ declare types '%@' version %d\n",
|
||||||
|
self, types, [current refNum]);
|
||||||
|
}
|
||||||
return [current refNum];
|
return [current refNum];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,9 +753,9 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
for (i = 0; i < [history count]; i++)
|
for (i = 0; i < [history count]; i++)
|
||||||
{
|
{
|
||||||
if ([[history objectAtIndex:i] refNum] == count)
|
if ([[history objectAtIndex: i] refNum] == count)
|
||||||
{
|
{
|
||||||
return (PasteboardEntry*)[history objectAtIndex:i];
|
return (PasteboardEntry*)[history objectAtIndex: i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -745,7 +786,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
NSLog(@"set data for type '%@' version %d\n", type, count);
|
NSLog(@"%@ set data for type '%@' version %d\n", self, type, count);
|
||||||
}
|
}
|
||||||
e = [self entryByCount: count];
|
e = [self entryByCount: count];
|
||||||
if (e)
|
if (e)
|
||||||
|
@ -811,7 +852,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
{
|
{
|
||||||
while ([history count] > histLength)
|
while ([history count] > histLength)
|
||||||
{
|
{
|
||||||
[history removeObjectAtIndex:0];
|
[history removeObjectAtIndex: 0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -826,7 +867,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e = [self entryByCount:*count];
|
e = [self entryByCount: *count];
|
||||||
}
|
}
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
@ -844,7 +885,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
@interface PasteboardServer : NSObject <GSPasteboardSvr>
|
@interface PasteboardServer : NSObject <GSPasteboardSvr>
|
||||||
{
|
{
|
||||||
NSMutableArray* permenant;
|
NSMutableArray *permenant;
|
||||||
}
|
}
|
||||||
- (BOOL) connection: (NSConnection*)ancestor
|
- (BOOL) connection: (NSConnection*)ancestor
|
||||||
shouldMakeNewConnection: (NSConnection*)newConn;
|
shouldMakeNewConnection: (NSConnection*)newConn;
|
||||||
|
@ -856,13 +897,14 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
- (id<GSPasteboardObj>) pasteboardByFilteringTypesInPasteboard: pb;
|
- (id<GSPasteboardObj>) pasteboardByFilteringTypesInPasteboard: pb;
|
||||||
- (id<GSPasteboardObj>) pasteboardWithName: (NSString*)name;
|
- (id<GSPasteboardObj>) pasteboardWithName: (NSString*)name;
|
||||||
- (id<GSPasteboardObj>) pasteboardWithUniqueName;
|
- (id<GSPasteboardObj>) pasteboardWithUniqueName;
|
||||||
- (NSArray*) typesFilterableTo: (NSString*)type;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@implementation PasteboardServer
|
@implementation PasteboardServer
|
||||||
|
|
||||||
- (BOOL) connection: (NSConnection*)ancestor
|
- (BOOL) connection: (NSConnection*)ancestor
|
||||||
shouldMakeNewConnection: (NSConnection*)newConn
|
shouldMakeNewConnection: (NSConnection*)newConn;
|
||||||
{
|
{
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
addObserver: self
|
addObserver: self
|
||||||
|
@ -897,7 +939,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[permenant release];
|
RELEASE(permenant);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,16 +948,27 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
permenant = [[NSMutableArray alloc] initWithCapacity:5];
|
/*
|
||||||
|
* Tell the NSPasteboard class to use us as the server so that the X
|
||||||
|
* pasteboard owners can talk to us directly rather than over D.O.
|
||||||
|
*/
|
||||||
|
[NSPasteboard _localServer: (id<GSPasteboardSvr>)self];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create all the pasteboards which must persist forever and add them
|
* Create all the pasteboards which must persist forever and add them
|
||||||
* to a local array.
|
* to a local array.
|
||||||
*/
|
*/
|
||||||
|
permenant = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||||
[permenant addObject: [self pasteboardWithName: NSGeneralPboard]];
|
[permenant addObject: [self pasteboardWithName: NSGeneralPboard]];
|
||||||
|
[permenant addObject: [self pasteboardWithName: NSDragPboard]];
|
||||||
[permenant addObject: [self pasteboardWithName: NSFontPboard]];
|
[permenant addObject: [self pasteboardWithName: NSFontPboard]];
|
||||||
[permenant addObject: [self pasteboardWithName: NSRulerPboard]];
|
[permenant addObject: [self pasteboardWithName: NSRulerPboard]];
|
||||||
[permenant addObject: [self pasteboardWithName: NSFindPboard]];
|
[permenant addObject: [self pasteboardWithName: NSFindPboard]];
|
||||||
[permenant addObject: [self pasteboardWithName: NSDragPboard]];
|
|
||||||
|
/*
|
||||||
|
* Ensure that the X pasteboard system is initialised.
|
||||||
|
*/
|
||||||
|
xPbClass = NSClassFromString(@"XPbOwner");
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -954,7 +1007,7 @@ NSMutableDictionary *pasteboards = nil;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static void
|
||||||
ihandler(int sig)
|
ihandler(int sig)
|
||||||
{
|
{
|
||||||
signal(sig, SIG_DFL);
|
signal(sig, SIG_DFL);
|
||||||
|
@ -964,39 +1017,38 @@ ihandler(int sig)
|
||||||
static void
|
static void
|
||||||
init(int argc, char** argv)
|
init(int argc, char** argv)
|
||||||
{
|
{
|
||||||
const char *options = "Hdv";
|
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||||
int sym;
|
unsigned count;
|
||||||
|
|
||||||
while ((sym = getopt(argc, argv, options)) != -1)
|
for (count = 1; count < [args count]; count++)
|
||||||
{
|
{
|
||||||
switch(sym)
|
NSString *a = [args objectAtIndex: count];
|
||||||
|
|
||||||
|
if ([a isEqualToString: @"--help"] == YES)
|
||||||
{
|
{
|
||||||
case 'H':
|
printf("gpbs\n\n");
|
||||||
printf("%s -[%s]\n", argv[0], options);
|
printf("GNU Pasteboard server\n");
|
||||||
printf("GNU Pasteboard server\n");
|
printf("--help\tfor help\n");
|
||||||
printf("-H\tfor help\n");
|
printf("--no-fork\tavoid fork() to make debugging easy\n");
|
||||||
printf("-d\tavoid fork() to make debugging easy\n");
|
printf("--verbose\tMore verbose debug output\n");
|
||||||
printf("-v\tMore verbose debug output\n");
|
exit(0);
|
||||||
exit(0);
|
}
|
||||||
|
else if ([a isEqualToString: @"--no-fork"] == YES)
|
||||||
case 'd':
|
debug++;
|
||||||
debug++;
|
else if ([a isEqualToString: @"--verbose"] == YES)
|
||||||
break;
|
verbose++;
|
||||||
|
else if ([a length] > 0)
|
||||||
case 'v':
|
{
|
||||||
verbose++;
|
printf("gpbs - GNU Pasteboard server\n");
|
||||||
break;
|
printf("I don't understand '%s'\n", [a cString]);
|
||||||
|
printf("--help for help\n");
|
||||||
default:
|
exit(0);
|
||||||
printf("%s - GNU Pasteboard server\n", argv[0]);
|
|
||||||
printf("-H for help\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sym = 0; sym < 32; sym++)
|
for (count = 0; count < 32; count++)
|
||||||
{
|
{
|
||||||
signal(sym, ihandler);
|
signal((int)count, ihandler);
|
||||||
}
|
}
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
@ -1040,14 +1092,13 @@ init(int argc, char** argv)
|
||||||
int
|
int
|
||||||
main(int argc, char** argv, char **env)
|
main(int argc, char** argv, char **env)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool;
|
CREATE_AUTORELEASE_POOL(pool);
|
||||||
NSString *hostname;
|
NSString *hostname;
|
||||||
|
|
||||||
|
|
||||||
#ifdef GS_PASS_ARGUMENTS
|
#ifdef GS_PASS_ARGUMENTS
|
||||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||||
#endif
|
#endif
|
||||||
pool = [NSAutoreleasePool new];
|
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
|
||||||
// [NSObject enableDoubleReleaseCheck: YES];
|
// [NSObject enableDoubleReleaseCheck: YES];
|
||||||
|
@ -1068,16 +1119,16 @@ main(int argc, char** argv, char **env)
|
||||||
addObserver: server
|
addObserver: server
|
||||||
selector: @selector(connectionBecameInvalid:)
|
selector: @selector(connectionBecameInvalid:)
|
||||||
name: NSConnectionDidDieNotification
|
name: NSConnectionDidDieNotification
|
||||||
object: conn];
|
object: (id)conn];
|
||||||
|
|
||||||
hostname = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
|
hostname = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
|
||||||
if ([hostname length] == 0)
|
if ([hostname length] == 0)
|
||||||
{
|
{
|
||||||
if ([conn registerName: PBSNAME] == NO)
|
if ([conn registerName: PBSNAME] == NO)
|
||||||
{
|
{
|
||||||
NSLog(@"Unable to register with name server.\n");
|
NSLog(@"Unable to register with name server.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1090,8 +1141,7 @@ main(int argc, char** argv, char **env)
|
||||||
if (host == nil)
|
if (host == nil)
|
||||||
{
|
{
|
||||||
NSLog(@"gdnc - unknown NSHost argument ... %@ - quiting.", hostname);
|
NSLog(@"gdnc - unknown NSHost argument ... %@ - quiting.", hostname);
|
||||||
DESTROY(self);
|
exit(1);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
a = [host names];
|
a = [host names];
|
||||||
c = [a count];
|
c = [a count];
|
||||||
|
@ -1122,8 +1172,7 @@ main(int argc, char** argv, char **env)
|
||||||
NSLog(@"GNU pasteboard server startup.\n");
|
NSLog(@"GNU pasteboard server startup.\n");
|
||||||
}
|
}
|
||||||
[[NSRunLoop currentRunLoop] run];
|
[[NSRunLoop currentRunLoop] run];
|
||||||
[pool release];
|
RELEASE(pool);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue