From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: [PATCH v1] Let input queue deal gracefully with up-events Date: Wed, 28 Jan 2015 16:19:03 +0100 Message-ID: <1422458343-12633-1-git-send-email-dak@gnu.org> References: <20150128145849.GA5107@acm.acm> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1422458366 30002 80.91.229.3 (28 Jan 2015 15:19:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 15:19:26 +0000 (UTC) Cc: David Kastrup To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 28 16:19:25 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YGUOp-0003mG-8e for ged-emacs-devel@m.gmane.org; Wed, 28 Jan 2015 16:19:23 +0100 Original-Received: from localhost ([::1]:54136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGUOo-0002eq-BV for ged-emacs-devel@m.gmane.org; Wed, 28 Jan 2015 10:19:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGUOj-0002Xt-MG for emacs-devel@gnu.org; Wed, 28 Jan 2015 10:19:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGUOi-0007fk-IC for emacs-devel@gnu.org; Wed, 28 Jan 2015 10:19:17 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:56114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGUOi-0007fZ-G5 for emacs-devel@gnu.org; Wed, 28 Jan 2015 10:19:16 -0500 Original-Received: from localhost ([127.0.0.1]:35057 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGUOh-0002Dd-Ut; Wed, 28 Jan 2015 10:19:16 -0500 Original-Received: by lola (Postfix, from userid 1000) id 8BCCADF31C; Wed, 28 Jan 2015 16:19:15 +0100 (CET) X-Mailer: git-send-email 2.1.0 In-Reply-To: <20150128145849.GA5107@acm.acm> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181909 Archived-At: * keyboard.c (apply_modifiers_uncached, parse_solitary_modifier) (parse_modifiers_uncached): React gracefully to "up-" modifiers: those may easily be injected by user-level Lisp code. (read_key_sequence): Discard unbound up-events like unbound down-events: they are even more likely only relevant for special purposes. While Emacs will not produce up-events on its own currently (those are converted to drag or click events before being converted to Lisp-readable structures), the input queue can be made to contain them by synthesizing events to `unread-command-events'. This patch makes Emacs deal consistently with such events. Signed-off-by: David Kastrup --- While changing the comment Alan complained about I decided to fix another comment that was no longer corresponding to the code. src/ChangeLog | 9 +++++++++ src/keyboard.c | 34 +++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1df4f6a..f9f53c4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2015-01-28 David Kastrup + + * keyboard.c (apply_modifiers_uncached, parse_solitary_modifier) + (parse_modifiers_uncached): React gracefully to "up-" modifiers: + those may easily be injected by user-level Lisp code. + (read_key_sequence): Discard unbound up-events like unbound + down-events: they are even more likely only relevant for special + purposes. + 2015-01-27 Eli Zaretskii * dired.c (directory_files_internal) [WINDOWSNT]: If readdir diff --git a/src/keyboard.c b/src/keyboard.c index 383c109..b762e13 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -6202,6 +6202,10 @@ parse_modifiers_uncached (Lisp_Object symbol, ptrdiff_t *modifier_end) case 't': MULTI_LETTER_MOD (triple_modifier, "triple", 6); break; + + case 'u': + MULTI_LETTER_MOD (up_modifier, "up", 2); + break; #undef MULTI_LETTER_MOD } @@ -6249,16 +6253,18 @@ apply_modifiers_uncached (int modifiers, char *base, int base_len, int base_len_ /* Since BASE could contain nulls, we can't use intern here; we have to use Fintern, which expects a genuine Lisp_String, and keeps a reference to it. */ - char new_mods[sizeof "A-C-H-M-S-s-down-drag-double-triple-"]; + char new_mods[sizeof "A-C-H-M-S-s-up-down-drag-double-triple-"]; int mod_len; { char *p = new_mods; - /* Only the event queue may use the `up' modifier; it should always - be turned into a click or drag event before presented to lisp code. */ - if (modifiers & up_modifier) - emacs_abort (); + /* Mouse events should not exhibit the `up' modifier; it should + always be turned into a click or drag event before being + presented to lisp code. And there should not be more than one + of up/down/click/drag anyway. But since Lisp events can be + synthesized, we don't take exception to unexpected + combinations */ if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } @@ -6268,6 +6274,7 @@ apply_modifiers_uncached (int modifiers, char *base, int base_len, int base_len_ if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; } if (modifiers & double_modifier) p = stpcpy (p, "double-"); if (modifiers & triple_modifier) p = stpcpy (p, "triple-"); + if (modifiers & up_modifier) p = stpcpy (p, "up-"); if (modifiers & down_modifier) p = stpcpy (p, "down-"); if (modifiers & drag_modifier) p = stpcpy (p, "drag-"); /* The click modifier is denoted by the absence of other modifiers. */ @@ -6387,8 +6394,7 @@ DEFUN ("internal-event-symbol-parse-modifiers", Fevent_symbol_parse_modifiers, BASE must be unmodified. This is like apply_modifiers_uncached, but uses BASE's - Qmodifier_cache property, if present. It also builds - Qevent_symbol_elements properties, since it has that info anyway. + Qmodifier_cache property, if present. apply_modifiers copies the value of BASE's Qevent_kind property to the modified symbol. */ @@ -6734,6 +6740,10 @@ parse_solitary_modifier (Lisp_Object symbol) MULTI_LETTER_MOD (triple_modifier, "triple", 6); break; + case 'u': + MULTI_LETTER_MOD (up_modifier, "up", 2); + break; + #undef SINGLE_LETTER_MOD #undef MULTI_LETTER_MOD } @@ -9441,14 +9451,16 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, Drags reduce to clicks. Double-clicks reduce to clicks. Triple-clicks reduce to double-clicks, then to clicks. - Down-clicks are eliminated. + Up/Down-clicks are eliminated. Double-downs reduce to downs, then are eliminated. Triple-downs reduce to double-downs, then to downs, then are eliminated. */ - if (modifiers & (down_modifier | drag_modifier + if (modifiers & (up_modifier | down_modifier + | drag_modifier | double_modifier | triple_modifier)) { - while (modifiers & (down_modifier | drag_modifier + while (modifiers & (up_modifier | down_modifier + | drag_modifier | double_modifier | triple_modifier)) { Lisp_Object new_head, new_click; @@ -9460,7 +9472,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, modifiers &= ~drag_modifier; else { - /* Dispose of this `down' event by simply jumping + /* Dispose of this `up/down' event by simply jumping back to replay_key, to get another event. Note that if this event came from mock input, -- 2.1.0