display: Add ability for device code to optionally handle keyboard input events

This commit is contained in:
Mark Pizzolato 2018-12-14 01:01:35 -08:00
parent 6e7127d954
commit c2b45a26e6
2 changed files with 40 additions and 9 deletions

View file

@ -55,6 +55,20 @@
int ws_lp_x = -1; int ws_lp_x = -1;
int ws_lp_y = -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 xpixels, ypixels;
static int pix_size = PIX_SIZE; static int pix_size = PIX_SIZE;
static const char *window_name; static const char *window_name;
@ -220,6 +234,8 @@ ws_poll(int *valp, int maxus)
vid_set_cursor_position (mev.x_pos, mev.y_pos); vid_set_cursor_position (mev.x_pos, mev.y_pos);
} }
if (SCPE_OK == vid_poll_kb (&kev)) { if (SCPE_OK == vid_poll_kb (&kev)) {
if ((vid_display_kb_event_process == NULL) ||
(vid_display_kb_event_process (&kev) != 0)) {
switch (kev.state) { switch (kev.state) {
case SIM_KEYPRESS_DOWN: case SIM_KEYPRESS_DOWN:
case SIM_KEYPRESS_REPEAT: case SIM_KEYPRESS_REPEAT:
@ -231,6 +247,7 @@ ws_poll(int *valp, int maxus)
} }
key_to_ascii (&kev); key_to_ascii (&kev);
} }
}
return 1; return 1;
} }

View file

@ -199,6 +199,20 @@ extern t_bool vid_active;
extern uint32 vid_mono_palette[2]; extern uint32 vid_mono_palette[2];
void vid_set_cursor_position (int32 x, int32 y); /* cursor position (set by calling code) */ 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_MOUSE 0x01000000
#define SIM_VID_DBG_CURSOR 0x02000000 #define SIM_VID_DBG_CURSOR 0x02000000
#define SIM_VID_DBG_KEY 0x04000000 #define SIM_VID_DBG_KEY 0x04000000