From 1489839384a139c1137337a191afd2b7ed83fbd3 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 1 Aug 2015 05:19:44 +0200 Subject: [PATCH] (OSX) Add HAVE_COCOA and HAVE_COCOATOUCH ifdefs to iohidmanager_hid.c --- input/drivers_hid/iohidmanager_hid.c | 41 ++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index 8f23c36cba..2670500b47 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -60,11 +60,17 @@ 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) { 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 uint64_t buttons = iohidmanager_hid_joypad_get_buttons(data, port); - if (!apple || joykey == NO_BTN) + 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)) @@ -72,8 +78,11 @@ static bool iohidmanager_hid_joypad_button(void *data, unsigned port, uint16_t j /* Check the button. */ if ((port < MAX_USERS) && (joykey < 32)) - return ((apple->buttons[port] & (1 << joykey)) != 0) || - ((buttons & (1 << joykey)) != 0); + return ((buttons & (1 << joykey)) != 0) +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) + || ((apple->buttons[port] & (1 << joykey)) != 0) +#endif + ; return false; } @@ -89,16 +98,24 @@ static bool iohidmanager_hid_joypad_rumble(void *data, unsigned pad, static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) { 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 iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; int16_t val = 0; - if (!apple || joyaxis == AXIS_NONE) + if (joyaxis == AXIS_NONE) return 0; +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) + if (!apple) + return 0; +#endif if (AXIS_NEG_GET(joyaxis) < 4) { - val = apple->axes[port][AXIS_NEG_GET(joyaxis)]; +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) + val += apple->axes[port][AXIS_NEG_GET(joyaxis)]; +#endif val += pad_connection_get_axis(&hid->slots[port], port, AXIS_NEG_GET(joyaxis)); if (val >= 0) @@ -106,7 +123,9 @@ static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t } else if(AXIS_POS_GET(joyaxis) < 4) { - val = apple->axes[port][AXIS_POS_GET(joyaxis)]; +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) + val += apple->axes[port][AXIS_POS_GET(joyaxis)]; +#endif val += pad_connection_get_axis(&hid->slots[port], port, AXIS_POS_GET(joyaxis)); if (val <= 0) @@ -147,7 +166,9 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, void* sender, IOHIDValueRef value) { 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; IOHIDElementRef element = IOHIDValueGetElement(value); uint32_t type = IOHIDElementGetType(element); @@ -187,8 +208,10 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, if (use != axis_use_ids[i]) continue; +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) apple->axes[adapter->slot][i] = ((val * 2.0f) - 1.0f) * 32767.0f; +#endif } } break; @@ -204,10 +227,12 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result, CFIndex state = IOHIDValueGetIntegerValue(value); unsigned id = use - 1; +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) if (state) BIT64_SET(apple->buttons[adapter->slot], id); else BIT64_CLEAR(apple->buttons[adapter->slot], id); +#endif } break; } @@ -218,7 +243,9 @@ 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; @@ -226,8 +253,10 @@ 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; memset(apple->axes[adapter->slot], 0, sizeof(apple->axes)); +#endif pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot); free(adapter);