SDL 1.3 Clipboard API enhancement proposal

Dear all,

find attached (as header file) an enhancement to the SDL 1.3 Clipboard
API, which extends it to support arbitrary content types and implicit
conversion mappings to allow applications easier access to external
content.

Background----------
The current implementation only supports text content in a quite limited
fashion. Furthermore, on X11 various aspects of exchanging data are not
realised, such as request timestamp awareness, compound text handling or
a distinction between the clipboard and selection buffer.

Also, most applications nowadays make their content available in
multiple formats, which gives applications accessing that content more
freedom to choose the format which they can handle best.

Internals

From an internal perspective I would recommend to implement a singleton
data structure

struct _SDLClipboard {
SDL_ClipboardMode mode;
void _ownedcontent[]; / pointers to content in the clipboard */

/* next are only for X11 */
Time _timestamp[];
Atom _clipatoms[];
};

which keeps track of the set mode, registered clipboard types (relevant
for X11), timstamps and the content placed into the clipboard by the SDL
application (so it can access the most recent content without the need
to use the OS-specific clipboard APIs).
Would the structure need to use the Atomic API for thread safety? I did
not look into that too much, so how is done for other internals of SDL
1.3?

Discussion

BMP format for exchanging SDL surface data might be reasonable to
implement. On Win32 we can utilise the DIB clipboard type without too
much effort. Something similar can be used for X11-based systems.

From what I know, MacOS X uses TIFF as standard format, so maybe there
are native API calls to create TIFF buffers without the need to link
against libTIFF. If not, the BMP format could be used, too.
Since I do not know much about the MacOS X APIs, I would like to hear
some feedback on that matter from a more knowledgable person :-).

X11 supports selection buffers and a “standard” clipboard for retrieving
or placing content. It is - given the 3 majors, MacOS X, Win32, X11 -
the only one that supports those buffers.

Is support for the selection buffer wanted? If so, the methods clipboard
mode functions from the API proposal could be introduced. Since the
mouse selection is commonly used in X11 environments, I would like to
support this, though it will make the API a bit more complex.

Automatic type mapping

Different platforms support a variety of built-in formats, such as
XA_STRING and XA_COMPOUND_TEXT on X11, CF_TEXT and CF_UNICODETEXT on
Win32, own format type definition, etc.pp.

My proposal is to have a defined mapping set on each platform to ensure
a solid interoperability with different programs.

Plain Text content would be mapped from “text/plain” to:
X11:
XA_STRING
"TEXT"
“UTF8_STRING”
“text/plain”
“text/plain;charset=ascii"
Win32:
CF_UNICODETEXT
CF_TEXT
"text/plain”
"text/plain;charset=ascii"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Surface content would be mapped to:
X11:
XA_BITMAP (PBM)
XA_PIXMAP (PPM)
“image/pbm”
“image/ppm”
"image/bmp"
Win32:
CF_DIB
"image/bmp"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Other implicit mappings:
X11:
“text/plain;charset=utf-8” -> “UTF8_STRING"
Win32:
“audio/wav” -> CF_WAVE
"text/plain;charset=utf-8” -> CF_UNICODETEXT
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Feedback is highly appreciated.

Best regards
Marcus
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL_clipboard.h
Type: text/x-chdr
Size: 5640 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111116/ef946c27/attachment.h
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111116/ef946c27/attachment.pgp

Hi Marcus,

I like the idea but after having just written a few automated tests for
the clipboard API, I would recommend to clarify a few things:

  • Testability? Without pairs of GetXYZContent/PutXYZContent functions
    and an integrated content-type system it will be hard to validate this
    API extension I think.
  • How does the original API change (if at all)? Can the new
    functionality be layered on top of an unchanged existing API? (recommended)
  • What is the use case? What would the “fancyclipboardtest” demo do?
  • Can one use an image or wave file in SDL without external
    dependencies (i.e. SDL_image, Win32 API)?

Keep in mind that the X11 clipboard is difficult to handle properly in a
generic fashion:
http://pvanhoof.be/files/Problems%20of%20the%20X11%20clipboard.pdf

I think a useful, simple enhancement would be the addition of a function
like “PutWindowScreenshotIntoClipboard()” similar to the Windows
PrintScreen-button functionality. Another one would be a simple
extension of the current API with a function that determines the current
content type (and provides a pointer to the captured content bits) for
non-text clipboard content without any more processing internal to SDL.

My 2cents.
–AndreasOn 11/15/11 11:29 PM, Marcus von Appen wrote:

Dear all,

find attached (as header file) an enhancement to the SDL 1.3 Clipboard
API, which extends it to support arbitrary content types and implicit
conversion mappings to allow applications easier access to external
content.

Background

