diff --git a/include/QF/input/binding.h b/include/QF/input/binding.h index 3b3bc3aa2..5c82d08c2 100644 --- a/include/QF/input/binding.h +++ b/include/QF/input/binding.h @@ -234,6 +234,8 @@ int IN_RegisterAxis (in_axis_t *axis); in_button_t *IN_FindButton (const char *name); in_axis_t *IN_FindAxis (const char *name); +struct IE_event_s; +int IN_Binding_HandleEvent (const struct IE_event_s *ie_event); void IN_Binding_Activate (void); void IN_Binding_Init (void); struct plitem_s; diff --git a/include/QF/input/event.h b/include/QF/input/event.h index 399d25f9f..4b526fa61 100644 --- a/include/QF/input/event.h +++ b/include/QF/input/event.h @@ -99,7 +99,7 @@ typedef enum { | (1 << ie_remove_device) \ ) -typedef struct { +typedef struct IE_event_s { IE_event_type type; uint64_t when; union { diff --git a/libs/input/in_binding.c b/libs/input/in_binding.c index bb846605b..d7da6878c 100644 --- a/libs/input/in_binding.c +++ b/libs/input/in_binding.c @@ -202,6 +202,19 @@ in_binding_event_handler (const IE_event_t *ie_event, void *unused) static void (*handlers[ie_event_count]) (const IE_event_t *ie_event) = { [ie_add_device] = in_binding_add_device, [ie_remove_device] = in_binding_remove_device, + }; + if (ie_event->type < 0 || ie_event->type >= ie_event_count + || !handlers[ie_event->type]) { + return 0; + } + handlers[ie_event->type] (ie_event); + return 1; +} + +int +IN_Binding_HandleEvent (const IE_event_t *ie_event) +{ + static void (*handlers[ie_event_count]) (const IE_event_t *ie_event) = { [ie_axis] = in_binding_axis, [ie_button] = in_binding_button, }; diff --git a/qw/source/cl_input.c b/qw/source/cl_input.c index df8f709ba..8f710c948 100644 --- a/qw/source/cl_input.c +++ b/qw/source/cl_input.c @@ -37,6 +37,7 @@ #include "QF/checksum.h" #include "QF/cmd.h" +#include "QF/console.h" #include "QF/cvar.h" #include "QF/input.h" #include "QF/keys.h" @@ -45,6 +46,8 @@ #include "QF/teamplay.h" #include "QF/va.h" +#include "QF/input/event.h" + #include "compat.h" #include "client/view.h" @@ -61,6 +64,7 @@ int cl_game_context; int cl_demo_context; +static int cl_event_id; cvar_t *cl_nodelta; cvar_t *cl_maxnetfps; @@ -563,9 +567,24 @@ CL_SendCmd (void) Netchan_Transmit (&cls.netchan, buf.cursize, buf.data); } +static int +cl_event_handler (const IE_event_t *ie_event, void *unused) +{ + if (ie_event->type == ie_key) { + if (ie_event->key.code == QFK_ESCAPE) { + // FIXME this should bring up the menu + Con_SetState (con_active); + return 1; + } + } + return IN_Binding_HandleEvent (ie_event); +} + void CL_Input_Init (void) { + cl_event_id = IE_Add_Handler (cl_event_handler, 0); + for (int i = 0; cl_in_axes[i]; i++) { IN_RegisterAxis (cl_in_axes[i]); } @@ -584,7 +603,7 @@ void CL_Input_Activate (void) { IMT_SetContext (cl_game_context); - IN_Binding_Activate (); + IE_Set_Focus (cl_event_id); } void