From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#51891: 29.0.50; [PATCH] Pixel delta support for wheel events on X Date: Wed, 17 Nov 2021 10:38:41 +0800 Message-ID: <871r3ftsjy.fsf@yahoo.com> References: <87zgq4uvh0.fsf.ref@yahoo.com> <87zgq4uvh0.fsf@yahoo.com> <871r3gnrrn.fsf@gmail.com> <875ysrtyak.fsf@yahoo.com> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12695"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: 51891@debbugs.gnu.org To: Robert Pluim Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 17 03:39:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1mnAqv-00039Y-0Q for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 17 Nov 2021 03:39:13 +0100 Original-Received: from localhost ([::1]:39174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnAqt-0005TU-JU for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Nov 2021 21:39:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnAqk-0005T8-Kq for bug-gnu-emacs@gnu.org; Tue, 16 Nov 2021 21:39:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mnAqk-0005tE-Cp for bug-gnu-emacs@gnu.org; Tue, 16 Nov 2021 21:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mnAqk-0006DI-65 for bug-gnu-emacs@gnu.org; Tue, 16 Nov 2021 21:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Nov 2021 02:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51891 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51891-submit@debbugs.gnu.org id=B51891.163711674023872 (code B ref 51891); Wed, 17 Nov 2021 02:39:02 +0000 Original-Received: (at 51891) by debbugs.gnu.org; 17 Nov 2021 02:39:00 +0000 Original-Received: from localhost ([127.0.0.1]:59549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnAqh-0006Cy-VV for submit@debbugs.gnu.org; Tue, 16 Nov 2021 21:39:00 -0500 Original-Received: from sonic316-21.consmr.mail.ne1.yahoo.com ([66.163.187.147]:45176) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnAqf-0006Cd-87 for 51891@debbugs.gnu.org; Tue, 16 Nov 2021 21:38:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637116730; bh=JpDzfOpurw8F7jDKFbbB7BkiDp4ZJZbs//3ho9RYvm8=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=THwuBC350ranUaLSY564xLvOdc7N8L0yiDGN1tj+jZFTev1YNJiL9GBs2BKizR+bCkhKZy3OyAmmCOUUCJ0kw27I3wvdrwxx7qAop1YIa04sZWE1YWsmggt/d068z6fM9/y+VqqTc2CkxBYrJ1eVuNz48d995bWr6IGCYUkmBTK0De1LQ19DZ7973CGvfMHOFZBLBOtzAwLisrsx945LUast3yfumiqQWl4s43PiShBVoknVz5X5HHA3PCzzkYTTDwh8t6R4qBAXvi+wcpz0Nxk3UEvE3YnSsbrcRQ3YSwXapcgIitUlSKqWA0644xXOpmHmew7LeurbZh2lPHu59A== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637116730; bh=5t0a9wTOirYVa537+qMSNRVKd3N+/zkjI7p7JnsVEwP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=WDezmBjSNxgxlL5CYGq2Y48WaAb21FKxJSog/gDpH/LGvL10+JputPkoERLfAO8VEIDUzhvj4KGXnxIcX8iuwIJJGMULtryGZWlzuNjEplUAGaBu09OKujR8ucLKDrawE5++EZE3VQkJvVDQ3SGzC32OY2Jk9PoyaWXP97hirZkvz1AKHXEY1ugcXEnOe5kSXzEUg6F4JtGRllDHiK96BwtafDiG3FtaJXU3xiSK4L+jMWBgCvc1KN0g5ISvaVwkBDq1Rv6foxf5/vP1CpmWutcqdNuxQdC5OoIRfYvCbZx8FIoe1I7TsSAxFndcAvN8aqfzd/65/u2aWwFEutJNhw== X-YMail-OSG: 3fEopFIVM1mSGyF4HW9GJO9lzi0kMl.3S_YUMLvMlBwAzb8HyR30lTtbSumBha3 hg_bJk2pq1Ap.XSn8Yhg4TTFeESLy81VeyNKjgGB_mf1Pd_mxNXGzw0QAQZ3uWgleZRdy36wcPqj mXIL3.ZmTHm7pH1GGVtepHvT_N7kTGVrzVsu.L_IFTV0EgJiItW9zmOIzTrdmGRQrUUKiGD5r0Fr Iy7mMWjoaCz0j2zMWAS4iReKe7eIW8vVpRMoK0ciF_9gaPhVnggoTx65uL5BLn4jct.7VCLn..Sm k4EVc1Q1rgocvNG3iwxfRSMkdr3YeAN_j5J0EszJQaJq7dKY71pskdI9FamnN7B6Ur9m0WWlFLq2 XNAOV6XBJilLAJcNN0JfPaD.jAPw0_bmu27VgVJ5xuWVpH0JtaTiCYvT04SjIwo7Al1ogKHKvgdw eFrjlF0fIjCXp4rbG3kJEzF_Ao2p2ARkhp_gz3aNyERVv7omsNB9Afj7iTFEO66zcNvtc_UrlYqK 4dWjMSlrU1EUWvT26QJIYS_LAyu.iubTcSmz5QTotql1GW52naYBFUJ3eAnnrL7KxeeZWMITo5HR BNhYAwwd8.R3z_HI6W6QzVf17DTJ0z3dVPc7hDLJUCOtUy2ZV33jEGJbwDgetN6CHnOCX0aB_cPu K3KVeKc1rM64wnLl.W6E05bdm143Fqc5k5ErrP8Ny_NonRYYAL.rmAxhm5429f3LD50orvEaTHjz OxCJyKknL_sBH4cAzewxndokAr9.7Yrpi4i1CY.Wo1Aof9yZgDWAaVKc4v0XT6KTTqDcCWNSfDbQ DDi1N9T_mO6LkwNTvFNu4Mj_Eu29n4YnvuuiIoyv1W X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.ne1.yahoo.com with HTTP; Wed, 17 Nov 2021 02:38:50 +0000 Original-Received: by kubenode503.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a290314d9739565ad69e7ca72bd7cdf8; Wed, 17 Nov 2021 02:38:46 +0000 (UTC) In-Reply-To: <875ysrtyak.fsf@yahoo.com> (Po Lu's message of "Wed, 17 Nov 2021 08:34:43 +0800") X-Mailer: WebService/1.1.19306 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:220172 Archived-At: --=-=-= Content-Type: text/plain Po Lu writes: > Because other systems (such as GDK) have different methods of reporting > scroll deltas. While it makes sense in the context of the XInput 2 code > to report them one at a time, it does not in the context of GDK, as it > reports both deltas to Emacs at the same time. > > Which means the pure GTK port will report both delta-y and delta-x at > the same time. > > Thanks. And here's a new version of the patch with the fixes to documentation, and an extra option to prevent motion events from being sent too rapidly. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Expose-pixel-wise-wheel-events-to-Lisp.patch >From cf9a4a28cd44077e7682c0deccda9d1fbc98344d Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 16 Nov 2021 19:39:50 +0800 Subject: [PATCH 2/2] Expose pixel-wise wheel events to Lisp * doc/lispref/commands.texi (Misc Events): Document changes to wheel events. * src/keyboard.c (make_lispy_event): Handle wheel events with pixel delta data. * src/termhooks.h (WHEEL_EVENT): Document changes to WHEEL_EVENT args. * src/xfns.c (syms_of_xfns): Declare new symbols. * src/xterm.c (handle_one_xevent): Give wheel events pixel delta data. (x_coalesce_scroll_events): New user option. --- doc/lispref/commands.texi | 6 +++++- src/keyboard.c | 5 ++++- src/termhooks.h | 6 +++++- src/xfns.c | 3 +++ src/xterm.c | 37 ++++++++++++++++++++++++++----------- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index 1509c200e0..be0f4189ee 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -1985,7 +1985,11 @@ Misc Events These kinds of event are generated by moving a mouse wheel. The @var{position} element is a mouse position list (@pxref{Click Events}), specifying the position of the mouse cursor when the event -occurred. +occurred. The event may have additional arguments after +@var{position}. The third argument after @var{position}, if present, +is a property list of the form @w{@code{(:delta-x @var{x} :delta-y +@var{y})}}, where @var{x} and @var{y} are the number of pixels to +scroll by in each axis. @vindex mouse-wheel-up-event @vindex mouse-wheel-down-event diff --git a/src/keyboard.c b/src/keyboard.c index de9805df32..276fd8c5aa 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5980,7 +5980,10 @@ make_lispy_event (struct input_event *event) ASIZE (wheel_syms)); } - if (NUMBERP (event->arg)) + if (CONSP (event->arg)) + return list5 (head, position, make_fixnum (double_click_count), + XCAR (event->arg), XCDR (event->arg)); + else if (NUMBERP (event->arg)) return list4 (head, position, make_fixnum (double_click_count), event->arg); else if (event->modifiers & (double_modifier | triple_modifier)) diff --git a/src/termhooks.h b/src/termhooks.h index e7539bbce2..19a6cc82da 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -119,7 +119,11 @@ #define EMACS_TERMHOOKS_H .timestamp gives a timestamp (in milliseconds) for the event. .arg may contain the number of - lines to scroll. */ + lines to scroll, or a list of + the form (NUMBER-OF-LINES . + (:delta-x :delta-y Y)) where + X and Y are the number of pixels + on each axis to scroll by. */ HORIZ_WHEEL_EVENT, /* A wheel event generated by a second horizontal wheel that is present on some mice. See WHEEL_EVENT. */ diff --git a/src/xfns.c b/src/xfns.c index b33b40b330..9d70ba479b 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -8085,6 +8085,9 @@ syms_of_xfns (void) #ifdef HAVE_XINPUT2 DEFSYM (Qxinput2, "xinput2"); + DEFSYM (QCdelta_x, ":delta-x"); + DEFSYM (QCdelta_y, ":delta-y"); + Fprovide (Qxinput2, Qnil); #endif diff --git a/src/xterm.c b/src/xterm.c index 63754a2cb6..74f0cefb7b 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -556,6 +556,7 @@ xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo, int id) { valuator = &device->valuators[i]; valuator->invalid_p = true; + valuator->emacs_value = 0.0; } return; @@ -9921,8 +9922,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, #endif goto XI_OTHER; case XI_Motion: - /* First test if there is some kind of scroll event - here! */ states = &xev->valuators; values = states->values; @@ -9932,10 +9931,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, { if (XIMaskIsSet (states->mask, i)) { - block_input (); - struct xi_scroll_valuator_t *val; - double delta; + double delta, scroll_unit; delta = x_get_scroll_valuator_delta (dpyinfo, xev->deviceid, i, *values, &val); @@ -9943,6 +9940,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (delta != DBL_MAX) { f = mouse_or_wdesc_frame (dpyinfo, xev->event); + scroll_unit = pow (FRAME_PIXEL_HEIGHT (f), 2.0 / 3.0); found_valuator = true; if (signbit (delta) != signbit (val->emacs_value)) @@ -9950,15 +9948,16 @@ handle_one_xevent (struct x_display_info *dpyinfo, val->emacs_value += delta; + if (x_coalesce_scroll_events + && (fabs (val->emacs_value) < 1)) + continue; + if (!f) { f = x_any_window_to_frame (dpyinfo, xev->event); if (!f) - { - unblock_input (); - goto XI_OTHER; - } + goto XI_OTHER; } bool s = signbit (val->emacs_value); @@ -9975,13 +9974,22 @@ handle_one_xevent (struct x_display_info *dpyinfo, inev.ie.modifiers |= x_x_to_emacs_modifiers (dpyinfo, xev->mods.effective); - inev.ie.arg = Qnil; + + if (val->horizontal) + inev.ie.arg = list5 (Qnil, QCdelta_x, + make_float (val->emacs_value + * scroll_unit), + QCdelta_y, make_float (0)); + else + inev.ie.arg = list5 (Qnil, QCdelta_x, make_float (0), + QCdelta_y, + make_float (val->emacs_value + * scroll_unit)); kbd_buffer_store_event_hold (&inev.ie, hold_quit); val->emacs_value = 0; } - unblock_input (); values++; } @@ -15048,4 +15056,11 @@ syms_of_xterm (void) consuming frame position adjustments. In newer versions of GTK, Emacs always uses gtk_window_move and ignores the value of this variable. */); x_gtk_use_window_move = true; + + DEFVAR_BOOL ("x-coalesce-scroll-events", x_coalesce_scroll_events, + doc: /* Non-nil means to only send one wheel event for each scroll unit. +Otherwise, a wheel event will be sent every time the mouse wheel is +moved. This option is only effective when Emacs is built with XInput +2. */); + x_coalesce_scroll_events = true; } -- 2.31.1 --=-=-=--