From aa99f4f5ba1717414ef78b690aeb680f12d85aab Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Tue, 18 Jul 2017 01:16:48 +0200 Subject: [PATCH] Disable keyboard input and restrict mouse input in some cases --- input/drivers/udev_input.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index b6c1dea98f..209933f870 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -549,6 +549,20 @@ static void udev_input_poll(void *data) udev->joypad->poll(); } +static bool udev_pointer_is_off_window(udev_input_mouse_t *mouse) +{ + struct video_viewport view; + bool r = video_driver_get_viewport_info(&view); + + if (r) + r = mouse->x < view.x || + mouse->x >= view.x + view.width || + mouse->y < view.y || + mouse->y >= view.y + view.height; + + return r; +} + static int16_t udev_mouse_state(udev_input_t *udev, unsigned port, unsigned id, bool screen) { @@ -557,6 +571,10 @@ static int16_t udev_mouse_state(udev_input_t *udev, if (!mouse) return 0; + if (id != RETRO_DEVICE_ID_MOUSE_X && id != RETRO_DEVICE_ID_MOUSE_Y && + udev_pointer_is_off_window(mouse)) + return 0; + switch (id) { case RETRO_DEVICE_ID_MOUSE_X: @@ -706,8 +724,10 @@ static int16_t udev_input_state(void *data, joypad_info, port, idx, id, binds[port]); return ret; case RETRO_DEVICE_KEYBOARD: - return id < RETROK_LAST && BIT_GET(udev_key_state, - rarch_keysym_lut[(enum retro_key)id]); + if (video_driver_cb_has_focus()) + return id < RETROK_LAST && BIT_GET(udev_key_state, + rarch_keysym_lut[(enum retro_key)id]); + break; case RETRO_DEVICE_MOUSE: return udev_mouse_state(udev, port, id, false); case RARCH_DEVICE_MOUSE_SCREEN: