2013-03-03 23:50:38 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-01-10 03:33:01 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2013-03-03 23:50:38 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-09-09 18:49:08 +00:00
|
|
|
#include <stdint.h>
|
2013-03-03 23:50:38 +00:00
|
|
|
#include <unistd.h>
|
2013-06-22 17:09:38 +00:00
|
|
|
|
2016-09-11 11:21:56 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-28 01:22:46 +00:00
|
|
|
#include "../input_config.h"
|
2015-11-28 15:22:49 +00:00
|
|
|
#include "../input_joypad_driver.h"
|
2015-01-12 05:16:52 +00:00
|
|
|
#include "../input_keymaps.h"
|
2015-04-19 15:59:45 +00:00
|
|
|
#include "cocoa_input.h"
|
2016-09-05 16:31:32 +00:00
|
|
|
#include "../../configuration.h"
|
2015-01-12 05:16:52 +00:00
|
|
|
#include "../../driver.h"
|
2013-03-03 23:50:38 +00:00
|
|
|
|
2015-11-29 14:52:37 +00:00
|
|
|
#include "../drivers_keyboard/keyboard_event_apple.h"
|
|
|
|
|
2016-01-15 21:22:37 +00:00
|
|
|
/* Forward declarations */
|
2016-02-26 12:40:29 +00:00
|
|
|
float get_backing_scale_factor(void);
|
2016-01-15 21:22:37 +00:00
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
int32_t cocoa_input_find_any_key(void)
|
2013-09-09 21:52:02 +00:00
|
|
|
{
|
2015-11-29 17:18:25 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_driver_get_data();
|
2014-09-30 13:44:40 +00:00
|
|
|
|
|
|
|
if (!apple)
|
|
|
|
return 0;
|
2014-10-04 14:34:52 +00:00
|
|
|
|
|
|
|
if (apple->joypad)
|
|
|
|
apple->joypad->poll();
|
2015-11-16 01:39:38 +00:00
|
|
|
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple->sec_joypad)
|
|
|
|
apple->sec_joypad->poll();
|
2013-11-22 14:30:02 +00:00
|
|
|
|
2015-11-29 14:46:01 +00:00
|
|
|
return apple_keyboard_find_any_key();
|
2013-09-09 21:52:02 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 01:40:16 +00:00
|
|
|
static int cocoa_input_find_any_button_ret(cocoa_input_data_t *apple,
|
|
|
|
unsigned buttons, unsigned port)
|
2015-09-16 01:29:38 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (buttons)
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
if (buttons & (1 << i))
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
int32_t cocoa_input_find_any_button(uint32_t port)
|
2013-09-09 21:52:02 +00:00
|
|
|
{
|
2015-11-16 05:46:29 +00:00
|
|
|
int ret = -1;
|
2015-11-29 17:18:25 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_driver_get_data();
|
2014-09-30 14:34:40 +00:00
|
|
|
|
|
|
|
if (!apple)
|
|
|
|
return -1;
|
2014-09-30 13:44:40 +00:00
|
|
|
|
2014-10-04 14:34:52 +00:00
|
|
|
if (apple->joypad)
|
2015-11-16 05:46:29 +00:00
|
|
|
{
|
2014-10-04 14:34:52 +00:00
|
|
|
apple->joypad->poll();
|
2013-12-28 01:12:19 +00:00
|
|
|
|
2015-11-16 05:46:29 +00:00
|
|
|
if (apple->joypad->get_buttons)
|
|
|
|
ret = cocoa_input_find_any_button_ret(apple, apple->joypad->get_buttons(port), port);
|
|
|
|
}
|
2013-09-09 21:52:02 +00:00
|
|
|
|
2015-09-16 01:29:38 +00:00
|
|
|
if (ret != -1)
|
|
|
|
return ret;
|
2015-11-16 05:46:29 +00:00
|
|
|
|
|
|
|
if (apple->sec_joypad)
|
2015-11-16 03:32:04 +00:00
|
|
|
{
|
2015-11-16 05:46:29 +00:00
|
|
|
apple->sec_joypad->poll();
|
2015-11-16 03:32:04 +00:00
|
|
|
|
2015-11-16 05:46:29 +00:00
|
|
|
if (apple->sec_joypad->get_buttons)
|
|
|
|
{
|
|
|
|
apple->sec_joypad->poll();
|
|
|
|
ret = cocoa_input_find_any_button_ret(apple, apple->sec_joypad->get_buttons(port), port);
|
|
|
|
}
|
2015-11-16 03:32:04 +00:00
|
|
|
}
|
2013-09-09 21:52:02 +00:00
|
|
|
|
2015-11-16 05:46:29 +00:00
|
|
|
if (ret != -1)
|
|
|
|
return ret;
|
|
|
|
|
2013-09-09 21:52:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
int32_t cocoa_input_find_any_axis(uint32_t port)
|
2013-09-09 21:52:02 +00:00
|
|
|
{
|
2014-09-30 13:44:40 +00:00
|
|
|
int i;
|
2015-11-29 17:18:25 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_driver_get_data();
|
2014-09-30 13:44:40 +00:00
|
|
|
|
2014-10-04 14:34:52 +00:00
|
|
|
if (apple && apple->joypad)
|
|
|
|
apple->joypad->poll();
|
2015-11-16 01:39:38 +00:00
|
|
|
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple && apple->sec_joypad)
|
|
|
|
apple->sec_joypad->poll();
|
2013-12-28 01:12:19 +00:00
|
|
|
|
2015-11-14 17:04:07 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
2013-09-09 21:52:02 +00:00
|
|
|
{
|
2015-11-16 05:32:25 +00:00
|
|
|
int16_t value = apple->joypad ? apple->joypad->axis(port, i) : 0;
|
2013-09-09 21:52:02 +00:00
|
|
|
|
2015-11-16 05:32:25 +00:00
|
|
|
if (abs(value) > 0x4000)
|
|
|
|
return (value < 0) ? -(i + 1) : i + 1;
|
|
|
|
|
|
|
|
value = apple->sec_joypad ? apple->sec_joypad->axis(port, i) : value;
|
|
|
|
|
2013-09-09 21:52:02 +00:00
|
|
|
if (abs(value) > 0x4000)
|
|
|
|
return (value < 0) ? -(i + 1) : i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-03 23:50:38 +00:00
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static void *cocoa_input_init(void)
|
2013-03-03 23:50:38 +00:00
|
|
|
{
|
2015-03-20 21:32:09 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)calloc(1, sizeof(*apple));
|
2014-09-30 13:44:40 +00:00
|
|
|
if (!apple)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-12 01:52:52 +00:00
|
|
|
input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid);
|
2014-06-10 01:32:03 +00:00
|
|
|
|
2015-06-03 16:22:54 +00:00
|
|
|
apple->joypad = input_joypad_init_driver(settings->input.joypad_driver, apple);
|
2014-06-10 03:41:06 +00:00
|
|
|
|
2015-11-16 01:39:38 +00:00
|
|
|
#ifdef HAVE_MFI
|
2015-11-16 02:57:52 +00:00
|
|
|
apple->sec_joypad = input_joypad_init_driver("mfi", apple);
|
2015-11-16 01:39:38 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-30 13:44:40 +00:00
|
|
|
return apple;
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static void cocoa_input_poll(void *data)
|
2013-03-03 23:50:38 +00:00
|
|
|
{
|
2014-09-09 18:49:08 +00:00
|
|
|
uint32_t i;
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2016-01-15 22:15:49 +00:00
|
|
|
#ifndef IOS
|
2016-01-15 21:22:37 +00:00
|
|
|
float backing_scale_factor = get_backing_scale_factor();
|
2016-01-15 22:15:49 +00:00
|
|
|
#endif
|
2016-01-15 21:20:46 +00:00
|
|
|
|
2014-09-30 13:44:40 +00:00
|
|
|
for (i = 0; i < apple->touch_count; i++)
|
2016-01-15 21:20:46 +00:00
|
|
|
{
|
2016-01-15 21:33:25 +00:00
|
|
|
#ifndef IOS
|
2016-01-15 21:20:46 +00:00
|
|
|
apple->touches[i].screen_x *= backing_scale_factor;
|
|
|
|
apple->touches[i].screen_y *= backing_scale_factor;
|
2016-01-15 21:33:25 +00:00
|
|
|
#endif
|
2015-02-11 01:16:33 +00:00
|
|
|
input_translate_coord_viewport(
|
|
|
|
apple->touches[i].screen_x,
|
|
|
|
apple->touches[i].screen_y,
|
|
|
|
&apple->touches[i].fixed_x,
|
|
|
|
&apple->touches[i].fixed_y,
|
|
|
|
&apple->touches[i].full_x,
|
|
|
|
&apple->touches[i].full_y);
|
2016-01-15 21:20:46 +00:00
|
|
|
}
|
2013-12-22 00:42:10 +00:00
|
|
|
|
2014-09-30 13:44:40 +00:00
|
|
|
if (apple->joypad)
|
|
|
|
apple->joypad->poll();
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple->sec_joypad)
|
|
|
|
apple->sec_joypad->poll();
|
2014-08-02 22:44:07 +00:00
|
|
|
|
2015-10-08 19:04:27 +00:00
|
|
|
apple->mouse_x_last = apple->mouse_rel_x;
|
|
|
|
apple->mouse_y_last = apple->mouse_rel_y;
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static int16_t cocoa_mouse_state(cocoa_input_data_t *apple,
|
2014-09-30 14:34:40 +00:00
|
|
|
unsigned id)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_X:
|
2015-10-08 19:04:27 +00:00
|
|
|
return apple->mouse_rel_x - apple->mouse_x_last;
|
2014-09-30 14:34:40 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_Y:
|
2015-10-08 19:04:27 +00:00
|
|
|
return apple->mouse_rel_y - apple->mouse_y_last;
|
2014-09-30 14:34:40 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
|
|
|
return apple->mouse_buttons & 1;
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
|
|
|
return apple->mouse_buttons & 2;
|
2015-03-10 23:35:26 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
|
|
|
return apple->mouse_wu;
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
|
|
|
return apple->mouse_wd;
|
2014-09-30 14:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-08 19:04:27 +00:00
|
|
|
static int16_t cocoa_mouse_state_screen(cocoa_input_data_t *apple,
|
|
|
|
unsigned id)
|
|
|
|
{
|
2016-01-15 21:33:25 +00:00
|
|
|
int16_t val;
|
|
|
|
#ifndef IOS
|
2016-01-15 21:20:46 +00:00
|
|
|
float backing_scale_factor = get_backing_scale_factor();
|
2016-01-15 21:33:25 +00:00
|
|
|
#endif
|
2016-01-15 21:20:46 +00:00
|
|
|
|
2015-10-08 19:04:27 +00:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_X:
|
2016-01-15 21:33:25 +00:00
|
|
|
val = apple->window_pos_x;
|
|
|
|
break;
|
2015-10-08 19:04:27 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_Y:
|
2016-01-15 21:33:25 +00:00
|
|
|
val = apple->window_pos_y;
|
2015-10-08 19:04:27 +00:00
|
|
|
break;
|
2016-01-15 21:33:25 +00:00
|
|
|
default:
|
|
|
|
return cocoa_mouse_state(apple, id);
|
2015-10-08 19:04:27 +00:00
|
|
|
}
|
2016-01-15 21:33:25 +00:00
|
|
|
|
|
|
|
#ifndef IOS
|
|
|
|
val *= backing_scale_factor;
|
|
|
|
#endif
|
|
|
|
return val;
|
2015-10-08 19:04:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static int16_t cocoa_pointer_state(cocoa_input_data_t *apple,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned device, unsigned idx, unsigned id)
|
2014-09-30 14:34:40 +00:00
|
|
|
{
|
2014-09-30 14:35:49 +00:00
|
|
|
const bool want_full = (device == RARCH_DEVICE_POINTER_SCREEN);
|
2014-09-30 14:34:40 +00:00
|
|
|
|
2014-10-20 18:31:00 +00:00
|
|
|
if (idx < apple->touch_count && (idx < MAX_TOUCHES))
|
2014-09-30 14:34:40 +00:00
|
|
|
{
|
2015-03-10 23:43:07 +00:00
|
|
|
int16_t x, y;
|
2015-04-19 15:58:15 +00:00
|
|
|
const cocoa_touch_data_t *touch = (const cocoa_touch_data_t *)
|
2014-10-20 18:31:00 +00:00
|
|
|
&apple->touches[idx];
|
2015-03-10 23:43:07 +00:00
|
|
|
|
|
|
|
if (!touch)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
x = touch->fixed_x;
|
|
|
|
y = touch->fixed_y;
|
2015-02-11 01:16:33 +00:00
|
|
|
|
|
|
|
if (want_full)
|
|
|
|
{
|
|
|
|
x = touch->full_x;
|
|
|
|
y = touch->full_y;
|
|
|
|
}
|
2014-09-30 14:34:40 +00:00
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
|
|
|
return (x != -0x8000) && (y != -0x8000);
|
|
|
|
case RETRO_DEVICE_ID_POINTER_X:
|
|
|
|
return x;
|
|
|
|
case RETRO_DEVICE_ID_POINTER_Y:
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static int16_t cocoa_input_state(void *data,
|
2014-09-30 14:34:40 +00:00
|
|
|
const struct retro_keybind **binds, unsigned port,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned device, unsigned idx, unsigned id)
|
2013-03-03 23:50:38 +00:00
|
|
|
{
|
2015-11-18 04:37:41 +00:00
|
|
|
int16_t ret;
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2014-04-26 15:39:46 +00:00
|
|
|
|
2014-10-07 02:12:41 +00:00
|
|
|
if (!apple || !apple->joypad)
|
|
|
|
return 0;
|
|
|
|
|
2013-03-03 23:50:38 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2015-11-29 14:44:21 +00:00
|
|
|
return apple_input_is_pressed(port, binds[port], id) ||
|
2015-11-16 01:39:38 +00:00
|
|
|
input_joypad_pressed(apple->joypad, port, binds[port], id)
|
|
|
|
#ifdef HAVE_MFI
|
2015-11-16 02:57:52 +00:00
|
|
|
|| input_joypad_pressed(apple->sec_joypad, port, binds[port], id)
|
2015-11-16 01:39:38 +00:00
|
|
|
#endif
|
|
|
|
;
|
2013-03-31 02:23:45 +00:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2015-11-16 01:39:38 +00:00
|
|
|
#ifdef HAVE_MFI
|
2015-11-18 04:37:41 +00:00
|
|
|
ret = input_joypad_analog(apple->sec_joypad, port,
|
2014-10-20 18:31:00 +00:00
|
|
|
idx, id, binds[port]);
|
2015-11-18 04:37:41 +00:00
|
|
|
if (!ret)
|
2015-11-16 01:39:38 +00:00
|
|
|
#endif
|
2015-11-18 04:37:41 +00:00
|
|
|
ret = input_joypad_analog(apple->joypad, port,
|
|
|
|
idx, id, binds[port]);
|
|
|
|
return ret;
|
2013-03-31 15:59:37 +00:00
|
|
|
case RETRO_DEVICE_KEYBOARD:
|
2015-11-29 14:44:21 +00:00
|
|
|
return apple_keyboard_state(id);
|
2013-08-11 04:20:15 +00:00
|
|
|
case RETRO_DEVICE_MOUSE:
|
2015-04-19 15:58:15 +00:00
|
|
|
return cocoa_mouse_state(apple, id);
|
2015-10-08 19:04:27 +00:00
|
|
|
case RARCH_DEVICE_MOUSE_SCREEN:
|
|
|
|
return cocoa_mouse_state_screen(apple, id);
|
2013-03-30 00:32:45 +00:00
|
|
|
case RETRO_DEVICE_POINTER:
|
2013-03-03 23:50:38 +00:00
|
|
|
case RARCH_DEVICE_POINTER_SCREEN:
|
2015-04-19 15:58:15 +00:00
|
|
|
return cocoa_pointer_state(apple, device, idx, id);
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
2014-09-30 14:34:40 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:59:12 +00:00
|
|
|
static bool cocoa_input_key_pressed(void *data, int key)
|
2013-03-03 23:50:38 +00:00
|
|
|
{
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2015-10-22 17:17:47 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-09-03 23:01:29 +00:00
|
|
|
int port = 0;
|
2015-10-22 17:17:47 +00:00
|
|
|
|
2015-11-29 14:44:21 +00:00
|
|
|
if (apple_input_is_pressed(0, settings->input.binds[0], key))
|
2015-10-23 06:34:15 +00:00
|
|
|
return true;
|
2016-09-03 23:01:29 +00:00
|
|
|
|
|
|
|
if (settings->input.all_users_control_menu)
|
|
|
|
{
|
|
|
|
for (port = 0; port < MAX_USERS; port++)
|
|
|
|
{
|
|
|
|
if (input_joypad_pressed(apple->joypad,
|
|
|
|
port, settings->input.binds[0], key))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#ifdef HAVE_MFI
|
|
|
|
if (input_joypad_pressed(apple->sec_joypad, port, settings->input.binds[0], key))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (input_joypad_pressed(apple->joypad,
|
|
|
|
0, settings->input.binds[0], key))
|
|
|
|
return true;
|
|
|
|
|
2015-11-16 01:39:38 +00:00
|
|
|
#ifdef HAVE_MFI
|
2016-09-03 23:01:29 +00:00
|
|
|
if (input_joypad_pressed(apple->sec_joypad, 0, settings->input.binds[0], key))
|
|
|
|
return true;
|
2015-11-16 01:39:38 +00:00
|
|
|
#endif
|
2015-10-22 17:17:47 +00:00
|
|
|
|
2015-10-23 06:34:15 +00:00
|
|
|
return false;
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:59:12 +00:00
|
|
|
static bool cocoa_input_meta_key_pressed(void *data, int key)
|
2015-07-17 01:31:51 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static void cocoa_input_free(void *data)
|
2013-03-03 23:50:38 +00:00
|
|
|
{
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2014-09-30 13:44:40 +00:00
|
|
|
|
2014-10-04 13:14:39 +00:00
|
|
|
if (!apple || !data)
|
2014-09-30 13:44:40 +00:00
|
|
|
return;
|
2014-05-13 11:49:29 +00:00
|
|
|
|
2014-10-04 13:14:39 +00:00
|
|
|
if (apple->joypad)
|
2014-09-30 13:44:40 +00:00
|
|
|
apple->joypad->destroy();
|
|
|
|
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple->sec_joypad)
|
|
|
|
apple->sec_joypad->destroy();
|
2015-11-16 01:39:38 +00:00
|
|
|
|
2015-11-29 14:44:21 +00:00
|
|
|
apple_keyboard_free();
|
2014-09-30 13:44:40 +00:00
|
|
|
free(apple);
|
2013-03-03 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static bool cocoa_input_set_rumble(void *data,
|
2014-09-30 13:44:40 +00:00
|
|
|
unsigned port, enum retro_rumble_effect effect, uint16_t strength)
|
2013-10-03 22:04:28 +00:00
|
|
|
{
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2014-09-30 13:44:40 +00:00
|
|
|
|
|
|
|
if (apple && apple->joypad)
|
2014-09-30 14:34:40 +00:00
|
|
|
return input_joypad_set_rumble(apple->joypad,
|
|
|
|
port, effect, strength);
|
2015-11-16 01:39:38 +00:00
|
|
|
#ifdef HAVE_MFI
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple && apple->sec_joypad)
|
|
|
|
return input_joypad_set_rumble(apple->sec_joypad,
|
2015-11-16 01:39:38 +00:00
|
|
|
port, effect, strength);
|
|
|
|
#endif
|
2014-09-30 13:44:40 +00:00
|
|
|
return false;
|
2013-10-03 22:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static uint64_t cocoa_input_get_capabilities(void *data)
|
2013-11-02 20:16:57 +00:00
|
|
|
{
|
2014-04-26 15:39:46 +00:00
|
|
|
(void)data;
|
|
|
|
|
2014-10-04 13:14:39 +00:00
|
|
|
return
|
|
|
|
(1 << RETRO_DEVICE_JOYPAD) |
|
|
|
|
(1 << RETRO_DEVICE_MOUSE) |
|
|
|
|
(1 << RETRO_DEVICE_KEYBOARD) |
|
|
|
|
(1 << RETRO_DEVICE_POINTER) |
|
|
|
|
(1 << RETRO_DEVICE_ANALOG);
|
|
|
|
}
|
2013-11-02 20:16:57 +00:00
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static void cocoa_input_grab_mouse(void *data, bool state)
|
2014-10-04 13:14:39 +00:00
|
|
|
{
|
|
|
|
/* Dummy for now. Might be useful in the future. */
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
2013-11-02 20:16:57 +00:00
|
|
|
}
|
2013-10-03 22:04:28 +00:00
|
|
|
|
2015-11-16 01:39:38 +00:00
|
|
|
static const input_device_driver_t *cocoa_input_get_sec_joypad_driver(void *data)
|
|
|
|
{
|
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
|
|
|
|
2015-11-16 02:57:52 +00:00
|
|
|
if (apple && apple->sec_joypad)
|
|
|
|
return apple->sec_joypad;
|
2015-11-16 01:39:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
static const input_device_driver_t *cocoa_input_get_joypad_driver(void *data)
|
2014-01-13 01:56:16 +00:00
|
|
|
{
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
2014-09-30 13:44:40 +00:00
|
|
|
|
|
|
|
if (apple && apple->joypad)
|
|
|
|
return apple->joypad;
|
|
|
|
return NULL;
|
2014-01-13 01:56:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 01:45:23 +00:00
|
|
|
static bool cocoa_input_keyboard_mapping_is_blocked(void *data)
|
|
|
|
{
|
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
|
|
|
if (!apple)
|
|
|
|
return false;
|
|
|
|
return apple->blocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cocoa_input_keyboard_mapping_set_block(void *data, bool value)
|
|
|
|
{
|
|
|
|
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
|
|
|
|
if (!apple)
|
|
|
|
return;
|
|
|
|
apple->blocked = value;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:58:15 +00:00
|
|
|
input_driver_t input_cocoa = {
|
|
|
|
cocoa_input_init,
|
|
|
|
cocoa_input_poll,
|
|
|
|
cocoa_input_state,
|
2015-07-12 06:45:12 +00:00
|
|
|
cocoa_input_key_pressed,
|
2015-07-17 01:31:51 +00:00
|
|
|
cocoa_input_meta_key_pressed,
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_free,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
2014-01-20 13:52:53 +00:00
|
|
|
NULL,
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_get_capabilities,
|
|
|
|
"cocoa",
|
|
|
|
cocoa_input_grab_mouse,
|
2015-05-19 17:33:58 +00:00
|
|
|
NULL,
|
2015-04-19 15:58:15 +00:00
|
|
|
cocoa_input_set_rumble,
|
2015-06-19 01:46:54 +00:00
|
|
|
cocoa_input_get_joypad_driver,
|
2015-11-16 01:39:38 +00:00
|
|
|
cocoa_input_get_sec_joypad_driver,
|
2015-06-19 01:45:23 +00:00
|
|
|
cocoa_input_keyboard_mapping_is_blocked,
|
|
|
|
cocoa_input_keyboard_mapping_set_block,
|
2013-03-03 23:50:38 +00:00
|
|
|
};
|