From c2b45a26e6f4a6866d1e4267fbe007e3e30469c8 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Fri, 14 Dec 2018 01:01:35 -0800 Subject: [PATCH] display: Add ability for device code to optionally handle keyboard input events --- display/sim_ws.c | 35 ++++++++++++++++++++++++++--------- sim_video.h | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/display/sim_ws.c b/display/sim_ws.c index bf61e196..0f8cc14f 100644 --- a/display/sim_ws.c +++ b/display/sim_ws.c @@ -55,6 +55,20 @@ int ws_lp_x = -1; int ws_lp_y = -1; +/* A device simulator can optionally set the vid_display_kb_event_process + * routine pointer to the address of a routine. + * Simulator code which uses the display library which processes window + * keyboard data with code in display/sim_ws.c can use this routine to + * explicitly get access to keyboard events that arrive in the display + * window. This routine should return 0 if it has handled the event that + * was passed, and non zero if it didn't handle it. If the routine address + * is not set or a non zero return value occurs, then the keyboard event + * will be processed by the display library which may then be handled as + * console character input if the device console code is implemented to + * accept this. + */ +int (*vid_display_kb_event_process)(SIM_KEY_EVENT *kev) = NULL; + static int xpixels, ypixels; static int pix_size = PIX_SIZE; static const char *window_name; @@ -220,16 +234,19 @@ ws_poll(int *valp, int maxus) vid_set_cursor_position (mev.x_pos, mev.y_pos); } if (SCPE_OK == vid_poll_kb (&kev)) { - switch (kev.state) { - case SIM_KEYPRESS_DOWN: - case SIM_KEYPRESS_REPEAT: - display_keydown(map_key(kev.key)); - break; - case SIM_KEYPRESS_UP: - display_keyup(map_key(kev.key)); - break; + if ((vid_display_kb_event_process == NULL) || + (vid_display_kb_event_process (&kev) != 0)) { + switch (kev.state) { + case SIM_KEYPRESS_DOWN: + case SIM_KEYPRESS_REPEAT: + display_keydown(map_key(kev.key)); + break; + case SIM_KEYPRESS_UP: + display_keyup(map_key(kev.key)); + break; + } + key_to_ascii (&kev); } - key_to_ascii (&kev); } return 1; } diff --git a/sim_video.h b/sim_video.h index 384f1a43..760a4f29 100644 --- a/sim_video.h +++ b/sim_video.h @@ -199,6 +199,20 @@ extern t_bool vid_active; extern uint32 vid_mono_palette[2]; void vid_set_cursor_position (int32 x, int32 y); /* cursor position (set by calling code) */ +/* A device simulator can optionally set the vid_display_kb_event_process + * routine pointer to the address of a routine. + * Simulator code which uses the display library which processes window + * keyboard data with code in display/sim_ws.c can use this routine to + * explicitly get access to keyboard events that arrive in the display + * window. This routine should return 0 if it has handled the event that + * was passed, and non zero if it didn't handle it. If the routine address + * is not set or a non zero return value occurs, then the keyboard event + * will be processed by the display library which may then be handled as + * console character input if the device console code is implemented to + * accept this. + */ +extern int (*vid_display_kb_event_process)(SIM_KEY_EVENT *kev); + #define SIM_VID_DBG_MOUSE 0x01000000 #define SIM_VID_DBG_CURSOR 0x02000000 #define SIM_VID_DBG_KEY 0x04000000