Skip to content

Commit

Permalink
Input sanitization, wayland enhancement and overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb committed Dec 28, 2024
1 parent b8c9665 commit 87362d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 67 deletions.
3 changes: 3 additions & 0 deletions input/drivers/android_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 29 additions & 27 deletions input/drivers/wayland_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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 =
Expand All @@ -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:
Expand All @@ -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. */
{
Expand Down
52 changes: 12 additions & 40 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 87362d8

Please sign in to comment.