SDL and Apple Shortcuts

Apprentice
Posts: 6
Joined: 2012.01
Post: #1
Does anyone know how to hide(Cmd-H) an SDL program? And is there a way to do this without using Objective-C? Can I add some code to SDLMain.m that will do this for me.

Thanks,
Mark
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
if you add to SDLMain.m

Code:
void HideMySDLApp(void)
{
    [NSApp hide:nil];
}

and then when you detect a command-H,

Code:
extern void HideMySDLApp(void);
HideMySDLApp();

that should work without requiring ObjC to appear in your own code.
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2012.01
Post: #3
Thanks for helping me out with this one, but I get an error with the code.

Undefined symbols for architecture x86_64:
"HideMySDLApp()"

It is an Apple Mach-O Linker (id) Error with HideMySDLApp()
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
If you're writing C++ you need to redeclare it
Code:
extern "C" HideMySDLApp();
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2012.01
Post: #5
A little confused. Where do I put this line of code? I tried replacing the previous line of code that had extern in it and that did not work.
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2012.01
Post: #6
Ok, I figured it out. extern "C" void HideMySDLApp(void); must be outside of the function.

Thanks OneSadCookie.
Quote this message in a reply
Member
Posts: 31
Joined: 2010.01
Post: #7
That's not a great solution and it doesn't fix command-Q, command-W, command-M, etc.

I found this solution on a mailing list a while ago, which is what I've been using:

In "@implementation SDLApplication", add the method:

Code:
- (void)sendEvent:(NSEvent *)anEvent
{
    if (NSKeyDown == [anEvent type] || NSKeyUp == [anEvent type])
    {
        if ([anEvent modifierFlags] & NSCommandKeyMask)
            [super sendEvent:anEvent];
    }
    else
    {
        [super sendEvent:anEvent];
    }
}

And in the applicationDidFinishLaunching: method in SDLMain's implementation, add a function call setenv("SDL_ENABLEAPPEVENTS", "1", 1) before SDL_main(...) function is called.
Quote this message in a reply
Post Reply