From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Radetsky Newsgroups: gmane.emacs.devel Subject: Disabling mouse input Date: Fri, 1 Nov 2024 19:01:00 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="bnuxsw4ebtj4gzta" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6393"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 02 03:01:54 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 1t73Sc-0001a8-MR for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Nov 2024 03:01:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t73Rs-0001ED-BN; Fri, 01 Nov 2024 22:01:08 -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 1t73Rp-0001E4-3a for emacs-devel@gnu.org; Fri, 01 Nov 2024 22:01:05 -0400 Original-Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t73Rm-0007nS-4v for emacs-devel@gnu.org; Fri, 01 Nov 2024 22:01:03 -0400 Original-Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-720c2db824eso2091013b3a.0 for ; Fri, 01 Nov 2024 19:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730512860; x=1731117660; darn=gnu.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=F1L8vyT5+MjDtRBrLIkPawzM/SJL8McljeN3+2y4nAk=; b=Y5BGgmKzB+0lo+yr7yrUk4gY9wPLBn+FPrXHhgQf1dmIKumo1w7hhA41NZNh4HrQTq lVcGV+X9T9CSy+N8oYe/AV3j4S0AbND4nVsyvKcGroi14JPULI7x55S/DCwkUtRiGbmd LHm8RYx8du8TdUwpKOXTIT2ruZLupe0zZWkSygn1Yp9dyr59Sqv53x/5HjUTixCnbn3w +HO9fRUAZTRvP9gC2Auv3CRgAanUbiRWDCz6mR+iPMNHS58z1PqltZuBgVk5fAXTgKJu 0esP24lmsghBF2381yUh9JydUy8ODwqkPiS2PwLdKhQEix0+7udE79taj+Q0w7xlsIgj ahMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730512860; x=1731117660; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F1L8vyT5+MjDtRBrLIkPawzM/SJL8McljeN3+2y4nAk=; b=ahvb+UiueyyzA/GNY8XLh6zNH+nJOyENICzYiiZIrCUfb7O/tHCGjle99fUj/GqqYC NQwUlaL6sXH2GuUSBZEvan781Bv+r5o75tkQlamUfvx092411D+YIFrpod3qopG6uGux Z4YjJkz+CKSEPtJiglBFyFrZx/ZQspQwSwO393TLGvBVjkIY6swy2pHEJbPVqaJfoZQN 29bqPKhXI2bhAm0stcRWun9Byp0vBmIrHGZI5PTAt5IYRmo66dMFSA26gP1ebIZDdeH9 l0WcPGVX3Z/p0P/OkUAQcj7pYHC3NlHX0vQkmUM+1kAEb/tEngouzxC3BJDB9LWDE3KP JsVw== X-Gm-Message-State: AOJu0YyyU9pxjnRRBsrkhYMoQjtqHpnY0ZEkv7rg3iKLDz6SzDFmEwab v207TNk5AiCnIEf1KXTYnWeShq6TDPdzaxgr7ndcJxb1LRsN/ufCNlkuTQ== X-Google-Smtp-Source: AGHT+IEuXUbieVxgYJ9FYpPmBkvM27r5ruq5GAkzfY4kwFqW+nwIS+RO8HlpDwZFVvQSS0Zc+BEZoA== X-Received: by 2002:a05:6a20:d80c:b0:1d9:9c6:5e8c with SMTP id adf61e73a8af0-1d9a83ffdcemr36179760637.25.1730512859922; Fri, 01 Nov 2024 19:00:59 -0700 (PDT) Original-Received: from flap ([2601:645:8a81:69c0:e657:69fd:648d:782]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc2eb64esm3338432b3a.168.2024.11.01.19.00.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:00:59 -0700 (PDT) Content-Disposition: inline Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=dradetsky@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:324999 Archived-At: --bnuxsw4ebtj4gzta Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. 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 --bnuxsw4ebtj4gzta Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-no-mouse.patch" >From 8e0522f053d369a73bd1f387d513303887363f51 Mon Sep 17 00:00:00 2001 From: Daniel Radetsky 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); + /* 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 --bnuxsw4ebtj4gzta--