Scrap for OSX (copy and paste)

Has anyone made the scrap project work in OSX yet:

http://www.libsdl.org/projects/scrap/

Yes, I sent Sam the code for this awhile back. I also cleaned up the
Windows code a bit so both text and images would work more naturally
with the clipboard.

I think the code might be included in SDL 1.3, but I haven’t checked.

-EricOn 11/28/07, Josiah <ravean_uo at hotmail.com> wrote:

Has anyone made the scrap project work in OSX yet:

http://www.libsdl.org/projects/scrap/


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

E. Wing <ewmailing gmail.com> writes:

Yes, I sent Sam the code for this awhile back. I also cleaned up the
Windows code a bit so both text and images would work more naturally
with the clipboard.

I think the code might be included in SDL 1.3, but I haven’t checked.

-Eric

I tried checking the latest build of SDL 1.3 but didn’t see any mention of it so
I was not sure if it was in there. Do you have the code posted anywhere or can
you send it to me?

I hope so, since it’d be quite useful in apps like Tux Paint.

-bill!On Wed, Nov 28, 2007 at 05:12:38PM -0800, E. Wing wrote:

Yes, I sent Sam the code for this awhile back. I also cleaned up the
Windows code a bit so both text and images would work more naturally
with the clipboard.

I think the code might be included in SDL 1.3, but I haven’t checked.

I’m still trying to find the code I sent Sam. I have some newer code,
but I made changes to the API and function names for my own use. I can
make that available if you don’t care.

-EricOn 11/28/07, Josiah <ravean_uo at hotmail.com> wrote:

E. Wing <ewmailing gmail.com> writes:

Yes, I sent Sam the code for this awhile back. I also cleaned up the
Windows code a bit so both text and images would work more naturally
with the clipboard.

I think the code might be included in SDL 1.3, but I haven’t checked.

-Eric

I tried checking the latest build of SDL 1.3 but didn’t see any mention of
it so
I was not sure if it was in there. Do you have the code posted anywhere or
can
you send it to me?


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

E. Wing <ewmailing gmail.com> writes:

I’m still trying to find the code I sent Sam. I have some newer code,
but I made changes to the API and function names for my own use. I can
make that available if you don’t care.

-Eric

That would be great, at this point I just need something functional that will
work in OSX and Windows.

Attached is my modified version. To compile on OS X, your build system
should skip the scrap.c and build scrap_OSX.m instead.

-Eric
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDLScrap2.zip
Type: application/zip
Size: 8558 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20071204/9f3b82e8/attachment.zip

E. Wing <ewmailing gmail.com> writes:

Attached is my modified version. To compile on OS X, your build system
should skip the scrap.c and build scrap_OSX.m instead.

-Eric

Thanks Eric, I managed to get it compiling correctly but whenever I try and copy
and past I get an error:

main(467,0xa000ed88) malloc: *** error for object 0xbfffddd0: pointer being
reallocated was not
allocated
main(467,0xa000ed88) malloc: *** set a breakpoint in szone_error to debug
Text scrap is empty

The code I am using to paste is taken from the original scrap.c and works in
Windows:

void getclipboard(char *scrap)
{
int scraplen;
char *cp;
int i;

SDLScrap_PasteFromClipboard(SDLSCRAP_TEXT, &scraplen, &scrap);
    if ( scraplen == 0 ) {
	printf("Text scrap is empty\n");
} else {
	{ /* Convert the scrap from Mac text to UNIX text */

		for ( cp=scrap, i=0; i<scraplen; ++cp, ++i ) {
			if ( *cp == '\r' )
				*cp = '\n';
		}
	}
	printf("Scrap is: %s\n", scrap);
}

}

Any ideas?

Thanks!

This error does not ring a bell. But clarify this, are you trying to
get Sam’s scrap code to interoperate with my version? If so, don’t do
this. My version is not compatible with Sam’s version (because he did
it wrong :P). My modifications post/get directly from the native
clipboard system using the well known text and image types so you can
copy/paste from standard apps like Notepad and Paint. I think Sam was
using some user defined type or something so the only thing that could
exchange data was two instances of scrap.

