unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Disabling mouse input
@ 2024-11-02  2:01 Daniel Radetsky
  2024-11-02  2:44 ` Corwin Brust
  2024-11-02  7:38 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Radetsky @ 2024-11-02  2:01 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1917 bytes --]

I want to disable mouse input to emacs. One reason is that,
while typing something on my laptop, I may accidentally hit
the touchpad, whereupon emacs will complain that
"C-c C-x <mouse-wheel-down> is not a real keybind" (whereas
I had actually intended to enter C-c C-x j or something).
This is annoying, and none of the common solutions to this
problem (e.g. palm detection) seem good enough. Since I
don't want to use the mouse with emacs to begin with, I'd
rather just disable it altogether.

Unfortunately, there doesn't seem to be a way to do that.
You can of course unbind the mouse inputs, but they will
still be generated and lead to spurious errors as above.
It's also not possible to solve this with advice since the
calls to functions which generate the mouse inputs occur in
C code. As far as I can tell, the only solution is hacking
core emacs.

Attached is a draft patch. I imagine I'll have to add
more/better docs and other checklist items, but what I have
here will allow others to see what I've done and tell me if
I'm doing it the Right Way or the Stupid Way.

Basically, we define a lisp var in C `ignore-mouse-input`.
If you setq it to t in emacs, you stop receiving mouse
inputs. If you setq it back to nil, you get them again. It
works for me, but unfortunately I have no idea how to write
ert tests. Maybe somebody could point me to a few of the
simple ones to study in order to get the idea.

Also, the C code does look a bit funny, but I couldn't
figure out any automated way to check/fix it, and I'm not
actually familiar with that C style. flycheck said it looked
fine. I tried running clang-format, but it said there were
already 3000 lines worth of errors in that file before I'd
even touched it, so that's obviously out-of-date. I didn't
see anything about this in the contrib guide. In any case, I
can fix this later once I know whether, in principle, the
change is acceptable.

--dmr

[-- Attachment #2: 0001-no-mouse.patch --]
[-- Type: text/plain, Size: 2103 bytes --]

From 8e0522f053d369a73bd1f387d513303887363f51 Mon Sep 17 00:00:00 2001
From: Daniel Radetsky <dradetsky@gmail.com>
Date: Fri, 1 Nov 2024 00:00:33 -0700
Subject: [PATCH] no mouse

---
 src/keyboard.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/keyboard.c b/src/keyboard.c
index 6d28dca9aeb..37a1e86d6e6 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1305,6 +1305,8 @@ some_mouse_moved (void)
   return NULL;
 }
 
+bool is_mouse_input (Lisp_Object);
+
 \f
 /* This is the actual command reading loop,
    sans error-handling encapsulation.  */
@@ -10420,6 +10422,20 @@ restore_reading_key_sequence (int old_reading_key_sequence)
    If DISABLE_TEXT_CONVERSION_P, disable text conversion so the input
    method will always send key events.  */
 
+/* Check if read key kind is a mouse input (so we can discard it if
+	 desired).  */
+bool
+is_mouse_input (Lisp_Object kind)
+{
+	return (EQ (kind, Qmouse_click) ||
+		EQ (kind, Qtouchscreen) ||
+		EQ (kind, Qtouchscreen_begin) ||
+		EQ (kind, Qtouchscreen_end) ||
+		EQ (kind, Qtouchscreen_update) ||
+		EQ (kind, Qtouch_end) ||
+		EQ (kind, Qpinch));
+}
+
 static int
 read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt,
 		   bool dont_downcase_last, bool can_return_switch_frame,
@@ -10924,6 +10940,11 @@ read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt,
       if (EVENT_HAS_PARAMETERS (key))
 	{
 	  Lisp_Object kind = EVENT_HEAD_KIND (EVENT_HEAD (key));
+		if (!NILP (ignore_mouse_input) && is_mouse_input (kind))
+			{
+				goto replay_key;
+			}
+
 	  if (EQ (kind, Qmouse_click) || EQ (kind, Qtouchscreen))
 	    {
 	      Lisp_Object window = POSN_WINDOW (EVENT_START (key));
@@ -13908,6 +13929,9 @@ syms_of_keyboard (void)
   DEFSYM (Qsuspend_resume_hook, "suspend-resume-hook");
   DEFSYM (Qcommand_error_default_function, "command-error-default-function");
   DEFSYM (Qsigusr2, "sigusr2");
+  DEFVAR_LISP ("ignore-mouse-input", ignore_mouse_input,
+	       doc: /* If non-nil, discard mouse input in the command loop */);
+  ignore_mouse_input = Qnil;
 }
 
 static void
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Disabling mouse input
  2024-11-02  2:01 Disabling mouse input Daniel Radetsky
@ 2024-11-02  2:44 ` Corwin Brust
  2024-11-02  3:07   ` Daniel Radetsky
  2024-11-02  7:38 ` Eli Zaretskii
  1 sibling, 1 reply; 5+ messages in thread
