* Disabling mouse input
@ 2024-11-02 2:01 Daniel Radetsky
2024-11-02 2:44 ` Corwin Brust
0 siblings, 1 reply; 3+ 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] 3+ 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
0 siblings, 1 reply; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2024-11-02 3:07 UTC | newest]
Thread overview: 3+ 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
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.