The current implementation only supports text content in a quite limited
fashion. Furthermore, on X11 various aspects of exchanging data are not
realised, such as request timestamp awareness, compound text handling or
a distinction between the clipboard and selection buffer.

Also, most applications nowadays make their content available in
multiple formats, which gives applications accessing that content more
freedom to choose the format which they can handle best.

Internals

From an internal perspective I would recommend to implement a singleton
data structure

struct _SDLClipboard {
SDL_ClipboardMode mode;
void _ownedcontent[]; / pointers to content in the clipboard */

/* next are only for X11 */
Time _timestamp[];
Atom _clipatoms[];
};

which keeps track of the set mode, registered clipboard types (relevant
for X11), timstamps and the content placed into the clipboard by the SDL
application (so it can access the most recent content without the need
to use the OS-specific clipboard APIs).
Would the structure need to use the Atomic API for thread safety? I did
not look into that too much, so how is done for other internals of SDL
1.3?

Discussion

BMP format for exchanging SDL surface data might be reasonable to
implement. On Win32 we can utilise the DIB clipboard type without too
much effort. Something similar can be used for X11-based systems.
From what I know, MacOS X uses TIFF as standard format, so maybe there
are native API calls to create TIFF buffers without the need to link
against libTIFF. If not, the BMP format could be used, too.
Since I do not know much about the MacOS X APIs, I would like to hear
some feedback on that matter from a more knowledgable person :-).

X11 supports selection buffers and a “standard” clipboard for retrieving
or placing content. It is - given the 3 majors, MacOS X, Win32, X11 -
the only one that supports those buffers.

Is support for the selection buffer wanted? If so, the methods clipboard
mode functions from the API proposal could be introduced. Since the
mouse selection is commonly used in X11 environments, I would like to
support this, though it will make the API a bit more complex.

Automatic type mapping

Different platforms support a variety of built-in formats, such as
XA_STRING and XA_COMPOUND_TEXT on X11, CF_TEXT and CF_UNICODETEXT on
Win32, own format type definition, etc.pp.

My proposal is to have a defined mapping set on each platform to ensure
a solid interoperability with different programs.

Plain Text content would be mapped from “text/plain” to:
X11:
XA_STRING
"TEXT"
“UTF8_STRING”
“text/plain”
“text/plain;charset=ascii"
Win32:
CF_UNICODETEXT
CF_TEXT
"text/plain”
"text/plain;charset=ascii"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Surface content would be mapped to:
X11:
XA_BITMAP (PBM)
XA_PIXMAP (PPM)
“image/pbm”
“image/ppm”
"image/bmp"
Win32:
CF_DIB
"image/bmp"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Other implicit mappings:
X11:
“text/plain;charset=utf-8” -> “UTF8_STRING"
Win32:
“audio/wav” -> CF_WAVE
"text/plain;charset=utf-8” -> CF_UNICODETEXT
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Feedback is highly appreciated.

Best regards
Marcus


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You caught me in the middle of a very busy period, but this is
something I’ve been interested in seeing for years.

I implemented a SDL_Clipboard proposal some years back with working
code for Mac OS X and Windows. And It does support both text and BMP
and interoperating with standard mechanisms so other apps can
generically share the clipboard data without special knowledge (e.g.
Notepad, Photoshop). But I never got X11 working quite right and need
an X11 expert.

http://playcontrol.net/ewing/jibberjabber/SDL_ClipboardPrototype.html

I worry a bit that your proposal may be trying to overreach too far
into X11 specifics. But you should look at my Mac and Windows
implementations and maybe you can tell me if that is actually true.
Also, the Mac OS X clipboard stuff should be very similar to the iOS
clipboard stuff (NSPasteboard => UIPasteboard) so there is in reality
another ‘major’ platform that can use this API.

Thanks,
Eric–
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

On 11/15/11, Marcus von Appen wrote:

Dear all,

find attached (as header file) an enhancement to the SDL 1.3 Clipboard
API, which extends it to support arbitrary content types and implicit
conversion mappings to allow applications easier access to external
content.

Background

The current implementation only supports text content in a quite limited
fashion. Furthermore, on X11 various aspects of exchanging data are not
realised, such as request timestamp awareness, compound text handling or
a distinction between the clipboard and selection buffer.

Also, most applications nowadays make their content available in
multiple formats, which gives applications accessing that content more
freedom to choose the format which they can handle best.

Internals

From an internal perspective I would recommend to implement a singleton
data structure

struct _SDLClipboard {
SDL_ClipboardMode mode;
void _ownedcontent[]; / pointers to content in the clipboard */

/* next are only for X11 */
Time _timestamp[];
Atom _clipatoms[];
};

