We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2858

Summary: [Patch] Mac: update some internal code to use modern codepaths rather than deprecated functionality, when available
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: icculus
Version: HG 2.0Keywords: triage-2.0.4
Hardware: x86_64   
OS: Mac OS X (All)   
Attachments: Patch to use some modern Mac APIs rather than deprecated ones, when available
Patch to use some modern Mac APIs rather than deprecated ones, when available
Patch to prefer some modern Mac APIs over deprecated ones (v3)
Patch to prefer some modern Mac APIs over deprecated ones (v4)

Description Alex Szpakowski 2015-01-27 18:56:11 UTC
Created attachment 2007 [details]
Patch to use some modern Mac APIs rather than deprecated ones, when available

SDL's Mac code for preventing the screensaver from activating and for making the app show up in the Dock is using long-deprecated APIs. I have attached a patch to use more modern APIs when available.
Comment 1 Alex Szpakowski 2015-01-27 20:44:17 UTC
Created attachment 2008 [details]
Patch to use some modern Mac APIs rather than deprecated ones, when available
Comment 2 Ryan C. Gordon 2015-02-02 07:04:02 UTC
(In reply to Alex Szpakowski from comment #1)
> Created attachment 2008 [details]
> Patch to use some modern Mac APIs rather than deprecated ones, when available

Notes:

- Cocoa_ShouldUseIdleIOPMAssertion() should just be checked once at init time and stored as a BOOL somewhere under _this. Not that it's a real expensive function or anything, of course.

- Put a FIXME or something on this: CFSTR("SDL-based app running") ... eventually I'd like to add a simple app metadata API that lets an app describe some basic things about itself, since there are a few places on various platforms where we end up saying "SDL application" instead of "Super Mario Bros."

- Does the legacy path not need to call SetFrontProcess()? That got removed in the patch.

--ryan.
Comment 3 Alex Szpakowski 2015-02-02 07:33:32 UTC
(In reply to Ryan C. Gordon from comment #2)
> - Put a FIXME or something on this: CFSTR("SDL-based app running") ...
> eventually I'd like to add a simple app metadata API that lets an app
> describe some basic things about itself, since there are a few places on
> various platforms where we end up saying "SDL application" instead of "Super
> Mario Bros."

Should I just make it use the actual application name? SDL_cocoaevents.m already has a function to determine it, since it creates the menubar items programmatically.

(In reply to Ryan C. Gordon from comment #2)
> - Does the legacy path not need to call SetFrontProcess()? That got removed
> in the patch.
> 
> --ryan.

The patch replaces the SetFrontProcess call with [NSApp activateIgnoringOtherApps:YES] (the Cocoa version of that Carbon function.)
Comment 4 Alex Szpakowski 2015-02-02 07:37:34 UTC
(In reply to Alex Szpakowski from comment #3)
> Should I just make it use the actual application name? SDL_cocoaevents.m
> already has a function to determine it, since it creates the menubar items
> programmatically.

Actually the Apple documentation says this, so I guess the app name isn't quite appropriate:
> specify a CFString like "Checking mail" or "Compiling" that describes the task that this assertion protects.
Comment 5 Alex Szpakowski 2015-02-02 07:45:36 UTC
Created attachment 2013 [details]
Patch to prefer some modern Mac APIs over deprecated ones (v3)
Comment 6 Alex Szpakowski 2015-02-02 09:20:23 UTC
Created attachment 2014 [details]
Patch to prefer some modern Mac APIs over deprecated ones (v4)

I updated the name used in IOPMAssertionCreate to include the application name, and added a comment about it.
Comment 7 Ryan C. Gordon 2015-02-19 05:22:19 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 8 Ryan C. Gordon 2015-02-20 01:06:43 UTC
This looks good to me; it's now https://hg.libsdl.org/SDL/rev/ad9d35983de5, thanks!

--ryan.