diff --git a/gfx/common/metal/Context.m b/gfx/common/metal/Context.m index 033bb219a1..604059592a 100644 --- a/gfx/common/metal/Context.m +++ b/gfx/common/metal/Context.m @@ -79,7 +79,7 @@ _inflightSemaphore = dispatch_semaphore_create(MAX_INFLIGHT); _device = d; _layer = layer; -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) _layer.framebufferOnly = NO; _layer.displaySyncEnabled = YES; #endif @@ -170,17 +170,17 @@ - (void)setDisplaySyncEnabled:(bool)displaySyncEnabled { -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) _layer.displaySyncEnabled = displaySyncEnabled; #endif } - (bool)displaySyncEnabled { -#ifdef OSX - return _layer.displaySyncEnabled; -#else +#if !defined(HAVE_COCOATOUCH) return NO; +#else + return _layer.displaySyncEnabled; #endif } @@ -650,7 +650,7 @@ if (_blitCommandBuffer) { -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) if (_captureEnabled) { id bce = [_blitCommandBuffer blitCommandEncoder]; @@ -745,7 +745,7 @@ static const NSUInteger kConstantAlignment = 4; - (void)commitRanges { -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) BufferNode *n; for (n = _head; n != nil; n = n.next) { diff --git a/gfx/drivers_context/cocoa_gl_ctx.m b/gfx/drivers_context/cocoa_gl_ctx.m index a7dcb78ca9..976c537364 100644 --- a/gfx/drivers_context/cocoa_gl_ctx.m +++ b/gfx/drivers_context/cocoa_gl_ctx.m @@ -23,13 +23,14 @@ #else #include #endif -#ifdef OSX + +#if defined(HAVE_COCOATOUCH) +#include +#else #include #include #include #include -#elif defined(HAVE_COCOATOUCH) -#include #endif #include @@ -57,12 +58,12 @@ typedef struct cocoa_ctx_data { -#ifndef OSX +#if defined(HAVE_COCOATOUCH) int fast_forward_skips; #endif unsigned width; unsigned height; -#ifndef OSX +#if defined(HAVE_COCOATOUCH) bool is_syncing; #endif bool core_hw_context_enable; @@ -127,13 +128,6 @@ static void cocoa_gl_gfx_ctx_set_flags(void *data, uint32_t flags) cocoa_ctx->core_hw_context_enable = true; } -#if defined(OSX) -void cocoa_gl_gfx_ctx_update(void) -{ - [g_ctx update]; - [g_hw_ctx update]; -} -#else #if defined(HAVE_COCOATOUCH) void *glkitview_init(void) { @@ -151,9 +145,13 @@ void glkitview_bind_fbo(void) if (glk_view) [glk_view bindDrawable]; } +#else +void cocoa_gl_gfx_ctx_update(void) +{ + [g_ctx update]; + [g_hw_ctx update]; +} #endif -#endif - static void cocoa_gl_gfx_ctx_destroy(void *data) { @@ -161,7 +159,10 @@ static void cocoa_gl_gfx_ctx_destroy(void *data) if (!cocoa_ctx) return; -#ifdef OSX + +#if defined(HAVE_COCOATOUCH) + [EAGLContext setCurrentContext:nil]; +#else [GLContextClass clearCurrentContext]; [g_ctx clearDrawable]; RELEASE(g_ctx); @@ -169,9 +170,8 @@ static void cocoa_gl_gfx_ctx_destroy(void *data) [g_hw_ctx clearDrawable]; RELEASE(g_hw_ctx); [GLContextClass clearCurrentContext]; -#else - [EAGLContext setCurrentContext:nil]; #endif + g_ctx = nil; free(cocoa_ctx); @@ -189,7 +189,18 @@ static void cocoa_gl_gfx_ctx_input_driver(void *data, *input_data = NULL; } -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if defined(HAVE_COCOATOUCH) +/* iOS */ +static void cocoa_gl_gfx_ctx_get_video_size(void *data, + unsigned* width, unsigned* height) +{ + float screenscale = cocoa_screen_get_native_scale(); + CGRect size = glk_view.bounds; + *width = CGRectGetWidth(size) * screenscale; + *height = CGRectGetHeight(size) * screenscale; +} +#else +#if MAC_OS_X_VERSION_10_7 /* NOTE: convertRectToBacking only available on MacOS X 10.7 and up. * Therefore, make specialized version of this function instead of * going through a selector for every call. */ @@ -206,7 +217,7 @@ static void cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up(void *data, *width = CGRectGetWidth(size); *height = CGRectGetHeight(size); } -#elif defined(OSX) +#else static void cocoa_gl_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height) { @@ -218,16 +229,7 @@ static void cocoa_gl_gfx_ctx_get_video_size(void *data, *width = CGRectGetWidth(size); *height = CGRectGetHeight(size); } -#else -/* iOS */ -static void cocoa_gl_gfx_ctx_get_video_size(void *data, - unsigned* width, unsigned* height) -{ - float screenscale = cocoa_screen_get_native_scale(); - CGRect size = glk_view.bounds; - *width = CGRectGetWidth(size) * screenscale; - *height = CGRectGetHeight(size) * screenscale; -} +#endif #endif static gfx_ctx_proc_t cocoa_gl_gfx_ctx_get_proc_address(const char *symbol_name) @@ -244,26 +246,17 @@ static void cocoa_gl_gfx_ctx_bind_hw_render(void *data, bool enable) cocoa_ctx->use_hw_ctx = enable; -#ifdef OSX +#ifdef HAVE_COCOATOUCH if (enable) - { - [g_hw_ctx makeCurrentContext]; - } + [EAGLContext setCurrentContext:g_hw_ctx]; else - { - [g_ctx makeCurrentContext]; - } + [EAGLContext setCurrentContext:g_ctx]; #else if (enable) - { - [EAGLContext setCurrentContext:g_hw_ctx]; - } + [g_hw_ctx makeCurrentContext]; else - { - [EAGLContext setCurrentContext:g_ctx]; - } + [g_ctx makeCurrentContext]; #endif - } static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit, @@ -273,7 +266,7 @@ static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit, *quit = false; -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH) cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height); #else cocoa_gl_gfx_ctx_get_video_size(data, &new_width, &new_height); @@ -290,30 +283,30 @@ static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit, static void cocoa_gl_gfx_ctx_swap_interval(void *data, int i) { unsigned interval = (unsigned)i; -#ifdef OSX - GLint value = interval ? 1 : 0; - [g_ctx setValues:&value forParameter:NSOpenGLCPSwapInterval]; -#else +#if defined(HAVE_COCOATOUCH) cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; /* < No way to disable Vsync on iOS? */ /* Just skip presents so fast forward still works. */ cocoa_ctx->is_syncing = interval ? true : false; cocoa_ctx->fast_forward_skips = interval ? 0 : 3; +#else + GLint value = interval ? 1 : 0; + [g_ctx setValues:&value forParameter:NSOpenGLCPSwapInterval]; #endif } static void cocoa_gl_gfx_ctx_swap_buffers(void *data) { -#ifdef OSX - [g_ctx flushBuffer]; - [g_hw_ctx flushBuffer]; -#else +#if defined(HAVE_COCOATOUCH) cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; if (!(--cocoa_ctx->fast_forward_skips < 0)) return; if (glk_view) [glk_view display]; cocoa_ctx->fast_forward_skips = cocoa_ctx->is_syncing ? 0 : 3; +#else + [g_ctx flushBuffer]; + [g_hw_ctx flushBuffer]; #endif } @@ -327,7 +320,51 @@ static bool cocoa_gl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, return true; } -#ifdef OSX +#if defined(HAVE_COCOATOUCH) +static bool cocoa_gl_gfx_ctx_set_video_mode(void *data, + unsigned width, unsigned height, bool fullscreen) +{ + cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; + + if (cocoa_ctx->use_hw_ctx) + g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + g_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + glk_view.context = g_ctx; + + [EAGLContext setCurrentContext:g_ctx]; + + /* TODO: Maybe iOS users should be able to + * show/hide the status bar here? */ + return true; +} + +static void *cocoa_gl_gfx_ctx_init(void *video_driver) +{ + cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*) + calloc(1, sizeof(cocoa_ctx_data_t)); + + if (!cocoa_ctx) + return NULL; + + cocoa_ctx->is_syncing = true; + + switch (cocoagl_api) + { + case GFX_CTX_OPENGL_ES_API: +#if defined(HAVE_COCOA_METAL) + /* The Metal build supports both the OpenGL + * and Metal video drivers */ + [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES]; +#endif + break; + case GFX_CTX_NONE: + default: + break; + } + + return cocoa_ctx; +} +#else static bool cocoa_gl_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { @@ -409,10 +446,10 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data, } [g_ctx setView:g_view]; -#ifdef OSX - [g_ctx makeCurrentContext]; -#else +#ifdef HAVE_COCOATOUCH [EAGLContext setCurrentContext:g_ctx]; +#else + [g_ctx makeCurrentContext]; #endif /* TODO/FIXME: Screen mode support. */ @@ -449,66 +486,12 @@ static void *cocoa_gl_gfx_ctx_init(void *video_driver) if (!cocoa_ctx) return NULL; -#ifndef OSX - cocoa_ctx->is_syncing = true; -#endif - #if defined(HAVE_COCOA_METAL) [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL]; #endif return cocoa_ctx; } -#else -static bool cocoa_gl_gfx_ctx_set_video_mode(void *data, - unsigned width, unsigned height, bool fullscreen) -{ - cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; - - if (cocoa_ctx->use_hw_ctx) - g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - g_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - glk_view.context = g_ctx; - -#ifdef OSX - [g_ctx makeCurrentContext]; -#else - [EAGLContext setCurrentContext:g_ctx]; -#endif - - /* TODO: Maybe iOS users should be able to - * show/hide the status bar here? */ - return true; -} - -static void *cocoa_gl_gfx_ctx_init(void *video_driver) -{ - cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*) - calloc(1, sizeof(cocoa_ctx_data_t)); - - if (!cocoa_ctx) - return NULL; - -#ifndef OSX - cocoa_ctx->is_syncing = true; -#endif - - switch (cocoagl_api) - { - case GFX_CTX_OPENGL_ES_API: -#if defined(HAVE_COCOA_METAL) - /* The Metal build supports both the OpenGL - * and Metal video drivers */ - [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES]; -#endif - break; - case GFX_CTX_NONE: - default: - break; - } - - return cocoa_ctx; -} #endif #ifdef HAVE_COCOA_METAL @@ -525,7 +508,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = { cocoa_gl_gfx_ctx_bind_api, cocoa_gl_gfx_ctx_swap_interval, cocoa_gl_gfx_ctx_set_video_mode, -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH) cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up, #else cocoa_gl_gfx_ctx_get_video_size, @@ -536,7 +519,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = { NULL, /* get_video_output_next */ cocoa_get_metrics, NULL, /* translate_aspect */ -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) cocoa_update_title, #else NULL, /* update_title */ diff --git a/gfx/drivers_context/cocoa_vk_ctx.m b/gfx/drivers_context/cocoa_vk_ctx.m index 0315025979..98491f1575 100755 --- a/gfx/drivers_context/cocoa_vk_ctx.m +++ b/gfx/drivers_context/cocoa_vk_ctx.m @@ -23,7 +23,7 @@ #else #include #endif -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) #include #endif @@ -96,7 +96,7 @@ static void cocoa_vk_gfx_ctx_input_driver(void *data, *input_data = NULL; } -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH) /* NOTE: convertRectToBacking only available on MacOS X 10.7 and up. * Therefore, make specialized version of this function instead of * going through a selector for every call. */ @@ -113,7 +113,7 @@ static void cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up(void *data, *width = CGRectGetWidth(size); *height = CGRectGetHeight(size); } -#elif defined(OSX) +#elif !defined(HAVE_COCOATOUCH) static void cocoa_vk_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height) { @@ -144,7 +144,7 @@ static void cocoa_vk_gfx_ctx_check_window(void *data, bool *quit, *resize = cocoa_ctx->vk.need_new_swapchain; -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH) cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height); #else cocoa_vk_gfx_ctx_get_video_size(data, &new_width, &new_height); @@ -201,7 +201,7 @@ static void *cocoa_vk_gfx_ctx_get_context_data(void *data) return &cocoa_ctx->vk.context; } -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) static bool cocoa_vk_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { @@ -261,7 +261,7 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data, static void *cocoa_vk_gfx_ctx_init(void *video_driver) { cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*) - calloc(1, sizeof(cocoa_ctx_data_t)); + calloc(1, sizeof(cocoa_ctx_data_t)); if (!cocoa_ctx) return NULL; @@ -272,7 +272,7 @@ static void *cocoa_vk_gfx_ctx_init(void *video_driver) free(cocoa_ctx); return NULL; } - + return cocoa_ctx; } #else @@ -289,7 +289,7 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data, static void *cocoa_vk_gfx_ctx_init(void *video_driver) { cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*) - calloc(1, sizeof(cocoa_ctx_data_t)); + calloc(1, sizeof(cocoa_ctx_data_t)); if (!cocoa_ctx) return NULL; @@ -330,7 +330,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoavk = { cocoa_vk_gfx_ctx_bind_api, cocoa_vk_gfx_ctx_swap_interval, cocoa_vk_gfx_ctx_set_video_mode, -#if MAC_OS_X_VERSION_10_7 && defined(OSX) +#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH) cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up, #else cocoa_vk_gfx_ctx_get_video_size, @@ -341,7 +341,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoavk = { NULL, /* get_video_output_next */ cocoa_get_metrics, NULL, /* translate_aspect */ -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) cocoa_update_title, #else NULL, /* update_title */ diff --git a/griffin/griffin_objc.m b/griffin/griffin_objc.m index f455fa9627..98bfb42117 100644 --- a/griffin/griffin_objc.m +++ b/griffin/griffin_objc.m @@ -28,7 +28,6 @@ #endif #if defined(HAVE_COCOATOUCH) || defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL) - #include "../ui/drivers/cocoa/cocoa_common.m" #if defined(HAVE_OPENGL) || defined(HAVE_OPENGL_ES) #include "../gfx/drivers_context/cocoa_gl_ctx.m" @@ -36,17 +35,16 @@ #if defined(HAVE_VULKAN) #include "../gfx/drivers_context/cocoa_vk_ctx.m" #endif +#endif -#if defined(OSX) +#if defined(HAVE_COCOATOUCH) +#include "../ui/drivers/ui_cocoatouch.m" +#else #include "../ui/drivers/cocoa/ui_cocoa_window.m" #include "../ui/drivers/cocoa/ui_cocoa_browser_window.m" #include "../ui/drivers/cocoa/ui_cocoa_application.m" #include "../ui/drivers/cocoa/ui_cocoa_msg_window.m" #include "../ui/drivers/ui_cocoa.m" -#else -#include "../ui/drivers/ui_cocoatouch.m" -#endif - #endif #ifdef HAVE_MFI diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index c7699c7036..0eabee3869 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -35,7 +35,7 @@ /* TODO/FIXME - * fix game focus toggle */ -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) /* Forward declaration */ float cocoa_screen_get_backing_scale_factor(void); #endif diff --git a/ui/drivers/cocoa/apple_platform.h b/ui/drivers/cocoa/apple_platform.h index 221ce68d88..147784c954 100644 --- a/ui/drivers/cocoa/apple_platform.h +++ b/ui/drivers/cocoa/apple_platform.h @@ -8,20 +8,9 @@ #if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH) @interface WindowListener : NSResponder -@end - -@implementation WindowListener - -/* Similarly to SDL, we'll respond to key events by doing nothing so we don't beep. - */ -- (void)flagsChanged:(NSEvent *)event { } -- (void)keyDown:(NSEvent *)event { } -- (void)keyUp:(NSEvent *)event { } - @end #endif - #if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH) @protocol ApplePlatform @@ -41,9 +30,6 @@ - (bool)setDisableDisplaySleep:(bool)disable; @end -#endif - -#if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH) extern id apple_platform; id apple_platform; diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 08d074790f..64922db838 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -45,7 +45,7 @@ void *glkitview_init(void); @implementation CocoaView -#if defined(OSX) +#if !defined(HAVE_COCOATOUCH) #ifdef HAVE_COCOA_METAL - (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)newScale fromWindow:(NSWindow *)window { return YES; } #endif @@ -67,86 +67,36 @@ void *glkitview_init(void); { self = [super init]; -#if defined(OSX) - [self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - NSArray *array = [NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil]; - [self registerForDraggedTypes:array]; -#endif - -#if defined(HAVE_COCOA) - ui_window_cocoa_t cocoa_view; - cocoa_view.data = (CocoaView*)self; -#elif defined(HAVE_COCOATOUCH) +#if defined(HAVE_COCOATOUCH) #if defined(HAVE_COCOA_METAL) self.view = [UIView new]; #else self.view = (BRIDGE GLKView*)glkitview_init(); #endif + +#if TARGET_OS_IOS + UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showNativeMenu)]; + swipe.numberOfTouchesRequired = 4; + swipe.direction = UISwipeGestureRecognizerDirectionDown; + [self.view addGestureRecognizer:swipe]; #endif - -#if defined(OSX) - video_driver_display_type_set(RARCH_DISPLAY_OSX); - video_driver_display_set(0); - video_driver_display_userdata_set((uintptr_t)self); -#elif TARGET_OS_IOS - UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showNativeMenu)]; - swipe.numberOfTouchesRequired = 4; - swipe.direction = UISwipeGestureRecognizerDirectionDown; - [self.view addGestureRecognizer:swipe]; +#else + [self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + NSArray *array = [NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil]; + [self registerForDraggedTypes:array]; + + ui_window_cocoa_t cocoa_view; + cocoa_view.data = (CocoaView*)self; + + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)self); #endif return self; } -#if defined(OSX) -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; -/* forward declarations */ -#if defined(HAVE_OPENGL) - void cocoa_gl_gfx_ctx_update(void); - cocoa_gl_gfx_ctx_update(); -#endif -} - -/* Stop the annoying sound when pressing a key. */ -- (BOOL)acceptsFirstResponder { return YES; } -- (BOOL)isFlipped { return YES; } -- (void)keyDown:(NSEvent*)theEvent { } - -- (NSDragOperation)draggingEntered:(id )sender -{ - NSDragOperation sourceDragMask = [sender draggingSourceOperationMask]; - NSPasteboard *pboard = [sender draggingPasteboard]; - - if ( [[pboard types] containsObject:NSFilenamesPboardType] ) - { - if (sourceDragMask & NSDragOperationCopy) - return NSDragOperationCopy; - } - - return NSDragOperationNone; -} - -- (BOOL)performDragOperation:(id)sender -{ - NSPasteboard *pboard = [sender draggingPasteboard]; - - if ( [[pboard types] containsObject:NSURLPboardType]) - { - NSURL *fileURL = [NSURL URLFromPasteboard:pboard]; - NSString *s = [fileURL path]; - if (s != nil) - { - RARCH_LOG("Drop name is: %s\n", [s UTF8String]); - } - } - return YES; -} - -- (void)draggingExited:(id )sender { [self setNeedsDisplay: YES]; } - -#elif TARGET_OS_IOS +#if TARGET_OS_IOS -(void) showNativeMenu { dispatch_async(dispatch_get_main_queue(), ^{ @@ -266,7 +216,6 @@ void *glkitview_init(void); } #endif -#ifdef HAVE_COCOATOUCH - (void)viewDidAppear:(BOOL)animated { #if TARGET_OS_IOS @@ -311,6 +260,53 @@ void *glkitview_init(void); }]; #endif } +#else +- (void)setFrame:(NSRect)frameRect +{ + [super setFrame:frameRect]; +/* forward declarations */ +#if defined(HAVE_OPENGL) + void cocoa_gl_gfx_ctx_update(void); + cocoa_gl_gfx_ctx_update(); +#endif +} + +/* Stop the annoying sound when pressing a key. */ +- (BOOL)acceptsFirstResponder { return YES; } +- (BOOL)isFlipped { return YES; } +- (void)keyDown:(NSEvent*)theEvent { } + +- (NSDragOperation)draggingEntered:(id )sender +{ + NSDragOperation sourceDragMask = [sender draggingSourceOperationMask]; + NSPasteboard *pboard = [sender draggingPasteboard]; + + if ( [[pboard types] containsObject:NSFilenamesPboardType] ) + { + if (sourceDragMask & NSDragOperationCopy) + return NSDragOperationCopy; + } + + return NSDragOperationNone; +} + +- (BOOL)performDragOperation:(id)sender +{ + NSPasteboard *pboard = [sender draggingPasteboard]; + + if ( [[pboard types] containsObject:NSURLPboardType]) + { + NSURL *fileURL = [NSURL URLFromPasteboard:pboard]; + NSString *s = [fileURL path]; + if (s != nil) + { + RARCH_LOG("Drop name is: %s\n", [s UTF8String]); + } + } + return YES; +} + +- (void)draggingExited:(id )sender { [self setNeedsDisplay: YES]; } #endif @end @@ -346,7 +342,7 @@ bool cocoa_has_focus(void *data) void cocoa_show_mouse(void *data, bool state) { -#ifdef OSX +#if !defined(HAVE_COCOATOUCH) if (state) [NSCursor unhide]; else @@ -354,26 +350,7 @@ void cocoa_show_mouse(void *data, bool state) #endif } -#ifdef OSX -#if MAC_OS_X_VERSION_10_7 -/* NOTE: backingScaleFactor only available on MacOS X 10.7 and up. */ -float cocoa_screen_get_backing_scale_factor(void) -{ - static float - backing_scale_def = 0.0f; - if (backing_scale_def == 0.0f) - { - RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen(); - if (!screen) - return 1.0f; - backing_scale_def = [screen backingScaleFactor]; - } - return backing_scale_def; -} -#else -float cocoa_screen_get_backing_scale_factor(void) { return 1.0f; } -#endif -#else +#if defined(HAVE_COCOATOUCH) static float get_from_selector( Class obj_class, id obj_id, SEL selector, CGFloat *ret) { @@ -415,11 +392,30 @@ float cocoa_screen_get_native_scale(void) return ret; } +#else +#if MAC_OS_X_VERSION_10_7 +/* NOTE: backingScaleFactor only available on MacOS X 10.7 and up. */ +float cocoa_screen_get_backing_scale_factor(void) +{ + static float + backing_scale_def = 0.0f; + if (backing_scale_def == 0.0f) + { + RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen(); + if (!screen) + return 1.0f; + backing_scale_def = [screen backingScaleFactor]; + } + return backing_scale_def; +} +#else +float cocoa_screen_get_backing_scale_factor(void) { return 1.0f; } +#endif #endif void *nsview_get_ptr(void) { -#if defined(OSX) +#if !defined(HAVE_COCOATOUCH) video_driver_display_type_set(RARCH_DISPLAY_OSX); video_driver_display_set(0); video_driver_display_userdata_set((uintptr_t)g_instance); @@ -441,62 +437,7 @@ CocoaView *cocoaview_get(void) #endif } -#ifdef OSX -void cocoa_update_title(void *data) -{ - const ui_window_t *window = ui_companion_driver_get_window_ptr(); - - if (window) - { - char title[128]; - - title[0] = '\0'; - - video_driver_get_window_title(title, sizeof(title)); - - if (title[0]) - window->set_title((void*)video_driver_display_userdata_get(), title); - } -} - -bool cocoa_get_metrics( - void *data, enum display_metric_types type, - float *value) -{ - RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen(); - NSDictionary *desc = [screen deviceDescription]; - CGSize display_physical_size = CGDisplayScreenSize( - [[desc objectForKey:@"NSScreenNumber"] unsignedIntValue]); - - float physical_width = display_physical_size.width; - float physical_height = display_physical_size.height; - - switch (type) - { - case DISPLAY_METRIC_MM_WIDTH: - *value = physical_width; - break; - case DISPLAY_METRIC_MM_HEIGHT: - *value = physical_height; - break; - case DISPLAY_METRIC_DPI: - { - NSSize disp_pixel_size = [[desc objectForKey:NSDeviceSize] sizeValue]; - float dispwidth = disp_pixel_size.width; - float scale = cocoa_screen_get_backing_scale_factor(); - float dpi = (dispwidth / physical_width) * 25.4f * scale; - *value = dpi; - } - break; - case DISPLAY_METRIC_NONE: - default: - *value = 0; - return false; - } - - return true; -} -#else +#if defined(HAVE_COCOATOUCH) bool cocoa_get_metrics( void *data, enum display_metric_types type, float *value) @@ -552,4 +493,72 @@ bool cocoa_get_metrics( return true; } +#else +void cocoa_update_title(void *data) +{ + const ui_window_t *window = ui_companion_driver_get_window_ptr(); + + if (window) + { + char title[128]; + + title[0] = '\0'; + + video_driver_get_window_title(title, sizeof(title)); + + if (title[0]) + window->set_title((void*)video_driver_display_userdata_get(), title); + } +} + +bool cocoa_get_metrics( + void *data, enum display_metric_types type, + float *value) +{ + RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen(); + NSDictionary *desc = [screen deviceDescription]; + CGSize display_physical_size = CGDisplayScreenSize( + [[desc objectForKey:@"NSScreenNumber"] unsignedIntValue]); + + float physical_width = display_physical_size.width; + float physical_height = display_physical_size.height; + + switch (type) + { + case DISPLAY_METRIC_MM_WIDTH: + *value = physical_width; + break; + case DISPLAY_METRIC_MM_HEIGHT: + *value = physical_height; + break; + case DISPLAY_METRIC_DPI: + { + NSSize disp_pixel_size = [[desc objectForKey:NSDeviceSize] sizeValue]; + float dispwidth = disp_pixel_size.width; + float scale = cocoa_screen_get_backing_scale_factor(); + float dpi = (dispwidth / physical_width) * 25.4f * scale; + *value = dpi; + } + break; + case DISPLAY_METRIC_NONE: + default: + *value = 0; + return false; + } + + return true; +} +#endif + +#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH) +@implementation WindowListener + +/* Similarly to SDL, we'll respond to key events + * by doing nothing so we don't beep. + */ +- (void)flagsChanged:(NSEvent *)event { } +- (void)keyDown:(NSEvent *)event { } +- (void)keyUp:(NSEvent *)event { } + +@end #endif