-EricOn 12/4/07, Josiah <ravean_uo at hotmail.com> wrote:

E. Wing <ewmailing gmail.com> writes:

Attached is my modified version. To compile on OS X, your build system
should skip the scrap.c and build scrap_OSX.m instead.

-Eric

Thanks Eric, I managed to get it compiling correctly but whenever I try and
copy
and past I get an error:

main(467,0xa000ed88) malloc: *** error for object 0xbfffddd0: pointer being
reallocated was not
allocated
main(467,0xa000ed88) malloc: *** set a breakpoint in szone_error to debug
Text scrap is empty

The code I am using to paste is taken from the original scrap.c and works in
Windows:

void getclipboard(char *scrap)
{
int scraplen;
char *cp;
int i;

SDLScrap_PasteFromClipboard(SDLSCRAP_TEXT, &scraplen, &scrap);
if ( scraplen == 0 ) {
printf(“Text scrap is empty\n”);
} else {
{ /* Convert the scrap from Mac text to UNIX text */

  	for ( cp=scrap, i=0; i<scraplen; ++cp, ++i ) {
  		if ( *cp == '\r' )
  			*cp = '\n';
  	}
  }
  printf("Scrap is: %s\n", scrap);

}
}

Any ideas?

Thanks!


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

E. Wing <ewmailing gmail.com> writes:

This error does not ring a bell. But clarify this, are you trying to
get Sam’s scrap code to interoperate with my version? If so, don’t do
this. My version is not compatible with Sam’s version (because he did
it wrong :P). My modifications post/get directly from the native
clipboard system using the well known text and image types so you can
copy/paste from standard apps like Notepad and Paint. I think Sam was
using some user defined type or something so the only thing that could
exchange data was two instances of scrap.

-Eric

I think I figured out the problem although I don’t know why it was working in
Windows :slight_smile: It was on my side. I think your code is working now, I just need
to get mine working.

Thanks!

Josiah

I’m not sure if this works, but this might have been one of the
modifications I made to the test program to work with my new stuff.

-Eric
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: main.c
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20071204/de863896/attachment.asc

E. Wing <ewmailing gmail.com> writes:

I’m not sure if this works, but this might have been one of the
modifications I made to the test program to work with my new stuff.

-Eric

Thanks for all your help, I have it working now :slight_smile: It seems like the remalloc
function was a lot more fussy in OSX then in Windows which is probably better.

Josiah

E. Wing <ewmailing gmail.com> writes:

Attached is my modified version. To compile on OS X, your build system
should skip the scrap.c and build scrap_OSX.m instead.

-Eric

Quick question for you if you have a min. I am not familiar with .m files such
as your scrap_OSX.m. I do have it working by including it in my xcode project,
but I would like to include it in my main.c. I use one code base for Windows,
OSX and Linux. I have a define at the top of the code which I change for each
OS. I would like to be able to stick to this with the scrap_OSX.m as well. I
tried including it like I would a normal .c file but that did not work. Is
there a way to include it from the main.c? Or make it a normal .c file instead
of a .m? Pardon my ignorance, I just have not use .m files before, I understand
they are for Mac OS which is probably why I have not been exposed to them.

Thanks,

Josiah

So .m is the extension used for Objective-C. (And .mm is the extension
used for Objective-C++.) Since I wrote the copy & paste code for OS X
in Cocoa, I used Objective-C which is the native language of Cocoa.

I intentionally separated the Cocoa implementation from the rest of
the code by placing it in scrap_OSX.m. The reason is pretty much the
same as why you would keep pure C code and C++ code separated. If you
take a pure C file, and put C++ only stuff in it, you now must compile
as C++ or you will get a compile error. And while some people have no
issues/reservations of simply making a former C file a C++ file and
changing the extension from .c to .cpp, unlike Objective-C which is at
least a pure superset of C, C++ creates a whole bunch of subtle
side-effects when compiling C code as C++.

