From 08bb85e509a579128198913f70b3fc9c619d53d8 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 16 Nov 2015 06:46:29 +0100 Subject: [PATCH] (OSX) apple->buttons refactored away --- input/drivers/cocoa_input.c | 27 +++++++++++++++----------- input/drivers/cocoa_input.h | 11 +++++------ input/drivers_hid/iohidmanager_hid.c | 29 ++++++---------------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index 79990f0757..e390f63650 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -167,7 +167,7 @@ static int cocoa_input_find_any_button_ret(cocoa_input_data_t *apple, int32_t cocoa_input_find_any_button(uint32_t port) { - int ret; + int ret = -1; driver_t *driver = driver_get_ptr(); cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; @@ -175,25 +175,30 @@ int32_t cocoa_input_find_any_button(uint32_t port) return -1; if (apple->joypad) + { apple->joypad->poll(); - - if (apple->sec_joypad) - apple->sec_joypad->poll(); - ret = cocoa_input_find_any_button_ret(apple, apple->buttons[port], port); + if (apple->joypad->get_buttons) + ret = cocoa_input_find_any_button_ret(apple, apple->joypad->get_buttons(port), port); + } if (ret != -1) return ret; - - if (apple && apple->sec_joypad && apple->sec_joypad->get_buttons) + + if (apple->sec_joypad) { - apple->sec_joypad->poll(); - ret = cocoa_input_find_any_button_ret(apple, apple->sec_joypad->get_buttons(port), port); + apple->sec_joypad->poll(); - if (ret != -1) - return ret; + 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); + } } + if (ret != -1) + return ret; + return -1; } diff --git a/input/drivers/cocoa_input.h b/input/drivers/cocoa_input.h index 9269005059..15d3e6f6bf 100644 --- a/input/drivers/cocoa_input.h +++ b/input/drivers/cocoa_input.h @@ -43,10 +43,10 @@ typedef struct uint32_t touch_count; uint32_t mouse_buttons; - int16_t mouse_x_last; - int16_t mouse_y_last; - int16_t window_pos_x; - int16_t window_pos_y; + int16_t mouse_x_last; + int16_t mouse_y_last; + int16_t window_pos_x; + int16_t window_pos_y; int16_t mouse_rel_x; int16_t mouse_rel_y; int16_t mouse_wu; @@ -54,13 +54,12 @@ typedef struct uint32_t key_state[MAX_KEYS]; - uint32_t buttons[MAX_USERS]; int8_t hats[NUM_HATS][2]; #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; diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index d5044d6d13..7ee087a8e1 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -26,6 +26,7 @@ typedef struct apple_hid { IOHIDManagerRef ptr; joypad_connection_t *slots; + uint32_t buttons[MAX_USERS]; int16_t axes[MAX_USERS][6]; } iohidmanager_hid_t; @@ -61,18 +62,11 @@ static uint64_t iohidmanager_hid_joypad_get_buttons(void *data, unsigned port) static bool iohidmanager_hid_joypad_button(void *data, unsigned port, uint16_t joykey) { -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - driver_t *driver = driver_get_ptr(); - cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; -#endif uint64_t buttons = iohidmanager_hid_joypad_get_buttons(data, port); + iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; if (joykey == NO_BTN) return false; -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - if (!apple) - return false; -#endif /* Check hat. */ if (GET_HAT_DIR(joykey)) @@ -80,10 +74,7 @@ static bool iohidmanager_hid_joypad_button(void *data, unsigned port, uint16_t j /* Check the button. */ if ((port < MAX_USERS) && (joykey < 32)) - return ((buttons & (1 << joykey)) != 0) -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - || ((apple->buttons[port] & (1 << joykey)) != 0) -#endif + return ((buttons & (1 << joykey)) != 0) || ((hid->buttons[port] & (1 << joykey)) != 0) ; return false; } @@ -157,9 +148,6 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, { driver_t *driver = driver_get_ptr(); iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL; -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; -#endif struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data; IOHIDElementRef element = IOHIDValueGetElement(value); uint32_t type = IOHIDElementGetType(element); @@ -224,9 +212,9 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, unsigned id = use - 1; if (state) - BIT64_SET(apple->buttons[adapter->slot], id); + BIT64_SET(hid->buttons[adapter->slot], id); else - BIT64_CLEAR(apple->buttons[adapter->slot], id); + BIT64_CLEAR(hid->buttons[adapter->slot], id); #endif } break; @@ -238,9 +226,6 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, static void iohidmanager_hid_device_remove(void *data, IOReturn result, void* sender) { driver_t *driver = driver_get_ptr(); -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; -#endif struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data; iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL; @@ -248,9 +233,7 @@ static void iohidmanager_hid_device_remove(void *data, IOReturn result, void* se { input_config_autoconfigure_disconnect(adapter->slot, adapter->name); -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - apple->buttons[adapter->slot] = 0; -#endif + hid->buttons[adapter->slot] = 0; memset(hid->axes[adapter->slot], 0, sizeof(hid->axes)); pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot);