From 29093ad3ea2e29050db7000847f91c92b0d4a1b5 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Wed, 3 Feb 2021 20:35:33 -0800 Subject: [PATCH 2/3] Support 'mouse-autoselect-window' for GPM and xterm mouse * src/dispnew.c (update_mouse_position): Generate SELECT_WINDOW_EVENT. Timestamp will be 0. * src/msdos.c (dos_rawgetc): * src/w32inevt.c (do_mouse_event): Refactor to call update_mouse_position. * src/nsterm.m (EV_TRAILER):([EmacsView mouseMoved:]): Make SELECT_WINDOW_EVENT have .timestamp set to 0. * src/termhooks.h (enum event_kind): Document that SELECT_WINDOW_EVENT always has .timestamp set to 0. * src/w32term.c (w32_read_socket): * src/xterm.c (handle_one_xevent): Add FIXMEs to refactor in the future. --- src/dispnew.c | 45 +++++++++++++++++++++++++++++++++++++++++---- src/msdos.c | 41 +---------------------------------------- src/nsterm.m | 9 +++++---- src/termhooks.h | 3 ++- src/w32inevt.c | 45 ++------------------------------------------- src/w32term.c | 1 + src/xterm.c | 1 + 7 files changed, 53 insertions(+), 92 deletions(-) diff --git a/src/dispnew.c b/src/dispnew.c index e603c67136..e7cb926d0e 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -3335,9 +3335,46 @@ update_frame_with_menu (struct frame *f, int row, int col) int update_mouse_position (struct frame *f, int x, int y) { - previous_help_echo_string = help_echo_string; - help_echo_string = Qnil; + Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); + int event_count = 0; + + if (hlinfo->mouse_face_hidden) + { + hlinfo->mouse_face_hidden = 0; + clear_mouse_face (hlinfo); + } + + /* 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; + event.arg = Qnil; + event.timestamp = 0; + kbd_buffer_store_event (&event); + ++event_count; + } + + /* Remember the last window where we saw the mouse. */ + last_mouse_window = window; + } + + previous_help_echo_string = help_echo_string; + help_echo_string = help_echo_object = help_echo_window = Qnil; + help_echo_pos = -1; note_mouse_highlight (f, x, y); /* If the contents of the global variable help_echo_string @@ -3350,10 +3387,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..40b498941b 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2643,46 +2643,7 @@ dos_rawgetc (void) might need to update mouse highlight. */ if (mouse_last_x != mouse_prev_x || mouse_last_y != mouse_prev_y) { - if (hlinfo->mouse_face_hidden) - { - hlinfo->mouse_face_hidden = 0; - clear_mouse_face (hlinfo); - } - - /* Generate SELECT_WINDOW_EVENTs when needed. */ - if (!NILP (Vmouse_autoselect_window)) - { - static Lisp_Object last_mouse_window; - - mouse_window = window_from_coordinates - (SELECTED_FRAME (), mouse_last_x, mouse_last_y, 0, 0, 0); - /* A window will be selected only when it is not - selected now, and the last mouse movement event was - not in it. A minibuffer window will be selected iff - it is active. */ - if (WINDOWP (mouse_window) - && !EQ (mouse_window, last_mouse_window) - && !EQ (mouse_window, selected_window)) - { - event.kind = SELECT_WINDOW_EVENT; - event.frame_or_window = mouse_window; - event.arg = Qnil; - event.timestamp = event_timestamp (); - kbd_buffer_store_event (&event); - } - /* Remember the last window where we saw the mouse. */ - last_mouse_window = mouse_window; - } - - previous_help_echo_string = help_echo_string; - help_echo_string = help_echo_object = help_echo_window = Qnil; - help_echo_pos = -1; - note_mouse_highlight (SELECTED_FRAME (), mouse_last_x, mouse_last_y); - /* If the contents of the global variable help_echo has - changed, generate a HELP_EVENT. */ - if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) - gen_help_event (help_echo_string, selected_frame, help_echo_window, - help_echo_object, help_echo_pos); + update_mouse_position (SELECTED_FRAME (), mouse_last_x, mouse_last_y); } for (but = 0; but < NUM_MOUSE_BUTTONS; but++) diff --git a/src/nsterm.m b/src/nsterm.m index 1b2328628e..c3c82b5fef 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -418,12 +418,12 @@ - (NSColor *)colorUsingDefaultColorSpace #define EV_TRAILER(e) \ { \ XSETFRAME (emacs_event->frame_or_window, emacsframe); \ - EV_TRAILER2 (e); \ + if (e) emacs_event->timestamp = EV_TIMESTAMP (e); \ + EV_TRAILER2 (); \ } -#define EV_TRAILER2(e) \ +#define EV_TRAILER2() \ { \ - if (e) emacs_event->timestamp = EV_TIMESTAMP (e); \ if (q_event_ptr) \ { \ Lisp_Object tem = Vinhibit_quit; \ @@ -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 { @@ -7081,7 +7082,7 @@ - (void)mouseMoved: (NSEvent *)e NSTRACE_MSG ("in_window"); emacs_event->kind = SELECT_WINDOW_EVENT; emacs_event->frame_or_window = window; - EV_TRAILER2 (e); + EV_TRAILER2 (); } /* Remember the last window where we saw the mouse. */ last_mouse_window = window; diff --git a/src/termhooks.h b/src/termhooks.h index 3800679e80..a9a0fb2761 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -212,7 +212,8 @@ #define EMACS_TERMHOOKS_H /* Generated when a frame is moved. */ MOVE_FRAME_EVENT, - /* Generated when mouse moves over window not currently selected. */ + /* Generated when mouse moves over window not currently selected. + .timestamp is always 0. */ SELECT_WINDOW_EVENT, /* Queued from XTread_socket when session manager sends diff --git a/src/w32inevt.c b/src/w32inevt.c index 1a80a00197..f46494c841 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -482,50 +482,9 @@ do_mouse_event (MOUSE_EVENT_RECORD *event, if (f->mouse_moved) { - if (hlinfo->mouse_face_hidden) - { - hlinfo->mouse_face_hidden = 0; - clear_mouse_face (hlinfo); - } - - /* Generate SELECT_WINDOW_EVENTs when needed. */ - if (!NILP (Vmouse_autoselect_window)) - { - Lisp_Object mouse_window = window_from_coordinates (f, mx, my, - 0, 0, 0); - /* A window will be selected only when it is not - selected now, and the last mouse movement event was - not in it. A minibuffer window will be selected iff - it is active. */ - if (WINDOWP (mouse_window) - && !EQ (mouse_window, last_mouse_window) - && !EQ (mouse_window, selected_window)) - { - struct input_event event; - - EVENT_INIT (event); - event.kind = SELECT_WINDOW_EVENT; - event.frame_or_window = mouse_window; - event.arg = Qnil; - event.timestamp = movement_time; - kbd_buffer_store_event (&event); - } - last_mouse_window = mouse_window; - } - else - last_mouse_window = Qnil; - - previous_help_echo_string = help_echo_string; - help_echo_string = help_echo_object = help_echo_window = Qnil; - help_echo_pos = -1; - note_mouse_highlight (f, mx, my); - /* If the contents of the global variable help_echo has - changed (inside note_mouse_highlight), generate a HELP_EVENT. */ - if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) - gen_help_event (help_echo_string, selected_frame, - help_echo_window, help_echo_object, - help_echo_pos); + update_mouse_position (f, mx, my); } + /* We already called kbd_buffer_store_event, so indicate to the caller it shouldn't. */ return 0; 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