Skip to content

Commit 6a76e74

Browse files
committed
[4.7] Allow compiling with min macOS version up to 14
1 parent cd709b3 commit 6a76e74

7 files changed

Lines changed: 52 additions & 0 deletions

File tree

drivers/coreaudio/audio_driver_coreaudio.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@
127127
AudioDeviceID device_id;
128128
UInt32 dev_id_size = sizeof(AudioDeviceID);
129129

130+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
130131
AudioObjectPropertyAddress property_dev_id = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
132+
#else
133+
AudioObjectPropertyAddress property_dev_id = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain };
134+
#endif
131135
result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property_dev_id, 0, nullptr, &dev_id_size, &device_id);
132136
ERR_FAIL_COND_V(result != noErr, FAILED);
133137

modules/camera/camera_apple.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,16 @@ - (void)dealloc {
491491
if (@available(macOS 14.0, *)) {
492492
session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeExternal, AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeContinuityCamera, nil] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];
493493
} else {
494+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
494495
session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeExternalUnknown, AVCaptureDeviceTypeBuiltInWideAngleCamera, nil] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];
496+
#endif
495497
}
496498
devices = session.devices;
497499
#if defined(__x86_64__)
498500
} else {
501+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101500
499502
devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
503+
#endif
500504
}
501505
#endif // __x86_64__
502506
#endif // APPLE_EMBEDDED_ENABLED

platform/macos/display_server_macos_base.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,12 @@
408408
color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
409409
}
410410
} else {
411+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
411412
NSAppearance *saved_appearance = [NSAppearance currentAppearance];
412413
[NSAppearance setCurrentAppearance:[NSApp effectiveAppearance]];
413414
color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
414415
[NSAppearance setCurrentAppearance:saved_appearance];
416+
#endif
415417
}
416418
if (color) {
417419
CGFloat components[4];
@@ -436,10 +438,12 @@
436438
color = [[NSColor controlColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
437439
}
438440
} else {
441+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
439442
NSAppearance *saved_appearance = [NSAppearance currentAppearance];
440443
[NSAppearance setCurrentAppearance:[NSApp effectiveAppearance]];
441444
color = [[NSColor controlColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
442445
[NSAppearance setCurrentAppearance:saved_appearance];
446+
#endif
443447
}
444448
if (color) {
445449
CGFloat components[4];

platform/macos/godot_application.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ - (void)sendEvent:(NSEvent *)event {
169169
}
170170
}
171171

172+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
173+
// This option was deprecated in macOS 14.0, replace it with 0 (no options) when min version is 14.0 or higher.
174+
#define NSApplicationActivateIgnoringOtherApps 0
175+
#endif
176+
172177
- (void)forceUnbundledWindowActivationHackStep1 {
173178
// Step 1: Switch focus to macOS SystemUIServer process.
174179
// Required to perform step 2, TransformProcessType will fail if app is already the in focus.
@@ -193,4 +198,8 @@ - (void)forceUnbundledWindowActivationHackStep3 {
193198
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
194199
}
195200

201+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
202+
#undef NSApplicationActivateIgnoringOtherApps
203+
#endif
204+
196205
@end

platform/macos/godot_open_save_delegate.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,23 @@ - (void)makeAccessoryView:(NSSavePanel *)p_panel filters:(const Vector<String> &
245245
[p_panel setAllowedContentTypes:type_filters];
246246
}
247247
} else {
248+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
248249
if (type_filters && [type_filters count] == 1 && [[type_filters objectAtIndex:0] isEqualToString:@"*"]) {
249250
[p_panel setAllowedFileTypes:nil];
250251
[p_panel setAllowsOtherFileTypes:true];
251252
} else {
252253
[p_panel setAllowsOtherFileTypes:false];
253254
[p_panel setAllowedFileTypes:type_filters];
254255
}
256+
#endif
255257
}
256258
} else {
257259
if (@available(macOS 11, *)) {
258260
[p_panel setAllowedContentTypes:@[ UTTypeData ]];
259261
} else {
262+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
260263
[p_panel setAllowedFileTypes:nil];
264+
#endif
261265
}
262266
[p_panel setAllowsOtherFileTypes:true];
263267
}
@@ -331,20 +335,24 @@ - (void)popupFileAction:(id)p_sender {
331335
[dialog setAllowedContentTypes:type_filters];
332336
}
333337
} else {
338+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
334339
if (type_filters && [type_filters count] == 1 && [[type_filters objectAtIndex:0] isEqualToString:@"*"]) {
335340
[dialog setAllowedFileTypes:nil];
336341
[dialog setAllowsOtherFileTypes:true];
337342
} else {
338343
[dialog setAllowsOtherFileTypes:false];
339344
[dialog setAllowedFileTypes:type_filters];
340345
}
346+
#endif
341347
}
342348
cur_index = index;
343349
} else {
344350
if (@available(macOS 11, *)) {
345351
[dialog setAllowedContentTypes:@[ UTTypeData ]];
346352
} else {
353+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
347354
[dialog setAllowedFileTypes:nil];
355+
#endif
348356
}
349357
[dialog setAllowsOtherFileTypes:true];
350358
cur_index = -1;

platform/macos/os_macos.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@
849849
#if defined(__x86_64__)
850850
} else {
851851
Error err = ERR_TIMEOUT;
852+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
852853
NSError *error = nullptr;
853854
NSDictionary *config = @{
854855
NSWorkspaceLaunchConfigurationArguments : arguments,
@@ -864,6 +865,7 @@
864865
}
865866
err = OK;
866867
}
868+
#endif
867869
return err;
868870
}
869871
#endif
@@ -950,11 +952,13 @@
950952
return err;
951953
#if defined(__x86_64__)
952954
} else {
955+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
953956
NSError *error = nullptr;
954957
[[NSWorkspace sharedWorkspace] openURLs:urls_to_open withApplicationAtURL:app_url options:NSWorkspaceLaunchDefault configuration:@{} error:&error];
955958
if (error) {
956959
return ERR_CANT_FORK;
957960
}
961+
#endif
958962
return OK;
959963
}
960964
#endif
@@ -973,7 +977,11 @@
973977
static String serial_number;
974978

