From: Daniel Radetsky <dradetsky@gmail.com>
To: emacs-devel@gnu.org
Subject: Disabling mouse input
Date: Fri, 1 Nov 2024 19:01:00 -0700 [thread overview]
Message-ID: <aa3ewfr7rscp4r4er5gz7ybrcxktxlzkce7qkgsjeqfemhrnvg@flu72dp56e5c> (raw)
[-- 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
next reply other threads:[~2024-11-02 2:01 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-02 2:01 Daniel Radetsky [this message]
2024-11-02 2:44 ` Disabling mouse input 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa3ewfr7rscp4r4er5gz7ybrcxktxlzkce7qkgsjeqfemhrnvg@flu72dp56e5c \
--to=dradetsky@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).