diff --git a/include/QF/console.h b/include/QF/console.h index b267a7efb..159c99c4d 100644 --- a/include/QF/console.h +++ b/include/QF/console.h @@ -60,6 +60,12 @@ typedef struct { int cur_line; // current line } con_buffer_t; +typedef enum { + con_inactive, + con_active, + con_fullscreen, +} con_state_t; + extern int con_linewidth; extern struct plugin_s *con_module; extern struct console_data_s con_data; @@ -73,7 +79,7 @@ void Con_DrawConsole (void); void Con_Printf (const char *fmt, ...) __attribute__((format(PRINTF, 1, 2))); void Con_Print (const char *fmt, va_list args) __attribute__((format(PRINTF, 1, 0))); -void Con_ToggleConsole_f (void); +void Con_SetState (con_state_t state); struct inputline_s; // wrapper function to attempt to either complete the command line diff --git a/include/QF/input/event.h b/include/QF/input/event.h index 648852258..4ce0dd2b3 100644 --- a/include/QF/input/event.h +++ b/include/QF/input/event.h @@ -88,6 +88,8 @@ typedef enum { ie_key, ie_axis, ie_button, + + ie_event_count } IE_event_type; #define IE_broadcast_events (0 \ @@ -113,5 +115,6 @@ int IE_Send_Event (const IE_event_t *event); int IE_Add_Handler (ie_handler_t *event_handler, void *data); void IE_Remove_Handler (int handle); void IE_Set_Focus (int handle); +int IE_Get_Focus (void); #endif//__QF_in_event_h diff --git a/include/QF/input/imt.h b/include/QF/input/imt.h index e5cc8b02d..1b7bf38fe 100644 --- a/include/QF/input/imt.h +++ b/include/QF/input/imt.h @@ -32,6 +32,7 @@ #ifndef __QFCC__ #include "QF/darray.h" +#include "QF/qtypes.h" #include "QF/input/binding.h" @@ -71,16 +72,20 @@ typedef struct in_context_s { imt_t **imt_tail; imt_t *active_imt; imt_t *default_imt; + struct cbuf_s *cbuf; } in_context_t; int IMT_GetAxisBlock (const char *device, int num_axes); int IMT_GetButtonBlock (const char *device, int num_buttons); int IMT_CreateContext (void); +int IMT_GetContext (void); +void IMT_SetContext (int ctx); +void IMT_SetContextCbuf (int ctx, struct cbuf_s *cbuf); imt_t *IMT_FindIMT (const char *name); int IMT_CreateIMT (int context, const char *imt_name, const char *chain_imt_name); -void IMT_ProcessAxis (int axis, int value); -void IMT_ProcessButton (int button, int state); +qboolean IMT_ProcessAxis (int axis, int value); +qboolean IMT_ProcessButton (int button, int state); #endif diff --git a/include/QF/keys.h b/include/QF/keys.h index c55d76fd8..b66f99414 100644 --- a/include/QF/keys.h +++ b/include/QF/keys.h @@ -42,6 +42,7 @@ ///@{ /// these are the key numbers that should be passed to Key_Event +/// FIXME clashes with actual inicode and OS keys typedef enum { /* The keyboard syms have been cleverly chosen to map to ASCII */ QFK_UNKNOWN = 0, @@ -375,148 +376,6 @@ typedef enum { QFK_BACK, QFK_FORWARD, - /* Add any other keys here */ - -// -// mouse buttons generate virtual keys -// - QFM_BUTTON1, - QFM_BUTTON2, - QFM_BUTTON3, - QFM_WHEEL_UP, - QFM_WHEEL_DOWN, - QFM_BUTTON6, - QFM_BUTTON7, - QFM_BUTTON8, - QFM_BUTTON9, - QFM_BUTTON10, - QFM_BUTTON11, - QFM_BUTTON12, - QFM_BUTTON13, - QFM_BUTTON14, - QFM_BUTTON15, - QFM_BUTTON16, - QFM_BUTTON17, - QFM_BUTTON18, - QFM_BUTTON19, - QFM_BUTTON20, - QFM_BUTTON21, - QFM_BUTTON22, - QFM_BUTTON23, - QFM_BUTTON24, - QFM_BUTTON25, - QFM_BUTTON26, - QFM_BUTTON27, - QFM_BUTTON28, - QFM_BUTTON29, - QFM_BUTTON30, - QFM_BUTTON31, - QFM_BUTTON32, - -// -// joystick buttons -// - QFJ_BUTTON1, - QFJ_BUTTON2, - QFJ_BUTTON3, - QFJ_BUTTON4, - QFJ_BUTTON5, - QFJ_BUTTON6, - QFJ_BUTTON7, - QFJ_BUTTON8, - QFJ_BUTTON9, - QFJ_BUTTON10, - QFJ_BUTTON11, - QFJ_BUTTON12, - QFJ_BUTTON13, - QFJ_BUTTON14, - QFJ_BUTTON15, - QFJ_BUTTON16, - QFJ_BUTTON17, - QFJ_BUTTON18, - QFJ_BUTTON19, - QFJ_BUTTON20, - QFJ_BUTTON21, - QFJ_BUTTON22, - QFJ_BUTTON23, - QFJ_BUTTON24, - QFJ_BUTTON25, - QFJ_BUTTON26, - QFJ_BUTTON27, - QFJ_BUTTON28, - QFJ_BUTTON29, - QFJ_BUTTON30, - QFJ_BUTTON31, - QFJ_BUTTON32, - QFJ_BUTTON33, - QFJ_BUTTON34, - QFJ_BUTTON35, - QFJ_BUTTON36, - QFJ_BUTTON37, - QFJ_BUTTON38, - QFJ_BUTTON39, - QFJ_BUTTON40, - QFJ_BUTTON41, - QFJ_BUTTON42, - QFJ_BUTTON43, - QFJ_BUTTON44, - QFJ_BUTTON45, - QFJ_BUTTON46, - QFJ_BUTTON47, - QFJ_BUTTON48, - QFJ_BUTTON49, - QFJ_BUTTON50, - QFJ_BUTTON51, - QFJ_BUTTON52, - QFJ_BUTTON53, - QFJ_BUTTON54, - QFJ_BUTTON55, - QFJ_BUTTON56, - QFJ_BUTTON57, - QFJ_BUTTON58, - QFJ_BUTTON59, - QFJ_BUTTON60, - QFJ_BUTTON61, - QFJ_BUTTON62, - QFJ_BUTTON63, - QFJ_BUTTON64, - -// -// joystick axes (for button emulation without consuming buttons) -// - QFJ_AXIS1, - QFJ_AXIS2, - QFJ_AXIS3, - QFJ_AXIS4, - QFJ_AXIS5, - QFJ_AXIS6, - QFJ_AXIS7, - QFJ_AXIS8, - QFJ_AXIS9, - QFJ_AXIS10, - QFJ_AXIS11, - QFJ_AXIS12, - QFJ_AXIS13, - QFJ_AXIS14, - QFJ_AXIS15, - QFJ_AXIS16, - QFJ_AXIS17, - QFJ_AXIS18, - QFJ_AXIS19, - QFJ_AXIS20, - QFJ_AXIS21, - QFJ_AXIS22, - QFJ_AXIS23, - QFJ_AXIS24, - QFJ_AXIS25, - QFJ_AXIS26, - QFJ_AXIS27, - QFJ_AXIS28, - QFJ_AXIS29, - QFJ_AXIS30, - QFJ_AXIS31, - QFJ_AXIS32, - QFK_LAST } knum_t; diff --git a/include/QF/plugin/console.h b/include/QF/plugin/console.h index e244ee5c1..e14c4d7dc 100644 --- a/include/QF/plugin/console.h +++ b/include/QF/plugin/console.h @@ -30,8 +30,8 @@ #include +#include #include -#include typedef struct console_funcs_s { void (*init) (void); @@ -40,6 +40,7 @@ typedef struct console_funcs_s { void (*draw_console) (void); void (*check_resize) (void); void (*new_map) (void); + void (*set_state) (con_state_t state); } console_funcs_t; typedef struct console_data_s { diff --git a/libs/console/client.c b/libs/console/client.c index d0329b1d1..1e907be83 100644 --- a/libs/console/client.c +++ b/libs/console/client.c @@ -59,6 +59,8 @@ #include "QF/va.h" #include "QF/vid.h" +#include "QF/input/event.h" + #include "QF/plugin/general.h" #include "QF/plugin/console.h" #include "QF/plugin/vid_render.h" @@ -89,6 +91,9 @@ static float con_times[NUM_CON_TIMES]; // realtime time the line was generated // for transparent notify lines static int con_totallines; // total lines in console scrollback +static con_state_t con_state; +static int con_event_id; +static int con_saved_focos; static qboolean con_debuglog; static qboolean chat_team; @@ -107,7 +112,7 @@ static view_t *hud_view; static qboolean con_initialized; static keydest_t con_curr_keydest; -static keydest_t con_prev_keydest; +//static keydest_t con_prev_keydest; static void ClearNotify (void) @@ -118,19 +123,33 @@ ClearNotify (void) con_times[i] = 0; } +static void +C_SetState (con_state_t state) +{ + con_state = state; + if (con_state == con_inactive) { + IE_Set_Focus (con_saved_focos); + } else { + con_saved_focos = IE_Get_Focus (); + IE_Set_Focus (con_event_id); + } +} static void ToggleConsole_f (void) { Con_ClearTyping (input_line, 0); - if (con_curr_keydest == key_console && !con_data.force_commandline) { - Key_SetKeyDest (con_prev_keydest); - } else { - con_prev_keydest = Key_GetKeyDest (); - Key_SetKeyDest (key_console); + switch (con_state) { + case con_inactive: + C_SetState (con_active); + break; + case con_active: + C_SetState (con_inactive); + break; + case con_fullscreen: + break; } - ClearNotify (); } @@ -140,9 +159,9 @@ ToggleChat_f (void) Con_ClearTyping (input_line, 0); if (con_curr_keydest == key_console && !con_data.force_commandline) { - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); } else { - Key_SetKeyDest (key_console); + //Key_SetKeyDest (key_console); } ClearNotify (); @@ -164,7 +183,7 @@ MessageMode_f (void) if (con_data.force_commandline) return; chat_team = false; - Key_SetKeyDest (key_message); + //Key_SetKeyDest (key_message); } static void @@ -173,7 +192,7 @@ MessageMode2_f (void) if (con_data.force_commandline) return; chat_team = true; - Key_SetKeyDest (key_message); + //Key_SetKeyDest (key_message); } static void @@ -330,7 +349,7 @@ C_Say (inputline_t *il) Cbuf_AddText (con_data.cbuf, "say \""); Cbuf_AddText (con_data.cbuf, line); Cbuf_AddText (con_data.cbuf, "\"\n"); - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); } static void @@ -343,7 +362,7 @@ C_SayTeam (inputline_t *il) Cbuf_AddText (con_data.cbuf, "say_team \""); Cbuf_AddText (con_data.cbuf, line); Cbuf_AddText (con_data.cbuf, "\"\n"); - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); } static void @@ -447,79 +466,6 @@ C_Print (const char *fmt, va_list args) fputs (buffer->str + 1, stdout); } -static void -C_KeyEvent (knum_t key, short unicode, qboolean down, void *data) -{ - inputline_t *il; - - if (!down) - return; - - if (con_curr_keydest == key_menu) { - Menu_KeyEvent (key, unicode, down); - return; - } - - if (down) { - if (key == key_toggleconsole) { - ToggleConsole_f (); - return; - } - } - - if (con_curr_keydest == key_message) { - if (chat_team) { - il = say_team_line; - } else { - il = say_line; - } - } else { - switch (key) { - case QFK_PAGEUP: - if (keydown[QFK_RCTRL] || keydown[QFK_LCTRL]) - con->display = 0; - else - con->display -= 10; - if (con->display < con->current - con->numlines) - con->display = con->current - con->numlines; - return; - case QFK_PAGEDOWN: - if (keydown[QFK_RCTRL] || keydown[QFK_LCTRL]) - con->display = con->current; - else - con->display += 10; - if (con->display > con->current) - con->display = con->current; - return; - case QFM_WHEEL_UP: - con->display -= 3; - if (con->display < con->current - con->numlines) - con->display = con->current - con->numlines; - return; - case QFM_WHEEL_DOWN: - con->display += 3; - if (con->display > con->current) - con->display = con->current; - return; - default: - break; - } - il = input_line; - } - //FIXME should this translation be here? - if ((unicode==0x0A) && (key==QFK_RETURN)) { - Con_ProcessInputLine (il, key); - } - if ((unicode==0x7F) && (key==QFK_BACKSPACE)) { - Con_ProcessInputLine (il, key); - } - if (unicode!=0) { - Con_ProcessInputLine (il, key >= 256 ? (int) key : unicode); - } else { - Con_ProcessInputLine (il, key); - } -} - /* DRAWING */ static void @@ -551,8 +497,8 @@ C_DrawInputLine (inputline_t *il) static void draw_input (view_t *view) { - if (con_curr_keydest != key_console)// && !con_data.force_commandline) - return; // don't draw anything (always draw if not active) + if (con_state == con_inactive)// && !con_data.force_commandline) + return; DrawInputLine (view->xabs + 8, view->yabs, 1, input_line); } @@ -641,7 +587,7 @@ draw_console (view_t *view) { byte alpha; - if (con_data.force_commandline) { + if (con_state == con_fullscreen) { alpha = 255; } else { float y = r_data->vid->conview->ylen * con_size->value; @@ -704,12 +650,17 @@ setup_console (void) { float lines; - if (con_data.force_commandline) { - lines = con_data.lines = r_data->vid->conview->ylen; - } else if (con_curr_keydest == key_console) { - lines = r_data->vid->conview->ylen * bound (0.2, con_size->value, 1); - } else { - lines = 0; + switch (con_state) { + case con_inactive: + lines = 0; + break; + case con_active: + lines = r_data->vid->conview->ylen * bound (0.2, con_size->value, + 1); + break; + case con_fullscreen: + lines = con_data.lines = r_data->vid->conview->ylen; + break; } if (con_speed->value) { @@ -776,13 +727,13 @@ exec_line (inputline_t *il) { Con_ExecLine (il->line); } - +#if 0 static void con_end_message (void *line) { - Key_PopEscape (); + //Key_PopEscape (); Con_ClearTyping (line, 1); - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); } static void @@ -798,7 +749,7 @@ con_keydest_callback (keydest_t kd, void *data) return; } if (kd != key_console && con_curr_keydest == key_console) { - Key_PopEscape (); + //Key_PopEscape (); } switch (kd) { case key_last: @@ -808,11 +759,11 @@ con_keydest_callback (keydest_t kd, void *data) case key_menu: break; case key_message: - Key_PushEscape (con_end_message, - chat_team ? say_team_line : say_line); + //Key_PushEscape (con_end_message, + // chat_team ? say_team_line : say_line); break; case key_console: - Key_PushEscape (con_leave_console, 0); + //Key_PushEscape (con_leave_console, 0); break; } con_curr_keydest = kd; @@ -823,6 +774,108 @@ con_enter_menu (void *data) { Menu_Enter (); } +#endif + +static void +con_key_event (const IE_event_t *event) +{ + inputline_t *il; + __auto_type key = &event->key; + +#if 0 + if (con_curr_keydest == key_menu) { + Menu_KeyEvent (key, unicode, down); + return; + } + + if (down) { + if (key == key_toggleconsole) { + ToggleConsole_f (); + return; + } + } +#endif +#if 0 + if (con_curr_keydest == key_message) { + if (chat_team) { + il = say_team_line; + } else { + il = say_line; + } + } else { +#endif + switch (key->code) { + case QFK_PAGEUP: + if (key->shift & ies_control) + con->display = 0; + else + con->display -= 10; + if (con->display < con->current - con->numlines) + con->display = con->current - con->numlines; + return; + case QFK_PAGEDOWN: + if (key->shift & ies_control) + con->display = con->current; + else + con->display += 10; + if (con->display > con->current) + con->display = con->current; + return; +#if 0 + case QFM_WHEEL_UP: + con->display -= 3; + if (con->display < con->current - con->numlines) + con->display = con->current - con->numlines; + return; + case QFM_WHEEL_DOWN: + con->display += 3; + if (con->display > con->current) + con->display = con->current; + return; +#endif + default: + break; + } + il = input_line; +#if 0 + } +#endif +#if 0 + //FIXME should this translation be here? + if ((unicode==0x0A) && (key==QFK_RETURN)) { + Con_ProcessInputLine (il, key); + } + if ((unicode==0x7F) && (key==QFK_BACKSPACE)) { + Con_ProcessInputLine (il, key); + } +#endif + if (key->unicode) { + Con_ProcessInputLine (il, key->code >= 256 ? (int) key->code + : key->unicode); + } else { + Con_ProcessInputLine (il, key->code); + } +} + +static void +con_mouse_event (const IE_event_t *event) +{ +} + +static int +con_event_handler (const IE_event_t *ie_event, void *data) +{ + static void (*handlers[ie_event_count]) (const IE_event_t *ie_event) = { + [ie_key] = con_key_event, + [ie_mouse] = con_mouse_event, + }; + 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; +} static void C_Init (void) @@ -833,11 +886,13 @@ C_Init (void) setlocale (LC_ALL, "C-TRADITIONAL"); #endif - Key_PushEscape (con_enter_menu, 0); - Key_KeydestCallback (con_keydest_callback, 0); - Key_SetKeyEvent (key_message, C_KeyEvent, 0); - Key_SetKeyEvent (key_menu, C_KeyEvent, 0); - Key_SetKeyEvent (key_console, C_KeyEvent, 0); + con_event_id = IE_Add_Handler (con_event_handler, 0); + + //Key_PushEscape (con_enter_menu, 0); + //Key_KeydestCallback (con_keydest_callback, 0); + //Key_SetKeyEvent (key_message, C_KeyEvent, 0); + //Key_SetKeyEvent (key_menu, C_KeyEvent, 0); + //Key_SetKeyEvent (key_console, C_KeyEvent, 0); Menu_Init (); con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL, @@ -966,6 +1021,7 @@ static console_funcs_t plugin_info_console_funcs = { .draw_console = C_DrawConsole, .check_resize = C_CheckResize, .new_map = C_NewMap, + .set_state = C_SetState, }; static plugin_funcs_t plugin_info_funcs = { diff --git a/libs/console/console.c b/libs/console/console.c index 6e0153f49..5c7323fb0 100644 --- a/libs/console/console.c +++ b/libs/console/console.c @@ -157,6 +157,14 @@ Con_Print (const char *fmt, va_list args) vfprintf (stdout, fmt, args); } +VISIBLE void +Con_SetState (con_state_t state) +{ + if (con_module) { + con_module->functions->console->set_state (state); + } +} + VISIBLE void Con_ProcessInput (void) { diff --git a/libs/console/menu.c b/libs/console/menu.c index f9b96fda7..a90547ffa 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -82,7 +82,7 @@ static cvar_t *confirm_quit; static progs_t menu_pr_state; static menu_item_t *menu; -static keydest_t menu_keydest; +//static keydest_t menu_keydest; static hashtab_t *menu_hash; static func_t menu_init; static func_t menu_quit; @@ -358,13 +358,13 @@ bi_Menu_TopMenu (progs_t *pr) free ((char *) top_menu); top_menu = strdup (name); } - +/* static void menu_leave (void *data) { Menu_Leave (); } - +*/ static void bi_Menu_SelectMenu (progs_t *pr) { @@ -374,11 +374,11 @@ bi_Menu_SelectMenu (progs_t *pr) if (name && *name) menu = Hash_Find (menu_hash, name); if (menu) { - if (Key_GetKeyDest () != key_menu) { + /*if (Key_GetKeyDest () != key_menu) { menu_keydest = Key_GetKeyDest (); Key_PushEscape (menu_leave, 0); Key_SetKeyDest (key_menu); - } + }*/ if (menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); @@ -387,8 +387,8 @@ bi_Menu_SelectMenu (progs_t *pr) } else { if (name && *name) Sys_Printf ("no menu \"%s\"\n", name); - Key_PopEscape (); - Key_SetKeyDest (menu_keydest); + //Key_PopEscape (); + //Key_SetKeyDest (menu_keydest); } } @@ -473,8 +473,8 @@ bi_Menu_Leave (progs_t *pr) } menu = menu->parent; if (!menu) { - Key_PopEscape (); - Key_SetKeyDest (menu_keydest); + //Key_PopEscape (); + //Key_SetKeyDest (menu_keydest); } } } @@ -775,15 +775,15 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down) return 0; switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: +// case QFM_WHEEL_DOWN: bi_Menu_Next (&menu_pr_state); return 1; case QFK_UP: - case QFM_WHEEL_UP: +// case QFM_WHEEL_UP: bi_Menu_Prev (&menu_pr_state); return 1; case QFK_RETURN: - case QFM_BUTTON1: +// case QFM_BUTTON1: bi_Menu_Enter (&menu_pr_state); return 1; default: @@ -795,14 +795,14 @@ void Menu_Enter () { if (!top_menu) { - Key_SetKeyDest (key_console); + //Key_SetKeyDest (key_console); return; } menu = Hash_Find (menu_hash, top_menu); if (menu) { - menu_keydest = Key_GetKeyDest (); - Key_PushEscape (menu_leave, 0); - Key_SetKeyDest (key_menu); + //menu_keydest = Key_GetKeyDest (); + //Key_PushEscape (menu_leave, 0); + //Key_SetKeyDest (key_menu); if (menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); @@ -822,8 +822,8 @@ Menu_Leave () } menu = menu->parent; if (!menu) { - Key_PopEscape (); - Key_SetKeyDest (menu_keydest); + //Key_PopEscape (); + //Key_SetKeyDest (menu_keydest); } } r_data->vid->recalc_refdef = true; diff --git a/libs/gib/gib_keys.c b/libs/gib/gib_keys.c index c40e1bb1c..a45428acd 100644 --- a/libs/gib/gib_keys.c +++ b/libs/gib/gib_keys.c @@ -47,6 +47,7 @@ static void Key_GIB_Bind_Get_f (void) { +#if 0 const char *key, *cmd; imt_t *imt; int k; @@ -68,6 +69,7 @@ Key_GIB_Bind_Get_f (void) GIB_Return (""); else GIB_Return (cmd); +#endif } void diff --git a/libs/input/Makemodule.am b/libs/input/Makemodule.am index 3455be6ab..774141caf 100644 --- a/libs/input/Makemodule.am +++ b/libs/input/Makemodule.am @@ -18,7 +18,6 @@ libs_input_libQFinput_la_LDFLAGS= $(lib_ldflags) libs_input_libQFinput_la_LIBADD= $(input_deps) libs_input_libQFinput_la_DEPENDENCIES= $(input_deps) libs_input_libQFinput_la_SOURCES= \ - libs/input/keys.c \ libs/input/old_keys.c \ libs/input/in_axis.c \ libs/input/in_binding.c \ diff --git a/libs/input/in_binding.c b/libs/input/in_binding.c index 6bcbb5e66..6e663f5f0 100644 --- a/libs/input/in_binding.c +++ b/libs/input/in_binding.c @@ -52,6 +52,7 @@ typedef struct DARRAY_TYPE (in_devbindings_t) in_devbindingset_t; static in_devbindingset_t devbindings = DARRAY_STATIC_INIT (8); +static int in_binding_handler; static void in_binding_add_device (const IE_event_t *ie_event) @@ -133,13 +134,13 @@ in_binding_button (const IE_event_t *ie_event) static int in_binding_event_handler (const IE_event_t *ie_event, void *unused) { - static void (*handlers[]) (const IE_event_t *ie_event) = { + 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, [ie_axis] = in_binding_axis, [ie_button] = in_binding_button, }; - if (ie_event->type < 0 || ie_event->type > ie_button + if (ie_event->type < 0 || ie_event->type >= ie_event_count || !handlers[ie_event->type]) { return 0; } @@ -147,8 +148,105 @@ in_binding_event_handler (const IE_event_t *ie_event, void *unused) return 1; } +static void +in_bind_f (void) +{ +} + +static void +in_unbind_f (void) +{ +} + +static void +in_clear_f (void) +{ +} + +static void +in_devices_f (void) +{ +} + +static void +keyhelp_f (void) +{ +} + +typedef struct { + const char *name; + xcommand_t func; + const char *desc; +} bindcmd_t; + +static bindcmd_t in_binding_commands[] = { + { "in_bind", in_bind_f, + "Assign a command or a set of commands to a key.\n" + "Note: To bind multiple commands to a key, enclose the " + "commands in quotes and separate with semi-colons." + }, + { "in_unbind", in_unbind_f, + "Remove the bind from the the selected key" + }, + { "in_clear", in_clear_f, + "Remove all binds from the specified imts" + }, + { "in_devices", in_devices_f, + "List the known devices and their status." + }, + { "keyhelp", keyhelp_f, + "Identify the next active input axis or button.\n" + "The identification includes the device binding name, axis or button " + "number, and (if known) the name of the axis or button. Axes and " + "buttons can always be bound by number, so even those for which a " + "name is not known, but" PACKAGE_NAME " sees, can be bound." + }, + { } +#if 0 + { "bindlist", Key_Bindlist_f, + "list all of the key bindings" + }, + { "unbindall", Key_Unbindall_f, + "Remove all binds (USE CAUTIOUSLY!!!" + }, + { "unbind", Key_Unbind_f, + "wrapper for in_unbind that uses in_bind_imt for the imt " + "parameter" + }, + { "bind", Key_Bind_f, + "wrapper for in_bind that uses " + "in_bind_imt for the imt parameter" + }, + { "imt", Key_InputMappingTable_f, + "" + }, + { "imt_keydest", Key_IMT_Keydest_f, + "" + }, + { "imt_create", Key_IMT_Create_f, + "create a new imt table:\n" + " imt_create [chain_name]\n" + "\n" + "The new table will be attached to the specified keydest\n" + "imt_name must not already exist.\n" + "If given, chain_name must already exist and be on " + "keydest.\n" + }, + { "imt_drop_all", Key_IMT_Drop_All_f, + "delete all imt tables\n" + }, + { "in_type", Key_In_Type_f, + "Send the given string as simulated key presses." + }, +#endif +}; + void IN_Binding_Init (void) { - IE_Add_Handler (in_binding_event_handler, 0); + in_binding_handler = IE_Add_Handler (in_binding_event_handler, 0); + + for (bindcmd_t *cmd = in_binding_commands; cmd->name; cmd++) { + Cmd_AddCommand (cmd->name, cmd->func, cmd->desc); + } } diff --git a/libs/input/in_event.c b/libs/input/in_event.c index b2aaf362c..0fdfa0f9b 100644 --- a/libs/input/in_event.c +++ b/libs/input/in_event.c @@ -108,3 +108,9 @@ IE_Set_Focus (int handle) IE_Send_Event (&event); } } + +int +IE_Get_Focus (void) +{ + return focus; +} diff --git a/libs/input/in_imt.c b/libs/input/in_imt.c index 4a00032f9..3c1a3eddb 100644 --- a/libs/input/in_imt.c +++ b/libs/input/in_imt.c @@ -42,6 +42,7 @@ #include "QF/cmd.h" #include "QF/hash.h" #include "QF/sys.h" +#include "QF/va.h" #include "QF/input/imt.h" @@ -56,6 +57,7 @@ static imt_blockset_t axis_blocks = DARRAY_STATIC_INIT (8); static imt_blockset_t button_blocks = DARRAY_STATIC_INIT (8); static in_contextset_t in_contexts = DARRAY_STATIC_INIT (8); +static size_t imt_current_context; static imt_block_t * __attribute__((pure)) imt_find_block (imt_blockset_t *blockset, const char *device) @@ -149,6 +151,30 @@ IMT_CreateContext (void) return ctx - in_contexts.a; } +int +IMT_GetContext (void) +{ + return imt_current_context; +} + +void +IMT_SetContext (int ctx) +{ + if ((size_t) ctx >= in_contexts.size) { + Sys_Error ("IMT_SetContext: invalid context %d", ctx); + } + imt_current_context = ctx; +} + +void +IMT_SetContextCbuf (int ctx, cbuf_t *cbuf) +{ + if ((size_t) ctx >= in_contexts.size) { + Sys_Error ("IMT_SetContextCbuf: invalid context %d", ctx); + } + in_contexts.a[imt_current_context].cbuf = cbuf; +} + static imt_t * __attribute__ ((pure)) imt_find_imt (in_context_t *ctx, const char *name) { @@ -227,12 +253,64 @@ IMT_CreateIMT (int context, const char *imt_name, const char *chain_imt_name) return 1; } -void +qboolean IMT_ProcessAxis (int axis, int value) { + imt_t *imt = in_contexts.a[imt_current_context].active_imt; + + while (imt) { + in_axisbinding_t *a = imt->axis_bindings.a[axis]; + if (a) { + return true; + } + imt = imt->chain; + } + return false; } -void +static void +process_binding (int button, int state, const char *cmd) +{ + cbuf_t *cbuf = in_contexts.a[imt_current_context].cbuf; + + if (!cbuf) { + return; + } + + if (cmd[0] == '+') { + if (state) { + Cbuf_AddText (cbuf, va (0, "%s %d\n", cmd, button)); + } else { + Cbuf_AddText (cbuf, va (0, "-%s %d\n", cmd + 1, button)); + } + } else { + if (state) { + Cbuf_AddText (cbuf, va (0, "%s\n", cmd)); + } + } +} + +qboolean IMT_ProcessButton (int button, int state) { + imt_t *imt = in_contexts.a[imt_current_context].active_imt; + + Sys_Printf ("IMT_ProcessButton: %d %d\n", button, state); + while (imt) { + in_buttonbinding_t *b = imt->button_bindings.a[button]; + if (b) { + switch (b->type) { + case inb_button: + IN_ButtonAction (b->button, button, state); + break; + case inb_command: + //FIXME avoid repeat + process_binding (button, state, b->command); + break; + } + return true; + } + imt = imt->chain; + } + return false; } diff --git a/libs/ruamoko/rua_keys.c b/libs/ruamoko/rua_keys.c index f5617406b..32229a4c4 100644 --- a/libs/ruamoko/rua_keys.c +++ b/libs/ruamoko/rua_keys.c @@ -43,8 +43,10 @@ static void bi_Key_keydown (progs_t *pr) { +#if 0 int keynum = P_INT (pr, 0); R_INT (pr) = keydown[keynum]; +#endif } /* @@ -55,6 +57,7 @@ bi_Key_keydown (progs_t *pr) static void bi_Key_SetBinding (progs_t *pr) { +#if 0 const char *imt_name = P_GSTRING (pr, 0); int keynum = P_INT (pr, 1); const char *binding = P_GSTRING (pr, 2); @@ -68,6 +71,7 @@ bi_Key_SetBinding (progs_t *pr) if (imt) { Key_SetBinding (imt, keynum, binding); } +#endif } /* @@ -78,6 +82,7 @@ bi_Key_SetBinding (progs_t *pr) static void bi_Key_LookupBinding (progs_t *pr) { +#if 0 const char *imt_name = P_GSTRING (pr, 0); int bindnum = P_INT (pr, 1); const char *binding = P_GSTRING (pr, 2); @@ -89,7 +94,7 @@ bi_Key_LookupBinding (progs_t *pr) imt = Key_FindIMT (imt_name); if (imt) { for (i = 0; i < QFK_LAST; i++) { -//XXX keybind = imt->button_bindings.a[i].str; + keybind = imt->button_bindings.a[i].str; if (keybind == NULL) { continue; } @@ -104,7 +109,8 @@ bi_Key_LookupBinding (progs_t *pr) } R_INT (pr) = keynum; -}; +#endif +} /* bi_Key_CountBinding @@ -114,6 +120,7 @@ bi_Key_LookupBinding (progs_t *pr) static void bi_Key_CountBinding (progs_t *pr) { +#if 0 const char *imt_name = P_GSTRING (pr, 0); const char *binding = P_GSTRING (pr, 1); int i, res = 0; @@ -123,7 +130,7 @@ bi_Key_CountBinding (progs_t *pr) imt = Key_FindIMT (imt_name); if (imt) { for (i = 0; i < QFK_LAST; i++) { -//XXX keybind = imt->button_bindings.a[i].str; + keybind = imt->button_bindings.a[i].str; if (keybind == NULL) { continue; } @@ -134,7 +141,8 @@ bi_Key_CountBinding (progs_t *pr) } R_INT (pr) = res; -}; +#endif +} /* @@ -145,16 +153,20 @@ bi_Key_CountBinding (progs_t *pr) static void bi_Key_KeynumToString (progs_t *pr) { +#if 0 int keynum = P_INT (pr, 0); RETURN_STRING (pr, Key_KeynumToString (keynum)); -}; +#endif +} static void bi_Key_StringToKeynum (progs_t *pr) { +#if 0 const char *keyname = P_GSTRING (pr, 0); R_INT (pr) = Key_StringToKeynum (keyname); +#endif } static builtin_t builtins[] = { diff --git a/libs/video/targets/in_x11.c b/libs/video/targets/in_x11.c index cd5d2bde8..7c7afe24e 100644 --- a/libs/video/targets/in_x11.c +++ b/libs/video/targets/in_x11.c @@ -807,7 +807,9 @@ event_key (XEvent *event) x11_key.shift = event->xmotion.state & 0xff; XLateKey (&event->xkey, &x11_key.code, &x11_key.unicode); - in_x11_send_key_event (); + if (event->type == KeyPress) { + in_x11_send_key_event (); + } } static void diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index a48d593d5..c1c879cac 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -114,7 +114,7 @@ CL_WriteConfiguration (void) return; } - Key_WriteBindings (f); + //Key_WriteBindings (f); Cvar_WriteVariables (f); Qclose (f); @@ -321,7 +321,7 @@ CL_EstablishConnection (const char *host) cls.demonum = -1; // not in the demo loop now CL_SetState (ca_connected); - Key_SetKeyDest (cls.key_dest); + //Key_SetKeyDest (cls.key_dest); } /* @@ -497,7 +497,7 @@ CL_SetState (cactive_t state) if (old_state != state) { if (old_state == ca_active) { // leaving active state - Key_SetKeyDest (key_console); + //Key_SetKeyDest (key_console); S_AmbientOff (); } switch (state) { @@ -512,14 +512,14 @@ CL_SetState (cactive_t state) cls.signon = so_none; // need all the signon messages // before playing cl.loading = true; - Key_SetKeyDest (cls.key_dest); + //Key_SetKeyDest (cls.key_dest); IN_ClearStates (); VID_SetCaption ("Connected"); break; case ca_active: // entering active state cl.loading = false; - Key_SetKeyDest (cls.key_dest); + //Key_SetKeyDest (cls.key_dest); IN_ClearStates (); VID_SetCaption (""); S_AmbientOn (); diff --git a/nq/source/host.c b/nq/source/host.c index 397911f90..2128e7f74 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -847,13 +847,13 @@ Host_Init_Memory (void) Sys_Printf ("%4.1f megabyte heap\n", host_mem_size->value); } - +#if 0 static void host_keydest_callback (keydest_t kd, void *data) { host_in_game = kd == key_game; } - +#endif void Host_Init (void) { @@ -888,7 +888,7 @@ Host_Init (void) Mod_Init (); - Key_KeydestCallback (host_keydest_callback, 0); + //Key_KeydestCallback (host_keydest_callback, 0); SV_Init (); diff --git a/nq/source/sbar.c b/nq/source/sbar.c index 5cbf233b9..5798a0112 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -1642,13 +1642,13 @@ Sbar_GIB_Print_Center_f (void) } else Sbar_CenterPrint (GIB_Argv(1)); } - +#if 0 static void sbar_keydest_callback (keydest_t kd, void *data) { overlay_view->visible = kd == key_game; } - +#endif void Sbar_Init (void) { @@ -1656,7 +1656,7 @@ Sbar_Init (void) init_views (); - Key_KeydestCallback (sbar_keydest_callback, 0); + //Key_KeydestCallback (sbar_keydest_callback, 0); for (i = 0; i < 10; i++) { sb_nums[0][i] = r_funcs->Draw_PicFromWad (va (0, "num_%i", i)); diff --git a/qw/source/cl_chat.c b/qw/source/cl_chat.c index da3b5f9e8..a101a5f27 100644 --- a/qw/source/cl_chat.c +++ b/qw/source/cl_chat.c @@ -237,7 +237,7 @@ CL_Chat_Flush_Ignores (void) { llist_flush (ignore_list); } - +#if 0 static void CL_ChatInfo (int val) { @@ -268,6 +268,7 @@ cl_chat_keydest (keydest_t keydest, void *data) break; } } +#endif void CL_Chat_Init (void) @@ -277,5 +278,5 @@ CL_Chat_Init (void) Cmd_AddCommand ("ignore", CL_Ignore_f, "Ignores chat and name-change messages from a user."); Cmd_AddCommand ("unignore", CL_Unignore_f, "Removes a previously ignored user from the ignore list."); - Key_KeydestCallback (cl_chat_keydest, 0); + //Key_KeydestCallback (cl_chat_keydest, 0); } diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index dd4114e14..9d10c2897 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -1014,7 +1014,7 @@ CL_StartDemo (void) Sys_Printf ("Playing demo from %s.\n", name->str); cls.demoplayback = true; - Key_SetKeyDest (key_demo); + //Key_SetKeyDest (key_demo); net_blocksend = 1; if (type == 2) { cls.demoplayback2 = true; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index ce71b1ad8..82e2df4d7 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1146,7 +1146,7 @@ CL_SetState (cactive_t state) if (old_state == ca_active) { // leaving active state IN_ClearStates (); - Key_SetKeyDest (key_console); + //Key_SetKeyDest (key_console); // Auto demo recorder stops here if (cl_autorecord->int_val && cls.demorecording) @@ -1155,7 +1155,7 @@ CL_SetState (cactive_t state) // entering active state VID_SetCaption (cls.servername->str); IN_ClearStates (); - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); // Auto demo recorder starts here if (cl_autorecord->int_val && !cls.demoplayback @@ -1163,8 +1163,7 @@ CL_SetState (cactive_t state) CL_Record (0, -1); } } - if (con_module) - con_module->data->console->force_commandline = (state != ca_active); + Con_SetState (state == ca_active ? con_inactive : con_fullscreen); } void @@ -1512,7 +1511,7 @@ Host_WriteConfiguration (void) return; } - Key_WriteBindings (f); + //Key_WriteBindings (f); Cvar_WriteVariables (f); Qclose (f); diff --git a/qw/source/sbar.c b/qw/source/sbar.c index 373b108c6..4c6d58710 100644 --- a/qw/source/sbar.c +++ b/qw/source/sbar.c @@ -1939,13 +1939,13 @@ Sbar_GIB_Print_Center_f (void) } else Sbar_CenterPrint (GIB_Argv(1)); } - +#if 0 static void sbar_keydest_callback (keydest_t kd, void *data) { overlay_view->visible = kd == key_game; } - +#endif void Sbar_Init (void) { @@ -1953,7 +1953,7 @@ Sbar_Init (void) init_views (); - Key_KeydestCallback (sbar_keydest_callback, 0); + //Key_KeydestCallback (sbar_keydest_callback, 0); for (i = 0; i < 10; i++) { sb_nums[0][i] = r_funcs->Draw_PicFromWad (va (0, "num_%i", i)); diff --git a/ruamoko/cl_menu/CrosshairView.r b/ruamoko/cl_menu/CrosshairView.r index 81152efee..0ca4e9532 100644 --- a/ruamoko/cl_menu/CrosshairView.r +++ b/ruamoko/cl_menu/CrosshairView.r @@ -32,7 +32,7 @@ { switch (key) { case QFK_RETURN: - case QFM_BUTTON1: + //case QFM_BUTTON1: [self next]; return 1; default: diff --git a/ruamoko/cl_menu/CvarToggleView.r b/ruamoko/cl_menu/CvarToggleView.r index 2102e99ab..8c1e96840 100644 --- a/ruamoko/cl_menu/CvarToggleView.r +++ b/ruamoko/cl_menu/CvarToggleView.r @@ -47,7 +47,7 @@ { switch (key) { case QFK_RETURN: - case QFM_BUTTON1: + //case QFM_BUTTON1: [self toggle]; return 1; default: diff --git a/ruamoko/cl_menu/MenuGroup.r b/ruamoko/cl_menu/MenuGroup.r index 5c89382c7..356d9d795 100644 --- a/ruamoko/cl_menu/MenuGroup.r +++ b/ruamoko/cl_menu/MenuGroup.r @@ -30,11 +30,11 @@ if (!ret) { switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: [self next]; return 1; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: [self prev]; return 1; } diff --git a/ruamoko/cl_menu/client_menu.r b/ruamoko/cl_menu/client_menu.r index dc4cd487e..a962f4305 100644 --- a/ruamoko/cl_menu/client_menu.r +++ b/ruamoko/cl_menu/client_menu.r @@ -47,11 +47,11 @@ menu_key_sound = { switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: S_LocalSound ("misc/menu1.wav"); break; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: S_LocalSound ("misc/menu1.wav"); break; } @@ -231,19 +231,19 @@ int (int key, int unicode, int down) load_quickbup_keyevent = { switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: S_LocalSound ("misc/menu1.wav"); load_cursor++; load_cursor %= MAX_QUICK; return 1; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: S_LocalSound ("misc/menu1.wav"); load_cursor += MAX_QUICK - 1; load_cursor %= MAX_QUICK; return 1; case QFK_RETURN: - case QFM_BUTTON1: + //case QFM_BUTTON1: if (loadable[load_cursor]) { S_LocalSound ("misc/menu2.wav"); Menu_SelectMenu (nil); @@ -259,19 +259,19 @@ int (int key, int unicode, int down) load_keyevent = { switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: S_LocalSound ("misc/menu1.wav"); load_cursor++; load_cursor %= MAX_SAVEGAMES + 1; return 1; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: S_LocalSound ("misc/menu1.wav"); load_cursor += MAX_SAVEGAMES; load_cursor %= MAX_SAVEGAMES + 1; return 1; case QFK_RETURN: - case QFM_BUTTON1: + //case QFM_BUTTON1: if (load_cursor == MAX_SAVEGAMES) { load_cursor = 0; scan_saves (1); @@ -290,19 +290,19 @@ int (int key, int unicode, int down) save_keyevent = { switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: S_LocalSound ("misc/menu1.wav"); save_cursor++; save_cursor %= MAX_SAVEGAMES; return 1; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: S_LocalSound ("misc/menu1.wav"); save_cursor += MAX_SAVEGAMES - 1; save_cursor %= MAX_SAVEGAMES; return 1; case QFK_RETURN: - case QFM_BUTTON1: + //case QFM_BUTTON1: Menu_SelectMenu (nil); Cbuf_AddText (sprintf ("save s%i.sav\n", save_cursor)); return 1; @@ -494,7 +494,7 @@ int (int key, int unicode, int down) lanconfig_keyevent = [input_active processInput:(key >= 256 ? key : unicode)]; switch (key) { case QFK_DOWN: - case QFM_WHEEL_DOWN: + //case QFM_WHEEL_DOWN: if (!input_active) { S_LocalSound ("misc/menu2.wav"); lanConfig_cursor ++; @@ -502,7 +502,7 @@ int (int key, int unicode, int down) lanconfig_keyevent = } return 1; case QFK_UP: - case QFM_WHEEL_UP: + //case QFM_WHEEL_UP: if (!input_active) { S_LocalSound ("misc/menu2.wav"); lanConfig_cursor += NUM_LANCONFIG_CMDS - 1; diff --git a/ruamoko/qwaq/builtins/input.c b/ruamoko/qwaq/builtins/input.c index 6d62ce4a2..82c3f8f16 100644 --- a/ruamoko/qwaq/builtins/input.c +++ b/ruamoko/qwaq/builtins/input.c @@ -526,6 +526,7 @@ qwaq_input_event_handler (const IE_event_t *ie_event, void *_res) event.when = ie_event->when * 1e-6 + Sys_DoubleTimeBase (); switch (ie_event->type) { + case ie_event_count: case ie_none: case ie_gain_focus: case ie_lose_focus: diff --git a/ruamoko/qwaq/builtins/qwaq-bi.c b/ruamoko/qwaq/builtins/qwaq-bi.c index 4d296ad73..ee29dbc5b 100644 --- a/ruamoko/qwaq/builtins/qwaq-bi.c +++ b/ruamoko/qwaq/builtins/qwaq-bi.c @@ -205,7 +205,7 @@ BI_Init (progs_t *pr) con_module->data->console->quit = quit_f; con_module->data->console->cbuf = qwaq_cbuf; } - Key_SetKeyDest (key_game); + //Key_SetKeyDest (key_game); S_Init (0, &con_frametime); //CDAudio_Init ();