From 3f4fe8dc4c1961dfa185a47c5256bf9103c90ff8 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Sat, 23 Jan 2021 16:53:43 -0800 Subject: [PATCH 3/4] Support 'mouse-autoselect-window' for GPM and xterm mouse * src/dispnew.c (update_mouse_position): Generate SELECT_WINDOW_EVENT. --- src/dispnew.c | 32 ++++++++++++++++++++++++++++++-- src/w32term.c | 1 + 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/dispnew.c b/src/dispnew.c index e603c67136..5dc4ac24db 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -3335,11 +3335,39 @@ update_frame_with_menu (struct frame *f, int row, int col) int update_mouse_position (struct frame *f, int x, int y) { + int event_count = 0; + previous_help_echo_string = help_echo_string; help_echo_string = Qnil; note_mouse_highlight (f, x, y); + /* When the mouse moves over a new window, generate a + SELECT_WINDOW_EVENT. */ + if (!NILP (Vmouse_autoselect_window)) + { + static Lisp_Object last_mouse_window; + Lisp_Object window = window_from_coordinates (f, x, y, 0, 0, 0); + + /* Window will be selected only when it is not selected now and + last mouse movement event was not in it. Minibuffer window + will be selected only when it is active. */ + if (WINDOWP (window) + && !EQ (window, last_mouse_window) + && !EQ (window, selected_window)) + { + struct input_event event; + EVENT_INIT (event); + event.kind = SELECT_WINDOW_EVENT; + event.frame_or_window = window; + kbd_buffer_store_event (&event); + ++event_count; + } + + /* Remember the last window where we saw the mouse. */ + last_mouse_window = window; + } + /* If the contents of the global variable help_echo_string has changed, generate a HELP_EVENT. */ if (!NILP (help_echo_string) @@ -3350,10 +3378,10 @@ update_mouse_position (struct frame *f, int x, int y) gen_help_event (help_echo_string, frame, help_echo_window, help_echo_object, help_echo_pos); - return 1; + ++event_count; } - return 0; + return event_count; } DEFUN ("display--update-for-mouse-movement", Fdisplay__update_for_mouse_movement, diff --git a/src/w32term.c b/src/w32term.c index 109aa58d73..041f2ec31f 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -5068,6 +5068,7 @@ w32_read_socket (struct terminal *terminal, break; case WM_MOUSEMOVE: + /* FIXME: Combine this logic with update_mouse_position. */ /* Ignore non-movement. */ { int x = LOWORD (msg.msg.lParam); -- 2.20.1