OS-X: Carbon event handling

Re: ‘general lack of enthusiasm’, I’d like to say that I’ve jumped
through the hoops nessesary to get something that uses SDL exported to a
scripting language in Mac OS X and I’d love to see this cleaned up :-).

Enter a bug at http://bugzilla.libsdl.org/ and then attach your patch.

Thanks!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Brad Beveridge <brad.beveridge gmail.com> writes:

The issue is that running out of a Lisp
(or any console based interpreter) image does not work properly, you
need to make calls like.
void osx_foreground ()
{
ProcessSerialNumber processSerialNum;
GetCurrentProcess(&processSerialNum);
CPSEnableForegroundOperation (&processSerialNum, 0, 0, 0, 0);
SetFrontProcess(&processSerialNum);
}

This “old” trick relies on an undocumented api. There is now a documented
way of achieving that [1].

ProcessSerialNumber psn = { 0, kCurrentProcess};
/* Dock visibility, no error check because of bundle launchs. */
TransformProcessType (&psn, kProcessTransformToForegroundApplication);

And to make the application frontmost (you typically want to decouple that
if you use a toplevel loop) you can add :

SetFrontProcess (&psn);

I use this successfully with the ocaml’s toplevel. Note that if you create an
executable with this code, it can be used both from the command line or
embedded in an app bundle.

Best,

Daniel

P.S. I’m not subscribed.

[1] http://developer.apple.com/documentation/Carbon/Reference/Process_Manager/index.html

Thanks for that Daniel! I’ll look into that at some stage.

BradOn 4/23/06, Daniel B?nzli <daniel.buenzli at epfl.ch> wrote:

This “old” trick relies on an undocumented api. There is now a documented
way of achieving that [1].

ProcessSerialNumber psn = { 0, kCurrentProcess};
/* Dock visibility, no error check because of bundle launchs. */
TransformProcessType (&psn, kProcessTransformToForegroundApplication);

And to make the application frontmost (you typically want to decouple that
if you use a toplevel loop) you can add :

SetFrontProcess (&psn);

I use this successfully with the ocaml’s toplevel. Note that if you create an
executable with this code, it can be used both from the command line or
embedded in an app bundle.

Best,

Daniel