diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 5064083985..8cd78a9b2f 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -33,6 +33,7 @@ static UIView* g_pause_indicator_view; #include "apple_input.h" +static bool g_has_went_fullscreen; static RAGameView* g_instance; static NSOpenGLContext* g_context; static NSOpenGLPixelFormat* g_format; @@ -312,10 +313,38 @@ void *apple_get_proc_address(const char *symbol_name) #endif } +void apple_update_window_title(void) +{ + static char buf[128]; + bool got_text = gfx_get_fps(buf, sizeof(buf), false); +#ifdef OSX + static const char* const text = buf; // < Can't access buf directly in the block + + if (got_text) + { + // NOTE: This could go bad if buf is updated again before this completes. + // If it poses a problem it should be changed to dispatch_sync. + dispatch_async(dispatch_get_main_queue(), ^ + { + g_view.window.title = @(text); + }); + } +#endif +} + +bool apple_game_view_has_focus(void) +{ +#ifdef OSX + return [NSApp isActive]; +#else + return true; +#endif +} + bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen) { __block bool result = true; - + #ifdef OSX dispatch_sync(dispatch_get_main_queue(), ^{ @@ -323,12 +352,24 @@ bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen) // TODO: Sceen mode support if (fullscreen) - result = [g_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; + { + if (!g_has_went_fullscreen) + result = [g_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; + g_has_went_fullscreen = true; + } else { - [g_view exitFullScreenModeWithOptions:nil]; - [g_view.window makeFirstResponder:g_view]; + if (g_has_went_fullscreen) + { + [g_view exitFullScreenModeWithOptions:nil]; + [g_view.window makeFirstResponder:g_view]; + } + g_has_went_fullscreen = false; + + [g_view.window setContentSize:NSMakeSize(width, height)]; } + + g_has_went_fullscreen = fullscreen; }); #endif diff --git a/apple/common/rarch_wrapper.h b/apple/common/rarch_wrapper.h index 3537360da5..92bce93c5e 100644 --- a/apple/common/rarch_wrapper.h +++ b/apple/common/rarch_wrapper.h @@ -23,13 +23,15 @@ char* ios_get_rarch_system_directory(); // These functions should only be called as arguments to dispatch_sync void apple_rarch_exited (void* result); -// These functions must only be called in gfx/context/ioseagl_ctx.c +// These functions must only be called in gfx/context/apple_gl_context.c bool apple_init_game_view(void); void apple_destroy_game_view(void); bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen); void apple_flip_game_view(void); void apple_set_game_view_sync(unsigned interval); void apple_get_game_view_size(unsigned *width, unsigned *height); +void apple_update_window_title(void); +bool apple_game_view_has_focus(void); void *apple_get_proc_address(const char *symbol_name); #ifdef IOS diff --git a/gfx/context/apple_gl_ctx.c b/gfx/context/apple_gl_ctx.c index a54e875ee6..fb7e6333aa 100644 --- a/gfx/context/apple_gl_ctx.c +++ b/gfx/context/apple_gl_ctx.c @@ -38,19 +38,6 @@ static bool gfx_ctx_bind_api(enum gfx_ctx_api api, unsigned major, unsigned mino #endif } -static bool gfx_ctx_set_video_mode( - unsigned width, unsigned height, - bool fullscreen) -{ - return apple_set_video_mode(width, height, fullscreen); -} - -static void gfx_ctx_update_window_title(void) -{ - char buf[128]; - gfx_get_fps(buf, sizeof(buf), false); -} - static void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { @@ -74,16 +61,6 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height) (void)height; } -static bool gfx_ctx_has_focus(void) -{ - return true; -} - -static void gfx_ctx_swap_buffers(void) -{ - apple_flip_game_view(); -} - static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) { *input = NULL; @@ -102,13 +79,13 @@ const gfx_ctx_driver_t gfx_ctx_apple = { apple_destroy_game_view, gfx_ctx_bind_api, apple_set_game_view_sync, - gfx_ctx_set_video_mode, + apple_set_video_mode, apple_get_game_view_size, NULL, - gfx_ctx_update_window_title, + apple_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, - gfx_ctx_has_focus, + apple_game_view_has_focus, apple_flip_game_view, gfx_ctx_input_driver, gfx_ctx_get_proc_address,