diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 8e4f16ae9e62..01f34132c6e3 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -829,6 +829,9 @@ static INLINE void android_input_poll_event_type_motion( vp.full_width = 0; vp.full_height = 0; + /* On other platforms, pointer query uses the confined wrap function, * + * but some extra functionality is added to Android which needs the * + * true offscreen value -0x8000. */ video_driver_translate_coord_viewport_wrap( &vp, x, y, diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 56c8e4096cbb..f1c86ef45504 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -109,18 +109,16 @@ static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl, { if (idx <= MAX_TOUCHES) { - struct video_viewport vp; + struct video_viewport vp = {0}; 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; + /* Shortcut: mouse button events will be reported on desktop with 0/0 coordinates. * + * Skip these, mouse handling will catch it elsewhere. */ + if (wl->touches[idx].x == 0 && wl->touches[idx].y == 0) + return 0; if (video_driver_translate_coord_viewport_confined_wrap(&vp, wl->touches[idx].x, wl->touches[idx].y, @@ -132,17 +130,14 @@ static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl, res_y = res_screen_y; } - if ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */ + switch (id) { - 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; - } + 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; } } } @@ -301,8 +296,18 @@ static int16_t input_wl_state( } break; case RETRO_DEVICE_POINTER: + case RARCH_DEVICE_POINTER_SCREEN: /* All ports report the same pointer state. See notes at mouse case. */ - if (idx == 0) + if (idx < MAX_TOUCHES) + { + int16_t touch_state = input_wl_touch_state(wl, idx, id, + device == RARCH_DEVICE_POINTER_SCREEN); + /* Touch state is only reported if it is meaningful. */ + if (touch_state) + return touch_state; + } + /* Fall through to system pointer emulating max. 3 touches. */ + if (idx < 3) { struct video_viewport vp = {0}; bool screen = @@ -329,7 +334,12 @@ static int16_t input_wl_state( case RETRO_DEVICE_ID_POINTER_Y: return res_y; case RETRO_DEVICE_ID_POINTER_PRESSED: - return wl->mouse.left; + if (idx == 0) + return (wl->mouse.left | wl->mouse.right | wl->mouse.middle); + else if (idx == 1) + return (wl->mouse.right | wl->mouse.middle); + else if (idx == 2) + return wl->mouse.middle; case RETRO_DEVICE_ID_POINTER_IS_OFFSCREEN: return input_driver_pointer_is_offscreen(res_x, res_y); default: @@ -338,14 +348,6 @@ static int16_t input_wl_state( } } break; - case RARCH_DEVICE_POINTER_SCREEN: - if (port == 0) /* TODO/FIXME: 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: /* All ports report the same lightgun state. See notes at mouse case. */ { diff --git a/input/input_driver.c b/input/input_driver.c index 0a5b1e7c3f6e..c9a480891cf6 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -1207,64 +1207,36 @@ static int16_t input_overlay_lightgun_state(settings_t *settings, switch(id) { + /* Pointer positions have been clamped earlier in input drivers, * + * so if we want to pass true offscreen value, it must be detected */ case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: ptr_st->device_mask |= (1 << RETRO_DEVICE_LIGHTGUN); - - if ( ptr_st->ptr[0].x != -0x8000 - || settings->bools.input_overlay_lightgun_allow_offscreen) + if ( ( ptr_st->ptr[0].x > -0x7fff && ptr_st->ptr[0].x != 0x7fff) + || !settings->bools.input_overlay_lightgun_allow_offscreen) return ptr_st->ptr[0].x; - else if (video_driver_get_viewport_info(&vp)) - { - edge = ((2 * vp.x * 0x7fff) / (int)vp.full_width) - 0x7fff; - return ((ptr_st->screen_x > edge) ? 0x7fff : -0x7fff); - } - return -0x8000; + else + return -0x8000; case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: - if ( ptr_st->ptr[0].y != -0x8000 - || settings->bools.input_overlay_lightgun_allow_offscreen) + if ( ( ptr_st->ptr[0].y > -0x7fff && ptr_st->ptr[0].y != 0x7fff) + || !settings->bools.input_overlay_lightgun_allow_offscreen) return ptr_st->ptr[0].y; - else if (video_driver_get_viewport_info(&vp)) - { - edge = ((2 * vp.y * 0x7fff) / (int)vp.full_height) - 0x7fff; - return ((ptr_st->screen_y > edge) ? 0x7fff : -0x7fff); - } - return -0x8000; + else + return -0x8000; case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return ( settings->bools.input_overlay_lightgun_allow_offscreen - && (ptr_st->ptr[0].x == -0x8000 || ptr_st->ptr[0].y == -0x8000)); + return input_driver_pointer_is_offscreen(ptr_st->ptr[0].x, ptr_st->ptr[0].y); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - rarch_id = RARCH_LIGHTGUN_AUX_A; - break; case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: - rarch_id = RARCH_LIGHTGUN_AUX_B; - break; case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: - rarch_id = RARCH_LIGHTGUN_AUX_C; - break; case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - rarch_id = RARCH_LIGHTGUN_TRIGGER; - break; case RETRO_DEVICE_ID_LIGHTGUN_START: case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: - rarch_id = RARCH_LIGHTGUN_START; - break; case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - rarch_id = RARCH_LIGHTGUN_SELECT; - break; case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - rarch_id = RARCH_LIGHTGUN_RELOAD; - break; case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: - rarch_id = RARCH_LIGHTGUN_DPAD_UP; - break; case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: - rarch_id = RARCH_LIGHTGUN_DPAD_DOWN; - break; case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: - rarch_id = RARCH_LIGHTGUN_DPAD_LEFT; - break; case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: - rarch_id = RARCH_LIGHTGUN_DPAD_RIGHT; + rarch_id = input_driver_lightgun_id_convert(id); break; default: rarch_id = RARCH_BIND_LIST_END;