Skip to content

Commit

Permalink
Improve touchpad key binding response
Browse files Browse the repository at this point in the history
  • Loading branch information
ceski-1 committed Aug 6, 2024
1 parent 639abf8 commit a5cfc27
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/i_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "i_gyro.h"
#include "i_printf.h"
#include "i_system.h"
#include "i_timer.h"
#include "m_config.h"
#include "mn_menu.h"

Expand Down Expand Up @@ -153,26 +154,40 @@ void I_UpdateGamepad(evtype_t type, boolean axis_buttons)
static void UpdateTouchState(boolean menu, boolean on)
{
static event_t ev = {.data1.i = GAMEPAD_TOUCHPAD_TOUCH};
static int touch_time;

if (on)
{
if (!menu)
if (menu)
{
touch_time = I_GetTimeMS();
}
else
{
ev.type = ev_joyb_down;
D_PostEvent(&ev);
}
}
else if (menu) // Allow separate "touch" and "press" bindings.
{
ev.type = ev_joyb_down;
D_PostEvent(&ev);
ev.type = ev_joyb_up;
D_PostEvent(&ev);
}
else
{
ev.type = ev_joyb_up;
D_PostEvent(&ev);
if (menu)
{
// Allow separate "touch" and "press" bindings. Touch binding is
// registered after 100 ms to prevent accidental activation.
if (I_GetTimeMS() - touch_time > 100)
{

ev.type = ev_joyb_down;
D_PostEvent(&ev);
ev.type = ev_joyb_up;
D_PostEvent(&ev);
}
}
else
{
ev.type = ev_joyb_up;
D_PostEvent(&ev);
}
}
}

Expand Down

0 comments on commit a5cfc27

Please sign in to comment.