From: Corwin Brust @ 2024-11-02  2:44 UTC (permalink / raw)
  To: Daniel Radetsky; +Cc: emacs-devel

Hi Daniel,

On Fri, Nov 1, 2024 at 9:01 PM Daniel Radetsky <dradetsky@gmail.com> wrote:
>
> I want to disable mouse input to emacs.

While reviewing your patch is beyond my meager abilities, I think I
might be able to try it out to at least confirm if it works fine under
Windows.

Mostly, I reply to say: disabling the mouse completely sounds like a
good feature to have; thanks for working on this!



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Disabling mouse input
  2024-11-02  2:44 ` Corwin Brust
@ 2024-11-02  3:07   ` Daniel Radetsky
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Radetsky @ 2024-11-02  3:07 UTC (permalink / raw)
  To: Corwin Brust; +Cc: emacs-devel

On Fri, Nov 01, 2024 at 09:44:59PM GMT, Corwin Brust wrote:

> While reviewing your patch is beyond my meager abilities, I think I
> might be able to try it out to at least confirm if it works fine under
> Windows.

You could always just claim to have reviewed it. Nobody will
know. That will help to intimidate any developers who may be
on the fence about approving.

Also thanks for testing. Let me know how it goes.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Disabling mouse input
  2024-11-02  2:01 Disabling mouse input Daniel Radetsky
  2024-11-02  2:44 ` Corwin Brust
@ 2024-11-02  7:38 ` Eli Zaretskii
  2024-11-02 10:17   ` Daniel Radetsky
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-11-02  7:38 UTC (permalink / raw)
  To: Daniel Radetsky, Stefan Monnier, Po Lu; +Cc: emacs-devel

> Date: Fri, 1 Nov 2024 19:01:00 -0700
> From: Daniel Radetsky <dradetsky@gmail.com>
> 
> I want to disable mouse input to emacs. One reason is that,
> while typing something on my laptop, I may accidentally hit
> the touchpad, whereupon emacs will complain that
> "C-c C-x <mouse-wheel-down> is not a real keybind" (whereas
> I had actually intended to enter C-c C-x j or something).
> This is annoying, and none of the common solutions to this
> problem (e.g. palm detection) seem good enough. Since I
> don't want to use the mouse with emacs to begin with, I'd
> rather just disable it altogether.
> 
> Unfortunately, there doesn't seem to be a way to do that.
> You can of course unbind the mouse inputs, but they will
> still be generated and lead to spurious errors as above.
> It's also not possible to solve this with advice since the
> calls to functions which generate the mouse inputs occur in
> C code. As far as I can tell, the only solution is hacking
> core emacs.

Not necessarily "hacking": changing the core will also do ;-)

(This should not surprise anyone, because input events are handled in
C, not in Lisp, and so disabling this in Lisp is expected to be
impossible.)

> Attached is a draft patch. I imagine I'll have to add
> more/better docs and other checklist items, but what I have
> here will allow others to see what I've done and tell me if
> I'm doing it the Right Way or the Stupid Way.
> 
> Basically, we define a lisp var in C `ignore-mouse-input`.
> If you setq it to t in emacs, you stop receiving mouse
> inputs. If you setq it back to nil, you get them again. It
> works for me, but unfortunately I have no idea how to write
> ert tests. Maybe somebody could point me to a few of the
> simple ones to study in order to get the idea.

Thanks, but this is not enough, and I also think it doesn't
necessarily ignore the mouse events on the right level.  We should
instead ignore these events where they are read, here:

          /* No need for FIONREAD or fcntl; just say don't wait.  */
	  while ((nr = (*t->read_socket_hook) (t, &hold_quit)) > 0)
	    nread += nr;

This loop should ignore and remove from the queue any events whose
'kind' (as declared in termhooks.h) is a mouse or touchpad event.  And
perhaps we also should allow ignoring the latter, but not the former.
Otherwise, the "ignored" input events will act like ghosts: they do
exist in the queue, and do trigger input-even related mechanisms we
have, such as while-no-input, but cannot be accessed.

Stefan, Po Lu (and others), do you agree?

In addition, we'd need to change display-mouse-p, so that it reflects
the fact that mouse clicks are not available.  Otherwise, some
features will present mouse-driven UI that cannot be used.

> +  DEFVAR_LISP ("ignore-mouse-input", ignore_mouse_input,
> +	       doc: /* If non-nil, discard mouse input in the command loop */);
> +  ignore_mouse_input = Qnil;

This should be DEFVAR_BOOL instead.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Disabling mouse input
  2024-11-02  7:38 ` Eli Zaretskii