which keeps track of the set mode, registered clipboard types (relevant
for X11), timstamps and the content placed into the clipboard by the SDL
application (so it can access the most recent content without the need
to use the OS-specific clipboard APIs).
Would the structure need to use the Atomic API for thread safety? I did
not look into that too much, so how is done for other internals of SDL
1.3?

Discussion

BMP format for exchanging SDL surface data might be reasonable to
implement. On Win32 we can utilise the DIB clipboard type without too
much effort. Something similar can be used for X11-based systems.
From what I know, MacOS X uses TIFF as standard format, so maybe there
are native API calls to create TIFF buffers without the need to link
against libTIFF. If not, the BMP format could be used, too.
Since I do not know much about the MacOS X APIs, I would like to hear
some feedback on that matter from a more knowledgable person :-).

X11 supports selection buffers and a “standard” clipboard for retrieving
or placing content. It is - given the 3 majors, MacOS X, Win32, X11 -
the only one that supports those buffers.

Is support for the selection buffer wanted? If so, the methods clipboard
mode functions from the API proposal could be introduced. Since the
mouse selection is commonly used in X11 environments, I would like to
support this, though it will make the API a bit more complex.

Automatic type mapping

Different platforms support a variety of built-in formats, such as
XA_STRING and XA_COMPOUND_TEXT on X11, CF_TEXT and CF_UNICODETEXT on
Win32, own format type definition, etc.pp.

My proposal is to have a defined mapping set on each platform to ensure
a solid interoperability with different programs.

Plain Text content would be mapped from “text/plain” to:
X11:
XA_STRING
"TEXT"
“UTF8_STRING”
“text/plain”
“text/plain;charset=ascii"
Win32:
CF_UNICODETEXT
CF_TEXT
"text/plain”
"text/plain;charset=ascii"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Surface content would be mapped to:
X11:
XA_BITMAP (PBM)
XA_PIXMAP (PPM)
“image/pbm”
“image/ppm”
"image/bmp"
Win32:
CF_DIB
"image/bmp"
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Other implicit mappings:
X11:
“text/plain;charset=utf-8” -> “UTF8_STRING"
Win32:
“audio/wav” -> CF_WAVE
"text/plain;charset=utf-8” -> CF_UNICODETEXT
MacOS X:
/* I would love to have some insights about the Mac APIs here */

Feedback is highly appreciated.

Best regards
Marcus

Hi Andreas,

On, Wed Nov 16, 2011, Andreas Schiffler wrote:

Hi Marcus,

I like the idea but after having just written a few automated tests for
the clipboard API, I would recommend to clarify a few things:

  • Testability? Without pairs of GetXYZContent/PutXYZContent functions
    and an integrated content-type system it will be hard to validate this
    API extension I think.

What do you mean by integrated content-type system? Since the API
basically allows an application to put arbitrary strings as content
identifiers, we do not have to take care of an explicit content-type
system.
What we have to do is to take care of the implicit conversion routines,
the API aims to support.

  • How does the original API change (if at all)? Can the new
    functionality be layered on top of an unchanged existing API? (recommended)

No. The original API will be put on top of the new system (see the
header file - it contains the existing 1.3 API). Especially since the
implementation and testing should not hold back a 1.3 release (but could
e.g. go into a later 1.3.x version). That means:

  • API compatibility will be ensured
  • ABI compatibility is likely to break
  • What is the use case? What would the “fancyclipboardtest” demo do?

The use-case is to have full clipboard support to allow sharing
(arbitrary) content between applications.
I do not know anything about a fancyclipboardtest demo - can you point
me to its location?

  • Can one use an image or wave file in SDL without external
    dependencies (i.e. SDL_image, Win32 API)?

As written in the proposal, BMP support could be implemented out of the
box on at least Win32 and X11, probably MacOS as well, though I am not
proficient with its APIs.

Keep in mind that the X11 clipboard is difficult to handle properly in a
generic fashion:
http://pvanhoof.be/files/Problems%20of%20the%20X11%20clipboard.pdf

I implemented it multiple times for now (e.g. for pygame), never got it
perfect but most of the times close enough to be considered good for
most cases of modern systems and applications. X11 is a horribly beast
and I am pretty much aware of it. The current implementation for X11
however lacks certain capabilities, so it would need to be overhauled in
some areas anyways, even for text support.

I think a useful, simple enhancement would be the addition of a function
like “PutWindowScreenshotIntoClipboard()” similar to the Windows
PrintScreen-button functionality. Another one would be a simple
extension of the current API with a function that determines the current
content type (and provides a pointer to the captured content bits) for
non-text clipboard content without any more processing internal to SDL.

That simple enhancement (screenshot placement) would require about 80%
to 90% of the internals of my API proposal ;-).

Regards
Marcus
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111116/bfb2306b/attachment.pgp