2015-04-12 01:02:48 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-06-04 02:24:54 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-04-12 01:02:48 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-12 01:02:48 +00:00
|
|
|
#include <file/file_path.h>
|
2016-05-16 15:29:02 +00:00
|
|
|
#include <queues/task_queue.h>
|
2017-05-16 02:00:37 +00:00
|
|
|
#include <string/stdstring.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-12 01:02:48 +00:00
|
|
|
#include "../ui_companion_driver.h"
|
2017-05-13 19:06:57 +00:00
|
|
|
#include "../../configuration.h"
|
|
|
|
#include "../../frontend/frontend.h"
|
2015-04-20 15:26:05 +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-08-15 00:59:36 +00:00
|
|
|
#include "../../retroarch.h"
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2015-12-06 17:18:50 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_setting.h"
|
|
|
|
#endif
|
|
|
|
|
2015-08-15 00:42:04 +00:00
|
|
|
static char msg_old[PATH_MAX_LENGTH];
|
2018-06-21 06:37:08 +00:00
|
|
|
id<ApplePlatform> apple_platform;
|
2015-04-20 15:26:05 +00:00
|
|
|
static CFRunLoopObserverRef iterate_observer;
|
|
|
|
|
2015-04-21 09:51:35 +00:00
|
|
|
/* forward declaration */
|
2016-06-04 16:10:52 +00:00
|
|
|
static void apple_rarch_exited(void);
|
2015-04-21 09:51:35 +00:00
|
|
|
|
2015-08-05 09:41:41 +00:00
|
|
|
static void rarch_enable_ui(void)
|
|
|
|
{
|
2016-01-18 20:35:09 +00:00
|
|
|
bool boolean = true;
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-18 01:51:28 +00:00
|
|
|
[[RetroArch_iOS get] supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-09-26 11:20:15 +00:00
|
|
|
|
2015-08-05 11:56:59 +00:00
|
|
|
ui_companion_set_foreground(true);
|
2015-09-26 11:20:15 +00:00
|
|
|
|
2017-05-15 03:06:23 +00:00
|
|
|
rarch_ctl(RARCH_CTL_SET_PAUSED, &boolean);
|
|
|
|
rarch_ctl(RARCH_CTL_SET_IDLE, &boolean);
|
2017-05-15 02:31:40 +00:00
|
|
|
rarch_menu_running();
|
2015-08-05 09:41:41 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 10:06:37 +00:00
|
|
|
static void rarch_disable_ui(void)
|
|
|
|
{
|
2015-09-26 11:20:15 +00:00
|
|
|
bool boolean = false;
|
|
|
|
|
2015-08-05 11:56:59 +00:00
|
|
|
ui_companion_set_foreground(false);
|
2015-09-26 11:20:15 +00:00
|
|
|
|
2017-05-15 03:06:23 +00:00
|
|
|
rarch_ctl(RARCH_CTL_SET_PAUSED, &boolean);
|
|
|
|
rarch_ctl(RARCH_CTL_SET_IDLE, &boolean);
|
2017-05-15 02:31:40 +00:00
|
|
|
rarch_menu_running_finished();
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-18 01:51:28 +00:00
|
|
|
[[RetroArch_iOS get] supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-08-05 10:06:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:24:53 +00:00
|
|
|
static void ui_companion_cocoatouch_event_command(
|
|
|
|
void *data, enum event_command cmd)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2015-08-21 02:42:38 +00:00
|
|
|
static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
|
|
|
CFRunLoopActivity activity, void *info)
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
2015-08-27 12:52:02 +00:00
|
|
|
unsigned sleep_ms = 0;
|
2016-10-22 15:41:26 +00:00
|
|
|
int ret = runloop_iterate(&sleep_ms);
|
2015-07-08 22:01:55 +00:00
|
|
|
|
2015-08-27 12:52:02 +00:00
|
|
|
if (ret == 1 && !ui_companion_is_on_foreground() && sleep_ms > 0)
|
2015-09-22 16:55:14 +00:00
|
|
|
retro_sleep(sleep_ms);
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_check();
|
2015-07-08 22:01:55 +00:00
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
2016-05-09 18:51:53 +00:00
|
|
|
ui_companion_cocoatouch_event_command(NULL, CMD_EVENT_MENU_SAVE_CURRENT_CONFIG);
|
2015-07-08 22:01:55 +00:00
|
|
|
main_exit(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-15 03:06:23 +00:00
|
|
|
if (rarch_ctl(RARCH_CTL_IS_IDLE, NULL))
|
2015-07-08 22:01:55 +00:00
|
|
|
return;
|
|
|
|
CFRunLoopWakeUp(CFRunLoopGetMain());
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
apple_frontend_settings_t apple_frontend_settings;
|
|
|
|
|
|
|
|
void get_ios_version(int *major, int *minor)
|
|
|
|
{
|
|
|
|
NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
|
|
|
|
|
|
|
|
if (major && decomposed_os_version.count > 0)
|
2017-02-26 09:33:03 +00:00
|
|
|
*major = (int)[decomposed_os_version[0] integerValue];
|
2015-04-20 15:26:05 +00:00
|
|
|
if (minor && decomposed_os_version.count > 1)
|
2017-02-26 09:33:03 +00:00
|
|
|
*minor = (int)[decomposed_os_version[1] integerValue];
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern float cocoagl_gfx_ctx_get_native_scale(void);
|
|
|
|
|
|
|
|
/* Input helpers: This is kept here because it needs ObjC */
|
|
|
|
static void handle_touch_event(NSArray* touches)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2015-11-29 17:18:25 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_driver_get_data();
|
2015-04-20 15:26:05 +00:00
|
|
|
float scale = cocoagl_gfx_ctx_get_native_scale();
|
|
|
|
|
|
|
|
if (!apple)
|
|
|
|
return;
|
|
|
|
|
|
|
|
apple->touch_count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++)
|
|
|
|
{
|
|
|
|
CGPoint coord;
|
|
|
|
UITouch *touch = [touches objectAtIndex:i];
|
|
|
|
|
2015-04-20 18:39:39 +00:00
|
|
|
if (touch.view != [CocoaView get].view)
|
2015-04-20 15:26:05 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
coord = [touch locationInView:[touch view]];
|
|
|
|
|
|
|
|
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled)
|
|
|
|
{
|
|
|
|
apple->touches[apple->touch_count ].screen_x = coord.x * scale;
|
|
|
|
apple->touches[apple->touch_count ++].screen_y = coord.y * scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 06:05:14 +00:00
|
|
|
#ifndef HAVE_APPLE_STORE
|
2015-04-20 15:26:05 +00:00
|
|
|
// iO7 Keyboard support
|
|
|
|
@interface UIEvent(iOS7Keyboard)
|
|
|
|
@property(readonly, nonatomic) long long _keyCode;
|
|
|
|
@property(readonly, nonatomic) _Bool _isKeyDown;
|
|
|
|
@property(retain, nonatomic) NSString *_privateInput;
|
|
|
|
@property(nonatomic) long long _modifierFlags;
|
|
|
|
- (struct __IOHIDEvent { }*)_hidEvent;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface UIApplication(iOS7Keyboard)
|
2015-12-27 00:38:02 +00:00
|
|
|
- (void)handleKeyUIEvent:(UIEvent*)event;
|
2015-04-20 15:26:05 +00:00
|
|
|
- (id)_keyCommandForEvent:(UIEvent*)event;
|
|
|
|
@end
|
2017-02-26 06:05:14 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
@interface RApplication : UIApplication
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RApplication
|
|
|
|
|
2017-02-26 06:05:14 +00:00
|
|
|
#ifndef HAVE_APPLE_STORE
|
2015-04-20 15:26:05 +00:00
|
|
|
/* Keyboard handler for iOS 7. */
|
|
|
|
|
|
|
|
/* This is copied here as it isn't
|
|
|
|
* defined in any standard iOS header */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NSAlphaShiftKeyMask = 1 << 16,
|
|
|
|
NSShiftKeyMask = 1 << 17,
|
|
|
|
NSControlKeyMask = 1 << 18,
|
|
|
|
NSAlternateKeyMask = 1 << 19,
|
|
|
|
NSCommandKeyMask = 1 << 20,
|
|
|
|
NSNumericPadKeyMask = 1 << 21,
|
|
|
|
NSHelpKeyMask = 1 << 22,
|
|
|
|
NSFunctionKeyMask = 1 << 23,
|
|
|
|
NSDeviceIndependentModifierFlagsMask = 0xffff0000U
|
|
|
|
};
|
|
|
|
|
2015-12-27 00:38:02 +00:00
|
|
|
// This is specifically for iOS 9, according to the private headers
|
|
|
|
-(void)handleKeyUIEvent:(UIEvent *)event {
|
|
|
|
/* This gets called twice with the same timestamp
|
|
|
|
* for each keypress, that's fine for polling
|
|
|
|
* but is bad for business with events. */
|
|
|
|
static double last_time_stamp;
|
|
|
|
|
2017-01-17 18:04:42 +00:00
|
|
|
if (last_time_stamp == event.timestamp)
|
|
|
|
return [super handleKeyUIEvent:event];
|
2015-12-27 00:38:02 +00:00
|
|
|
|
|
|
|
last_time_stamp = event.timestamp;
|
|
|
|
|
|
|
|
/* If the _hidEvent is null, [event _keyCode] will crash.
|
|
|
|
* (This happens with the on screen keyboard). */
|
|
|
|
if (event._hidEvent)
|
|
|
|
{
|
|
|
|
NSString *ch = (NSString*)event._privateInput;
|
|
|
|
uint32_t character = 0;
|
|
|
|
uint32_t mod = 0;
|
|
|
|
|
|
|
|
mod |= (event._modifierFlags & NSAlphaShiftKeyMask) ? RETROKMOD_CAPSLOCK : 0;
|
|
|
|
mod |= (event._modifierFlags & NSShiftKeyMask ) ? RETROKMOD_SHIFT : 0;
|
|
|
|
mod |= (event._modifierFlags & NSControlKeyMask ) ? RETROKMOD_CTRL : 0;
|
|
|
|
mod |= (event._modifierFlags & NSAlternateKeyMask ) ? RETROKMOD_ALT : 0;
|
|
|
|
mod |= (event._modifierFlags & NSCommandKeyMask ) ? RETROKMOD_META : 0;
|
|
|
|
mod |= (event._modifierFlags & NSNumericPadKeyMask) ? RETROKMOD_NUMLOCK : 0;
|
|
|
|
|
|
|
|
if (ch && ch.length != 0)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
character = [ch characterAtIndex:0];
|
|
|
|
|
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
|
|
|
(uint32_t)event._keyCode, 0, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
|
|
|
|
for (i = 1; i < ch.length; i++)
|
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
|
|
|
0, [ch characterAtIndex:i], mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
|
|
|
(uint32_t)event._keyCode, character, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
[super handleKeyUIEvent:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is for iOS versions < 9.0
|
2015-04-20 15:26:05 +00:00
|
|
|
- (id)_keyCommandForEvent:(UIEvent*)event
|
|
|
|
{
|
|
|
|
/* This gets called twice with the same timestamp
|
|
|
|
* for each keypress, that's fine for polling
|
|
|
|
* but is bad for business with events. */
|
|
|
|
static double last_time_stamp;
|
|
|
|
|
|
|
|
if (last_time_stamp == event.timestamp)
|
|
|
|
return [super _keyCommandForEvent:event];
|
|
|
|
last_time_stamp = event.timestamp;
|
|
|
|
|
|
|
|
/* If the _hidEvent is null, [event _keyCode] will crash.
|
|
|
|
* (This happens with the on screen keyboard). */
|
|
|
|
if (event._hidEvent)
|
|
|
|
{
|
|
|
|
NSString *ch = (NSString*)event._privateInput;
|
|
|
|
uint32_t character = 0;
|
|
|
|
uint32_t mod = 0;
|
|
|
|
|
|
|
|
mod |= (event._modifierFlags & NSAlphaShiftKeyMask) ? RETROKMOD_CAPSLOCK : 0;
|
|
|
|
mod |= (event._modifierFlags & NSShiftKeyMask ) ? RETROKMOD_SHIFT : 0;
|
|
|
|
mod |= (event._modifierFlags & NSControlKeyMask ) ? RETROKMOD_CTRL : 0;
|
|
|
|
mod |= (event._modifierFlags & NSAlternateKeyMask ) ? RETROKMOD_ALT : 0;
|
|
|
|
mod |= (event._modifierFlags & NSCommandKeyMask ) ? RETROKMOD_META : 0;
|
|
|
|
mod |= (event._modifierFlags & NSNumericPadKeyMask) ? RETROKMOD_NUMLOCK : 0;
|
|
|
|
|
|
|
|
if (ch && ch.length != 0)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
character = [ch characterAtIndex:0];
|
|
|
|
|
2015-11-29 15:26:13 +00:00
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
2015-04-20 15:26:05 +00:00
|
|
|
(uint32_t)event._keyCode, 0, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
|
|
|
|
for (i = 1; i < ch.length; i++)
|
2015-11-29 15:26:13 +00:00
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
2015-04-20 15:26:05 +00:00
|
|
|
0, [ch characterAtIndex:i], mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
2015-11-29 15:26:13 +00:00
|
|
|
apple_input_keyboard_event(event._isKeyDown,
|
2015-04-20 15:26:05 +00:00
|
|
|
(uint32_t)event._keyCode, character, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super _keyCommandForEvent:event];
|
|
|
|
}
|
2017-02-26 06:05:14 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
#define GSEVENT_TYPE_KEYDOWN 10
|
|
|
|
#define GSEVENT_TYPE_KEYUP 11
|
|
|
|
|
|
|
|
- (void)sendEvent:(UIEvent *)event
|
|
|
|
{
|
|
|
|
int major, minor;
|
|
|
|
[super sendEvent:event];
|
|
|
|
|
|
|
|
if (event.allTouches.count)
|
|
|
|
handle_touch_event(event.allTouches.allObjects);
|
|
|
|
|
|
|
|
get_ios_version(&major, &minor);
|
|
|
|
|
2016-07-10 19:02:40 +00:00
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000
|
2015-04-20 15:26:05 +00:00
|
|
|
if ((major < 7) && [event respondsToSelector:@selector(_gsEvent)])
|
|
|
|
{
|
|
|
|
/* Keyboard event hack for iOS versions prior to iOS 7.
|
|
|
|
*
|
|
|
|
* Derived from:
|
|
|
|
* http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
|
|
|
*/
|
|
|
|
const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
|
|
|
|
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
|
|
|
|
|
|
|
switch (eventType)
|
|
|
|
{
|
|
|
|
case GSEVENT_TYPE_KEYDOWN:
|
2015-11-29 15:26:13 +00:00
|
|
|
case GSEVENT_TYPE_KEYUP:
|
|
|
|
apple_input_keyboard_event(eventType == GSEVENT_TYPE_KEYDOWN,
|
2015-04-20 15:26:05 +00:00
|
|
|
*(uint16_t*)&eventMem[0x3C], 0, 0, RETRO_DEVICE_KEYBOARD);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-10 19:02:40 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RetroArch_iOS
|
|
|
|
|
|
|
|
+ (RetroArch_iOS*)get
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
|
|
|
/* Implicitly initializes your audio session. */
|
2016-01-18 01:51:28 +00:00
|
|
|
[(RetroArch_iOS*)[[UIApplication sharedApplication] delegate] supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate];
|
|
|
|
}
|
|
|
|
|
2018-03-23 08:43:20 +00:00
|
|
|
-(NSString*)documentsDirectory {
|
|
|
|
if ( _documentsDirectory == nil ) {
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
_documentsDirectory = paths.firstObject;
|
|
|
|
}
|
|
|
|
return _documentsDirectory;
|
|
|
|
}
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
|
|
|
{
|
2016-04-05 18:58:17 +00:00
|
|
|
char arguments[] = "retroarch";
|
|
|
|
char *argv[] = {arguments, NULL};
|
2016-04-05 18:53:02 +00:00
|
|
|
int argc = 1;
|
|
|
|
apple_platform = self;
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
[self setDelegate:self];
|
2016-01-16 21:02:49 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
/* Other background audio check */
|
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
/* Setup window */
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|
|
|
[self.window makeKeyAndVisible];
|
|
|
|
|
2015-05-12 14:45:26 +00:00
|
|
|
self.mainmenu = [RAMainMenu new];
|
2015-09-21 20:52:28 +00:00
|
|
|
self.mainmenu.last_menu = self.mainmenu;
|
|
|
|
[self pushViewController:self.mainmenu animated:NO];
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2015-04-20 21:16:35 +00:00
|
|
|
[self refreshSystemConfig];
|
|
|
|
[self showGameView];
|
2016-01-16 21:02:49 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2016-04-05 19:22:23 +00:00
|
|
|
if (rarch_main(argc, argv, NULL))
|
2015-04-20 15:26:05 +00:00
|
|
|
apple_rarch_exited();
|
|
|
|
|
2015-05-17 10:22:41 +00:00
|
|
|
iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
|
|
|
true, 0, rarch_draw_observer, 0);
|
|
|
|
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes);
|
2015-11-16 01:39:38 +00:00
|
|
|
|
2015-08-14 00:50:48 +00:00
|
|
|
#ifdef HAVE_MFI
|
2015-11-16 01:39:38 +00:00
|
|
|
extern bool apple_gamecontroller_joypad_init(void *data);
|
|
|
|
apple_gamecontroller_joypad_init(NULL);
|
2015-08-14 00:50:48 +00:00
|
|
|
#endif
|
2018-03-23 08:43:20 +00:00
|
|
|
|
2015-05-17 10:22:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application
|
|
|
|
{
|
2015-08-14 00:48:36 +00:00
|
|
|
CFRunLoopObserverInvalidate(iterate_observer);
|
|
|
|
CFRelease(iterate_observer);
|
|
|
|
iterate_observer = NULL;
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
2016-01-16 18:25:57 +00:00
|
|
|
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2017-04-27 22:53:06 +00:00
|
|
|
if (settings->bools.ui_companion_start_on_boot)
|
2015-04-20 15:26:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
[self showGameView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(),
|
|
|
|
^{
|
2016-05-09 18:51:53 +00:00
|
|
|
ui_companion_cocoatouch_event_command(NULL, CMD_EVENT_MENU_SAVE_CURRENT_CONFIG);
|
2015-04-20 15:26:05 +00:00
|
|
|
});
|
|
|
|
[self showPauseMenu: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
|
|
|
{
|
|
|
|
NSString *filename = (NSString*)url.path.lastPathComponent;
|
|
|
|
NSError *error = nil;
|
2016-01-16 18:25:57 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
[[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error];
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
printf("%s\n", [[error description] UTF8String]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
|
|
|
|
{
|
|
|
|
[self setToolbarHidden:![[viewController toolbarItems] count] animated:YES];
|
|
|
|
[self refreshSystemConfig];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showGameView
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
|
|
|
/* implicitly initializes your audio session */
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
[self popToRootViewControllerAnimated:NO];
|
|
|
|
[self setToolbarHidden:true animated:NO];
|
|
|
|
[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationNone];
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:true];
|
2015-04-20 18:39:39 +00:00
|
|
|
[self.window setRootViewController:[CocoaView get]];
|
2015-04-20 15:26:05 +00:00
|
|
|
|
2016-05-09 18:51:53 +00:00
|
|
|
ui_companion_cocoatouch_event_command(NULL, CMD_EVENT_AUDIO_START);
|
2015-08-05 10:06:37 +00:00
|
|
|
rarch_disable_ui();
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showPauseMenu:(id)sender
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifndef HAVE_AVFOUNDATION
|
2016-05-09 18:51:53 +00:00
|
|
|
ui_companion_cocoatouch_event_command(NULL, CMD_EVENT_AUDIO_STOP);
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-08-05 09:41:41 +00:00
|
|
|
rarch_enable_ui();
|
2015-04-20 15:26:05 +00:00
|
|
|
|
|
|
|
[[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone];
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:false];
|
|
|
|
[self.window setRootViewController:self];
|
|
|
|
}
|
|
|
|
|
2015-08-22 21:28:17 +00:00
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
- (void)toggleUI
|
|
|
|
{
|
2015-08-05 11:56:59 +00:00
|
|
|
if (ui_companion_is_on_foreground())
|
2015-04-20 15:26:05 +00:00
|
|
|
{
|
|
|
|
[self showGameView];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self showPauseMenu:self];
|
|
|
|
}
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[self supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)refreshSystemConfig
|
|
|
|
{
|
|
|
|
/* Get enabled orientations */
|
|
|
|
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskAll;
|
|
|
|
|
2018-01-16 21:53:38 +00:00
|
|
|
if (string_is_equal(apple_frontend_settings.orientations, "landscape"))
|
2015-04-20 15:26:05 +00:00
|
|
|
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskLandscape;
|
2018-01-16 21:53:38 +00:00
|
|
|
else if (string_is_equal(apple_frontend_settings.orientations, "portrait"))
|
2017-05-16 02:00:37 +00:00
|
|
|
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskPortrait
|
|
|
|
| UIInterfaceOrientationMaskPortraitUpsideDown;
|
2015-04-20 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:52:28 +00:00
|
|
|
- (void)mainMenuRefresh
|
2015-05-12 14:45:26 +00:00
|
|
|
{
|
2015-05-14 20:18:32 +00:00
|
|
|
[self.mainmenu reloadData];
|
2015-05-12 14:45:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:52:28 +00:00
|
|
|
- (void)mainMenuPushPop: (bool)pushp
|
|
|
|
{
|
2017-01-17 18:04:42 +00:00
|
|
|
if ( pushp )
|
|
|
|
{
|
|
|
|
self.menu_count++;
|
|
|
|
RAMenuBase* next_menu = [RAMainMenu new];
|
|
|
|
next_menu.last_menu = self.mainmenu;
|
|
|
|
self.mainmenu = next_menu;
|
|
|
|
[self pushViewController:self.mainmenu animated:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( self.menu_count == 0 )
|
|
|
|
[self.mainmenu reloadData];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.menu_count--;
|
|
|
|
|
|
|
|
[self popViewControllerAnimated:YES];
|
|
|
|
self.mainmenu = self.mainmenu.last_menu;
|
|
|
|
}
|
2015-09-21 20:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 18:25:57 +00:00
|
|
|
- (void)supportOtherAudioSessions
|
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
|
|
|
/* implicitly initializes your audio session */
|
2016-01-16 18:25:57 +00:00
|
|
|
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
|
|
|
|
[audioSession setCategory: AVAudioSessionCategoryAmbient error: nil];
|
|
|
|
[audioSession setActive:YES error:nil];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2016-01-16 18:25:57 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 00:42:04 +00:00
|
|
|
- (void)mainMenuRenderMessageBox:(NSString *)msg
|
|
|
|
{
|
|
|
|
[self.mainmenu renderMessageBox:msg];
|
|
|
|
}
|
|
|
|
|
2015-04-20 15:26:05 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
return UIApplicationMain(argc, argv, NSStringFromClass([RApplication class]), NSStringFromClass([RetroArch_iOS class]));
|
|
|
|
}
|
|
|
|
}
|
2015-04-12 01:02:48 +00:00
|
|
|
|
2016-06-08 05:19:19 +00:00
|
|
|
#if 0
|
|
|
|
static void apple_display_alert(const char *message, const char *title)
|
2015-04-20 16:10:15 +00:00
|
|
|
{
|
|
|
|
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:BOXSTRING(title)
|
|
|
|
message:BOXSTRING(message)
|
|
|
|
delegate:nil
|
|
|
|
cancelButtonTitle:BOXSTRING("OK")
|
|
|
|
otherButtonTitles:nil];
|
|
|
|
[alert show];
|
|
|
|
}
|
2016-06-08 05:19:19 +00:00
|
|
|
#endif
|
2015-04-20 16:10:15 +00:00
|
|
|
|
2016-06-04 16:10:52 +00:00
|
|
|
static void apple_rarch_exited(void)
|
2015-04-21 09:51:35 +00:00
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
|
|
|
|
|
|
|
if (!ap)
|
|
|
|
return;
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 18:25:57 +00:00
|
|
|
[ap supportOtherAudioSessions];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-21 09:51:35 +00:00
|
|
|
[ap showPauseMenu:ap];
|
|
|
|
}
|
|
|
|
|
2015-04-12 01:02:48 +00:00
|
|
|
typedef struct ui_companion_cocoatouch
|
|
|
|
{
|
|
|
|
void *empty;
|
|
|
|
} ui_companion_cocoatouch_t;
|
|
|
|
|
2015-04-12 02:03:27 +00:00
|
|
|
static void ui_companion_cocoatouch_notify_content_loaded(void *data)
|
2015-04-12 01:02:48 +00:00
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
2015-08-14 00:48:36 +00:00
|
|
|
|
|
|
|
(void)data;
|
|
|
|
|
2015-04-12 02:03:27 +00:00
|
|
|
if (ap)
|
|
|
|
[ap showGameView];
|
2015-04-12 01:02:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 23:07:14 +00:00
|
|
|
static void ui_companion_cocoatouch_toggle(void *data, bool force)
|
2015-04-12 23:55:35 +00:00
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
|
|
|
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
if (ap)
|
|
|
|
[ap toggleUI];
|
|
|
|
}
|
|
|
|
|
2015-04-12 01:18:37 +00:00
|
|
|
static int ui_companion_cocoatouch_iterate(void *data, unsigned action)
|
2015-04-12 01:02:48 +00:00
|
|
|
{
|
2015-08-14 00:48:36 +00:00
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS*)apple_platform;
|
2015-04-12 01:02:48 +00:00
|
|
|
|
2015-08-14 00:48:36 +00:00
|
|
|
(void)data;
|
|
|
|
|
|
|
|
if (ap)
|
|
|
|
[ap showPauseMenu:ap];
|
2015-04-12 01:02:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_companion_cocoatouch_deinit(void *data)
|
|
|
|
{
|
|
|
|
ui_companion_cocoatouch_t *handle = (ui_companion_cocoatouch_t*)data;
|
|
|
|
|
2015-04-20 15:10:28 +00:00
|
|
|
apple_rarch_exited();
|
|
|
|
|
2015-04-12 01:02:48 +00:00
|
|
|
if (handle)
|
|
|
|
free(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ui_companion_cocoatouch_init(void)
|
|
|
|
{
|
2015-04-20 16:25:37 +00:00
|
|
|
ui_companion_cocoatouch_t *handle = (ui_companion_cocoatouch_t*)
|
|
|
|
calloc(1, sizeof(*handle));
|
2015-04-12 01:02:48 +00:00
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
2015-08-05 09:41:41 +00:00
|
|
|
|
|
|
|
rarch_enable_ui();
|
2015-04-12 01:02:48 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2015-09-21 20:52:28 +00:00
|
|
|
static size_t old_size = 0;
|
2015-12-06 17:18:50 +00:00
|
|
|
|
2015-05-11 07:56:13 +00:00
|
|
|
static void ui_companion_cocoatouch_notify_list_pushed(void *data,
|
|
|
|
file_list_t *list, file_list_t *menu_list)
|
|
|
|
{
|
2015-08-30 11:03:34 +00:00
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
2017-01-17 18:04:42 +00:00
|
|
|
bool pushp = false;
|
|
|
|
size_t new_size = file_list_get_size( menu_list );
|
2015-09-21 21:32:06 +00:00
|
|
|
|
|
|
|
/* FIXME workaround for the double call */
|
|
|
|
if ( old_size == 0 )
|
|
|
|
{
|
|
|
|
old_size = new_size;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-17 18:04:42 +00:00
|
|
|
if ( old_size == new_size )
|
2015-09-21 20:52:28 +00:00
|
|
|
pushp = false;
|
2017-01-17 18:04:42 +00:00
|
|
|
else if ( old_size < new_size )
|
2015-09-21 20:52:28 +00:00
|
|
|
pushp = true;
|
2017-01-17 18:04:42 +00:00
|
|
|
else if ( old_size > new_size )
|
2015-09-21 20:52:28 +00:00
|
|
|
printf( "notify_list_pushed: old size should not be larger\n" );
|
2017-01-17 18:04:42 +00:00
|
|
|
|
2015-09-21 20:52:28 +00:00
|
|
|
old_size = new_size;
|
|
|
|
|
2015-08-30 11:03:34 +00:00
|
|
|
if (ap)
|
2015-09-21 20:52:28 +00:00
|
|
|
[ap mainMenuPushPop: pushp];
|
2015-08-30 11:03:34 +00:00
|
|
|
}
|
2015-05-12 14:45:26 +00:00
|
|
|
|
2015-08-30 11:03:34 +00:00
|
|
|
static void ui_companion_cocoatouch_notify_refresh(void *data)
|
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
|
|
|
|
|
|
|
if (ap)
|
2015-09-21 20:52:28 +00:00
|
|
|
[ap mainMenuRefresh];
|
2015-05-11 07:56:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 00:42:04 +00:00
|
|
|
static void ui_companion_cocoatouch_render_messagebox(const char *msg)
|
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
|
|
|
|
2016-01-20 03:11:25 +00:00
|
|
|
if (ap && !string_is_equal(msg, msg_old))
|
2015-08-15 00:42:04 +00:00
|
|
|
{
|
|
|
|
[ap mainMenuRenderMessageBox: [NSString stringWithUTF8String:msg]];
|
|
|
|
strlcpy(msg_old, msg, sizeof(msg_old));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 23:07:14 +00:00
|
|
|
static void ui_companion_cocoatouch_msg_queue_push(void *data,
|
|
|
|
const char *msg,
|
|
|
|
unsigned priority, unsigned duration, bool flush)
|
2015-09-22 20:50:58 +00:00
|
|
|
{
|
|
|
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
|
|
|
|
|
|
|
if (ap && msg)
|
|
|
|
{
|
|
|
|
[ap.mainmenu msgQueuePush: [NSString stringWithUTF8String:msg]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:33:05 +00:00
|
|
|
ui_companion_driver_t ui_companion_cocoatouch = {
|
2015-04-12 01:02:48 +00:00
|
|
|
ui_companion_cocoatouch_init,
|
|
|
|
ui_companion_cocoatouch_deinit,
|
|
|
|
ui_companion_cocoatouch_iterate,
|
2015-04-12 23:55:35 +00:00
|
|
|
ui_companion_cocoatouch_toggle,
|
2015-04-13 11:46:48 +00:00
|
|
|
ui_companion_cocoatouch_event_command,
|
2015-04-12 02:03:27 +00:00
|
|
|
ui_companion_cocoatouch_notify_content_loaded,
|
2015-05-11 07:56:13 +00:00
|
|
|
ui_companion_cocoatouch_notify_list_pushed,
|
2015-08-30 11:03:34 +00:00
|
|
|
ui_companion_cocoatouch_notify_refresh,
|
2015-09-22 20:50:58 +00:00
|
|
|
ui_companion_cocoatouch_msg_queue_push,
|
2015-08-15 00:42:04 +00:00
|
|
|
ui_companion_cocoatouch_render_messagebox,
|
2018-08-31 23:14:26 +00:00
|
|
|
NULL, /* get_main_window */
|
|
|
|
NULL, /* log_msg */
|
2016-06-08 13:47:00 +00:00
|
|
|
&ui_browser_window_null,
|
2016-06-08 04:29:52 +00:00
|
|
|
&ui_msg_window_null,
|
2016-06-04 02:24:54 +00:00
|
|
|
&ui_window_null,
|
2016-06-07 14:31:35 +00:00
|
|
|
&ui_application_null,
|
2015-04-12 02:03:27 +00:00
|
|
|
"cocoatouch",
|
2015-04-12 01:02:48 +00:00
|
|
|
};
|