diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 15773b7262..3dfb76a0d0 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -343,15 +343,23 @@ bool apple_game_view_has_focus(void) bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen) { + __block bool result = true; + #ifdef OSX dispatch_sync(dispatch_get_main_queue(), ^{ - // TODO: Multi-monitor support // TODO: Sceen mode support if (fullscreen && !g_has_went_fullscreen) { - [g_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; + if (g_settings.video.monitor_index >= [NSScreen screens].count) + { + apple_display_alert(@"Could not go fullscreen: Monitor index out of range.", nil); + result = false; + return; + } + + [g_view enterFullScreenMode:[NSScreen screens][g_settings.video.monitor_index] withOptions:nil]; [NSCursor hide]; } else if (!fullscreen && g_has_went_fullscreen) @@ -369,7 +377,7 @@ bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen) // TODO: Maybe iOS users should be apple to show/hide the status bar here? - return true; + return result; } #ifdef IOS diff --git a/audio/coreaudio.c b/audio/coreaudio.c index b396e6a1e3..4d71eb4b8a 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -22,6 +22,10 @@ #include "../boolean.h" #include +#ifdef OSX +#include +#endif + #include #include #include @@ -93,6 +97,48 @@ static OSStatus audio_write_cb(void *userdata, AudioUnitRenderActionFlags *actio return noErr; } +#ifdef OSX +static void choose_output_device(coreaudio_t *dev, const char* device) +{ + AudioObjectPropertyAddress propaddr = + { + kAudioHardwarePropertyDevices, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + + UInt32 size = 0; + + if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, 0, &size) != noErr) + return; + + UInt32 deviceCount = size / sizeof(AudioDeviceID); + AudioDeviceID *devices = malloc(size); + + if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, 0, &size, devices) != noErr) + goto done; + + propaddr.mScope = kAudioDevicePropertyScopeOutput; + propaddr.mSelector = kAudioDevicePropertyDeviceName; + size = 1024; + + for (unsigned i = 0; i < deviceCount; i ++) + { + char device_name[1024]; + device_name[0] = 0; + + if (AudioObjectGetPropertyData(devices[i], &propaddr, 0, 0, &size, device_name) == noErr && strcmp(device_name, device) == 0) + { + AudioUnitSetProperty(dev->dev, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &devices[i], sizeof(AudioDeviceID)); + goto done; + } + } + +done: + free(devices); +} +#endif + static void *coreaudio_init(const char *device, unsigned rate, unsigned latency) { (void)device; @@ -121,6 +167,11 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency) if (AudioComponentInstanceNew(comp, &dev->dev) != noErr) goto error; +#ifdef OSX + if (device) + choose_output_device(dev, device); +#endif + dev->dev_alive = true; // Set audio format