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 4114

Summary: SDLMain.m: replace CPS* stuff with activateIgnoringOtherApps
Product: SDL Reporter: Ozkan Sezer <sezeroz>
Component: mainAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sdl-bugzilla
Version: HG 1.2   
Hardware: All   
OS: Mac OS X (All)   
Attachments: osx_main.patch

Description Ozkan Sezer 2018-03-24 21:16:46 UTC
Created attachment 3212 [details]
osx_main.patch

CPS stuff are deprecated and emit warnings at runtime, e.g.:

warning: CPSGetCurrentProcess(): This call is deprecated and should not be called anymore
warning: CPSSetForegroundOperationState() (as above)
warning: capture_display; Captured mirror master 0x350000c1 (unit 1) on behalf of slave 0x042716c0 (unit 0)

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2006-April/055749.html
suggests doing something like:

 ProcessSerialNumber psn = { 0, kCurrentProcess};
 TransformProcessType (&psn, kProcessTransformToForegroundApplication);
 SetFrontProcess (&psn);

And SetFrontProcess() is deprecated in 10.9.  Processes.h suggests
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES]
to make one's own application frontmost.


So, the attached patch is what I came up with:  Please review, and
apply if it's OK.
Comment 1 Ozkan Sezer 2018-06-22 08:58:47 UTC
Any comments on this?
Comment 2 Sam Lantinga 2018-06-22 17:43:31 UTC
This seems reasonable. Does it work? If so, go ahead and commit it.
Comment 3 Ozkan Sezer 2018-06-22 17:49:40 UTC
I've been using it in uhexen2 (uhexen2.sf.net) for quite some time,
no ill effects reported so far.  Will push shortly.
Comment 4 Ozkan Sezer 2018-06-22 18:04:46 UTC
Pushed:  http://hg.libsdl.org/SDL/rev/67f391c74aee
Comment 5 Dominik Reichardt 2019-11-12 19:43:39 UTC
A bit late to the party, but this change is badly affecting DOSBox and possibly other programs.
With this changeset, starting the DOSBox binary from terminal opens DOSBox in the background and even worse, every keyboard input is sent to the terminal but not to DOSBox.

BUT if you put the binary in an app bundle and open the app, all is fine.
Comment 6 Ozkan Sezer 2019-11-12 20:05:37 UTC
(In reply to Dominik Reichardt from comment #5)
> A bit late to the party, but this change is badly affecting DOSBox and
> possibly other programs.
> With this changeset, starting the DOSBox binary from terminal opens DOSBox
> in the background and even worse, every keyboard input is sent to the
> terminal but not to DOSBox.
> 
> BUT if you put the binary in an app bundle and open the app, all is fine.

- Do you have a patch?
- Does reverting this patch make things work, despite the
  deprecation warnings, especially on new macOS versions?
Comment 7 Dominik Reichardt 2019-11-12 20:23:58 UTC
sorry, I have no patch. I have no clue what it does, only that it took me a while to hunt down where the culprit was.

Reverting the patch makes it work correctly again. Compiled and run on macOS 10.14 and also run successfully on macOS 10.15 (though just a late beta of 10.15 not the actual release).

[[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; 
or     
[NSApplication sharedApplication];
makes no difference. Only the other stuff taken out makes it not work (or work when put back in).
Comment 8 Ozkan Sezer 2019-11-12 20:34:49 UTC
Sam, Ryan: Do you have a better fix, or should I just revert this?
Comment 9 Sam Lantinga 2019-11-13 04:35:18 UTC
Go ahead and revert it.
Comment 10 Ozkan Sezer 2019-11-13 07:00:35 UTC
Reverted it in all projects.

Keeping the bug report open because the issue still needs fixing.