dispserv_apple: replace Obj-C 2.0 dot-syntax with bracket calls

Apple GCC 4.0 (the default compiler in Xcode 3.1) only supports
Objective-C 2.0 dot-syntax on explicitly declared @property.  On the
10.5-10.8 SDKs, NSWindow's isKeyWindow / alphaValue / styleMask are
declared as plain getter methods, not @property — Apple only added
the @property annotations in 10.10+.  GCC 4.0 sees the dot-syntax,
notices NSWindow* isn't a struct, and bails:

    dispserv_apple.m:62: error: request for member 'keyWindow' in
        something not a structure or union

Convert every dot-syntax site in the OSX-only blocks to explicit
bracket method calls (e.g. window.keyWindow -> [window isKeyWindow],
window.alphaValue = x -> [window setAlphaValue:x]).  Bracket syntax
works on every Apple compiler back to GCC 3.3, and modern clang
compiles it identically to the dot-syntax form.

Three functions touched:

  - set_window_opacity: dot-syntax converted.  No version gate
    needed; the underlying APIs are all 10.0-era.

  - set_window_progress: dot-syntax converted, AND gated on
    RARCH_HAS_CGDISPLAYMODE_API (10.6+).  This function relies on
    dispatch_once and Obj-C blocks (^{}), neither of which exist
    in GCC 4.0 / pre-10.6 toolchains.  The driver struct slot
    becomes NULL on pre-10.6, matching the existing iOS NULL.

  - set_window_decorations: dot-syntax converted.  Also pulled in
    <defines/cocoa_defines.h> so that NSWindowStyleMaskTitled
    (10.12+) gets its existing pre-10.12 polyfill (it expands to
    the older NSTitledWindowMask).

Modern clang builds are unaffected — bracket syntax compiles to the
same code as dot-syntax there.  Pre-10.6 builds lose the dock-tile
progress indicator but keep window opacity and decorations.
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-04-21 01:17:47 +02:00
1 parent 667256a797
commit c49a5258c6
1 file changed
+23 -14
+23 -14
View File
@@ -25,6 +25,8 @@
#include "../../ui/drivers/cocoa/apple_platform.h"
#include "../../ui/drivers/cocoa/cocoa_common.h"
#include "../../configuration.h"
/* For NSWindowStyleMaskTitled polyfill on pre-10.12 SDKs */
#include <defines/cocoa_defines.h>
#ifdef OSX
#import <AppKit/AppKit.h>
@@ -58,13 +60,15 @@ static bool apple_display_server_set_window_opacity(void *data, unsigned opacity
{
settings_t *settings = config_get_ptr();
bool windowed_full = settings->bools.video_windowed_fullscreen;
NSWindow *window = ((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]).window;
if (windowed_full || !window.keyWindow)
NSWindow *window = [((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]) window];
if (windowed_full || ![window isKeyWindow])
return false;
window.alphaValue = (CGFloat)opacity / (CGFloat)100.0f;
[window setAlphaValue:(CGFloat)opacity / (CGFloat)100.0f];
return true;
}
#ifdef RARCH_HAS_CGDISPLAYMODE_API
/* Uses GCD (dispatch_once) and Obj-C blocks, both 10.6+. */
static bool apple_display_server_set_window_progress(void *data, int progress, bool finished)
{
static NSProgressIndicator *indicator;
@@ -75,35 +79,36 @@ static bool apple_display_server_set_window_progress(void *data, int progress, b
[iv setImage:[[NSApplication sharedApplication] applicationIconImage]];
[dockTile setContentView:iv];
indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, dockTile.size.width, 20)];
indicator.indeterminate = NO;
indicator.minValue = 0;
indicator.maxValue = 100;
indicator.doubleValue = 0;
indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, [dockTile size].width, 20)];
[indicator setIndeterminate:NO];
[indicator setMinValue:0];
[indicator setMaxValue:100];
[indicator setDoubleValue:0];
// Create a custom view for the dock tile
[iv addSubview:indicator];
});
if (finished)
indicator.doubleValue = (double)-1;
[indicator setDoubleValue:(double)-1];
else
indicator.doubleValue = (double)progress;
indicator.hidden = finished;
[indicator setDoubleValue:(double)progress];
[indicator setHidden:finished];
[[NSApp dockTile] display];
return true;
}
#endif /* RARCH_HAS_CGDISPLAYMODE_API */
static bool apple_display_server_set_window_decorations(void *data, bool on)
{
settings_t *settings = config_get_ptr();
bool windowed_full = settings->bools.video_windowed_fullscreen;
NSWindow *window = ((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]).window;
NSWindow *window = [((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]) window];
if (windowed_full)
return false;
if (on)
window.styleMask |= NSWindowStyleMaskTitled;
[window setStyleMask:([window styleMask] | NSWindowStyleMaskTitled)];
else
window.styleMask &= ~NSWindowStyleMaskTitled;
[window setStyleMask:([window styleMask] & ~NSWindowStyleMaskTitled)];
return true;
}
#endif
@@ -578,7 +583,11 @@ const video_display_server_t dispserv_apple = {
apple_display_server_destroy,
#ifdef OSX
apple_display_server_set_window_opacity,
#ifdef RARCH_HAS_CGDISPLAYMODE_API
apple_display_server_set_window_progress,
#else
NULL, /* set_window_progress (needs 10.6+ GCD/blocks) */
#endif
apple_display_server_set_window_decorations,
#else
NULL, /* set_window_opacity */