Skip to content

Commit

Permalink
PNG support in copy and paste; NSPasteboardTypePNG XG_MIME_PNG
Browse files Browse the repository at this point in the history
  • Loading branch information
rmottola committed Mar 5, 2024
1 parent 707c523 commit c787d26
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Tools/xpbs.m
Expand Up @@ -853,6 +853,11 @@ - (void) pasteboard: (NSPasteboard*)pb provideDataForType: (NSString*)type
NSDebugLLog(@"Pbs", @"pasteboard: provideDataForType: - requestData XG_MIME_TIFF");
[self requestData: (xType = XG_MIME_TIFF)];
}
else if ([type isEqual: NSPasteboardTypePNG])
{
NSDebugLLog(@"Pbs", @"pasteboard: provideDataForType: - requestData XG_MIME_PNG");
[self requestData: XG_MIME_PNG];
}
// FIXME: Support more types
else
{
Expand Down Expand Up @@ -1326,6 +1331,10 @@ - (void) xSelectionNotify: (XSelectionEvent*)xEvent
{
[self setData: md];
}
else if (actual_type == XG_MIME_PNG)
{
[self setData: md];
}
else if (actual_type == XA_ATOM)
{
// Used when requesting TARGETS to get available types
Expand Down Expand Up @@ -1405,7 +1414,7 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
{
unsigned numTypes = 0;
// ATTENTION: Increase this array when adding more types
Atom xTypes[17];
Atom xTypes[18];

/*
* The requestor wants a list of the types we can supply it with.
Expand Down Expand Up @@ -1446,6 +1455,11 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
xTypes[numTypes++] = XG_MIME_TIFF;
}

if ([types containsObject: NSPasteboardTypePNG])
{
xTypes[numTypes++] = XG_MIME_PNG;
}

xType = XA_ATOM;
format = 32;
data = [NSData dataWithBytes: (const void*)xTypes
Expand Down Expand Up @@ -1534,6 +1548,11 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
xEvent->target = XG_MIME_TIFF;
[self xProvideSelection: xEvent];
}
else if ([types containsObject: NSPasteboardTypePNG])
{
xEvent->target = XG_MIME_PNG;
[self xProvideSelection: xEvent];
}
}
else if (xEvent->target == XG_MULTIPLE)
{
Expand Down Expand Up @@ -1672,6 +1691,14 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
format = 8;
numItems = [data length];
}
else if ((xEvent->target == XG_MIME_PNG)
&& [types containsObject: NSPasteboardTypePNG])
{
data = [_pb dataForType: NSPasteboardTypePNG];
xType = xEvent->target;
format = 8;
numItems = [data length];
}
// FIXME: Support more types
else
{
Expand Down

0 comments on commit c787d26

Please sign in to comment.