From 0219f8e1af24844189b6f3ac3af7f11379fd3a94 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Sat, 23 Jan 2021 16:53:43 -0800 Subject: [PATCH 2/3] Support 'mouse-autoselect-window' for GPM and xterm mouse * src/dispnew.c (update_mouse_position): Generate SELECT_WINDOW_EVENT. --- src/dispnew.c | 32 ++++++++++++++++++++++++++++++-- src/msdos.c | 1 + src/nsterm.m | 1 + src/w32inevt.c | 1 + src/w32term.c | 1 + src/xterm.c | 1 + 6 files changed, 35 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/msdos.c b/src/msdos.c index 5da01c9e7c..0dab89d9df 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2639,6 +2639,7 @@ dos_rawgetc (void) /* Check for mouse movement *before* buttons. */ mouse_check_moved (); + /* FIXME: Combine this logic with update_mouse_position. */ /* If the mouse moved from the spot of its last sighting, we might need to update mouse highlight. */ if (mouse_last_x != mouse_prev_x || mouse_last_y != mouse_prev_y) diff --git a/src/nsterm.m b/src/nsterm.m index 1b2328628e..60acda1bcd 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -7037,6 +7037,7 @@ - (void) scrollWheel: (NSEvent *)theEvent } +/* FIXME: Combine this logic with update_mouse_position. */ /* Tell emacs the mouse has moved. */ - (void)mouseMoved: (NSEvent *)e { diff --git a/src/w32inevt.c b/src/w32inevt.c index 1a80a00197..383169c3d1 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -473,6 +473,7 @@ do_mouse_event (MOUSE_EVENT_RECORD *event, switch (flags) { case MOUSE_MOVED: + /* FIXME: Combine this logic with update_mouse_position. */ { struct frame *f = get_frame (); Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); diff --git a/src/w32term.c b/src/w32term.c index 0ee805a852..7e9b641414 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -5083,6 +5083,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); diff --git a/src/xterm.c b/src/xterm.c index 744b80c68a..d9fb389f89 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -8830,6 +8830,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, goto OTHER; case MotionNotify: + /* FIXME: Combine this logic with update_mouse_position. */ { x_display_set_last_user_time (dpyinfo, event->xmotion.time); previous_help_echo_string = help_echo_string; -- 2.20.1