From 756c297535ed10534973e84387419ea7d728938e Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Thu, 1 Oct 2020 00:48:19 -0700 Subject: [PATCH 2/2] WIP: Adding mouse navigation of tty menus. --- src/term.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/term.c b/src/term.c index 3677644845..8167763e84 100644 --- a/src/term.c +++ b/src/term.c @@ -3101,7 +3101,27 @@ read_menu_input (struct frame *sf, int *x, int *y, int min_y, int max_y, st = MI_SCROLL_BACK; } else if (EQ (cmd, Qtty_menu_select)) - st = MI_ITEM_SELECTED; + { + // Remaining to do: + // * Add new symbol "tty-menu-mouse-select-or-dismiss", bind to mouse buttons. + // * If click is in visible menu act as if tty-menu-select, otherwise act as if tty-menu-exit. + // * Ensure logic works with any menu popup position. + Lisp_Object posn_x_y = CALLN (Ffuncall, intern ("posn-x-y"), + CALLN (Ffuncall, intern ("event-start"), last_nonmenu_event)); + int mouse_x = XFIXNUM (Fcar (posn_x_y)); + int mouse_y = XFIXNUM (Fcdr (posn_x_y)); + message ("In read_menu_input: tty_menu_select w/ mouse_x=%d, mouse_y=%d, min_y=%d, max_y=%d", + mouse_x, mouse_y, min_y, max_y); + + // Unclear offset -- need to figure this out. Perhaps due to menu-bar? + mouse_y++; + if (mouse_y >= min_y && mouse_y <= max_y) + { + *y = mouse_y; + } + + st = MI_ITEM_SELECTED; + } else if (!EQ (cmd, Qtty_menu_ignore)) usable_input = 0; if (usable_input) @@ -3224,6 +3244,9 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, int max_y = min (min_y + state[0].menu->count, FRAME_TOTAL_LINES (sf) - 1) - 1; input_status = read_menu_input (sf, &x, &y, min_y, max_y, &first_time); + + message("In tty_menu_activate: read_menu_input --> input_status=%d, x=%d, y=%d, first_time=%d", + input_status, x, y, first_time); if (input_status) { leave = 1; @@ -3369,6 +3392,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, clear_input_pending (); SAFE_FREE (); Vinhibit_redisplay = prev_inhibit_redisplay; + message ("Returning result=%d", result); return result; } -- 2.20.1