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/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..c24b3bba71 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -736,13 +736,16 @@ 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 6a9b21104b..a62b3bfd7d 100644 --- a/gfx/drivers_context/wayland_vk_ctx.c +++ b/gfx/drivers_context/wayland_vk_ctx.c @@ -549,13 +549,16 @@ 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/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..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_udev.init(joypad_name); + *input_data = input_driver_init_wrap(&input_udev, 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/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/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/android_input.c b/input/drivers/android_input.c index e00231ae65..f18fadf13b 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 @@ -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; @@ -156,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; @@ -166,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); @@ -432,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) >> @@ -445,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) >> @@ -461,8 +457,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? */ @@ -498,9 +494,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; @@ -543,8 +540,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; } @@ -554,7 +549,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; @@ -563,74 +559,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) { @@ -649,16 +577,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) @@ -695,13 +629,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; @@ -762,11 +697,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++) @@ -815,7 +752,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; @@ -828,7 +766,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; @@ -1232,7 +1171,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); @@ -1246,11 +1186,12 @@ 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 - engine_handle_dpad(android, event, port, source); + engine_handle_dpad(android_app, event, port, source); break; case AINPUT_EVENT_TYPE_KEY: { @@ -1260,8 +1201,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 @@ -1287,7 +1231,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; @@ -1296,34 +1241,22 @@ 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. */ -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, - android_keyboard_port_input_pressed(input_config_binds[0], + && 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, NULL, NULL, NULL)) >= 0) @@ -1360,9 +1293,6 @@ static void android_input_poll(void *data) return; } } - - if (android_app->input_alive) - android_input_poll_memcpy(android); } bool android_run_events(void *data) @@ -1389,10 +1319,17 @@ 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) + 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; @@ -1402,13 +1339,13 @@ 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++) { 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); } } @@ -1420,9 +1357,9 @@ 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) + || ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], id) ) return 1; } @@ -1431,19 +1368,86 @@ static int16_t android_input_state(void *data, 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: + 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); @@ -1451,33 +1455,13 @@ static int16_t android_input_state(void *data, 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; - 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; @@ -1494,10 +1478,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 @@ -1511,8 +1491,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) | @@ -1569,7 +1547,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; @@ -1593,26 +1571,14 @@ 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; } @@ -1626,10 +1592,7 @@ input_driver_t input_android = { android_input_get_capabilities, "android", - android_input_grab_mouse, + NULL, /* grab_mouse */ NULL, - android_input_set_rumble, - android_input_get_joypad_driver, - NULL, - false + android_input_set_rumble }; diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index f84a7913e4..66e9445b1d 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,115 +84,19 @@ 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, - 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, +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) + 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; @@ -210,15 +108,15 @@ 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 ; - if (!input_cocoa.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -235,12 +133,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 @@ -255,12 +153,87 @@ static int16_t cocoa_input_state(void *data, 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; @@ -274,31 +247,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; @@ -306,8 +271,6 @@ static bool cocoa_input_set_rumble(void *data, static uint64_t cocoa_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_MOUSE) | @@ -316,33 +279,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 +288,7 @@ 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 + cocoa_input_set_rumble }; diff --git a/input/drivers/cocoa_input.h b/input/drivers/cocoa_input.h index 013973752c..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; @@ -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..5239316737 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -35,19 +35,17 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ctr_input_t *ctr = (ctr_input_t*)data; @@ -58,13 +56,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 +76,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,48 +85,24 @@ static void* ctr_input_init(const char *joypad_driver) if (!ctr) return NULL; - ctr->joypad = input_joypad_init_driver(joypad_driver, ctr); - return ctr; } static uint64_t ctr_input_get_capabilities(void *data) { - (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, /* grab_mouse */ NULL, - ctr_input_set_rumble, - ctr_input_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index ef2d652280..1ea410e7d4 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- @@ -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( @@ -327,38 +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) -{ - const struct retro_keybind *bind_minus, *bind_plus; - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0, id_plus = 0; - - input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - - bind_minus = &binds[id_minus]; - bind_plus = &binds[id_plus]; - - if (!bind_minus->valid || !bind_plus->valid) - return 0; - - if (bind_minus->key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; - if (di->state[sym] & 0x80) - pressed_minus = -0x7fff; - } - if (bind_plus->key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_plus->key]; - if (di->state[sym] & 0x80) - pressed_plus = 0x7fff; - } - - return pressed_plus + pressed_minus; -} - static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned idx, unsigned id) { @@ -431,144 +394,17 @@ 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, +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) + 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; @@ -585,7 +421,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) @@ -602,7 +438,7 @@ static int16_t dinput_input_state(void *data, } } - if (!input_dinput.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -624,14 +460,14 @@ 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 && (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 ( @@ -650,27 +486,165 @@ static int16_t dinput_input_state(void *data, 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); - break; - case RETRO_DEVICE_MOUSE: { - settings = config_get_ptr(); - if (settings->uints.input_mouse_index[port] == 0) - return dinput_mouse_state(di, port, 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 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) { @@ -737,13 +711,13 @@ 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; 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 ) @@ -923,9 +897,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 +929,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 +947,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 +967,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 +1001,7 @@ input_driver_t input_dinput = { NULL, dinput_get_capabilities, "dinput", - dinput_grab_mouse, NULL, - dinput_set_rumble, - dinput_get_joypad_driver, - NULL, - false + dinput_set_rumble }; diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 5fd2dc4558..055f8afbcd 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -33,21 +33,13 @@ 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 */ /* 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]; @@ -62,21 +54,19 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + 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; @@ -87,7 +77,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++) @@ -95,7 +85,8 @@ static int16_t dos_input_state(void *data, 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,9 +99,11 @@ 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) + || (id < RARCH_BIND_LIST_END + && dos_key_state[DOS_KEYBOARD_PORT] + [rarch_keysym_lut[binds[port][id].key]]) ) return 1; } @@ -118,7 +111,8 @@ static int16_t dos_input_state(void *data, 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; } @@ -129,9 +123,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 +138,24 @@ 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, /* grab_mouse */ NULL, - dos_input_set_rumble, - dos_input_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 16b731fa8f..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 { @@ -47,98 +50,25 @@ typedef struct typedef struct gx_input { - const input_device_driver_t *joypad; #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: - return 0; - } -} -#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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { gx_input_t *gx = (gx_input_t*)data; @@ -149,12 +79,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; @@ -162,10 +92,92 @@ static int16_t gx_input_state(void *data, 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 } @@ -179,8 +191,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 +198,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,105 +212,101 @@ 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 void gx_input_poll_mouse(gx_input_t *gx) +static INLINE int rvl_count_mouse(gx_input_t *gx) { - int count = gx_count_mouse(gx); + unsigned i; + int count = 0; - if (gx && count > 0) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { - unsigned i; - if (count != gx->mouse_max) - { - gx_input_mouse_t* tmp = NULL; - - 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); - } + const char *joypad_name = joypad_driver_name(i); + if (!string_is_empty(joypad_name)) + if (string_is_equal(joypad_name, "Wiimote Controller")) + count++; } -} -#endif -static void gx_input_poll(void *data) + return count; +} + +static void rvl_input_poll(void *data) { gx_input_t *gx = (gx_input_t*)data; - - if (gx && gx->joypad) + if (gx && gx->mouse) { - gx->joypad->poll(); -#ifdef HW_RVL - if (gx->mouse) - gx_input_poll_mouse(gx); -#endif + int count = rvl_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 uint64_t gx_input_get_capabilities(void *data) +static uint64_t rvl_input_get_capabilities(void *data) { - (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 -} - -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, NULL, +#ifdef HW_RVL + rvl_input_get_capabilities, +#else gx_input_get_capabilities, +#endif "gx", - gx_input_grab_mouse, + NULL, /* grab_mouse */ NULL, - gx_input_set_rumble, - gx_input_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index f155621320..b5c0750a44 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,47 +69,20 @@ static void *linuxraw_input_init(const char *joypad_driver) linux_terminal_claim_stdin(); - linuxraw->joypad = input_joypad_init_driver(joypad_driver, linuxraw); - return linuxraw; } -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; - - input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - - bind_minus = &binds[id_minus]; - bind_plus = &binds[id_plus]; - - if (!bind_minus->valid || !bind_plus->valid) - return 0; - - if (bind_minus->key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; - if (linuxraw->state[sym] & 0x80) - pressed_minus = -0x7fff; - } - if (bind_plus->key < RETROK_LAST) - { - unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key]; - if (linuxraw->state[sym] & 0x80) - pressed_plus = 0x7fff; - } - - 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) + 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; @@ -120,7 +92,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 +117,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; @@ -159,8 +131,37 @@ static int16_t linuxraw_input_state(void *data, break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return linuxraw_analog_pressed( - 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; } @@ -174,28 +175,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) @@ -211,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) @@ -220,29 +212,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 +232,7 @@ 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 + linuxraw_set_rumble }; diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 77743e6f0b..209abb0901 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -28,22 +28,20 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps2_input_t *ps2 = (ps2_input_t*)data; @@ -51,11 +49,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 +68,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,56 +77,36 @@ static void* ps2_input_initialize(const char *joypad_driver) if (!ps2) return NULL; - ps2->joypad = input_joypad_init_driver(joypad_driver, ps2); - return ps2; } static uint64_t ps2_input_get_capabilities(void *data) { - (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 + ps2_input_set_rumble }; diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 01cb40cbad..2e97a3778f 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -48,25 +48,21 @@ typedef struct ps3_input { #ifdef HAVE_MOUSE unsigned mice_connected; +#else + void *empty; #endif - const input_device_driver_t *joypad; } ps3_input_t; +#ifdef HAVE_MOUSE static void ps3_input_poll(void *data) { + CellMouseInfo mouse_info; ps3_input_t *ps3 = (ps3_input_t*)data; - if (ps3 && ps3->joypad) - ps3->joypad->poll(); - -#ifdef HAVE_MOUSE - CellMouseInfo mouse_info; 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) { @@ -93,11 +89,17 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps3_input_t *ps3 = (ps3_input_t*)data; @@ -108,11 +110,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; @@ -125,16 +127,13 @@ static int16_t ps3_input_state(void *data, { /* 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 @@ -154,9 +153,6 @@ static void ps3_input_free_input(void *data) if (!ps3) return; - if (ps3->joypad) - ps3->joypad->destroy(); - #ifdef HAVE_MOUSE cellMouseEnd(); #endif @@ -173,14 +169,11 @@ static void* ps3_input_init(const char *joypad_driver) cellMouseInit(MAX_MICE); #endif - ps3->joypad = input_joypad_init_driver(joypad_driver, ps3); - return ps3; } static uint64_t ps3_input_get_capabilities(void *data) { - (void)data; return #ifdef HAVE_MOUSE (1 << RETRO_DEVICE_MOUSE) | @@ -193,7 +186,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,48 +193,41 @@ 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; } + + return false; } -static bool ps3_input_set_rumble(void *data, unsigned port, +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 && ps3->joypad) - return input_joypad_set_rumble(ps3->joypad, + if (joypad) + return input_joypad_set_rumble(joypad, port, effect, 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, +#ifdef HAVE_MOUSE ps3_input_poll, +#else + NULL, /* poll */ +#endif ps3_input_state, ps3_input_free_input, ps3_input_set_sensor_state, @@ -250,10 +235,7 @@ 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 + ps3_input_set_rumble }; diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index 608425d28d..fcb7e0e9fa 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -34,22 +34,20 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps4_input_t *ps4 = (ps4_input_t*)data; @@ -57,12 +55,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 +73,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 +82,36 @@ 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 + ps4_input_set_rumble }; diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index b6bb796fdf..0f604762ae 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]) @@ -115,24 +112,32 @@ 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++) { - 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; break; } + } if (newly_depressed) { @@ -143,14 +148,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); @@ -160,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; @@ -179,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; @@ -193,21 +199,29 @@ 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; } -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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { ps3_input_t *ps3 = (ps3_input_t*)data; @@ -220,14 +234,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 +254,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,14 +298,11 @@ 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; } static uint64_t ps3_input_get_capabilities(void *data) { - (void)data; return #ifdef HAVE_MOUSE (1 << RETRO_DEVICE_MOUSE) | @@ -301,27 +313,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; -} - -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; -} + enum retro_sensor_action action, unsigned event_rate) { return false; } input_driver_t input_ps3 = { ps3_input_init, @@ -333,12 +325,9 @@ 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 + NULL /* set_rumble */ }; /* RetroArch - A frontend for libretro. @@ -555,14 +544,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 10a07940e2..237279ce91 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -50,8 +50,13 @@ #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,15 +71,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 { - const input_device_driver_t *joypad; -#ifdef VITA int keyboard_hid_handle; int mouse_hid_handle; int32_t mouse_x; @@ -87,13 +86,11 @@ typedef struct psp_input bool mouse_button_right; bool mouse_button_middle; bool sensors_enabled; -#endif } psp_input_t; -static void psp_input_poll(void *data) +static void vita_input_poll(void *data) { - psp_input_t *psp = (psp_input_t*)data; -#ifdef VITA + psp_input_t *psp = (psp_input_t*)data; unsigned int i = 0; int key_sym = 0; unsigned key_code = 0; @@ -101,7 +98,6 @@ static void psp_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]; @@ -109,7 +105,7 @@ static void psp_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); @@ -137,9 +133,9 @@ static void psp_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 @@ -191,7 +187,7 @@ static void psp_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) @@ -221,70 +217,38 @@ static void psp_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; -#endif - - if (psp && psp->joypad) - psp->joypad->poll(); + psp->mouse_y = MOUSE_MAX_Y; } - -#ifdef VITA -static int16_t psp_input_mouse_state( - psp_input_t *psp, unsigned id, bool screen) +#else +typedef struct psp_input { - int val = 0; - switch (id) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - val = psp->mouse_button_left; - break; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - val = psp->mouse_button_right; - break; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - val = psp->mouse_button_middle; - break; - 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 */ - } - 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 */ - } - break; - } - - return val; -} + void *empty; +} psp_input_t; #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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { psp_input_t *psp = (psp_input_t*)data; @@ -297,12 +261,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; @@ -310,13 +274,39 @@ static int16_t psp_input_state(void *data, 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 } @@ -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,15 +341,11 @@ 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; } static uint64_t psp_input_get_capabilities(void *data) { - (void)data; - uint64_t caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); #ifdef VITA @@ -374,27 +355,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; } @@ -405,7 +375,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) @@ -477,7 +447,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 +468,7 @@ 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 + psp_input_set_rumble }; diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 9ea8a7cf1e..708f38c2b8 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,10 +769,17 @@ 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) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { qnx_input_t *qnx = (qnx_input_t*)data; @@ -786,10 +789,10 @@ 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) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -809,12 +812,12 @@ 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 ( ((id == RARCH_GAME_FOCUS_TOGGLE) || - !input_qnx.keyboard_mapping_blocked) && + !keyboard_mapping_blocked) && qnx_keyboard_pressed(qnx, key) ) return 1; @@ -855,12 +858,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, @@ -872,8 +869,5 @@ input_driver_t input_qnx = { "qnx_input", NULL, NULL, - NULL, - qnx_input_get_joypad_driver, - NULL, - false + NULL }; diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index f0dac8cb08..fc4fd74f19 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; @@ -221,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; } @@ -263,23 +261,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; } @@ -287,8 +281,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; @@ -303,28 +296,31 @@ 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(); - 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( @@ -332,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( @@ -340,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( @@ -348,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( @@ -365,13 +362,7 @@ 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: - free(rwebinput); - return NULL; } static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key) @@ -382,62 +373,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) -{ - 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) +static int16_t rwebinput_mouse_state( + rwebinput_mouse_state_t *mouse, + unsigned id, bool screen) { switch (id) { @@ -473,7 +411,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. */ @@ -484,12 +423,13 @@ 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)) 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) @@ -497,36 +437,17 @@ 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) -{ - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - - input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - - if (id < RARCH_BIND_LIST_END) - { - if (binds[id].valid) - { - if (rwebinput_is_pressed(rwebinput, - rwebinput->joypad, joypad_info, binds, idx, id_minus)) - pressed_minus = -0x7fff; - if (rwebinput_is_pressed(rwebinput, - rwebinput->joypad, joypad_info, binds, idx, id_plus)) - pressed_plus = 0x7fff; - } - } - - 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) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; @@ -542,8 +463,9 @@ static int16_t rwebinput_input_state(void *data, if (binds[port][i].valid) { if (rwebinput_is_pressed( - rwebinput, rwebinput->joypad, - joypad_info, binds[port], port, i)) + rwebinput, joypad, + joypad_info, binds[port], port, i, + keyboard_mapping_blocked)) ret |= (1 << i); } } @@ -556,9 +478,10 @@ 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)) + port, id, + keyboard_mapping_blocked)) return 1; } } @@ -566,20 +489,103 @@ static int16_t rwebinput_input_state(void *data, break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return rwebinput_analog_pressed( - rwebinput, 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, + 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, + keyboard_mapping_blocked)) + ret += -0x7fff; + } + + return ret; + } 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; @@ -591,28 +597,27 @@ 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); } -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) @@ -648,48 +653,33 @@ 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; - - 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 +704,5 @@ input_driver_t input_rwebinput = { "rwebinput", rwebinput_grab_mouse, NULL, - rwebinput_set_rumble, - rwebinput_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 6a01a39cae..503bba08f3 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -36,10 +36,19 @@ 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; + 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) @@ -50,8 +59,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; } @@ -72,126 +79,17 @@ 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, - unsigned idx, unsigned id) -{ - int16_t pressed_minus = 0, pressed_plus = 0; - unsigned id_minus = 0; - unsigned id_plus = 0; - - 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; - - return pressed_plus + pressed_minus; -} - -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, +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) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { sdl_input_t *sdl = (sdl_input_t*)data; @@ -201,7 +99,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 +117,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)) @@ -230,26 +128,136 @@ static int16_t sdl_input_state(void *data, break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return sdl_analog_pressed(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) - 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; @@ -272,16 +280,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 +297,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 +330,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 +406,11 @@ 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 + sdl_set_rumble }; diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index cbba6b7896..96d641c76f 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,107 +276,18 @@ 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) -{ - 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(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; @@ -394,12 +298,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; @@ -407,15 +311,84 @@ static int16_t switch_input_state(void *data, 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 } @@ -799,18 +772,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 +828,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 +844,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 +951,18 @@ 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 + switch_input_set_rumble }; diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index d69cd780c1..83f4b87aef 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; @@ -165,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, @@ -349,13 +350,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; } @@ -388,9 +389,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; } @@ -774,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) @@ -934,29 +932,6 @@ static bool udev_mouse_button_pressed( return false; } -static int16_t udev_analog_pressed(udev_input_t *udev, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; - - 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; - - return pressed_plus + pressed_minus; -} - static int16_t udev_pointer_state(udev_input_t *udev, unsigned port, unsigned id, bool screen) { @@ -980,11 +955,16 @@ 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) + 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) ) @@ -992,7 +972,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, @@ -1003,10 +983,17 @@ 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) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { udev_input_t *udev = (udev_input_t*)data; @@ -1016,7 +1003,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++) @@ -1027,7 +1014,7 @@ static int16_t udev_input_state(void *data, ret |= (1 << i); } } - if (!input_udev.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -1048,14 +1035,14 @@ 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 ( (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, @@ -1067,23 +1054,51 @@ static int16_t udev_input_state(void *data, break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return udev_analog_pressed(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); 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: @@ -1095,41 +1110,74 @@ static int16_t udev_input_state(void *data, 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - return udev_input_lightgun_state(udev, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_RELOAD); case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: - return udev_input_lightgun_state(udev, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_AUX_C); case RETRO_DEVICE_ID_LIGHTGUN_START: - return udev_input_lightgun_state(udev, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - return udev_input_lightgun_state(udev, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_SELECT); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_SELECT); case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: - return udev_input_lightgun_state(udev, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); + return udev_input_lightgun_state(udev, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); - /*deprecated*/ + return udev_input_lightgun_state(udev, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); + /*deprecated*/ case RETRO_DEVICE_ID_LIGHTGUN_X: { udev_input_mouse_t *mouse = udev_get_mouse(udev, port); @@ -1148,7 +1196,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, @@ -1172,9 +1220,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); @@ -1319,8 +1364,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: @@ -1330,8 +1373,6 @@ error: static uint64_t udev_input_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | @@ -1366,24 +1407,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, @@ -1399,8 +1434,5 @@ input_driver_t input_udev = { #else NULL, #endif - udev_input_set_rumble, - udev_input_get_joypad_driver, - NULL, - false + udev_input_set_rumble }; diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index b85c35af12..c016963e94 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,62 +73,28 @@ 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, - 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; - - /* 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]; - - if (!bind_minus->valid || !bind_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; - - 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, - unsigned index, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned index, + unsigned id) { uwp_input_t *uwp = (uwp_input_t*)data; @@ -148,10 +104,10 @@ 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) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -184,13 +140,13 @@ 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) && 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, @@ -202,7 +158,35 @@ static int16_t uwp_input_state(void *data, 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); @@ -228,10 +212,7 @@ 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 + uwp_input_set_rumble }; diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 22f96eff00..61956f82a5 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,98 +86,15 @@ static void input_wl_poll(void *data) wl->mouse.delta_y = 0; } - if (wl->joypad) - wl->joypad->poll(); - - input_wl_touch_pool(wl); -} - -static int16_t input_wl_analog_pressed(input_ctx_wayland_data_t *wl, - const struct retro_keybind *binds, - unsigned idx, unsigned id) -{ - unsigned id_minus = 0; - unsigned id_plus = 0; - int16_t pressed_minus = 0; - int16_t pressed_plus = 0; - - 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; - - return pressed_plus + pressed_minus; -} - -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->gfx, 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, @@ -295,10 +147,17 @@ 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) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data; @@ -308,7 +167,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 +188,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, @@ -341,18 +201,111 @@ static int16_t input_wl_state(void *data, break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return input_wl_analog_pressed(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); + 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. */ + } + } + break; 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) @@ -360,21 +313,30 @@ static int16_t input_wl_state(void *data, 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; } -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(); -} +static void input_wl_free(void *data) { } bool input_wl_init(void *data, const char *joypad_name) { @@ -385,18 +347,11 @@ 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; } static uint64_t input_wl_get_capabilities(void *data) { - (void)data; - return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | @@ -405,30 +360,17 @@ 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(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, @@ -438,10 +380,7 @@ input_driver_t input_wayland = { NULL, input_wl_get_capabilities, "wayland", - input_wl_grab_mouse, + NULL, /* grab_mouse */ NULL, - input_wl_set_rumble, - input_wl_get_joypad_driver, - NULL, - false + input_wl_set_rumble }; diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index e37d59367f..372feecd32 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) @@ -90,43 +90,17 @@ 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, unsigned id) -{ - switch (id) - { - case RETRO_DEVICE_ID_POINTER_PRESSED: - { - input_bits_t state; - wiiu->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); - case RETRO_DEVICE_ID_POINTER_Y: - return wiiu->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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { wiiu_input_t *wiiu = (wiiu_input_t*)data; @@ -137,12 +111,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 +127,23 @@ 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); + /* 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; @@ -163,9 +153,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); @@ -177,14 +164,13 @@ 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); - DEBUG_STR(joypad_driver); - wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu); - return wiiu; } @@ -196,36 +182,16 @@ 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, /* grab_mouse */ NULL, - wiiu_input_set_rumble, - wiiu_input_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 989db21935..22efb7ecf8 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; @@ -80,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()); } @@ -118,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) { @@ -238,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) @@ -257,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) { @@ -339,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; @@ -432,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]; @@ -510,8 +488,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,19 +534,21 @@ 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) + 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)) @@ -582,20 +560,27 @@ 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) + bool keyboard_mapping_blocked, + 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 +610,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) @@ -641,7 +626,7 @@ static int16_t winraw_input_state(void *d, } } - if (!input_winraw.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -663,14 +648,14 @@ 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 ( (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, @@ -687,9 +672,8 @@ static int16_t winraw_input_state(void *d, 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: @@ -704,47 +688,91 @@ 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, - binds, port, device, idx, RARCH_LIGHTGUN_TRIGGER); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_TRIGGER); case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: - return winraw_input_lightgun_state(wr, mouse, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_RELOAD); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_A); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_B); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_AUX_C); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); case RETRO_DEVICE_ID_LIGHTGUN_SELECT: - return winraw_input_lightgun_state(wr, mouse, joypad_info, - binds, port, device, idx, RARCH_LIGHTGUN_SELECT); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_UP); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_DOWN); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_LEFT); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT); /*deprecated*/ 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_info, - binds, port, device, idx, RARCH_LIGHTGUN_START); + return winraw_input_lightgun_state(wr, mouse, joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, device, idx, RARCH_LIGHTGUN_START); } break; } @@ -756,8 +784,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 +819,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 = { @@ -819,8 +841,5 @@ input_driver_t input_winraw = { "raw", winraw_grab_mouse, NULL, - winraw_set_rumble, - winraw_get_joypad_driver, - NULL, - false + winraw_set_rumble }; diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 75f94a4dc8..77a836d195 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; @@ -46,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; @@ -66,8 +67,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; } @@ -80,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; @@ -106,172 +103,17 @@ 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) -{ - 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; - - input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); - - 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; - - 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; - - return pressed_plus + pressed_minus; -} - -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, +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) + 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(); @@ -285,7 +127,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) @@ -300,7 +142,7 @@ static int16_t x_input_state(void *data, } } } - if (!input_x.keyboard_mapping_blocked) + if (!keyboard_mapping_blocked) { for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { @@ -321,14 +163,14 @@ 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 ( ((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) @@ -343,20 +185,112 @@ static int16_t x_input_state(void *data, 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); 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 ) @@ -365,20 +299,61 @@ static int16_t x_input_state(void *data, 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: { 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) ) 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; @@ -394,14 +369,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -417,14 +392,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -440,14 +415,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -463,14 +438,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -486,14 +461,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -509,14 +484,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -532,14 +507,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -555,14 +530,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -578,14 +553,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -601,14 +576,14 @@ static int16_t x_input_state(void *data, 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) ) 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; @@ -629,14 +604,14 @@ static int16_t x_input_state(void *data, 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) ) 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,20 +638,21 @@ static void x_input_free(void *data) if (!x11) return; - if (x11->joypad) - x11->joypad->destroy(); - 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; @@ -727,22 +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); - - if (x11->joypad) - x11->joypad->poll(); -} - static void x_grab_mouse(void *data, bool state) { x11_input_t *x11 = (x11_input_t*)data; @@ -750,24 +710,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; @@ -793,8 +746,5 @@ input_driver_t input_x = { "x", x_grab_mouse, NULL, - x_set_rumble, - x_get_joypad_driver, - NULL, - false + x_set_rumble }; diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 5bd77cdcc1..b0c01d3d75 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -37,22 +37,20 @@ 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, - unsigned index, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned index, + unsigned id) { xdk_input_t *xdk = (xdk_input_t*)data; @@ -63,12 +61,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 +84,6 @@ static void xdk_input_free_input(void *data) if (!xdk) return; - if (xdk->joypad) - xdk->joypad->destroy(); - free(xdk); } @@ -98,57 +93,38 @@ 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 + xdk_input_set_rumble }; diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 3839c5a395..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; @@ -61,11 +62,17 @@ 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, - unsigned idx, unsigned id) + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) { uint64_t button = binds[port][id].joykey; @@ -109,7 +116,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 +126,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 +139,7 @@ input_driver_t input_xenon360 = { NULL, xenon360_input_get_capabilities, "xenon360", - xenon360_input_grab_mouse, + NULL, /* grab_mouse */ NULL, - xenon360_input_set_rumble, - xenon360_get_joypad_driver, - NULL, - false + NULL /* set_rumble */ }; 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; } diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 6ded6e6644..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- @@ -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.h b/input/drivers_joypad/dinput_joypad.h index 1a5e2cbdf1..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-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_hybrid_joypad.c b/input/drivers_joypad/dinput_joypad_excl.h similarity index 86% rename from input/drivers_joypad/dinput_hybrid_joypad.c rename to input/drivers_joypad/dinput_joypad_excl.h index d65d905ab8..1eca1aea0c 100644 --- a/input/drivers_joypad/dinput_hybrid_joypad.c +++ b/input/drivers_joypad/dinput_joypad_excl.h @@ -1,209 +1,177 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - 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" - -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); - } -} - -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", -}; +/* 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 . + */ + +#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..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- @@ -35,48 +34,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 +103,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 +307,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 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- diff --git a/input/input_driver.h b/input/input_driver.h index bf414f07a7..ecde7f4ee8 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -181,8 +181,11 @@ 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, + bool keyboard_mapping_blocked, unsigned port, unsigned device, unsigned index, unsigned id); /* Frees the input struct. */ @@ -196,11 +199,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; }; struct rarch_joypad_driver diff --git a/retroarch.c b/retroarch.c index a379561709..e22b85c7e3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -676,10 +676,14 @@ 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, + 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, enum retro_sensor_action action, unsigned rate) { return false; } @@ -687,10 +691,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, @@ -703,10 +708,7 @@ static input_driver_t input_null = { "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, + input_null_set_rumble }; static input_driver_t *input_drivers[] = { @@ -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 @@ -2550,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; @@ -2798,7 +2802,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 +3534,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 +3619,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 +3639,17 @@ 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, + p_rarch->keyboard_mapping_blocked, + 0, + RETRO_DEVICE_KEYBOARD, + 0, + RETROK_RETURN); menu_input_key_bind_poll_bind_state_internal( joypad, state, port, timed_out); @@ -3958,7 +3968,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; @@ -3979,8 +3988,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++; @@ -4010,11 +4018,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); @@ -4059,8 +4066,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 @@ -15621,7 +15627,15 @@ static void command_event_reinit(struct rarch_state *p_rarch, 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 @@ -17139,7 +17153,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, @@ -17151,7 +17165,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, @@ -23377,6 +23391,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,18 +23412,42 @@ 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); + p_rarch->keyboard_mapping_blocked, + 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, + p_rarch->keyboard_mapping_blocked, + 0, + device, + i, + RETRO_DEVICE_ID_POINTER_X); + 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); + p_rarch->keyboard_mapping_blocked, + 0, + device, + i, + RETRO_DEVICE_ID_POINTER_Y); memset(&polled_data, 0, sizeof(struct input_overlay_state)); @@ -23712,19 +23755,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 +23847,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,9 +23884,18 @@ 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, - (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); + 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, + p_rarch->keyboard_mapping_blocked, + (unsigned)i, + RETRO_DEVICE_JOYPAD, + 0, + RARCH_TURBO_ENABLE); } #ifdef HAVE_OVERLAY @@ -23825,7 +23918,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,8 +23942,11 @@ 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, + p_rarch->keyboard_mapping_blocked, (unsigned)i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); @@ -24512,6 +24608,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 +24638,23 @@ 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->libretro_input_binds, port, device, idx, id); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, + p_rarch->libretro_input_binds, + p_rarch->keyboard_mapping_blocked, + 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 +24806,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,8 +24849,13 @@ static int16_t menu_input_read_mouse_hw( } return p_rarch->current_input->input_state( - p_rarch->current_input_data, &joypad_info, - NULL, 0, device, 0, type); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, + NULL, + p_rarch->keyboard_mapping_blocked, + 0, device, 0, type); } static void menu_input_get_mouse_hw_state( @@ -24882,6 +25003,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,8 +25048,13 @@ 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, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, + p_rarch->keyboard_mapping_blocked, + 0, pointer_device, + 0, RETRO_DEVICE_ID_POINTER_X); hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; /* > An annoyance - we get different starting positions @@ -24944,8 +25077,13 @@ 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, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, + p_rarch->keyboard_mapping_blocked, + 0, pointer_device, + 0, RETRO_DEVICE_ID_POINTER_Y); hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; if (pointer_device == RARCH_DEVICE_POINTER_SCREEN) @@ -24964,8 +25102,13 @@ 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, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, + 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; @@ -24973,8 +25116,13 @@ 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, - 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + &joypad_info, binds, + 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; @@ -26216,12 +26364,24 @@ 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, - &binds[port], port, RETRO_DEVICE_JOYPAD, 0, + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + joypad_info, + &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) @@ -26251,8 +26411,12 @@ 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, + &binds[port], + p_rarch->keyboard_mapping_blocked, + port, RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE)) p_rarch->input_driver_block_hotkey = false; } @@ -26274,7 +26438,11 @@ static void input_keys_pressed( { int16_t ret = p_rarch->current_input->input_state( p_rarch->current_input_data, - joypad_info, &binds[port], port, RETRO_DEVICE_JOYPAD, 0, + p_rarch->joypad, + sec_joypad, + 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++) @@ -26308,8 +26476,13 @@ 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, - &binds[port], port, RETRO_DEVICE_JOYPAD, 0, i); + p_rarch->current_input_data, + p_rarch->joypad, + sec_joypad, + joypad_info, + &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)) @@ -26326,13 +26499,40 @@ 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) +{ + 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 +27085,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 +27103,15 @@ 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, + p_rarch->keyboard_mapping_blocked, + port, + RETRO_DEVICE_MOUSE, 0, id); return false; } #endif @@ -27156,7 +27370,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; } @@ -27276,7 +27490,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) @@ -27315,7 +27529,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 { @@ -27356,12 +27570,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; @@ -31343,6 +31557,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,8 +31648,18 @@ 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); - p_rarch->current_input->keyboard_mapping_blocked = false; + 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->keyboard_mapping_blocked = false; } p_rarch->current_input_data = NULL; } @@ -34563,7 +34788,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 @@ -38591,7 +38817,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; { @@ -38608,6 +38834,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,7 +38941,11 @@ static enum runloop_state runloop_check_state( { if (p_rarch->current_input->input_state( p_rarch->current_input_data, - &joypad_info, &binds, port, + p_rarch->joypad, + sec_joypad, + &joypad_info, &binds, + p_rarch->keyboard_mapping_blocked, + 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);