Anyhow, you could use a bunch of #defines to guard the Objective-C
code inside main.c, but I don’t recommend it. This means that when
compiling for a Mac, you must compile the file as Objective-C instead
of C. The easiest way of doing this is to rename the extension to .m,
but this will confuse/break things on other platforms that have no
idea what Objective-C is (e.g. Visual Studio). Or you could leave the
extension alone and tell your build system to compile as Objective-C,
but this requires that you tell your build system how to compile
something other than relying on the defaults. Xcode will let you do
this, but I suspect things would get harder when using alternative
build systems like autoconf, CMake, etc. (You could also flip-it so
that it always has the .m extension and tell the other compilers to
compile as C, but it’s the same problem, but in reverse.)

I think this is more trouble than dealing with the separate files. So
I personally recommend you leave it as is, and structure your build
system to have a case that says, ‘when on Mac, compile scrap_OSX.m,
otherwise compile scrap.c’.

The public interface is all pure-C, so scrap_OSX.m and scrap.c is just
an implementation detail. Your main code should never know/care how
the backend was implemented. You really shouldn’t have any of this
platform specific stuff in your main.c.

By the way since you mention Linux, I was not able to fix up the copy
& paste code for X11 so it is still mostly/all of Sam’s original code.
While I was able to fix up Windows and Mac, I couldn’t figure out how
to get X11 to behave properly. I can’t remember all the issues, but it
was something like…

  • Can’t copy text from my program to the clipboard (for other programs to read)
  • Might be able to paste text into my program.
  • There might be some big lags from when you copy/paste and when it
    actually appears. I don’t know why.
  • I can’t remember if I tried anything with images.

I tested Sam’s code and some other pure X11 code I found and they
suffer the same problems on my system.

My system was running Linux with KDE, so it’s possible that the X11
clipboard buffers Sam uses are different/incompatible with KDE. This
implies that maybe a KDE, Gnome, etc, native pasteboard implementation
needs to be developed sort of like how SDL handles the different sound
daemons.

I don’t know X11 or any of these other APIs, so I hit my limits in
trying to fix this up. Maybe some X11/KDE/Gnome gurus would like to
take a crack at this.

-EricOn 12/5/07, Josiah <ravean_uo at hotmail.com> wrote:

E. Wing <ewmailing gmail.com> writes:

Attached is my modified version. To compile on OS X, your build system
should skip the scrap.c and build scrap_OSX.m instead.

-Eric

Quick question for you if you have a min. I am not familiar with .m files
such
as your scrap_OSX.m. I do have it working by including it in my xcode
project,
but I would like to include it in my main.c. I use one code base for
Windows,
OSX and Linux. I have a define at the top of the code which I change for
each
OS. I would like to be able to stick to this with the scrap_OSX.m as well.
I
tried including it like I would a normal .c file but that did not work. Is
there a way to include it from the main.c? Or make it a normal .c file
instead
of a .m? Pardon my ignorance, I just have not use .m files before, I
understand
they are for Mac OS which is probably why I have not been exposed to them.

Thanks,

Josiah


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

E. Wing <ewmailing gmail.com> writes:

I’m not sure if this works, but this might have been one of the
modifications I made to the test program to work with my new stuff.

-Eric

Quick question for you if you have a min. I am not familiar with .m files such
as your scrap_OSX.m. I do have it working by including it in my xcode project,
but I would like to include it in my main.c. I use one code base for Windows,
OSX and Linux. I have a define at the top of the code which I change for each
OS. I would like to be able to stick to this with the scrap_OSX.m as well. I
tried including it like I would a normal .c file but that did not work. Is
there a way to include it from the main.c? Or make it a normal .c file instead
of a .m? Pardon my ignorance, I just have not use .m files before, I understand
they are for Mac OS which is probably why I have not been exposed to them.

Thanks,

Josiah

E. Wing <ewmailing gmail.com> writes:

I think this is more trouble than dealing with the separate files. So
I personally recommend you leave it as is, and structure your build
system to have a case that says, ‘when on Mac, compile scrap_OSX.m,
otherwise compile scrap.c’.

Do you know if there is anyway to tell XCode this from inside main.c? If it was
a .c file I would just have a #include inside a #ifdef OSX but including the .m
file gives a whole bunch of errors.

Josiah

So a #include in a file is equivalent to copying the entire contents
of the file you are including and pasting it in the calling file.

