Skip to content

Commit f0b5fd9

Browse files
committed
ui_cocoa: promote bare binary to foreground on pre-10.6
On 10.5 Leopard, the RetroArch window now responded to mouse input (after 23a9456) but still ignored keyboard input entirely. ROOT CAUSE: A bare binary launched from a terminal (no .app bundle wrapping, no Info.plist) starts as a background-only process. The WindowServer delivers mouse events to background processes that own windows, but routes keystrokes only to the frontmost UI app (Finder or the terminal emulator in this case). Commit 6c37fb0 guards [NSApp setActivationPolicy:NSApplication- ActivationPolicyRegular] - the Cocoa API that promotes a background process to a foreground GUI app - behind MAC_OS_X_VERSION_10_6 because the selector doesn't exist on 10.5. That's correct but leaves pre-10.6 bare-binary builds with no promotion path at all, hence no keystrokes. FIX: fall back to the Carbon Process Manager equivalent on pre-10.6: ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); Available since 10.3 in <ApplicationServices/ApplicationServices.h>. Per Leopard's HIServices release notes, 10.5 specifically added support for promoting plain background processes (not just LSUIElement / LSBackgroundOnly apps) to foreground, which covers the bare-binary case. On 10.6+ builds nothing changes - setActivationPolicy: is still used. On bundled .app builds nothing changes either - bundle identity sets the process type at launch and the foreground promotion is a no-op. Bare-binary launches on 10.5 are the only configuration affected, and they now receive keystrokes.
1 parent 23a9456 commit f0b5fd9

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

ui/drivers/ui_cocoa.m

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
#include "cocoa/cocoa_common.h"
3535
#include "cocoa/apple_platform.h"
3636

37+
#if !defined(MAC_OS_X_VERSION_10_6)
38+
/* Pre-10.6: need the Carbon Process Manager's TransformProcessType()
39+
* to promote a bare-binary process to a foreground GUI app that
40+
* receives keystrokes. See the call site below in main() for detail. */
41+
#include <ApplicationServices/ApplicationServices.h>
42+
#endif
43+
3744
#if defined(HAVE_COCOA_METAL)
3845
#include "../../gfx/common/metal_common.h"
3946
#endif
@@ -1445,11 +1452,26 @@ int main(int argc, char *argv[])
14451452
#endif
14461453
[NSApplication sharedApplication];
14471454
#ifdef MAC_OS_X_VERSION_10_6
1448-
/* setActivationPolicy: and NSApplicationActivationPolicyRegular
1449-
* are 10.6+. Before that, an app becomes a regular GUI app
1450-
* via Info.plist (CFBundlePackageType=APPL, no LSUIElement
1451-
* / LSBackgroundOnly), which the PPC bundle already does. */
1455+
/* setActivationPolicy: is 10.6+. On Snow Leopard and later,
1456+
* this is the official way to promote a bare-binary background
1457+
* process to a regular GUI app that receives keystrokes. */
14521458
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
1459+
#else
1460+
/* Pre-10.6: setActivationPolicy: doesn't exist. For bare-
1461+
* binary builds (no .app bundle wrapping, no Info.plist the
1462+
* WindowServer can consult), the process starts as a
1463+
* background-only app and NEVER RECEIVES KEYSTROKES. Mouse
1464+
* events still reach the window, but key events go to whatever
1465+
* app is actually frontmost (Finder or a terminal emulator).
1466+
*
1467+
* The pre-10.6 equivalent is the Carbon Process Manager call
1468+
* TransformProcessType(), available since 10.3 and supporting
1469+
* plain background-only processes (no LSUIElement / LSBackground-
1470+
* Only) on 10.5+ per the Leopard HIServices release notes. */
1471+
{
1472+
ProcessSerialNumber psn = { 0, kCurrentProcess };
1473+
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
1474+
}
14531475
#endif
14541476

14551477
delegate = [[RetroArch_OSX alloc] init];

0 commit comments

Comments
 (0)