@ 2024-11-02 10:17   ` Daniel Radetsky
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Radetsky @ 2024-11-02 10:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, Po Lu, emacs-devel

On Sat, Nov 02, 2024 at 09:38:20AM GMT, Eli Zaretskii wrote:
> (This should not surprise anyone, because input events are handled in
> C, not in Lisp, and so disabling this in Lisp is expected to be
> impossible.)

Well, everyone I talked to was sure it must be possible in
Lisp, so I figured somebody would ask eventually.

> Thanks, but this is not enough, and I also think it doesn't
> necessarily ignore the mouse events on the right level.  We should
> instead ignore these events where they are read, here:

It was clearly enough for you to tell me I was doing it the
Stupid Way, which was my objective, so I don't see the
problem. I mean, obviously you're not going to merge what I
sent. That wasn't the point.

> This loop should ignore and remove from the queue any events whose
> 'kind' (as declared in termhooks.h) is a mouse or touchpad event.  And
> perhaps we also should allow ignoring the latter, but not the former.

Sounds reasonable. I'll take another look soon.

> Otherwise, the "ignored" input events will act like ghosts: they do
> exist in the queue, and do trigger input-even related mechanisms we
> have, such as while-no-input, but cannot be accessed.

I can't tell if this issue is supposed to be a consequence
of not implementing ignore-touchpad-but-not-mouse, or of
ignoring the events the way I was doing it (via the goto in
read_key_sequence).

> In addition, we'd need to change display-mouse-p, so that it reflects
> the fact that mouse clicks are not available.  Otherwise, some
> features will present mouse-driven UI that cannot be used.

Good point. I'm thoroughly ignorant of emacs' mouse-driven UI.

> > +  DEFVAR_LISP ("ignore-mouse-input", ignore_mouse_input,
> > +	       doc: /* If non-nil, discard mouse input in the command loop */);
> > +  ignore_mouse_input = Qnil;
> 
> This should be DEFVAR_BOOL instead.

Okay, wasn't certain about that.

It was also suggested to me that other devs would want the
feature exposed via a global minor mode, not just a
variable. Do you? I looked into it and it was about 10 lines
of Lisp (most of which was to allow it to be set via
customize), so that's not a big deal if so. Or I mean
probably not; maybe I'll discover it's much worse in
practice once I know what's actually involved.

Thanks for the info.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-02 10:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-02  2:01 Disabling mouse input Daniel Radetsky
2024-11-02  2:44 ` Corwin Brust
2024-11-02  3:07   ` Daniel Radetsky
2024-11-02  7:38 ` Eli Zaretskii
2024-11-02 10:17   ` Daniel Radetsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).