2015-04-20 10:43:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-04-20 10:43:07 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
#include <objc/objc-runtime.h>
|
2015-04-20 10:43:07 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
#include <boolean.h>
|
2015-04-20 10:43:07 +00:00
|
|
|
#include <file/file_path.h>
|
2016-01-20 03:11:25 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-05-16 15:29:02 +00:00
|
|
|
#include <queues/task_queue.h>
|
2017-06-28 02:41:38 +00:00
|
|
|
#include <retro_timers.h>
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
#include "cocoa/cocoa_common.h"
|
2015-04-20 10:43:07 +00:00
|
|
|
#include "../ui_companion_driver.h"
|
2015-04-20 15:27:07 +00:00
|
|
|
#include "../../input/drivers/cocoa_input.h"
|
2015-11-29 15:30:38 +00:00
|
|
|
#include "../../input/drivers_keyboard/keyboard_event_apple.h"
|
2015-04-20 15:27:07 +00:00
|
|
|
#include "../../frontend/frontend.h"
|
2016-09-05 16:33:22 +00:00
|
|
|
#include "../../configuration.h"
|
2016-09-23 01:42:50 +00:00
|
|
|
#include "../../paths.h"
|
2016-09-06 04:11:44 +00:00
|
|
|
#include "../../core.h"
|
2016-01-19 23:38:48 +00:00
|
|
|
#include "../../retroarch.h"
|
2019-01-20 02:26:35 +00:00
|
|
|
#include "../../tasks/task_content.h"
|
2016-02-10 06:20:54 +00:00
|
|
|
#include "../../tasks/tasks_internal.h"
|
2018-10-01 01:43:53 +00:00
|
|
|
#include ".././verbosity.h"
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
id apple_platform;
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2016-09-09 13:56:56 +00:00
|
|
|
#if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
|
2018-11-04 16:29:40 +00:00
|
|
|
@interface RetroArch_OSX : NSObject
|
2016-06-12 17:38:30 +00:00
|
|
|
#else
|
2018-11-04 16:29:40 +00:00
|
|
|
@interface RetroArch_OSX : NSObject <NSApplicationDelegate>
|
2016-06-12 17:38:30 +00:00
|
|
|
#endif
|
2016-06-12 17:29:07 +00:00
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
NSWindow* _window;
|
2016-06-12 17:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property (nonatomic, retain) NSWindow IBOutlet* window;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-06-04 16:09:40 +00:00
|
|
|
static void app_terminate(void)
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2015-04-21 09:43:43 +00:00
|
|
|
[[NSApplication sharedApplication] terminate:nil];
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-21 22:57:05 +00:00
|
|
|
@interface RApplication : NSApplication
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RApplication
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
- (void)sendEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
NSEventType event_type;
|
2018-10-18 05:39:45 +00:00
|
|
|
cocoa_input_data_t *apple = NULL;
|
2018-11-04 16:29:40 +00:00
|
|
|
[super sendEvent:event];
|
|
|
|
|
|
|
|
event_type = event.type;
|
2016-01-13 12:08:51 +00:00
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
switch ((int32_t)event_type)
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSKeyDown:
|
|
|
|
case NSKeyUp:
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
NSString* ch = (NSString*)event.characters;
|
2016-01-13 12:08:51 +00:00
|
|
|
uint32_t character = 0;
|
|
|
|
uint32_t mod = 0;
|
|
|
|
|
|
|
|
if (ch && ch.length != 0)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
character = [ch characterAtIndex:0];
|
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSAlphaShiftKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_CAPSLOCK;
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSShiftKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_SHIFT;
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSControlKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_CTRL;
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSAlternateKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_ALT;
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSCommandKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_META;
|
2018-11-04 16:29:40 +00:00
|
|
|
if (event.modifierFlags & NSNumericPadKeyMask)
|
2016-01-13 12:08:51 +00:00
|
|
|
mod |= RETROKMOD_NUMLOCK;
|
|
|
|
|
|
|
|
for (i = 1; i < ch.length; i++)
|
2018-11-04 16:29:40 +00:00
|
|
|
apple_input_keyboard_event(event_type == NSKeyDown,
|
2016-01-13 12:08:51 +00:00
|
|
|
0, [ch characterAtIndex:i], mod, RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
apple_input_keyboard_event(event_type == NSKeyDown,
|
2016-01-13 12:08:51 +00:00
|
|
|
event.keyCode, character, mod, RETRO_DEVICE_KEYBOARD);
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSFlagsChanged:
|
2016-01-13 12:08:51 +00:00
|
|
|
{
|
|
|
|
static uint32_t old_flags = 0;
|
2017-01-16 21:34:36 +00:00
|
|
|
uint32_t new_flags = event.modifierFlags;
|
|
|
|
bool down = (new_flags & old_flags) == old_flags;
|
|
|
|
|
|
|
|
old_flags = new_flags;
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2016-01-13 12:08:51 +00:00
|
|
|
apple_input_keyboard_event(down, event.keyCode,
|
|
|
|
0, event.modifierFlags, RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSMouseMoved:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
2015-11-29 17:06:09 +00:00
|
|
|
{
|
|
|
|
NSPoint pos;
|
|
|
|
NSPoint mouse_pos;
|
2016-01-15 21:15:23 +00:00
|
|
|
apple = (cocoa_input_data_t*)input_driver_get_data();
|
2016-01-15 21:20:46 +00:00
|
|
|
if (!apple)
|
2015-11-29 17:06:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Relative */
|
2018-11-04 16:29:40 +00:00
|
|
|
apple->mouse_rel_x = event.deltaX;
|
|
|
|
apple->mouse_rel_y = event.deltaY;
|
2015-11-29 17:06:09 +00:00
|
|
|
|
|
|
|
/* Absolute */
|
2018-11-04 16:29:40 +00:00
|
|
|
pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
|
|
|
|
apple->touches[0].screen_x = pos.x;
|
|
|
|
apple->touches[0].screen_y = pos.y;
|
2015-11-29 17:06:09 +00:00
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
mouse_pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
|
2016-01-15 21:20:46 +00:00
|
|
|
apple->window_pos_x = (int16_t)mouse_pos.x;
|
|
|
|
apple->window_pos_y = (int16_t)mouse_pos.y;
|
2015-11-29 17:06:09 +00:00
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSScrollWheel:
|
2016-01-13 12:08:51 +00:00
|
|
|
/* TODO/FIXME - properly implement. */
|
|
|
|
break;
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
2017-01-16 21:34:36 +00:00
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
NSPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
|
2017-01-16 21:34:36 +00:00
|
|
|
apple = (cocoa_input_data_t*)input_driver_get_data();
|
|
|
|
if (!apple || pos.y < 0)
|
|
|
|
return;
|
|
|
|
apple->mouse_buttons |= 1 << event.buttonNumber;
|
|
|
|
|
|
|
|
apple->touch_count = 1;
|
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
2018-11-04 16:29:40 +00:00
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
2017-01-16 21:34:36 +00:00
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
NSPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
|
2017-01-16 21:34:36 +00:00
|
|
|
apple = (cocoa_input_data_t*)input_driver_get_data();
|
|
|
|
if (!apple || pos.y < 0)
|
|
|
|
return;
|
|
|
|
apple->mouse_buttons &= ~(1 << event.buttonNumber);
|
|
|
|
apple->touch_count = 0;
|
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static int waiting_argc;
|
|
|
|
static char** waiting_argv;
|
|
|
|
|
2015-10-12 10:21:54 +00:00
|
|
|
@implementation RetroArch_OSX
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
@synthesize window = _window;
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[_window release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:03:57 +00:00
|
|
|
#define NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY (1 << 17)
|
2016-01-17 17:58:50 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
2015-07-25 13:56:14 +00:00
|
|
|
unsigned i;
|
2016-01-17 17:58:50 +00:00
|
|
|
SEL selector = NSSelectorFromString(BOXSTRING("setCollectionBehavior:"));
|
2016-01-17 18:03:57 +00:00
|
|
|
SEL fsselector = NSSelectorFromString(BOXSTRING("toggleFullScreen:"));
|
2018-11-04 16:29:40 +00:00
|
|
|
apple_platform = self;
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-01-17 17:58:50 +00:00
|
|
|
if ([self.window respondsToSelector:selector])
|
|
|
|
{
|
2016-01-17 18:03:57 +00:00
|
|
|
if ([self.window respondsToSelector:fsselector])
|
|
|
|
[self.window setCollectionBehavior:NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY];
|
2016-01-17 17:58:50 +00:00
|
|
|
}
|
2018-11-04 16:29:40 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
[self.window setAcceptsMouseMovedEvents: YES];
|
2018-11-04 16:29:40 +00:00
|
|
|
|
|
|
|
[[CocoaView get] setFrame: [[self.window contentView] bounds]];
|
2015-04-20 15:26:05 +00:00
|
|
|
[[self.window contentView] setAutoresizesSubviews:YES];
|
2018-11-04 16:29:40 +00:00
|
|
|
[[self.window contentView] addSubview:[CocoaView get]];
|
|
|
|
[self.window makeFirstResponder:[CocoaView get]];
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2015-07-25 13:56:14 +00:00
|
|
|
for (i = 0; i < waiting_argc; i++)
|
|
|
|
{
|
2016-01-20 03:11:25 +00:00
|
|
|
if (string_is_equal(waiting_argv[i], "-NSDocumentRevisionsDebugMode"))
|
2015-07-25 13:56:14 +00:00
|
|
|
{
|
|
|
|
waiting_argv[i] = NULL;
|
|
|
|
waiting_argv[i+1] = NULL;
|
|
|
|
waiting_argc -= 2;
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 19:31:25 +00:00
|
|
|
if (rarch_main(waiting_argc, waiting_argv, NULL))
|
2016-06-04 16:09:40 +00:00
|
|
|
app_terminate();
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
waiting_argc = 0;
|
2018-07-04 20:13:03 +00:00
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
[self performSelectorOnMainThread:@selector(rarch_main) withObject:nil waitUntilDone:NO];
|
2018-07-04 20:13:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
- (void) rarch_main
|
|
|
|
{
|
2016-09-30 06:17:18 +00:00
|
|
|
do
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2016-09-30 06:17:18 +00:00
|
|
|
int ret;
|
2015-11-28 02:05:37 +00:00
|
|
|
unsigned sleep_ms = 0;
|
2018-10-15 01:38:15 +00:00
|
|
|
#ifdef HAVE_QT
|
2018-10-15 01:38:43 +00:00
|
|
|
const ui_application_t *application = &ui_application_qt;
|
2018-10-15 01:38:15 +00:00
|
|
|
#else
|
2016-06-07 15:14:57 +00:00
|
|
|
const ui_application_t *application = ui_companion_driver_get_application_ptr();
|
2018-10-15 01:38:15 +00:00
|
|
|
#endif
|
2016-06-07 15:14:57 +00:00
|
|
|
if (application)
|
|
|
|
application->process_events();
|
2018-10-15 01:38:15 +00:00
|
|
|
|
2016-10-22 15:41:26 +00:00
|
|
|
ret = runloop_iterate(&sleep_ms);
|
2018-10-15 01:38:15 +00:00
|
|
|
|
2015-08-27 12:52:02 +00:00
|
|
|
if (ret == 1 && sleep_ms > 0)
|
2015-09-22 16:55:14 +00:00
|
|
|
retro_sleep(sleep_ms);
|
2018-10-15 01:38:15 +00:00
|
|
|
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_check();
|
2018-10-15 01:38:15 +00:00
|
|
|
|
2015-08-27 12:52:02 +00:00
|
|
|
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002, FALSE) == kCFRunLoopRunHandledSource);
|
2016-09-30 06:17:18 +00:00
|
|
|
if (ret == -1)
|
2018-10-15 01:38:15 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_QT
|
|
|
|
ui_application_qt.quit();
|
|
|
|
#endif
|
2016-09-30 06:17:18 +00:00
|
|
|
break;
|
2018-10-15 01:38:15 +00:00
|
|
|
}
|
2016-09-30 06:17:18 +00:00
|
|
|
}while(1);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
main_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillResignActive:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
|
|
|
NSApplicationTerminateReply reply = NSTerminateNow;
|
|
|
|
|
2016-01-19 22:26:47 +00:00
|
|
|
if (rarch_ctl(RARCH_CTL_IS_INITED, NULL))
|
2015-04-20 15:26:05 +00:00
|
|
|
reply = NSTerminateCancel;
|
|
|
|
|
2018-11-04 16:29:40 +00:00
|
|
|
ui_companion_event_command(CMD_EVENT_QUIT);
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
|
|
|
|
{
|
2019-01-31 21:18:15 +00:00
|
|
|
if (filenames.count == 1 && filenames[0])
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2018-10-30 16:11:07 +00:00
|
|
|
struct retro_system_info *system = runloop_get_libretro_system_info();
|
2019-01-31 21:18:15 +00:00
|
|
|
NSString *__core = filenames[0];
|
2018-10-30 16:11:07 +00:00
|
|
|
const char *core_name = system ? system->library_name : NULL;
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
if (core_name)
|
2016-05-16 10:51:55 +00:00
|
|
|
{
|
2016-05-16 14:25:16 +00:00
|
|
|
content_ctx_info_t content_info = {0};
|
2017-02-21 16:29:30 +00:00
|
|
|
task_push_load_content_with_current_core_from_companion_ui(
|
2016-05-16 10:51:55 +00:00
|
|
|
__core.UTF8String,
|
2016-05-16 14:25:16 +00:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
2016-05-16 10:51:55 +00:00
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
2016-09-29 07:58:57 +00:00
|
|
|
path_set(RARCH_PATH_CONTENT, __core.UTF8String);
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-08 05:19:19 +00:00
|
|
|
const ui_msg_window_t *msg_window = ui_companion_driver_get_msg_window_ptr();
|
|
|
|
if (msg_window)
|
|
|
|
{
|
2016-06-08 05:24:26 +00:00
|
|
|
ui_msg_window_state msg_window_state;
|
|
|
|
msg_window_state.text = strdup("Cannot open multiple files");
|
2018-10-30 18:32:52 +00:00
|
|
|
msg_window_state.title = strdup(msg_hash_to_str(MSG_PROGRAM));
|
2016-06-08 05:19:19 +00:00
|
|
|
msg_window->information(&msg_window_state);
|
2016-06-08 05:24:26 +00:00
|
|
|
|
|
|
|
free(msg_window_state.text);
|
|
|
|
free(msg_window_state.title);
|
2016-06-08 05:19:19 +00:00
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
[sender replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 15:18:48 +00:00
|
|
|
static void open_core_handler(ui_browser_window_state_t *state, bool result)
|
2016-01-17 17:38:08 +00:00
|
|
|
{
|
2017-05-28 15:21:57 +00:00
|
|
|
rarch_system_info_t *info = runloop_get_system_info();
|
2016-06-08 15:18:48 +00:00
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
if (string_is_empty(state->result))
|
|
|
|
return;
|
|
|
|
if (!result)
|
|
|
|
return;
|
|
|
|
|
|
|
|
settings_t *settings = config_get_ptr();
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2017-05-15 03:06:23 +00:00
|
|
|
rarch_ctl(RARCH_CTL_SET_LIBRETRO_PATH, (void*)state->result);
|
2016-06-08 15:18:48 +00:00
|
|
|
ui_companion_event_command(CMD_EVENT_LOAD_CORE);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2017-05-28 15:21:57 +00:00
|
|
|
if (info && info->load_no_content
|
|
|
|
&& settings->bools.set_supports_no_game_enable)
|
2016-06-08 15:18:48 +00:00
|
|
|
{
|
|
|
|
content_ctx_info_t content_info = {0};
|
2016-09-30 02:31:19 +00:00
|
|
|
path_clear(RARCH_PATH_CONTENT);
|
2017-02-21 16:29:30 +00:00
|
|
|
task_push_load_content_with_current_core_from_companion_ui(
|
|
|
|
NULL,
|
2016-06-08 15:18:48 +00:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
2016-01-17 17:38:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 15:51:05 +00:00
|
|
|
static void open_document_handler(ui_browser_window_state_t *state, bool result)
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2016-06-08 15:51:05 +00:00
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
if (string_is_empty(state->result))
|
|
|
|
return;
|
|
|
|
if (!result)
|
|
|
|
return;
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2018-10-30 16:11:07 +00:00
|
|
|
struct retro_system_info *system = runloop_get_libretro_system_info();
|
|
|
|
const char *core_name = system ? system->library_name : NULL;
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-09-29 07:58:57 +00:00
|
|
|
path_set(RARCH_PATH_CONTENT, state->result);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:51:05 +00:00
|
|
|
if (core_name)
|
|
|
|
{
|
|
|
|
content_ctx_info_t content_info = {0};
|
2017-02-21 16:30:18 +00:00
|
|
|
task_push_load_content_with_current_core_from_companion_ui(
|
2017-02-21 16:29:30 +00:00
|
|
|
NULL,
|
2016-06-08 15:51:05 +00:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
2016-01-17 17:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-17 17:43:24 +00:00
|
|
|
- (IBAction)openCore:(id)sender {
|
2016-06-08 15:18:48 +00:00
|
|
|
const ui_browser_window_t *browser = ui_companion_driver_get_browser_window_ptr();
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:18:48 +00:00
|
|
|
if (browser)
|
|
|
|
{
|
|
|
|
ui_browser_window_state_t browser_state;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:18:48 +00:00
|
|
|
browser_state.filters = strdup("dylib");
|
2018-10-30 18:32:52 +00:00
|
|
|
browser_state.filters_title = strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_SETTINGS));
|
|
|
|
browser_state.title = strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_LIST));
|
2017-04-29 00:00:50 +00:00
|
|
|
browser_state.startdir = strdup(settings->paths.directory_libretro);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:18:48 +00:00
|
|
|
bool result = browser->open(&browser_state);
|
|
|
|
open_core_handler(&browser_state, result);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:18:48 +00:00
|
|
|
free(browser_state.filters);
|
|
|
|
free(browser_state.filters_title);
|
|
|
|
free(browser_state.title);
|
|
|
|
free(browser_state.startdir);
|
|
|
|
}
|
2016-01-17 17:43:24 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 17:42:52 +00:00
|
|
|
- (void)openDocument:(id)sender
|
|
|
|
{
|
2016-06-08 15:54:42 +00:00
|
|
|
const ui_browser_window_t *browser = ui_companion_driver_get_browser_window_ptr();
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:51:05 +00:00
|
|
|
if (browser)
|
|
|
|
{
|
2016-06-12 17:29:07 +00:00
|
|
|
ui_browser_window_state_t browser_state = {{0}};
|
2016-06-09 08:57:02 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2017-04-29 00:00:50 +00:00
|
|
|
NSString *startdir = BOXSTRING(settings->paths.directory_menu_content);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-09 08:57:02 +00:00
|
|
|
if (!startdir.length)
|
|
|
|
startdir = BOXSTRING("/");
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2018-10-30 18:32:52 +00:00
|
|
|
browser_state.title = strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_LOAD_CONTENT_LIST));
|
2016-06-08 15:51:05 +00:00
|
|
|
browser_state.startdir = strdup([startdir UTF8String]);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:51:05 +00:00
|
|
|
bool result = browser->open(&browser_state);
|
|
|
|
open_document_handler(&browser_state, result);
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2016-06-08 15:56:09 +00:00
|
|
|
free(browser_state.startdir);
|
2016-06-08 15:51:05 +00:00
|
|
|
free(browser_state.title);
|
|
|
|
}
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unloadingCore
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showCoresDirectory:(id)sender
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
2017-04-29 00:00:50 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openFile:BOXSTRING(settings->paths.directory_libretro)];
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showPreferences:(id)sender
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)basicEvent:(id)sender
|
|
|
|
{
|
2015-04-20 16:46:55 +00:00
|
|
|
enum event_command cmd;
|
2015-04-20 15:26:05 +00:00
|
|
|
unsigned sender_tag = (unsigned)[sender tag];
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
switch (sender_tag)
|
|
|
|
{
|
|
|
|
case 1:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_RESET;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_LOAD_STATE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_SAVE_STATE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_DISK_EJECT_TOGGLE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_DISK_PREV;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_DISK_NEXT;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_GRAB_MOUSE_TOGGLE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_MENU_TOGGLE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 9:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_PAUSE_TOGGLE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
case 20:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_FULLSCREEN_TOGGLE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_NONE;
|
2015-04-20 15:26:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
if (sender_tag >= 10 && sender_tag <= 19)
|
|
|
|
{
|
|
|
|
unsigned idx = (sender_tag - (10-1));
|
2017-05-15 03:06:23 +00:00
|
|
|
rarch_ctl(RARCH_CTL_SET_WINDOWED_SCALE, &idx);
|
2016-05-09 18:51:53 +00:00
|
|
|
cmd = CMD_EVENT_RESIZE_WINDOWED_SCALE;
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 16:43:08 +00:00
|
|
|
ui_companion_event_command(cmd);
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alertDidEnd:(NSAlert *)alert returnCode:(int32_t)returnCode contextInfo:(void *)contextInfo
|
|
|
|
{
|
|
|
|
[[NSApplication sharedApplication] stopModal];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-01-17 15:26:04 +00:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
if (argv[1] != '\0')
|
|
|
|
if (!strncmp(argv[1], "-psn", 4))
|
|
|
|
argc = 1;
|
|
|
|
}
|
2018-04-30 18:33:05 +00:00
|
|
|
|
2015-07-25 13:45:22 +00:00
|
|
|
waiting_argc = argc;
|
|
|
|
waiting_argv = argv;
|
2016-01-17 14:55:30 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
return NSApplicationMain(argc, (const char **) argv);
|
|
|
|
}
|
2015-04-20 10:43:07 +00:00
|
|
|
|
|
|
|
typedef struct ui_companion_cocoa
|
|
|
|
{
|
|
|
|
void *empty;
|
|
|
|
} ui_companion_cocoa_t;
|
|
|
|
|
|
|
|
static void ui_companion_cocoa_notify_content_loaded(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:33:05 +00:00
|
|
|
static void ui_companion_cocoa_toggle(void *data, bool force)
|
2015-04-20 10:43:07 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2018-04-30 18:33:05 +00:00
|
|
|
(void)force;
|
2015-04-20 10:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ui_companion_cocoa_iterate(void *data, unsigned action)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_companion_cocoa_deinit(void *data)
|
|
|
|
{
|
|
|
|
ui_companion_cocoa_t *handle = (ui_companion_cocoa_t*)data;
|
|
|
|
|
2016-06-04 16:09:40 +00:00
|
|
|
app_terminate();
|
2015-04-20 15:10:28 +00:00
|
|
|
|
2015-04-20 10:43:07 +00:00
|
|
|
if (handle)
|
|
|
|
free(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ui_companion_cocoa_init(void)
|
|
|
|
{
|
|
|
|
ui_companion_cocoa_t *handle = (ui_companion_cocoa_t*)calloc(1, sizeof(*handle));
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2015-04-20 16:38:47 +00:00
|
|
|
static void ui_companion_cocoa_event_command(void *data, enum event_command cmd)
|
2015-04-20 10:43:07 +00:00
|
|
|
{
|
2015-04-20 16:53:02 +00:00
|
|
|
(void)data;
|
2018-11-04 16:29:40 +00:00
|
|
|
command_event(cmd, NULL);
|
2015-04-20 10:43:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 07:56:13 +00:00
|
|
|
static void ui_companion_cocoa_notify_list_pushed(void *data,
|
|
|
|
file_list_t *list, file_list_t *menu_list)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)list;
|
|
|
|
(void)menu_list;
|
|
|
|
}
|
|
|
|
|
2016-06-12 17:29:07 +00:00
|
|
|
static void *ui_companion_cocoa_get_main_window(void *data)
|
|
|
|
{
|
2018-11-04 16:29:40 +00:00
|
|
|
return ((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]).window;
|
2016-06-12 17:29:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 18:33:05 +00:00
|
|
|
ui_companion_driver_t ui_companion_cocoa = {
|
2015-04-20 10:43:07 +00:00
|
|
|
ui_companion_cocoa_init,
|
|
|
|
ui_companion_cocoa_deinit,
|
|
|
|
ui_companion_cocoa_iterate,
|
|
|
|
ui_companion_cocoa_toggle,
|
|
|
|
ui_companion_cocoa_event_command,
|
|
|
|
ui_companion_cocoa_notify_content_loaded,
|
2015-05-11 07:56:13 +00:00
|
|
|
ui_companion_cocoa_notify_list_pushed,
|
2018-08-31 23:14:26 +00:00
|
|
|
NULL, /* notify_refresh */
|
|
|
|
NULL, /* msg_queue_push */
|
|
|
|
NULL, /* render_messagebox */
|
2016-06-12 17:29:07 +00:00
|
|
|
ui_companion_cocoa_get_main_window,
|
2018-08-31 23:14:26 +00:00
|
|
|
NULL, /* log_msg */
|
2016-06-08 13:51:43 +00:00
|
|
|
&ui_browser_window_cocoa,
|
2016-06-08 04:33:15 +00:00
|
|
|
&ui_msg_window_cocoa,
|
2016-06-04 05:56:28 +00:00
|
|
|
&ui_window_cocoa,
|
2016-06-07 14:51:25 +00:00
|
|
|
&ui_application_cocoa,
|
2015-04-20 10:43:07 +00:00
|
|
|
"cocoa",
|
|
|
|
};
|