So if you #include a .m file from a .c file, you’ve effectively just
changed your pure C file to Obj-C. (Same goes for C++.)

This is probably why you are getting errors. You are compiling
Objective-C code as C instead of Obj-C.

As I said, my recommendation is that your main.c should only #include
the public header file (scrap.h) which is a pure C interface. Then
compile scrap.c or scrap_OSX.m depending on the platform.

-EricOn 12/5/07, Josiah <ravean_uo at hotmail.com> wrote:

E. Wing <ewmailing gmail.com> writes:

I think this is more trouble than dealing with the separate files. So
I personally recommend you leave it as is, and structure your build
system to have a case that says, ‘when on Mac, compile scrap_OSX.m,
otherwise compile scrap.c’.

Do you know if there is anyway to tell XCode this from inside main.c? If it
was
a .c file I would just have a #include inside a #ifdef OSX but including the
.m
file gives a whole bunch of errors.

Josiah


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

Josiah wrote:

Do you know if there is anyway to tell XCode this from inside main.c? If it was
a .c file I would just have a #include inside a #ifdef OSX but including the .m
file gives a whole bunch of errors.

That’s not a nice idea, objectiveC and C use different compilers, simply
add scrap_OSX.m to the sources file in the xcode project, the project is
not crossplatform anyway. Otherwise, if you use a crossplatform makefile
you can do something like this inside your makefile:

OBJS = main.c
OSNAME = $(shell uname)

ifeq ("$(OSNAME)", “Darwin”)
OBJS += scrap_OSX.m
endif–
Bye,
Gabry

hi,

pygame has taken the scrap code and improved it greatly. Windows and
X11 code in particular.

However currently the macosx code is broken, but it worked in the past.

Also qnx support was dropped.

Have a look in pygame subversion ( http://pygame.org/wiki/cvs )

It would be great if we(pygame) could use your osx code, or put our
code back into SDL_scrap.On Dec 7, 2007 12:47 AM, Gabriele Greco <gabriele.greco at darts.it> wrote:

Josiah wrote:

Do you know if there is anyway to tell XCode this from inside main.c? If it was
a .c file I would just have a #include inside a #ifdef OSX but including the .m
file gives a whole bunch of errors.

That’s not a nice idea, objectiveC and C use different compilers, simply
add scrap_OSX.m to the sources file in the xcode project, the project is
not crossplatform anyway. Otherwise, if you use a crossplatform makefile
you can do something like this inside your makefile:

OBJS = main.c
OSNAME = $(shell uname)

ifeq ("$(OSNAME)", “Darwin”)
OBJS += scrap_OSX.m
endif


Bye,
Gabry


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

Since there seems to be enough interest in a cross-platform copy/paste
system, I think it would be beneficial to see the changes I’ve made
and the changes made to pygame integrated into some kind of
semi-official SDL_Scrap2 project. (Or maybe rename it the project.)

I don’t know much about pygame though. Are you offering to help
backport pygame’s changes?

Thanks,
EricOn 12/7/07, Ren? Dudfield wrote:

hi,

pygame has taken the scrap code and improved it greatly. Windows and
X11 code in particular.

However currently the macosx code is broken, but it worked in the past.

Also qnx support was dropped.

Have a look in pygame subversion ( http://pygame.org/wiki/cvs )

It would be great if we(pygame) could use your osx code, or put our
code back into SDL_scrap.

On Dec 7, 2007 12:47 AM, Gabriele Greco <gabriele.greco at darts.it> wrote:

Josiah wrote:

Do you know if there is anyway to tell XCode this from inside main.c?
If it was

a .c file I would just have a #include inside a #ifdef OSX but including
the .m

file gives a whole bunch of errors.

That’s not a nice idea, objectiveC and C use different compilers, simply
add scrap_OSX.m to the sources file in the xcode project, the project is
not crossplatform anyway. Otherwise, if you use a crossplatform makefile
you can do something like this inside your makefile:

OBJS = main.c
OSNAME = $(shell uname)

ifeq ("$(OSNAME)", “Darwin”)
OBJS += scrap_OSX.m
endif


Bye,
Gabry


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


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