diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 6e92397c28..9312a6121a 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -686,16 +686,15 @@ static INLINE void android_input_poll_event_type_motion( android_input_t *android, AInputEvent *event, int port, int source) { - int btn; int getaction = AMotionEvent_getAction(event); - int action = getaction & AMOTION_EVENT_ACTION_MASK; + int action = getaction & AMOTION_EVENT_ACTION_MASK; size_t motion_ptr = getaction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; bool keyup = ( - action == AMOTION_EVENT_ACTION_UP || - action == AMOTION_EVENT_ACTION_CANCEL || - action == AMOTION_EVENT_ACTION_POINTER_UP) || - (source == AINPUT_SOURCE_MOUSE && - action != AMOTION_EVENT_ACTION_DOWN); + action == AMOTION_EVENT_ACTION_UP + || action == AMOTION_EVENT_ACTION_CANCEL + || action == AMOTION_EVENT_ACTION_POINTER_UP) + || (source == AINPUT_SOURCE_MOUSE && + action != AMOTION_EVENT_ACTION_DOWN); /* If source is mouse then calculate button state * and mouse deltas and don't process as touchscreen event */ @@ -704,13 +703,13 @@ static INLINE void android_input_poll_event_type_motion( /* getButtonState requires API level 14 */ if (p_AMotionEvent_getButtonState) { - btn = (int)AMotionEvent_getButtonState(event); + int btn = (int)AMotionEvent_getButtonState(event); - android->mouse_l = (btn & AMOTION_EVENT_BUTTON_PRIMARY); - android->mouse_r = (btn & AMOTION_EVENT_BUTTON_SECONDARY); - android->mouse_m = (btn & AMOTION_EVENT_BUTTON_TERTIARY); + android->mouse_l = (btn & AMOTION_EVENT_BUTTON_PRIMARY); + android->mouse_r = (btn & AMOTION_EVENT_BUTTON_SECONDARY); + android->mouse_m = (btn & AMOTION_EVENT_BUTTON_TERTIARY); - btn = (int)AMotionEvent_getAxisValue(event, + btn = (int)AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, motion_ptr); if (btn > 0) @@ -910,9 +909,9 @@ static int android_input_get_id_index_from_name(android_input_t *android, static int android_input_recover_port(android_input_t *android, int id) { char device_name[256] = { 0 }; - int vendorId = 0; - int productId = 0; - settings_t *settings = config_get_ptr(); + int vendorId = 0; + int productId = 0; + settings_t *settings = config_get_ptr(); if (!settings->bools.android_input_disconnect_workaround) return -1; @@ -928,23 +927,22 @@ static int android_input_recover_port(android_input_t *android, int id) static bool is_configured_as_physical_keyboard(int vendor_id, int product_id, const char *device_name) { - settings_t *settings = config_get_ptr(); - - char keyboard_name[sizeof(settings->arrays.input_android_physical_keyboard)]; - int keyboard_vendor_id; - int keyboard_product_id; - bool is_keyboard; bool compare_by_id; + int keyboard_vendor_id; + int keyboard_product_id; + char keyboard_name[sizeof(settings->arrays.input_android_physical_keyboard)]; + settings_t *settings = config_get_ptr(); + if (sscanf(settings->arrays.input_android_physical_keyboard, "%04x:%04x ", &keyboard_vendor_id, &keyboard_product_id) != 2) { strlcpy(keyboard_name, settings->arrays.input_android_physical_keyboard, sizeof(keyboard_name)); - is_keyboard = string_is_equal(device_name, keyboard_name); + is_keyboard = string_is_equal(device_name, keyboard_name); compare_by_id = false; } else { - is_keyboard = vendor_id == keyboard_vendor_id && product_id == keyboard_product_id; + is_keyboard = (vendor_id == keyboard_vendor_id && product_id == keyboard_product_id); compare_by_id = true; } @@ -1670,7 +1668,8 @@ static int16_t android_input_state( case RETRO_DEVICE_MOUSE: { int val = 0; - if(port > 0) return 0; /* TODO: implement mouse for additional ports/players */ + if(port > 0) + break; /* TODO: implement mouse for additional ports/players */ switch (id) { case RETRO_DEVICE_ID_MOUSE_LEFT: @@ -1703,7 +1702,8 @@ static int16_t android_input_state( case RETRO_DEVICE_LIGHTGUN: { int val = 0; - if(port > 0) return 0; /* TODO: implement lightgun for additional ports/players */ + if(port > 0) + break; /* TODO: implement lightgun for additional ports/players */ switch (id) { case RETRO_DEVICE_ID_LIGHTGUN_X: @@ -1782,7 +1782,7 @@ static void android_input_free_input(void *data) android_app->gyroscopeSensor = NULL; android_app->sensorManager = NULL; - android_app->input_alive = false; + android_app->input_alive = false; #ifdef HAVE_DYLIB dylib_close((dylib_t)libandroid_handle); @@ -1830,91 +1830,91 @@ static void android_input_enable_sensor_manager(struct android_app *android_app) static bool android_input_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned event_rate) { - struct android_app *android_app = (struct android_app*)g_android; - android_input_t *android = (android_input_t*)data; - - if (port > 0) - return false; - - if (event_rate == 0) - event_rate = DEFAULT_ASENSOR_EVENT_RATE; - - switch (action) + if (port <= 0) { - case RETRO_SENSOR_ACCELEROMETER_ENABLE: - if (!android_app->accelerometerSensor) - android_input_enable_sensor_manager(android_app); + struct android_app *android_app = (struct android_app*)g_android; + android_input_t *android = (android_input_t*)data; - if (android_app->sensorEventQueue && - android_app->accelerometerSensor) - { - ASensorEventQueue_enableSensor(android_app->sensorEventQueue, - android_app->accelerometerSensor); + if (event_rate == 0) + event_rate = DEFAULT_ASENSOR_EVENT_RATE; - /* Events per second (in microseconds). */ - ASensorEventQueue_setEventRate(android_app->sensorEventQueue, - android_app->accelerometerSensor, (1000L / event_rate) - * 1000); - } + switch (action) + { + case RETRO_SENSOR_ACCELEROMETER_ENABLE: + if (!android_app->accelerometerSensor) + android_input_enable_sensor_manager(android_app); - android_app->accelerometer_event_rate = event_rate; + if (android_app->sensorEventQueue && + android_app->accelerometerSensor) + { + ASensorEventQueue_enableSensor(android_app->sensorEventQueue, + android_app->accelerometerSensor); - BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE); - BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE); - return true; + /* Events per second (in microseconds). */ + ASensorEventQueue_setEventRate(android_app->sensorEventQueue, + android_app->accelerometerSensor, (1000L / event_rate) + * 1000); + } - case RETRO_SENSOR_ACCELEROMETER_DISABLE: - if (android_app->sensorEventQueue && - android_app->accelerometerSensor) - ASensorEventQueue_disableSensor(android_app->sensorEventQueue, - android_app->accelerometerSensor); + android_app->accelerometer_event_rate = event_rate; - android->accelerometer_state.x = 0.0f; - android->accelerometer_state.y = 0.0f; - android->accelerometer_state.z = 0.0f; + BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE); + BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE); + return true; - BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE); - BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE); - return true; + case RETRO_SENSOR_ACCELEROMETER_DISABLE: + if (android_app->sensorEventQueue && + android_app->accelerometerSensor) + ASensorEventQueue_disableSensor(android_app->sensorEventQueue, + android_app->accelerometerSensor); - case RETRO_SENSOR_GYROSCOPE_ENABLE: - if (!android_app->gyroscopeSensor) - android_input_enable_sensor_manager(android_app); + android->accelerometer_state.x = 0.0f; + android->accelerometer_state.y = 0.0f; + android->accelerometer_state.z = 0.0f; - if (android_app->sensorEventQueue && - android_app->gyroscopeSensor) - { - ASensorEventQueue_enableSensor(android_app->sensorEventQueue, - android_app->gyroscopeSensor); + BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE); + BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE); + return true; - /* Events per second (in microseconds). */ - ASensorEventQueue_setEventRate(android_app->sensorEventQueue, - android_app->gyroscopeSensor, (1000L / event_rate) - * 1000); - } + case RETRO_SENSOR_GYROSCOPE_ENABLE: + if (!android_app->gyroscopeSensor) + android_input_enable_sensor_manager(android_app); - android_app->gyroscope_event_rate = event_rate; + if (android_app->sensorEventQueue && + android_app->gyroscopeSensor) + { + ASensorEventQueue_enableSensor(android_app->sensorEventQueue, + android_app->gyroscopeSensor); - BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE); - BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE); - return true; + /* Events per second (in microseconds). */ + ASensorEventQueue_setEventRate(android_app->sensorEventQueue, + android_app->gyroscopeSensor, (1000L / event_rate) + * 1000); + } - case RETRO_SENSOR_GYROSCOPE_DISABLE: - if (android_app->sensorEventQueue && - android_app->gyroscopeSensor) - ASensorEventQueue_disableSensor(android_app->sensorEventQueue, - android_app->gyroscopeSensor); + android_app->gyroscope_event_rate = event_rate; - android->gyroscope_state.x = 0.0f; - android->gyroscope_state.y = 0.0f; - android->gyroscope_state.z = 0.0f; + BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE); + BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE); + return true; - BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE); - BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE); - return true; + case RETRO_SENSOR_GYROSCOPE_DISABLE: + if (android_app->sensorEventQueue && + android_app->gyroscopeSensor) + ASensorEventQueue_disableSensor(android_app->sensorEventQueue, + android_app->gyroscopeSensor); - default: - break; + android->gyroscope_state.x = 0.0f; + android->gyroscope_state.y = 0.0f; + android->gyroscope_state.z = 0.0f; + + BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE); + BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE); + return true; + + default: + break; + } } return false; @@ -1923,25 +1923,25 @@ static bool android_input_set_sensor_state(void *data, unsigned port, static float android_input_get_sensor_input(void *data, unsigned port, unsigned id) { - android_input_t *android = (android_input_t*)data; - - if (port > 0) - return 0.0f; - - switch (id) + if (port <= 0) { - case RETRO_SENSOR_ACCELEROMETER_X: - return android->accelerometer_state.x; - case RETRO_SENSOR_ACCELEROMETER_Y: - return android->accelerometer_state.y; - case RETRO_SENSOR_ACCELEROMETER_Z: - return android->accelerometer_state.z; - case RETRO_SENSOR_GYROSCOPE_X: - return android->gyroscope_state.x; - case RETRO_SENSOR_GYROSCOPE_Y: - return android->gyroscope_state.y; - case RETRO_SENSOR_GYROSCOPE_Z: - return android->gyroscope_state.z; + android_input_t *android = (android_input_t*)data; + + switch (id) + { + case RETRO_SENSOR_ACCELEROMETER_X: + return android->accelerometer_state.x; + case RETRO_SENSOR_ACCELEROMETER_Y: + return android->accelerometer_state.y; + case RETRO_SENSOR_ACCELEROMETER_Z: + return android->accelerometer_state.z; + case RETRO_SENSOR_GYROSCOPE_X: + return android->gyroscope_state.x; + case RETRO_SENSOR_GYROSCOPE_Y: + return android->gyroscope_state.y; + case RETRO_SENSOR_GYROSCOPE_Z: + return android->gyroscope_state.z; + } } return 0.0f; diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index 9670669d63..a9cabd5b45 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -47,8 +47,8 @@ static bool apple_key_state[MAX_KEYS]; void apple_direct_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod, unsigned device) { - int appleKey = rarch_keysym_lut[code]; - apple_key_state[appleKey] = down; + int apple_key = rarch_keysym_lut[code]; + apple_key_state[apple_key] = down; input_keyboard_event(down, code, character, (enum retro_mod)mod, device); @@ -326,7 +326,7 @@ static const unsigned char MAC_NATIVE_TO_HID[128] = { void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod, unsigned device) { - code = HIDKEY(code); + code = HIDKEY(code); if (code == 0 || code >= MAX_KEYS) return; @@ -480,12 +480,13 @@ static int16_t cocoa_input_state( } #ifdef IOS #ifdef HAVE_IOS_TOUCHMOUSE - if (apple->window_pos_x > 0) { + if (apple->window_pos_x > 0) + { val = apple->window_pos_x - apple->mouse_x_last; apple->mouse_x_last = apple->window_pos_x; - } else { - val = apple->mouse_rel_x; } + else + val = apple->mouse_rel_x; #else val = apple->mouse_rel_x; #endif @@ -505,14 +506,15 @@ static int16_t cocoa_input_state( } #ifdef IOS #ifdef HAVE_IOS_TOUCHMOUSE - if (apple->window_pos_y > 0) { + if (apple->window_pos_y > 0) + { val = apple->window_pos_y - apple->mouse_y_last; apple->mouse_y_last = apple->window_pos_y; - } else { - val = apple->mouse_rel_y; } + else + val = apple->mouse_rel_y; #else - val = apple->mouse_rel_y; + val = apple->mouse_rel_y; #endif #else val = apple->window_pos_y - apple->mouse_y_last; @@ -537,36 +539,36 @@ static int16_t cocoa_input_state( case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: { - const bool want_full = (device == RARCH_DEVICE_POINTER_SCREEN); if (idx < apple->touch_count && (idx < MAX_TOUCHES)) { - int16_t x, y; const cocoa_touch_data_t *touch = (const cocoa_touch_data_t *) &apple->touches[idx]; - if (!touch) - return 0; - - x = touch->fixed_x; - y = touch->fixed_y; - - if (want_full) + if (touch) { - x = touch->full_x; - y = touch->full_y; - } + int16_t x, y; + const bool want_full = (device == RARCH_DEVICE_POINTER_SCREEN); - 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; - case RETRO_DEVICE_ID_POINTER_COUNT: - return apple->touch_count; + switch (id) + { + case RETRO_DEVICE_ID_POINTER_PRESSED: + x = touch->fixed_x; + y = touch->fixed_y; + + if (want_full) + { + x = touch->full_x; + y = touch->full_y; + } + return (x != -0x8000) && (y != -0x8000); /* Inside? */ + case RETRO_DEVICE_ID_POINTER_X: + return want_full ? touch->full_x : touch->fixed_x; + case RETRO_DEVICE_ID_POINTER_Y: + return want_full ? touch->full_y : touch->fixed_y; + case RETRO_DEVICE_ID_POINTER_COUNT: + return apple->touch_count; + } } } } diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 2cd25606ce..f0cd494b0a 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -449,7 +449,6 @@ static int16_t dinput_lightgun_aiming_state( { struct video_viewport vp; const int edge_detect = 32700; - bool inside = false; int16_t res_x = 0; int16_t res_y = 0; int16_t res_screen_x = 0; @@ -472,7 +471,7 @@ static int16_t dinput_lightgun_aiming_state( while (check_pos && num < idx) { num++; - check_pos = check_pos->next; + check_pos = check_pos->next; } if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */ @@ -487,30 +486,30 @@ static int16_t dinput_lightgun_aiming_state( y = check_pos->pointer_y; } - if (!(video_driver_translate_coord_viewport_wrap( + if (video_driver_translate_coord_viewport_wrap( &vp, x, y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - inside = (res_x >= -edge_detect) - && (res_y >= -edge_detect) - && (res_x <= edge_detect) - && (res_y <= edge_detect); - - switch ( id ) + &res_x, &res_y, &res_screen_x, &res_screen_y)) { - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: - if (inside) - return res_x; - break; - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: - if (inside) - return res_y; - break; - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; - default: - break; + bool inside = (res_x >= -edge_detect) + && (res_y >= -edge_detect) + && (res_x <= edge_detect) + && (res_y <= edge_detect); + + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: + if (inside) + return res_x; + break; + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: + if (inside) + return res_y; + break; + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return !inside; + default: + break; + } } return 0; @@ -567,301 +566,298 @@ static int16_t dinput_input_state( int16_t ret = 0; struct dinput_input *di = (struct dinput_input*)data; - if (port >= MAX_USERS) - return 0; - - switch (device) + if (port < MAX_USERS) { - case RETRO_DEVICE_JOYPAD: - { - settings = config_get_ptr(); - - if (id == RETRO_DEVICE_ID_JOYPAD_MASK) + switch (device) + { + case RETRO_DEVICE_JOYPAD: { - unsigned i; + settings = config_get_ptr(); - if (settings->uints.input_mouse_index[port] == 0) + if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + unsigned i; + + if (settings->uints.input_mouse_index[port] == 0) { - if (binds[port][i].valid) + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (dinput_mouse_button_pressed( - di, port, binds[port][i].mbutton) + if (binds[port][i].valid) + { + if (dinput_mouse_button_pressed( + di, port, binds[port][i].mbutton) + ) + ret |= (1 << i); + } + } + } + + if (!keyboard_mapping_blocked) + { + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + { + if (binds[port][i].valid) + { + if ((binds[port][i].key < RETROK_LAST) && + di->state[rarch_keysym_lut + [(enum retro_key)binds[port][i].key]] & 0x80) + ret |= (1 << i); + } + } + } + return ret; + } + + if (id < RARCH_BIND_LIST_END) + { + if (binds[port][id].valid) + { + if (binds[port][id].key < RETROK_LAST + && (di->state[rarch_keysym_lut + [(enum retro_key)binds[port][id].key]] & 0x80) + && ( (id == RARCH_GAME_FOCUS_TOGGLE) + || !keyboard_mapping_blocked) + ) + return 1; + else if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][id].mbutton) ) - ret |= (1 << i); - } + return 1; } } - - if (!keyboard_mapping_blocked) - { - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) - { - if (binds[port][i].valid) - { - if ((binds[port][i].key < RETROK_LAST) && - di->state[rarch_keysym_lut - [(enum retro_key)binds[port][i].key]] & 0x80) - ret |= (1 << i); - } - } - } - return ret; } - - if (id < RARCH_BIND_LIST_END) - { - if (binds[port][id].valid) - { - if (binds[port][id].key < RETROK_LAST - && (di->state[rarch_keysym_lut - [(enum retro_key)binds[port][id].key]] & 0x80) - && ( (id == RARCH_GAME_FOCUS_TOGGLE) - || !keyboard_mapping_blocked) - ) - return 1; - else if ( - settings->uints.input_mouse_index[port] == 0 - && dinput_mouse_button_pressed( - di, port, binds[port][id].mbutton) - ) - return 1; - } - } - } - break; - case RETRO_DEVICE_KEYBOARD: - return (id < RETROK_LAST) && - di->state[rarch_keysym_lut[(enum retro_key)id]] & 0x80; - case RETRO_DEVICE_ANALOG: - { - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - bool id_plus_valid = false; - bool id_minus_valid = false; - - input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - - id_minus_valid = binds[port][id_minus].valid; - id_plus_valid = binds[port][id_plus].valid; - id_minus_key = binds[port][id_minus].key; - id_plus_key = binds[port][id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if (di->state[sym] & 0x80) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if (di->state[sym] & 0x80) - ret += -0x7fff; - } - } - return ret; - case RARCH_DEVICE_MOUSE_SCREEN: - settings = config_get_ptr(); - if (settings->uints.input_mouse_index[ port ] != 0) break; + case RETRO_DEVICE_KEYBOARD: + return (id < RETROK_LAST) && + di->state[rarch_keysym_lut[(enum retro_key)id]] & 0x80; + case RETRO_DEVICE_ANALOG: + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return di->mouse_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return di->mouse_y; - default: + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); + + id_minus_valid = binds[port][id_minus].valid; + id_plus_valid = binds[port][id_plus].valid; + id_minus_key = binds[port][id_minus].key; + id_plus_key = binds[port][id_plus].key; + + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; + if (di->state[sym] & 0x80) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (di->state[sym] & 0x80) + ret += -0x7fff; + } + } + return ret; + case RARCH_DEVICE_MOUSE_SCREEN: + settings = config_get_ptr(); + if (settings->uints.input_mouse_index[ port ] != 0) break; - } - /* fall-through */ - case RETRO_DEVICE_MOUSE: - settings = config_get_ptr(); - if (settings->uints.input_mouse_index[port] == 0) - { - int16_t state = 0; switch (id) { case RETRO_DEVICE_ID_MOUSE_X: - return di->mouse_rel_x; + return di->mouse_x; case RETRO_DEVICE_ID_MOUSE_Y: - return di->mouse_rel_y; - case RETRO_DEVICE_ID_MOUSE_LEFT: - return (di->flags & DINP_FLAG_MOUSE_L_BTN); - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return (di->flags & DINP_FLAG_MOUSE_R_BTN); - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - if (di->flags & DINP_FLAG_MOUSE_WU_BTN) - state = 1; - di->flags &= ~DINP_FLAG_MOUSE_WU_BTN; - return state; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - if (di->flags & DINP_FLAG_MOUSE_WD_BTN) - state = 1; - di->flags &= ~DINP_FLAG_MOUSE_WD_BTN; - return state; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - if (di->flags & DINP_FLAG_MOUSE_HWU_BTN) - state = 1; - di->flags &= ~DINP_FLAG_MOUSE_HWU_BTN; - return state; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - if (di->flags & DINP_FLAG_MOUSE_HWD_BTN) - state = 1; - di->flags &= ~DINP_FLAG_MOUSE_HWD_BTN; - return state; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return (di->flags & DINP_FLAG_MOUSE_M_BTN); - case RETRO_DEVICE_ID_MOUSE_BUTTON_4: - return (di->flags & DINP_FLAG_MOUSE_B4_BTN); - case RETRO_DEVICE_ID_MOUSE_BUTTON_5: - return (di->flags & DINP_FLAG_MOUSE_B5_BTN); - } - } - break; - case RETRO_DEVICE_POINTER: - case RARCH_DEVICE_POINTER_SCREEN: - { - struct video_viewport vp; - bool pointer_down = false; - bool inside = false; - int x = 0; - int y = 0; - int16_t res_x = 0; - int16_t res_y = 0; - int16_t res_screen_x = 0; - int16_t res_screen_y = 0; - unsigned num = 0; - struct dinput_pointer_status * - check_pos = di->pointer_head.next; - - vp.x = 0; - vp.y = 0; - vp.width = 0; - vp.height = 0; - vp.full_width = 0; - vp.full_height = 0; - - while (check_pos && num < idx) - { - num++; - check_pos = check_pos->next; - } - if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */ - return 0; - - x = di->mouse_x; - y = di->mouse_y; - pointer_down = di->flags & DINP_FLAG_MOUSE_L_BTN; - - if (check_pos) - { - x = check_pos->pointer_x; - y = check_pos->pointer_y; - pointer_down = true; - } - - if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - if (device == RARCH_DEVICE_POINTER_SCREEN) - { - res_x = res_screen_x; - res_y = res_screen_y; - } - - if (!(inside = (res_x >= -0x7fff) && (res_y >= -0x7fff))) - return 0; - - switch (id) - { - case RETRO_DEVICE_ID_POINTER_X: - return res_x; - case RETRO_DEVICE_ID_POINTER_Y: - return res_y; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return pointer_down; + return di->mouse_y; default: break; } - } - break; - case RETRO_DEVICE_LIGHTGUN: - switch (id) - { - /*aiming*/ - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return dinput_lightgun_aiming_state(di, idx, id); + /* fall-through */ + case RETRO_DEVICE_MOUSE: + settings = config_get_ptr(); + if (settings->uints.input_mouse_index[port] == 0) + { + int16_t state = 0; - /*buttons*/ - case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: - case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: - case RETRO_DEVICE_ID_LIGHTGUN_START: - case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: - case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + switch (id) { - unsigned new_id = dinput_retro_id_to_rarch(id); - const uint64_t bind_joykey = input_config_binds[port][new_id].joykey; - const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis; - const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey; - const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis; - uint16_t port = joypad_info->joy_idx; - float axis_threshold = joypad_info->axis_threshold; - const uint64_t joykey = (bind_joykey != NO_BTN) - ? bind_joykey : autobind_joykey; - const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE) - ? bind_joyaxis : autobind_joyaxis; - if (binds[port][new_id].valid) + case RETRO_DEVICE_ID_MOUSE_X: + return di->mouse_rel_x; + case RETRO_DEVICE_ID_MOUSE_Y: + return di->mouse_rel_y; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return (di->flags & DINP_FLAG_MOUSE_L_BTN); + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return (di->flags & DINP_FLAG_MOUSE_R_BTN); + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + if (di->flags & DINP_FLAG_MOUSE_WU_BTN) + state = 1; + di->flags &= ~DINP_FLAG_MOUSE_WU_BTN; + return state; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + if (di->flags & DINP_FLAG_MOUSE_WD_BTN) + state = 1; + di->flags &= ~DINP_FLAG_MOUSE_WD_BTN; + return state; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + if (di->flags & DINP_FLAG_MOUSE_HWU_BTN) + state = 1; + di->flags &= ~DINP_FLAG_MOUSE_HWU_BTN; + return state; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + if (di->flags & DINP_FLAG_MOUSE_HWD_BTN) + state = 1; + di->flags &= ~DINP_FLAG_MOUSE_HWD_BTN; + return state; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return (di->flags & DINP_FLAG_MOUSE_M_BTN); + case RETRO_DEVICE_ID_MOUSE_BUTTON_4: + return (di->flags & DINP_FLAG_MOUSE_B4_BTN); + case RETRO_DEVICE_ID_MOUSE_BUTTON_5: + return (di->flags & DINP_FLAG_MOUSE_B5_BTN); + } + } + break; + case RETRO_DEVICE_POINTER: + case RARCH_DEVICE_POINTER_SCREEN: + { + struct video_viewport vp; + bool inside = false; + int x = 0; + int y = 0; + int16_t res_x = 0; + int16_t res_y = 0; + int16_t res_screen_x = 0; + int16_t res_screen_y = 0; + unsigned num = 0; + struct dinput_pointer_status * + check_pos = di->pointer_head.next; + + vp.x = 0; + vp.y = 0; + vp.width = 0; + vp.height = 0; + vp.full_width = 0; + vp.full_height = 0; + + while (check_pos && num < idx) + { + num++; + check_pos = check_pos->next; + } + if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */ + return 0; + + x = di->mouse_x; + y = di->mouse_y; + + if (check_pos) + { + x = check_pos->pointer_x; + y = check_pos->pointer_y; + } + + if (video_driver_translate_coord_viewport_wrap(&vp, x, y, + &res_x, &res_y, &res_screen_x, &res_screen_y)) + { + if (device == RARCH_DEVICE_POINTER_SCREEN) { - if ((uint16_t)joykey != NO_BTN && joypad->button( - port, (uint16_t)joykey)) - return 1; - if (joyaxis != AXIS_NONE && - ((float)abs(joypad->axis(port, joyaxis)) - / 0x8000) > axis_threshold) - return 1; - else if ( - binds[port][new_id].key < RETROK_LAST - && !keyboard_mapping_blocked - && di->state[rarch_keysym_lut - [(enum retro_key)binds[port][new_id].key]] & 0x80 - ) - return 1; - else + res_x = res_screen_x; + res_y = res_screen_y; + } + + if ((inside = (res_x >= -0x7fff) && (res_y >= -0x7fff))) + { + switch (id) { - settings = config_get_ptr(); - if ( - settings->uints.input_mouse_index[port] == 0 - && dinput_mouse_button_pressed( - di, port, binds[port][new_id].mbutton) - ) - return 1; + case RETRO_DEVICE_ID_POINTER_X: + return res_x; + case RETRO_DEVICE_ID_POINTER_Y: + return res_y; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return check_pos ? true : (di->flags & DINP_FLAG_MOUSE_L_BTN); + default: + break; } } } - break; - /*deprecated*/ - case RETRO_DEVICE_ID_LIGHTGUN_X: - return di->mouse_rel_x; - case RETRO_DEVICE_ID_LIGHTGUN_Y: - return di->mouse_rel_y; - } - break; + } + break; + case RETRO_DEVICE_LIGHTGUN: + switch (id) + { + /*aiming*/ + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return dinput_lightgun_aiming_state(di, idx, id); + + /*buttons*/ + case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: + case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: + case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: + case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: + case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: + case RETRO_DEVICE_ID_LIGHTGUN_START: + case RETRO_DEVICE_ID_LIGHTGUN_SELECT: + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + { + unsigned new_id = dinput_retro_id_to_rarch(id); + const uint64_t bind_joykey = input_config_binds[port][new_id].joykey; + const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis; + const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey; + const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis; + uint16_t port = joypad_info->joy_idx; + float axis_threshold = joypad_info->axis_threshold; + const uint64_t joykey = (bind_joykey != NO_BTN) + ? bind_joykey : autobind_joykey; + const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE) + ? bind_joyaxis : autobind_joyaxis; + if (binds[port][new_id].valid) + { + if ((uint16_t)joykey != NO_BTN && joypad->button( + port, (uint16_t)joykey)) + return 1; + if (joyaxis != AXIS_NONE && + ((float)abs(joypad->axis(port, joyaxis)) + / 0x8000) > axis_threshold) + return 1; + else if ( + binds[port][new_id].key < RETROK_LAST + && !keyboard_mapping_blocked + && di->state[rarch_keysym_lut + [(enum retro_key)binds[port][new_id].key]] & 0x80 + ) + return 1; + else + { + settings = config_get_ptr(); + if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][new_id].mbutton) + ) + return 1; + } + } + } + break; + /*deprecated*/ + case RETRO_DEVICE_ID_LIGHTGUN_X: + return di->mouse_rel_x; + case RETRO_DEVICE_ID_LIGHTGUN_Y: + return di->mouse_rel_y; + } + break; + } } return 0; @@ -885,14 +881,13 @@ static int16_t dinput_input_state( #define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam)) #endif -/* Stores x/y in client coordinates. */ +/* Stores X/Y in client coordinates. */ static void dinput_pointer_store_pos( struct dinput_pointer_status *pointer, WPARAM lParam) { POINT point; - - point.x = GET_X_LPARAM(lParam); - point.y = GET_Y_LPARAM(lParam); + point.x = GET_X_LPARAM(lParam); + point.y = GET_Y_LPARAM(lParam); ScreenToClient((HWND)video_driver_window_get(), &point); pointer->pointer_x = point.x; pointer->pointer_y = point.y; @@ -903,12 +898,12 @@ static void dinput_add_pointer(struct dinput_input *di, { struct dinput_pointer_status *insert_pos = NULL; - new_pointer->next = NULL; - insert_pos = &di->pointer_head; + new_pointer->next = NULL; + insert_pos = &di->pointer_head; while (insert_pos->next) - insert_pos = insert_pos->next; - insert_pos->next = new_pointer; + insert_pos = insert_pos->next; + insert_pos->next = new_pointer; } static void dinput_delete_pointer(struct dinput_input *di, int pointer_id) @@ -948,7 +943,7 @@ static void dinput_clear_pointers(struct dinput_input *di) while (pointer->next) { - struct dinput_pointer_status *del = pointer->next; + struct dinput_pointer_status *del = pointer->next; pointer->next = pointer->next->next; free(del); @@ -981,28 +976,29 @@ bool dinput_handle_message(void *data, struct dinput_pointer_status *new_pointer = (struct dinput_pointer_status *)malloc(sizeof(struct dinput_pointer_status)); - if (!new_pointer) - return false; - - new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam); - dinput_pointer_store_pos(new_pointer, lParam); - dinput_add_pointer(di, new_pointer); - return true; + if (new_pointer) + { + new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam); + dinput_pointer_store_pos(new_pointer, lParam); + dinput_add_pointer(di, new_pointer); + return true; + } } + break; case WM_POINTERUP: { int pointer_id = GET_POINTERID_WPARAM(wParam); dinput_delete_pointer(di, pointer_id); - return true; } + return true; case WM_POINTERUPDATE: { int pointer_id = GET_POINTERID_WPARAM(wParam); struct dinput_pointer_status *pointer = dinput_find_pointer(di, pointer_id); if (pointer) dinput_pointer_store_pos(pointer, lParam); - return true; } + return true; case WM_DEVICECHANGE: #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ if ( wParam == DBT_DEVICEARRIVAL || diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index bee207104a..3655ab6133 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -59,46 +59,46 @@ static int16_t dos_input_state( unsigned idx, unsigned id) { - if (port > 0) - return 0; - - switch (device) + if (port <= 0) { - case RETRO_DEVICE_JOYPAD: - if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - { - unsigned i; - int16_t ret = 0; - - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + switch (device) + { + case RETRO_DEVICE_JOYPAD: + if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { - if (binds[port][i].valid) + unsigned i; + int16_t ret = 0; + + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (id < RARCH_BIND_LIST_END) - if (dos_key_state[DOS_KEYBOARD_PORT] - [rarch_keysym_lut[binds[port][i].key]]) - ret |= (1 << i); + if (binds[port][i].valid) + { + if (id < RARCH_BIND_LIST_END) + if (dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[port][i].key]]) + ret |= (1 << i); + } } + + return ret; } - return ret; - } - - if (binds[port][id].valid) - { - if ( - (id < RARCH_BIND_LIST_END - && dos_key_state[DOS_KEYBOARD_PORT] - [rarch_keysym_lut[binds[port][id].key]]) - ) - return 1; - } - break; - case RETRO_DEVICE_KEYBOARD: - if (id < RARCH_BIND_LIST_END) - return (dos_key_state[DOS_KEYBOARD_PORT] - [rarch_keysym_lut[binds[port][id].key]]); - break; + if (binds[port][id].valid) + { + if ( + (id < RARCH_BIND_LIST_END + && dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[port][id].key]]) + ) + return 1; + } + break; + case RETRO_DEVICE_KEYBOARD: + if (id < RARCH_BIND_LIST_END) + return (dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[port][id].key]]); + break; + } } return 0; @@ -112,7 +112,6 @@ static void dos_input_free_input(void *data) static void* dos_input_init(const char *joypad_driver) { input_keymaps_init_keyboard_lut(rarch_key_map_dos); - return (void*)-1; } diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index b84571a730..3df3886a1f 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -50,7 +50,7 @@ static void *linuxraw_input_init(const char *joypad_driver) if (linux_terminal_grab_stdin(NULL)) { - RARCH_WARN("stdin is already used for content loading. Cannot use stdin for input.\n"); + RARCH_DBG("stdin is already used for content loading. Cannot use stdin for input.\n"); return NULL; } diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 357865b009..cebe88686f 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -73,9 +73,6 @@ static int16_t ps3_mouse_device_state(ps3_input_t *ps3, CellMouseData mouse_state; cellMouseGetData(id, &mouse_state); - if (!ps3->mice_connected) - return 0; - switch (id) { /* TODO: mouse wheel up/down */ @@ -107,34 +104,36 @@ static int16_t ps3_input_state( { ps3_input_t *ps3 = (ps3_input_t*)data; - if (!ps3) - return 0; - - switch (device) + if (ps3) { - case RETRO_DEVICE_JOYPAD: - case RETRO_DEVICE_ANALOG: - break; + switch (device) + { + case RETRO_DEVICE_JOYPAD: + case RETRO_DEVICE_ANALOG: + break; #if 0 - case RETRO_DEVICE_SENSOR_ACCELEROMETER: - switch (id) - { - /* Fixed range of 0x000 - 0x3ff */ - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X: - return ps3->accelerometer_state[port].x; - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y: - return ps3->accelerometer_state[port].y; - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z: - return ps3->accelerometer_state[port].z; - default: - break; - } - break; + case RETRO_DEVICE_SENSOR_ACCELEROMETER: + switch (id) + { + /* Fixed range of 0x000 - 0x3ff */ + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X: + return ps3->accelerometer_state[port].x; + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y: + return ps3->accelerometer_state[port].y; + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z: + return ps3->accelerometer_state[port].z; + default: + break; + } + break; #endif #ifdef HAVE_MOUSE - case RETRO_DEVICE_MOUSE: - return ps3_mouse_device_state(data, port, id); + case RETRO_DEVICE_MOUSE: + if (ps3->mice_connected) + return ps3_mouse_device_state(data, port, id); + break; #endif + } } return 0; diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index 9f4f0ac3ac..4a520ba615 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -85,9 +85,9 @@ int16_t ps4_input_state(void *data, if ((uint16_t)joykey != NO_BTN && ps4->joypad->button( joypad_info->joy_idx, (uint16_t)joykey)) - return true; + return 1; if (((float)abs(ps4->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - return true; + return 1; } break; case RETRO_DEVICE_ANALOG: diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index fa7640cf40..5c8816fc9a 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -119,11 +119,6 @@ static void ps3_connect_keyboard(ps3_input_t *ps3, int port) ps3->connected[port] = 1; } -static void ps3_disconnect_keyboard(ps3_input_t *ps3, int port) -{ - ps3->connected[port] = 0; -} - #ifdef HAVE_LIGHTGUN void endCamera(ps3_input_t *ps3) { @@ -135,62 +130,54 @@ void endCamera(ps3_input_t *ps3) int setupCamera(ps3_input_t *ps3) { - int ret; int error = 0; cameraGetType(0, &ps3->type); - if (ps3->type == CAM_TYPE_PLAYSTATION_EYE) { - ps3->camInf.format = CAM_FORM_RAW8; - ps3->camInf.framerate = 60; - ps3->camInf.resolution = CAM_RESO_VGA; - ps3->camInf.info_ver = 0x0101; - ps3->camInf.container = ps3->container; + if (ps3->type == CAM_TYPE_PLAYSTATION_EYE) + { + ps3->camInf.format = CAM_FORM_RAW8; + ps3->camInf.framerate = 60; + ps3->camInf.resolution = CAM_RESO_VGA; + ps3->camInf.info_ver = 0x0101; + ps3->camInf.container = ps3->container; - ret = cameraOpenEx(0, &ps3->camInf); - switch (ret) + switch (cameraOpenEx(0, &ps3->camInf)) { case CAMERA_ERRO_DOUBLE_OPEN: cameraClose(0); - error = 1; + error = 1; break; case CAMERA_ERRO_NO_DEVICE_FOUND: - error = 1; + error = 1; break; case 0: - ps3->camread.buffer = ps3->camInf.buffer; + ps3->camread.buffer = ps3->camInf.buffer; ps3->camread.version = 0x0100; - ps3->cam_buf = (u8 *)(u64)ps3->camread.buffer; + ps3->cam_buf = (u8 *)(u64)ps3->camread.buffer; break; default: - error = 1; + error = 1; + break; } } else - { error = 1; - } return error; } int initCamera(ps3_input_t *ps3) { - int ret; - - ret = sysMemContainerCreate(&ps3->container, 0x200000); - ret = cameraInit(); + int ret = sysMemContainerCreate(&ps3->container, 0x200000); + ret = cameraInit(); if (ret == 0) - { - ret = setupCamera(ps3); - } + return setupCamera(ps3); return ret; } int readCamera(ps3_input_t *ps3) { - int ret; - - ret = cameraReadEx(0, &ps3->camread); + int ret = cameraReadEx(0, &ps3->camread); switch (ret) { case CAMERA_ERRO_NEED_START: @@ -205,36 +192,26 @@ int readCamera(ps3_input_t *ps3) break; } if (ret == 0 && ps3->camread.readcount != 0) - { return ps3->camread.readcount; - } - else - { - return 0; - } + return 0; } int proccessGem(ps3_input_t *ps3, int t) { - int ret; - switch (t) { + switch (t) + { case 0: - ret = gemUpdateStart(ps3->camread.buffer, ps3->camread.timestamp); - break; + return gemUpdateStart(ps3->camread.buffer, ps3->camread.timestamp); case 1: - ret = gemConvertVideoStart(ps3->camread.buffer); - break; + return gemConvertVideoStart(ps3->camread.buffer); case 2: - ret = gemUpdateFinish(); - break; + return gemUpdateFinish(); case 3: - ret = gemConvertVideoFinish(); - break; + return gemConvertVideoFinish(); default: - ret = -1; break; - } - return ret; + } + return -1; } @@ -272,54 +249,38 @@ int processMove(ps3_input_t *ps3) int initSpurs(ps3_input_t *ps3) { - int ret; int i; - sys_ppu_thread_t ppu_thread_id; int ppu_prio; + sys_ppu_thread_t ppu_thread_id; unsigned int nthread; - - ret = sysSpuInitialize(6, 0); - ret = sysThreadGetId(&ppu_thread_id); - ret = sysThreadGetPriority(ppu_thread_id, &ppu_prio); + int ret = sysSpuInitialize(6, 0); + ret = sysThreadGetId(&ppu_thread_id); + ret = sysThreadGetPriority(ppu_thread_id, &ppu_prio); /* initialize spurs */ - ps3->spurs = (Spurs *)memalign(SPURS_ALIGN, sizeof(Spurs)); + ps3->spurs = (Spurs *)memalign(SPURS_ALIGN, sizeof(Spurs)); SpursAttribute attributeSpurs; - ret = spursAttributeInitialize(&attributeSpurs, 5, 250, ppu_prio - 1, true); - if (ret) - { + if ((ret = spursAttributeInitialize(&attributeSpurs, 5, 250, ppu_prio - 1, true))) return (ret); - } - ret = spursAttributeSetNamePrefix(&attributeSpurs, SPURS_PREFIX_NAME, strlen(SPURS_PREFIX_NAME)); - if (ret) - { + if ((ret = spursAttributeSetNamePrefix(&attributeSpurs, SPURS_PREFIX_NAME, strlen(SPURS_PREFIX_NAME)))) return (ret); - } - ret = spursInitializeWithAttribute(ps3->spurs, &attributeSpurs); - if (ret) - { + if ((ret = spursInitializeWithAttribute(ps3->spurs, &attributeSpurs))) return (ret); - } - ret = spursGetNumSpuThread(ps3->spurs, &nthread); - if (ret) - { + if ((ret = spursGetNumSpuThread(ps3->spurs, &nthread))) return (ret); - } ps3->threads = (sys_spu_thread_t *)malloc(sizeof(sys_spu_thread_t) * nthread); - ret = spursGetSpuThreadId(ps3->spurs, ps3->threads, &nthread); - if (ret) - { + if ((ret = spursGetSpuThreadId(ps3->spurs, ps3->threads, &nthread))) return (ret); - } SpursInfo info; ret = spursGetInfo(ps3->spurs, &info); + return 0; } @@ -345,14 +306,12 @@ static inline void initAttributeGem(gemAttribute * attribute, { int i; - attribute->version = 2; - attribute->max = max_connect; - attribute->spurs = spurs; - attribute->memory = memory_ptr; + attribute->version = 2; + attribute->max = max_connect; + attribute->spurs = spurs; + attribute->memory = memory_ptr; for (i = 0; i < 8; ++i) - { - attribute->spu_priorities[i] = spu_priorities[i]; - } + attribute->spu_priorities[i] = spu_priorities[i]; } int initGemVideoConvert(ps3_input_t *ps3) @@ -360,9 +319,9 @@ int initGemVideoConvert(ps3_input_t *ps3) ps3->gem_video_convert.version = 2; ps3->gem_video_convert.format = 2; /* GEM_RGBA_640x480; */ ps3->gem_video_convert.conversion = GEM_AUTO_WHITE_BALANCE - | GEM_COMBINE_PREVIOUS_INPUT_FRAME + | GEM_COMBINE_PREVIOUS_INPUT_FRAME | GEM_FILTER_OUTLIER_PIXELS - | GEM_GAMMA_BOOST; + | GEM_GAMMA_BOOST; ps3->gem_video_convert.gain = 1.0f; ps3->gem_video_convert.red_gain = 1.0f; ps3->gem_video_convert.green_gain = 1.0f; @@ -386,8 +345,7 @@ int initGem(ps3_input_t *ps3) if (initSpurs(ps3)) return -1; - ps3->gem_memory = (void *)malloc(gemGetMemorySize(1)); - if (!ps3->gem_memory) + if (!(ps3->gem_memory = (void *)malloc(gemGetMemorySize(1)))) return -1; initAttributeGem(&gem_attr, 1, ps3->gem_memory, @@ -507,7 +465,7 @@ static void ps3_input_poll(void *data) ps3_connect_keyboard(ps3, i); #if 0 if (!ps3->kbinfo.status[i] && ps3->connected[i]) - ps3_disconnect_keyboard(ps3, i); + ps3->connected[i] = 0; #endif } @@ -615,16 +573,17 @@ static bool psl1ght_keyboard_port_input_pressed( } code = rarch_keysym_lut[id]; - if (code == 0) - return false; - for (i = 0; i < MAX_KB_PORT_NUM; i++) + if (code != 0) { - if (ps3->kbinfo.status[i]) + for (i = 0; i < MAX_KB_PORT_NUM; i++) { - for (j = 0; j < ps3->kbdata[i].nb_keycode; j++) + if (ps3->kbinfo.status[i]) { - if (ps3->kbdata[i].keycode[j] == code) - return true; + for (j = 0; j < ps3->kbdata[i].nb_keycode; j++) + { + if (ps3->kbdata[i].keycode[j] == code) + return true; + } } } } @@ -636,24 +595,25 @@ static bool psl1ght_keyboard_port_input_pressed( static int16_t ps3_mouse_device_state(ps3_input_t *ps3, unsigned user, unsigned id) { - if (!ps3->mice_connected) - return 0; - - mouseData mouse_state; - ioMouseGetData(id, &mouse_state); - - switch (id) + if (ps3->mice_connected) { - /* TODO: mouse wheel up/down */ - case RETRO_DEVICE_ID_MOUSE_LEFT: - return (mouse_state.buttons & CELL_MOUSE_BUTTON_1); - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return (mouse_state.buttons & CELL_MOUSE_BUTTON_2); - case RETRO_DEVICE_ID_MOUSE_X: - return (mouse_state.x_axis); - case RETRO_DEVICE_ID_MOUSE_Y: - return (mouse_state.y_axis); + mouseData mouse_state; + ioMouseGetData(id, &mouse_state); + + switch (id) + { + /* TODO: mouse wheel up/down */ + case RETRO_DEVICE_ID_MOUSE_LEFT: + return (mouse_state.buttons & CELL_MOUSE_BUTTON_1); + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return (mouse_state.buttons & CELL_MOUSE_BUTTON_2); + case RETRO_DEVICE_ID_MOUSE_X: + return (mouse_state.x_axis); + case RETRO_DEVICE_ID_MOUSE_Y: + return (mouse_state.y_axis); + } } + return 0; } #endif @@ -721,9 +681,9 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, /* tracking mode 2: 3D coordinate system (move pointer position by moving the * whole controller) */ VmathVector4 v; - v.vec128 = ps3->gem_state.pos; - pointer_x = v.vec128[0]; - pointer_y = v.vec128[1]; + v.vec128 = ps3->gem_state.pos; + pointer_x = v.vec128[0]; + pointer_y = v.vec128[1]; #endif if (video_driver_translate_coord_viewport_wrap(&vp, @@ -778,11 +738,11 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, break; case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: if (inside) - return (res_x); + return res_x; break; case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: if (inside) - return (~res_y); + return ~res_y; break; case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: return !inside; @@ -809,49 +769,49 @@ static int16_t ps3_input_state( { ps3_input_t *ps3 = (ps3_input_t*)data; - if (!ps3) - return 0; - - switch (device) + if (ps3) { - case RETRO_DEVICE_JOYPAD: - if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - { - int i; - int16_t ret = 0; - - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + switch (device) + { + case RETRO_DEVICE_JOYPAD: + if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { - if (binds[port][i].valid) + int i; + int16_t ret = 0; + + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (psl1ght_keyboard_port_input_pressed( - ps3, binds[port][i].key)) - ret |= (1 << i); + if (binds[port][i].valid) + { + if (psl1ght_keyboard_port_input_pressed( + ps3, binds[port][i].key)) + ret |= (1 << i); + } } + + return ret; } - return ret; - } - - if (binds[port][id].valid) - { - if (psl1ght_keyboard_port_input_pressed( - ps3, binds[port][id].key)) - return 1; - } - break; - case RETRO_DEVICE_ANALOG: - break; - case RETRO_DEVICE_KEYBOARD: - return psl1ght_keyboard_port_input_pressed(ps3, id); + if (binds[port][id].valid) + { + if (psl1ght_keyboard_port_input_pressed( + ps3, binds[port][id].key)) + return 1; + } + break; + case RETRO_DEVICE_ANALOG: + break; + case RETRO_DEVICE_KEYBOARD: + return psl1ght_keyboard_port_input_pressed(ps3, id); #ifdef HAVE_MOUSE - case RETRO_DEVICE_MOUSE: - return ps3_mouse_device_state(ps3, port, id); + case RETRO_DEVICE_MOUSE: + return ps3_mouse_device_state(ps3, port, id); #endif #ifdef HAVE_LIGHTGUN - case RETRO_DEVICE_LIGHTGUN: - return ps3_lightgun_device_state(ps3, port, id); + case RETRO_DEVICE_LIGHTGUN: + return ps3_lightgun_device_state(ps3, port, id); #endif + } } return 0; diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 4a82a40e0c..2a68652fe7 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -317,34 +317,34 @@ static bool psp_input_set_sensor_state(void *data, unsigned port, { psp_input_t *psp = (psp_input_t*)data; - if (!psp) - return false; - - switch (action) + if (psp) { - case RETRO_SENSOR_ILLUMINANCE_DISABLE: - return true; - case RETRO_SENSOR_ACCELEROMETER_DISABLE: - case RETRO_SENSOR_GYROSCOPE_DISABLE: - if(psp->sensors_enabled) - { - psp->sensors_enabled = false; - sceMotionMagnetometerOff(); - sceMotionStopSampling(); - } - return true; - case RETRO_SENSOR_ACCELEROMETER_ENABLE: - case RETRO_SENSOR_GYROSCOPE_ENABLE: - if(!psp->sensors_enabled) - { - psp->sensors_enabled = true; - sceMotionStartSampling(); - sceMotionMagnetometerOn(); - } - return true; - case RETRO_SENSOR_DUMMY: - case RETRO_SENSOR_ILLUMINANCE_ENABLE: - break; + switch (action) + { + case RETRO_SENSOR_ILLUMINANCE_DISABLE: + return true; + case RETRO_SENSOR_ACCELEROMETER_DISABLE: + case RETRO_SENSOR_GYROSCOPE_DISABLE: + if(psp->sensors_enabled) + { + psp->sensors_enabled = false; + sceMotionMagnetometerOff(); + sceMotionStopSampling(); + } + return true; + case RETRO_SENSOR_ACCELEROMETER_ENABLE: + case RETRO_SENSOR_GYROSCOPE_ENABLE: + if(!psp->sensors_enabled) + { + psp->sensors_enabled = true; + sceMotionStartSampling(); + sceMotionMagnetometerOn(); + } + return true; + case RETRO_SENSOR_DUMMY: + case RETRO_SENSOR_ILLUMINANCE_ENABLE: + break; + } } return false; @@ -358,7 +358,7 @@ static float psp_input_get_sensor_input(void *data, psp_input_t *psp = (psp_input_t*)data; if(!psp || !psp->sensors_enabled) - return false; + return 0.0f; if(id >= RETRO_SENSOR_ACCELEROMETER_X && id <= RETRO_SENSOR_GYROSCOPE_Z) { @@ -399,9 +399,9 @@ static void *vita_input_initialize(const char *joypad_driver) for (i = 0; i <= VITA_MAX_SCANCODE; i++) psp->keyboard_state[i] = false; for (i = 0; i < 6; i++) - psp->prev_keys[i] = 0; - psp->mouse_x = 0; - psp->mouse_y = 0; + psp->prev_keys[i] = 0; + psp->mouse_x = 0; + psp->mouse_y = 0; return psp; } diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index 4a9fbeca60..729793d62f 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -384,13 +384,13 @@ static int16_t rwebinput_mouse_state( case RETRO_DEVICE_ID_MOUSE_BUTTON_5: return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTN5)); case RETRO_DEVICE_ID_MOUSE_WHEELUP: - return mouse->scroll_y < 0.0; + return mouse->scroll_y < 0.0f; case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - return mouse->scroll_y > 0.0; + return mouse->scroll_y > 0.0f; case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - return mouse->scroll_x < 0.0; + return mouse->scroll_x < 0.0f; case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - return mouse->scroll_x > 0.0; + return mouse->scroll_x > 0.0f; } return 0; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 8d9114e19b..3774c82421 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -28,7 +28,6 @@ #include "../../configuration.h" #include "../../retroarch.h" -#include "../../verbosity.h" #include "../../tasks/tasks_internal.h" #ifdef HAVE_SDL2 @@ -61,7 +60,8 @@ typedef struct sdl_input } sdl_input_t; #ifdef WEBOS -enum sdl_webos_special_key { +enum sdl_webos_special_key +{ sdl_webos_spkey_back, sdl_webos_spkey_size, }; @@ -202,14 +202,14 @@ static int16_t sdl_input_state( sdl->mouse_wd = 0; return 1; } - return 0; + break; case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: if (sdl->mouse_wu != 0) { sdl->mouse_wu = 0; return 1; } - return 0; + break; case RETRO_DEVICE_ID_MOUSE_X: return sdl->mouse_abs_x; case RETRO_DEVICE_ID_MOUSE_Y: @@ -339,16 +339,14 @@ static void sdl2_grab_mouse(void *data, bool state) video_ptr = (sdl2_video_t*)video_driver_get_ptr(); - if (!video_ptr) - return; - - SDL_SetWindowGrab(video_ptr->window, state ? SDL_TRUE : SDL_FALSE); + if (video_ptr) + SDL_SetWindowGrab(video_ptr->window, state ? SDL_TRUE : SDL_FALSE); } #endif static void sdl_poll_mouse(sdl_input_t *sdl) { - Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y); + Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y); SDL_GetMouseState(&sdl->mouse_abs_x, &sdl->mouse_abs_y); @@ -483,11 +481,11 @@ input_driver_t input_sdl = { SDL_bool SDL_webOSCursorVisibility(SDL_bool visible) { static SDL_bool (*fn)(SDL_bool visible) = NULL; - static bool dlsym_called = false; + static bool dlsym_called = false; if (!dlsym_called) { - fn = dlsym(RTLD_NEXT, "SDL_webOSCursorVisibility"); - dlsym_called = true; + fn = dlsym(RTLD_NEXT, "SDL_webOSCursorVisibility"); + dlsym_called = true; } if (!fn) { diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 7d6f8d4236..222afaed4c 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -598,7 +598,7 @@ static int udev_input_add_device(udev_input_t *udev, mouse = 1; if (!test_bit(keycaps, BTN_MOUSE)) - RARCH_LOG("[udev]: Waring REL pointer device (%s) has no mouse button\n",device->ident); + RARCH_DBG("[udev]: Waring REL pointer device (%s) has no mouse button\n",device->ident); } } @@ -617,7 +617,7 @@ static int udev_input_add_device(udev_input_t *udev, device->mouse.abs = 2; if ( !test_bit(keycaps, BTN_TOUCH) && !test_bit(keycaps, BTN_MOUSE) ) - RARCH_LOG("[udev]: Warning ABS pointer device (%s) has no touch or mouse button\n",device->ident); + RARCH_DBG("[udev]: Warning ABS pointer device (%s) has no touch or mouse button\n",device->ident); } } @@ -631,7 +631,7 @@ static int udev_input_add_device(udev_input_t *udev, if (ioctl(fd, EVIOCGABS(ABS_X), &absinfo) == -1) { - RARCH_LOG("[udev]: ABS pointer device (%s) Failed to get ABS_X parameters \n",device->ident); + RARCH_DBG("[udev]: ABS pointer device (%s) Failed to get ABS_X parameters \n",device->ident); goto end; } @@ -640,7 +640,7 @@ static int udev_input_add_device(udev_input_t *udev, if (ioctl(fd, EVIOCGABS(ABS_Y), &absinfo) == -1) { - RARCH_LOG("[udev]: ABS pointer device (%s) Failed to get ABS_Y parameters \n",device->ident); + RARCH_DBG("[udev]: ABS pointer device (%s) Failed to get ABS_Y parameters \n",device->ident); goto end; } device->mouse.y_min = absinfo.minimum; @@ -942,37 +942,29 @@ static int16_t udev_lightgun_aiming_state( { const int edge_detect = 32700; - bool inside = false; - int16_t res_x = 0; - int16_t res_y = 0; - int16_t res_screen_x = 0; - int16_t res_screen_y = 0; - udev_input_mouse_t *mouse = udev_get_mouse(udev, port); - if (!mouse) - return 0; - - res_x = udev_mouse_get_pointer_x(mouse, false); - res_y = udev_mouse_get_pointer_y(mouse, false); - - inside = (res_x >= -edge_detect) - && (res_y >= -edge_detect) - && (res_x <= edge_detect) - && (res_y <= edge_detect); - - switch ( id ) + if (mouse) { - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: + bool inside = false; + int16_t res_x = udev_mouse_get_pointer_x(mouse, false); + int16_t res_y = udev_mouse_get_pointer_y(mouse, false); + + switch ( id ) + { + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: return res_x; - break; - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: return res_y; - break; - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; - default: - break; + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + inside = (res_x >= -edge_detect) + && (res_y >= -edge_detect) + && (res_x <= edge_detect) + && (res_y <= edge_detect); + return !inside; + default: + break; + } } return 0; @@ -983,37 +975,37 @@ static int16_t udev_mouse_state(udev_input_t *udev, { udev_input_mouse_t *mouse = udev_get_mouse(udev, port); - if (!mouse) - return 0; - - if (id != RETRO_DEVICE_ID_MOUSE_X && id != RETRO_DEVICE_ID_MOUSE_Y && - udev_pointer_is_off_window(udev)) - return 0; - - switch (id) + if (mouse) { - case RETRO_DEVICE_ID_MOUSE_X: - return screen ? udev->pointer_x : udev_mouse_get_x(mouse); - case RETRO_DEVICE_ID_MOUSE_Y: - return screen ? udev->pointer_y : udev_mouse_get_y(mouse); - case RETRO_DEVICE_ID_MOUSE_LEFT: - return mouse->l; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return mouse->r; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return mouse->m; - case RETRO_DEVICE_ID_MOUSE_BUTTON_4: - return mouse->b4; - case RETRO_DEVICE_ID_MOUSE_BUTTON_5: - return mouse->b5; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - return mouse->wu; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - return mouse->wd; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - return mouse->whu; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - return mouse->whd; + if (id != RETRO_DEVICE_ID_MOUSE_X && id != RETRO_DEVICE_ID_MOUSE_Y && + udev_pointer_is_off_window(udev)) + return 0; + + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_X: + return screen ? udev->pointer_x : udev_mouse_get_x(mouse); + case RETRO_DEVICE_ID_MOUSE_Y: + return screen ? udev->pointer_y : udev_mouse_get_y(mouse); + case RETRO_DEVICE_ID_MOUSE_LEFT: + return mouse->l; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return mouse->r; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return mouse->m; + case RETRO_DEVICE_ID_MOUSE_BUTTON_4: + return mouse->b4; + case RETRO_DEVICE_ID_MOUSE_BUTTON_5: + return mouse->b5; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + return mouse->wu; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + return mouse->wd; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + return mouse->whu; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + return mouse->whd; + } } return 0; @@ -1063,20 +1055,19 @@ static int16_t udev_pointer_state(udev_input_t *udev, { udev_input_mouse_t *mouse = udev_get_mouse(udev, port); - if (!mouse) - return 0; - - switch (id) + if (mouse) { - case RETRO_DEVICE_ID_POINTER_X: - return udev_mouse_get_pointer_x(mouse, screen); - case RETRO_DEVICE_ID_POINTER_Y: - return udev_mouse_get_pointer_y(mouse, screen); - case RETRO_DEVICE_ID_POINTER_PRESSED: - if(mouse->abs == 1) - return mouse->pp; - else - return mouse->l; + switch (id) + { + case RETRO_DEVICE_ID_POINTER_X: + return udev_mouse_get_pointer_x(mouse, screen); + case RETRO_DEVICE_ID_POINTER_Y: + return udev_mouse_get_pointer_y(mouse, screen); + case RETRO_DEVICE_ID_POINTER_PRESSED: + if(mouse->abs == 1) + return mouse->pp; + return mouse->l; + } } return 0; } @@ -1371,12 +1362,10 @@ static bool open_devices(udev_input_t *udev, if (fd != -1) { - int check = udev_input_add_device(udev, type, devnode, cb); - if (check == 0) - RARCH_LOG("[udev]: udev_input_add_device error : %s (%s).\n", + if (udev_input_add_device(udev, type, devnode, cb) == 0) + RARCH_DBG("[udev]: udev_input_add_device error : %s (%s).\n", devnode, strerror(errno)); - (void)check; close(fd); } } @@ -1406,8 +1395,7 @@ static void *udev_input_init(const char *joypad_driver) if (!udev->udev) goto error; - udev->monitor = udev_monitor_new_from_netlink(udev->udev, "udev"); - if (udev->monitor) + if ((udev->monitor = udev_monitor_new_from_netlink(udev->udev, "udev"))) { udev_monitor_filter_add_match_subsystem_devtype(udev->monitor, "input", NULL); udev_monitor_enable_receiving(udev->monitor); @@ -1467,7 +1455,7 @@ static void *udev_input_init(const char *joypad_driver) { if (udev->devices[i]->type != UDEV_INPUT_KEYBOARD) { - RARCH_LOG("[udev]: Mouse #%u: \"%s\" (%s) %s\n", + RARCH_DBG("[udev]: Mouse #%u: \"%s\" (%s) %s\n", mouse, udev->devices[i]->ident, udev->devices[i]->mouse.abs ? "ABS" : "REL", @@ -1478,7 +1466,7 @@ static void *udev_input_init(const char *joypad_driver) } else { - RARCH_LOG("[udev]: Keyboard #%u: \"%s\" (%s).\n", + RARCH_DBG("[udev]: Keyboard #%u: \"%s\" (%s).\n", keyboard, udev->devices[i]->ident, udev->devices[i]->devnode); diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 0aa190d857..2df385a17f 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -42,7 +42,6 @@ #include "../common/wayland_common.h" #include "../../retroarch.h" -#include "../../verbosity.h" /* TODO/FIXME - * fix game focus toggle */ @@ -56,8 +55,6 @@ static bool wayland_context_gettouchpos( unsigned id, unsigned* touch_x, unsigned* touch_y) { - if (id >= MAX_TOUCHES) - return false; *touch_x = wl->active_touch_positions[id].x; *touch_y = wl->active_touch_positions[id].y; return wl->active_touch_positions[id].active; @@ -99,48 +96,44 @@ static void input_wl_poll(void *data) static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl, unsigned idx, unsigned id, bool screen) { - struct video_viewport vp; - - bool inside = false; - int16_t res_x = 0; - int16_t res_y = 0; - int16_t res_screen_x = 0; - int16_t res_screen_y = 0; - - vp.x = 0; - vp.y = 0; - vp.width = 0; - vp.height = 0; - vp.full_width = 0; - vp.full_height = 0; - - if (idx > MAX_TOUCHES) - return 0; - - if (!(video_driver_translate_coord_viewport_wrap(&vp, - wl->touches[idx].x, wl->touches[idx].y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - if (screen) + if (idx <= MAX_TOUCHES) { - res_x = res_screen_x; - res_y = res_screen_y; - } + struct video_viewport vp; + int16_t res_x = 0; + int16_t res_y = 0; + int16_t res_screen_x = 0; + int16_t res_screen_y = 0; - inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); + vp.x = 0; + vp.y = 0; + vp.width = 0; + vp.height = 0; + vp.full_width = 0; + vp.full_height = 0; - if (!inside) - return 0; + if (video_driver_translate_coord_viewport_wrap(&vp, + wl->touches[idx].x, wl->touches[idx].y, + &res_x, &res_y, &res_screen_x, &res_screen_y)) + { + if (screen) + { + res_x = res_screen_x; + res_y = res_screen_y; + } - switch (id) - { - case RETRO_DEVICE_ID_POINTER_X: - return res_x; - case RETRO_DEVICE_ID_POINTER_Y: - return res_y; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return wl->touches[idx].active; + if ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */ + { + switch (id) + { + case RETRO_DEVICE_ID_POINTER_X: + return res_x; + case RETRO_DEVICE_ID_POINTER_Y: + return res_y; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return wl->touches[idx].active; + } + } + } } return 0; @@ -294,7 +287,6 @@ static int16_t input_wl_state( struct video_viewport vp; bool screen = (device == RARCH_DEVICE_POINTER_SCREEN); - bool inside = false; int16_t res_x = 0; int16_t res_y = 0; int16_t res_screen_x = 0; @@ -311,28 +303,39 @@ static int16_t input_wl_state( wl->mouse.x, wl->mouse.y, &res_x, &res_y, &res_screen_x, &res_screen_y)) { - if (screen) - { - res_x = res_screen_x; - res_y = res_screen_y; - } - - inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); - switch (id) { case RETRO_DEVICE_ID_POINTER_X: - if (inside) - return res_x; + { + if (screen) + { + res_x = res_screen_x; + res_y = res_screen_y; + } + return ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */ + return res_x; + } break; case RETRO_DEVICE_ID_POINTER_Y: - if (inside) - return res_y; + { + if (screen) + { + res_x = res_screen_x; + res_y = res_screen_y; + } + if ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */ + return res_y; + } break; case RETRO_DEVICE_ID_POINTER_PRESSED: return wl->mouse.left; case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; + if (screen) + { + res_x = res_screen_x; + res_y = res_screen_y; + } + return (!((res_x >= -0x7fff) && (res_y >= -0x7fff))); default: break; } @@ -340,43 +343,38 @@ static int16_t input_wl_state( } break; case RARCH_DEVICE_POINTER_SCREEN: - if (port > 0 ) return 0; /* TODO: support pointers on additional ports */ + if (port > 0) + break; /* TODO: support pointers on additional ports */ if (idx < MAX_TOUCHES) return input_wl_touch_state(wl, idx, id, device == RARCH_DEVICE_POINTER_SCREEN); break; case RETRO_DEVICE_LIGHTGUN: - if (port > 0 ) return 0; /* TODO: support lightguns on additional ports */ + if (port > 0) + break; /* TODO: support lightguns on additional ports */ switch (id) { - case RETRO_DEVICE_ID_LIGHTGUN_X: /* TODO: migrate to RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X */ - return wl->mouse.delta_x; /* deprecated relative coordinates */ - case RETRO_DEVICE_ID_LIGHTGUN_Y: /* TODO: migrate to RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y */ - return wl->mouse.delta_y; /* deprecated relative coordinates */ - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: /* TODO: implement this status check*/ - return 0; + case RETRO_DEVICE_ID_LIGHTGUN_X: /* TODO: migrate to RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X */ + return wl->mouse.delta_x; /* deprecated relative coordinates */ + case RETRO_DEVICE_ID_LIGHTGUN_Y: /* TODO: migrate to RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y */ + return wl->mouse.delta_y; /* deprecated relative coordinates */ case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: return wl->mouse.left; - case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: /* forced/faked off-screen shot */ + case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: /* forced/faked off-screen shot */ return wl->mouse.middle; - case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: /* TODO */ - return 0; - case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: /* TODO */ - return 0; case RETRO_DEVICE_ID_LIGHTGUN_START: return wl->mouse.right; case RETRO_DEVICE_ID_LIGHTGUN_SELECT: return wl->mouse.left && wl->mouse.right; - case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: /* TODO */ - return 0; - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: /* TODO */ - return 0; - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: /* TODO */ - return 0; - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: /* TODO */ - return 0; - case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: /* TODO */ - return 0; + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: /* TODO: implement this status check*/ + case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: /* TODO */ + case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: /* TODO */ + break; } break; } diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 0c0ba91042..5dcd5505df 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -30,7 +30,6 @@ #include "../../configuration.h" #include "../../retroarch.h" -#include "../../verbosity.h" typedef struct x11_input { @@ -61,8 +60,7 @@ static void *x_input_init(const char *joypad_driver) return NULL; } - x11 = (x11_input_t*)calloc(1, sizeof(*x11)); - if (!x11) + if (!(x11 = (x11_input_t*)calloc(1, sizeof(*x11)))) return NULL; /* Borrow the active X window ... */ @@ -439,34 +437,32 @@ static void x_input_free(void *data) { x11_input_t *x11 = (x11_input_t*)data; - if (!x11) - return; - - free(x11); + if (x11) + free(x11); } static void x_input_poll(void *data) { Window root_win; Window child_win; - x11_input_t *x11 = (x11_input_t*)data; - bool video_has_focus = video_driver_has_focus(); - int root_x = 0; - int root_y = 0; - int win_x = 0; - int win_y = 0; - unsigned mask = 0; + x11_input_t *x11 = (x11_input_t*)data; + bool video_has_focus = video_driver_has_focus(); + int root_x = 0; + int root_y = 0; + int win_x = 0; + int win_y = 0; + unsigned mask = 0; /* If window loses focus, 'reset' keyboard * and ignore mouse input */ if (!video_has_focus) { memset(x11->state, 0, sizeof(x11->state)); - x11->mouse_delta_x = 0; - x11->mouse_delta_y = 0; - x11->mouse_l = 0; - x11->mouse_m = 0; - x11->mouse_r = 0; + x11->mouse_delta_x = 0; + x11->mouse_delta_y = 0; + x11->mouse_l = 0; + x11->mouse_m = 0; + x11->mouse_r = 0; return; } @@ -477,11 +473,11 @@ static void x_input_poll(void *data) * window, ignore mouse input */ if (!g_x11_entered) { - x11->mouse_delta_x = 0; - x11->mouse_delta_y = 0; - x11->mouse_l = 0; - x11->mouse_m = 0; - x11->mouse_r = 0; + x11->mouse_delta_x = 0; + x11->mouse_delta_y = 0; + x11->mouse_l = 0; + x11->mouse_m = 0; + x11->mouse_r = 0; return; } @@ -495,9 +491,9 @@ static void x_input_poll(void *data) return; /* > Mouse buttons */ - x11->mouse_l = mask & Button1Mask; - x11->mouse_m = mask & Button2Mask; - x11->mouse_r = mask & Button3Mask; + x11->mouse_l = mask & Button1Mask; + x11->mouse_m = mask & Button2Mask; + x11->mouse_r = mask & Button3Mask; /* > Mouse pointer */ if (!x11->mouse_grabbed) @@ -505,25 +501,24 @@ static void x_input_poll(void *data) /* Mouse is not grabbed - this corresponds * to 'conventional' pointer input, using * absolute screen coordinates */ - int mouse_last_x = x11->mouse_x; - int mouse_last_y = x11->mouse_y; + int mouse_last_x = x11->mouse_x; + int mouse_last_y = x11->mouse_y; - x11->mouse_x = win_x; - x11->mouse_y = win_y; + x11->mouse_x = win_x; + x11->mouse_y = win_y; - x11->mouse_delta_x = x11->mouse_x - mouse_last_x; - x11->mouse_delta_y = x11->mouse_y - mouse_last_y; + x11->mouse_delta_x = x11->mouse_x - mouse_last_x; + x11->mouse_delta_y = x11->mouse_y - mouse_last_y; } else { /* Mouse is grabbed - all pointer movement * must be considered 'relative' */ XWindowAttributes win_attr; - int centre_x; - int centre_y; - int warp_x = win_x; - int warp_y = win_y; - bool do_warp = false; + int centre_x, centre_y; + int warp_x = win_x; + int warp_y = win_y; + bool do_warp = false; /* Get dimensions/centre coordinates of * application window */ @@ -534,24 +529,31 @@ static void x_input_poll(void *data) return; } - centre_x = win_attr.width >> 1; - centre_y = win_attr.height >> 1; + centre_x = win_attr.width >> 1; + centre_y = win_attr.height >> 1; /* Get relative movement delta since last * poll event */ - x11->mouse_delta_x = win_x - centre_x; - x11->mouse_delta_y = win_y - centre_y; + x11->mouse_delta_x = win_x - centre_x; + x11->mouse_delta_y = win_y - centre_y; /* Get effective 'absolute' pointer location * (last position + delta, bounded by current * application window dimensions) */ - x11->mouse_x += x11->mouse_delta_x; - x11->mouse_x = (x11->mouse_x < 0) ? 0 : x11->mouse_x; - x11->mouse_x = (x11->mouse_x >= win_attr.width) ? (win_attr.width - 1) : x11->mouse_x; + x11->mouse_x += x11->mouse_delta_x; + x11->mouse_y += x11->mouse_delta_y; - x11->mouse_y += x11->mouse_delta_y; - x11->mouse_y = (x11->mouse_y < 0) ? 0 : x11->mouse_y; - x11->mouse_y = (x11->mouse_y >= win_attr.height) ? (win_attr.height - 1) : x11->mouse_y; + /* Clamp X */ + if (x11->mouse_x < 0) + x11->mouse_x = 0; + if (x11->mouse_x >= win_attr.width) + x11->mouse_x = (win_attr.width - 1); + + /* Clamp Y */ + if (x11->mouse_y < 0) + x11->mouse_y = 0; + if (x11->mouse_y >= win_attr.height) + x11->mouse_y = (win_attr.height - 1); /* Hack/workaround: * - X11 gives absolute pointer coordinates @@ -588,10 +590,8 @@ static void x_input_poll(void *data) static void x_grab_mouse(void *data, bool state) { x11_input_t *x11 = (x11_input_t*)data; - if (!x11) - return; - - x11->mouse_grabbed = state; + if (x11) + x11->mouse_grabbed = state; } static uint64_t x_input_get_capabilities(void *data) diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index f8145a0c6b..1566a6f194 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -28,8 +28,6 @@ #include #include -#include "../../config.def.h" - #include "../input_driver.h" static void xdk_input_free_input(void *data) { } diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 48434e41fe..8db7301de5 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -23,8 +23,6 @@ #include -#include "../../config.def.h" - #include "../input_driver.h" /* TODO/FIXME - add joypad driver */