From 5f086056801bcebb61c9e9a46d1e08bd21cdc523 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 05:29:32 +0200 Subject: [PATCH 01/30] Refactor joypad drivers --- gfx/common/d3d_common.c | 10 +- gfx/drivers/ctr_gfx.c | 2 +- gfx/drivers/gcm_gfx.c | 2 +- gfx/drivers/gdi_gfx.c | 4 +- gfx/drivers/gx2_gfx.c | 2 +- gfx/drivers/gx_gfx.c | 2 +- gfx/drivers/network_gfx.c | 2 +- gfx/drivers/oga_gfx.c | 2 +- gfx/drivers/ps2_gfx.c | 2 +- gfx/drivers/psp1_gfx.c | 2 +- gfx/drivers/sdl_dingux_gfx.c | 3 +- gfx/drivers/sdl_gfx.c | 3 +- gfx/drivers/sixel_gfx.c | 3 +- gfx/drivers/switch_nx_gfx.c | 7 +- gfx/drivers/vita2d_gfx.c | 3 +- gfx/drivers/xshm_gfx.c | 4 +- gfx/drivers/xvideo.c | 3 +- gfx/drivers_context/android_ctx.c | 2 +- gfx/drivers_context/android_vk_ctx.c | 2 +- gfx/drivers_context/drm_ctx.c | 4 +- gfx/drivers_context/drm_go2_ctx.c | 2 +- gfx/drivers_context/emscriptenegl_ctx.c | 2 +- gfx/drivers_context/khr_display_ctx.c | 4 +- gfx/drivers_context/ps3_ctx.c | 2 +- gfx/drivers_context/qnx_ctx.c | 2 +- gfx/drivers_context/uwp_egl_ctx.c | 4 +- gfx/drivers_context/w_vk_ctx.c | 6 +- gfx/drivers_context/wayland_ctx.c | 1 + gfx/drivers_context/wayland_vk_ctx.c | 1 + gfx/drivers_context/wgl_ctx.c | 4 +- gfx/drivers_context/x_ctx.c | 4 +- gfx/drivers_context/x_vk_ctx.c | 4 +- gfx/drivers_context/xegl_ctx.c | 2 +- input/drivers/android_input.c | 42 ++-- input/drivers/cocoa_input.c | 81 ++---- input/drivers/cocoa_input.h | 5 - input/drivers/ctr_input.c | 47 +--- input/drivers/dinput.c | 44 ++-- input/drivers/dos_input.c | 63 +---- input/drivers/gx_input.c | 96 +++---- input/drivers/linuxraw_input.c | 51 ++-- input/drivers/ps2_input.c | 55 ++-- input/drivers/ps3_input.c | 72 ++---- input/drivers/ps4_input.c | 59 ++--- input/drivers/psl1ght_input.c | 57 ++--- input/drivers/psp_input.c | 88 +++---- input/drivers/qnx_input.c | 23 +- input/drivers/rwebinput_input.c | 60 ++--- input/drivers/sdl_input.c | 51 ++-- input/drivers/switch_input.c | 72 ++---- input/drivers/udev_input.c | 76 +++--- input/drivers/uwp_input.c | 49 ++-- input/drivers/wayland_input.c | 42 ++-- input/drivers/wiiu_input.c | 64 ++--- input/drivers/winraw_input.c | 78 +++--- input/drivers/x11_input.c | 64 ++--- input/drivers/xdk_xinput_input.c | 56 ++--- input/drivers/xenon360_input.c | 33 +-- input/input_driver.h | 9 +- retroarch.c | 317 +++++++++++++++++++----- retroarch.h | 7 + 61 files changed, 800 insertions(+), 1063 deletions(-) diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c index 8b0b292852..8df5ac2cfc 100644 --- a/gfx/common/d3d_common.c +++ b/gfx/common/d3d_common.c @@ -140,18 +140,18 @@ void d3d_input_driver(const char* input_name, const char* joypad_name, * supports joypad only (uwp driver was added later) */ if (string_is_equal(input_name, "xinput")) { - void *xinput = input_xinput.init(joypad_name); + void *xinput = input_driver_init_wrap(&input_xinput, joypad_name); *input = xinput ? (input_driver_t*)&input_xinput : NULL; *input_data = xinput; } else { - void *uwp = input_uwp.init(joypad_name); + void *uwp = input_driver_init_wrap(&input_uwp, joypad_name); *input = uwp ? (input_driver_t*)&input_uwp : NULL; *input_data = uwp; } #elif defined(_XBOX) - void *xinput = input_xinput.init(joypad_name); + void *xinput = input_driver_init_wrap(&input_xinput, joypad_name); *input = xinput ? (input_driver_t*)&input_xinput : NULL; *input_data = xinput; #else @@ -160,7 +160,7 @@ void d3d_input_driver(const char* input_name, const char* joypad_name, /* winraw only available since XP */ if (string_is_equal(input_name, "raw")) { - *input_data = input_winraw.init(joypad_name); + *input_data = input_driver_init_wrap(&input_winraw, joypad_name); if (*input_data) { *input = &input_winraw; @@ -171,7 +171,7 @@ void d3d_input_driver(const char* input_name, const char* joypad_name, #endif #ifdef HAVE_DINPUT - *input_data = input_dinput.init(joypad_name); + *input_data = input_driver_init_wrap(&input_dinput, joypad_name); *input = *input_data ? &input_dinput : NULL; #endif #endif diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 4b7584b615..10f909183b 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -482,7 +482,7 @@ static void* ctr_init(const video_info_t* video, if (input && input_data) { - ctrinput = input_ctr.init(settings->arrays.input_joypad_driver); + ctrinput = input_driver_init_wrap(&input_ctr, settings->arrays.input_joypad_driver); *input = ctrinput ? &input_ctr : NULL; *input_data = ctrinput; } diff --git a/gfx/drivers/gcm_gfx.c b/gfx/drivers/gcm_gfx.c index 9ad27cd07a..b1556bc639 100644 --- a/gfx/drivers/gcm_gfx.c +++ b/gfx/drivers/gcm_gfx.c @@ -318,7 +318,7 @@ static void* gcm_init(const video_info_t* video, if (input && input_data) { - void *ps3input = input_ps3.init(ps3_joypad.ident); + void *ps3input = input_driver_init_wrap(&input_ps3, ps3_joypad.ident); *input = ps3input ? &input_ps3 : NULL; *input_data = ps3input; } diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c index 8106b2b205..b2ecd17faf 100644 --- a/gfx/drivers/gdi_gfx.c +++ b/gfx/drivers/gdi_gfx.c @@ -148,7 +148,7 @@ static void gfx_ctx_gdi_input_driver( /* winraw only available since XP */ if (string_is_equal(settings->arrays.input_driver, "raw")) { - *input_data = input_winraw.init(settings->arrays.input_driver); + *input_data = input_driver_init_wrap(&input_winraw, settings->arrays.input_driver); if (*input_data) { *input = &input_winraw; @@ -160,7 +160,7 @@ static void gfx_ctx_gdi_input_driver( #endif #ifdef HAVE_DINPUT - dinput_gdi = input_dinput.init(settings->arrays.input_driver); + dinput_gdi = input_driver_init_wrap(&input_dinput, settings->arrays.input_driver); *input = dinput_gdi ? &input_dinput : NULL; #else dinput_gdi = NULL; diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c index 991f403598..2457ab95df 100644 --- a/gfx/drivers/gx2_gfx.c +++ b/gfx/drivers/gx2_gfx.c @@ -204,7 +204,7 @@ static void *wiiu_gfx_init(const video_info_t *video, if (input && input_data) { - wiiuinput = input_wiiu.init(input_joypad_driver); + wiiuinput = input_driver_init_wrap(&input_wiiu, input_joypad_driver); *input = wiiuinput ? &input_wiiu : NULL; *input_data = wiiuinput; } diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 51f3946d6c..1b9240889f 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -793,7 +793,7 @@ static void *gx_init(const video_info_t *video, if (!gx) return NULL; - gxinput = input_gx.init(input_joypad_driver); + gxinput = input_driver_init_wrap(&input_gx, input_joypad_driver); *input = gxinput ? &input_gx : NULL; *input_data = gxinput; diff --git a/gfx/drivers/network_gfx.c b/gfx/drivers/network_gfx.c index 73b10ffd26..da51fe7848 100644 --- a/gfx/drivers/network_gfx.c +++ b/gfx/drivers/network_gfx.c @@ -69,7 +69,7 @@ static void gfx_ctx_network_input_driver( input_driver_t **input, void **input_data) { #ifdef HAVE_UDEV - *input_data = input_udev.init(joypad_driver); + *input_data = input_driver_init_wrap(&input_udev, joypad_driver); if (*input_data) { diff --git a/gfx/drivers/oga_gfx.c b/gfx/drivers/oga_gfx.c index 8b2c98ff59..2e69f19c56 100644 --- a/gfx/drivers/oga_gfx.c +++ b/gfx/drivers/oga_gfx.c @@ -119,7 +119,7 @@ static void *oga_gfx_init(const video_info_t *video, if (input && input_data) { - void* udev = input_udev.init(settings->arrays.input_joypad_driver); + void* udev = input_driver_init_wrap(&input_udev, settings->arrays.input_joypad_driver); if (udev) { *input = &input_udev; diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 740a91c0ae..af886ad172 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -251,7 +251,7 @@ static void *ps2_gfx_init(const video_info_t *video, if (input && input_data) { settings_t *settings = config_get_ptr(); - ps2input = input_ps2.init( + ps2input = input_driver_init_wrap(&input_ps2, settings->arrays.input_joypad_driver); *input = ps2input ? &input_ps2 : NULL; *input_data = ps2input; diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index fa7c848ea1..f4d9e8fc0b 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -534,7 +534,7 @@ static void *psp_init(const video_info_t *video, if (input && input_data) { settings_t *settings = config_get_ptr(); - pspinput = input_psp.init( + pspinput = input_driver_init_wrap(&input_psp, settings->arrays.input_joypad_driver); *input = pspinput ? &input_psp : NULL; *input_data = pspinput; diff --git a/gfx/drivers/sdl_dingux_gfx.c b/gfx/drivers/sdl_dingux_gfx.c index 3f427d367b..aa4fe6d874 100644 --- a/gfx/drivers/sdl_dingux_gfx.c +++ b/gfx/drivers/sdl_dingux_gfx.c @@ -108,7 +108,8 @@ static void *sdl_dingux_gfx_init(const video_info_t *video, if (input && input_data) { - void *sdl_input = input_sdl.init(settings->arrays.input_joypad_driver); + void *sdl_input = input_driver_init_wrap(&input_sdl, + settings->arrays.input_joypad_driver); if (sdl_input) { diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 6ecc9abdf0..9419853653 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -300,7 +300,8 @@ static void *sdl_gfx_init(const video_info_t *video, if (input && input_data) { - void *sdl_input = input_sdl.init(settings->arrays.input_joypad_driver); + void *sdl_input = input_driver_init_wrap(&input_sdl, + settings->arrays.input_joypad_driver); if (sdl_input) { diff --git a/gfx/drivers/sixel_gfx.c b/gfx/drivers/sixel_gfx.c index 831ce2817f..8274a4aee8 100644 --- a/gfx/drivers/sixel_gfx.c +++ b/gfx/drivers/sixel_gfx.c @@ -221,7 +221,8 @@ static void *sixel_gfx_init(const video_info_t *video, } #ifdef HAVE_UDEV - *input_data = input_udev.init(settings->arrays.input_driver); + *input_data = input_driver_init_wrap(&input_udev, + settings->arrays.input_driver); if (*input_data) *input = &input_udev; diff --git a/gfx/drivers/switch_nx_gfx.c b/gfx/drivers/switch_nx_gfx.c index 8ed12184c9..c903e3a840 100644 --- a/gfx/drivers/switch_nx_gfx.c +++ b/gfx/drivers/switch_nx_gfx.c @@ -210,9 +210,10 @@ static void *switch_init(const video_info_t *video, if (input && input_data) { settings_t *settings = config_get_ptr(); - switchinput = input_switch.init(settings->arrays.input_joypad_driver); - *input = switchinput ? &input_switch : NULL; - *input_data = switchinput; + switchinput = input_driver_init_wrap(&input_switch, + settings->arrays.input_joypad_driver); + *input = switchinput ? &input_switch : NULL; + *input_data = switchinput; } font_driver_init_osd(sw, diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index c510a1f41d..57867ecadb 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -101,7 +101,8 @@ static void *vita2d_gfx_init(const video_info_t *video, if (input && input_data) { settings_t *settings = config_get_ptr(); - void *pspinput = input_psp.init(settings->arrays.input_joypad_driver); + void *pspinput = input_driver_init_wrap(&input_psp, + settings->arrays.input_joypad_driver); *input = pspinput ? &input_psp : NULL; *input_data = pspinput; } diff --git a/gfx/drivers/xshm_gfx.c b/gfx/drivers/xshm_gfx.c index 46cc018d3e..f874d432fb 100644 --- a/gfx/drivers/xshm_gfx.c +++ b/gfx/drivers/xshm_gfx.c @@ -114,9 +114,9 @@ static void *xshm_gfx_init(const video_info_t *video, if (input && input_data) { - void *xinput = NULL; settings_t *settings = config_get_ptr(); - xinput = input_x.init(settings->arrays.input_joypad_driver); + void *xinput = input_driver_init_wrap(&input_x, + settings->arrays.input_joypad_driver); if (xinput) { *input = &input_x; diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index 820901f682..f7405e5bb0 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -858,7 +858,8 @@ static void *xv_init(const video_info_t *video, if (input && input_data) { - xinput = input_x.init(settings->arrays.input_joypad_driver); + xinput = input_driver_init_wrap(&input_x, + settings->arrays.input_joypad_driver); if (xinput) { *input = &input_x; diff --git a/gfx/drivers_context/android_ctx.c b/gfx/drivers_context/android_ctx.c index c07b52f195..10bc012656 100644 --- a/gfx/drivers_context/android_ctx.c +++ b/gfx/drivers_context/android_ctx.c @@ -220,7 +220,7 @@ static void android_gfx_ctx_input_driver(void *data, const char *joypad_name, input_driver_t **input, void **input_data) { - void *androidinput = input_android.init(joypad_name); + void *androidinput = input_driver_init_wrap(&input_android, joypad_name); *input = androidinput ? &input_android : NULL; *input_data = androidinput; diff --git a/gfx/drivers_context/android_vk_ctx.c b/gfx/drivers_context/android_vk_ctx.c index 53ed60078d..695c800e78 100644 --- a/gfx/drivers_context/android_vk_ctx.c +++ b/gfx/drivers_context/android_vk_ctx.c @@ -177,7 +177,7 @@ static void android_gfx_ctx_vk_input_driver(void *data, const char *joypad_name, input_driver_t **input, void **input_data) { - void *androidinput = input_android.init(joypad_name); + void *androidinput = input_driver_init_wrap(&input_android, joypad_name); *input = androidinput ? &input_android : NULL; *input_data = androidinput; diff --git a/gfx/drivers_context/drm_ctx.c b/gfx/drivers_context/drm_ctx.c index ad65db7b44..48c6038bbf 100644 --- a/gfx/drivers_context/drm_ctx.c +++ b/gfx/drivers_context/drm_ctx.c @@ -743,7 +743,7 @@ static void gfx_ctx_drm_input_driver(void *data, #ifdef HAVE_UDEV { /* Try to set it to udev instead */ - void *udev = input_udev.init(joypad_name); + void *udev = input_driver_init_wrap(&input_udev, joypad_name); if (udev) { *input = &input_udev; @@ -755,7 +755,7 @@ static void gfx_ctx_drm_input_driver(void *data, #if defined(__linux__) && !defined(ANDROID) { /* Try to set it to linuxraw instead */ - void *linuxraw = input_linuxraw.init(joypad_name); + void *linuxraw = input_driver_init_wrap(&input_linuxraw, joypad_name); if (linuxraw) { *input = &input_linuxraw; diff --git a/gfx/drivers_context/drm_go2_ctx.c b/gfx/drivers_context/drm_go2_ctx.c index 36d0c78644..7daa4c9cbb 100644 --- a/gfx/drivers_context/drm_go2_ctx.c +++ b/gfx/drivers_context/drm_go2_ctx.c @@ -97,7 +97,7 @@ static void gfx_ctx_go2_drm_input_driver(void *data, { #ifdef HAVE_UDEV /* Try to set it to udev instead */ - void *udev = input_udev.init(joypad_name); + void *udev = input_driver_init_wrap(&input_udev, joypad_name); if (udev) { *input = &input_udev; diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index 2012e17ad6..b78d5e296d 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -271,7 +271,7 @@ static void gfx_ctx_emscripten_input_driver(void *data, const char *name, input_driver_t **input, void **input_data) { - void *rwebinput = input_rwebinput.init(name); + void *rwebinput = input_driver_init_wrap(&input_rwebinput, name); *input = rwebinput ? &input_rwebinput : NULL; *input_data = rwebinput; diff --git a/gfx/drivers_context/khr_display_ctx.c b/gfx/drivers_context/khr_display_ctx.c index 1a31cb3296..ed4d11fb77 100644 --- a/gfx/drivers_context/khr_display_ctx.c +++ b/gfx/drivers_context/khr_display_ctx.c @@ -169,7 +169,7 @@ static void gfx_ctx_khr_display_input_driver(void *data, #ifdef HAVE_UDEV { /* Try to set it to udev instead */ - void *udev = input_udev.init(joypad_name); + void *udev = input_driver_init_wrap(&input_udev, joypad_name); if (udev) { *input = &input_udev; @@ -181,7 +181,7 @@ static void gfx_ctx_khr_display_input_driver(void *data, #if defined(__linux__) && !defined(ANDROID) { /* Try to set it to linuxraw instead */ - void *linuxraw = input_linuxraw.init(joypad_name); + void *linuxraw = input_driver_init_wrap(&input_linuxraw, joypad_name); if (linuxraw) { *input = &input_linuxraw; diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index e870e5307f..916169b0d6 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -288,7 +288,7 @@ static void gfx_ctx_ps3_input_driver(void *data, const char *joypad_name, input_driver_t **input, void **input_data) { - void *ps3input = input_ps3.init(joypad_name); + void *ps3input = input_driver_init_wrap(&input_ps3, joypad_name); *input = ps3input ? &input_ps3 : NULL; *input_data = ps3input; diff --git a/gfx/drivers_context/qnx_ctx.c b/gfx/drivers_context/qnx_ctx.c index 7bf6b5c1be..a418fba02a 100644 --- a/gfx/drivers_context/qnx_ctx.c +++ b/gfx/drivers_context/qnx_ctx.c @@ -306,7 +306,7 @@ static void gfx_ctx_qnx_input_driver(void *data, const char *joypad_name, input_driver_t **input, void **input_data) { - void *qnxinput = input_qnx.init(joypad_name); + void *qnxinput = input_driver_init_wrap(&input_qnx, joypad_name); *input = qnxinput ? &input_qnx : NULL; *input_data = qnxinput; diff --git a/gfx/drivers_context/uwp_egl_ctx.c b/gfx/drivers_context/uwp_egl_ctx.c index 6bd594d6f3..b03e0a5dea 100644 --- a/gfx/drivers_context/uwp_egl_ctx.c +++ b/gfx/drivers_context/uwp_egl_ctx.c @@ -213,13 +213,13 @@ static void gfx_ctx_uwp_input_driver(void *data, * supports joypad only (uwp driver was added later) */ if (string_is_equal(settings->arrays.input_driver, "xinput")) { - void* xinput = input_xinput.init(joypad_name); + void* xinput = input_driver_init_wrap(&input_xinput, joypad_name); *input = xinput ? (input_driver_t*)&input_xinput : NULL; *input_data = xinput; } else { - void* uwp = input_uwp.init(joypad_name); + void* uwp = input_driver_init_wrap(&input_uwp, joypad_name); *input = uwp ? (input_driver_t*)&input_uwp : NULL; *input_data = uwp; } diff --git a/gfx/drivers_context/w_vk_ctx.c b/gfx/drivers_context/w_vk_ctx.c index 6dec4a1e1c..670f86b2c0 100644 --- a/gfx/drivers_context/w_vk_ctx.c +++ b/gfx/drivers_context/w_vk_ctx.c @@ -271,10 +271,10 @@ static void gfx_ctx_w_vk_input_driver(void *data, /* winraw only available since XP */ if (string_is_equal(input_driver, "raw")) { - *input_data = input_winraw.init(joypad_name); + *input_data = input_driver_init_wrap(&input_winraw, joypad_name); if (*input_data) { - *input = &input_winraw; + *input = &input_winraw; dinput_vk_wgl = NULL; return; } @@ -283,7 +283,7 @@ static void gfx_ctx_w_vk_input_driver(void *data, #endif #ifdef HAVE_DINPUT - dinput_vk_wgl = input_dinput.init(joypad_name); + dinput_vk_wgl = input_driver_init_wrap(&input_dinput, joypad_name); *input = dinput_vk_wgl ? &input_dinput : NULL; *input_data = dinput_vk_wgl; #endif diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 2b66963820..bef4e5dde2 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -743,6 +743,7 @@ static void gfx_ctx_wl_input_driver(void *data, { *input = &input_wayland; *input_data = &wl->input; + input_driver_init_joypads(); } } diff --git a/gfx/drivers_context/wayland_vk_ctx.c b/gfx/drivers_context/wayland_vk_ctx.c index 6a9b21104b..e852f8fcab 100644 --- a/gfx/drivers_context/wayland_vk_ctx.c +++ b/gfx/drivers_context/wayland_vk_ctx.c @@ -556,6 +556,7 @@ static void gfx_ctx_wl_input_driver(void *data, { *input = &input_wayland; *input_data = &wl->input; + input_driver_init_joypads(); } } diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 930b81ab9f..0d077503dc 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -692,7 +692,7 @@ static void gfx_ctx_wgl_input_driver(void *data, /* winraw only available since XP */ if (string_is_equal(input_driver, "raw")) { - *input_data = input_winraw.init(joypad_name); + *input_data = input_driver_init_wrap(&input_winraw, joypad_name); if (*input_data) { *input = &input_winraw; @@ -704,7 +704,7 @@ static void gfx_ctx_wgl_input_driver(void *data, #endif #ifdef HAVE_DINPUT - dinput_wgl = input_dinput.init(joypad_name); + dinput_wgl = input_driver_init_wrap(&input_dinput, joypad_name); *input = dinput_wgl ? &input_dinput : NULL; *input_data = dinput_wgl; #endif diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index cf3357ed60..155956994d 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -927,7 +927,7 @@ static void gfx_ctx_x_input_driver(void *data, if (string_is_equal(input_driver, "udev")) { - *input_data = input_udev.init(joypad_name); + *input_data = input_driver_init_wrap(&input_udev, joypad_name); if (*input_data) { *input = &input_udev; @@ -936,7 +936,7 @@ static void gfx_ctx_x_input_driver(void *data, } #endif - x_input = input_x.init(joypad_name); + x_input = input_driver_init_wrap(&input_x, joypad_name); *input = x_input ? &input_x : NULL; *input_data = x_input; } diff --git a/gfx/drivers_context/x_vk_ctx.c b/gfx/drivers_context/x_vk_ctx.c index 79bbe70d3d..1f4882f115 100644 --- a/gfx/drivers_context/x_vk_ctx.c +++ b/gfx/drivers_context/x_vk_ctx.c @@ -464,7 +464,7 @@ static void gfx_ctx_x_vk_input_driver(void *data, if (string_is_equal(input_driver, "udev")) { - *input_data = input_udev.init(joypad_name); + *input_data = input_driver_init_wrap(&input_udev.init, joypad_name); if (*input_data) { *input = &input_udev; @@ -473,7 +473,7 @@ static void gfx_ctx_x_vk_input_driver(void *data, } #endif - x_input = input_x.init(joypad_name); + x_input = input_driver_init_wrap(&input_x, joypad_name); *input = x_input ? &input_x : NULL; *input_data = x_input; } diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index 8870acb0d4..809deb81cc 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -456,7 +456,7 @@ static void gfx_ctx_xegl_input_driver(void *data, const char *joypad_name, input_driver_t **input, void **input_data) { - void *xinput = input_x.init(joypad_name); + void *xinput = input_driver_init_wrap(&input_x, joypad_name); *input = xinput ? &input_x : NULL; *input_data = xinput; diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index e00231ae65..fc30a8612c 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -147,7 +147,6 @@ typedef struct state_device typedef struct android_input { int64_t quick_tap_time; - const input_device_driver_t *joypad; state_device_t pad_states[MAX_USERS]; /* int alignment */ int mouse_x_delta, mouse_y_delta; int mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd; @@ -543,8 +542,6 @@ static void *android_input_init(const char *joypad_driver) android_app->input_alive = true; - android->joypad = input_joypad_init_driver(joypad_driver, android); - return android; } @@ -1313,16 +1310,18 @@ static void android_input_poll_memcpy(android_input_t *android) /* Handle all events. If our activity is in pause state, * block until we're unpaused. */ -static void android_input_poll(void *data) +static void android_input_poll(void *data, const void *joypad_data) { int ident; struct android_app *android_app = (struct android_app*)g_android; android_input_t *android = (android_input_t*)data; + const input_device_driver_t + *joypad = (const input_device_driver_t*)joypad_data; settings_t *settings = config_get_ptr(); while ((ident = ALooper_pollAll((input_config_binds[0][RARCH_PAUSE_TOGGLE].valid - && input_key_pressed(android->joypad, RARCH_PAUSE_TOGGLE, + && input_key_pressed(joypad, RARCH_PAUSE_TOGGLE, android_keyboard_port_input_pressed(input_config_binds[0], RARCH_PAUSE_TOGGLE))) ? -1 : settings->uints.input_block_timeout, @@ -1389,7 +1388,10 @@ bool android_run_events(void *data) return true; } -static int16_t android_input_state(void *data, +static int16_t android_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -1402,7 +1404,7 @@ static int16_t android_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = android->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -1420,7 +1422,7 @@ static int16_t android_input_state(void *data, { if ( button_is_pressed( - android->joypad, joypad_info, binds[port], + joypad, joypad_info, binds[port], port, id) || android_keyboard_port_input_pressed(binds[port], id) ) @@ -1494,10 +1496,6 @@ static void android_input_free_input(void *data) ASensorManager_destroyEventQueue(android_app->sensorManager, android_app->sensorEventQueue); - if (android->joypad) - android->joypad->destroy(); - android->joypad = NULL; - android_app->input_alive = false; #ifdef HAVE_DYNAMIC @@ -1593,26 +1591,20 @@ static float android_input_get_sensor_input(void *data, return 0; } -static const input_device_driver_t *android_input_get_joypad_driver(void *data) -{ - android_input_t *android = (android_input_t*)data; - if (!android) - return NULL; - return android->joypad; -} - static void android_input_grab_mouse(void *data, bool state) { (void)data; (void)state; } -static bool android_input_set_rumble(void *data, unsigned port, +static bool android_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - android_input_t *android = (android_input_t*)data; - if (android) - return input_joypad_set_rumble(android->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } @@ -1629,7 +1621,5 @@ input_driver_t input_android = { android_input_grab_mouse, NULL, android_input_set_rumble, - android_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index f84a7913e4..bb748cee44 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -46,12 +46,6 @@ static void *cocoa_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid); - apple->joypad = input_joypad_init_driver(joypad_driver, apple); - -#ifdef HAVE_MFI - apple->sec_joypad = input_joypad_init_driver("mfi", apple); -#endif - return apple; } @@ -90,13 +84,6 @@ static void cocoa_input_poll(void *data) &apple->touches[i].full_x, &apple->touches[i].full_y); } - - if (apple->joypad) - apple->joypad->poll(); -#ifdef HAVE_MFI - if (apple->sec_joypad) - apple->sec_joypad->poll(); -#endif } static int16_t cocoa_mouse_state(cocoa_input_data_t *apple, @@ -195,7 +182,10 @@ static int16_t cocoa_pointer_state(cocoa_input_data_t *apple, return 0; } -static int16_t cocoa_input_state(void *data, +static int16_t cocoa_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -210,10 +200,10 @@ static int16_t cocoa_input_state(void *data, unsigned i; /* Do a bitwise OR to combine both input * states together */ - int16_t ret = apple->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port) #ifdef HAVE_MFI - | apple->sec_joypad->state( + | sec_joypad->state( joypad_info, binds[port], port) #endif ; @@ -235,12 +225,12 @@ static int16_t cocoa_input_state(void *data, if (binds[port][id].valid) { if (button_is_pressed( - apple->joypad, + joypad, joypad_info, binds[port], port, id)) return 1; #ifdef HAVE_MFI else if (button_is_pressed( - apple->sec_joypad, + sec_joypad, joypad_info, binds[port], port, id)) return 1; #endif @@ -274,31 +264,23 @@ static void cocoa_input_free(void *data) if (!apple || !data) return; - if (apple->joypad) - apple->joypad->destroy(); - -#ifdef HAVE_MFI - if (apple->sec_joypad) - apple->sec_joypad->destroy(); -#endif - for (i = 0; i < MAX_KEYS; i++) apple_key_state[i] = 0; free(apple); } -static bool cocoa_input_set_rumble(void *data, - unsigned port, enum retro_rumble_effect effect, uint16_t strength) +static bool cocoa_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - cocoa_input_data_t *apple = (cocoa_input_data_t*)data; - - if (apple && apple->joypad) - return input_joypad_set_rumble(apple->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); #ifdef HAVE_MFI - if (apple && apple->sec_joypad) - return input_joypad_set_rumble(apple->sec_joypad, + if (sec_joypad) + return input_joypad_set_rumble(sec_joypad, port, effect, strength); #endif return false; @@ -316,33 +298,6 @@ static uint64_t cocoa_input_get_capabilities(void *data) (1 << RETRO_DEVICE_ANALOG); } -static void cocoa_input_grab_mouse(void *data, bool state) -{ - /* Dummy for now. Might be useful in the future. */ - (void)data; - (void)state; -} - -static const input_device_driver_t *cocoa_input_get_sec_joypad_driver(void *data) -{ -#ifdef HAVE_MFI - cocoa_input_data_t *apple = (cocoa_input_data_t*)data; - - if (apple && apple->sec_joypad) - return apple->sec_joypad; -#endif - return NULL; -} - -static const input_device_driver_t *cocoa_input_get_joypad_driver(void *data) -{ - cocoa_input_data_t *apple = (cocoa_input_data_t*)data; - - if (apple && apple->joypad) - return apple->joypad; - return NULL; -} - input_driver_t input_cocoa = { cocoa_input_init, cocoa_input_poll, @@ -352,10 +307,8 @@ input_driver_t input_cocoa = { NULL, cocoa_input_get_capabilities, "cocoa", - cocoa_input_grab_mouse, + NULL, /* grab_mouse */ NULL, cocoa_input_set_rumble, - cocoa_input_get_joypad_driver, - cocoa_input_get_sec_joypad_driver, false }; diff --git a/input/drivers/cocoa_input.h b/input/drivers/cocoa_input.h index 013973752c..bc1bcd4e2e 100644 --- a/input/drivers/cocoa_input.h +++ b/input/drivers/cocoa_input.h @@ -52,11 +52,6 @@ typedef struct int16_t mouse_wd; int16_t mouse_wl; int16_t mouse_wr; - -#ifdef HAVE_MFI - const input_device_driver_t *sec_joypad; -#endif - const input_device_driver_t *joypad; } cocoa_input_data_t; #endif diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index 92c5c10733..a0f1cef12b 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -35,15 +35,10 @@ typedef struct ctr_input const input_device_driver_t *joypad; } ctr_input_t; -static void ctr_input_poll(void *data) -{ - ctr_input_t *ctr = (ctr_input_t*)data; - - if (ctr->joypad) - ctr->joypad->poll(); -} - -static int16_t ctr_input_state(void *data, +static int16_t ctr_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -58,13 +53,13 @@ static int16_t ctr_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return ctr->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (id < RARCH_BIND_LIST_END) if (binds[port][id].valid) if (button_is_pressed( - ctr->joypad, joypad_info, binds[port], port, id)) + joypad, joypad_info, binds[port], port, id)) return 1; break; case RETRO_DEVICE_ANALOG: @@ -78,9 +73,6 @@ static void ctr_input_free_input(void *data) { ctr_input_t *ctr = (ctr_input_t*)data; - if (ctr && ctr->joypad) - ctr->joypad->destroy(); - free(data); } @@ -90,8 +82,6 @@ static void* ctr_input_init(const char *joypad_driver) if (!ctr) return NULL; - ctr->joypad = input_joypad_init_driver(joypad_driver, ctr); - return ctr; } @@ -102,36 +92,17 @@ static uint64_t ctr_input_get_capabilities(void *data) return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } -static const input_device_driver_t *ctr_input_get_joypad_driver(void *data) -{ - ctr_input_t *ctr = (ctr_input_t*)data; - if (ctr) - return ctr->joypad; - return NULL; -} - -static void ctr_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool ctr_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - input_driver_t input_ctr = { ctr_input_init, - ctr_input_poll, + NULL, /* poll */ ctr_input_state, ctr_input_free_input, NULL, NULL, ctr_input_get_capabilities, "ctr", - ctr_input_grab_mouse, - NULL, - ctr_input_set_rumble, - ctr_input_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index ef2d652280..383beb8f2f 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -187,8 +187,6 @@ static void *dinput_init(const char *joypad_driver) win32_set_input_userdata(di); #endif - di->joypad = input_joypad_init_driver(joypad_driver, di); - return di; } @@ -280,9 +278,6 @@ static void dinput_poll(void *data) di->mouse_x = point.x; di->mouse_y = point.y; } - - if (di->joypad) - di->joypad->poll(); } static bool dinput_mouse_button_pressed( @@ -565,7 +560,10 @@ static int16_t dinput_pointer_state(struct dinput_input *di, return 0; } -static int16_t dinput_input_state(void *data, +static int16_t dinput_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -585,7 +583,7 @@ static int16_t dinput_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = di->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); if (settings->uints.input_mouse_index[port] == 0) @@ -624,7 +622,7 @@ static int16_t dinput_input_state(void *data, if (binds[port][id].valid) { if (button_is_pressed( - di->joypad, + joypad, joypad_info, binds[port], port, id)) return 1; else if (binds[port][id].key < RETROK_LAST @@ -737,7 +735,7 @@ static int16_t dinput_input_state(void *data, } if (binds[port][new_id].valid) { - if (button_is_pressed(di->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -923,9 +921,7 @@ bool dinput_handle_message(void *data, /* TODO/FIXME: Don't destroy everything, let's just * handle new devices gracefully */ - if (di->joypad) - di->joypad->destroy(); - di->joypad = input_joypad_init_driver(di->joypad_driver_name, di); + joypad_driver_reinit(di, di->joypad_driver_name); } } #endif @@ -957,8 +953,6 @@ static void dinput_free(void *data) /* Prevent a joypad driver to kill our context prematurely. */ g_dinput_ctx = NULL; - if (di->joypad) - di->joypad->destroy(); #ifndef _XBOX win32_unset_input_userdata(); @@ -977,6 +971,7 @@ static void dinput_free(void *data) if (di->joypad_driver_name) free(di->joypad_driver_name); + di->joypad_driver_name = NULL; free(di); @@ -996,23 +991,17 @@ static void dinput_grab_mouse(void *data, bool state) IDirectInputDevice8_Acquire(di->mouse); } -static bool dinput_set_rumble(void *data, unsigned port, +static bool dinput_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - struct dinput_input *di = (struct dinput_input*)data; - if (di) - return input_joypad_set_rumble(di->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *dinput_get_joypad_driver(void *data) -{ - struct dinput_input *di = (struct dinput_input*)data; - if (!di) - return NULL; - return di->joypad; -} - static uint64_t dinput_get_capabilities(void *data) { uint64_t caps = 0; @@ -1036,11 +1025,8 @@ input_driver_t input_dinput = { NULL, dinput_get_capabilities, "dinput", - dinput_grab_mouse, NULL, dinput_set_rumble, - dinput_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 5fd2dc4558..63cc02dfd0 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -33,7 +33,7 @@ typedef struct dos_input { - const input_device_driver_t *joypad; + void *empty; } dos_input_t; /* First ports are used to keeping track of gamepad states. Last port is used for keyboard state */ @@ -62,15 +62,10 @@ static void dos_keyboard_free(void) dos_key_state[i][j] = 0; } -static void dos_input_poll(void *data) -{ - dos_input_t *dos = (dos_input_t*)data; - - if (dos->joypad) - dos->joypad->poll(); -} - -static int16_t dos_input_state(void *data, +static int16_t dos_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -87,7 +82,7 @@ static int16_t dos_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = dos->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -108,7 +103,7 @@ static int16_t dos_input_state(void *data, { if ( button_is_pressed( - dos->joypad, joypad_info, binds[port], + joypad, joypad_info, binds[port], port, id) || dos_keyboard_port_input_pressed(binds[port], id) ) @@ -129,9 +124,6 @@ static void dos_input_free_input(void *data) { dos_input_t *dos = (dos_input_t*)data; - if (dos && dos->joypad) - dos->joypad->destroy(); - dos_keyboard_free(); if (data) @@ -147,58 +139,25 @@ static void* dos_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_dos); - dos->joypad = input_joypad_init_driver(joypad_driver, dos); - return dos; } static uint64_t dos_input_get_capabilities(void *data) { - uint64_t caps = 0; - - caps |= UINT64_C(1) << RETRO_DEVICE_JOYPAD; - - return caps; -} - -static const input_device_driver_t *dos_input_get_joypad_driver(void *data) -{ - dos_input_t *dos = (dos_input_t*)data; - if (dos) - return dos->joypad; - return NULL; -} - -static void dos_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool dos_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) -{ - (void)data; - (void)port; - (void)effect; - (void)strength; - - return false; + return UINT64_C(1) << RETRO_DEVICE_JOYPAD; } input_driver_t input_dos = { dos_input_init, - dos_input_poll, + NULL, /* poll */ dos_input_state, dos_input_free_input, NULL, NULL, dos_input_get_capabilities, "dos", - dos_input_grab_mouse, - NULL, - dos_input_set_rumble, - dos_input_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 16b731fa8f..8e2eeb22b5 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -47,7 +47,6 @@ typedef struct typedef struct gx_input { - const input_device_driver_t *joypad; #ifdef HW_RVL int mouse_max; gx_input_mouse_t *mouse; @@ -55,7 +54,8 @@ typedef struct gx_input } gx_input_t; #ifdef HW_RVL -static int16_t gx_lightgun_state(gx_input_t *gx, unsigned id, uint16_t joy_idx) +static int16_t gx_lightgun_state(gx_input_t *gx, + unsigned id, uint16_t joy_idx) { struct video_viewport vp = {0}; video_driver_get_viewport_info(&vp); @@ -134,7 +134,10 @@ static int16_t gx_mouse_state(gx_input_t *gx, unsigned id, uint16_t joy_idx) } #endif -static int16_t gx_input_state(void *data, +static int16_t gx_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -149,12 +152,12 @@ static int16_t gx_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return gx->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) if ( - button_is_pressed(gx->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -179,8 +182,6 @@ static void gx_input_free_input(void *data) if (!gx) return; - if (gx->joypad) - gx->joypad->destroy(); #ifdef HW_RVL if (gx->mouse) free(gx->mouse); @@ -188,27 +189,6 @@ static void gx_input_free_input(void *data) free(gx); } -#ifdef HW_RVL -static inline int gx_count_mouse(gx_input_t *gx) -{ - unsigned i; - int count = 0; - - if (gx) - { - for (i = 0; i < DEFAULT_MAX_PADS; i++) - { - if (gx->joypad->name(i)) - { - if (string_is_equal(gx->joypad->name(i), "Wiimote Controller")) - count++; - } - } - } - - return count; -} -#endif static void *gx_input_init(const char *joypad_driver) { @@ -223,11 +203,29 @@ static void *gx_input_init(const char *joypad_driver) gx->mouse_max, sizeof(gx_input_mouse_t)); #endif - gx->joypad = input_joypad_init_driver(joypad_driver, gx); return gx; } #ifdef HW_RVL +static inline int gx_count_mouse(gx_input_t *gx) +{ + unsigned i; + int count = 0; + + if (!gx) + return 0; + + for (i = 0; i < DEFAULT_MAX_PADS; i++) + { + const char *joypad_name = joypad_driver_name(i); + if (!string_is_empty(joypad_name)) + if (string_is_equal(joypad_name, "Wiimote Controller")) + count++; + } + + return count; +} + static void gx_input_poll_mouse(gx_input_t *gx) { int count = gx_count_mouse(gx); @@ -266,25 +264,17 @@ static void gx_input_poll_mouse(gx_input_t *gx) } } } -#endif -static void gx_input_poll(void *data) +static void rvl_input_poll(void *data) { gx_input_t *gx = (gx_input_t*)data; - - if (gx && gx->joypad) - { - gx->joypad->poll(); -#ifdef HW_RVL - if (gx->mouse) - gx_input_poll_mouse(gx); -#endif - } + if (gx && gx->mouse) + gx_input_poll_mouse(gx); } +#endif static uint64_t gx_input_get_capabilities(void *data) { - (void)data; #ifdef HW_RVL return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | @@ -296,21 +286,13 @@ static uint64_t gx_input_get_capabilities(void *data) #endif } -static const input_device_driver_t *gx_input_get_joypad_driver(void *data) -{ - gx_input_t *gx = (gx_input_t*)data; - if (!gx) - return NULL; - return gx->joypad; -} - -static void gx_input_grab_mouse(void *data, bool state) { } -static bool gx_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - input_driver_t input_gx = { gx_input_init, - gx_input_poll, +#ifdef HW_RVL + rvl_input_poll, +#else + NULL, /* poll */ +#endif gx_input_state, gx_input_free_input, NULL, @@ -318,10 +300,8 @@ input_driver_t input_gx = { gx_input_get_capabilities, "gx", - gx_input_grab_mouse, - NULL, - gx_input_set_rumble, - gx_input_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index f155621320..3cc1b1d8f8 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -37,7 +37,6 @@ typedef struct linuxraw_input { - const input_device_driver_t *joypad; bool state[0x80]; } linuxraw_input_t; @@ -70,8 +69,6 @@ static void *linuxraw_input_init(const char *joypad_driver) linux_terminal_claim_stdin(); - linuxraw->joypad = input_joypad_init_driver(joypad_driver, linuxraw); - return linuxraw; } @@ -107,7 +104,10 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, return pressed_plus + pressed_minus; } -static int16_t linuxraw_input_state(void *data, +static int16_t linuxraw_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -120,7 +120,7 @@ static int16_t linuxraw_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = linuxraw->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -145,7 +145,7 @@ static int16_t linuxraw_input_state(void *data, { if ( button_is_pressed( - linuxraw->joypad, joypad_info, binds[port], + joypad, joypad_info, binds[port], port, id) ) return 1; @@ -174,28 +174,19 @@ static void linuxraw_input_free(void *data) if (!linuxraw) return; - if (linuxraw->joypad) - linuxraw->joypad->destroy(); - linux_terminal_restore_input(); free(data); } -static bool linuxraw_set_rumble(void *data, unsigned port, +static bool linuxraw_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; - if (!linuxraw) - return false; - return input_joypad_set_rumble(linuxraw->joypad, port, effect, strength); -} - -static const input_device_driver_t *linuxraw_get_joypad_driver(void *data) -{ - linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; - if (!linuxraw) - return NULL; - return linuxraw->joypad; + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); + return false; } static void linuxraw_input_poll(void *data) @@ -220,29 +211,17 @@ static void linuxraw_input_poll(void *data) else linuxraw->state[c] = pressed; } - - if (linuxraw->joypad) - linuxraw->joypad->poll(); } static uint64_t linuxraw_get_capabilities(void *data) { uint64_t caps = 0; - - (void)data; - caps |= (1 << RETRO_DEVICE_JOYPAD); caps |= (1 << RETRO_DEVICE_ANALOG); return caps; } -static void linuxraw_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - input_driver_t input_linuxraw = { linuxraw_input_init, linuxraw_input_poll, @@ -252,10 +231,8 @@ input_driver_t input_linuxraw = { NULL, linuxraw_get_capabilities, "linuxraw", - linuxraw_grab_mouse, + NULL, /* grab_mouse */ linux_terminal_grab_stdin, linuxraw_set_rumble, - linuxraw_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 77743e6f0b..94e74a426a 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -28,18 +28,13 @@ typedef struct ps2_input { - const input_device_driver_t *joypad; + void *empty; } ps2_input_t; -static void ps2_input_poll(void *data) -{ - ps2_input_t *ps2 = (ps2_input_t*)data; - - if (ps2 && ps2->joypad) - ps2->joypad->poll(); -} - -static int16_t ps2_input_state(void *data, +static int16_t ps2_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -51,11 +46,11 @@ static int16_t ps2_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return ps2->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) - if (button_is_pressed(ps2->joypad, joypad_info, binds[port], + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -70,9 +65,6 @@ static void ps2_input_free_input(void *data) { ps2_input_t *ps2 = (ps2_input_t*)data; - if (ps2 && ps2->joypad) - ps2->joypad->destroy(); - free(data); } @@ -82,8 +74,6 @@ static void* ps2_input_initialize(const char *joypad_driver) if (!ps2) return NULL; - ps2->joypad = input_joypad_init_driver(joypad_driver, ps2); - return ps2; } @@ -94,44 +84,29 @@ static uint64_t ps2_input_get_capabilities(void *data) return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } -static const input_device_driver_t *ps2_input_get_joypad_driver(void *data) -{ - ps2_input_t *ps2 = (ps2_input_t*)data; - if (ps2) - return ps2->joypad; - return NULL; -} - -static void ps2_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool ps2_input_set_rumble(void *data, unsigned port, +static bool ps2_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - ps2_input_t *ps2 = (ps2_input_t*)data; - - if (ps2 && ps2->joypad) - return input_joypad_set_rumble(ps2->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } input_driver_t input_ps2 = { ps2_input_initialize, - ps2_input_poll, + NULL, /* poll */ ps2_input_state, ps2_input_free_input, NULL, NULL, ps2_input_get_capabilities, "ps2", - ps2_input_grab_mouse, + NULL, /* grab_mouse */ NULL, ps2_input_set_rumble, - ps2_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 01cb40cbad..630e79291b 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -48,19 +48,17 @@ typedef struct ps3_input { #ifdef HAVE_MOUSE unsigned mice_connected; +#else + void *empty; #endif - const input_device_driver_t *joypad; } ps3_input_t; static void ps3_input_poll(void *data) { - ps3_input_t *ps3 = (ps3_input_t*)data; - - if (ps3 && ps3->joypad) - ps3->joypad->poll(); - #ifdef HAVE_MOUSE CellMouseInfo mouse_info; + ps3_input_t *ps3 = (ps3_input_t*)data; + cellMouseGetInfo(&mouse_info); ps3->mice_connected = mouse_info.now_connect; #endif @@ -93,7 +91,10 @@ static int16_t ps3_mouse_device_state(ps3_input_t *ps3, } #endif -static int16_t ps3_input_state(void *data, +static int16_t ps3_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -108,11 +109,11 @@ static int16_t ps3_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return ps3->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) - if (button_is_pressed(ps3->joypad, joypad_info, binds[port], + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; @@ -154,9 +155,6 @@ static void ps3_input_free_input(void *data) if (!ps3) return; - if (ps3->joypad) - ps3->joypad->destroy(); - #ifdef HAVE_MOUSE cellMouseEnd(); #endif @@ -173,8 +171,6 @@ static void* ps3_input_init(const char *joypad_driver) cellMouseInit(MAX_MICE); #endif - ps3->joypad = input_joypad_init_driver(joypad_driver, ps3); - return ps3; } @@ -193,7 +189,6 @@ static bool ps3_input_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned event_rate) { CellPadInfo2 pad_info; - (void)event_rate; switch (action) { @@ -201,43 +196,32 @@ static bool ps3_input_set_sensor_state(void *data, unsigned port, cellPadGetInfo2(&pad_info); if ((pad_info.device_capability[port] & CELL_PAD_CAPABILITY_SENSOR_MODE) - != CELL_PAD_CAPABILITY_SENSOR_MODE) - return false; - - cellPadSetPortSetting(port, CELL_PAD_SETTING_SENSOR_ON); - return true; + == CELL_PAD_CAPABILITY_SENSOR_MODE) + { + cellPadSetPortSetting(port, CELL_PAD_SETTING_SENSOR_ON); + return true; + } + break; case RETRO_SENSOR_ACCELEROMETER_DISABLE: cellPadSetPortSetting(port, 0); return true; - default: - return false; + break; } -} -static bool ps3_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) -{ - ps3_input_t *ps3 = (ps3_input_t*)data; - - if (ps3 && ps3->joypad) - return input_joypad_set_rumble(ps3->joypad, - port, effect, strength); return false; } -static const input_device_driver_t *ps3_input_get_joypad_driver(void *data) +static bool ps3_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, + enum retro_rumble_effect effect, uint16_t strength) { - ps3_input_t *ps3 = (ps3_input_t*)data; - if (ps3) - return ps3->joypad; - return NULL; -} - -static void ps3_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; + if (joypad) + return input_joypad_set_rumble(joypad, + port, effect, strength); + return false; } input_driver_t input_ps3 = { @@ -250,10 +234,8 @@ input_driver_t input_ps3 = { ps3_input_get_capabilities, "ps3", - ps3_input_grab_mouse, + NULL, /* grab_mouse */ NULL, ps3_input_set_rumble, - ps3_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index 608425d28d..ac58e6d783 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -34,18 +34,13 @@ typedef struct ps4_input { - const input_device_driver_t *joypad; + void *empty; } ps4_input_t; -static void ps4_input_poll(void *data) -{ - ps4_input_t *ps4 = (ps4_input_t*)data; - - if (ps4 && ps4->joypad) - ps4->joypad->poll(); -} - -static int16_t ps4_input_state(void *data, +static int16_t ps4_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -57,12 +52,12 @@ static int16_t ps4_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return ps4->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) if ( - button_is_pressed(ps4->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -75,11 +70,6 @@ static int16_t ps4_input_state(void *data, static void ps4_input_free_input(void *data) { - ps4_input_t *ps4 = (ps4_input_t*)data; - - if (ps4 && ps4->joypad) - ps4->joypad->destroy(); - free(data); } @@ -89,56 +79,37 @@ static void* ps4_input_initialize(const char *joypad_driver) if (!ps4) return NULL; - ps4->joypad = input_joypad_init_driver(joypad_driver, ps4); - return ps4; } static uint64_t ps4_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } -static const input_device_driver_t *ps4_input_get_joypad_driver(void *data) -{ - ps4_input_t *ps4 = (ps4_input_t*)data; - if (ps4) - return ps4->joypad; - return NULL; -} - -static void ps4_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool ps4_input_set_rumble(void *data, unsigned port, +static bool ps4_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - ps4_input_t *ps4 = (ps4_input_t*)data; - - if (ps4 && ps4->joypad) - return input_joypad_set_rumble(ps4->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } input_driver_t input_ps4 = { ps4_input_initialize, - ps4_input_poll, + NULL, /* poll */ ps4_input_state, ps4_input_free_input, NULL, NULL, ps4_input_get_capabilities, "ps4", - ps4_input_grab_mouse, + NULL, /* grab_mouse */ NULL, ps4_input_set_rumble, - ps4_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index b6bb796fdf..6b89d9e981 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -51,7 +51,6 @@ typedef struct typedef struct ps3_input { - const input_device_driver_t *joypad; int connected[MAX_KB_PORT_NUM]; #ifdef HAVE_MOUSE unsigned mice_connected; @@ -89,10 +88,8 @@ static void ps3_input_poll(void *data) ps3_input_t *ps3 = (ps3_input_t*)data; KbData last_kbdata[MAX_KB_PORT_NUM]; - if (ps3 && ps3->joypad) - ps3->joypad->poll(); - ioKbGetInfo(&ps3->kbinfo); + for (i = 0; i < MAX_KB_PORT_NUM; i++) { if (ps3->kbinfo.status[i] && !ps3->connected[i]) @@ -125,9 +122,11 @@ static void ps3_input_poll(void *data) for (j = 0; j < last_kbdata[i].nb_keycode; j++) { - int code = last_kbdata[i].keycode[j]; + unsigned k; + int code = last_kbdata[i].keycode[j]; int newly_depressed = 1; - for (int k = 0; k < MAX_KB_PORT_NUM; i++) + + for (k = 0; k < MAX_KB_PORT_NUM; i++) if (ps3->kbdata[i].keycode[k] == code) { newly_depressed = 0; @@ -143,14 +142,19 @@ static void ps3_input_poll(void *data) for (j = 0; j < ps3->kbdata[i].nb_keycode; j++) { - int code = ps3->kbdata[i].keycode[j]; + unsigned k; + int code = ps3->kbdata[i].keycode[j]; int newly_pressed = 1; - for (int k = 0; k < MAX_KB_PORT_NUM; i++) + + for (k = 0; k < MAX_KB_PORT_NUM; i++) + { if (last_kbdata[i].keycode[k] == code) { newly_pressed = 0; break; } + } + if (newly_pressed) { unsigned keyboardcode = input_keymaps_translate_keysym_to_rk(code); @@ -203,7 +207,10 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id) return false; } -static int16_t ps3_input_state(void *data, +static int16_t ps3_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -220,14 +227,15 @@ static int16_t ps3_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = ps3->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { if (binds[port][i].valid) { - if (psl1ght_keyboard_port_input_pressed(ps3, binds[port][i].key)) + if (psl1ght_keyboard_port_input_pressed( + ps3, binds[port][i].key)) ret |= (1 << i); } } @@ -239,7 +247,7 @@ static int16_t ps3_input_state(void *data, if (binds[port][id].valid) { if ( - button_is_pressed(ps3->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if (psl1ght_keyboard_port_input_pressed( @@ -283,8 +291,6 @@ static void* ps3_input_init(const char *joypad_driver) ps3_connect_keyboard(ps3, i); } - ps3->joypad = input_joypad_init_driver(joypad_driver, ps3); - return ps3; } @@ -306,23 +312,6 @@ static bool ps3_input_set_sensor_state(void *data, unsigned port, return false; } -static bool ps3_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - -static const input_device_driver_t *ps3_input_get_joypad_driver(void *data) -{ - ps3_input_t *ps3 = (ps3_input_t*)data; - if (ps3) - return ps3->joypad; - return NULL; -} - -static void ps3_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - input_driver_t input_ps3 = { ps3_input_init, ps3_input_poll, @@ -333,11 +322,9 @@ input_driver_t input_ps3 = { ps3_input_get_capabilities, "ps3", - ps3_input_grab_mouse, - NULL, - ps3_input_set_rumble, - ps3_input_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 10a07940e2..8e3cacbc50 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -73,7 +73,6 @@ uint8_t modifier_lut[VITA_NUM_MODIFIERS][2] = typedef struct psp_input { - const input_device_driver_t *joypad; #ifdef VITA int keyboard_hid_handle; int mouse_hid_handle; @@ -90,10 +89,10 @@ typedef struct psp_input #endif } psp_input_t; -static void psp_input_poll(void *data) +#ifdef VITA +static void vita_input_poll(void *data) { psp_input_t *psp = (psp_input_t*)data; -#ifdef VITA unsigned int i = 0; int key_sym = 0; unsigned key_code = 0; @@ -234,13 +233,8 @@ static void psp_input_poll(void *data) psp->mouse_y = 0; else if (psp->mouse_y > MOUSE_MAX_Y) psp->mouse_y = MOUSE_MAX_Y; -#endif - - if (psp && psp->joypad) - psp->joypad->poll(); } -#ifdef VITA static int16_t psp_input_mouse_state( psp_input_t *psp, unsigned id, bool screen) { @@ -248,31 +242,24 @@ static int16_t psp_input_mouse_state( switch (id) { case RETRO_DEVICE_ID_MOUSE_LEFT: - val = psp->mouse_button_left; - break; + return psp->mouse_button_left; case RETRO_DEVICE_ID_MOUSE_RIGHT: - val = psp->mouse_button_right; - break; + return psp->mouse_button_right; case RETRO_DEVICE_ID_MOUSE_MIDDLE: - val = psp->mouse_button_middle; - break; + return psp->mouse_button_middle; case RETRO_DEVICE_ID_MOUSE_X: if (screen) - val = psp->mouse_x; - else - { - val = psp->mouse_x_delta; - psp->mouse_x_delta = 0; /* flush delta after it has been read */ - } + return psp->mouse_x; + + val = psp->mouse_x_delta; + psp->mouse_x_delta = 0; /* flush delta after it has been read */ break; case RETRO_DEVICE_ID_MOUSE_Y: if (screen) - val = psp->mouse_y; - else - { - val = psp->mouse_y_delta; - psp->mouse_y_delta = 0; /* flush delta after it has been read */ - } + return psp->mouse_y; + + val = psp->mouse_y_delta; + psp->mouse_y_delta = 0; /* flush delta after it has been read */ break; } @@ -280,7 +267,10 @@ static int16_t psp_input_mouse_state( } #endif -static int16_t psp_input_state(void *data, +static int16_t psp_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -297,12 +287,12 @@ static int16_t psp_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return psp->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) if ( - button_is_pressed(psp->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -326,11 +316,6 @@ static int16_t psp_input_state(void *data, static void psp_input_free_input(void *data) { - psp_input_t *psp = (psp_input_t*)data; - - if (psp && psp->joypad) - psp->joypad->destroy(); - free(data); } @@ -356,8 +341,6 @@ static void* psp_input_initialize(const char *joypad_driver) psp->mouse_y = 0; #endif - psp->joypad = input_joypad_init_driver(joypad_driver, psp); - return psp; } @@ -374,27 +357,16 @@ static uint64_t psp_input_get_capabilities(void *data) return caps; } -static const input_device_driver_t *psp_input_get_joypad_driver(void *data) -{ - psp_input_t *psp = (psp_input_t*)data; - if (psp) - return psp->joypad; - return NULL; -} - -static void psp_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool psp_input_set_rumble(void *data, unsigned port, +static bool psp_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { psp_input_t *psp = (psp_input_t*)data; - if (psp && psp->joypad) - return input_joypad_set_rumble(psp->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } @@ -477,7 +449,11 @@ static float psp_input_get_sensor_input(void *data, input_driver_t input_psp = { psp_input_initialize, - psp_input_poll, +#ifdef VITA + vita_input_poll, +#else + NULL, /* poll */ +#endif psp_input_state, psp_input_free_input, #ifdef VITA @@ -494,10 +470,8 @@ input_driver_t input_psp = { "psp", #endif - psp_input_grab_mouse, + NULL, /* grab_mouse */ NULL, psp_input_set_rumble, - psp_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 9ea8a7cf1e..778e35a0e7 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -77,8 +77,6 @@ typedef struct qnx_input { uint64_t pad_state[DEFAULT_MAX_PADS]; - const input_device_driver_t *joypad; - /* * The first pointer_count indices of touch_map will be a valid, * active index in pointer array. @@ -245,7 +243,7 @@ static void qnx_input_autodetect_gamepad(qnx_input_t *qnx, input_autoconfigure_connect( name_buf, NULL, - qnx->joypad->ident, + "qnx", controller->port, *controller->vid, *controller->pid); @@ -691,8 +689,6 @@ static void *qnx_input_init(const char *joypad_driver) qnx->touch_map[i] = -1; } - qnx->joypad = input_joypad_init_driver(joypad_driver, qnx); - for (i = 0; i < DEFAULT_MAX_PADS; ++i) qnx_init_controller(qnx, &qnx->devices[i]); @@ -773,7 +769,10 @@ static int16_t qnx_pointer_input_state(qnx_input_t *qnx, return 0; } -static int16_t qnx_input_state(void *data, +static int16_t qnx_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -786,7 +785,7 @@ static int16_t qnx_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = qnx->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); if (!input_qnx.keyboard_mapping_blocked) @@ -809,7 +808,7 @@ static int16_t qnx_input_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed(qnx->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if ( @@ -855,12 +854,6 @@ static uint64_t qnx_input_get_capabilities(void *data) (1 << RETRO_DEVICE_KEYBOARD); } -static const input_device_driver_t *qnx_input_get_joypad_driver(void *data) -{ - qnx_input_t *qnx = (qnx_input_t*)data; - return qnx->joypad; -} - input_driver_t input_qnx = { qnx_input_init, qnx_input_poll, @@ -873,7 +866,5 @@ input_driver_t input_qnx = { NULL, NULL, NULL, - qnx_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index f0dac8cb08..83a3b2784c 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -77,7 +77,6 @@ typedef struct rwebinput_mouse_states typedef struct rwebinput_input { rwebinput_mouse_state_t mouse; /* double alignment */ - const input_device_driver_t *joypad; rwebinput_keyboard_event_queue_t keyboard; /* ptr alignment */ bool keys[RETROK_LAST]; } rwebinput_input_t; @@ -365,8 +364,6 @@ static void *rwebinput_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_rwebinput); - rwebinput->joypad = input_joypad_init_driver(joypad_driver, rwebinput); - return rwebinput; error: @@ -382,8 +379,9 @@ static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key) return rwebinput->keys[key]; } -static int16_t rwebinput_pointer_device_state(rwebinput_mouse_state_t *mouse, - unsigned id, bool screen) +static int16_t rwebinput_pointer_device_state( + rwebinput_mouse_state_t *mouse, + unsigned id, bool screen) { struct video_viewport vp; const int edge_detect = 32700; @@ -436,8 +434,9 @@ static int16_t rwebinput_pointer_device_state(rwebinput_mouse_state_t *mouse, return 0; } -static int16_t rwebinput_mouse_state(rwebinput_mouse_state_t *mouse, - unsigned id, bool screen) +static int16_t rwebinput_mouse_state( + rwebinput_mouse_state_t *mouse, + unsigned id, bool screen) { switch (id) { @@ -497,9 +496,12 @@ static int16_t rwebinput_is_pressed( return 0; } -static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, - rarch_joypad_info_t *joypad_info, const struct retro_keybind *binds, - unsigned idx, unsigned id) +static int16_t rwebinput_analog_pressed( + rwebinput_input_t *rwebinput, + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned idx, unsigned id) { int16_t pressed_minus = 0, pressed_plus = 0; unsigned id_minus = 0; @@ -512,10 +514,10 @@ static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, if (binds[id].valid) { if (rwebinput_is_pressed(rwebinput, - rwebinput->joypad, joypad_info, binds, idx, id_minus)) + joypad, joypad_info, binds, idx, id_minus)) pressed_minus = -0x7fff; if (rwebinput_is_pressed(rwebinput, - rwebinput->joypad, joypad_info, binds, idx, id_plus)) + joypad, joypad_info, binds, idx, id_plus)) pressed_plus = 0x7fff; } } @@ -523,7 +525,10 @@ static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, return pressed_plus + pressed_minus; } -static int16_t rwebinput_input_state(void *data, +static int16_t rwebinput_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -542,7 +547,7 @@ static int16_t rwebinput_input_state(void *data, if (binds[port][i].valid) { if (rwebinput_is_pressed( - rwebinput, rwebinput->joypad, + rwebinput, joypad, joypad_info, binds[port], port, i)) ret |= (1 << i); } @@ -556,7 +561,7 @@ static int16_t rwebinput_input_state(void *data, { if (binds[port][id].valid) { - if (rwebinput_is_pressed(rwebinput, rwebinput->joypad, + if (rwebinput_is_pressed(rwebinput, joypad, joypad_info, binds[port], port, id)) return 1; @@ -567,7 +572,7 @@ static int16_t rwebinput_input_state(void *data, case RETRO_DEVICE_ANALOG: if (binds[port]) return rwebinput_analog_pressed( - rwebinput, joypad_info, binds[port], + rwebinput, joypad, joypad_info, binds[port], idx, id); break; case RETRO_DEVICE_KEYBOARD: @@ -591,9 +596,6 @@ static void rwebinput_input_free(void *data) emscripten_html5_remove_all_event_listeners(); - if (rwebinput->joypad) - rwebinput->joypad->destroy(); - free(rwebinput->keyboard.events); free(rwebinput); } @@ -664,32 +666,16 @@ static void rwebinput_input_poll(void *data) rwebinput->mouse.scroll_y = rwebinput->mouse.pending_scroll_y; rwebinput->mouse.pending_scroll_x = 0; rwebinput->mouse.pending_scroll_y = 0; - - if (rwebinput->joypad) - rwebinput->joypad->poll(); } static void rwebinput_grab_mouse(void *data, bool state) { - (void)data; - if (state) emscripten_request_pointerlock("#canvas", EM_TRUE); else emscripten_exit_pointerlock(); } -static bool rwebinput_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - -static const input_device_driver_t *rwebinput_get_joypad_driver(void *data) -{ - rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; - if (!rwebinput) - return NULL; - return rwebinput->joypad; -} - static uint64_t rwebinput_get_capabilities(void *data) { uint64_t caps = 0; @@ -714,8 +700,6 @@ input_driver_t input_rwebinput = { "rwebinput", rwebinput_grab_mouse, NULL, - rwebinput_set_rumble, - rwebinput_get_joypad_driver, - NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 6a01a39cae..1819b798ec 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -36,7 +36,6 @@ typedef struct sdl_input { - const input_device_driver_t *joypad; int mouse_x, mouse_y; int mouse_abs_x, mouse_abs_y; int mouse_l, mouse_r, mouse_m, mouse_b4, mouse_b5, mouse_wu, mouse_wd, mouse_wl, mouse_wr; @@ -50,8 +49,6 @@ static void *sdl_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_sdl); - sdl->joypad = input_joypad_init_driver(joypad_driver, sdl); - return sdl; } @@ -188,7 +185,10 @@ static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id) return 0; } -static int16_t sdl_input_state(void *data, +static int16_t sdl_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -201,7 +201,7 @@ static int16_t sdl_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = sdl->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -219,7 +219,7 @@ static int16_t sdl_input_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed(sdl->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if (sdl_key_pressed(binds[port][id].key)) @@ -272,16 +272,14 @@ static void sdl_input_free(void *data) while (SDL_PollEvent(&event)); #endif - if (sdl->joypad) - sdl->joypad->destroy(); - free(data); } -static void sdl_grab_mouse(void *data, bool state) -{ #ifdef HAVE_SDL2 - struct temp{ +static void sdl2_grab_mouse(void *data, bool state) +{ + struct temp + { SDL_Window *w; }; @@ -291,26 +289,20 @@ static void sdl_grab_mouse(void *data, bool state) /* First member of sdl2_video_t is the window */ SDL_SetWindowGrab(((struct temp*)video_driver_get_ptr(false))->w, state ? SDL_TRUE : SDL_FALSE); -#endif } +#endif -static bool sdl_set_rumble(void *data, unsigned port, +static bool sdl_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - sdl_input_t *sdl = (sdl_input_t*)data; - if (sdl) - return input_joypad_set_rumble(sdl->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *sdl_get_joypad_driver(void *data) -{ - sdl_input_t *sdl = (sdl_input_t*)data; - if (!sdl) - return NULL; - return sdl->joypad; -} - static void sdl_poll_mouse(sdl_input_t *sdl) { Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y); @@ -330,13 +322,11 @@ static void sdl_poll_mouse(sdl_input_t *sdl) static void sdl_input_poll(void *data) { - sdl_input_t *sdl = (sdl_input_t*)data; SDL_Event event; + sdl_input_t *sdl = (sdl_input_t*)data; SDL_PumpEvents(); - if (sdl->joypad) - sdl->joypad->poll(); sdl_poll_mouse(sdl); #ifdef HAVE_SDL2 @@ -408,13 +398,12 @@ input_driver_t input_sdl = { sdl_get_capabilities, #ifdef HAVE_SDL2 "sdl2", + sdl2_grab_mouse, #else "sdl", + NULL, /* grab_mouse */ #endif - sdl_grab_mouse, NULL, sdl_set_rumble, - sdl_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index cbba6b7896..083b1bfbf7 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -92,8 +92,6 @@ typedef struct typedef struct switch_input { - const input_device_driver_t *joypad; - #ifdef HAVE_LIBNX /* pointer */ bool touch_state[MULTITOUCH_LIMIT]; @@ -131,6 +129,8 @@ typedef struct switch_input /* sensor handles */ uint32_t sixaxis_handles[DEFAULT_MAX_PADS][4]; unsigned sixaxis_handles_count[DEFAULT_MAX_PADS]; +#else + void *empty; #endif } switch_input_t; @@ -147,24 +147,17 @@ static void finish_simulated_mouse_clicks(switch_input_t *sw, uint64_t currentTi /* end of touch mouse function declarations */ #endif +#ifdef HAVE_LIBNX static void switch_input_poll(void *data) { -#ifdef HAVE_LIBNX MousePosition mouse_pos; - uint32_t touch_count; unsigned int i = 0; int keySym = 0; unsigned keyCode = 0; uint16_t mod = 0; uint64_t mouse_current_report = 0; -#endif switch_input_t *sw = (switch_input_t*) data; - - if (sw->joypad) - sw->joypad->poll(); - -#ifdef HAVE_LIBNX - touch_count = hidTouchCount(); + uint32_t touch_count = hidTouchCount(); for (i = 0; i < MULTITOUCH_LIMIT; i++) { sw->previous_touch_state[i] = sw->touch_state[i]; @@ -283,10 +276,8 @@ static void switch_input_poll(void *data) sw->mouse_y = MOUSE_MAX_Y; sw->mouse_wheel = mouse_pos.scrollVelocityY; -#endif } -#ifdef HAVE_LIBNX static int16_t switch_pointer_screen_device_state(switch_input_t *sw, unsigned id, unsigned idx) { @@ -394,12 +385,12 @@ static int16_t switch_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return sw->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) if ( - button_is_pressed(sw->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -799,18 +790,15 @@ static void switch_input_free_input(void *data) unsigned i,j; switch_input_t *sw = (switch_input_t*) data; - if (sw) - { - if(sw->joypad) - sw->joypad->destroy(); + if (!sw) + return; - for (i = 0; i < DEFAULT_MAX_PADS; i++) - if (sw->sixaxis_handles_count[i] > 0) - for (j = 0; j < sw->sixaxis_handles_count[i]; j++) - hidStopSixAxisSensor(sw->sixaxis_handles[i][j]); + for (i = 0; i < DEFAULT_MAX_PADS; i++) + if (sw->sixaxis_handles_count[i] > 0) + for (j = 0; j < sw->sixaxis_handles_count[i]; j++) + hidStopSixAxisSensor(sw->sixaxis_handles[i][j]); - free(sw); - } + free(sw); #ifdef HAVE_LIBNX hidExit(); @@ -858,8 +846,6 @@ static void* switch_input_init(const char *joypad_driver) sw->sixaxis_handles_count[i] = 0; #endif - sw->joypad = input_joypad_init_driver(joypad_driver, sw); - return sw; } @@ -876,27 +862,15 @@ static uint64_t switch_input_get_capabilities(void *data) return caps; } -static const input_device_driver_t *switch_input_get_joypad_driver(void *data) -{ - switch_input_t *sw = (switch_input_t*) data; - if (sw) - return sw->joypad; - return NULL; -} - -static void switch_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool switch_input_set_rumble(void *data, unsigned port, +static bool switch_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { #ifdef HAVE_LIBNX - switch_input_t *sw = (switch_input_t*) data; - if (sw) - return input_joypad_set_rumble(sw->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); #endif return false; } @@ -995,17 +969,19 @@ static float switch_input_get_sensor_input(void *data, input_driver_t input_switch = { switch_input_init, +#ifdef HAVE_LIBNX switch_input_poll, +#else + NULL, /* poll */ +#endif switch_input_state, switch_input_free_input, switch_input_set_sensor_state, switch_input_get_sensor_input, switch_input_get_capabilities, "switch", - switch_input_grab_mouse, + NULL, /* grab_mouse */ NULL, switch_input_set_rumble, - switch_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 2379eec5c6..8f9638ea2d 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -130,7 +130,6 @@ struct udev_input { struct udev *udev; struct udev_monitor *monitor; - const input_device_driver_t *joypad; udev_input_device_t **devices; int fd; @@ -776,9 +775,6 @@ static void udev_input_poll(void *data) } } } - - if (udev->joypad) - udev->joypad->poll(); } static bool udev_pointer_is_off_window(const udev_input_t *udev) @@ -982,6 +978,7 @@ static int16_t udev_pointer_state(udev_input_t *udev, static int16_t udev_input_lightgun_state( udev_input_t *udev, + const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -994,7 +991,7 @@ static int16_t udev_input_lightgun_state( if (binds[port][id].valid) { unsigned new_id = id; - if (button_is_pressed(udev->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id) || udev_mouse_button_pressed(udev, port, @@ -1005,7 +1002,10 @@ static int16_t udev_input_lightgun_state( return 0; } -static int16_t udev_input_state(void *data, +static int16_t udev_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -1018,7 +1018,7 @@ static int16_t udev_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = udev->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -1050,7 +1050,7 @@ static int16_t udev_input_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed(udev->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if ( @@ -1099,37 +1099,48 @@ static int16_t udev_input_state(void *data, /*buttons*/ case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); case RETRO_DEVICE_ID_LIGHTGUN_START: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_SELECT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: - return udev_input_lightgun_state(udev, joypad_info, + return udev_input_lightgun_state(udev, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: @@ -1150,7 +1161,7 @@ static int16_t udev_input_state(void *data, if (binds[port][RARCH_LIGHTGUN_START].valid) { unsigned new_id = RARCH_LIGHTGUN_START; - if (button_is_pressed(udev->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id) || udev_mouse_button_pressed(udev, port, @@ -1174,9 +1185,6 @@ static void udev_input_free(void *data) if (!data || !udev) return; - if (udev->joypad) - udev->joypad->destroy(); - if (udev->fd >= 0) close(udev->fd); @@ -1321,8 +1329,6 @@ static void *udev_input_init(const char *joypad_driver) RARCH_WARN("[udev]: Full-screen pointer won't be available.\n"); #endif - udev->joypad = input_joypad_init_driver(joypad_driver, udev); - return udev; error: @@ -1368,24 +1374,18 @@ static void udev_input_grab_mouse(void *data, bool state) #endif } -static bool udev_input_set_rumble(void *data, unsigned port, +static bool udev_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - udev_input_t *udev = (udev_input_t*)data; - if (udev && udev->joypad) - return input_joypad_set_rumble(udev->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *udev_input_get_joypad_driver(void *data) -{ - udev_input_t *udev = (udev_input_t*)data; - if (!udev) - return NULL; - return udev->joypad; -} - input_driver_t input_udev = { udev_input_init, udev_input_poll, @@ -1402,7 +1402,5 @@ input_driver_t input_udev = { NULL, #endif udev_input_set_rumble, - udev_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index b85c35af12..824e79289d 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -31,16 +31,11 @@ typedef struct uwp_input { - const input_device_driver_t *joypad; + void *empty; } uwp_input_t; static void uwp_input_poll(void *data) { - uwp_input_t *uwp = (uwp_input_t*)data; - - if (uwp && uwp->joypad) - uwp->joypad->poll(); - uwp_input_next_frame(); } @@ -51,9 +46,6 @@ static void uwp_input_free_input(void *data) if (!uwp) return; - if (uwp->joypad) - uwp->joypad->destroy(); - free(uwp); } @@ -65,8 +57,6 @@ static void *uwp_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_uwp); - uwp->joypad = input_joypad_init_driver(joypad_driver, uwp); - return uwp; } @@ -83,29 +73,17 @@ static uint64_t uwp_input_get_capabilities(void *data) return caps; } -static bool uwp_input_set_rumble(void *data, unsigned port, +static bool uwp_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - struct uwp_input *uwp = (struct uwp_input*)data; - if (uwp) - return input_joypad_set_rumble(uwp->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *uwp_input_get_joypad_driver(void *data) -{ - uwp_input_t *uwp = (uwp_input_t*)data; - if (!uwp) - return NULL; - return uwp->joypad; -} - -static void uwp_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - static int16_t uwp_pressed_analog(uwp_input_t *uwp, rarch_joypad_info_t *joypad_info, const struct retro_keybind *binds, @@ -134,7 +112,10 @@ static int16_t uwp_pressed_analog(uwp_input_t *uwp, return pressed_plus + pressed_minus; } -static int16_t uwp_input_state(void *data, +static int16_t uwp_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -148,7 +129,7 @@ static int16_t uwp_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = uwp->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); if (!input_uwp.keyboard_mapping_blocked) @@ -184,7 +165,7 @@ static int16_t uwp_input_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed(uwp->joypad, joypad_info, + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if ((binds[port][id].key < RETROK_LAST) @@ -228,10 +209,8 @@ input_driver_t input_uwp = { NULL, uwp_input_get_capabilities, "uwp", - uwp_input_grab_mouse, + NULL, /* grab_mouse */ NULL, uwp_input_set_rumble, - uwp_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 22f96eff00..399dd51ace 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -151,9 +151,6 @@ static void input_wl_poll(void *data) wl->mouse.delta_y = 0; } - if (wl->joypad) - wl->joypad->poll(); - input_wl_touch_pool(wl); } @@ -295,7 +292,10 @@ static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl, return 0; } -static int16_t input_wl_state(void *data, +static int16_t input_wl_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -308,7 +308,7 @@ static int16_t input_wl_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = wl->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -329,7 +329,8 @@ static int16_t input_wl_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed(wl->joypad, joypad_info, binds[port], + if (button_is_pressed(joypad, + joypad_info, binds[port], port, id)) return 1; else if (BIT_GET(wl->key_state, @@ -371,9 +372,7 @@ static void input_wl_free(void *data) input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; if (!wl) return; - - if (wl->joypad) - wl->joypad->destroy(); + free(data); } bool input_wl_init(void *data, const char *joypad_name) @@ -385,11 +384,6 @@ bool input_wl_init(void *data, const char *joypad_name) input_keymaps_init_keyboard_lut(rarch_key_map_linux); - wl->joypad = input_joypad_init_driver(joypad_name, wl); - - if (!wl->joypad) - return false; - return true; } @@ -412,23 +406,17 @@ static void input_wl_grab_mouse(void *data, bool state) (void)state; } -static bool input_wl_set_rumble(void *data, unsigned port, +static bool input_wl_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; - if (wl && wl->joypad) - return input_joypad_set_rumble(wl->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *input_wl_get_joypad_driver(void *data) -{ - input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; - if (!wl) - return NULL; - return wl->joypad; -} - input_driver_t input_wayland = { NULL, input_wl_poll, @@ -441,7 +429,5 @@ input_driver_t input_wayland = { input_wl_grab_mouse, NULL, input_wl_set_rumble, - input_wl_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index e37d59367f..c4ed5c6844 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -41,7 +41,7 @@ static bool keyboard_state[RETROK_LAST] = { 0 }; typedef struct wiiu_input { - const input_device_driver_t *joypad; + void *empty; } wiiu_input_t; static void kb_connection_callback(KBDKeyEvent *key) @@ -94,35 +94,32 @@ static void kb_key_callback(KBDKeyEvent *key) hard to get working nicely. */ -static int16_t wiiu_pointer_device_state(wiiu_input_t* wiiu, unsigned id) +static int16_t wiiu_pointer_device_state( + wiiu_input_t* wiiu, + const input_device_driver_t *joypad, + unsigned id) { switch (id) { case RETRO_DEVICE_ID_POINTER_PRESSED: { input_bits_t state; - wiiu->joypad->get_buttons(0, &state); + joypad->get_buttons(0, &state); return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0; } case RETRO_DEVICE_ID_POINTER_X: - return wiiu->joypad->axis(0, 0xFFFF0004UL); + return joypad->axis(0, 0xFFFF0004UL); case RETRO_DEVICE_ID_POINTER_Y: - return wiiu->joypad->axis(0, 0xFFFF0005UL); + return joypad->axis(0, 0xFFFF0005UL); } return 0; } -static void wiiu_input_poll(void *data) -{ - wiiu_input_t *wiiu = (wiiu_input_t*)data; - - if (wiiu) - if (wiiu->joypad) - wiiu->joypad->poll(); -} - -static int16_t wiiu_input_state(void *data, +static int16_t wiiu_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -137,12 +134,12 @@ static int16_t wiiu_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return wiiu->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) return button_is_pressed( - wiiu->joypad, + joypad, joypad_info, binds[port], port, id); break; case RETRO_DEVICE_KEYBOARD: @@ -153,7 +150,7 @@ static int16_t wiiu_input_state(void *data, break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return wiiu_pointer_device_state(wiiu, id); + return wiiu_pointer_device_state(wiiu, joypad, id); } return 0; @@ -163,9 +160,6 @@ static void wiiu_input_free_input(void *data) { wiiu_input_t *wiiu = (wiiu_input_t*)data; - if (wiiu && wiiu->joypad) - wiiu->joypad->destroy(); - KBDTeardown(); free(data); @@ -182,9 +176,6 @@ static void* wiiu_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_wiiu); - DEBUG_STR(joypad_driver); - wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu); - return wiiu; } @@ -196,36 +187,17 @@ static uint64_t wiiu_input_get_capabilities(void *data) (1 << RETRO_DEVICE_POINTER); } -static const input_device_driver_t *wiiu_input_get_joypad_driver(void *data) -{ - wiiu_input_t *wiiu = (wiiu_input_t*)data; - if (wiiu) - return wiiu->joypad; - return NULL; -} - -static void wiiu_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool wiiu_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - input_driver_t input_wiiu = { wiiu_input_init, - wiiu_input_poll, + NULL, /* poll */ wiiu_input_state, wiiu_input_free_input, NULL, NULL, wiiu_input_get_capabilities, "wiiu", - wiiu_input_grab_mouse, - NULL, - wiiu_input_set_rumble, - wiiu_input_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 989db21935..fe5e1b087b 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -39,7 +39,6 @@ typedef struct winraw_keyboard_t keyboard; HWND window; winraw_mouse_t *mice; - const input_device_driver_t *joypad; bool mouse_grab; } winraw_input_t; @@ -510,8 +509,6 @@ static void *winraw_init(const char *joypad_driver) if (!winraw_set_mouse_input(wr->window, false)) goto error; - wr->joypad = input_joypad_init_driver(joypad_driver, wr); - return wr; error: @@ -558,14 +555,12 @@ static void winraw_poll(void *d) wr->mice[i].btn_b4 = g_mice[i].btn_b4; wr->mice[i].btn_b5 = g_mice[i].btn_b5; } - - if (wr->joypad) - wr->joypad->poll(); } static int16_t winraw_input_lightgun_state( winraw_input_t *wr, winraw_mouse_t *mouse, + const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -582,20 +577,23 @@ static int16_t winraw_input_lightgun_state( [id].mbutton)) return 1; return button_is_pressed( - wr->joypad, joypad_info, binds[port], + joypad, joypad_info, binds[port], port, id); } return 0; } -static int16_t winraw_input_state(void *d, +static int16_t winraw_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { settings_t *settings = NULL; winraw_mouse_t *mouse = NULL; - winraw_input_t *wr = (winraw_input_t*)d; + winraw_input_t *wr = (winraw_input_t*)data; bool process_mouse = (device == RETRO_DEVICE_JOYPAD) || (device == RETRO_DEVICE_MOUSE) @@ -625,7 +623,7 @@ static int16_t winraw_input_state(void *d, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = wr->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); if (mouse) @@ -663,7 +661,7 @@ static int16_t winraw_input_state(void *d, if (binds[port][id].valid) { if (button_is_pressed( - wr->joypad, + joypad, joypad_info, binds[port], port, id)) return 1; else if ( @@ -704,37 +702,48 @@ static int16_t winraw_input_state(void *d, break; /*buttons*/ case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); case RETRO_DEVICE_ID_LIGHTGUN_START: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_SELECT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: @@ -743,7 +752,8 @@ static int16_t winraw_input_state(void *d, return winraw_deprecated_lightgun_state(wr, mouse, port, id); break; case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: - return winraw_input_lightgun_state(wr, mouse, joypad_info, + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, binds, port, device, idx, RARCH_LIGHTGUN_START); } break; @@ -756,8 +766,6 @@ static void winraw_free(void *d) { winraw_input_t *wr = (winraw_input_t*)d; - if (wr->joypad) - wr->joypad->destroy(); winraw_set_mouse_input(NULL, false); winraw_set_keyboard_input(NULL); winraw_destroy_window(wr->window); @@ -793,19 +801,15 @@ static void winraw_grab_mouse(void *d, bool grab) wr->mouse_grab = grab; } -static bool winraw_set_rumble(void *d, unsigned port, +static bool winraw_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - winraw_input_t *wr = (winraw_input_t*)d; - - return input_joypad_set_rumble(wr->joypad, port, effect, strength); -} - -static const input_device_driver_t *winraw_get_joypad_driver(void *d) -{ - winraw_input_t *wr = (winraw_input_t*)d; - - return wr->joypad; + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); + return false; } input_driver_t input_winraw = { @@ -820,7 +824,5 @@ input_driver_t input_winraw = { winraw_grab_mouse, NULL, winraw_set_rumble, - winraw_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 75f94a4dc8..199b305803 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -34,8 +34,6 @@ typedef struct x11_input { - const input_device_driver_t *joypad; - Display *display; Window win; @@ -66,8 +64,6 @@ static void *x_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_x11); - x11->joypad = input_joypad_init_driver(joypad_driver, x11); - return x11; } @@ -268,7 +264,10 @@ static int16_t x_pointer_state(x11_input_t *x11, return 0; } -static int16_t x_input_state(void *data, +static int16_t x_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -285,7 +284,7 @@ static int16_t x_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = x11->joypad->state( + int16_t ret = joypad->state( joypad_info, binds[port], port); if (settings->uints.input_mouse_index[port] == 0) @@ -321,7 +320,7 @@ static int16_t x_input_state(void *data, { if (binds[port][id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; else if ( @@ -378,7 +377,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -401,7 +400,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -424,7 +423,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -447,7 +446,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -470,7 +469,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -493,7 +492,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -516,7 +515,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -539,7 +538,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -562,7 +561,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -585,7 +584,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -608,7 +607,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -636,7 +635,7 @@ static int16_t x_input_state(void *data, return 1; if (binds[port][new_id].valid) { - if (button_is_pressed( x11->joypad, + if (button_is_pressed(joypad, joypad_info, binds[port], port, new_id)) return 1; @@ -663,9 +662,6 @@ static void x_input_free(void *data) if (!x11) return; - if (x11->joypad) - x11->joypad->destroy(); - free(x11); } @@ -738,9 +734,6 @@ static void x_input_poll(void *data) memset(x11->state, 0, sizeof(x11->state)); x_input_poll_mouse(x11, video_has_focus); - - if (x11->joypad) - x11->joypad->poll(); } static void x_grab_mouse(void *data, bool state) @@ -750,24 +743,17 @@ static void x_grab_mouse(void *data, bool state) x11->grab_mouse = state; } -static bool x_set_rumble(void *data, unsigned port, +static bool x_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - x11_input_t *x11 = (x11_input_t*)data; - if (x11) - return input_joypad_set_rumble(x11->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *x_get_joypad_driver(void *data) -{ - x11_input_t *x11 = (x11_input_t*)data; - - if (!x11) - return NULL; - return x11->joypad; -} - static uint64_t x_input_get_capabilities(void *data) { uint64_t caps = 0; @@ -794,7 +780,5 @@ input_driver_t input_x = { x_grab_mouse, NULL, x_set_rumble, - x_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 5bd77cdcc1..1f32d04c3c 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -37,18 +37,13 @@ typedef struct xdk_input { - const input_device_driver_t *joypad; + void *empty; } xdk_input_t; -static void xdk_input_poll(void *data) -{ - xdk_input_t *xdk = (xdk_input_t*)data; - - if (xdk && xdk->joypad) - xdk->joypad->poll(); -} - -static int16_t xdk_input_state(void *data, +static int16_t xdk_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, @@ -63,12 +58,12 @@ static int16_t xdk_input_state(void *data, { case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) - return xdk->joypad->state( + return joypad->state( joypad_info, binds[port], port); if (binds[port][id].valid) if ( - button_is_pressed(xdk->joypad, joypad_info, binds[port], + button_is_pressed(joypad, joypad_info, binds[port], port, id)) return 1; break; @@ -86,9 +81,6 @@ static void xdk_input_free_input(void *data) if (!xdk) return; - if (xdk->joypad) - xdk->joypad->destroy(); - free(xdk); } @@ -98,57 +90,39 @@ static void *xdk_input_init(const char *joypad_driver) if (!xdk) return NULL; - xdk->joypad = input_joypad_init_driver(joypad_driver, xdk); - return xdk; } static uint64_t xdk_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } /* FIXME - are we sure about treating low frequency motor as the * "strong" motor? Does it apply for Xbox too? */ -static bool xdk_input_set_rumble(void *data, unsigned port, +static bool xdk_input_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - xdk_input_t *xdk = (xdk_input_t*)data; - if (xdk) - return input_joypad_set_rumble(xdk->joypad, port, effect, strength); + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, strength); return false; } -static const input_device_driver_t *xdk_input_get_joypad_driver(void *data) -{ - xdk_input_t *xdk = (xdk_input_t*)data; - if (!xdk) - return NULL; - return xdk->joypad; -} - -static void xdk_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - input_driver_t input_xinput = { xdk_input_init, - xdk_input_poll, + NULL, /* poll */ xdk_input_state, xdk_input_free_input, NULL, NULL, xdk_input_get_capabilities, "xinput", - xdk_input_grab_mouse, + NULL, /* grab_mouse */ NULL, xdk_input_set_rumble, - xdk_input_get_joypad_driver, - NULL, false }; diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 3839c5a395..231fd2615c 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -61,7 +61,10 @@ static void xenon360_input_poll(void *data) } } -static int16_t xenon360_input_state(void *data, +static int16_t xenon360_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, bool port, unsigned device, @@ -109,7 +112,7 @@ static int16_t xenon360_input_state(void *data, static void xenon360_input_free_input(void *data) { - (void)data; + free(data); } static void* xenon360_input_init(const char *joypad_driver) @@ -119,25 +122,7 @@ static void* xenon360_input_init(const char *joypad_driver) static uint64_t xenon360_input_get_capabilities(void *data) { - uint64_t caps = 0; - - caps |= (1 << RETRO_DEVICE_JOYPAD); - - return caps; -} - -static void xenon360_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - -static bool xenon360_input_set_rumble(void *data, unsigned port, - enum retro_rumble_effect effect, uint16_t strength) { return false; } - -static const input_device_driver_t *xenon360_get_joypad_driver(void *data) -{ - return NULL; + return (1 << RETRO_DEVICE_JOYPAD); } input_driver_t input_xenon360 = { @@ -150,10 +135,8 @@ input_driver_t input_xenon360 = { NULL, xenon360_input_get_capabilities, "xenon360", - xenon360_input_grab_mouse, - NULL, - xenon360_input_set_rumble, - xenon360_get_joypad_driver, + NULL, /* grab_mouse */ NULL, + NULL, /* set_rumble */ false }; diff --git a/input/input_driver.h b/input/input_driver.h index bf414f07a7..4d89940045 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -181,6 +181,8 @@ struct input_driver * Analog values have same range as a signed 16-bit integer. */ int16_t (*input_state)(void *data, + const input_device_driver_t *joypad_data, + const input_device_driver_t *sec_joypad_data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id); @@ -196,10 +198,11 @@ struct input_driver void (*grab_mouse)(void *data, bool state); bool (*grab_stdin)(void *data); - bool (*set_rumble)(void *data, unsigned port, + bool (*set_rumble)( + const input_device_driver_t *joypad_data, + const input_device_driver_t *sec_joypad_data, + unsigned port, enum retro_rumble_effect effect, uint16_t state); - const input_device_driver_t *(*get_joypad_driver)(void *data); - const input_device_driver_t *(*get_sec_joypad_driver)(void *data); bool keyboard_mapping_blocked; }; diff --git a/retroarch.c b/retroarch.c index a379561709..8013c9ed51 100644 --- a/retroarch.c +++ b/retroarch.c @@ -676,10 +676,13 @@ static const gfx_ctx_driver_t *gfx_ctx_gl_drivers[] = { static void *input_null_init(const char *joypad_driver) { return (void*)-1; } static void input_null_poll(void *data) { } -static int16_t input_null_input_state(void *data, - rarch_joypad_info_t *joypad_info, - const struct retro_keybind **retro_keybinds, - unsigned port, unsigned device, unsigned index, unsigned id) { return 0; } +static int16_t input_null_input_state( + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind **retro_keybinds, + unsigned port, unsigned device, unsigned index, unsigned id) { return 0; } static void input_null_free(void *data) { } static bool input_null_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned rate) { return false; } @@ -687,10 +690,11 @@ static float input_null_get_sensor_input(void *data, unsigned port, unsigned id) static uint64_t input_null_get_capabilities(void *data) { return 0; } static void input_null_grab_mouse(void *data, bool state) { } static bool input_null_grab_stdin(void *data) { return false; } -static bool input_null_set_rumble(void *data, unsigned port, +static bool input_null_set_rumble( + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + unsigned port, enum retro_rumble_effect effect, uint16_t state) { return false; } -static const input_device_driver_t *input_null_get_joypad_driver(void *data) { return NULL; } -static const input_device_driver_t *input_null_get_sec_joypad_driver(void *data) { return NULL; } static input_driver_t input_null = { input_null_init, @@ -704,8 +708,6 @@ static input_driver_t input_null = { input_null_grab_mouse, input_null_grab_stdin, input_null_set_rumble, - input_null_get_joypad_driver, - input_null_get_sec_joypad_driver, false, }; @@ -2135,6 +2137,7 @@ struct rarch_state core_info_state_t core_info_st; /* ptr alignment */ rarch_system_info_t runloop_system; /* ptr alignment */ struct retro_hw_render_callback hw_render; /* ptr alignment */ + const input_device_driver_t *joypad; /* ptr alignment */ #ifdef HAVE_BSV_MOVIE bsv_movie_t *bsv_movie_state_handle; /* ptr alignment */ #endif @@ -2798,7 +2801,6 @@ static void retro_frame_null(const void *data, unsigned width, static void retro_run_null(void); static void retro_input_poll_null(void); -static const input_device_driver_t *input_driver_get_sec_joypad_driver(void); static uint64_t input_driver_get_capabilities(void); static void uninit_libretro_symbols( @@ -3531,10 +3533,12 @@ static void menu_input_key_bind_poll_bind_get_rested_axes( struct menu_bind_state *state) { unsigned a; - const input_device_driver_t *joypad = - p_rarch->current_input->get_joypad_driver(p_rarch->current_input_data); - const input_device_driver_t *sec_joypad = - input_driver_get_sec_joypad_driver(); + const input_device_driver_t *joypad = p_rarch->joypad; +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif unsigned port = state->port; if (!joypad) @@ -3614,14 +3618,12 @@ static void menu_input_key_bind_poll_bind_state( input_driver_t *current_input = p_rarch->current_input; void *input_data = p_rarch->current_input_data; unsigned port = state->port; - const input_device_driver_t *joypad = NULL; - const input_device_driver_t *sec_joypad = - input_driver_get_sec_joypad_driver(); - - if ( current_input - && current_input->get_joypad_driver) - joypad = - current_input->get_joypad_driver(input_data); + const input_device_driver_t *joypad = p_rarch->joypad; +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif memset(state->state, 0, sizeof(state->state)); @@ -3636,10 +3638,13 @@ static void menu_input_key_bind_poll_bind_state( state->skip = timed_out || - current_input->input_state(input_data, - &joypad_info, - NULL, - 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); + current_input->input_state( + input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, + NULL, + 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); menu_input_key_bind_poll_bind_state_internal( joypad, state, port, timed_out); @@ -15617,11 +15622,24 @@ static void command_event_reinit(struct rarch_state *p_rarch, bool adaptive_vsync = settings->bools.video_adaptive_vsync; unsigned swap_interval = settings->uints.video_swap_interval; #endif +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif video_driver_reinit(flags); /* Poll input to avoid possibly stale data to corrupt things. */ if (p_rarch->current_input && p_rarch->current_input->poll) + { + if (p_rarch->joypad->poll) + p_rarch->joypad->poll(); +#ifdef HAVE_MFI + if (p_rarch->sec_joypad->poll) + p_rarch->sec_joypad->poll(); +#endif p_rarch->current_input->poll(p_rarch->current_input_data); + } command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, (void*)(intptr_t)-1); #ifdef HAVE_MENU @@ -23377,6 +23395,11 @@ static void input_poll_overlay( settings_t *settings = p_rarch->configuration_settings; bool input_overlay_show_physical_inputs = settings->bools.input_overlay_show_physical_inputs; unsigned input_overlay_show_physical_inputs_port = settings->uints.input_overlay_show_physical_inputs_port; +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif if (!ol_state) return; @@ -23393,16 +23416,28 @@ static void input_poll_overlay( RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER; for (i = 0; - input_ptr->input_state(input_data, &joypad_info, + input_ptr->input_state( + input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_PRESSED); i++) { input_overlay_state_t polled_data; - int16_t x = input_ptr->input_state(input_data, &joypad_info, + int16_t x = input_ptr->input_state( + input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_X); - int16_t y = input_ptr->input_state(input_data, &joypad_info, + int16_t y = input_ptr->input_state( + input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_Y); @@ -23712,19 +23747,47 @@ const char* config_get_input_driver_options(void) bool input_driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - struct rarch_state *p_rarch = &rarch_st; - if (!p_rarch->current_input || !p_rarch->current_input->set_rumble) - return false; - return p_rarch->current_input->set_rumble(p_rarch->current_input_data, - port, effect, strength); + struct rarch_state *p_rarch = &rarch_st; + if (p_rarch->current_input && p_rarch->current_input->set_rumble) + { +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif + return p_rarch->current_input->set_rumble(p_rarch->joypad, + sec_joypad, + port, effect, strength); + } + return false; } -static const input_device_driver_t *input_driver_get_sec_joypad_driver(void) +const char *joypad_driver_name(unsigned i) { - struct rarch_state *p_rarch = &rarch_st; - if (!p_rarch->current_input || !p_rarch->current_input->get_sec_joypad_driver) + struct rarch_state *p_rarch = &rarch_st; + if (!p_rarch || !p_rarch->joypad || !p_rarch->joypad->name) return NULL; - return p_rarch->current_input->get_sec_joypad_driver(p_rarch->current_input_data); + return p_rarch->joypad->name(i); +} + +void joypad_driver_reinit(void *data, const char *joypad_driver_name) +{ + struct rarch_state *p_rarch = &rarch_st; + if (!p_rarch) + return; + + if (p_rarch->joypad) + p_rarch->joypad->destroy(); + p_rarch->joypad = NULL; +#ifdef HAVE_MFI + if (p_rarch->sec_joypad) + p_rarch->sec_joypad->destroy(); + p_rarch->sec_joypad = NULL; +#endif + p_rarch->joypad = input_joypad_init_driver(joypad_driver_name, data); +#ifdef HAVE_MFI + p_rarch->sec_joypad = input_joypad_init_driver("mfi", data); +#endif } static uint64_t input_driver_get_capabilities(void) @@ -23776,12 +23839,25 @@ static void input_driver_poll(void) rarch_joypad_info_t joypad_info[MAX_USERS]; struct rarch_state *p_rarch = &rarch_st; settings_t *settings = p_rarch->configuration_settings; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif #ifdef HAVE_OVERLAY float input_overlay_opacity = settings->floats.input_overlay_opacity; #endif bool input_remap_binds_enable = settings->bools.input_remap_binds_enable; uint8_t max_users = (uint8_t)p_rarch->input_driver_max_users; + if (p_rarch->joypad->poll) + p_rarch->joypad->poll(); +#ifdef HAVE_MFI + if (p_rarch->sec_joypad->poll) + p_rarch->sec_joypad->poll(); +#endif p_rarch->current_input->poll(p_rarch->current_input_data); p_rarch->input_driver_turbo_btns.count++; @@ -23800,8 +23876,13 @@ static void input_driver_poll(void) if (!p_rarch->libretro_input_binds[i][RARCH_TURBO_ENABLE].valid) continue; - p_rarch->input_driver_turbo_btns.frame_enable[i] = p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info[i], p_rarch->libretro_input_binds, + p_rarch->input_driver_turbo_btns.frame_enable[i] = + p_rarch->current_input->input_state( + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info[i], + p_rarch->libretro_input_binds, (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); } @@ -23825,7 +23906,7 @@ static void input_driver_poll(void) #endif input_mapper_t *handle = p_rarch->input_driver_mapper; const input_device_driver_t *joypad_driver - = p_rarch->current_input->get_joypad_driver(p_rarch->current_input_data); + = p_rarch->joypad; memset(handle->keys, 0, sizeof(handle->keys)); @@ -23849,6 +23930,8 @@ static void input_driver_poll(void) unsigned k, j; int16_t ret = p_rarch->current_input->input_state( p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, &joypad_info[i], p_rarch->libretro_input_binds, (unsigned)i, RETRO_DEVICE_JOYPAD, @@ -24512,6 +24595,13 @@ static int16_t input_state(unsigned port, unsigned device, settings_t *settings = p_rarch->configuration_settings; int16_t result = 0; int16_t ret = 0; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif joypad_info.axis_threshold = p_rarch->input_driver_axis_threshold; joypad_info.joy_idx = settings->uints.input_joypad_map[port]; @@ -24535,17 +24625,21 @@ static int16_t input_state(unsigned port, unsigned device, device &= RETRO_DEVICE_MASK; ret = p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, p_rarch->libretro_input_binds, port, device, idx, id); if ( (device == RETRO_DEVICE_ANALOG) && (ret == 0)) { - const input_device_driver_t *joypad = - p_rarch->current_input->get_joypad_driver( - p_rarch->current_input_data); - const input_device_driver_t *sec_joypad = - input_driver_get_sec_joypad_driver(); + const input_device_driver_t *joypad = p_rarch->joypad; +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif if (p_rarch->libretro_input_binds[port]) { if (idx == RETRO_DEVICE_INDEX_ANALOG_BUTTON) @@ -24697,6 +24791,13 @@ static int16_t menu_input_read_mouse_hw( rarch_joypad_info_t joypad_info; unsigned type = 0; unsigned device = RETRO_DEVICE_MOUSE; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif joypad_info.joy_idx = 0; joypad_info.auto_binds = NULL; @@ -24733,7 +24834,10 @@ static int16_t menu_input_read_mouse_hw( } return p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, NULL, 0, device, 0, type); } @@ -24882,6 +24986,13 @@ static void menu_input_get_touchscreen_hw_state( static bool last_cancel_pressed = false; bool overlay_active = false; bool pointer_enabled = settings->bools.menu_pointer_enable; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif /* Easiest to set inactive by default, and toggle * when input is detected */ @@ -24920,7 +25031,10 @@ static void menu_input_get_touchscreen_hw_state( /* X pos */ pointer_x = p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, binds, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; @@ -24944,7 +25058,10 @@ static void menu_input_get_touchscreen_hw_state( /* Y pos */ pointer_y = p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, binds, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; @@ -24964,7 +25081,10 @@ static void menu_input_get_touchscreen_hw_state( /* Select (touch screen contact) * Note that releasing select also counts as activity */ hw_state->select_pressed = (bool)p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, binds, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); if (hw_state->select_pressed || (hw_state->select_pressed != last_select_pressed)) hw_state->active = true; @@ -24973,7 +25093,10 @@ static void menu_input_get_touchscreen_hw_state( /* Cancel (touch screen 'back' - don't know what is this, but whatever...) * Note that releasing cancel also counts as activity */ hw_state->cancel_pressed = (bool)p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, binds, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); if (hw_state->cancel_pressed || (hw_state->cancel_pressed != last_cancel_pressed)) hw_state->active = true; @@ -26216,11 +26339,21 @@ static void input_keys_pressed( rarch_joypad_info_t *joypad_info) { unsigned i; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif if (CHECK_INPUT_DRIVER_BLOCK_HOTKEY(binds_norm, binds_auto)) { if ( p_rarch->current_input->input_state( - p_rarch->current_input_data, joypad_info, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY)) { @@ -26251,6 +26384,8 @@ static void input_keys_pressed( { if (p_rarch->current_input->input_state( p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE)) @@ -26274,6 +26409,8 @@ static void input_keys_pressed( { int16_t ret = p_rarch->current_input->input_state( p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); @@ -26308,7 +26445,10 @@ static void input_keys_pressed( { bool bit_pressed = binds[port][i].valid && p_rarch->current_input->input_state( - p_rarch->current_input_data, joypad_info, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, i); if ( bit_pressed || BIT64_GET(lifecycle_state, i) @@ -26326,13 +26466,41 @@ void *input_driver_get_data(void) return p_rarch->current_input_data; } +void input_driver_init_joypads(void) +{ + struct rarch_state *p_rarch = &rarch_st; + settings_t *settings = p_rarch->configuration_settings; + p_rarch->joypad = input_joypad_init_driver( + settings->arrays.input_joypad_driver, + p_rarch->current_input_data); +#ifdef HAVE_MFI + p_rarch->sec_joypad = input_joypad_init_driver( + "mfi", + p_rarch->current_input_data); +#endif +} + +void *input_driver_init_wrap(input_driver_t *input, const char *name) +{ + struct rarch_state *p_rarch = &rarch_st; + void *ret = NULL; + if (!input) + return NULL; + if ((ret = input->init(name))) + { + input_driver_init_joypads(); + return ret; + } + return NULL; +} + static bool input_driver_init(struct rarch_state *p_rarch) { if (p_rarch->current_input) { settings_t *settings = p_rarch->configuration_settings; - p_rarch->current_input_data = p_rarch->current_input->init( - settings->arrays.input_joypad_driver); + p_rarch->current_input_data = input_driver_init_wrap( + p_rarch->current_input, settings->arrays.input_joypad_driver); } return (p_rarch->current_input_data != NULL); @@ -26885,6 +27053,13 @@ static bool input_mouse_button_raw( { rarch_joypad_info_t joypad_info; settings_t *settings = p_rarch->configuration_settings; +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif /*ignore axes*/ if (id == RETRO_DEVICE_ID_MOUSE_X || id == RETRO_DEVICE_ID_MOUSE_Y) @@ -26896,8 +27071,14 @@ static bool input_mouse_button_raw( if ( p_rarch->current_input && p_rarch->current_input->input_state) - return p_rarch->current_input->input_state(p_rarch->current_input_data, - &joypad_info, p_rarch->libretro_input_binds, port, RETRO_DEVICE_MOUSE, 0, id); + return p_rarch->current_input->input_state( + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, + p_rarch->libretro_input_binds, + port, + RETRO_DEVICE_MOUSE, 0, id); return false; } #endif @@ -31343,6 +31524,7 @@ static void video_driver_init_input(input_driver_t *tmp) RARCH_ERR("[Video]: Cannot initialize input driver. Exiting ...\n"); retroarch_fail(1, "video_driver_init_input()"); } + } /** @@ -31433,7 +31615,17 @@ static void video_driver_free_internal(void) if (p_rarch->current_input) { if (p_rarch->current_input->free) + { p_rarch->current_input->free(p_rarch->current_input_data); + if (p_rarch->joypad) + p_rarch->joypad->destroy(); +#ifdef HAVE_MFI + if (p_rarch->sec_joypad) + p_rarch->sec_joypad->destroy(); + p_rarch->sec_joypad = NULL; +#endif + p_rarch->joypad = NULL; + } p_rarch->current_input->keyboard_mapping_blocked = false; } p_rarch->current_input_data = NULL; @@ -38608,6 +38800,13 @@ static enum runloop_state runloop_check_state( #else bool menu_input_active = false; #endif +#ifdef HAVE_MFI + const input_device_driver_t + *sec_joypad = p_rarch->sec_joypad; +#else + const input_device_driver_t + *sec_joypad = NULL; +#endif joypad_info.joy_idx = settings->uints.input_joypad_map[port]; joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx]; @@ -38708,6 +38907,8 @@ static enum runloop_state runloop_check_state( { if (p_rarch->current_input->input_state( p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, &joypad_info, &binds, port, RETRO_DEVICE_KEYBOARD, 0, ids[i][0])) BIT256_SET_PTR(¤t_bits, ids[i][1]); diff --git a/retroarch.h b/retroarch.h index af4860e815..124e94baad 100644 --- a/retroarch.h +++ b/retroarch.h @@ -1983,6 +1983,13 @@ bool is_input_keyboard_display_on(void); bool input_key_pressed(const void *data, int key, bool keyboard_pressed); +const char *joypad_driver_name(unsigned i); +void joypad_driver_reinit(void *data, const char *joypad_driver_name); + +void input_driver_init_joypads(void); + +void *input_driver_init_wrap(input_driver_t *input, const char *name); + /* creates folder and core options stub file for subsequent runs */ bool create_folder_and_core_options(void); From 219793a1db4a71be582cac6b39ac890c99ee2052 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 05:50:07 +0200 Subject: [PATCH 02/30] (GX) Cleanups --- input/drivers/gx_input.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 8e2eeb22b5..e82d4f8db7 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -50,6 +50,8 @@ typedef struct gx_input #ifdef HW_RVL int mouse_max; gx_input_mouse_t *mouse; +#else + void *empty; #endif } gx_input_t; @@ -129,8 +131,10 @@ static int16_t gx_mouse_state(gx_input_t *gx, unsigned id, uint16_t joy_idx) case RETRO_DEVICE_ID_MOUSE_RIGHT: return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_MOUSE_RIGHT); default: - return 0; + break; } + + return 0; } #endif @@ -235,9 +239,7 @@ static void gx_input_poll_mouse(gx_input_t *gx) unsigned i; if (count != gx->mouse_max) { - gx_input_mouse_t* tmp = NULL; - - tmp = (gx_input_mouse_t*)realloc( + gx_input_mouse_t *tmp = (gx_input_mouse_t*)realloc( gx->mouse, count * sizeof(gx_input_mouse_t)); if (!tmp) free(gx->mouse); From adf1322cbb0a7fdeee7b857ac94ab119c1769075 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 06:53:16 +0200 Subject: [PATCH 03/30] (DInput joypad) Cut down on code duplication --- input/drivers_joypad/dinput_hybrid_joypad.c | 150 +---------------- input/drivers_joypad/dinput_joypad.c | 150 +---------------- input/drivers_joypad/dinput_joypad_excl.h | 178 ++++++++++++++++++++ input/drivers_joypad/dinput_joypad_inl.h | 99 +++++------ 4 files changed, 230 insertions(+), 347 deletions(-) create mode 100644 input/drivers_joypad/dinput_joypad_excl.h diff --git a/input/drivers_joypad/dinput_hybrid_joypad.c b/input/drivers_joypad/dinput_hybrid_joypad.c index d65d905ab8..ec75bd430c 100644 --- a/input/drivers_joypad/dinput_hybrid_joypad.c +++ b/input/drivers_joypad/dinput_hybrid_joypad.c @@ -44,155 +44,7 @@ struct dinput_joypad_data g_pads[MAX_USERS]; unsigned g_joypad_cnt; #include "dinput_joypad_inl.h" - -static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) -{ - LPDIRECTINPUTDEVICE8 *pad = NULL; - if (g_joypad_cnt == MAX_USERS) - return DIENUM_STOP; - - pad = &g_pads[g_joypad_cnt].joypad; - -#ifdef __cplusplus - if (FAILED(IDirectInput8_CreateDevice( - g_dinput_ctx, inst->guidInstance, pad, NULL))) -#else - if (FAILED(IDirectInput8_CreateDevice( - g_dinput_ctx, &inst->guidInstance, pad, NULL))) -#endif - return DIENUM_CONTINUE; - - g_pads[g_joypad_cnt].joy_name = - strdup((const char*)inst->tszProductName); - g_pads[g_joypad_cnt].joy_friendly_name = - strdup((const char*)inst->tszInstanceName); - - /* there may be more useful info in the GUID, - * so leave this here for a while */ -#if 0 - printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", - inst->guidProduct.Data1, - inst->guidProduct.Data2, - inst->guidProduct.Data3, - inst->guidProduct.Data4[0], - inst->guidProduct.Data4[1], - inst->guidProduct.Data4[2], - inst->guidProduct.Data4[3], - inst->guidProduct.Data4[4], - inst->guidProduct.Data4[5], - inst->guidProduct.Data4[6], - inst->guidProduct.Data4[7]); -#endif - - g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1 % 0x10000; - g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1 / 0x10000; - - /* Set data format to simple joystick */ - IDirectInputDevice8_SetDataFormat(*pad, &c_dfDIJoystick2); - IDirectInputDevice8_SetCooperativeLevel(*pad, - (HWND)video_driver_window_get(), - DISCL_EXCLUSIVE | DISCL_BACKGROUND); - - IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, - *pad, DIDFT_ABSAXIS); - - dinput_create_rumble_effects(&g_pads[g_joypad_cnt]); - - input_autoconfigure_connect( - g_pads[g_joypad_cnt].joy_name, - g_pads[g_joypad_cnt].joy_friendly_name, - dinput_joypad.ident, - g_joypad_cnt, - g_pads[g_joypad_cnt].vid, - g_pads[g_joypad_cnt].pid); - - g_joypad_cnt++; - return DIENUM_CONTINUE; -} - -static bool dinput_joypad_init(void *data) -{ - unsigned i; - - if (!dinput_init_context()) - return false; - - for (i = 0; i < MAX_USERS; ++i) - { - g_pads[i].joy_name = NULL; - g_pads[i].joy_friendly_name = NULL; - } - - IDirectInput8_EnumDevices(g_dinput_ctx, DI8DEVCLASS_GAMECTRL, - enum_joypad_cb, NULL, DIEDFL_ATTACHEDONLY); - return true; -} - -static void dinput_joypad_poll(void) -{ - unsigned i; - for (i = 0; i < MAX_USERS; i++) - { - unsigned j; - HRESULT ret; - struct dinput_joypad_data *pad = &g_pads[i]; - if (!pad || !pad->joypad) - continue; - - pad->joy_state.lX = 0; - pad->joy_state.lY = 0; - pad->joy_state.lRx = 0; - pad->joy_state.lRy = 0; - pad->joy_state.lRz = 0; - pad->joy_state.rglSlider[0] = 0; - pad->joy_state.rglSlider[1] = 0; - pad->joy_state.rgdwPOV[0] = 0; - pad->joy_state.rgdwPOV[1] = 0; - pad->joy_state.rgdwPOV[2] = 0; - pad->joy_state.rgdwPOV[3] = 0; - for (j = 0; j < 128; j++) - pad->joy_state.rgbButtons[j] = 0; - - pad->joy_state.lVX = 0; - pad->joy_state.lVY = 0; - pad->joy_state.lVZ = 0; - pad->joy_state.lVRx = 0; - pad->joy_state.lVRy = 0; - pad->joy_state.lVRz = 0; - pad->joy_state.rglVSlider[0] = 0; - pad->joy_state.rglVSlider[1] = 0; - pad->joy_state.lAX = 0; - pad->joy_state.lAY = 0; - pad->joy_state.lAZ = 0; - pad->joy_state.lARx = 0; - pad->joy_state.lARy = 0; - pad->joy_state.lARz = 0; - pad->joy_state.rglASlider[0] = 0; - pad->joy_state.rglASlider[1] = 0; - pad->joy_state.lFX = 0; - pad->joy_state.lFY = 0; - pad->joy_state.lFZ = 0; - pad->joy_state.lFRx = 0; - pad->joy_state.lFRy = 0; - pad->joy_state.lFRz = 0; - pad->joy_state.rglFSlider[0] = 0; - pad->joy_state.rglFSlider[1] = 0; - - /* If this fails, something *really* bad must have happened. */ - if (FAILED(IDirectInputDevice8_Poll(pad->joypad))) - if ( - FAILED(IDirectInputDevice8_Acquire(pad->joypad)) - || FAILED(IDirectInputDevice8_Poll(pad->joypad)) - ) - continue; - - ret = IDirectInputDevice8_GetDeviceState(pad->joypad, - sizeof(DIJOYSTATE2), &pad->joy_state); - - if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) - input_autoconfigure_disconnect(i, g_pads[i].joy_friendly_name); - } -} +#include "dinput_joypad_excl.h" input_device_driver_t dinput_joypad = { dinput_joypad_init, diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 6ded6e6644..0b8cbcc142 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -44,155 +44,7 @@ unsigned g_joypad_cnt; extern LPDIRECTINPUT8 g_dinput_ctx; #include "dinput_joypad_inl.h" - -static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) -{ - LPDIRECTINPUTDEVICE8 *pad = NULL; - if (g_joypad_cnt == MAX_USERS) - return DIENUM_STOP; - - pad = &g_pads[g_joypad_cnt].joypad; - -#ifdef __cplusplus - if (FAILED(IDirectInput8_CreateDevice( - g_dinput_ctx, inst->guidInstance, pad, NULL))) -#else - if (FAILED(IDirectInput8_CreateDevice( - g_dinput_ctx, &inst->guidInstance, pad, NULL))) -#endif - return DIENUM_CONTINUE; - - g_pads[g_joypad_cnt].joy_name = - strdup((const char*)inst->tszProductName); - g_pads[g_joypad_cnt].joy_friendly_name = - strdup((const char*)inst->tszInstanceName); - - /* there may be more useful info in the GUID, - * so leave this here for a while */ -#if 0 - printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", - inst->guidProduct.Data1, - inst->guidProduct.Data2, - inst->guidProduct.Data3, - inst->guidProduct.Data4[0], - inst->guidProduct.Data4[1], - inst->guidProduct.Data4[2], - inst->guidProduct.Data4[3], - inst->guidProduct.Data4[4], - inst->guidProduct.Data4[5], - inst->guidProduct.Data4[6], - inst->guidProduct.Data4[7]); -#endif - - g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1 % 0x10000; - g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1 / 0x10000; - - /* Set data format to simple joystick */ - IDirectInputDevice8_SetDataFormat(*pad, &c_dfDIJoystick2); - IDirectInputDevice8_SetCooperativeLevel(*pad, - (HWND)video_driver_window_get(), - DISCL_EXCLUSIVE | DISCL_BACKGROUND); - - IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, - *pad, DIDFT_ABSAXIS); - - dinput_create_rumble_effects(&g_pads[g_joypad_cnt]); - - input_autoconfigure_connect( - g_pads[g_joypad_cnt].joy_name, - g_pads[g_joypad_cnt].joy_friendly_name, - dinput_joypad.ident, - g_joypad_cnt, - g_pads[g_joypad_cnt].vid, - g_pads[g_joypad_cnt].pid); - - g_joypad_cnt++; - return DIENUM_CONTINUE; -} - -static bool dinput_joypad_init(void *data) -{ - unsigned i; - - if (!dinput_init_context()) - return false; - - for (i = 0; i < MAX_USERS; ++i) - { - g_pads[i].joy_name = NULL; - g_pads[i].joy_friendly_name = NULL; - } - - IDirectInput8_EnumDevices(g_dinput_ctx, DI8DEVCLASS_GAMECTRL, - enum_joypad_cb, NULL, DIEDFL_ATTACHEDONLY); - return true; -} - -static void dinput_joypad_poll(void) -{ - unsigned i; - for (i = 0; i < MAX_USERS; i++) - { - unsigned j; - HRESULT ret; - struct dinput_joypad_data *pad = &g_pads[i]; - if (!pad || !pad->joypad) - continue; - - pad->joy_state.lX = 0; - pad->joy_state.lY = 0; - pad->joy_state.lRx = 0; - pad->joy_state.lRy = 0; - pad->joy_state.lRz = 0; - pad->joy_state.rglSlider[0] = 0; - pad->joy_state.rglSlider[1] = 0; - pad->joy_state.rgdwPOV[0] = 0; - pad->joy_state.rgdwPOV[1] = 0; - pad->joy_state.rgdwPOV[2] = 0; - pad->joy_state.rgdwPOV[3] = 0; - for (j = 0; j < 128; j++) - pad->joy_state.rgbButtons[j] = 0; - - pad->joy_state.lVX = 0; - pad->joy_state.lVY = 0; - pad->joy_state.lVZ = 0; - pad->joy_state.lVRx = 0; - pad->joy_state.lVRy = 0; - pad->joy_state.lVRz = 0; - pad->joy_state.rglVSlider[0] = 0; - pad->joy_state.rglVSlider[1] = 0; - pad->joy_state.lAX = 0; - pad->joy_state.lAY = 0; - pad->joy_state.lAZ = 0; - pad->joy_state.lARx = 0; - pad->joy_state.lARy = 0; - pad->joy_state.lARz = 0; - pad->joy_state.rglASlider[0] = 0; - pad->joy_state.rglASlider[1] = 0; - pad->joy_state.lFX = 0; - pad->joy_state.lFY = 0; - pad->joy_state.lFZ = 0; - pad->joy_state.lFRx = 0; - pad->joy_state.lFRy = 0; - pad->joy_state.lFRz = 0; - pad->joy_state.rglFSlider[0] = 0; - pad->joy_state.rglFSlider[1] = 0; - - /* If this fails, something *really* bad must have happened. */ - if (FAILED(IDirectInputDevice8_Poll(pad->joypad))) - if ( - FAILED(IDirectInputDevice8_Acquire(pad->joypad)) - || FAILED(IDirectInputDevice8_Poll(pad->joypad)) - ) - continue; - - ret = IDirectInputDevice8_GetDeviceState(pad->joypad, - sizeof(DIJOYSTATE2), &pad->joy_state); - - if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) - input_autoconfigure_disconnect(i, g_pads[i].joy_friendly_name); - } -} +#include "dinput_joypad_excl.h" input_device_driver_t dinput_joypad = { dinput_joypad_init, diff --git a/input/drivers_joypad/dinput_joypad_excl.h b/input/drivers_joypad/dinput_joypad_excl.h new file mode 100644 index 0000000000..63a9cd6d99 --- /dev/null +++ b/input/drivers_joypad/dinput_joypad_excl.h @@ -0,0 +1,178 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2016-2019 - Brad Parker + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __DINPUT_JOYPAD_EXCL_INL_H +#define __DINPUT_JOYPAD_EXCL_INL_H + +#include +#include +#include + +#include +#include +#include + +static void dinput_joypad_poll(void) +{ + unsigned i; + for (i = 0; i < MAX_USERS; i++) + { + unsigned j; + HRESULT ret; + struct dinput_joypad_data *pad = &g_pads[i]; + if (!pad || !pad->joypad) + continue; + + pad->joy_state.lX = 0; + pad->joy_state.lY = 0; + pad->joy_state.lRx = 0; + pad->joy_state.lRy = 0; + pad->joy_state.lRz = 0; + pad->joy_state.rglSlider[0] = 0; + pad->joy_state.rglSlider[1] = 0; + pad->joy_state.rgdwPOV[0] = 0; + pad->joy_state.rgdwPOV[1] = 0; + pad->joy_state.rgdwPOV[2] = 0; + pad->joy_state.rgdwPOV[3] = 0; + for (j = 0; j < 128; j++) + pad->joy_state.rgbButtons[j] = 0; + + pad->joy_state.lVX = 0; + pad->joy_state.lVY = 0; + pad->joy_state.lVZ = 0; + pad->joy_state.lVRx = 0; + pad->joy_state.lVRy = 0; + pad->joy_state.lVRz = 0; + pad->joy_state.rglVSlider[0] = 0; + pad->joy_state.rglVSlider[1] = 0; + pad->joy_state.lAX = 0; + pad->joy_state.lAY = 0; + pad->joy_state.lAZ = 0; + pad->joy_state.lARx = 0; + pad->joy_state.lARy = 0; + pad->joy_state.lARz = 0; + pad->joy_state.rglASlider[0] = 0; + pad->joy_state.rglASlider[1] = 0; + pad->joy_state.lFX = 0; + pad->joy_state.lFY = 0; + pad->joy_state.lFZ = 0; + pad->joy_state.lFRx = 0; + pad->joy_state.lFRy = 0; + pad->joy_state.lFRz = 0; + pad->joy_state.rglFSlider[0] = 0; + pad->joy_state.rglFSlider[1] = 0; + + /* If this fails, something *really* bad must have happened. */ + if (FAILED(IDirectInputDevice8_Poll(pad->joypad))) + if ( + FAILED(IDirectInputDevice8_Acquire(pad->joypad)) + || FAILED(IDirectInputDevice8_Poll(pad->joypad)) + ) + continue; + + ret = IDirectInputDevice8_GetDeviceState(pad->joypad, + sizeof(DIJOYSTATE2), &pad->joy_state); + + if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) + input_autoconfigure_disconnect(i, g_pads[i].joy_friendly_name); + } +} + +static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) +{ + LPDIRECTINPUTDEVICE8 *pad = NULL; + if (g_joypad_cnt == MAX_USERS) + return DIENUM_STOP; + + pad = &g_pads[g_joypad_cnt].joypad; + +#ifdef __cplusplus + if (FAILED(IDirectInput8_CreateDevice( + g_dinput_ctx, inst->guidInstance, pad, NULL))) +#else + if (FAILED(IDirectInput8_CreateDevice( + g_dinput_ctx, &inst->guidInstance, pad, NULL))) +#endif + return DIENUM_CONTINUE; + + g_pads[g_joypad_cnt].joy_name = + strdup((const char*)inst->tszProductName); + g_pads[g_joypad_cnt].joy_friendly_name = + strdup((const char*)inst->tszInstanceName); + + /* there may be more useful info in the GUID, + * so leave this here for a while */ +#if 0 + printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", + inst->guidProduct.Data1, + inst->guidProduct.Data2, + inst->guidProduct.Data3, + inst->guidProduct.Data4[0], + inst->guidProduct.Data4[1], + inst->guidProduct.Data4[2], + inst->guidProduct.Data4[3], + inst->guidProduct.Data4[4], + inst->guidProduct.Data4[5], + inst->guidProduct.Data4[6], + inst->guidProduct.Data4[7]); +#endif + + g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1 % 0x10000; + g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1 / 0x10000; + + /* Set data format to simple joystick */ + IDirectInputDevice8_SetDataFormat(*pad, &c_dfDIJoystick2); + IDirectInputDevice8_SetCooperativeLevel(*pad, + (HWND)video_driver_window_get(), + DISCL_EXCLUSIVE | DISCL_BACKGROUND); + + IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, + *pad, DIDFT_ABSAXIS); + + dinput_create_rumble_effects(&g_pads[g_joypad_cnt]); + + input_autoconfigure_connect( + g_pads[g_joypad_cnt].joy_name, + g_pads[g_joypad_cnt].joy_friendly_name, + dinput_joypad.ident, + g_joypad_cnt, + g_pads[g_joypad_cnt].vid, + g_pads[g_joypad_cnt].pid); + + g_joypad_cnt++; + return DIENUM_CONTINUE; +} + +static bool dinput_joypad_init(void *data) +{ + unsigned i; + + if (!dinput_init_context()) + return false; + + for (i = 0; i < MAX_USERS; ++i) + { + g_pads[i].joy_name = NULL; + g_pads[i].joy_friendly_name = NULL; + } + + IDirectInput8_EnumDevices(g_dinput_ctx, DI8DEVCLASS_GAMECTRL, + enum_joypad_cb, NULL, DIEDFL_ATTACHEDONLY); + return true; +} + +#endif diff --git a/input/drivers_joypad/dinput_joypad_inl.h b/input/drivers_joypad/dinput_joypad_inl.h index 7faeefe203..b127e0a854 100644 --- a/input/drivers_joypad/dinput_joypad_inl.h +++ b/input/drivers_joypad/dinput_joypad_inl.h @@ -35,48 +35,6 @@ extern LPDIRECTINPUT8 g_dinput_ctx; void dinput_destroy_context(void); bool dinput_init_context(void); -/* Keep track of which pad indexes are 360 controllers. - * Not static, will be read in xinput_joypad.c - * -1 = not xbox pad, otherwise 0..3 - */ -static void dinput_joypad_destroy(void) -{ - unsigned i; - - for (i = 0; i < MAX_USERS; i++) - { - if (g_pads[i].joypad) - { - if (g_pads[i].rumble_iface[0]) - { - IDirectInputEffect_Stop(g_pads[i].rumble_iface[0]); - IDirectInputEffect_Release(g_pads[i].rumble_iface[0]); - } - if (g_pads[i].rumble_iface[1]) - { - IDirectInputEffect_Stop(g_pads[i].rumble_iface[1]); - IDirectInputEffect_Release(g_pads[i].rumble_iface[1]); - } - - IDirectInputDevice8_Unacquire(g_pads[i].joypad); - IDirectInputDevice8_Release(g_pads[i].joypad); - } - - free(g_pads[i].joy_name); - g_pads[i].joy_name = NULL; - free(g_pads[i].joy_friendly_name); - g_pads[i].joy_friendly_name = NULL; - - input_config_clear_device_name(i); - } - - g_joypad_cnt = 0; - memset(g_pads, 0, sizeof(g_pads)); - - /* Can be blocked by global Dinput context. */ - dinput_destroy_context(); -} - static void dinput_create_rumble_effects(struct dinput_joypad_data *pad) { DIENVELOPE dienv; @@ -146,13 +104,6 @@ static BOOL CALLBACK enum_axes_cb( return DIENUM_CONTINUE; } -static const char *dinput_joypad_name(unsigned port) -{ - if (port < MAX_USERS) - return g_pads[port].joy_name; - return NULL; -} - static int16_t dinput_joypad_button_state( const struct dinput_joypad_data *pad, uint16_t joykey) @@ -357,4 +308,54 @@ static bool dinput_joypad_set_rumble(unsigned port, return true; } +/* Keep track of which pad indexes are 360 controllers. + * Not static, will be read in xinput_joypad.c + * -1 = not xbox pad, otherwise 0..3 + */ +static void dinput_joypad_destroy(void) +{ + unsigned i; + + for (i = 0; i < MAX_USERS; i++) + { + if (g_pads[i].joypad) + { + if (g_pads[i].rumble_iface[0]) + { + IDirectInputEffect_Stop(g_pads[i].rumble_iface[0]); + IDirectInputEffect_Release(g_pads[i].rumble_iface[0]); + } + if (g_pads[i].rumble_iface[1]) + { + IDirectInputEffect_Stop(g_pads[i].rumble_iface[1]); + IDirectInputEffect_Release(g_pads[i].rumble_iface[1]); + } + + IDirectInputDevice8_Unacquire(g_pads[i].joypad); + IDirectInputDevice8_Release(g_pads[i].joypad); + } + + free(g_pads[i].joy_name); + g_pads[i].joy_name = NULL; + free(g_pads[i].joy_friendly_name); + g_pads[i].joy_friendly_name = NULL; + + input_config_clear_device_name(i); + } + + g_joypad_cnt = 0; + memset(g_pads, 0, sizeof(g_pads)); + + /* Can be blocked by global Dinput context. */ + dinput_destroy_context(); +} + +static const char *dinput_joypad_name(unsigned port) +{ + if (port < MAX_USERS) + return g_pads[port].joy_name; + return NULL; +} + + #endif From 56b077cf4aee33dcc091667eb0ee76a9083800ce Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 14:36:39 +0200 Subject: [PATCH 04/30] (Vita driver) Cleanups --- input/drivers/psp_input.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 8e3cacbc50..a289d6cb01 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -50,8 +50,14 @@ #include "../../defines/psp_defines.h" #include "../input_driver.h" + +/* TODO/FIXME - + * fix game focus toggle */ + #ifdef VITA + #include "../input_keymaps.h" + uint8_t modifier_lut[VITA_NUM_MODIFIERS][2] = { { 0xE0, 0x01 }, /* LCTRL */ @@ -66,14 +72,9 @@ uint8_t modifier_lut[VITA_NUM_MODIFIERS][2] = { 0x39, 0x02 }, /* CAPSLOCK */ { 0x47, 0x04 } /* SCROLLOCK */ }; -#endif - -/* TODO/FIXME - - * fix game focus toggle */ typedef struct psp_input { -#ifdef VITA int keyboard_hid_handle; int mouse_hid_handle; int32_t mouse_x; @@ -86,10 +87,8 @@ typedef struct psp_input bool mouse_button_right; bool mouse_button_middle; bool sensors_enabled; -#endif } psp_input_t; -#ifdef VITA static void vita_input_poll(void *data) { psp_input_t *psp = (psp_input_t*)data; @@ -265,6 +264,11 @@ static int16_t psp_input_mouse_state( return val; } +#else +typedef struct psp_input +{ + void *empty; +} psp_input_t; #endif static int16_t psp_input_state( @@ -346,8 +350,6 @@ static void* psp_input_initialize(const char *joypad_driver) static uint64_t psp_input_get_capabilities(void *data) { - (void)data; - uint64_t caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); #ifdef VITA @@ -377,7 +379,7 @@ static bool psp_input_set_sensor_state(void *data, unsigned port, { psp_input_t *psp = (psp_input_t*)data; - if(!psp) + if (!psp) return false; switch (action) From d801dab8b42a197429318cb4620306fb16117453 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 14:41:45 +0200 Subject: [PATCH 05/30] Cleanups --- input/drivers/rwebinput_input.c | 2 +- input/drivers/sdl_input.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index 83a3b2784c..b146a2c472 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -302,7 +302,7 @@ static void *rwebinput_input_init(const char *joypad_driver) (rwebinput_input_t*)calloc(1, sizeof(*rwebinput)); if (!rwebinput) - goto error; + return NULL; rwebinput_generate_lut(); diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 1819b798ec..dc5a7f9654 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -36,9 +36,19 @@ typedef struct sdl_input { - int mouse_x, mouse_y; - int mouse_abs_x, mouse_abs_y; - int mouse_l, mouse_r, mouse_m, mouse_b4, mouse_b5, mouse_wu, mouse_wd, mouse_wl, mouse_wr; + int mouse_x; + int mouse_y; + int mouse_abs_x; + int mouse_abs_y; + int mouse_l; + int mouse_r; + int mouse_m; + int mouse_b4; + int mouse_b5; + int mouse_wu; + int mouse_wd; + int mouse_wl; + int mouse_wr; } sdl_input_t; static void *sdl_input_init(const char *joypad_driver) @@ -69,7 +79,8 @@ static bool sdl_key_pressed(int key) return keymap[sym]; } -static int16_t sdl_analog_pressed(sdl_input_t *sdl, const struct retro_keybind *binds, +static int16_t sdl_analog_pressed(sdl_input_t *sdl, + const struct retro_keybind *binds, unsigned idx, unsigned id) { int16_t pressed_minus = 0, pressed_plus = 0; From 1a567dfbc988d3873a43c1c49679233b08c7968a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 15:43:12 +0200 Subject: [PATCH 06/30] Cleanup dinput_pressed_analog --- input/drivers/dinput.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 383beb8f2f..18f639c8df 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -326,32 +326,38 @@ static int16_t dinput_pressed_analog(struct dinput_input *di, const struct retro_keybind *binds, unsigned idx, unsigned id) { - const struct retro_keybind *bind_minus, *bind_plus; - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0, id_plus = 0; + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - bind_minus = &binds[id_minus]; - bind_plus = &binds[id_plus]; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - if (!bind_minus->valid || !bind_plus->valid) + if (!id_minus_valid || !id_plus_valid) return 0; - if (bind_minus->key < RETROK_LAST) + if (id_plus_key < RETROK_LAST) { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; if (di->state[sym] & 0x80) - pressed_minus = -0x7fff; + ret = 0x7fff; } - if (bind_plus->key < RETROK_LAST) + if (id_minus_key < RETROK_LAST) { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_plus->key]; + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; if (di->state[sym] & 0x80) - pressed_plus = 0x7fff; + ret += -0x7fff; } - return pressed_plus + pressed_minus; + return ret; } static int16_t dinput_lightgun_aiming_state( From 262e68be3b0d43459fb1260310525191bc1e0ced Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 15:52:58 +0200 Subject: [PATCH 07/30] Standardize x_pressed_analog --- input/drivers/dinput.c | 2 +- input/drivers/x11_input.c | 43 +++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 18f639c8df..acd7db6327 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -344,7 +344,7 @@ static int16_t dinput_pressed_analog(struct dinput_input *di, if (!id_minus_valid || !id_plus_valid) return 0; - if (id_plus_key < RETROK_LAST) + 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) diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 199b305803..c2593f1dfe 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -39,7 +39,7 @@ typedef struct x11_input int mouse_x, mouse_y; int mouse_last_x, mouse_last_y; - char state[32]; + uint8_t state[32]; bool mouse_l, mouse_r, mouse_m; bool grab_mouse; } x11_input_t; @@ -105,32 +105,41 @@ static bool x_mouse_button_pressed( static int16_t x_pressed_analog(x11_input_t *x11, const struct retro_keybind *binds, unsigned idx, unsigned id) { - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; int id_minus_key = 0; int id_plus_key = 0; - unsigned keycode = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t pressed_minus = 0; + int16_t pressed_plus = 0; + int16_t ret = 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[id_minus].valid; + id_plus_valid = binds[id_plus].valid; id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - keycode = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if ( binds[id_minus].valid - && (id_minus_key < RETROK_LAST) - && (x11->state[keycode >> 3] & (1 << (keycode & 7)))) - pressed_minus = -0x7fff; + if (!id_minus_valid || !id_plus_valid) + return 0; - keycode = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if ( binds[id_plus].valid - && (id_plus_key < RETROK_LAST) - && (x11->state[keycode >> 3] & (1 << (keycode & 7)))) - pressed_plus = 0x7fff; + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; + if (x11->state[sym >> 3] & (1 << (sym & 7))) + ret = 0x7fff; + } - return pressed_plus + pressed_minus; + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (x11->state[sym >> 3] & (1 << (sym & 7))) + ret += -0x7fff; + } + + return ret; } static int16_t x_lightgun_aiming_state( From 97319d4f9872e3083fda2575f7778ce0cef9e37b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 16:19:11 +0200 Subject: [PATCH 08/30] Standardize pressed_analog functions --- input/drivers/dinput.c | 5 ++-- input/drivers/linuxraw_input.c | 33 +++++++++++++++----------- input/drivers/rwebinput_input.c | 40 ++++++++++++++++++++----------- input/drivers/sdl_input.c | 39 +++++++++++++++++++++++------- input/drivers/udev_input.c | 40 +++++++++++++++++++++---------- input/drivers/uwp_input.c | 37 ++++++++++++++++++----------- input/drivers/wayland_input.c | 42 ++++++++++++++++++++------------- 7 files changed, 155 insertions(+), 81 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index acd7db6327..2e2c1d00bd 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -322,7 +322,8 @@ static bool dinput_mouse_button_pressed( return false; } -static int16_t dinput_pressed_analog(struct dinput_input *di, +static int16_t dinput_pressed_analog( + struct dinput_input *di, const struct retro_keybind *binds, unsigned idx, unsigned id) { @@ -350,7 +351,7 @@ static int16_t dinput_pressed_analog(struct dinput_input *di, if (di->state[sym] & 0x80) ret = 0x7fff; } - if (id_minus_key < RETROK_LAST) + 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) diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 3cc1b1d8f8..ad123badf9 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -75,33 +75,38 @@ static void *linuxraw_input_init(const char *joypad_driver) static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, const struct retro_keybind *binds, unsigned idx, unsigned id) { - const struct retro_keybind *bind_minus, *bind_plus; - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - bind_minus = &binds[id_minus]; - bind_plus = &binds[id_plus]; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - if (!bind_minus->valid || !bind_plus->valid) + if (!id_minus_valid || !id_plus_valid) return 0; - if (bind_minus->key < RETROK_LAST) + if (id_plus_valid && id_plus_key < RETROK_LAST) { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; if (linuxraw->state[sym] & 0x80) - pressed_minus = -0x7fff; + ret = 0x7fff; } - if (bind_plus->key < RETROK_LAST) + if (id_minus_valid && id_minus_key < RETROK_LAST) { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; if (linuxraw->state[sym] & 0x80) - pressed_plus = 0x7fff; + ret += -0x7fff; } - return pressed_plus + pressed_minus; + return ret; } static int16_t linuxraw_input_state( diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index b146a2c472..deb62429b3 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -503,26 +503,38 @@ static int16_t rwebinput_analog_pressed( const struct retro_keybind *binds, unsigned idx, unsigned id) { - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - if (id < RARCH_BIND_LIST_END) + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; + + if (!id_minus_valid || !id_plus_valid) + return 0; + + if (id_plus_valid && id_plus_key < RETROK_LAST) { - if (binds[id].valid) - { - if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds, idx, id_minus)) - pressed_minus = -0x7fff; - if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds, idx, id_plus)) - pressed_plus = 0x7fff; - } + if (rwebinput_is_pressed(rwebinput, + joypad, joypad_info, binds, idx, id_plus)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + if (rwebinput_is_pressed(rwebinput, + joypad, joypad_info, binds, idx, id_minus)) + ret += -0x7fff; } - return pressed_plus + pressed_minus; + return ret; } static int16_t rwebinput_input_state( diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index dc5a7f9654..798c7b4a7e 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -79,22 +79,43 @@ static bool sdl_key_pressed(int key) return keymap[sym]; } -static int16_t sdl_analog_pressed(sdl_input_t *sdl, +static int16_t sdl_analog_pressed( + sdl_input_t *sdl, const struct retro_keybind *binds, unsigned idx, unsigned id) { - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - if ((binds[id_minus].key < RETROK_LAST) && sdl_key_pressed(binds[id_minus].key)) - pressed_minus = -0x7fff; - if ((binds[id_plus].key < RETROK_LAST) && sdl_key_pressed(binds[id_plus].key)) - pressed_plus = 0x7fff; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - return pressed_plus + pressed_minus; + if (!id_minus_valid || !id_plus_valid) + return 0; + + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; + if (sdl_key_pressed(sym)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (sdl_key_pressed(sym)) + ret += -0x7fff; + } + + return ret; } static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 8f9638ea2d..f64f99e86f 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -932,27 +932,43 @@ static bool udev_mouse_button_pressed( return false; } -static int16_t udev_analog_pressed(udev_input_t *udev, +static int16_t udev_analog_pressed( + udev_input_t *udev, const struct retro_keybind *binds, unsigned idx, unsigned id) { + int id_minus_key = 0; + int id_plus_key = 0; unsigned id_minus = 0; unsigned id_plus = 0; - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - if ( binds[id_minus].valid - && BIT_GET(udev->state, - rarch_keysym_lut[binds[id_minus].key])) - pressed_minus = -0x7fff; - if ( binds[id_plus].valid - && BIT_GET(udev->state, - rarch_keysym_lut[binds[id_plus].key])) - pressed_plus = 0x7fff; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - return pressed_plus + pressed_minus; + if (!id_minus_valid || !id_plus_valid) + return 0; + + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; + if BIT_GET(udev->state, sym) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (BIT_GET(udev->state, sym)) + ret += -0x7fff; + } + + return ret; } static int16_t udev_pointer_state(udev_input_t *udev, diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index 824e79289d..adc58e3a71 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -89,27 +89,36 @@ static int16_t uwp_pressed_analog(uwp_input_t *uwp, const struct retro_keybind *binds, unsigned port, unsigned idx, unsigned id) { - const struct retro_keybind *bind_minus, *bind_plus; - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0, id_plus = 0; + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; - /* First, process the keyboard bindings */ input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - bind_minus = &binds[id_minus]; - bind_plus = &binds[id_plus]; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - if (!bind_minus->valid || !bind_plus->valid) + if (!id_minus_valid || !id_plus_valid) return 0; - if ((bind_minus->key < RETROK_LAST) - && uwp_keyboard_pressed(bind_minus->key)) - pressed_minus = -0x7fff; - if ((bind_plus->key < RETROK_LAST) - && uwp_keyboard_pressed(bind_plus->key)) - pressed_plus = 0x7fff; + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + if (uwp_keyboard_pressed(bind_plus_key)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + if (uwp_keyboard_pressed(bind_minus_key)) + ret += -0x7fff; + } - return pressed_plus + pressed_minus; + return ret; } static int16_t uwp_input_state( diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 399dd51ace..b1cf29b4d3 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -154,31 +154,41 @@ static void input_wl_poll(void *data) input_wl_touch_pool(wl); } -static int16_t input_wl_analog_pressed(input_ctx_wayland_data_t *wl, +static int16_t input_wl_analog_pressed( + input_ctx_wayland_data_t *wl, const struct retro_keybind *binds, unsigned idx, unsigned id) { + int id_minus_key = 0; + int id_plus_key = 0; unsigned id_minus = 0; unsigned id_plus = 0; - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; + int16_t ret = 0; + bool id_plus_valid = false; + bool id_minus_valid = false; input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - if (binds - && binds[id_minus].valid - && (id_minus < RARCH_BIND_LIST_END) - && BIT_GET(wl->key_state, rarch_keysym_lut[binds[id_minus].key]) - ) - pressed_minus = -0x7fff; - if (binds - && binds[id_plus].valid - && (id_plus < RARCH_BIND_LIST_END) - && BIT_GET(wl->key_state, rarch_keysym_lut[binds[id_plus].key]) - ) - pressed_plus = 0x7fff; + id_minus_valid = binds[id_minus].valid; + id_plus_valid = binds[id_plus].valid; + id_minus_key = binds[id_minus].key; + id_plus_key = binds[id_plus].key; - return pressed_plus + pressed_minus; + if (!id_minus_valid || !id_plus_valid) + return 0; + + if (id_plus_valid && id_plus_key < RETROK_LAST) + { + if (BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id_plus_key])) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + if (BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id_minus_key])) + ret += -0x7fff; + } + + return ret; } static bool input_wl_state_kb(input_ctx_wayland_data_t *wl, From e119d3c98ef80bd20cfdcb1ee61c8cfc0dc35741 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 16:38:53 +0200 Subject: [PATCH 09/30] Further cleanups/standardizations to analog_pressed --- input/drivers/dinput.c | 3 --- input/drivers/linuxraw_input.c | 7 ++----- input/drivers/rwebinput_input.c | 22 +++++++--------------- input/drivers/sdl_input.c | 7 ++----- input/drivers/udev_input.c | 7 ++----- input/drivers/uwp_input.c | 3 --- input/drivers/wayland_input.c | 13 ++++++------- input/drivers/x11_input.c | 4 ---- 8 files changed, 19 insertions(+), 47 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 2e2c1d00bd..5bbf2e0d7a 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -342,9 +342,6 @@ static int16_t dinput_pressed_analog( id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index ad123badf9..1e4d22e454 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -72,7 +72,7 @@ static void *linuxraw_input_init(const char *joypad_driver) return linuxraw; } -static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, +static int16_t linuxraw_pressed_analog(linuxraw_input_t *linuxraw, const struct retro_keybind *binds, unsigned idx, unsigned id) { int id_minus_key = 0; @@ -90,9 +90,6 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; @@ -164,7 +161,7 @@ static int16_t linuxraw_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return linuxraw_analog_pressed( + return linuxraw_pressed_analog( linuxraw, binds[port], idx, id); break; } diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index deb62429b3..f99bf64f59 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -262,23 +262,19 @@ static EM_BOOL rwebinput_keyboard_cb(int event_type, static EM_BOOL rwebinput_mouse_cb(int event_type, const EmscriptenMouseEvent *mouse_event, void *user_data) { - rwebinput_input_t *rwebinput = (rwebinput_input_t*)user_data; + rwebinput_input_t *rwebinput = (rwebinput_input_t*)user_data; - uint8_t mask = 1 << mouse_event->button; + uint8_t mask = 1 << mouse_event->button; - rwebinput->mouse.x = mouse_event->targetX; - rwebinput->mouse.y = mouse_event->targetY; + rwebinput->mouse.x = mouse_event->targetX; + rwebinput->mouse.y = mouse_event->targetY; rwebinput->mouse.pending_delta_x += mouse_event->movementX; rwebinput->mouse.pending_delta_y += mouse_event->movementY; if (event_type == EMSCRIPTEN_EVENT_MOUSEDOWN) - { rwebinput->mouse.buttons |= mask; - } else if (event_type == EMSCRIPTEN_EVENT_MOUSEUP) - { rwebinput->mouse.buttons &= ~mask; - } return EM_TRUE; } @@ -286,8 +282,7 @@ static EM_BOOL rwebinput_mouse_cb(int event_type, static EM_BOOL rwebinput_wheel_cb(int event_type, const EmscriptenWheelEvent *wheel_event, void *user_data) { - rwebinput_input_t *rwebinput = (rwebinput_input_t*)user_data; - (void)event_type; + rwebinput_input_t *rwebinput = (rwebinput_input_t*)user_data; rwebinput->mouse.pending_scroll_x += wheel_event->deltaX; rwebinput->mouse.pending_scroll_y += wheel_event->deltaY; @@ -496,7 +491,7 @@ static int16_t rwebinput_is_pressed( return 0; } -static int16_t rwebinput_analog_pressed( +static int16_t rwebinput_pressed_analog( rwebinput_input_t *rwebinput, const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, @@ -518,9 +513,6 @@ static int16_t rwebinput_analog_pressed( id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { if (rwebinput_is_pressed(rwebinput, @@ -583,7 +575,7 @@ static int16_t rwebinput_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return rwebinput_analog_pressed( + return rwebinput_pressed_analog( rwebinput, joypad, joypad_info, binds[port], idx, id); break; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 798c7b4a7e..4562066f1b 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -79,7 +79,7 @@ static bool sdl_key_pressed(int key) return keymap[sym]; } -static int16_t sdl_analog_pressed( +static int16_t sdl_pressed_analog( sdl_input_t *sdl, const struct retro_keybind *binds, unsigned idx, unsigned id) @@ -99,9 +99,6 @@ static int16_t sdl_analog_pressed( id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; @@ -262,7 +259,7 @@ static int16_t sdl_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return sdl_analog_pressed(sdl, binds[port], idx, id); + return sdl_pressed_analog(sdl, binds[port], idx, id); break; case RETRO_DEVICE_MOUSE: if (config_get_ptr()->uints.input_mouse_index[ port ] == 0) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index f64f99e86f..b85aa294a2 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -932,7 +932,7 @@ static bool udev_mouse_button_pressed( return false; } -static int16_t udev_analog_pressed( +static int16_t udev_pressed_analog( udev_input_t *udev, const struct retro_keybind *binds, unsigned idx, unsigned id) @@ -952,9 +952,6 @@ static int16_t udev_analog_pressed( id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; @@ -1085,7 +1082,7 @@ static int16_t udev_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return udev_analog_pressed(udev, binds[port], idx, id); + return udev_pressed_analog(udev, binds[port], idx, id); break; case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && udev_keyboard_pressed(udev, id); diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index adc58e3a71..d33fee868e 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -104,9 +104,6 @@ static int16_t uwp_pressed_analog(uwp_input_t *uwp, id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { if (uwp_keyboard_pressed(bind_plus_key)) diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index b1cf29b4d3..06bff9d3c0 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -154,7 +154,7 @@ static void input_wl_poll(void *data) input_wl_touch_pool(wl); } -static int16_t input_wl_analog_pressed( +static int16_t input_wl_pressed_analog( input_ctx_wayland_data_t *wl, const struct retro_keybind *binds, unsigned idx, unsigned id) @@ -174,17 +174,16 @@ static int16_t input_wl_analog_pressed( id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { - if (BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id_plus_key])) + unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; + if (BIT_GET(wl->key_state, sym)) ret = 0x7fff; } if (id_minus_valid && id_minus_key < RETROK_LAST) { - if (BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id_minus_key])) + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (BIT_GET(wl->key_state, sym)) ret += -0x7fff; } @@ -352,7 +351,7 @@ static int16_t input_wl_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return input_wl_analog_pressed(wl, binds[port], idx, id); + return input_wl_pressed_analog(wl, binds[port], idx, id); break; case RETRO_DEVICE_KEYBOARD: return input_wl_state_kb(wl, binds, port, device, idx, id); diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index c2593f1dfe..a68b4f44e8 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -122,16 +122,12 @@ static int16_t x_pressed_analog(x11_input_t *x11, id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; - if (!id_minus_valid || !id_plus_valid) - return 0; - if (id_plus_valid && id_plus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; if (x11->state[sym >> 3] & (1 << (sym & 7))) ret = 0x7fff; } - if (id_minus_valid && id_minus_key < RETROK_LAST) { unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; From 035efa5136ed8625f434972ff37a9f15b88c979c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 16:57:04 +0200 Subject: [PATCH 10/30] Inline pressed_analog functions into input_state function itself --- input/drivers/dinput.c | 67 ++++++++++++++---------------- input/drivers/linuxraw_input.c | 67 ++++++++++++++---------------- input/drivers/rwebinput_input.c | 72 ++++++++++++++------------------- input/drivers/sdl_input.c | 68 ++++++++++++++----------------- input/drivers/udev_input.c | 68 ++++++++++++++----------------- input/drivers/uwp_input.c | 64 +++++++++++++---------------- input/drivers/wayland_input.c | 68 ++++++++++++++----------------- input/drivers/x11_input.c | 70 +++++++++++++++----------------- 8 files changed, 247 insertions(+), 297 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 5bbf2e0d7a..4acf930014 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -322,42 +322,6 @@ static bool dinput_mouse_button_pressed( return false; } -static int16_t dinput_pressed_analog( - struct dinput_input *di, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[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; -} - static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned idx, unsigned id) { @@ -652,7 +616,36 @@ static int16_t dinput_input_state( di->state[rarch_keysym_lut[(enum retro_key)id]] & 0x80; case RETRO_DEVICE_ANALOG: if (binds[port]) - return dinput_pressed_analog(di, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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; + } break; case RETRO_DEVICE_MOUSE: { diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 1e4d22e454..1c8955eaaf 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -72,40 +72,6 @@ static void *linuxraw_input_init(const char *joypad_driver) return linuxraw; } -static int16_t linuxraw_pressed_analog(linuxraw_input_t *linuxraw, - const struct retro_keybind *binds, unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if (linuxraw->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 (linuxraw->state[sym] & 0x80) - ret += -0x7fff; - } - - return ret; -} - static int16_t linuxraw_input_state( void *data, const input_device_driver_t *joypad, @@ -161,8 +127,37 @@ static int16_t linuxraw_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return linuxraw_pressed_analog( - linuxraw, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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 (linuxraw->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 (linuxraw->state[sym] & 0x80) + ret += -0x7fff; + } + + return ret; + } break; } diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index f99bf64f59..8aca5f76ba 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -491,44 +491,6 @@ static int16_t rwebinput_is_pressed( return 0; } -static int16_t rwebinput_pressed_analog( - rwebinput_input_t *rwebinput, - const input_device_driver_t *joypad, - rarch_joypad_info_t *joypad_info, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds, idx, id_plus)) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds, idx, id_minus)) - ret += -0x7fff; - } - - return ret; -} - static int16_t rwebinput_input_state( void *data, const input_device_driver_t *joypad, @@ -575,9 +537,37 @@ static int16_t rwebinput_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return rwebinput_pressed_analog( - rwebinput, joypad, joypad_info, binds[port], - idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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) + { + if (rwebinput_is_pressed(rwebinput, + joypad, joypad_info, binds[port], idx, id_plus)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + if (rwebinput_is_pressed(rwebinput, + joypad, joypad_info, binds[port], idx, id_minus)) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_KEYBOARD: return rwebinput_key_pressed(rwebinput, id); diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 4562066f1b..7f9c59fe06 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -79,42 +79,6 @@ static bool sdl_key_pressed(int key) return keymap[sym]; } -static int16_t sdl_pressed_analog( - sdl_input_t *sdl, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if (sdl_key_pressed(sym)) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if (sdl_key_pressed(sym)) - ret += -0x7fff; - } - - return ret; -} - static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id) { switch (id) @@ -259,7 +223,37 @@ static int16_t sdl_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return sdl_pressed_analog(sdl, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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 (sdl_key_pressed(sym)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (sdl_key_pressed(sym)) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_MOUSE: if (config_get_ptr()->uints.input_mouse_index[ port ] == 0) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index b85aa294a2..27b61439bc 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -932,42 +932,6 @@ static bool udev_mouse_button_pressed( return false; } -static int16_t udev_pressed_analog( - udev_input_t *udev, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if BIT_GET(udev->state, sym) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if (BIT_GET(udev->state, sym)) - ret += -0x7fff; - } - - return ret; -} - static int16_t udev_pointer_state(udev_input_t *udev, unsigned port, unsigned id, bool screen) { @@ -1082,7 +1046,37 @@ static int16_t udev_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return udev_pressed_analog(udev, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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 BIT_GET(udev->state, sym) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (BIT_GET(udev->state, sym)) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && udev_keyboard_pressed(udev, id); diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index d33fee868e..f16230eb2a 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -84,40 +84,6 @@ static bool uwp_input_set_rumble( return false; } -static int16_t uwp_pressed_analog(uwp_input_t *uwp, - rarch_joypad_info_t *joypad_info, - const struct retro_keybind *binds, - unsigned port, unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - if (uwp_keyboard_pressed(bind_plus_key)) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - if (uwp_keyboard_pressed(bind_minus_key)) - ret += -0x7fff; - } - - return ret; -} - static int16_t uwp_input_state( void *data, const input_device_driver_t *joypad, @@ -189,7 +155,35 @@ static int16_t uwp_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return uwp_pressed_analog(uwp, joypad_info, binds[port], port, index, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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) + { + if (uwp_keyboard_pressed(bind_plus_key)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + if (uwp_keyboard_pressed(bind_minus_key)) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && uwp_keyboard_pressed(id); diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 06bff9d3c0..936d4f6923 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -154,42 +154,6 @@ static void input_wl_poll(void *data) input_wl_touch_pool(wl); } -static int16_t input_wl_pressed_analog( - input_ctx_wayland_data_t *wl, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if (BIT_GET(wl->key_state, sym)) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if (BIT_GET(wl->key_state, sym)) - ret += -0x7fff; - } - - return ret; -} - static bool input_wl_state_kb(input_ctx_wayland_data_t *wl, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) @@ -351,7 +315,37 @@ static int16_t input_wl_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return input_wl_pressed_analog(wl, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t ret = 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 (BIT_GET(wl->key_state, sym)) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (BIT_GET(wl->key_state, sym)) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_KEYBOARD: return input_wl_state_kb(wl, binds, port, device, idx, id); diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index a68b4f44e8..fb6970f638 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -102,42 +102,6 @@ static bool x_mouse_button_pressed( return false; } -static int16_t x_pressed_analog(x11_input_t *x11, - const struct retro_keybind *binds, unsigned idx, unsigned id) -{ - int id_minus_key = 0; - int id_plus_key = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; - int16_t ret = 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[id_minus].valid; - id_plus_valid = binds[id_plus].valid; - id_minus_key = binds[id_minus].key; - id_plus_key = binds[id_plus].key; - - if (id_plus_valid && id_plus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_plus_key]; - if (x11->state[sym >> 3] & (1 << (sym & 7))) - ret = 0x7fff; - } - if (id_minus_valid && id_minus_key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; - if (x11->state[sym >> 3] & (1 << (sym & 7))) - ret += -0x7fff; - } - - return ret; -} - static int16_t x_lightgun_aiming_state( x11_input_t *x11, unsigned idx, unsigned id ) { @@ -347,7 +311,39 @@ static int16_t x_input_state( break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return x_pressed_analog(x11, binds[port], idx, id); + { + int id_minus_key = 0; + int id_plus_key = 0; + unsigned id_minus = 0; + unsigned id_plus = 0; + int16_t pressed_minus = 0; + int16_t pressed_plus = 0; + int16_t ret = 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 (x11->state[sym >> 3] & (1 << (sym & 7))) + ret = 0x7fff; + } + if (id_minus_valid && id_minus_key < RETROK_LAST) + { + unsigned sym = rarch_keysym_lut[(enum retro_key)id_minus_key]; + if (x11->state[sym >> 3] & (1 << (sym & 7))) + ret += -0x7fff; + } + + return ret; + } break; case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && x_keyboard_pressed(x11, id); From d4d8b6934ac8f7110ba1d9314439c369f0567075 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 18:47:29 +0200 Subject: [PATCH 11/30] Put keyboard_mapping_blocked into p_rarch / rarch struct instead --- input/drivers/android_input.c | 11 ++-- input/drivers/cocoa_input.c | 10 ++-- input/drivers/ctr_input.c | 12 ++--- input/drivers/dinput.c | 17 +++--- input/drivers/dos_input.c | 10 ++-- input/drivers/gx_input.c | 10 ++-- input/drivers/linuxraw_input.c | 11 ++-- input/drivers/ps2_input.c | 10 ++-- input/drivers/ps3_input.c | 10 ++-- input/drivers/ps4_input.c | 10 ++-- input/drivers/psl1ght_input.c | 25 ++++----- input/drivers/psp_input.c | 10 ++-- input/drivers/qnx_input.c | 13 +++-- input/drivers/rwebinput_input.c | 26 +++++---- input/drivers/sdl_input.c | 9 ++-- input/drivers/switch_input.c | 13 +++-- input/drivers/udev_input.c | 65 ++++++++++++++++------- input/drivers/uwp_input.c | 14 ++--- input/drivers/wayland_input.c | 9 ++-- input/drivers/wiiu_input.c | 10 ++-- input/drivers/winraw_input.c | 69 +++++++++++++++++------- input/drivers/x11_input.c | 39 +++++++------- input/drivers/xdk_xinput_input.c | 10 ++-- input/drivers/xenon360_input.c | 10 ++-- input/input_driver.h | 2 +- retroarch.c | 91 +++++++++++++++++++++----------- 26 files changed, 332 insertions(+), 194 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index fc30a8612c..912fb789e1 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1393,8 +1393,12 @@ static int16_t android_input_state( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, - const struct retro_keybind **binds, unsigned port, unsigned device, - unsigned idx, unsigned id) + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { android_input_t *android = (android_input_t*)data; @@ -1620,6 +1624,5 @@ input_driver_t input_android = { android_input_grab_mouse, NULL, - android_input_set_rumble, - false + android_input_set_rumble }; diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index bb748cee44..8c91f49e6c 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -187,8 +187,12 @@ static int16_t cocoa_input_state( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, - const struct retro_keybind **binds, unsigned port, - unsigned device, unsigned idx, unsigned id) + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { cocoa_input_data_t *apple = (cocoa_input_data_t*)data; @@ -208,7 +212,7 @@ static int16_t cocoa_input_state( #endif ; - if (!input_cocoa.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index a0f1cef12b..5239316737 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -41,8 +41,11 @@ static int16_t ctr_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ctr_input_t *ctr = (ctr_input_t*)data; @@ -87,8 +90,6 @@ static void* ctr_input_init(const char *joypad_driver) static uint64_t ctr_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } @@ -103,6 +104,5 @@ input_driver_t input_ctr = { "ctr", NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 4acf930014..26855ce835 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -533,8 +533,12 @@ static int16_t dinput_input_state( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, - const struct retro_keybind **binds, unsigned port, - unsigned device, unsigned idx, unsigned id) + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { settings_t *settings; struct dinput_input *di = (struct dinput_input*)data; @@ -568,7 +572,7 @@ static int16_t dinput_input_state( } } - if (!input_dinput.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -597,7 +601,7 @@ static int16_t dinput_input_state( && (di->state[rarch_keysym_lut [(enum retro_key)binds[port][id].key]] & 0x80) && ( (id == RARCH_GAME_FOCUS_TOGGLE) - || !input_dinput.keyboard_mapping_blocked) + || !keyboard_mapping_blocked) ) return 1; else if ( @@ -738,7 +742,7 @@ static int16_t dinput_input_state( return 1; else if ( binds[port][new_id].key < RETROK_LAST - && !input_dinput.keyboard_mapping_blocked + && !keyboard_mapping_blocked && di->state[rarch_keysym_lut [(enum retro_key)binds[port][new_id].key]] & 0x80 ) @@ -1024,6 +1028,5 @@ input_driver_t input_dinput = { "dinput", dinput_grab_mouse, NULL, - dinput_set_rumble, - false + dinput_set_rumble }; diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 63cc02dfd0..46a8b6064e 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -68,8 +68,11 @@ static int16_t dos_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { dos_input_t *dos = (dos_input_t*)data; @@ -158,6 +161,5 @@ input_driver_t input_dos = { "dos", NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index e82d4f8db7..36f453f812 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -144,8 +144,11 @@ static int16_t gx_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { gx_input_t *gx = (gx_input_t*)data; @@ -304,6 +307,5 @@ input_driver_t input_gx = { NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 1c8955eaaf..2cb769b4a3 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -77,8 +77,12 @@ static int16_t linuxraw_input_state( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, - const struct retro_keybind **binds, unsigned port, - unsigned device, unsigned idx, unsigned id) + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; @@ -230,6 +234,5 @@ input_driver_t input_linuxraw = { "linuxraw", NULL, /* grab_mouse */ linux_terminal_grab_stdin, - linuxraw_set_rumble, - false + linuxraw_set_rumble }; diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 94e74a426a..08782a4358 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -37,8 +37,11 @@ static int16_t ps2_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps2_input_t *ps2 = (ps2_input_t*)data; @@ -107,6 +110,5 @@ input_driver_t input_ps2 = { "ps2", NULL, /* grab_mouse */ NULL, - ps2_input_set_rumble, - false + ps2_input_set_rumble }; diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 630e79291b..043d3d4835 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -97,8 +97,11 @@ static int16_t ps3_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps3_input_t *ps3 = (ps3_input_t*)data; @@ -236,6 +239,5 @@ input_driver_t input_ps3 = { NULL, /* grab_mouse */ NULL, - ps3_input_set_rumble, - false + ps3_input_set_rumble }; diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index ac58e6d783..fcb7e0e9fa 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -43,8 +43,11 @@ static int16_t ps4_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps4_input_t *ps4 = (ps4_input_t*)data; @@ -110,6 +113,5 @@ input_driver_t input_ps4 = { "ps4", NULL, /* grab_mouse */ NULL, - ps4_input_set_rumble, - false + ps4_input_set_rumble }; diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index 6b89d9e981..0914344423 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -213,8 +213,11 @@ static int16_t ps3_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps3_input_t *ps3 = (ps3_input_t*)data; @@ -296,7 +299,6 @@ static void* ps3_input_init(const char *joypad_driver) static uint64_t ps3_input_get_capabilities(void *data) { - (void)data; return #ifdef HAVE_MOUSE (1 << RETRO_DEVICE_MOUSE) | @@ -307,10 +309,7 @@ static uint64_t ps3_input_get_capabilities(void *data) } static bool ps3_input_set_sensor_state(void *data, unsigned port, - enum retro_sensor_action action, unsigned event_rate) -{ - return false; -} + enum retro_sensor_action action, unsigned event_rate) { return false; } input_driver_t input_ps3 = { ps3_input_init, @@ -324,8 +323,7 @@ input_driver_t input_ps3 = { NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; /* RetroArch - A frontend for libretro. @@ -542,14 +540,9 @@ static bool ps3_joypad_query_pad(unsigned pad) } static bool ps3_joypad_rumble(unsigned pad, - enum retro_rumble_effect effect, uint16_t strength) -{ - return true; -} + enum retro_rumble_effect effect, uint16_t strength) { return true; } -static void ps3_joypad_destroy(void) -{ -} +static void ps3_joypad_destroy(void) { } input_device_driver_t ps3_joypad = { ps3_joypad_init, diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index a289d6cb01..158ee7a966 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -277,8 +277,11 @@ static int16_t psp_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { psp_input_t *psp = (psp_input_t*)data; @@ -474,6 +477,5 @@ input_driver_t input_psp = { NULL, /* grab_mouse */ NULL, - psp_input_set_rumble, - false + psp_input_set_rumble }; diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 778e35a0e7..708f38c2b8 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -775,7 +775,11 @@ static int16_t qnx_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { qnx_input_t *qnx = (qnx_input_t*)data; @@ -788,7 +792,7 @@ static int16_t qnx_input_state( int16_t ret = joypad->state( joypad_info, binds[port], port); - if (!input_qnx.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -813,7 +817,7 @@ static int16_t qnx_input_state( return 1; else if ( ((id == RARCH_GAME_FOCUS_TOGGLE) || - !input_qnx.keyboard_mapping_blocked) && + !keyboard_mapping_blocked) && qnx_keyboard_pressed(qnx, key) ) return 1; @@ -865,6 +869,5 @@ input_driver_t input_qnx = { "qnx_input", NULL, NULL, - NULL, - false + NULL }; diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index 8aca5f76ba..1fd38fedfd 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -467,7 +467,8 @@ static int16_t rwebinput_is_pressed( const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind *binds, - unsigned port, unsigned id) + unsigned port, unsigned id, + bool keyboard_mapping_blocked) { const struct retro_keybind *bind = &binds[id]; /* Auto-binds are per joypad, not per user. */ @@ -478,7 +479,7 @@ static int16_t rwebinput_is_pressed( int key = bind->key; if ((key < RETROK_LAST) && rwebinput_key_pressed(rwebinput, key)) - if ((id == RARCH_GAME_FOCUS_TOGGLE) || !input_rwebinput.keyboard_mapping_blocked) + if ((id == RARCH_GAME_FOCUS_TOGGLE) || !keyboard_mapping_blocked) return 1; if (port == 0 && !!rwebinput_mouse_state(&rwebinput->mouse, bind->mbutton, false)) @@ -497,7 +498,11 @@ static int16_t rwebinput_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; @@ -514,7 +519,8 @@ static int16_t rwebinput_input_state( { if (rwebinput_is_pressed( rwebinput, joypad, - joypad_info, binds[port], port, i)) + joypad_info, binds[port], port, i, + keyboard_mapping_blocked)) ret |= (1 << i); } } @@ -529,7 +535,8 @@ static int16_t rwebinput_input_state( { if (rwebinput_is_pressed(rwebinput, joypad, joypad_info, binds[port], - port, id)) + port, id, + keyboard_mapping_blocked)) return 1; } } @@ -556,13 +563,15 @@ static int16_t rwebinput_input_state( if (id_plus_valid && id_plus_key < RETROK_LAST) { if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds[port], idx, id_plus)) + joypad, joypad_info, binds[port], idx, id_plus, + keyboard_mapping_blocked)) ret = 0x7fff; } if (id_minus_valid && id_minus_key < RETROK_LAST) { if (rwebinput_is_pressed(rwebinput, - joypad, joypad_info, binds[port], idx, id_minus)) + joypad, joypad_info, binds[port], idx, id_minus, + keyboard_mapping_blocked)) ret += -0x7fff; } @@ -694,6 +703,5 @@ input_driver_t input_rwebinput = { "rwebinput", rwebinput_grab_mouse, NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 7f9c59fe06..5ff0821183 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -184,7 +184,11 @@ static int16_t sdl_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { sdl_input_t *sdl = (sdl_input_t*)data; @@ -427,6 +431,5 @@ input_driver_t input_sdl = { NULL, /* grab_mouse */ #endif NULL, - sdl_set_rumble, - false + sdl_set_rumble }; diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index 083b1bfbf7..6507e49e0d 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -370,11 +370,15 @@ static int16_t switch_input_mouse_state( } #endif -static int16_t switch_input_state(void *data, +static int16_t switch_input_state( + void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { switch_input_t *sw = (switch_input_t*) data; @@ -982,6 +986,5 @@ input_driver_t input_switch = { "switch", NULL, /* grab_mouse */ NULL, - switch_input_set_rumble, - false + switch_input_set_rumble }; diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 27b61439bc..249b308809 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -958,9 +958,13 @@ static int16_t udev_input_lightgun_state( const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { - if (!input_udev.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][id].key < RETROK_LAST) && udev_keyboard_pressed(udev, binds[port] [id].key) ) @@ -985,7 +989,11 @@ static int16_t udev_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { udev_input_t *udev = (udev_input_t*)data; @@ -1006,7 +1014,7 @@ static int16_t udev_input_state( ret |= (1 << i); } } - if (!input_udev.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -1034,7 +1042,7 @@ static int16_t udev_input_state( (binds[port][id].key < RETROK_LAST) && udev_keyboard_pressed(udev, binds[port][id].key) && (( id == RARCH_GAME_FOCUS_TOGGLE) - || !input_udev.keyboard_mapping_blocked) + || !keyboard_mapping_blocked) ) return 1; else if (udev_mouse_button_pressed(udev, port, @@ -1108,47 +1116,69 @@ static int16_t udev_input_state( case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_RELOAD); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_A); case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_B); case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_C); case RETRO_DEVICE_ID_LIGHTGUN_START: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_SELECT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_SELECT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_UP); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: return udev_input_lightgun_state(udev, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: { @@ -1408,6 +1438,5 @@ input_driver_t input_udev = { #else NULL, #endif - udev_input_set_rumble, - false + udev_input_set_rumble }; diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index f16230eb2a..c016963e94 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -90,8 +90,11 @@ static int16_t uwp_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned index, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned index, + unsigned id) { uwp_input_t *uwp = (uwp_input_t*)data; @@ -104,7 +107,7 @@ static int16_t uwp_input_state( int16_t ret = joypad->state( joypad_info, binds[port], port); - if (!input_uwp.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -143,7 +146,7 @@ static int16_t uwp_input_state( else if ((binds[port][id].key < RETROK_LAST) && uwp_keyboard_pressed(binds[port][id].key) && ((id == RARCH_GAME_FOCUS_TOGGLE) || - !input_uwp.keyboard_mapping_blocked) + !keyboard_mapping_blocked) ) return 1; else if (uwp_mouse_state(port, @@ -211,6 +214,5 @@ input_driver_t input_uwp = { "uwp", NULL, /* grab_mouse */ NULL, - uwp_input_set_rumble, - false + uwp_input_set_rumble }; diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 936d4f6923..ef2ab1e5ca 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -271,7 +271,11 @@ static int16_t input_wl_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; @@ -431,6 +435,5 @@ input_driver_t input_wayland = { "wayland", input_wl_grab_mouse, NULL, - input_wl_set_rumble, - false + input_wl_set_rumble }; diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index c4ed5c6844..24a95aedd5 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -122,8 +122,11 @@ static int16_t wiiu_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { wiiu_input_t *wiiu = (wiiu_input_t*)data; @@ -198,6 +201,5 @@ input_driver_t input_wiiu = { "wiiu", NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index fe5e1b087b..977cef1f0c 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -563,9 +563,13 @@ static int16_t winraw_input_lightgun_state( const input_device_driver_t *joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { - if (!input_winraw.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][id].key < RETROK_LAST) && winraw_keyboard_pressed(wr, binds[port] [id].key)) @@ -589,7 +593,11 @@ static int16_t winraw_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { settings_t *settings = NULL; winraw_mouse_t *mouse = NULL; @@ -639,7 +647,7 @@ static int16_t winraw_input_state( } } - if (!input_winraw.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -668,7 +676,7 @@ static int16_t winraw_input_state( (binds[port][id].key < RETROK_LAST) && winraw_keyboard_pressed(wr, binds[port][id].key) && (( id == RARCH_GAME_FOCUS_TOGGLE) - || !input_winraw.keyboard_mapping_blocked) + || !keyboard_mapping_blocked) ) return 1; else if (mouse && winraw_mouse_button_pressed(wr, @@ -704,47 +712,69 @@ static int16_t winraw_input_state( case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_RELOAD); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_A); case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_B); case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_C); case RETRO_DEVICE_ID_LIGHTGUN_START: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_SELECT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_SELECT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_UP); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: case RETRO_DEVICE_ID_LIGHTGUN_Y: @@ -754,7 +784,9 @@ static int16_t winraw_input_state( case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: return winraw_input_lightgun_state(wr, mouse, joypad, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); } break; } @@ -823,6 +855,5 @@ input_driver_t input_winraw = { "raw", winraw_grab_mouse, NULL, - winraw_set_rumble, - false + winraw_set_rumble }; diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index fb6970f638..e140acd4ac 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -238,8 +238,12 @@ static int16_t x_input_state( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, - const struct retro_keybind **binds, unsigned port, - unsigned device, unsigned idx, unsigned id) + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { x11_input_t *x11 = (x11_input_t*)data; settings_t *settings = config_get_ptr(); @@ -268,7 +272,7 @@ static int16_t x_input_state( } } } - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -296,7 +300,7 @@ static int16_t x_input_state( ((binds[port][id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port][id].key)) && (( id == RARCH_GAME_FOCUS_TOGGLE) - || !input_x.keyboard_mapping_blocked) + || !keyboard_mapping_blocked) ) return 1; else if (settings->uints.input_mouse_index[port] == 0) @@ -371,7 +375,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: { unsigned new_id = RARCH_LIGHTGUN_TRIGGER; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -394,7 +398,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: { unsigned new_id = RARCH_LIGHTGUN_RELOAD; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -417,7 +421,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: { unsigned new_id = RARCH_LIGHTGUN_AUX_A; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -440,7 +444,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: { unsigned new_id = RARCH_LIGHTGUN_AUX_B; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -463,7 +467,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: { unsigned new_id = RARCH_LIGHTGUN_AUX_C; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -486,7 +490,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_START: { unsigned new_id = RARCH_LIGHTGUN_START; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -509,7 +513,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_SELECT: { unsigned new_id = RARCH_LIGHTGUN_SELECT; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -532,7 +536,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: { unsigned new_id = RARCH_LIGHTGUN_DPAD_UP; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -555,7 +559,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: { unsigned new_id = RARCH_LIGHTGUN_DPAD_DOWN; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -578,7 +582,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: { unsigned new_id = RARCH_LIGHTGUN_DPAD_LEFT; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -601,7 +605,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: { unsigned new_id = RARCH_LIGHTGUN_DPAD_RIGHT; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -629,7 +633,7 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: { unsigned new_id = RARCH_LIGHTGUN_START; - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) if ((binds[port][new_id].key < RETROK_LAST) && x_keyboard_pressed(x11, binds[port] [new_id].key) ) @@ -780,6 +784,5 @@ input_driver_t input_x = { "x", x_grab_mouse, NULL, - x_set_rumble, - false + x_set_rumble }; diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 1f32d04c3c..b0c01d3d75 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -46,8 +46,11 @@ static int16_t xdk_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - unsigned port, unsigned device, - unsigned index, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned index, + unsigned id) { xdk_input_t *xdk = (xdk_input_t*)data; @@ -123,6 +126,5 @@ input_driver_t input_xinput = { "xinput", NULL, /* grab_mouse */ NULL, - xdk_input_set_rumble, - false + xdk_input_set_rumble }; diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 231fd2615c..dfba6c4b86 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -67,8 +67,11 @@ static int16_t xenon360_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, - bool port, unsigned device, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { uint64_t button = binds[port][id].joykey; @@ -137,6 +140,5 @@ input_driver_t input_xenon360 = { "xenon360", NULL, /* grab_mouse */ NULL, - NULL, /* set_rumble */ - false + NULL /* set_rumble */ }; diff --git a/input/input_driver.h b/input/input_driver.h index 4d89940045..ecde7f4ee8 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -185,6 +185,7 @@ struct input_driver const input_device_driver_t *sec_joypad_data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **retro_keybinds, + bool keyboard_mapping_blocked, unsigned port, unsigned device, unsigned index, unsigned id); /* Frees the input struct. */ @@ -203,7 +204,6 @@ struct input_driver const input_device_driver_t *sec_joypad_data, unsigned port, enum retro_rumble_effect effect, uint16_t state); - bool keyboard_mapping_blocked; }; struct rarch_joypad_driver diff --git a/retroarch.c b/retroarch.c index 8013c9ed51..efa06b8aa7 100644 --- a/retroarch.c +++ b/retroarch.c @@ -682,6 +682,7 @@ static int16_t input_null_input_state( const input_device_driver_t *sec_joypad, rarch_joypad_info_t *joypad_info, const struct retro_keybind **retro_keybinds, + bool keyboard_mapping_blocked, unsigned port, unsigned device, unsigned index, unsigned id) { return 0; } static void input_null_free(void *data) { } static bool input_null_set_sensor_state(void *data, unsigned port, @@ -707,8 +708,7 @@ static input_driver_t input_null = { "null", input_null_grab_mouse, input_null_grab_stdin, - input_null_set_rumble, - false, + input_null_set_rumble }; static input_driver_t *input_drivers[] = { @@ -2553,6 +2553,7 @@ struct rarch_state bool midi_drv_output_pending; bool main_ui_companion_is_on_foreground; + bool keyboard_mapping_blocked; #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) bool shader_presets_need_reload; @@ -3644,6 +3645,7 @@ static void menu_input_key_bind_poll_bind_state( sec_joypad, &joypad_info, NULL, + p_rarch->keyboard_mapping_blocked, 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); menu_input_key_bind_poll_bind_state_internal( @@ -3984,8 +3986,7 @@ static bool menu_input_key_bind_iterate( if (RARCH_TIMER_HAS_EXPIRED(_binds->timer_timeout)) { - if (input_drv) - input_drv->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; /*skip to next bind*/ _binds->begin++; @@ -4015,11 +4016,10 @@ static bool menu_input_key_bind_iterate( } { - bool complete = false; - struct menu_bind_state new_binds = *_binds; + bool complete = false; + struct menu_bind_state new_binds = *_binds; - if (input_drv) - input_drv->keyboard_mapping_blocked = true; + p_rarch->keyboard_mapping_blocked = false; menu_input_key_bind_poll_bind_state(p_rarch, &new_binds, timed_out); @@ -4064,8 +4064,7 @@ static bool menu_input_key_bind_iterate( /* Update bind */ *(new_binds.output) = new_binds.buffer; - if (input_drv) - input_drv->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; /* Avoid new binds triggering things right away. */ /* Inhibits input for 2 frames @@ -17157,7 +17156,7 @@ bool command_event(enum event_command cmd, void *data) input_driver_grab_mouse(p_rarch); video_driver_hide_mouse(); p_rarch->input_driver_block_hotkey = true; - p_rarch->current_input->keyboard_mapping_blocked = true; + p_rarch->keyboard_mapping_blocked = false; if (mode != -1) runloop_msg_queue_push(msg_hash_to_str(MSG_GAME_FOCUS_ON), 1, 120, true, @@ -17169,7 +17168,7 @@ bool command_event(enum event_command cmd, void *data) if (!video_fullscreen) video_driver_show_mouse(); p_rarch->input_driver_block_hotkey = false; - p_rarch->current_input->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; if (mode != -1) runloop_msg_queue_push(msg_hash_to_str(MSG_GAME_FOCUS_OFF), 1, 120, true, @@ -23422,6 +23421,7 @@ static void input_poll_overlay( sec_joypad, &joypad_info, NULL, + p_rarch->keyboard_mapping_blocked, 0, device, i, RETRO_DEVICE_ID_POINTER_PRESSED); i++) { @@ -23432,6 +23432,7 @@ static void input_poll_overlay( sec_joypad, &joypad_info, NULL, + p_rarch->keyboard_mapping_blocked, 0, device, i, RETRO_DEVICE_ID_POINTER_X); int16_t y = input_ptr->input_state( input_data, @@ -23439,6 +23440,7 @@ static void input_poll_overlay( sec_joypad, &joypad_info, NULL, + p_rarch->keyboard_mapping_blocked, 0, device, i, RETRO_DEVICE_ID_POINTER_Y); memset(&polled_data, 0, sizeof(struct input_overlay_state)); @@ -23883,6 +23885,7 @@ static void input_driver_poll(void) sec_joypad, &joypad_info[i], p_rarch->libretro_input_binds, + p_rarch->keyboard_mapping_blocked, (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); } @@ -23934,6 +23937,7 @@ static void input_driver_poll(void) sec_joypad, &joypad_info[i], p_rarch->libretro_input_binds, + p_rarch->keyboard_mapping_blocked, (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); @@ -24629,7 +24633,9 @@ static int16_t input_state(unsigned port, unsigned device, p_rarch->joypad, sec_joypad, &joypad_info, - p_rarch->libretro_input_binds, port, device, idx, id); + p_rarch->libretro_input_binds, + p_rarch->keyboard_mapping_blocked, + port, device, idx, id); if ( (device == RETRO_DEVICE_ANALOG) && (ret == 0)) @@ -24838,7 +24844,9 @@ static int16_t menu_input_read_mouse_hw( p_rarch->joypad, sec_joypad, &joypad_info, - NULL, 0, device, 0, type); + NULL, + p_rarch->keyboard_mapping_blocked, + 0, device, 0, type); } static void menu_input_get_mouse_hw_state( @@ -25035,7 +25043,10 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); + 0, + pointer_device, + p_rarch->keyboard_mapping_blocked, + 0, RETRO_DEVICE_ID_POINTER_X); hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; /* > An annoyance - we get different starting positions @@ -25062,7 +25073,9 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); + 0, pointer_device, + p_rarch->keyboard_mapping_blocked, + 0, RETRO_DEVICE_ID_POINTER_Y); hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; if (pointer_device == RARCH_DEVICE_POINTER_SCREEN) @@ -25085,7 +25098,9 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); + p_rarch->keyboard_mapping_blocked, + 0, pointer_device, + 0, RETRO_DEVICE_ID_POINTER_PRESSED); if (hw_state->select_pressed || (hw_state->select_pressed != last_select_pressed)) hw_state->active = true; last_select_pressed = hw_state->select_pressed; @@ -25097,7 +25112,9 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); + p_rarch->keyboard_mapping_blocked, + 0, pointer_device, + 0, RARCH_DEVICE_ID_POINTER_BACK); if (hw_state->cancel_pressed || (hw_state->cancel_pressed != last_cancel_pressed)) hw_state->active = true; last_cancel_pressed = hw_state->cancel_pressed; @@ -26354,7 +26371,9 @@ static void input_keys_pressed( p_rarch->joypad, sec_joypad, joypad_info, - &binds[port], port, RETRO_DEVICE_JOYPAD, 0, + &binds[port], + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY)) { if (p_rarch->input_hotkey_block_counter < input_hotkey_block_delay) @@ -26387,7 +26406,9 @@ static void input_keys_pressed( p_rarch->joypad, sec_joypad, joypad_info, - &binds[port], port, + &binds[port], + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE)) p_rarch->input_driver_block_hotkey = false; } @@ -26411,7 +26432,9 @@ static void input_keys_pressed( p_rarch->current_input_data, p_rarch->joypad, sec_joypad, - joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, + joypad_info, &binds[port], + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); for (i = 0; i < RARCH_FIRST_META_KEY; i++) @@ -26449,7 +26472,9 @@ static void input_keys_pressed( p_rarch->joypad, sec_joypad, joypad_info, - &binds[port], port, RETRO_DEVICE_JOYPAD, 0, i); + &binds[port], + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_JOYPAD, 0, i); if ( bit_pressed || BIT64_GET(lifecycle_state, i) || input_keys_pressed_other_sources(p_rarch, i, p_new_state)) @@ -27077,6 +27102,7 @@ static bool input_mouse_button_raw( sec_joypad, &joypad_info, p_rarch->libretro_input_binds, + p_rarch->keyboard_mapping_blocked, port, RETRO_DEVICE_MOUSE, 0, id); return false; @@ -27337,7 +27363,7 @@ static const char **input_keyboard_start_line(void *userdata, p_rarch->keyboard_line->userdata = userdata; /* While reading keyboard line input, we have to block all hotkeys. */ - p_rarch->current_input->keyboard_mapping_blocked = true; + p_rarch->keyboard_mapping_blocked = true; return (const char**)&p_rarch->keyboard_line->buffer; } @@ -27457,7 +27483,7 @@ void input_keyboard_event(bool down, unsigned code, p_rarch->keyboard_press_cb = NULL; p_rarch->keyboard_press_data = NULL; - p_rarch->current_input->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; deferred_wait_keys = false; } else if (p_rarch->keyboard_press_cb) @@ -27496,7 +27522,7 @@ void input_keyboard_event(bool down, unsigned code, p_rarch->keyboard_line = NULL; /* Unblock all hotkeys. */ - p_rarch->current_input->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; } else { @@ -27537,12 +27563,12 @@ static bool input_keyboard_ctl( } /* While waiting for input, we have to block all hotkeys. */ - p_rarch->current_input->keyboard_mapping_blocked = true; + p_rarch->keyboard_mapping_blocked = true; break; case RARCH_INPUT_KEYBOARD_CTL_CANCEL_WAIT_KEYS: p_rarch->keyboard_press_cb = NULL; p_rarch->keyboard_press_data = NULL; - p_rarch->current_input->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; break; case RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED: return p_rarch->input_driver_keyboard_linefeed_enable; @@ -31626,7 +31652,7 @@ static void video_driver_free_internal(void) #endif p_rarch->joypad = NULL; } - p_rarch->current_input->keyboard_mapping_blocked = false; + p_rarch->keyboard_mapping_blocked = false; } p_rarch->current_input_data = NULL; } @@ -34755,7 +34781,8 @@ static void driver_adjust_system_rates(struct rarch_state *p_rarch) unsigned video_swap_interval = settings->uints.video_swap_interval; if (p_rarch->current_video->set_nonblock_state) - p_rarch->current_video->set_nonblock_state(p_rarch->video_driver_data, true, + p_rarch->current_video->set_nonblock_state( + p_rarch->video_driver_data, true, video_driver_test_all_flags(GFX_CTX_FLAGS_ADAPTIVE_VSYNC) && video_adaptive_vsync, video_swap_interval @@ -38783,7 +38810,7 @@ static enum runloop_state runloop_check_state( p_rarch->input_driver_block_libretro_input = false; p_rarch->input_driver_block_hotkey = false; - if (p_rarch->current_input->keyboard_mapping_blocked) + if (p_rarch->keyboard_mapping_blocked) p_rarch->input_driver_block_hotkey = true; { @@ -38909,7 +38936,9 @@ static enum runloop_state runloop_check_state( p_rarch->current_input_data, p_rarch->joypad, sec_joypad, - &joypad_info, &binds, port, + &joypad_info, &binds, + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_KEYBOARD, 0, ids[i][0])) BIT256_SET_PTR(¤t_bits, ids[i][1]); } From 6c6bca9db9e7c4f5497056c80c6624f504ea7716 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 18:48:58 +0200 Subject: [PATCH 12/30] Update cocoa_input.c --- input/drivers/cocoa_input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index 8c91f49e6c..3b1eb478a7 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -313,6 +313,5 @@ input_driver_t input_cocoa = { "cocoa", NULL, /* grab_mouse */ NULL, - cocoa_input_set_rumble, - false + cocoa_input_set_rumble }; From 82c558e5cead646fe9195f4ecfcaa44ae24f35fb Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 18:59:57 +0200 Subject: [PATCH 13/30] Update copyrights --- input/drivers_joypad/dinput_hybrid_joypad.c | 2 +- input/drivers_joypad/dinput_joypad.c | 2 +- input/drivers_joypad/dinput_joypad.h | 2 +- input/drivers_joypad/dinput_joypad_excl.h | 3 +-- input/drivers_joypad/dinput_joypad_inl.h | 3 +-- input/drivers_joypad/xinput_hybrid_joypad.c | 2 +- input/drivers_joypad/xinput_joypad.c | 2 +- input/drivers_joypad/xinput_joypad.h | 3 +-- input/drivers_joypad/xinput_joypad_inl.h | 3 +-- 9 files changed, 9 insertions(+), 13 deletions(-) diff --git a/input/drivers_joypad/dinput_hybrid_joypad.c b/input/drivers_joypad/dinput_hybrid_joypad.c index ec75bd430c..aeb5c4d8ef 100644 --- a/input/drivers_joypad/dinput_hybrid_joypad.c +++ b/input/drivers_joypad/dinput_hybrid_joypad.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 0b8cbcc142..cab4d6916d 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/dinput_joypad.h b/input/drivers_joypad/dinput_joypad.h index 1a5e2cbdf1..4362675dc2 100644 --- a/input/drivers_joypad/dinput_joypad.h +++ b/input/drivers_joypad/dinput_joypad.h @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms diff --git a/input/drivers_joypad/dinput_joypad_excl.h b/input/drivers_joypad/dinput_joypad_excl.h index 63a9cd6d99..1eca1aea0c 100644 --- a/input/drivers_joypad/dinput_joypad_excl.h +++ b/input/drivers_joypad/dinput_joypad_excl.h @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/dinput_joypad_inl.h b/input/drivers_joypad/dinput_joypad_inl.h index b127e0a854..9a57ffb486 100644 --- a/input/drivers_joypad/dinput_joypad_inl.h +++ b/input/drivers_joypad/dinput_joypad_inl.h @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/xinput_hybrid_joypad.c b/input/drivers_joypad/xinput_hybrid_joypad.c index ca403ff69b..d5e55488e3 100644 --- a/input/drivers_joypad/xinput_hybrid_joypad.c +++ b/input/drivers_joypad/xinput_hybrid_joypad.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2013-2015 - pinumbernumber - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 3744ace024..ce87d2b621 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2013-2015 - pinumbernumber - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/xinput_joypad.h b/input/drivers_joypad/xinput_joypad.h index 9fd0be5d5f..7992dc6c9e 100644 --- a/input/drivers_joypad/xinput_joypad.h +++ b/input/drivers_joypad/xinput_joypad.h @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/drivers_joypad/xinput_joypad_inl.h b/input/drivers_joypad/xinput_joypad_inl.h index 0687515860..bac9547a63 100644 --- a/input/drivers_joypad/xinput_joypad_inl.h +++ b/input/drivers_joypad/xinput_joypad_inl.h @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2016 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- From 9fdbcae3a87f6fda6fd8a56ec04dc7c85539a5b5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 19:00:44 +0200 Subject: [PATCH 14/30] Update copyrights; person was not involved in this file --- input/drivers_joypad/dinput_joypad.h | 1 - 1 file changed, 1 deletion(-) diff --git a/input/drivers_joypad/dinput_joypad.h b/input/drivers_joypad/dinput_joypad.h index 4362675dc2..012f0a4013 100644 --- a/input/drivers_joypad/dinput_joypad.h +++ b/input/drivers_joypad/dinput_joypad.h @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2020 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- From ea17294ff1c3e44f77246be68f6224ded2cc0816 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 19:04:50 +0200 Subject: [PATCH 15/30] Update copyright --- input/drivers/dinput.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 26855ce835..43d4a8134d 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2011-2020 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- From 7b0fe597223430580d7c5897dab999437117b3de Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 30 Aug 2020 19:41:44 +0200 Subject: [PATCH 16/30] Get rid of duplicate dinput_hybrid_joypad.c --- Makefile.common | 7 +-- griffin/griffin.c | 4 -- input/drivers_joypad/dinput_hybrid_joypad.c | 61 --------------------- 3 files changed, 1 insertion(+), 71 deletions(-) delete mode 100644 input/drivers_joypad/dinput_hybrid_joypad.c diff --git a/Makefile.common b/Makefile.common index 2e73a458d8..6852f32070 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1106,12 +1106,7 @@ ifeq ($(HAVE_DINPUT), 1) LIBS += -ldinput8 -lole32 DEFINES += -DHAVE_DINPUT OBJ += input/drivers/dinput.o - - ifeq ($(HAVE_XINPUT), 1) - OBJ += input/drivers_joypad/dinput_hybrid_joypad.o - else - OBJ += input/drivers_joypad/dinput_joypad.o - endif + OBJ += input/drivers_joypad/dinput_joypad.o endif ifeq ($(HAVE_XINPUT), 1) diff --git a/griffin/griffin.c b/griffin/griffin.c index cb0a430d8f..a6d0aca4f2 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -748,12 +748,8 @@ INPUT #ifdef HAVE_DINPUT #include "../input/drivers/dinput.c" -#ifdef HAVE_XINPUT -#include "../input/drivers_joypad/dinput_hybrid_joypad.c" -#else #include "../input/drivers_joypad/dinput_joypad.c" #endif -#endif #ifdef HAVE_XINPUT #ifdef HAVE_DINPUT diff --git a/input/drivers_joypad/dinput_hybrid_joypad.c b/input/drivers_joypad/dinput_hybrid_joypad.c deleted file mode 100644 index aeb5c4d8ef..0000000000 --- a/input/drivers_joypad/dinput_hybrid_joypad.c +++ /dev/null @@ -1,61 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2020 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -/* Specialized version of dinput_joypad.c, - * has both DirectInput and XInput codepaths */ - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include "../../config.h" -#endif - -#include "../../tasks/tasks_internal.h" -#include "../input_keymaps.h" -#include "../../retroarch.h" -#include "../../verbosity.h" -#include "dinput_joypad.h" - -/* TODO/FIXME - globals referenced outside */ -struct dinput_joypad_data g_pads[MAX_USERS]; -unsigned g_joypad_cnt; - -#include "dinput_joypad_inl.h" -#include "dinput_joypad_excl.h" - -input_device_driver_t dinput_joypad = { - dinput_joypad_init, - dinput_joypad_query_pad, - dinput_joypad_destroy, - dinput_joypad_button, - dinput_joypad_state, - NULL, - dinput_joypad_axis, - dinput_joypad_poll, - dinput_joypad_set_rumble, - dinput_joypad_name, - "dinput", -}; From 06ac5217acefb61c6ac25210920433300f73d43e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 00:32:49 +0200 Subject: [PATCH 17/30] Simplify dinput.c --- input/drivers/dinput.c | 267 +++++++++++++++++++---------------------- 1 file changed, 121 insertions(+), 146 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 43d4a8134d..1ea410e7d4 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -394,140 +394,6 @@ static int16_t dinput_lightgun_aiming_state( return 0; } -static int16_t dinput_mouse_state(struct dinput_input *di, - unsigned port, unsigned id) -{ - int16_t state = 0; - - switch (id) - { - 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->mouse_l; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return di->mouse_r; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - if (di->mouse_wu) - state = 1; - di->mouse_wu = false; - return state; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - if (di->mouse_wd) - state = 1; - di->mouse_wd = false; - return state; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - if (di->mouse_hwu) - state = 1; - di->mouse_hwu = false; - return state; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - if (di->mouse_hwd) - state = 1; - di->mouse_hwd = false; - return state; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return di->mouse_m; - case RETRO_DEVICE_ID_MOUSE_BUTTON_4: - return di->mouse_b4; - case RETRO_DEVICE_ID_MOUSE_BUTTON_5: - return di->mouse_b5; - } - - return 0; -} - -static int16_t dinput_mouse_state_screen(struct dinput_input *di, - unsigned port, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return di->mouse_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return di->mouse_y; - default: - break; - } - - return dinput_mouse_state(di, port, id); -} - -static int16_t dinput_pointer_state(struct dinput_input *di, - unsigned idx, unsigned id, bool 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 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->mouse_l; - - 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 (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_POINTER_X: - return res_x; - case RETRO_DEVICE_ID_POINTER_Y: - return res_y; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return pointer_down; - default: - break; - } - - return 0; -} - static int16_t dinput_input_state( void *data, const input_device_driver_t *joypad, @@ -651,25 +517,134 @@ static int16_t dinput_input_state( return ret; } break; - case RETRO_DEVICE_MOUSE: - { - settings = config_get_ptr(); - if (settings->uints.input_mouse_index[port] == 0) - return dinput_mouse_state(di, port, id); - } - break; case RARCH_DEVICE_MOUSE_SCREEN: + settings = config_get_ptr(); + if (settings->uints.input_mouse_index[ port ] != 0) + break; + + switch (id) { - settings = config_get_ptr(); - if (settings->uints.input_mouse_index[ port ] == 0) - return dinput_mouse_state_screen(di, port, id); + case RETRO_DEVICE_ID_MOUSE_X: + return di->mouse_x; + case RETRO_DEVICE_ID_MOUSE_Y: + return di->mouse_y; + default: + 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; + case RETRO_DEVICE_ID_MOUSE_Y: + return di->mouse_rel_y; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return di->mouse_l; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return di->mouse_r; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + if (di->mouse_wu) + state = 1; + di->mouse_wu = false; + return state; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + if (di->mouse_wd) + state = 1; + di->mouse_wd = false; + return state; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + if (di->mouse_hwu) + state = 1; + di->mouse_hwu = false; + return state; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + if (di->mouse_hwd) + state = 1; + di->mouse_hwd = false; + return state; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return di->mouse_m; + case RETRO_DEVICE_ID_MOUSE_BUTTON_4: + return di->mouse_b4; + case RETRO_DEVICE_ID_MOUSE_BUTTON_5: + return di->mouse_b5; + } } break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return dinput_pointer_state(di, idx, id, - device == 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 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->mouse_l; + + 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; + default: + break; + } + } + break; case RETRO_DEVICE_LIGHTGUN: switch (id) { From 6f92c56ca3b0cfce59c587b661bf2c8ce28eec51 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 02:07:43 +0200 Subject: [PATCH 18/30] Simplify input drivers --- input/drivers/android_input.c | 247 ++++++++++++++-------------- input/drivers/cocoa_input.c | 179 +++++++++------------ input/drivers/dos_input.c | 20 +-- input/drivers/gx_input.c | 269 +++++++++++++++---------------- input/drivers/linuxraw_input.c | 4 +- input/drivers/ps2_input.c | 2 - input/drivers/ps3_input.c | 20 ++- input/drivers/psl1ght_input.c | 26 +-- input/drivers/psp_input.c | 97 ++++++----- input/drivers/rwebinput_input.c | 191 +++++++++++----------- input/drivers/sdl_input.c | 193 ++++++++++------------ input/drivers/switch_input.c | 170 +++++++++----------- input/drivers/udev_input.c | 16 +- input/drivers/wayland_input.c | 243 ++++++++++++---------------- input/drivers/wiiu_input.c | 50 +++--- input/drivers/winraw_input.c | 50 +++--- input/drivers/x11_input.c | 276 ++++++++++++++------------------ input/drivers/xenon360_input.c | 5 +- 18 files changed, 939 insertions(+), 1119 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 912fb789e1..30d71e5acf 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -84,9 +84,9 @@ enum { * Last port is used for keyboard state */ static uint8_t android_key_state[DEFAULT_MAX_PADS + 1][MAX_KEYS]; -#define android_keyboard_port_input_pressed(binds, id) (BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[(binds)[(id)].key])) +#define ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds, id) (BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[(binds)[(id)].key])) -#define android_keyboard_input_pressed(key) (BIT_GET(android_key_state[0], (key))) +#define ANDROID_KEYBOARD_INPUT_PRESSED(key) (BIT_GET(android_key_state[0], (key))) uint8_t *android_keyboard_state_get(unsigned port) { @@ -125,16 +125,16 @@ static int kbd_num = 0; enum { - AXIS_X = 0, - AXIS_Y = 1, - AXIS_Z = 11, - AXIS_RZ = 14, - AXIS_HAT_X = 15, - AXIS_HAT_Y = 16, + AXIS_X = 0, + AXIS_Y = 1, + AXIS_Z = 11, + AXIS_RZ = 14, + AXIS_HAT_X = 15, + AXIS_HAT_Y = 16, AXIS_LTRIGGER = 17, AXIS_RTRIGGER = 18, - AXIS_GAS = 22, - AXIS_BRAKE = 23 + AXIS_GAS = 22, + AXIS_BRAKE = 23 }; typedef struct state_device @@ -178,12 +178,12 @@ static typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue; #define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue) +#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState) + extern int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event); static typeof(AMotionEvent_getButtonState) *p_AMotionEvent_getButtonState; -#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState) - #ifdef HAVE_DYNAMIC static void *libandroid_handle; #endif @@ -460,8 +460,8 @@ static void engine_handle_dpad_getaxisvalue(android_input_t *android, float brake = AMotionEvent_getAxisValue(event, AXIS_BRAKE, motion_ptr); float gas = AMotionEvent_getAxisValue(event, AXIS_GAS, motion_ptr); - android->hat_state[port][0] = (int)hatx; - android->hat_state[port][1] = (int)haty; + android->hat_state[port][0] = (int)hatx; + android->hat_state[port][1] = (int)haty; /* XXX: this could be a loop instead, but do we really want to * loop through every axis? */ @@ -497,9 +497,10 @@ static bool android_input_init_handle(void) if ((p_AMotionEvent_getAxisValue = dlsym(RTLD_DEFAULT, "AMotionEvent_getAxisValue"))) - engine_handle_dpad = engine_handle_dpad_getaxisvalue; + engine_handle_dpad = engine_handle_dpad_getaxisvalue; - p_AMotionEvent_getButtonState = dlsym(RTLD_DEFAULT,"AMotionEvent_getButtonState"); + p_AMotionEvent_getButtonState = dlsym(RTLD_DEFAULT, + "AMotionEvent_getButtonState"); #endif pad_id1 = -1; @@ -551,7 +552,8 @@ static int android_check_quick_tap(android_input_t *android) * and then not touched again for 200ms * If so then return true and deactivate quick tap timer */ retro_time_t now = cpu_features_get_time_usec(); - if (android->quick_tap_time && (now/1000 - android->quick_tap_time/1000000) >= 200) + if (android->quick_tap_time && + (now / 1000 - android->quick_tap_time / 1000000) >= 200) { android->quick_tap_time = 0; return 1; @@ -560,74 +562,6 @@ static int android_check_quick_tap(android_input_t *android) return 0; } -static int16_t android_mouse_state(android_input_t *android, unsigned id) -{ - int val = 0; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - val = android->mouse_l || android_check_quick_tap(android); - break; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - val = android->mouse_r; - break; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - val = android->mouse_m; - break; - case RETRO_DEVICE_ID_MOUSE_X: - val = android->mouse_x_delta; - android->mouse_x_delta = 0; /* flush delta after it has been read */ - break; - case RETRO_DEVICE_ID_MOUSE_Y: - val = android->mouse_y_delta; /* flush delta after it has been read */ - android->mouse_y_delta = 0; - break; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - val = android->mouse_wu; - android->mouse_wu = 0; - break; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - val = android->mouse_wd; - android->mouse_wd = 0; - break; - } - - return val; -} - -static int16_t android_lightgun_device_state(android_input_t *android, unsigned id) -{ - int val = 0; - switch (id) - { - case RETRO_DEVICE_ID_LIGHTGUN_X: - val = android->mouse_x_delta; - android->mouse_x_delta = 0; /* flush delta after it has been read */ - break; - case RETRO_DEVICE_ID_LIGHTGUN_Y: - val = android->mouse_y_delta; /* flush delta after it has been read */ - android->mouse_y_delta = 0; - break; - case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - val = android->mouse_l || android_check_quick_tap(android); - break; - case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: - val = android->mouse_m; - break; - case RETRO_DEVICE_ID_LIGHTGUN_TURBO: - val = android->mouse_r; - break; - case RETRO_DEVICE_ID_LIGHTGUN_START: - val = android->mouse_m && android->mouse_r; - break; - case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: - val = android->mouse_m && android->mouse_l; - break; - } - - return val; -} - static INLINE void android_mouse_calculate_deltas(android_input_t *android, AInputEvent *event,size_t motion_ptr) { @@ -646,16 +580,22 @@ static INLINE void android_mouse_calculate_deltas(android_input_t *android, y_scale = 2 * (float)geom->base_height / (float)custom_vp->height; } - /* This axis is only available on Android Nougat and on Android devices with NVIDIA extensions */ + /* This axis is only available on Android Nougat and on + * Android devices with NVIDIA extensions */ if (p_AMotionEvent_getAxisValue) { - x = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_X, motion_ptr); - y = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_Y, motion_ptr); + x = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_X, + motion_ptr); + y = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_Y, + motion_ptr); } - /* If AXIS_RELATIVE had 0 values it might be because we're not running Android Nougat or on a device - * with NVIDIA extension, so re-calculate deltas based on AXIS_X and AXIS_Y. This has limitations - * compared to AXIS_RELATIVE because once the Android mouse cursor hits the edge of the screen it is + /* If AXIS_RELATIVE had 0 values it might be because we're not + * running Android Nougat or on a device + * with NVIDIA extension, so re-calculate deltas based on + * AXIS_X and AXIS_Y. This has limitations + * compared to AXIS_RELATIVE because once the Android mouse cursor + * hits the edge of the screen it is * not possible to move the in-game mouse any further in that direction. */ if (!x && !y) @@ -692,13 +632,14 @@ static INLINE void android_input_poll_event_type_motion( /* getButtonState requires API level 14 */ if (p_AMotionEvent_getButtonState) { - btn = (int)AMotionEvent_getButtonState(event); + 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); - btn = (int)AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, motion_ptr); + btn = (int)AMotionEvent_getAxisValue(event, + AMOTION_EVENT_AXIS_VSCROLL, motion_ptr); if (btn > 0) android->mouse_wu = btn; @@ -759,11 +700,13 @@ static INLINE void android_input_poll_event_type_motion( if ((AMotionEvent_getEventTime(event) - android->quick_tap_time)/1000000 < 200) { android->quick_tap_time = 0; - android->mouse_l = 1; + android->mouse_l = 1; } } - if ((action == AMOTION_EVENT_ACTION_MOVE || action == AMOTION_EVENT_ACTION_HOVER_MOVE) && ENABLE_TOUCH_SCREEN_MOUSE) + if (( action == AMOTION_EVENT_ACTION_MOVE + || action == AMOTION_EVENT_ACTION_HOVER_MOVE) + && ENABLE_TOUCH_SCREEN_MOUSE) android_mouse_calculate_deltas(android,event,motion_ptr); for (motion_ptr = 0; motion_ptr < pointer_max; motion_ptr++) @@ -812,7 +755,8 @@ static bool android_is_keyboard_id(int id) static INLINE void android_input_poll_event_type_keyboard( AInputEvent *event, int keycode, int *handled) { - int keydown = (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN); + int keydown = (AKeyEvent_getAction(event) + == AKEY_EVENT_ACTION_DOWN); unsigned keyboardcode = input_keymaps_translate_keysym_to_rk(keycode); /* Set keyboard modifier based on shift,ctrl and alt state */ uint16_t mod = 0; @@ -825,7 +769,8 @@ static INLINE void android_input_poll_event_type_keyboard( if (meta & AMETA_SHIFT_ON) mod |= RETROKMOD_SHIFT; - input_keyboard_event(keydown, keyboardcode, keyboardcode, mod, RETRO_DEVICE_KEYBOARD); + input_keyboard_event(keydown, keyboardcode, + keyboardcode, mod, RETRO_DEVICE_KEYBOARD); if ((keycode == AKEYCODE_VOLUME_UP || keycode == AKEYCODE_VOLUME_DOWN)) *handled = 0; @@ -1229,7 +1174,8 @@ static void android_input_poll_input(android_input_t *android, while (AInputQueue_getEvent(android_app->inputQueue, &event) >= 0) { int32_t handled = 1; - int predispatched = AInputQueue_preDispatchEvent(android_app->inputQueue, event); + int predispatched = AInputQueue_preDispatchEvent( + android_app->inputQueue, event); int source = AInputEvent_getSource(event); int type_event = AInputEvent_getType(event); int id = android_input_get_id(event); @@ -1243,7 +1189,8 @@ static void android_input_poll_input(android_input_t *android, { case AINPUT_EVENT_TYPE_MOTION: /* Only handle events from a touchscreen or mouse */ - if ((source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE))) + if ((source & (AINPUT_SOURCE_TOUCHSCREEN + | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE))) android_input_poll_event_type_motion(android, event, port, source, vibrate_on_keypress); else @@ -1257,8 +1204,11 @@ static void android_input_poll_input(android_input_t *android, { if (!predispatched) { - android_input_poll_event_type_keyboard(event, keycode, &handled); - android_input_poll_event_type_key(android_app, event, ANDROID_KEYBOARD_PORT, keycode, source, type_event, &handled); + android_input_poll_event_type_keyboard( + event, keycode, &handled); + android_input_poll_event_type_key( + android_app, event, ANDROID_KEYBOARD_PORT, + keycode, source, type_event, &handled); } } else @@ -1284,7 +1234,8 @@ static void android_input_poll_user(android_input_t *android) && android_app->accelerometerSensor) { ASensorEvent event; - while (ASensorEventQueue_getEvents(android_app->sensorEventQueue, &event, 1) > 0) + while (ASensorEventQueue_getEvents( + android_app->sensorEventQueue, &event, 1) > 0) { android->accelerometer_state.x = event.acceleration.x; android->accelerometer_state.y = event.acceleration.y; @@ -1322,7 +1273,7 @@ static void android_input_poll(void *data, const void *joypad_data) while ((ident = ALooper_pollAll((input_config_binds[0][RARCH_PAUSE_TOGGLE].valid && input_key_pressed(joypad, RARCH_PAUSE_TOGGLE, - android_keyboard_port_input_pressed(input_config_binds[0], + ANDROID_KEYBOARD_PORT_INPUT_PRESSED(input_config_binds[0], RARCH_PAUSE_TOGGLE))) ? -1 : settings->uints.input_block_timeout, NULL, NULL, NULL)) >= 0) @@ -1414,7 +1365,7 @@ static int16_t android_input_state( { if (binds[port][i].valid) { - if (android_keyboard_port_input_pressed(binds[port], i)) + if (ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], i)) ret |= (1 << i); } } @@ -1428,7 +1379,7 @@ static int16_t android_input_state( button_is_pressed( joypad, joypad_info, binds[port], port, id) - || android_keyboard_port_input_pressed(binds[port], id) + || ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], id) ) return 1; } @@ -1437,11 +1388,69 @@ static int16_t android_input_state( case RETRO_DEVICE_ANALOG: break; case RETRO_DEVICE_KEYBOARD: - return (id < RETROK_LAST) && BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[id]); + return (id < RETROK_LAST) + && BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], + rarch_keysym_lut[id]); case RETRO_DEVICE_MOUSE: - return android_mouse_state(android, id); + { + int val = 0; + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + return android->mouse_l || android_check_quick_tap(android); + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return android->mouse_r; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return android->mouse_m; + case RETRO_DEVICE_ID_MOUSE_X: + val = android->mouse_x_delta; + android->mouse_x_delta = 0; + /* flush delta after it has been read */ + return val; + case RETRO_DEVICE_ID_MOUSE_Y: + val = android->mouse_y_delta; + android->mouse_y_delta = 0; + /* flush delta after it has been read */ + return val; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + val = android->mouse_wu; + android->mouse_wu = 0; + return val; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + val = android->mouse_wd; + android->mouse_wd = 0; + return val; + } + } + break; case RETRO_DEVICE_LIGHTGUN: - return android_lightgun_device_state(android, id); + { + int val = 0; + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_X: + val = android->mouse_x_delta; + android->mouse_x_delta = 0; + /* flush delta after it has been read */ + return val; + case RETRO_DEVICE_ID_LIGHTGUN_Y: + val = android->mouse_y_delta; + android->mouse_y_delta = 0; + /* flush delta after it has been read */ + return val; + case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: + return android->mouse_l || android_check_quick_tap(android); + case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: + return android->mouse_m; + case RETRO_DEVICE_ID_LIGHTGUN_TURBO: + return android->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_START: + return android->mouse_m && android->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + return android->mouse_m && android->mouse_l; + } + } + break; case RETRO_DEVICE_POINTER: switch (id) { @@ -1457,9 +1466,10 @@ static int16_t android_input_state( return android->pointer_count; case RARCH_DEVICE_ID_POINTER_BACK: { - const struct retro_keybind *keyptr = &input_autoconf_binds[0][RARCH_MENU_TOGGLE]; + const struct retro_keybind *keyptr = + &input_autoconf_binds[0][RARCH_MENU_TOGGLE]; if (keyptr->joykey == 0) - return android_keyboard_input_pressed(AKEYCODE_BACK); + return ANDROID_KEYBOARD_INPUT_PRESSED(AKEYCODE_BACK); } } break; @@ -1478,9 +1488,10 @@ static int16_t android_input_state( return android->pointer_count; case RARCH_DEVICE_ID_POINTER_BACK: { - const struct retro_keybind *keyptr = &input_autoconf_binds[0][RARCH_MENU_TOGGLE]; + const struct retro_keybind *keyptr = + &input_autoconf_binds[0][RARCH_MENU_TOGGLE]; if (keyptr->joykey == 0) - return android_keyboard_input_pressed(AKEYCODE_BACK); + return ANDROID_KEYBOARD_INPUT_PRESSED(AKEYCODE_BACK); } } break; @@ -1513,8 +1524,6 @@ static void android_input_free_input(void *data) static uint64_t android_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_POINTER) | @@ -1571,7 +1580,7 @@ static bool android_input_set_sensor_state(void *data, unsigned port, BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE); return true; default: - return false; + break; } return false; @@ -1595,12 +1604,6 @@ static float android_input_get_sensor_input(void *data, return 0; } -static void android_input_grab_mouse(void *data, bool state) -{ - (void)data; - (void)state; -} - static bool android_input_set_rumble( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, @@ -1622,7 +1625,7 @@ input_driver_t input_android = { android_input_get_capabilities, "android", - android_input_grab_mouse, + NULL, /* grab_mouse */ NULL, android_input_set_rumble }; diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index 3b1eb478a7..66e9445b1d 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -86,102 +86,6 @@ static void cocoa_input_poll(void *data) } } -static int16_t cocoa_mouse_state(cocoa_input_data_t *apple, - unsigned id) -{ - int16_t val; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - val = apple->window_pos_x - apple->mouse_x_last; - apple->mouse_x_last = apple->window_pos_x; - return val; - case RETRO_DEVICE_ID_MOUSE_Y: - val = apple->window_pos_y - apple->mouse_y_last; - apple->mouse_y_last = apple->window_pos_y; - return val; - case RETRO_DEVICE_ID_MOUSE_LEFT: - return apple->mouse_buttons & 1; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return apple->mouse_buttons & 2; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - return apple->mouse_wu; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - return apple->mouse_wd; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - return apple->mouse_wl; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - return apple->mouse_wr; - } - - return 0; -} - -static int16_t cocoa_mouse_state_screen(cocoa_input_data_t *apple, - unsigned id) -{ - int16_t val; -#ifndef IOS - float backing_scale_factor = get_backing_scale_factor(); -#endif - - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - val = apple->window_pos_x; - break; - case RETRO_DEVICE_ID_MOUSE_Y: - val = apple->window_pos_y; - break; - default: - return cocoa_mouse_state(apple, id); - } - -#ifndef IOS - val *= backing_scale_factor; -#endif - return val; -} - -static int16_t cocoa_pointer_state(cocoa_input_data_t *apple, - unsigned device, unsigned idx, unsigned id) -{ - 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) - { - x = touch->full_x; - y = touch->full_y; - } - - 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; - } - } - - return 0; -} - static int16_t cocoa_input_state( void *data, const input_device_driver_t *joypad, @@ -249,12 +153,87 @@ static int16_t cocoa_input_state( case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && apple_key_state[rarch_keysym_lut[(enum retro_key)id]]; case RETRO_DEVICE_MOUSE: - return cocoa_mouse_state(apple, id); case RARCH_DEVICE_MOUSE_SCREEN: - return cocoa_mouse_state_screen(apple, id); + { + int16_t val = 0; + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_X: + if (device == RARCH_DEVICE_MOUSE_SCREEN) + { +#ifdef IOS + return apple->window_pos_x; +#else + return apple->window_pos_x * get_backing_scale_factor(); +#endif + } + val = apple->window_pos_x - apple->mouse_x_last; + apple->mouse_x_last = apple->window_pos_x; + return val; + case RETRO_DEVICE_ID_MOUSE_Y: + if (device == RARCH_DEVICE_MOUSE_SCREEN) + { +#ifdef IOS + return apple->window_pos_y; +#else + return apple->window_pos_y * get_backing_scale_factor(); +#endif + } + val = apple->window_pos_y - apple->mouse_y_last; + apple->mouse_y_last = apple->window_pos_y; + return val; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return apple->mouse_buttons & 1; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return apple->mouse_buttons & 2; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + return apple->mouse_wu; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + return apple->mouse_wd; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + return apple->mouse_wl; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + return apple->mouse_wr; + } + } + break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return cocoa_pointer_state(apple, device, idx, id); + { + 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) + { + x = touch->full_x; + y = touch->full_y; + } + + 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; + } + } + } + break; } return 0; @@ -292,8 +271,6 @@ static bool cocoa_input_set_rumble( static uint64_t cocoa_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_MOUSE) | diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 46a8b6064e..055f8afbcd 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -40,14 +40,6 @@ typedef struct dos_input /* TODO/FIXME - static globals */ static uint16_t dos_key_state[DEFAULT_MAX_PADS+1][MAX_KEYS]; -static bool dos_keyboard_port_input_pressed( - const struct retro_keybind *binds, unsigned id) -{ - if (id < RARCH_BIND_LIST_END) - return dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[id].key]]; - return false; -} - uint16_t *dos_keyboard_state_get(unsigned port) { return dos_key_state[port]; @@ -74,7 +66,7 @@ static int16_t dos_input_state( unsigned idx, unsigned id) { - dos_input_t *dos = (dos_input_t*)data; + dos_input_t *dos = (dos_input_t*)data; if (port > 0) return 0; @@ -93,7 +85,8 @@ static int16_t dos_input_state( if (binds[port][i].valid) { if (id < RARCH_BIND_LIST_END) - if (dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[i].key]]) + if (dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[i].key]]) ret |= (1 << i); } } @@ -108,7 +101,9 @@ static int16_t dos_input_state( button_is_pressed( joypad, joypad_info, binds[port], port, id) - || dos_keyboard_port_input_pressed(binds[port], id) + || (id < RARCH_BIND_LIST_END + && dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[port][id].key]]) ) return 1; } @@ -116,7 +111,8 @@ static int16_t dos_input_state( break; case RETRO_DEVICE_KEYBOARD: if (id < RARCH_BIND_LIST_END) - return (dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[id].key]]); + return (dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[id].key]]); break; } diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 36f453f812..19e3ddb7d8 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -22,6 +22,7 @@ #include #include +#include #include @@ -35,7 +36,9 @@ #ifdef HW_RVL /* gx joypad functions */ bool gxpad_mousevalid(unsigned port); -void gx_joypad_read_mouse(unsigned port, int *irx, int *iry, uint32_t *button); + +void gx_joypad_read_mouse(unsigned port, + int *irx, int *iry, uint32_t *button); typedef struct { @@ -48,96 +51,13 @@ typedef struct typedef struct gx_input { #ifdef HW_RVL - int mouse_max; gx_input_mouse_t *mouse; + int mouse_max; #else void *empty; #endif } gx_input_t; -#ifdef HW_RVL -static int16_t gx_lightgun_state(gx_input_t *gx, - unsigned id, uint16_t joy_idx) -{ - struct video_viewport vp = {0}; - video_driver_get_viewport_info(&vp); - int16_t res_x = 0; - int16_t res_y = 0; - int16_t res_screen_x = 0; - int16_t res_screen_y = 0; - int16_t x = 0; - int16_t y = 0; - - vp.x = 0; - vp.y = 0; - vp.width = 0; - vp.height = 0; - vp.full_width = 0; - vp.full_height = 0; - - x = gx->mouse[joy_idx].x_abs; - y = gx->mouse[joy_idx].y_abs; - - if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - switch (id) - { - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: - return res_screen_x; - case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: - return res_screen_y; - case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_TRIGGER); - case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_A); - case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_B); - case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_C); - case RETRO_DEVICE_ID_LIGHTGUN_START: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_START); - case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_SELECT); - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !gxpad_mousevalid(joy_idx); - default: - return 0; - } - - return 0; -} - -static int16_t gx_mouse_state(gx_input_t *gx, unsigned id, uint16_t joy_idx) -{ - settings_t *settings = config_get_ptr(); - unsigned input_mouse_scale = settings->uints.input_mouse_scale; - int x_scale = input_mouse_scale; - int y_scale = input_mouse_scale; - int x = (gx->mouse[joy_idx].x_abs - - gx->mouse[joy_idx].x_last) * x_scale; - int y = (gx->mouse[joy_idx].y_abs - - gx->mouse[joy_idx].y_last) * y_scale; - - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return x; - case RETRO_DEVICE_ID_MOUSE_Y: - return y; - case RETRO_DEVICE_ID_MOUSE_LEFT: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_MOUSE_LEFT); - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_MOUSE_RIGHT); - default: - break; - } - - return 0; -} -#endif - static int16_t gx_input_state( void *data, const input_device_driver_t *joypad, @@ -172,10 +92,92 @@ static int16_t gx_input_state( break; #ifdef HW_RVL case RETRO_DEVICE_MOUSE: - return gx_mouse_state(gx, id, joypad_info->joy_idx); + { + settings_t *settings = config_get_ptr(); + uint16_t joy_idx = joypad_info->joy_idx; + unsigned input_mouse_scale = settings->uints.input_mouse_scale; + int x_scale = input_mouse_scale; + int y_scale = input_mouse_scale; + int x = (gx->mouse[joy_idx].x_abs + - gx->mouse[joy_idx].x_last) * x_scale; + int y = (gx->mouse[joy_idx].y_abs + - gx->mouse[joy_idx].y_last) * y_scale; + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_X: + return x; + case RETRO_DEVICE_ID_MOUSE_Y: + return y; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_MOUSE_LEFT); + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_MOUSE_RIGHT); + default: + break; + } + } + break; case RETRO_DEVICE_LIGHTGUN: - return gx_lightgun_state(gx, id, joypad_info->joy_idx); + { + struct video_viewport vp = {0}; + uint16_t joy_idx = joypad_info->joy_idx; + int16_t res_x = 0; + int16_t res_y = 0; + int16_t res_screen_x = 0; + int16_t res_screen_y = 0; + int16_t x = 0; + int16_t y = 0; + + video_driver_get_viewport_info(&vp); + + vp.x = 0; + vp.y = 0; + vp.width = 0; + vp.height = 0; + vp.full_width = 0; + vp.full_height = 0; + + x = gx->mouse[joy_idx].x_abs; + y = gx->mouse[joy_idx].y_abs; + + if (video_driver_translate_coord_viewport_wrap(&vp, x, y, + &res_x, &res_y, &res_screen_x, &res_screen_y)) + { + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: + return res_screen_x; + case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: + return res_screen_y; + case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_TRIGGER); + case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_A); + case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_B); + case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_C); + case RETRO_DEVICE_ID_LIGHTGUN_START: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_START); + case RETRO_DEVICE_ID_LIGHTGUN_SELECT: + return gx->mouse[joy_idx].button & + (1 << RETRO_DEVICE_ID_LIGHTGUN_SELECT); + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return !gxpad_mousevalid(joy_idx); + default: + break; + } + } + } + break; #endif } @@ -214,14 +216,11 @@ static void *gx_input_init(const char *joypad_driver) } #ifdef HW_RVL -static inline int gx_count_mouse(gx_input_t *gx) +static INLINE int rvl_count_mouse(gx_input_t *gx) { unsigned i; int count = 0; - if (!gx) - return 0; - for (i = 0; i < DEFAULT_MAX_PADS; i++) { const char *joypad_name = joypad_driver_name(i); @@ -233,63 +232,61 @@ static inline int gx_count_mouse(gx_input_t *gx) return count; } -static void gx_input_poll_mouse(gx_input_t *gx) -{ - int count = gx_count_mouse(gx); - - if (gx && count > 0) - { - unsigned i; - if (count != gx->mouse_max) - { - gx_input_mouse_t *tmp = (gx_input_mouse_t*)realloc( - gx->mouse, count * sizeof(gx_input_mouse_t)); - if (!tmp) - free(gx->mouse); - else - { - unsigned i; - gx->mouse = tmp; - gx->mouse_max = count; - - for (i = 0; i < gx->mouse_max; i++) - { - gx->mouse[i].x_last = 0; - gx->mouse[i].y_last = 0; - } - } - } - - for (i = 0; i < gx->mouse_max; i++) - { - gx->mouse[i].x_last = gx->mouse[i].x_abs; - gx->mouse[i].y_last = gx->mouse[i].y_abs; - gx_joypad_read_mouse(i, &gx->mouse[i].x_abs, - &gx->mouse[i].y_abs, &gx->mouse[i].button); - } - } -} - static void rvl_input_poll(void *data) { gx_input_t *gx = (gx_input_t*)data; if (gx && gx->mouse) - gx_input_poll_mouse(gx); -} -#endif + { + int count = rvl_count_mouse(gx); -static uint64_t gx_input_get_capabilities(void *data) + if (gx && count > 0) + { + unsigned i; + if (count != gx->mouse_max) + { + gx_input_mouse_t *tmp = (gx_input_mouse_t*)realloc( + gx->mouse, count * sizeof(gx_input_mouse_t)); + if (!tmp) + free(gx->mouse); + else + { + unsigned i; + gx->mouse = tmp; + gx->mouse_max = count; + + for (i = 0; i < gx->mouse_max; i++) + { + gx->mouse[i].x_last = 0; + gx->mouse[i].y_last = 0; + } + } + } + + for (i = 0; i < gx->mouse_max; i++) + { + gx->mouse[i].x_last = gx->mouse[i].x_abs; + gx->mouse[i].y_last = gx->mouse[i].y_abs; + gx_joypad_read_mouse(i, &gx->mouse[i].x_abs, + &gx->mouse[i].y_abs, &gx->mouse[i].button); + } + } + } +} + +static uint64_t rvl_input_get_capabilities(void *data) { -#ifdef HW_RVL return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | (1 << RETRO_DEVICE_MOUSE) | (1 << RETRO_DEVICE_LIGHTGUN); +} #else +static uint64_t gx_input_get_capabilities(void *data) +{ return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); -#endif } +#endif input_driver_t input_gx = { gx_input_init, @@ -302,7 +299,11 @@ input_driver_t input_gx = { gx_input_free_input, NULL, NULL, +#ifdef HW_RVL + rvl_input_get_capabilities, +#else gx_input_get_capabilities, +#endif "gx", NULL, /* grab_mouse */ diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 2cb769b4a3..b5c0750a44 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -203,8 +203,8 @@ static void linuxraw_input_poll(void *data) if (c == KEY_C && (linuxraw->state[KEY_LEFTCTRL] || linuxraw->state[KEY_RIGHTCTRL])) kill(getpid(), SIGINT); - pressed = !(c & 0x80); - c &= ~0x80; + pressed = !(c & 0x80); + c &= ~0x80; /* ignore extended scancodes */ if (!c) diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 08782a4358..209abb0901 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -82,8 +82,6 @@ static void* ps2_input_initialize(const char *joypad_driver) static uint64_t ps2_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 043d3d4835..2e97a3778f 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -53,18 +53,16 @@ typedef struct ps3_input #endif } ps3_input_t; +#ifdef HAVE_MOUSE static void ps3_input_poll(void *data) { -#ifdef HAVE_MOUSE CellMouseInfo mouse_info; ps3_input_t *ps3 = (ps3_input_t*)data; cellMouseGetInfo(&mouse_info); ps3->mice_connected = mouse_info.now_connect; -#endif } -#ifdef HAVE_MOUSE static int16_t ps3_mouse_device_state(ps3_input_t *ps3, unsigned user, unsigned id) { @@ -129,16 +127,13 @@ static int16_t ps3_input_state( { /* Fixed range of 0x000 - 0x3ff */ case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X: - retval = ps3->accelerometer_state[port].x; - break; + return ps3->accelerometer_state[port].x; case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y: - retval = ps3->accelerometer_state[port].y; - break; + return ps3->accelerometer_state[port].y; case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z: - retval = ps3->accelerometer_state[port].z; - break; + return ps3->accelerometer_state[port].z; default: - retval = 0; + break; } break; #endif @@ -179,7 +174,6 @@ static void* ps3_input_init(const char *joypad_driver) static uint64_t ps3_input_get_capabilities(void *data) { - (void)data; return #ifdef HAVE_MOUSE (1 << RETRO_DEVICE_MOUSE) | @@ -229,7 +223,11 @@ static bool ps3_input_set_rumble( input_driver_t input_ps3 = { ps3_input_init, +#ifdef HAVE_MOUSE ps3_input_poll, +#else + NULL, /* poll */ +#endif ps3_input_state, ps3_input_free_input, ps3_input_set_sensor_state, diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index 0914344423..0f604762ae 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -112,12 +112,16 @@ static void ps3_input_poll(void *data) /* Set keyboard modifier based on shift,ctrl and alt state */ uint16_t mod = 0; - if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_alt || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_alt) + if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_alt + || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_alt) mod |= RETROKMOD_ALT; - if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_ctrl || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_ctrl) + if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_ctrl + || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_ctrl) mod |= RETROKMOD_CTRL; - if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_shift || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_shift) + if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_shift + || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_shift) mod |= RETROKMOD_SHIFT; + /* TODO: windows keys. */ for (j = 0; j < last_kbdata[i].nb_keycode; j++) @@ -127,11 +131,13 @@ static void ps3_input_poll(void *data) int newly_depressed = 1; for (k = 0; k < MAX_KB_PORT_NUM; i++) + { if (ps3->kbdata[i].keycode[k] == code) { newly_depressed = 0; break; } + } if (newly_depressed) { @@ -164,12 +170,8 @@ static void ps3_input_poll(void *data) } } -#ifdef HAVE_MOUSE -static int16_t ps3_mouse_device_state(ps3_input_t *ps3, - unsigned user, unsigned id) { } -#endif - -static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id) +static bool psl1ght_keyboard_port_input_pressed( + ps3_input_t *ps3, unsigned id) { int code; unsigned i, j; @@ -183,8 +185,8 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id) { for (j = 0; j < MAX_KB_PORT_NUM; j++) { - if (ps3->kbinfo.status[j] && (ps3->kbdata[j].mkey._KbMkeyU.mkeys & - (1 << i))) + if (ps3->kbinfo.status[j] + && (ps3->kbdata[j].mkey._KbMkeyU.mkeys & (1 << i))) return true; } return false; @@ -197,11 +199,13 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id) for (i = 0; i < MAX_KB_PORT_NUM; i++) { if (ps3->kbinfo.status[i]) + { for (j = 0; j < ps3->kbdata[i].nb_keycode; j++) { if (ps3->kbdata[i].keycode[j] == code) return true; } + } } return false; diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 158ee7a966..237279ce91 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -55,7 +55,6 @@ * fix game focus toggle */ #ifdef VITA - #include "../input_keymaps.h" uint8_t modifier_lut[VITA_NUM_MODIFIERS][2] = @@ -91,7 +90,7 @@ typedef struct psp_input static void vita_input_poll(void *data) { - psp_input_t *psp = (psp_input_t*)data; + psp_input_t *psp = (psp_input_t*)data; unsigned int i = 0; int key_sym = 0; unsigned key_code = 0; @@ -99,7 +98,6 @@ static void vita_input_poll(void *data) uint16_t mod = 0; uint8_t modifiers[2] = { 0, 0 }; bool key_held = false; - int numReports = 0; int mouse_velocity_x = 0; int mouse_velocity_y = 0; SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT]; @@ -107,7 +105,7 @@ static void vita_input_poll(void *data) if (psp->keyboard_hid_handle > 0) { - numReports = sceHidKeyboardRead( + int numReports = sceHidKeyboardRead( psp->keyboard_hid_handle, (SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT); @@ -135,9 +133,9 @@ static void vita_input_poll(void *data) for (i = 0; i < VITA_NUM_MODIFIERS; i++) { - key_sym = (int) modifier_lut[i][0]; - mod_code = modifier_lut[i][1]; - key_code = input_keymaps_translate_keysym_to_rk(key_sym); + key_sym = (int)modifier_lut[i][0]; + mod_code = modifier_lut[i][1]; + key_code = input_keymaps_translate_keysym_to_rk(key_sym); if (i < 8) key_held = (modifiers[0] & mod_code); else @@ -189,7 +187,7 @@ static void vita_input_poll(void *data) if (psp->mouse_hid_handle > 0) { - numReports = sceHidMouseRead(psp->mouse_hid_handle, + int numReports = sceHidMouseRead(psp->mouse_hid_handle, (SceHidMouseReport**)&m_reports, SCE_HID_MAX_REPORT); if (numReports > 0) @@ -219,50 +217,19 @@ static void vita_input_poll(void *data) } } - psp->mouse_x_delta = mouse_velocity_x; - psp->mouse_y_delta = mouse_velocity_y; - psp->mouse_x += mouse_velocity_x; - psp->mouse_y += mouse_velocity_y; + psp->mouse_x_delta = mouse_velocity_x; + psp->mouse_y_delta = mouse_velocity_y; + psp->mouse_x += mouse_velocity_x; + psp->mouse_y += mouse_velocity_y; if (psp->mouse_x < 0) - psp->mouse_x = 0; + psp->mouse_x = 0; else if (psp->mouse_x > MOUSE_MAX_X) - psp->mouse_x = MOUSE_MAX_X; + psp->mouse_x = MOUSE_MAX_X; if (psp->mouse_y < 0) - psp->mouse_y = 0; + psp->mouse_y = 0; else if (psp->mouse_y > MOUSE_MAX_Y) - psp->mouse_y = MOUSE_MAX_Y; -} - -static int16_t psp_input_mouse_state( - psp_input_t *psp, unsigned id, bool screen) -{ - int val = 0; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - return psp->mouse_button_left; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return psp->mouse_button_right; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return psp->mouse_button_middle; - case RETRO_DEVICE_ID_MOUSE_X: - if (screen) - return psp->mouse_x; - - val = psp->mouse_x_delta; - psp->mouse_x_delta = 0; /* flush delta after it has been read */ - break; - case RETRO_DEVICE_ID_MOUSE_Y: - if (screen) - return psp->mouse_y; - - val = psp->mouse_y_delta; - psp->mouse_y_delta = 0; /* flush delta after it has been read */ - break; - } - - return val; + psp->mouse_y = MOUSE_MAX_Y; } #else typedef struct psp_input @@ -307,13 +274,39 @@ static int16_t psp_input_state( break; #ifdef VITA case RETRO_DEVICE_KEYBOARD: - return ((id < RETROK_LAST) && psp->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]); - break; + return ((id < RETROK_LAST) && + psp->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]); case RETRO_DEVICE_MOUSE: - return psp_input_mouse_state(psp, id, false); - break; case RARCH_DEVICE_MOUSE_SCREEN: - return psp_input_mouse_state(psp, id, true); + { + bool screen = device == RARCH_DEVICE_MOUSE_SCREEN; + int val = 0; + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + return psp->mouse_button_left; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return psp->mouse_button_right; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return psp->mouse_button_middle; + case RETRO_DEVICE_ID_MOUSE_X: + if (screen) + return psp->mouse_x; + + val = psp->mouse_x_delta; + psp->mouse_x_delta = 0; + /* flush delta after it has been read */ + break; + case RETRO_DEVICE_ID_MOUSE_Y: + if (screen) + return psp->mouse_y; + val = psp->mouse_y_delta; + psp->mouse_y_delta = 0; + /* flush delta after it has been read */ + break; + } + return val; + } break; #endif } diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index 1fd38fedfd..fc4fd74f19 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -220,17 +220,16 @@ static void rwebinput_generate_lut(void) /* sanity check: make sure there's no collisions */ for (j = 0; j < i; j++) - { retro_assert(rarch_key_map_rwebinput[j].sym != crc); - } - key_map->rk = key_to_code->rk; + key_map->rk = key_to_code->rk; key_map->sym = crc; } /* set terminating entry */ - key_map = &rarch_key_map_rwebinput[ARRAY_SIZE(rarch_key_map_rwebinput) - 1]; - key_map->rk = RETROK_UNKNOWN; + key_map = &rarch_key_map_rwebinput[ + ARRAY_SIZE(rarch_key_map_rwebinput) - 1]; + key_map->rk = RETROK_UNKNOWN; key_map->sym = 0; } @@ -301,24 +300,27 @@ static void *rwebinput_input_init(const char *joypad_driver) rwebinput_generate_lut(); - r = emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, - rwebinput_keyboard_cb); + r = emscripten_set_keydown_callback( + EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, + rwebinput_keyboard_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( "[EMSCRIPTEN/INPUT] failed to create keydown callback: %d\n", r); } - r = emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, - rwebinput_keyboard_cb); + r = emscripten_set_keyup_callback( + EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, + rwebinput_keyboard_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( "[EMSCRIPTEN/INPUT] failed to create keydown callback: %d\n", r); } - r = emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, - rwebinput_keyboard_cb); + r = emscripten_set_keypress_callback( + EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, + rwebinput_keyboard_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( @@ -326,7 +328,7 @@ static void *rwebinput_input_init(const char *joypad_driver) } r = emscripten_set_mousedown_callback("#canvas", rwebinput, false, - rwebinput_mouse_cb); + rwebinput_mouse_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( @@ -334,7 +336,7 @@ static void *rwebinput_input_init(const char *joypad_driver) } r = emscripten_set_mouseup_callback("#canvas", rwebinput, false, - rwebinput_mouse_cb); + rwebinput_mouse_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( @@ -342,15 +344,16 @@ static void *rwebinput_input_init(const char *joypad_driver) } r = emscripten_set_mousemove_callback("#canvas", rwebinput, false, - rwebinput_mouse_cb); + rwebinput_mouse_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( "[EMSCRIPTEN/INPUT] failed to create mousemove callback: %d\n", r); } - r = emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, - rwebinput_wheel_cb); + r = emscripten_set_wheel_callback( + EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false, + rwebinput_wheel_cb); if (r != EMSCRIPTEN_RESULT_SUCCESS) { RARCH_ERR( @@ -360,10 +363,6 @@ static void *rwebinput_input_init(const char *joypad_driver) input_keymaps_init_keyboard_lut(rarch_key_map_rwebinput); return rwebinput; - -error: - free(rwebinput); - return NULL; } static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key) @@ -374,61 +373,6 @@ static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key) return rwebinput->keys[key]; } -static int16_t rwebinput_pointer_device_state( - rwebinput_mouse_state_t *mouse, - unsigned id, bool screen) -{ - 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; - 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, mouse->x, mouse->x, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - 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); - - switch (id) - { - case RETRO_DEVICE_ID_POINTER_X: - if (inside) - return res_x; - break; - case RETRO_DEVICE_ID_POINTER_Y: - if (inside) - return res_y; - break; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTNL)); - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; - default: - break; - } - - return 0; -} - static int16_t rwebinput_mouse_state( rwebinput_mouse_state_t *mouse, unsigned id, bool screen) @@ -484,7 +428,8 @@ static int16_t rwebinput_is_pressed( if (port == 0 && !!rwebinput_mouse_state(&rwebinput->mouse, bind->mbutton, false)) return 1; - if ((uint16_t)joykey != NO_BTN && joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) + if ((uint16_t)joykey != NO_BTN + && joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) return 1; if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) @@ -579,15 +524,68 @@ static int16_t rwebinput_input_state( } break; case RETRO_DEVICE_KEYBOARD: - return rwebinput_key_pressed(rwebinput, id); + return ((id < RETROK_LAST) && rwebinput->keys[id]); case RETRO_DEVICE_MOUSE: - return rwebinput_mouse_state(&rwebinput->mouse, id, false); case RARCH_DEVICE_MOUSE_SCREEN: - return rwebinput_mouse_state(&rwebinput->mouse, id, true); + return rwebinput_mouse_state(&rwebinput->mouse, id, + device == RARCH_DEVICE_MOUSE_SCREEN); case RETRO_DEVICE_POINTER: - return rwebinput_pointer_device_state(&rwebinput->mouse, id, false); case RARCH_DEVICE_POINTER_SCREEN: - return rwebinput_pointer_device_state(&rwebinput->mouse, id, true); + { + struct video_viewport vp; + rwebinput_mouse_state_t + *mouse = &rwebinput->mouse; + const int edge_detect = 32700; + 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, mouse->x, mouse->x, + &res_x, &res_y, &res_screen_x, &res_screen_y))) + return 0; + + 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); + + switch (id) + { + case RETRO_DEVICE_ID_POINTER_X: + if (inside) + return res_x; + break; + case RETRO_DEVICE_ID_POINTER_Y: + if (inside) + return res_y; + break; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTNL)); + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return !inside; + default: + break; + } + } + break; } return 0; @@ -603,21 +601,23 @@ static void rwebinput_input_free(void *data) free(rwebinput); } -static void rwebinput_process_keyboard_events(rwebinput_input_t *rwebinput, - rwebinput_keyboard_event_t *event) +static void rwebinput_process_keyboard_events( + rwebinput_input_t *rwebinput, + rwebinput_keyboard_event_t *event) { uint32_t keycode; unsigned translated_keycode; - uint32_t character = 0; - uint16_t mod = 0; + uint32_t character = 0; + uint16_t mod = 0; const EmscriptenKeyboardEvent *key_event = &event->event; - bool keydown = event->type == EMSCRIPTEN_EVENT_KEYDOWN; + bool keydown = + event->type == EMSCRIPTEN_EVENT_KEYDOWN; /* a printable key: populate character field */ if (utf8len(key_event->key) == 1) { const char *key_ptr = &key_event->key[0]; - character = utf8_walk(&key_ptr); + character = utf8_walk(&key_ptr); } if (key_event->ctrlKey) @@ -653,20 +653,21 @@ static void rwebinput_process_keyboard_events(rwebinput_input_t *rwebinput, static void rwebinput_input_poll(void *data) { size_t i; - rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; + rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; for (i = 0; i < rwebinput->keyboard.count; i++) rwebinput_process_keyboard_events(rwebinput, &rwebinput->keyboard.events[i]); - rwebinput->keyboard.count = 0; - rwebinput->mouse.delta_x = rwebinput->mouse.pending_delta_x; - rwebinput->mouse.delta_y = rwebinput->mouse.pending_delta_y; - rwebinput->mouse.pending_delta_x = 0; - rwebinput->mouse.pending_delta_y = 0; + rwebinput->keyboard.count = 0; - rwebinput->mouse.scroll_x = rwebinput->mouse.pending_scroll_x; - rwebinput->mouse.scroll_y = rwebinput->mouse.pending_scroll_y; + rwebinput->mouse.delta_x = rwebinput->mouse.pending_delta_x; + rwebinput->mouse.delta_y = rwebinput->mouse.pending_delta_y; + rwebinput->mouse.pending_delta_x = 0; + rwebinput->mouse.pending_delta_y = 0; + + rwebinput->mouse.scroll_x = rwebinput->mouse.pending_scroll_x; + rwebinput->mouse.scroll_y = rwebinput->mouse.pending_scroll_y; rwebinput->mouse.pending_scroll_x = 0; rwebinput->mouse.pending_scroll_y = 0; } diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 5ff0821183..503bba08f3 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -79,105 +79,6 @@ static bool sdl_key_pressed(int key) return keymap[sym]; } -static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - return sdl->mouse_l; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return sdl->mouse_r; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - return sdl->mouse_wu; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - return sdl->mouse_wd; - case RETRO_DEVICE_ID_MOUSE_X: - return sdl->mouse_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return sdl->mouse_y; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return sdl->mouse_m; - case RETRO_DEVICE_ID_MOUSE_BUTTON_4: - return sdl->mouse_b4; - case RETRO_DEVICE_ID_MOUSE_BUTTON_5: - return sdl->mouse_b5; - } - - return 0; -} - -static int16_t sdl_pointer_device_state(sdl_input_t *sdl, - unsigned idx, unsigned id, bool screen) -{ - 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; - 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, sdl->mouse_abs_x, sdl->mouse_abs_y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - 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); - - 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 sdl->mouse_l; - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; - } - - return 0; -} - -static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_LIGHTGUN_X: - return sdl->mouse_x; - case RETRO_DEVICE_ID_LIGHTGUN_Y: - return sdl->mouse_y; - case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - return sdl->mouse_l; - case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: - return sdl->mouse_m; - case RETRO_DEVICE_ID_LIGHTGUN_TURBO: - return sdl->mouse_r; - case RETRO_DEVICE_ID_LIGHTGUN_START: - return sdl->mouse_m && sdl->mouse_r; - case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: - return sdl->mouse_m && sdl->mouse_l; - } - - return 0; -} - static int16_t sdl_input_state( void *data, const input_device_driver_t *joypad, @@ -260,23 +161,103 @@ static int16_t sdl_input_state( } break; case RETRO_DEVICE_MOUSE: - if (config_get_ptr()->uints.input_mouse_index[ port ] == 0) - return sdl_mouse_device_state(sdl, id); - break; case RARCH_DEVICE_MOUSE_SCREEN: if (config_get_ptr()->uints.input_mouse_index[ port ] == 0) - return sdl_mouse_device_state(sdl, id); + { + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + return sdl->mouse_l; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return sdl->mouse_r; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + return sdl->mouse_wu; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + return sdl->mouse_wd; + case RETRO_DEVICE_ID_MOUSE_X: + return sdl->mouse_x; + case RETRO_DEVICE_ID_MOUSE_Y: + return sdl->mouse_y; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return sdl->mouse_m; + case RETRO_DEVICE_ID_MOUSE_BUTTON_4: + return sdl->mouse_b4; + case RETRO_DEVICE_ID_MOUSE_BUTTON_5: + return sdl->mouse_b5; + } + } break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: if (idx == 0) - return sdl_pointer_device_state(sdl, idx, id, - device == RARCH_DEVICE_POINTER_SCREEN); + { + struct video_viewport vp; + bool screen = device == + RARCH_DEVICE_POINTER_SCREEN; + 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; + + 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, sdl->mouse_abs_x, sdl->mouse_abs_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 >= -edge_detect) + && (res_y >= -edge_detect) + && (res_x <= edge_detect) + && (res_y <= edge_detect); + + 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 sdl->mouse_l; + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return !inside; + } + } + } break; case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && sdl_key_pressed(id); case RETRO_DEVICE_LIGHTGUN: - return sdl_lightgun_device_state(sdl, id); + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_X: + return sdl->mouse_x; + case RETRO_DEVICE_ID_LIGHTGUN_Y: + return sdl->mouse_y; + case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: + return sdl->mouse_l; + case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: + return sdl->mouse_m; + case RETRO_DEVICE_ID_LIGHTGUN_TURBO: + return sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_START: + return sdl->mouse_m && sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + return sdl->mouse_m && sdl->mouse_l; + } + break; } return 0; diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index 6507e49e0d..96d641c76f 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -277,97 +277,6 @@ static void switch_input_poll(void *data) sw->mouse_wheel = mouse_pos.scrollVelocityY; } - -static int16_t switch_pointer_screen_device_state(switch_input_t *sw, - unsigned id, unsigned idx) -{ - if (idx >= MULTITOUCH_LIMIT) - return 0; - - switch (id) - { - case RETRO_DEVICE_ID_POINTER_PRESSED: - return sw->touch_state[idx]; - case RETRO_DEVICE_ID_POINTER_X: - return sw->touch_x_screen[idx]; - case RETRO_DEVICE_ID_POINTER_Y: - return sw->touch_y_screen[idx]; - } - - return 0; -} - -static int16_t switch_pointer_device_state( - switch_input_t *sw, - unsigned id, unsigned idx) -{ - if (idx >= MULTITOUCH_LIMIT) - return 0; - - switch (id) - { - case RETRO_DEVICE_ID_POINTER_PRESSED: - return sw->touch_state[idx]; - case RETRO_DEVICE_ID_POINTER_X: - return sw->touch_x_viewport[idx]; - case RETRO_DEVICE_ID_POINTER_Y: - return sw->touch_y_viewport[idx]; - } - - return 0; -} - -static int16_t switch_input_mouse_state( - switch_input_t *sw, unsigned id, bool screen) -{ - int val = 0; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - val = sw->mouse_button_left; - break; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - val = sw->mouse_button_right; - break; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - val = sw->mouse_button_middle; - break; - case RETRO_DEVICE_ID_MOUSE_X: - if (screen) - val = sw->mouse_x; - else - { - val = sw->mouse_x_delta; - sw->mouse_x_delta = 0; /* flush delta after it has been read */ - } - break; - case RETRO_DEVICE_ID_MOUSE_Y: - if (screen) - val = sw->mouse_y; - else - { - val = sw->mouse_y_delta; - sw->mouse_y_delta = 0; /* flush delta after it has been read */ - } - break; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - if (sw->mouse_wheel > 0) - { - val = sw->mouse_wheel; - sw->mouse_wheel = 0; - } - break; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - if (sw->mouse_wheel < 0) - { - val = sw->mouse_wheel; - sw->mouse_wheel = 0; - } - break; - } - - return val; -} #endif static int16_t switch_input_state( @@ -402,15 +311,84 @@ static int16_t switch_input_state( break; #ifdef HAVE_LIBNX case RETRO_DEVICE_KEYBOARD: - return ((id < RETROK_LAST) && sw->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]); + return ((id < RETROK_LAST) && + sw->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]); case RETRO_DEVICE_MOUSE: - return switch_input_mouse_state(sw, id, false); case RARCH_DEVICE_MOUSE_SCREEN: - return switch_input_mouse_state(sw, id, true); + { + int16_t val = 0; + bool screen = (device == RARCH_DEVICE_MOUSE_SCREEN); + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + return sw->mouse_button_left; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return sw->mouse_button_right; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return sw->mouse_button_middle; + case RETRO_DEVICE_ID_MOUSE_X: + if (screen) + return sw->mouse_x; + + val = sw->mouse_x_delta; + sw->mouse_x_delta = 0; + /* flush delta after it has been read */ + break; + case RETRO_DEVICE_ID_MOUSE_Y: + if (screen) + return sw->mouse_y; + + val = sw->mouse_y_delta; + sw->mouse_y_delta = 0; + /* flush delta after it has been read */ + break; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + if (sw->mouse_wheel > 0) + { + val = sw->mouse_wheel; + sw->mouse_wheel = 0; + } + break; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + if (sw->mouse_wheel < 0) + { + val = sw->mouse_wheel; + sw->mouse_wheel = 0; + } + break; + } + + return val; + } + break; case RETRO_DEVICE_POINTER: - return switch_pointer_device_state(sw, id, idx); + if (idx < MULTITOUCH_LIMIT) + { + switch (id) + { + case RETRO_DEVICE_ID_POINTER_PRESSED: + return sw->touch_state[idx]; + case RETRO_DEVICE_ID_POINTER_X: + return sw->touch_x_viewport[idx]; + case RETRO_DEVICE_ID_POINTER_Y: + return sw->touch_y_viewport[idx]; + } + } + break; case RARCH_DEVICE_POINTER_SCREEN: - return switch_pointer_screen_device_state(sw, id, idx); + if (idx < MULTITOUCH_LIMIT) + { + switch (id) + { + case RETRO_DEVICE_ID_POINTER_PRESSED: + return sw->touch_state[idx]; + case RETRO_DEVICE_ID_POINTER_X: + return sw->touch_x_screen[idx]; + case RETRO_DEVICE_ID_POINTER_Y: + return sw->touch_y_screen[idx]; + } + } + break; #endif } diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 249b308809..8f84054873 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -1090,17 +1090,15 @@ static int16_t udev_input_state( return (id < RETROK_LAST) && udev_keyboard_pressed(udev, id); case RETRO_DEVICE_MOUSE: - return udev_mouse_state(udev, port, id, false); case RARCH_DEVICE_MOUSE_SCREEN: - return udev_mouse_state(udev, port, id, true); + return udev_mouse_state(udev, port, id, + device == RARCH_DEVICE_MOUSE_SCREEN); case RETRO_DEVICE_POINTER: - if (idx == 0) /* multi-touch unsupported (for now) */ - return udev_pointer_state(udev, port, id, false); - break; case RARCH_DEVICE_POINTER_SCREEN: if (idx == 0) /* multi-touch unsupported (for now) */ - return udev_pointer_state(udev, port, id, true); + return udev_pointer_state(udev, port, id, + device == RARCH_DEVICE_POINTER_SCREEN); break; case RETRO_DEVICE_LIGHTGUN: @@ -1112,7 +1110,7 @@ static int16_t udev_input_state( case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: return udev_lightgun_aiming_state( udev, port, id ); - /*buttons*/ + /*buttons*/ case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: return udev_input_lightgun_state(udev, joypad, joypad_info, @@ -1179,7 +1177,7 @@ static int16_t udev_input_state( binds, keyboard_mapping_blocked, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); - /*deprecated*/ + /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: { udev_input_mouse_t *mouse = udev_get_mouse(udev, port); @@ -1375,8 +1373,6 @@ error: static uint64_t udev_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index ef2ab1e5ca..896f84191e 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -52,58 +52,11 @@ void flush_wayland_fd(void *data); -static int16_t input_wl_mouse_state( - input_ctx_wayland_data_t *wl, unsigned id, bool screen) -{ - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return screen ? wl->mouse.x : wl->mouse.delta_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return screen ? wl->mouse.y : wl->mouse.delta_y; - case RETRO_DEVICE_ID_MOUSE_LEFT: - return wl->mouse.left; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return wl->mouse.right; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return wl->mouse.middle; - - /* TODO: Rest of the mouse inputs. */ - } - - return 0; -} - -static int16_t input_wl_lightgun_state( - input_ctx_wayland_data_t *wl, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_LIGHTGUN_X: - return wl->mouse.delta_x; - case RETRO_DEVICE_ID_LIGHTGUN_Y: - return wl->mouse.delta_y; - case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: - return wl->mouse.left; - case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: - return wl->mouse.middle; - case RETRO_DEVICE_ID_LIGHTGUN_TURBO: - return wl->mouse.right; - case RETRO_DEVICE_ID_LIGHTGUN_START: - return wl->mouse.middle && wl->mouse.right; - case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: - return wl->mouse.middle && wl->mouse.left; - } - - return 0; -} - -/* forward declaration */ -static bool wayland_context_gettouchpos(void *data, unsigned id, +static bool wayland_context_gettouchpos( + gfx_ctx_wayland_data_t *wl, + unsigned id, unsigned* touch_x, unsigned* touch_y) { - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - if (id >= MAX_TOUCHES) return false; *touch_x = wl->active_touch_positions[id].x; @@ -111,30 +64,12 @@ static bool wayland_context_gettouchpos(void *data, unsigned id, return wl->active_touch_positions[id].active; } -static void input_wl_touch_pool(void *data) +static void input_wl_poll(void *data) { int id; unsigned touch_x = 0; unsigned touch_y = 0; input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; - - if (!wl) - return; - - for (id = 0; id < MAX_TOUCHES; id++) - { - if (wayland_context_gettouchpos(wl, id, &touch_x, &touch_y)) - wl->touches[id].active = true; - else - wl->touches[id].active = false; - wl->touches[id].x = touch_x; - wl->touches[id].y = touch_y; - } -} - -static void input_wl_poll(void *data) -{ - input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; if (!wl) return; @@ -151,68 +86,15 @@ static void input_wl_poll(void *data) wl->mouse.delta_y = 0; } - input_wl_touch_pool(wl); -} - -static bool input_wl_state_kb(input_ctx_wayland_data_t *wl, - const struct retro_keybind **binds, - unsigned port, unsigned device, unsigned idx, unsigned id) -{ - unsigned bit = rarch_keysym_lut[(enum retro_key)id]; - return id < RETROK_LAST && BIT_GET(wl->key_state, bit); -} - -static int16_t input_wl_pointer_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 (!(video_driver_translate_coord_viewport_wrap(&vp, - wl->mouse.x, wl->mouse.y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - - return 0; - - if (screen) + for (id = 0; id < MAX_TOUCHES; id++) { - res_x = res_screen_x; - res_y = res_screen_y; + if (wayland_context_gettouchpos(wl, id, &touch_x, &touch_y)) + wl->touches[id].active = true; + else + wl->touches[id].active = false; + wl->touches[id].x = touch_x; + wl->touches[id].y = touch_y; } - - inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); - - switch (id) - { - case RETRO_DEVICE_ID_POINTER_X: - if (inside) - return res_x; - break; - case RETRO_DEVICE_ID_POINTER_Y: - if (inside) - return res_y; - break; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return wl->mouse.left; - case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return !inside; - default: - break; - } - - return 0; } static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl, @@ -352,15 +234,78 @@ static int16_t input_wl_state( } break; case RETRO_DEVICE_KEYBOARD: - return input_wl_state_kb(wl, binds, port, device, idx, id); + return id < RETROK_LAST && + BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id]); case RETRO_DEVICE_MOUSE: - return input_wl_mouse_state(wl, id, false); case RARCH_DEVICE_MOUSE_SCREEN: - return input_wl_mouse_state(wl, id, true); + { + bool screen = device == RARCH_DEVICE_MOUSE_SCREEN; + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_X: + return screen ? wl->mouse.x : wl->mouse.delta_x; + case RETRO_DEVICE_ID_MOUSE_Y: + return screen ? wl->mouse.y : wl->mouse.delta_y; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return wl->mouse.left; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return wl->mouse.right; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return wl->mouse.middle; + /* TODO: Rest of the mouse inputs. */ + } + } + breka; case RETRO_DEVICE_POINTER: if (idx == 0) - return input_wl_pointer_state(wl, idx, id, - device == RARCH_DEVICE_POINTER_SCREEN); + { + 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); + + switch (id) + { + case RETRO_DEVICE_ID_POINTER_X: + if (inside) + return res_x; + break; + case RETRO_DEVICE_ID_POINTER_Y: + if (inside) + return res_y; + break; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return wl->mouse.left; + case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: + return !inside; + default: + break; + } + } + } break; case RARCH_DEVICE_POINTER_SCREEN: if (idx < MAX_TOUCHES) @@ -368,7 +313,24 @@ static int16_t input_wl_state( device == RARCH_DEVICE_POINTER_SCREEN); break; case RETRO_DEVICE_LIGHTGUN: - return input_wl_lightgun_state(wl, id); + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_X: + return wl->mouse.delta_x; + case RETRO_DEVICE_ID_LIGHTGUN_Y: + return wl->mouse.delta_y; + case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: + return wl->mouse.left; + case RETRO_DEVICE_ID_LIGHTGUN_CURSOR: + return wl->mouse.middle; + case RETRO_DEVICE_ID_LIGHTGUN_TURBO: + return wl->mouse.right; + case RETRO_DEVICE_ID_LIGHTGUN_START: + return wl->mouse.middle && wl->mouse.right; + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + return wl->mouse.middle && wl->mouse.left; + } + break; } return 0; @@ -396,8 +358,6 @@ bool input_wl_init(void *data, const char *joypad_name) static uint64_t input_wl_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | @@ -406,13 +366,6 @@ static uint64_t input_wl_get_capabilities(void *data) (1 << RETRO_DEVICE_LIGHTGUN); } -static void input_wl_grab_mouse(void *data, bool state) -{ - /* Dummy for now. Might be useful in the future. */ - (void)data; - (void)state; -} - static bool input_wl_set_rumble( const input_device_driver_t *joypad, const input_device_driver_t *sec_joypad, @@ -433,7 +386,7 @@ input_driver_t input_wayland = { NULL, input_wl_get_capabilities, "wayland", - input_wl_grab_mouse, + NULL, /* grab_mouse */ NULL, input_wl_set_rumble }; diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 24a95aedd5..372feecd32 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -90,32 +90,6 @@ static void kb_key_callback(KBDKeyEvent *key) RETRO_DEVICE_KEYBOARD); } -/* TODO: emulate a relative mouse. This is suprisingly - hard to get working nicely. -*/ - -static int16_t wiiu_pointer_device_state( - wiiu_input_t* wiiu, - const input_device_driver_t *joypad, - unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_POINTER_PRESSED: - { - input_bits_t state; - joypad->get_buttons(0, &state); - return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0; - } - case RETRO_DEVICE_ID_POINTER_X: - return joypad->axis(0, 0xFFFF0004UL); - case RETRO_DEVICE_ID_POINTER_Y: - return joypad->axis(0, 0xFFFF0005UL); - } - - return 0; -} - static int16_t wiiu_input_state( void *data, const input_device_driver_t *joypad, @@ -153,7 +127,23 @@ static int16_t wiiu_input_state( break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return wiiu_pointer_device_state(wiiu, joypad, id); + /* TODO: Emulate a relative mouse. + * This is suprisingly hard to get working nicely. + */ + switch (id) + { + case RETRO_DEVICE_ID_POINTER_PRESSED: + { + input_bits_t state; + joypad->get_buttons(0, &state); + return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0; + } + case RETRO_DEVICE_ID_POINTER_X: + return joypad->axis(0, 0xFFFF0004UL); + case RETRO_DEVICE_ID_POINTER_Y: + return joypad->axis(0, 0xFFFF0005UL); + } + break; } return 0; @@ -174,8 +164,10 @@ static void* wiiu_input_init(const char *joypad_driver) if (!wiiu) return NULL; - KBDSetup(&kb_connection_callback, - &kb_disconnection_callback,&kb_key_callback); + KBDSetup( + &kb_connection_callback, + &kb_disconnection_callback, + &kb_key_callback); input_keymaps_init_keyboard_lut(rarch_key_map_wiiu); diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 977cef1f0c..22efb7ecf8 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -79,21 +79,15 @@ error: static void winraw_destroy_window(HWND wnd) { - BOOL r; - if (!wnd) return; - r = DestroyWindow(wnd); - - if (!r) + if (!DestroyWindow(wnd)) { RARCH_WARN("[WINRAW]: DestroyWindow failed with error %lu.\n", GetLastError()); } - r = UnregisterClassA("winraw-input", NULL); - - if (!r) + if (!UnregisterClassA("winraw-input", NULL)) { RARCH_WARN("[WINRAW]: UnregisterClassA failed with error %lu.\n", GetLastError()); } @@ -117,7 +111,7 @@ static void winraw_log_mice_info(winraw_mouse_t *mice, unsigned mouse_cnt) char name[256]; UINT name_size = sizeof(name); - name[0] = '\0'; + name[0] = '\0'; for (i = 0; i < mouse_cnt; ++i) { @@ -237,7 +231,7 @@ static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr, && (res_x <= edge_detect) && (res_y <= edge_detect); - switch ( id ) + switch (id) { case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: if (inside) @@ -256,7 +250,7 @@ static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr, return 0; } -static int16_t winraw_mouse_state(winraw_input_t *wr, +static int16_t winraw_mouse_state( winraw_mouse_t *mouse, unsigned port, bool abs, unsigned id) { @@ -338,22 +332,6 @@ static void winraw_init_mouse_xy_mapping(void) } } -static int16_t winraw_deprecated_lightgun_state( - winraw_input_t *wr, - winraw_mouse_t *mouse, - unsigned port, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_LIGHTGUN_X: - return mouse->dlt_x; - case RETRO_DEVICE_ID_LIGHTGUN_Y: - return mouse->dlt_y; - } - - return 0; -} - static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state) { POINT crs_pos; @@ -431,7 +409,8 @@ static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state) } } -static LRESULT CALLBACK winraw_callback(HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar) +static LRESULT CALLBACK winraw_callback( + HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar) { unsigned i; static uint8_t data[1024]; @@ -693,9 +672,8 @@ static int16_t winraw_input_state( case RETRO_DEVICE_MOUSE: case RARCH_DEVICE_MOUSE_SCREEN: if (mouse) - return winraw_mouse_state(wr, mouse, port, - (device == RARCH_DEVICE_MOUSE_SCREEN) - ? true : false, + return winraw_mouse_state(mouse, port, + (device == RARCH_DEVICE_MOUSE_SCREEN), id); break; case RETRO_DEVICE_LIGHTGUN: @@ -779,7 +757,15 @@ static int16_t winraw_input_state( case RETRO_DEVICE_ID_LIGHTGUN_X: case RETRO_DEVICE_ID_LIGHTGUN_Y: if (mouse) - return winraw_deprecated_lightgun_state(wr, mouse, port, id); + { + switch (id) + { + case RETRO_DEVICE_ID_LIGHTGUN_X: + return mouse->dlt_x; + case RETRO_DEVICE_ID_LIGHTGUN_Y: + return mouse->dlt_y; + } + } break; case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: return winraw_input_lightgun_state(wr, mouse, joypad, diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index e140acd4ac..00cd981d25 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -44,6 +44,9 @@ typedef struct x11_input bool grab_mouse; } x11_input_t; +/* Public global variable */ +extern bool g_x11_entered; + static void *x_input_init(const char *joypad_driver) { x11_input_t *x11; @@ -76,9 +79,7 @@ static bool x_keyboard_pressed(x11_input_t *x11, unsigned key) static bool x_mouse_button_pressed( x11_input_t *x11, unsigned port, unsigned key) { - bool result; - - switch ( key ) + switch (key) { case RETRO_DEVICE_ID_MOUSE_LEFT: return x11->mouse_l; @@ -102,137 +103,6 @@ static bool x_mouse_button_pressed( return false; } -static int16_t x_lightgun_aiming_state( - x11_input_t *x11, unsigned idx, unsigned id ) -{ - 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; - 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, x11->mouse_x, x11->mouse_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 ) - { - 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; -} - -static int16_t x_mouse_state(x11_input_t *x11, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return x11->mouse_x - x11->mouse_last_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return x11->mouse_y - x11->mouse_last_y; - case RETRO_DEVICE_ID_MOUSE_LEFT: - return x11->mouse_l; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - return x11->mouse_r; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - return x_mouse_state_wheel(id); - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - return x11->mouse_m; - } - - return 0; -} - -static int16_t x_mouse_state_screen(x11_input_t *x11, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_X: - return x11->mouse_x; - case RETRO_DEVICE_ID_MOUSE_Y: - return x11->mouse_y; - default: - break; - } - - return x_mouse_state(x11, id); -} - -static int16_t x_pointer_state(x11_input_t *x11, - 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 (!(video_driver_translate_coord_viewport_wrap( - &vp, x11->mouse_x, x11->mouse_y, - &res_x, &res_y, &res_screen_x, &res_screen_y))) - return 0; - - 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_POINTER_X: - return res_x; - case RETRO_DEVICE_ID_POINTER_Y: - return res_y; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return x11->mouse_l; - } - - return 0; -} - static int16_t x_input_state( void *data, const input_device_driver_t *joypad, @@ -352,15 +222,75 @@ static int16_t x_input_state( case RETRO_DEVICE_KEYBOARD: return (id < RETROK_LAST) && x_keyboard_pressed(x11, id); case RETRO_DEVICE_MOUSE: - return x_mouse_state(x11, id); case RARCH_DEVICE_MOUSE_SCREEN: - return x_mouse_state_screen(x11, id); - + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_X: + if (device == RARCH_DEVICE_MOUSE_SCREEN) + return x11->mouse_x; + return x11->mouse_x - x11->mouse_last_x; + case RETRO_DEVICE_ID_MOUSE_Y: + if (device == RARCH_DEVICE_MOUSE_SCREEN) + return x11->mouse_y; + return x11->mouse_y - x11->mouse_last_y; + case RETRO_DEVICE_ID_MOUSE_LEFT: + return x11->mouse_l; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return x11->mouse_r; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + return x_mouse_state_wheel(id); + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + return x11->mouse_m; + } + break; case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: if (idx == 0) - return x_pointer_state(x11, idx, id, - device == RARCH_DEVICE_POINTER_SCREEN); + { + 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, x11->mouse_x, x11->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_POINTER_X: + return res_x; + case RETRO_DEVICE_ID_POINTER_Y: + return res_y; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return x11->mouse_l; + } + } + } break; case RETRO_DEVICE_LIGHTGUN: switch ( id ) @@ -369,8 +299,49 @@ static int16_t x_input_state( case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: - return x_lightgun_aiming_state( x11, idx, id ); + { + 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; + 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, + x11->mouse_x, x11->mouse_y, + &res_x, &res_y, &res_screen_x, &res_screen_y)) + { + 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; + } + } + } + break; /*buttons*/ case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER: { @@ -670,14 +641,18 @@ static void x_input_free(void *data) free(x11); } -extern bool g_x11_entered; - -static void x_input_poll_mouse(x11_input_t *x11, - bool video_has_focus) +static void x_input_poll(void *data) { unsigned mask; int root_x, root_y, win_x, win_y; Window root_win, child_win; + x11_input_t *x11 = (x11_input_t*)data; + bool video_has_focus = video_driver_has_focus(); + + if (video_has_focus) + XQueryKeymap(x11->display, x11->state); + else + memset(x11->state, 0, sizeof(x11->state)); x11->mouse_last_x = x11->mouse_x; x11->mouse_last_y = x11->mouse_y; @@ -728,19 +703,6 @@ static void x_input_poll_mouse(x11_input_t *x11, } } -static void x_input_poll(void *data) -{ - x11_input_t *x11 = (x11_input_t*)data; - bool video_has_focus = video_driver_has_focus(); - - if (video_has_focus) - XQueryKeymap(x11->display, x11->state); - else - memset(x11->state, 0, sizeof(x11->state)); - - x_input_poll_mouse(x11, video_has_focus); -} - static void x_grab_mouse(void *data, bool state) { x11_input_t *x11 = (x11_input_t*)data; diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index dfba6c4b86..aec38e24ee 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -35,8 +35,9 @@ static uint64_t state[DEFAULT_MAX_PADS]; static void xenon360_input_poll(void *data) { - (void)data; - for (unsigned i = 0; i < DEFAULT_MAX_PADS; i++) + unsigned i; + + for (i = 0; i < DEFAULT_MAX_PADS; i++) { struct controller_data_s pad; uint64_t *cur_state; From d7559cdb1821a13df3b262c727947aabd134d448 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 31 Aug 2020 02:12:31 +0200 Subject: [PATCH 19/30] Cleanup some unused variable warnings --- retroarch.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/retroarch.c b/retroarch.c index efa06b8aa7..9345f1dfd6 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3965,7 +3965,6 @@ static bool menu_input_key_bind_iterate( bool timed_out = false; settings_t *settings = p_rarch->configuration_settings; struct menu_bind_state *_binds = &p_rarch->menu_input_binds; - input_driver_t *input_drv = p_rarch->current_input; menu_input_t *menu_input = &p_rarch->menu_input_state; uint64_t input_bind_hold_us = settings->uints.input_bind_hold * 1000000; uint64_t input_bind_timeout_us = settings->uints.input_bind_timeout * 1000000; @@ -15621,11 +15620,6 @@ static void command_event_reinit(struct rarch_state *p_rarch, bool adaptive_vsync = settings->bools.video_adaptive_vsync; unsigned swap_interval = settings->uints.video_swap_interval; #endif -#ifdef HAVE_MFI - const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; -#else - const input_device_driver_t *sec_joypad = NULL; -#endif video_driver_reinit(flags); /* Poll input to avoid possibly stale data to corrupt things. */ @@ -26507,7 +26501,6 @@ void input_driver_init_joypads(void) void *input_driver_init_wrap(input_driver_t *input, const char *name) { - struct rarch_state *p_rarch = &rarch_st; void *ret = NULL; if (!input) return NULL; From 0cb0a0892340c9c69b323c05dc513c371f2c7f47 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 02:17:18 +0200 Subject: [PATCH 20/30] (Android) Buildfix --- input/drivers/android_input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 30d71e5acf..c887c580ba 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -178,12 +178,12 @@ static typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue; #define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue) -#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState) - extern int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event); static typeof(AMotionEvent_getButtonState) *p_AMotionEvent_getButtonState; +#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState) + #ifdef HAVE_DYNAMIC static void *libandroid_handle; #endif From a217ef393f1894f332d6978ac2730a337bb46bc5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 02:43:48 +0200 Subject: [PATCH 21/30] Fix pointer controls --- retroarch.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/retroarch.c b/retroarch.c index 9345f1dfd6..e22b85c7e3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3646,7 +3646,10 @@ static void menu_input_key_bind_poll_bind_state( &joypad_info, NULL, p_rarch->keyboard_mapping_blocked, - 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); + 0, + RETRO_DEVICE_KEYBOARD, + 0, + RETROK_RETURN); menu_input_key_bind_poll_bind_state_internal( joypad, state, port, timed_out); @@ -23416,7 +23419,10 @@ static void input_poll_overlay( &joypad_info, NULL, p_rarch->keyboard_mapping_blocked, - 0, device, i, RETRO_DEVICE_ID_POINTER_PRESSED); + 0, + device, + i, + RETRO_DEVICE_ID_POINTER_PRESSED); i++) { input_overlay_state_t polled_data; @@ -23427,7 +23433,10 @@ static void input_poll_overlay( &joypad_info, NULL, p_rarch->keyboard_mapping_blocked, - 0, device, i, RETRO_DEVICE_ID_POINTER_X); + 0, + device, + i, + RETRO_DEVICE_ID_POINTER_X); int16_t y = input_ptr->input_state( input_data, p_rarch->joypad, @@ -23435,7 +23444,10 @@ static void input_poll_overlay( &joypad_info, NULL, p_rarch->keyboard_mapping_blocked, - 0, device, i, RETRO_DEVICE_ID_POINTER_Y); + 0, + device, + i, + RETRO_DEVICE_ID_POINTER_Y); memset(&polled_data, 0, sizeof(struct input_overlay_state)); @@ -23880,7 +23892,10 @@ static void input_driver_poll(void) &joypad_info[i], p_rarch->libretro_input_binds, p_rarch->keyboard_mapping_blocked, - (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); + (unsigned)i, + RETRO_DEVICE_JOYPAD, + 0, + RARCH_TURBO_ENABLE); } #ifdef HAVE_OVERLAY @@ -25037,9 +25052,8 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, - pointer_device, p_rarch->keyboard_mapping_blocked, + 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; @@ -25067,8 +25081,8 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->joypad, sec_joypad, &joypad_info, binds, - 0, pointer_device, p_rarch->keyboard_mapping_blocked, + 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; From 202e460be7d601029bd00aa12953ecfbf5f8439d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 02:54:12 +0200 Subject: [PATCH 22/30] (Android) Simplify code --- input/drivers/android_input.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index c887c580ba..f4ac7d4092 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1452,13 +1452,22 @@ static int16_t android_input_state( } break; case RETRO_DEVICE_POINTER: + case RARCH_DEVICE_POINTER_SCREEN: switch (id) { case RETRO_DEVICE_ID_POINTER_X: + if (device == RARCH_DEVICE_POINTER_SCREEN) + return android->pointer[idx].full_x; return android->pointer[idx].x; case RETRO_DEVICE_ID_POINTER_Y: + if (device == RARCH_DEVICE_POINTER_SCREEN) + return android->pointer[idx].full_y; return android->pointer[idx].y; case RETRO_DEVICE_ID_POINTER_PRESSED: + if (device == RARCH_DEVICE_POINTER_SCREEN) + return (idx < android->pointer_count) && + (android->pointer[idx].full_x != -0x8000) && + (android->pointer[idx].full_y != -0x8000); return (idx < android->pointer_count) && (android->pointer[idx].x != -0x8000) && (android->pointer[idx].y != -0x8000); @@ -1473,28 +1482,6 @@ static int16_t android_input_state( } } break; - case RARCH_DEVICE_POINTER_SCREEN: - switch (id) - { - case RETRO_DEVICE_ID_POINTER_X: - return android->pointer[idx].full_x; - case RETRO_DEVICE_ID_POINTER_Y: - return android->pointer[idx].full_y; - case RETRO_DEVICE_ID_POINTER_PRESSED: - return (idx < android->pointer_count) && - (android->pointer[idx].full_x != -0x8000) && - (android->pointer[idx].full_y != -0x8000); - case RETRO_DEVICE_ID_POINTER_COUNT: - return android->pointer_count; - case RARCH_DEVICE_ID_POINTER_BACK: - { - const struct retro_keybind *keyptr = - &input_autoconf_binds[0][RARCH_MENU_TOGGLE]; - if (keyptr->joykey == 0) - return ANDROID_KEYBOARD_INPUT_PRESSED(AKEYCODE_BACK); - } - } - break; } return 0; From 0adee503f20f26e6c7563f98ba39cb543155c21e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 03:11:52 +0200 Subject: [PATCH 23/30] (Android) Don't do memcpy copy anymore --- input/drivers/android_input.c | 28 ++++----------------------- input/drivers_joypad/android_joypad.c | 4 ++-- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index f4ac7d4092..f18fadf13b 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -155,8 +155,6 @@ typedef struct android_input sensor_t accelerometer_state; /* float alignment */ float mouse_x_prev, mouse_y_prev; struct input_pointer pointer[MAX_TOUCH]; /* int16_t alignment */ - int16_t analog_state[MAX_USERS][MAX_AXIS]; - int8_t hat_state[MAX_USERS][2]; char device_model[256]; } android_input_t; @@ -165,8 +163,7 @@ static void frontend_android_get_name(char *s, size_t len); bool (*engine_lookup_name)(char *buf, int *vendorId, int *productId, size_t size, int id); - -void (*engine_handle_dpad)(android_input_t *, AInputEvent*, int, int); +void (*engine_handle_dpad)(struct android_app *, AInputEvent*, int, int); static bool android_input_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned event_rate); @@ -431,7 +428,7 @@ static void android_input_poll_main_cmd(void) } } -static void engine_handle_dpad_default(android_input_t *android, +static void engine_handle_dpad_default(struct android_app *android, AInputEvent *event, int port, int source) { size_t motion_ptr = AMotionEvent_getAction(event) >> @@ -444,7 +441,7 @@ static void engine_handle_dpad_default(android_input_t *android, } #ifdef HAVE_DYNAMIC -static void engine_handle_dpad_getaxisvalue(android_input_t *android, +static void engine_handle_dpad_getaxisvalue(struct android_app *android, AInputEvent *event, int port, int source) { size_t motion_ptr = AMotionEvent_getAction(event) >> @@ -1194,7 +1191,7 @@ static void android_input_poll_input(android_input_t *android, android_input_poll_event_type_motion(android, event, port, source, vibrate_on_keypress); else - engine_handle_dpad(android, event, port, source); + engine_handle_dpad(android_app, event, port, source); break; case AINPUT_EVENT_TYPE_KEY: { @@ -1244,20 +1241,6 @@ static void android_input_poll_user(android_input_t *android) } } -static void android_input_poll_memcpy(android_input_t *android) -{ - unsigned i, j; - struct android_app *android_app = (struct android_app*)g_android; - - for (i = 0; i < DEFAULT_MAX_PADS; i++) - { - for (j = 0; j < 2; j++) - android_app->hat_state[i][j] = android->hat_state[i][j]; - for (j = 0; j < MAX_AXIS; j++) - android_app->analog_state[i][j] = android->analog_state[i][j]; - } -} - /* Handle all events. If our activity is in pause state, * block until we're unpaused. */ @@ -1310,9 +1293,6 @@ static void android_input_poll(void *data, const void *joypad_data) return; } } - - if (android_app->input_alive) - android_input_poll_memcpy(android); } bool android_run_events(void *data) diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index 1f0864093a..9b849a684c 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -45,11 +45,11 @@ static int16_t android_joypad_button_state( case HAT_LEFT_MASK: return (android_app->hat_state[port][0] == -1); case HAT_RIGHT_MASK: - return (android_app->hat_state[port][0] == 1); + return (android_app->hat_state[port][0] == 1); case HAT_UP_MASK: return (android_app->hat_state[port][1] == -1); case HAT_DOWN_MASK: - return (android_app->hat_state[port][1] == 1); + return (android_app->hat_state[port][1] == 1); default: break; } From fe6d047bfedd6b0afd0f13c992cb323936df0ec1 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 03:38:51 +0200 Subject: [PATCH 24/30] (Udev) Cleanups --- input/drivers/udev_input.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 8f84054873..9a3f7cce72 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -164,8 +164,10 @@ static unsigned input_unify_ev_key_code(unsigned code) case KEY_BACK: return KEY_BACKSPACE; default: - return code; + break; } + + return code; } static void udev_handle_keyboard(void *data, @@ -350,13 +352,13 @@ static int16_t udev_mouse_get_pointer_x(const udev_input_mouse_t *mouse, bool sc src_width = vp.width; } - x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min); + x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min); x += (x < 0 ? -0.5 : 0.5); if (x < -0x7fff) - x = -0x7fff; + return -0x7fff; else if(x > 0x7fff) - x = 0x7fff; + return 0x7fff; return x; } @@ -389,9 +391,9 @@ static int16_t udev_mouse_get_pointer_y(const udev_input_mouse_t *mouse, bool sc y += (y < 0 ? -0.5 : 0.5); if (y < -0x7fff) - y = -0x7fff; + return -0x7fff; else if(y > 0x7fff) - y = 0x7fff; + return 0x7fff; return y; } From d7522aebe005087544d3cf9d1ed25a5d0186f901 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 03:40:36 +0200 Subject: [PATCH 25/30] (Cocoa) Struct reordering, alignment --- input/drivers/cocoa_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/drivers/cocoa_input.h b/input/drivers/cocoa_input.h index bc1bcd4e2e..213d02054f 100644 --- a/input/drivers/cocoa_input.h +++ b/input/drivers/cocoa_input.h @@ -38,10 +38,10 @@ typedef struct typedef struct { - cocoa_touch_data_t touches[MAX_TOUCHES]; uint32_t touch_count; uint32_t mouse_buttons; + cocoa_touch_data_t touches[MAX_TOUCHES]; /* int16_t alignment */ int16_t mouse_x_last; int16_t mouse_y_last; int16_t window_pos_x; From 0e5cceb4438b31b111782f266f25249592d67301 Mon Sep 17 00:00:00 2001 From: Autechre Date: Mon, 31 Aug 2020 14:08:41 +0200 Subject: [PATCH 26/30] Update wayland_input.c --- input/drivers/wayland_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 896f84191e..0f8bff16f4 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -255,7 +255,7 @@ static int16_t input_wl_state( /* TODO: Rest of the mouse inputs. */ } } - breka; + break; case RETRO_DEVICE_POINTER: if (idx == 0) { From 094ae69b09350bff787d3688837cf43e6ac902fc Mon Sep 17 00:00:00 2001 From: Autechre Date: Mon, 31 Aug 2020 14:17:36 +0200 Subject: [PATCH 27/30] Update x_vk_ctx.c --- gfx/drivers_context/x_vk_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/drivers_context/x_vk_ctx.c b/gfx/drivers_context/x_vk_ctx.c index 1f4882f115..3ffa238984 100644 --- a/gfx/drivers_context/x_vk_ctx.c +++ b/gfx/drivers_context/x_vk_ctx.c @@ -464,7 +464,7 @@ static void gfx_ctx_x_vk_input_driver(void *data, if (string_is_equal(input_driver, "udev")) { - *input_data = input_driver_init_wrap(&input_udev.init, joypad_name); + *input_data = input_driver_init_wrap(&input_udev, joypad_name); if (*input_data) { *input = &input_udev; From 71fbd8bdaef5f61d5daa19332edbd166ad0907a4 Mon Sep 17 00:00:00 2001 From: Autechre Date: Mon, 31 Aug 2020 14:22:07 +0200 Subject: [PATCH 28/30] Update x11_input.c --- input/drivers/x11_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 00cd981d25..77a836d195 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -39,7 +39,7 @@ typedef struct x11_input int mouse_x, mouse_y; int mouse_last_x, mouse_last_y; - uint8_t state[32]; + char state[32]; bool mouse_l, mouse_r, mouse_m; bool grab_mouse; } x11_input_t; From fe81f0ad4e1ea43c0ab384dc514099ce5f28b4f8 Mon Sep 17 00:00:00 2001 From: Autechre Date: Mon, 31 Aug 2020 19:27:37 +0200 Subject: [PATCH 29/30] Update wayland_input.c --- input/drivers/wayland_input.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 0f8bff16f4..023a400c46 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -336,13 +336,7 @@ static int16_t input_wl_state( return 0; } -static void input_wl_free(void *data) -{ - input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; - if (!wl) - return; - free(data); -} +static void input_wl_free(void *data) { } bool input_wl_init(void *data, const char *joypad_name) { From a82bff205550d5e619c72a294c5b99276b133d1d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 31 Aug 2020 19:56:03 +0200 Subject: [PATCH 30/30] (Wayland) Fix serious warnings - input struct pointer was being passed to function that requires gfx struct pointer --- gfx/drivers_context/wayland_ctx.c | 10 ++++++---- gfx/drivers_context/wayland_vk_ctx.c | 10 ++++++---- input/common/wayland_common.h | 3 +++ input/drivers/wayland_input.c | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index bef4e5dde2..c24b3bba71 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -736,13 +736,15 @@ static void gfx_ctx_wl_input_driver(void *data, * on Wayland, so just implement the input driver here. */ if (!input_wl_init(&wl->input, joypad_name)) { - *input = NULL; - *input_data = NULL; + wl->input.gfx = NULL; + *input = NULL; + *input_data = NULL; } else { - *input = &input_wayland; - *input_data = &wl->input; + wl->input.gfx = wl; + *input = &input_wayland; + *input_data = &wl->input; input_driver_init_joypads(); } } diff --git a/gfx/drivers_context/wayland_vk_ctx.c b/gfx/drivers_context/wayland_vk_ctx.c index e852f8fcab..a62b3bfd7d 100644 --- a/gfx/drivers_context/wayland_vk_ctx.c +++ b/gfx/drivers_context/wayland_vk_ctx.c @@ -549,13 +549,15 @@ static void gfx_ctx_wl_input_driver(void *data, * on Wayland, so just implement the input driver here. */ if (!input_wl_init(&wl->input, joypad_name)) { - *input = NULL; - *input_data = NULL; + wl->input.gfx = NULL; + *input = NULL; + *input_data = NULL; } else { - *input = &input_wayland; - *input_data = &wl->input; + wl->input.gfx = wl; + *input = &input_wayland; + *input_data = &wl->input; input_driver_init_joypads(); } } diff --git a/input/common/wayland_common.h b/input/common/wayland_common.h index 9772a1684c..fe421c7642 100644 --- a/input/common/wayland_common.h +++ b/input/common/wayland_common.h @@ -83,10 +83,13 @@ typedef struct output_info struct wl_list link; /* wl->all_outputs */ } output_info_t; +typedef struct gfx_ctx_wayland_data gfx_ctx_wayland_data_t; + typedef struct input_ctx_wayland_data { struct wl_display *dpy; const input_device_driver_t *joypad; + gfx_ctx_wayland_data_t *gfx; int fd; diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 023a400c46..61956f82a5 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -88,7 +88,7 @@ static void input_wl_poll(void *data) for (id = 0; id < MAX_TOUCHES; id++) { - if (wayland_context_gettouchpos(wl, id, &touch_x, &touch_y)) + if (wayland_context_gettouchpos(wl->gfx, id, &touch_x, &touch_y)) wl->touches[id].active = true; else wl->touches[id].active = false;