emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Additional xterm-mouse cleanup


From: Stefan Monnier
Subject: Re: Additional xterm-mouse cleanup
Date: Thu, 28 Jan 2021 09:25:26 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> -                  (while (or (memq char (append help-event-list
> -                                                (cons help-char '(?? ?\C-v 
> ?\s ?\177 delete backspace vertical-scroll-bar ?\M-v))))
> +                     (while (or (memq (event-basic-type char)
> +                                      (append help-event-list
> +                                              (list help-char ?? ?\C-v ?\s 
> ?\177
> +                                                    'delete 'backspace
> +                                                    'vertical-scroll-bar
> +                                                    'mouse-4 'mouse-5 
> ?\M-v)))

LGTM, but it would be good to improve the code so it determine this set
of events automatically, e.g. by looking up local-map or something.

> Subject: [PATCH 3/4] Support 'mouse-autoselect-window' for GPM and xterm mouse

Oh, thank you, thank you, thank you.

> --- a/src/dispnew.c
> +++ b/src/dispnew.c
> @@ -3335,11 +3335,39 @@ update_frame_with_menu (struct frame *f, int row, int 
> col)
[...]
> +  /* 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;
> +    }

I think this should be consolidated with the *very* similar code in
`src/msdos.c` and `src/w32inevt.c`.

[ Ideally it should also be consolidated with the `Vmouse_autoselect_window`
  support in `src/xterm.c`, `src/nsterm.m`, and `src/w32term.c`.  ]

> The function read_char normally clears the active echo area after
> reading any event.  When xterm-mouse-mode is active the event can get
> discarded when input-decode-map is applied (example: a mouse movement
> escape sequence with 'track-mouse' set to nil) in which case the echo
> area should stay unchanged.  Other translation keymaps are not
> intended to ever discard events so the restoring is only done for
> input-decode-map.

Actually, I have had translations in `function-key-map` which end up
discarding the input (and I can't think of any reason why
`key-translation-map` wouldn't ever want to do that either, other than
the fact that it's virtually never used).

>         if (done)
>           {
>             mock_input = diff + max (t, mock_input);
> +
> +           /* By this point the echo area was cleared by calls to
> +              read_char.  However, we may have completely thrown
> +              out the input (for example if decoding a mouse move
> +              event but `track-mouse' is nil) in which case the
> +              echo area should be restored to its pristene
> +              state.  */
> +           echo_area_buffer[0] = echo_area_buffer[1];
>             goto replay_sequence;
>           }

[ Oh ... how I hate that echo area code.  ]

I think this needs a reproducible test case, ideally one we can run in
batch as part of our test suite.

Also, I'm curious about a few things:
- How do we know that the echo area was cleared by calls to `read_char`?
  [ Do we even know for sure that `read_char` always clears it?  ]
- How do we know that this extra line has the effect of restoring it to
  its pristine state?

I think I'd like it better if we could make those things clear in
the code.  E.g. by having the "code that clears" set some variable
indicating that it's indeed been cleared and maybe also how it's been
cleared, and which we can then use here.

Or alternatively, change the "code that clears" so that it doesn't
actually clear when called from `read_key_sequence` and let
`read_key_sequence` take care of clearing the echo area once it has
*really* read some input?

WDYT?


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]