diff options
| author | Stefan Monnier | 2024-01-29 09:35:09 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2024-04-05 17:04:34 -0400 |
| commit | d859856869f06bf6372370556303ea27c6b0e0e9 (patch) | |
| tree | c826d616a368f64bfd554b9c528ee8b3765b2f8a /src | |
| parent | 7a41de3d515077e3895fe9201d7786134c82ca26 (diff) | |
| download | emacs-scratch/mouse-wheel-buttons.tar.gz emacs-scratch/mouse-wheel-buttons.zip | |
(mouse-wheel-buttons): Map old-style wheel buttons to actual wheel eventsscratch/mouse-wheel-buttons
Change the handling of the old X11 convention to use mouse-4/5/6/7
events to represent wheel events: instead of asking downstream
packages to use the `mouse-wheel-*-event` variables to know which events
represent wheel events, use new var `mouse-wheel-buttons` to directly
convert those events into the standard `wheel-up/down/left/right` events
used everywhere else.
This will simplify the work of packages which can thus just bind their
commands to `wheel-up/down/left/right`.
* lisp/mouse.el (mouse-wheel-buttons): New custom variable.
* src/keyboard.c (make_lispy_event): Adjust for "wheel-clicks" on the tab-bar.
* src/xterm.c (x_construct_mouse_click): Add `xi2` argument and
obey `mouse-wheel-buttons` variable.
(handle_one_xevent): Adjust calls accordingly.
(syms_of_xterm): Define the `mouse-wheel-buttons` and the
`wheel-up/down/left/right`symbols.
* lisp/xt-mouse.el: Don't require `mwheel` any more.
(xterm-mouse--same-button-p): Delete function.
(xterm-mouse--read-event-sequence): Use `mouse-wheel-buttons`.
* lisp/mwheel.el (mouse-wheel-up-event, mouse-wheel-down-event)
(mouse-wheel-left-event, mouse-wheel-right-event): Make obsolete.
(mouse-wheel-obey-old-style-wheel-buttons): Delete variable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 13 | ||||
| -rw-r--r-- | src/xterm.c | 53 |
2 files changed, 54 insertions, 12 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 91faf4582fa..a06c9116d24 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -6639,8 +6639,17 @@ make_lispy_event (struct input_event *event) | |||
| 6639 | 6639 | ||
| 6640 | if (CONSP (event->arg)) | 6640 | if (CONSP (event->arg)) |
| 6641 | return list5 (head, position, make_fixnum (double_click_count), | 6641 | return list5 (head, position, make_fixnum (double_click_count), |
| 6642 | XCAR (event->arg), Fcons (XCAR (XCDR (event->arg)), | 6642 | XCAR (event->arg), |
| 6643 | XCAR (XCDR (XCDR (event->arg))))); | 6643 | /* FIXME: When a mouse-click on a tab-bar is |
| 6644 | converted into a wheel-event we get here something | ||
| 6645 | of an unexpected shape... */ | ||
| 6646 | (CONSP (XCDR (event->arg)) | ||
| 6647 | && CONSP (XCDR (XCDR (event->arg)))) | ||
| 6648 | ? Fcons (XCAR (XCDR (event->arg)), | ||
| 6649 | XCAR (XCDR (XCDR (event->arg)))) | ||
| 6650 | /* ... not knowing what this "unexpected shape" means, | ||
| 6651 | we just use nil. */ | ||
| 6652 | : Qnil); | ||
| 6644 | else if (NUMBERP (event->arg)) | 6653 | else if (NUMBERP (event->arg)) |
| 6645 | return list4 (head, position, make_fixnum (double_click_count), | 6654 | return list4 (head, position, make_fixnum (double_click_count), |
| 6646 | event->arg); | 6655 | event->arg); |
diff --git a/src/xterm.c b/src/xterm.c index c0aef65ab66..5e5eb6269e4 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -14551,18 +14551,19 @@ x_query_pointer (Display *dpy, Window w, Window *root_return, | |||
| 14551 | `x', `y', `x_root' and `y_root'. This function should not access | 14551 | `x', `y', `x_root' and `y_root'. This function should not access |
| 14552 | any other fields in EVENT without also initializing the | 14552 | any other fields in EVENT without also initializing the |
| 14553 | corresponding fields in `bv' under the XI_ButtonPress and | 14553 | corresponding fields in `bv' under the XI_ButtonPress and |
| 14554 | XI_ButtonRelease labels inside `handle_one_xevent'. */ | 14554 | XI_ButtonRelease labels inside `handle_one_xevent'. |
| 14555 | |||
| 14556 | XI2 indicates that this click comes from XInput2 rather than core | ||
| 14557 | event. */ | ||
| 14555 | 14558 | ||
| 14556 | static Lisp_Object | 14559 | static Lisp_Object |
| 14557 | x_construct_mouse_click (struct input_event *result, | 14560 | x_construct_mouse_click (struct input_event *result, |
| 14558 | const XButtonEvent *event, | 14561 | const XButtonEvent *event, |
| 14559 | struct frame *f) | 14562 | struct frame *f, bool xi2) |
| 14560 | { | 14563 | { |
| 14561 | int x = event->x; | 14564 | int x = event->x; |
| 14562 | int y = event->y; | 14565 | int y = event->y; |
| 14563 | 14566 | ||
| 14564 | /* Make the event type NO_EVENT; we'll change that when we decide | ||
| 14565 | otherwise. */ | ||
| 14566 | result->kind = MOUSE_CLICK_EVENT; | 14567 | result->kind = MOUSE_CLICK_EVENT; |
| 14567 | result->code = event->button - Button1; | 14568 | result->code = event->button - Button1; |
| 14568 | result->timestamp = event->time; | 14569 | result->timestamp = event->time; |
| @@ -14572,6 +14573,29 @@ x_construct_mouse_click (struct input_event *result, | |||
| 14572 | ? up_modifier | 14573 | ? up_modifier |
| 14573 | : down_modifier)); | 14574 | : down_modifier)); |
| 14574 | 14575 | ||
| 14576 | /* Convert pre-XInput2 wheel events represented as mouse-clicks. */ | ||
| 14577 | if (!xi2) | ||
| 14578 | { | ||
| 14579 | Lisp_Object base | ||
| 14580 | = Fcdr_safe (Fassq (make_fixnum (result->code + 1), | ||
| 14581 | Fsymbol_value (Qmouse_wheel_buttons))); | ||
| 14582 | int wheel | ||
| 14583 | = (NILP (base) ? -1 | ||
| 14584 | : BASE_EQ (base, Qwheel_down) ? 0 | ||
| 14585 | : BASE_EQ (base, Qwheel_up) ? 1 | ||
| 14586 | : BASE_EQ (base, Qwheel_left) ? 2 | ||
| 14587 | : BASE_EQ (base, Qwheel_right) ? 3 | ||
| 14588 | : -1); | ||
| 14589 | if (wheel >= 0) | ||
| 14590 | { | ||
| 14591 | result->kind = (event->type != ButtonRelease ? NO_EVENT | ||
| 14592 | : wheel & 2 ? HORIZ_WHEEL_EVENT : WHEEL_EVENT); | ||
| 14593 | result->code = 0; /* Not used. */ | ||
| 14594 | result->modifiers &= ~(up_modifier || down_modifier); | ||
| 14595 | result->modifiers |= wheel & 1 ? up_modifier : down_modifier; | ||
| 14596 | } | ||
| 14597 | } | ||
| 14598 | |||
| 14575 | /* If result->window is not the frame's edit widget (which can | 14599 | /* If result->window is not the frame's edit widget (which can |
| 14576 | happen with GTK+ scroll bars, for example), translate the | 14600 | happen with GTK+ scroll bars, for example), translate the |
| 14577 | coordinates so they appear at the correct position. */ | 14601 | coordinates so they appear at the correct position. */ |
| @@ -21881,13 +21905,14 @@ handle_one_xevent (struct x_display_info *dpyinfo, | |||
| 21881 | && event->xbutton.time > ignore_next_mouse_click_timeout) | 21905 | && event->xbutton.time > ignore_next_mouse_click_timeout) |
| 21882 | { | 21906 | { |
| 21883 | ignore_next_mouse_click_timeout = 0; | 21907 | ignore_next_mouse_click_timeout = 0; |
| 21884 | x_construct_mouse_click (&inev.ie, &event->xbutton, f); | 21908 | x_construct_mouse_click (&inev.ie, &event->xbutton, |
| 21909 | f, false); | ||
| 21885 | } | 21910 | } |
| 21886 | if (event->type == ButtonRelease) | 21911 | if (event->type == ButtonRelease) |
| 21887 | ignore_next_mouse_click_timeout = 0; | 21912 | ignore_next_mouse_click_timeout = 0; |
| 21888 | } | 21913 | } |
| 21889 | else | 21914 | else |
| 21890 | x_construct_mouse_click (&inev.ie, &event->xbutton, f); | 21915 | x_construct_mouse_click (&inev.ie, &event->xbutton, f, false); |
| 21891 | 21916 | ||
| 21892 | *finish = X_EVENT_DROP; | 21917 | *finish = X_EVENT_DROP; |
| 21893 | goto OTHER; | 21918 | goto OTHER; |
| @@ -21957,13 +21982,15 @@ handle_one_xevent (struct x_display_info *dpyinfo, | |||
| 21957 | && event->xbutton.time > ignore_next_mouse_click_timeout) | 21982 | && event->xbutton.time > ignore_next_mouse_click_timeout) |
| 21958 | { | 21983 | { |
| 21959 | ignore_next_mouse_click_timeout = 0; | 21984 | ignore_next_mouse_click_timeout = 0; |
| 21960 | x_construct_mouse_click (&inev.ie, &event->xbutton, f); | 21985 | x_construct_mouse_click (&inev.ie, &event->xbutton, |
| 21986 | f, false); | ||
| 21961 | } | 21987 | } |
| 21962 | if (event->type == ButtonRelease) | 21988 | if (event->type == ButtonRelease) |
| 21963 | ignore_next_mouse_click_timeout = 0; | 21989 | ignore_next_mouse_click_timeout = 0; |
| 21964 | } | 21990 | } |
| 21965 | else | 21991 | else |
| 21966 | x_construct_mouse_click (&inev.ie, &event->xbutton, f); | 21992 | x_construct_mouse_click (&inev.ie, &event->xbutton, |
| 21993 | f, false); | ||
| 21967 | 21994 | ||
| 21968 | if (!NILP (tab_bar_arg)) | 21995 | if (!NILP (tab_bar_arg)) |
| 21969 | inev.ie.arg = tab_bar_arg; | 21996 | inev.ie.arg = tab_bar_arg; |
| @@ -23740,13 +23767,13 @@ handle_one_xevent (struct x_display_info *dpyinfo, | |||
| 23740 | && xev->time > ignore_next_mouse_click_timeout) | 23767 | && xev->time > ignore_next_mouse_click_timeout) |
| 23741 | { | 23768 | { |
| 23742 | ignore_next_mouse_click_timeout = 0; | 23769 | ignore_next_mouse_click_timeout = 0; |
| 23743 | x_construct_mouse_click (&inev.ie, &bv, f); | 23770 | x_construct_mouse_click (&inev.ie, &bv, f, true); |
| 23744 | } | 23771 | } |
| 23745 | if (xev->evtype == XI_ButtonRelease) | 23772 | if (xev->evtype == XI_ButtonRelease) |
| 23746 | ignore_next_mouse_click_timeout = 0; | 23773 | ignore_next_mouse_click_timeout = 0; |
| 23747 | } | 23774 | } |
| 23748 | else | 23775 | else |
| 23749 | x_construct_mouse_click (&inev.ie, &bv, f); | 23776 | x_construct_mouse_click (&inev.ie, &bv, f, true); |
| 23750 | 23777 | ||
| 23751 | if (!NILP (tab_bar_arg)) | 23778 | if (!NILP (tab_bar_arg)) |
| 23752 | inev.ie.arg = tab_bar_arg; | 23779 | inev.ie.arg = tab_bar_arg; |
| @@ -32452,6 +32479,12 @@ syms_of_xterm (void) | |||
| 32452 | DEFSYM (Qexpose, "expose"); | 32479 | DEFSYM (Qexpose, "expose"); |
| 32453 | DEFSYM (Qdont_save, "dont-save"); | 32480 | DEFSYM (Qdont_save, "dont-save"); |
| 32454 | 32481 | ||
| 32482 | DEFSYM (Qmouse_wheel_buttons, "mouse-wheel-buttons"); | ||
| 32483 | DEFSYM (Qwheel_up, "wheel-up"); | ||
| 32484 | DEFSYM (Qwheel_down, "wheel-down"); | ||
| 32485 | DEFSYM (Qwheel_left, "wheel-left"); | ||
| 32486 | DEFSYM (Qwheel_right, "wheel-right"); | ||
| 32487 | |||
| 32455 | #ifdef USE_GTK | 32488 | #ifdef USE_GTK |
| 32456 | xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg"); | 32489 | xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg"); |
| 32457 | staticpro (&xg_default_icon_file); | 32490 | staticpro (&xg_default_icon_file); |