Support for lightgun in Wayland input driver (#17152)

This commit is contained in:
zoltanvb 2024-11-04 01:14:41 +01:00 committed by GitHub
parent 71ed81dc38
commit d5dd3689fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -365,12 +365,47 @@ static int16_t input_wl_state(
case RETRO_DEVICE_LIGHTGUN:
if (port == 0) /* TODO/FIXME: support lightguns on additional ports */
{
const int edge_detect = 32700;
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;
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 (video_driver_translate_coord_viewport_wrap(&vp,
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);
if (!inside)
return 0;
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_SCREEN_X:
return res_x;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
return res_y;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return wl->mouse.left;
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: /* forced/faked off-screen shot */
@ -379,7 +414,17 @@ static int16_t input_wl_state(
return wl->mouse.right;
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
return wl->mouse.left && wl->mouse.right;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: /* TODO: implement this status check*/
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
if (screen)
{
res_x = res_screen_x;
res_y = res_screen_y;
}
inside = (res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
return (!inside);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: /* TODO */
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: /* TODO */
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: /* TODO */
@ -390,6 +435,7 @@ static int16_t input_wl_state(
break;
}
}
}
break;
}