all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Disabling mouse input
@ 2024-11-02  2:01 Daniel Radetsky
  2024-11-02  2:44 ` Corwin Brust
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ 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] 27+ messages in thread

end of thread, other threads:[~2024-11-04 13:20 UTC | newest]

Thread overview: 27+ 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
2024-11-02 12:04     ` Eli Zaretskii
2024-11-02 13:38     ` Stefan Monnier
2024-11-02 14:32       ` James Cherti
2024-11-02 16:30         ` Dov Grobgeld
2024-11-02 16:43           ` Stefan Monnier
2024-11-02 17:07             ` tomas
2024-11-03 12:34           ` James Cherti
2024-11-03 12:47             ` tomas
2024-11-02 16:50       ` Eli Zaretskii
2024-11-02 16:54         ` Stefan Monnier
2024-11-02 16:59           ` Eli Zaretskii
2024-11-02 17:04             ` Stefan Monnier
2024-11-02 17:40               ` Eli Zaretskii
2024-11-02 18:11                 ` Stefan Monnier
2024-11-02 18:32                   ` Eli Zaretskii
2024-11-02 23:09                   ` Daniel Radetsky
2024-11-03  1:56                     ` Stefan Monnier
2024-11-03  7:54                       ` Daniel Radetsky
2024-11-03 14:01       ` James Cherti
2024-11-04  9:48   ` Po Lu
2024-11-04 13:20     ` Eli Zaretskii
2024-11-02 13:17 ` James Cherti

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.