(Cocoa) Cleanups

This commit is contained in:
twinaphex 2020-09-15 21:00:22 +02:00
parent 62f4eae323
commit de68ce185c

View File

@ -214,14 +214,13 @@ static char **waiting_argv;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{ {
unsigned i; unsigned i;
#ifdef HAVE_COCOA_METAL
apple_platform = self; apple_platform = self;
[self.window setAcceptsMouseMovedEvents: YES];
#ifdef HAVE_COCOA_METAL
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
_listener = [WindowListener new]; _listener = [WindowListener new];
[self.window setAcceptsMouseMovedEvents: YES];
[self.window setNextResponder:_listener]; [self.window setNextResponder:_listener];
self.window.delegate = _listener; self.window.delegate = _listener;
@ -229,31 +228,28 @@ static char **waiting_argv;
#else #else
SEL selector = NSSelectorFromString(BOXSTRING("setCollectionBehavior:")); SEL selector = NSSelectorFromString(BOXSTRING("setCollectionBehavior:"));
SEL fsselector = NSSelectorFromString(BOXSTRING("toggleFullScreen:")); SEL fsselector = NSSelectorFromString(BOXSTRING("toggleFullScreen:"));
apple_platform = self;
if ([self.window respondsToSelector:selector]) if ([self.window respondsToSelector:selector])
{ {
if ([self.window respondsToSelector:fsselector]) if ([self.window respondsToSelector:fsselector])
[self.window setCollectionBehavior:NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY]; [self.window setCollectionBehavior:NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY];
} }
[self.window setAcceptsMouseMovedEvents: YES];
[[CocoaView get] setFrame: [[self.window contentView] bounds]]; [[CocoaView get] setFrame: [[self.window contentView] bounds]];
[[self.window contentView] setAutoresizesSubviews:YES]; [[self.window contentView] setAutoresizesSubviews:YES];
[[self.window contentView] addSubview:[CocoaView get]]; [[self.window contentView] addSubview:[CocoaView get]];
[self.window makeFirstResponder:[CocoaView get]]; [self.window makeFirstResponder:[CocoaView get]];
#endif #endif
for (i = 0; i < waiting_argc; i++) for (i = 0; i < waiting_argc; i++)
{ {
if (string_is_equal(waiting_argv[i], "-NSDocumentRevisionsDebugMode")) if (string_is_equal(waiting_argv[i], "-NSDocumentRevisionsDebugMode"))
{ {
waiting_argv[i] = NULL; waiting_argv[i] = NULL;
waiting_argv[i+1] = NULL; waiting_argv[i+1] = NULL;
waiting_argc -= 2; waiting_argc -= 2;
} }
} }
if (rarch_main(waiting_argc, waiting_argv, NULL)) if (rarch_main(waiting_argc, waiting_argv, NULL))
[[NSApplication sharedApplication] terminate:nil]; [[NSApplication sharedApplication] terminate:nil];
@ -270,7 +266,8 @@ static char **waiting_argv;
#pragma mark - ApplePlatform #pragma mark - ApplePlatform
#ifdef HAVE_COCOA_METAL #ifdef HAVE_COCOA_METAL
- (void)setViewType:(apple_view_type_t)vt { - (void)setViewType:(apple_view_type_t)vt
{
if (vt == _vt) if (vt == _vt)
return; return;
@ -301,7 +298,7 @@ static char **waiting_argv;
break; break;
case APPLE_VIEW_TYPE_NONE: case APPLE_VIEW_TYPE_NONE:
default: default:
return; return;
} }
@ -312,17 +309,9 @@ static char **waiting_argv;
self.window.contentView.nextResponder = _listener; self.window.contentView.nextResponder = _listener;
} }
- (apple_view_type_t)viewType { - (apple_view_type_t)viewType { return _vt; }
return _vt; - (id)renderView { return _renderView; }
} - (bool)hasFocus { return [NSApp isActive]; }
- (id)renderView {
return _renderView;
}
- (bool)hasFocus {
return [NSApp isActive];
}
- (void)setVideoMode:(gfx_ctx_mode_t)mode { - (void)setVideoMode:(gfx_ctx_mode_t)mode {
BOOL isFullScreen = (self.window.styleMask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen; BOOL isFullScreen = (self.window.styleMask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;
@ -345,7 +334,8 @@ static char **waiting_argv;
[self.window setContentSize:NSMakeSize(mode.width, mode.height)]; [self.window setContentSize:NSMakeSize(mode.width, mode.height)];
} }
- (void)setCursorVisible:(bool)v { - (void)setCursorVisible:(bool)v
{
if (v) if (v)
[NSCursor unhide]; [NSCursor unhide];
else else
@ -398,19 +388,9 @@ static char **waiting_argv;
main_exit(NULL); main_exit(NULL);
} }
- (void)applicationDidBecomeActive:(NSNotification *)notification - (void)applicationDidBecomeActive:(NSNotification *)notification { }
{ - (void)applicationWillResignActive:(NSNotification *)notification { }
} - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; }
- (void)applicationWillResignActive:(NSNotification *)notification
{
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{ {
NSApplicationTerminateReply reply = NSTerminateNow; NSApplicationTerminateReply reply = NSTerminateNow;
@ -467,9 +447,7 @@ static void open_core_handler(ui_browser_window_state_t *state, bool result)
rarch_system_info_t *info = runloop_get_system_info(); rarch_system_info_t *info = runloop_get_system_info();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool set_supports_no_game_enable = settings->bools.set_supports_no_game_enable; bool set_supports_no_game_enable = settings->bools.set_supports_no_game_enable;
if (!state) if (!state || string_is_empty(state->result))
return;
if (string_is_empty(state->result))
return; return;
if (!result) if (!result)
return; return;
@ -497,9 +475,7 @@ static void open_document_handler(
struct retro_system_info *system = runloop_get_libretro_system_info(); struct retro_system_info *system = runloop_get_libretro_system_info();
const char *core_name = system ? system->library_name : NULL; const char *core_name = system ? system->library_name : NULL;
if (!state) if (!state || string_is_empty(state->result))
return;
if (string_is_empty(state->result))
return; return;
if (!result) if (!result)
return; return;
@ -570,9 +546,8 @@ static void open_document_handler(
} }
} }
- (void)unloadingCore - (void)unloadingCore { }
{ - (IBAction)showPreferences:(id)sender { }
}
- (IBAction)showCoresDirectory:(id)sender - (IBAction)showCoresDirectory:(id)sender
{ {
@ -581,14 +556,10 @@ static void open_document_handler(
[[NSWorkspace sharedWorkspace] openFile:BOXSTRING(path_dir_libretro)]; [[NSWorkspace sharedWorkspace] openFile:BOXSTRING(path_dir_libretro)];
} }
- (IBAction)showPreferences:(id)sender
{
}
- (IBAction)basicEvent:(id)sender - (IBAction)basicEvent:(id)sender
{ {
enum event_command cmd; enum event_command cmd = CMD_EVENT_NONE;
unsigned sender_tag = (unsigned)[sender tag]; unsigned sender_tag = (unsigned)[sender tag];
switch (sender_tag) switch (sender_tag)
{ {
@ -623,7 +594,6 @@ static void open_document_handler(
cmd = CMD_EVENT_FULLSCREEN_TOGGLE; cmd = CMD_EVENT_FULLSCREEN_TOGGLE;
break; break;
default: default:
cmd = CMD_EVENT_NONE;
break; break;
} }