Start no longer having dependencies on apple input data for

keyboard_event_apple.c
This commit is contained in:
twinaphex 2015-11-29 15:44:21 +01:00
parent dff44d8d49
commit bc748951c6
4 changed files with 63 additions and 42 deletions

View File

@ -33,6 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef KEYCODE_KEYCODE_H
#define KEYCODE_KEYCODE_H
#ifndef MAX_KEYS
#define MAX_KEYS 256
#endif
enum
{
KEY_A = 4,
@ -158,4 +162,13 @@ enum
#include "../input_config.h"
int16_t apple_input_is_pressed(unsigned port_num,
const struct retro_keybind *binds, unsigned id);
int16_t apple_keyboard_state(unsigned id);
void apple_keyboard_find_any_key(void);
void apple_keyboard_free(void);
#endif

View File

@ -26,7 +26,6 @@
int32_t cocoa_input_find_any_key(void)
{
unsigned i;
driver_t *driver =driver_get_ptr();
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
@ -39,9 +38,7 @@ int32_t cocoa_input_find_any_key(void)
if (apple->sec_joypad)
apple->sec_joypad->poll();
for (i = 0; apple_key_name_map[i].hid_id; i++)
if (apple->key_state[apple_key_name_map[i].hid_id])
return apple_key_name_map[i].hid_id;
apple_keyboard_find_any_key();
return 0;
}
@ -123,17 +120,6 @@ int32_t cocoa_input_find_any_axis(uint32_t port)
return 0;
}
static int16_t cocoa_input_is_pressed(cocoa_input_data_t *apple, unsigned port_num,
const struct retro_keybind *binds, unsigned id)
{
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned bit = input_keymaps_translate_rk_to_keysym(bind->key);
return bind->valid && apple->key_state[bit];
}
return 0;
}
static void *cocoa_input_init(void)
{
@ -251,12 +237,6 @@ static int16_t cocoa_pointer_state(cocoa_input_data_t *apple,
return 0;
}
static int16_t cocoa_keyboard_state(cocoa_input_data_t *apple, unsigned id)
{
unsigned bit = input_keymaps_translate_rk_to_keysym((enum retro_key)id);
return (id < RETROK_LAST) && apple->key_state[bit];
}
static int16_t cocoa_input_state(void *data,
const struct retro_keybind **binds, unsigned port,
unsigned device, unsigned idx, unsigned id)
@ -270,7 +250,7 @@ static int16_t cocoa_input_state(void *data,
switch (device)
{
case RETRO_DEVICE_JOYPAD:
return cocoa_input_is_pressed(apple, port, binds[port], id) ||
return apple_input_is_pressed(port, binds[port], id) ||
input_joypad_pressed(apple->joypad, port, binds[port], id)
#ifdef HAVE_MFI
|| input_joypad_pressed(apple->sec_joypad, port, binds[port], id)
@ -286,7 +266,7 @@ static int16_t cocoa_input_state(void *data,
idx, id, binds[port]);
return ret;
case RETRO_DEVICE_KEYBOARD:
return cocoa_keyboard_state(apple, id);
return apple_keyboard_state(id);
case RETRO_DEVICE_MOUSE:
return cocoa_mouse_state(apple, id);
case RARCH_DEVICE_MOUSE_SCREEN:
@ -304,7 +284,7 @@ static bool cocoa_input_key_pressed(void *data, int key)
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
settings_t *settings = config_get_ptr();
if (cocoa_input_is_pressed(apple, 0, settings->input.binds[0], key))
if (apple_input_is_pressed(0, settings->input.binds[0], key))
return true;
if (input_joypad_pressed(apple->joypad, 0, settings->input.binds[0], key))
return true;
@ -334,6 +314,7 @@ static void cocoa_input_free(void *data)
if (apple->sec_joypad)
apple->sec_joypad->destroy();
apple_keyboard_free();
free(apple);
}

View File

@ -23,7 +23,6 @@
/* Input responder */
#define MAX_TOUCHES 16
#define MAX_KEYS 256
typedef struct
{
@ -48,11 +47,6 @@ typedef struct
int16_t mouse_wu;
int16_t mouse_wd;
uint32_t key_state[MAX_KEYS];
#if TARGET_OS_IPHONE
bool small_keyboard_active;
#endif
const input_device_driver_t *sec_joypad;
const input_device_driver_t *joypad;
} cocoa_input_data_t;

View File

@ -27,6 +27,12 @@
#include "../drivers/apple_keycode.h"
#if TARGET_OS_IPHONE
static bool small_keyboard_active;
#endif
static uint32_t apple_key_state[MAX_KEYS];
#if defined(HAVE_COCOATOUCH)
#define HIDKEY(X) X
@ -72,8 +78,6 @@ static bool handle_small_keyboard(unsigned* code, bool down)
{ KEY_X, KP_2 }, { KEY_C, KP_3 },
{ 0 }
};
driver_t *driver = driver_get_ptr();
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
unsigned translated_code = 0;
if (!map_initialized)
@ -86,7 +90,7 @@ static bool handle_small_keyboard(unsigned* code, bool down)
if (*code == KEY_RightShift)
{
apple->small_keyboard_active = down;
small_keyboard_active = down;
*code = 0;
return true;
}
@ -94,11 +98,11 @@ static bool handle_small_keyboard(unsigned* code, bool down)
translated_code = (*code < 128) ? mapping[*code] : 0;
/* Allow old keys to be released. */
if (!down && apple->key_state[*code])
if (!down && apple_key_state[*code])
return false;
if ((!down && apple->key_state[translated_code]) ||
apple->small_keyboard_active)
if ((!down && apple_key_state[translated_code]) ||
small_keyboard_active)
{
*code = translated_code;
return true;
@ -273,14 +277,9 @@ static bool handle_icade_event(unsigned *code, bool *keydown)
void cocoa_input_keyboard_event(bool down,
unsigned code, uint32_t character, uint32_t mod, unsigned device)
{
driver_t *driver = driver_get_ptr();
#if TARGET_OS_IPHONE
settings_t *settings = config_get_ptr();
#endif
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
if (!apple)
return;
code = HIDKEY(code);
@ -302,9 +301,43 @@ void cocoa_input_keyboard_event(bool down,
if (code == 0 || code >= MAX_KEYS)
return;
apple->key_state[code] = down;
apple_key_state[code] = down;
input_keyboard_event(down,
input_keymaps_translate_keysym_to_rk(code),
character, (enum retro_mod)mod, device);
}
int16_t apple_input_is_pressed_kb(unsigned port_num,
const struct retro_keybind *binds, unsigned id)
{
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned bit = input_keymaps_translate_rk_to_keysym(bind->key);
return bind->valid && apple_key_state[bit];
}
return 0;
}
int16_t apple_keyboard_state(unsigned id)
{
unsigned bit = input_keymaps_translate_rk_to_keysym((enum retro_key)id);
return (id < RETROK_LAST) && apple_key_state[bit];
}
void apple_keyboard_find_any_key(void)
{
unsigned i;
for (i = 0; apple_key_name_map[i].hid_id; i++)
if (apple_key_state[apple_key_name_map[i].hid_id])
return apple_key_name_map[i].hid_id;
}
void apple_keyboard_free(void)
{
unsigned i;
for (i = 0; i < MAX_KEYS; i++)
apple_key_state[i] = 0;
}