From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Disabling mouse input Date: Sat, 02 Nov 2024 09:38:20 +0200 Message-ID: <86sesaytjn.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14844"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Daniel Radetsky , Stefan Monnier , Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 02 08:39:18 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t78j7-0003im-OC for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Nov 2024 08:39:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t78iH-0003um-FB; Sat, 02 Nov 2024 03:38:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t78iG-0003ud-GG for emacs-devel@gnu.org; Sat, 02 Nov 2024 03:38:24 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t78iF-0000PL-6x; Sat, 02 Nov 2024 03:38:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=4rWSPw6Bb31MdTufD1tzftYrCza1CzDRH0e2980dmU4=; b=C4+DcmKoUEOV Vk4k45aTd9VYzJ8Yxk7xZ25MPLCklkDUZGh69rWPHaA8O9W5Zg7/wMaIrMgqKp1Ke2vawFrEaNG5N NmloVK47Q2vX+k0RdknQu0Zzp1q+DGI58NdBCroaQMWsPiIdsjYTzG1jeB+n3f/mdbsDDJmUx3JJs QrOl61tm39xspWdVx3/9qsK3mzGday0hAoThBGMIA6LqvY7HT/0YDHPtA8ywkFK3KElnSl3Ejjnfw +NiV1hguvxYmj0uslc+gOji5pWFhfFsgB8ZoYh7tyE0UWYFg3L0GulO2/C5+rAWqnRk82XN6ZgDo3 c4aQzPGZB4B9PVFHeblCIA==; In-Reply-To: (message from Daniel Radetsky on Fri, 1 Nov 2024 19:01:00 -0700) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325003 Archived-At: > Date: Fri, 1 Nov 2024 19:01:00 -0700 > From: Daniel Radetsky > > 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 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.