975979
if (serial_number.is_empty()) {
980+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
976981
io_service_t platform_expert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
982+
#else
983+
io_service_t platform_expert = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
984+
#endif
977985
CFStringRef serial_number_cf_string = nullptr;
978986
if (platform_expert) {
979987
serial_number_cf_string = (CFStringRef)IORegistryEntryCreateCFProperty(platform_expert, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);

platform/macos/tts_macos.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ - (id)init {
4545
[self->synth setDelegate:self];
4646
print_verbose("Text-to-Speech: AVSpeechSynthesizer initialized.");
4747
} else {
48+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
4849
self->synth = [[NSSpeechSynthesizer alloc] init];
4950
[self->synth setDelegate:self];
5051
print_verbose("Text-to-Speech: NSSpeechSynthesizer initialized.");
52+
#endif
5153
}
5254
return self;
5355
}
@@ -90,6 +92,8 @@ - (void)speechSynthesizer:(AVSpeechSynthesizer *)av_synth didFinishSpeechUtteran
9092

9193
// NSSpeechSynthesizer callback (macOS 10.4+)
9294

95+
// Deprecated in macOS 14.0, needs to be removed when compiling with min macOS 14.0.
96+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
9397
- (void)speechSynthesizer:(NSSpeechSynthesizer *)ns_synth willSpeakWord:(NSRange)characterRange ofString:(NSString *)string {
9498
if (!paused && have_utterance) {
9599
// Convert from UTF-16 to UTF-32 position.
@@ -118,6 +122,7 @@ - (void)speechSynthesizer:(NSSpeechSynthesizer *)ns_synth didFinishSpeaking:(BOO
118122
speaking = false;
119123
[self update];
120124
}
125+
#endif
121126

122127
- (void)update {
123128
if (!speaking && queue.size() > 0) {
@@ -138,6 +143,7 @@ - (void)update {
138143
ids[new_utterance] = message.id;
139144
[av_synth speakUtterance:new_utterance];
140145
} else {
146+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
141147
NSSpeechSynthesizer *ns_synth = synth;
142148
[ns_synth setObject:nil forProperty:NSSpeechResetProperty error:nil];
143149
[ns_synth setVoice:[NSString stringWithUTF8String:message.voice.utf8().get_data()]];
@@ -149,6 +155,7 @@ - (void)update {
149155
last_utterance = message.id;
150156
have_utterance = true;
151157
[ns_synth startSpeakingString:[NSString stringWithUTF8String:message.text.utf8().get_data()]];
158+
#endif
152159
}
153160
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServerEnums::TTS_UTTERANCE_STARTED, message.id);
154161
queue.pop_front();
@@ -162,8 +169,10 @@ - (void)pauseSpeaking {
162169
AVSpeechSynthesizer *av_synth = synth;
163170
[av_synth pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
164171
} else {
172+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
165173
NSSpeechSynthesizer *ns_synth = synth;
166174
[ns_synth pauseSpeakingAtBoundary:NSSpeechImmediateBoundary];
175+
#endif
167176
}
168177
paused = true;
169178
}
@@ -173,8 +182,10 @@ - (void)resumeSpeaking {
173182
AVSpeechSynthesizer *av_synth = synth;
174183
[av_synth continueSpeaking];
175184
} else {
185+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
176186
NSSpeechSynthesizer *ns_synth = synth;
177187
[ns_synth continueSpeaking];
188+
#endif
178189
}
179190
paused = false;
180191
}
@@ -188,11 +199,13 @@ - (void)stopSpeaking {
188199
AVSpeechSynthesizer *av_synth = synth;
189200
[av_synth stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
190201
} else {
202+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
191203
NSSpeechSynthesizer *ns_synth = synth;
192204
if (have_utterance) {
193205
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServerEnums::TTS_UTTERANCE_CANCELED, last_utterance);
194206
}
195207
[ns_synth stopSpeaking];
208+
#endif
196209
}
197210
have_utterance = false;
198211
speaking = false;
@@ -252,6 +265,7 @@ - (Array)getVoices {
252265
list.push_back(voice_d);
253266
}
254267
} else {
268+
#if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
255269
for (NSString *voiceIdentifierString in [NSSpeechSynthesizer availableVoices]) {
256270
NSString *voiceLocaleIdentifier = [[NSSpeechSynthesizer attributesForVoice:voiceIdentifierString] objectForKey:NSVoiceLocaleIdentifier];
257271
NSString *voiceName = [[NSSpeechSynthesizer attributesForVoice:voiceIdentifierString] objectForKey:NSVoiceName];
@@ -261,6 +275,7 @@ - (Array)getVoices {
261275
voice_d["language"] = String([voiceLocaleIdentifier UTF8String]);
262276
list.push_back(voice_d);
263277
}
278+
#endif
264279
}
265280
return list;
266281
}

0 commit comments

Comments
 (0)