iDevGames Forums
SDL and Apple Shortcuts - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: SDL and Apple Shortcuts (/thread-9698.html)



SDL and Apple Shortcuts - mvaughn - Jan 10, 2012 08:44 PM

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


RE: SDL and Apple Shortcuts - OneSadCookie - Jan 10, 2012 09:53 PM

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.


RE: SDL and Apple Shortcuts - mvaughn - Jan 11, 2012 08:32 PM

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()


RE: SDL and Apple Shortcuts - OneSadCookie - Jan 11, 2012 09:42 PM

If you're writing C++ you need to redeclare it
Code:
extern "C" HideMySDLApp();



RE: SDL and Apple Shortcuts - mvaughn - Jan 11, 2012 09:50 PM

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.


RE: SDL and Apple Shortcuts - mvaughn - Jan 12, 2012 08:36 AM

Ok, I figured it out. extern "C" void HideMySDLApp(void); must be outside of the function.

Thanks OneSadCookie.


RE: SDL and Apple Shortcuts - Zorg - Jan 12, 2012 04:52 PM

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.