[qwaq] Separate out mouse (de)init code

This is the simplest fix for the curses/input initialization order
issue. The terminal io code should still be moved to its own file,
really, but I think it can wait.
This commit is contained in:
Bill Currie 2021-09-23 13:14:42 +09:00
parent 72900fd16b
commit 6f71ef6657
5 changed files with 20 additions and 7 deletions

View file

@ -1595,6 +1595,8 @@ bi_initialize (progs_t *pr)
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
refresh(); refresh();
qwaq_input_enable_mouse ();
res->stdscr.win = stdscr; res->stdscr.win = stdscr;
create_thread (qwaq_curses_thread, res); create_thread (qwaq_curses_thread, res);
@ -1843,6 +1845,7 @@ bi_curses_clear (progs_t *pr, void *data)
__auto_type res = (qwaq_resources_t *) data; __auto_type res = (qwaq_resources_t *) data;
if (res->initialized) { if (res->initialized) {
qwaq_input_disable_mouse ();
endwin (); endwin ();
} }
need_endwin = 0; need_endwin = 0;

View file

@ -569,13 +569,26 @@ qwaq_input_init (qwaq_input_resources_t *res)
action.sa_handler = handle_winch; action.sa_handler = handle_winch;
sigaction (SIGWINCH, &action, &save_winch); sigaction (SIGWINCH, &action, &save_winch);
#endif #endif
}
void
qwaq_input_enable_mouse (void)
{
// ncurses takes care of input mode for us, so need only tell xterm // ncurses takes care of input mode for us, so need only tell xterm
// what we need // what we need
(void) !write(1, MOUSE_MOVES_ON, sizeof (MOUSE_MOVES_ON) - 1); (void) !write(1, MOUSE_MOVES_ON, sizeof (MOUSE_MOVES_ON) - 1);
(void) !write(1, SGR_ON, sizeof (SGR_ON) - 1); (void) !write(1, SGR_ON, sizeof (SGR_ON) - 1);
} }
void
qwaq_input_disable_mouse (void)
{
// ncurses takes care of input mode for us, so need only tell xterm
// what we need
(void) !write(1, SGR_OFF, sizeof (SGR_OFF) - 1);
(void) !write(1, MOUSE_MOVES_OFF, sizeof (MOUSE_MOVES_OFF) - 1);
}
static void static void
qwaq_process_input (qwaq_input_resources_t *res) qwaq_process_input (qwaq_input_resources_t *res)
{ {
@ -588,11 +601,6 @@ qwaq_input_shutdown (qwaq_input_resources_t *res)
IE_Remove_Handler (res->input_event_handler); IE_Remove_Handler (res->input_event_handler);
IN_DriverData (term_driver_handle, 0); IN_DriverData (term_driver_handle, 0);
// ncurses takes care of input mode for us, so need only tell xterm
// what we need
(void) !write(1, SGR_OFF, sizeof (SGR_OFF) - 1);
(void) !write(1, MOUSE_MOVES_OFF, sizeof (MOUSE_MOVES_OFF) - 1);
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
sigaction (SIGWINCH, &save_winch, 0); sigaction (SIGWINCH, &save_winch, 0);
#endif #endif

View file

@ -42,8 +42,8 @@ arp_end (void)
return nil; return nil;
} }
initialize ();
init_input (); init_input ();
initialize ();
for (int i = 1; i < 64; i++) { for (int i = 1; i < 64; i++) {
init_pair (i, i & 0x7, i >> 3); init_pair (i, i & 0x7, i >> 3);
color_palette[i] = COLOR_PAIR (i); color_palette[i] = COLOR_PAIR (i);

View file

@ -41,8 +41,8 @@ arp_end (void)
return nil; return nil;
} }
initialize ();
init_input (); init_input ();
initialize ();
for (int i = 1; i < 64; i++) { for (int i = 1; i < 64; i++) {
init_pair (i, i & 0x7, i >> 3); init_pair (i, i & 0x7, i >> 3);
color_palette[i] = COLOR_PAIR (i); color_palette[i] = COLOR_PAIR (i);

View file

@ -127,6 +127,8 @@ typedef struct qwaq_input_resources_s {
} qwaq_input_resources_t; } qwaq_input_resources_t;
int qwaq_add_event (qwaq_input_resources_t *res, qwaq_event_t *event); int qwaq_add_event (qwaq_input_resources_t *res, qwaq_event_t *event);
void qwaq_input_enable_mouse (void);
void qwaq_input_disable_mouse (void);
#endif #endif