input: don't map wheel events to BTN_{BACK,FORWARD}

BTN_BACK and BTN_FORWARD are separate buttons. The scroll wheel don't
have any button mappings in libinput/wayland, so make up our own
defines.

This allows us to map them in mouse bindings.

Also expose BTN_WHEEL_{LEFT,RIGHT}. These were already defined, and
used, internally, to handle wheel tilt events. With this, they can
also be used in mouse bindings.

Finally, fix encoding used for BTN_{BACK,FORWARD} when sending mouse
button events to the client application. Before this, they were mapped
to buttons 4/5. But, button 4/5 are for the scroll wheel, and as
mentioned above, BTN_{BACK,FORWARD} are not the same as scroll wheel
"buttons".

Closes #1763
This commit is contained in:
Daniel Eklöf 2024-07-13 10:24:11 +02:00
parent 15c0078c2d
commit 1136108c97
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 59 additions and 27 deletions

View file

@ -89,9 +89,19 @@
and background are the same), the cursor will instead be rendered
using the default foreground and background colors, inverted
([#1761][1761]).
* Mouse wheel events now generate `BTN_WHEEL_BACK` and
`BTN_WHEEL_FORWARD` "button presses", instead of `BTN_BACK` and
`BTN_FORWARD`. The default bindings have been updated, and
`scrollback-up-mouse`, `scrollback-down-mouse`, `font-increase` and
`font-decrease` now use the new button names.
This change allow users to separate physical mouse buttons that
_also_ generates `BTN_BACK` and `BTN_FORWARD`, from wheel scrolling
([#1763][1763]).
[1701]: https://codeberg.org/dnkl/foot/issues/1701
[1761]: https://codeberg.org/dnkl/foot/issues/1761
[1763]: https://codeberg.org/dnkl/foot/issues/1763
### Deprecated
@ -118,6 +128,8 @@
foot config has not set any custom cursor colors (i.e. without
OSC-12, inverted fg/bg would be used).
* Wrong color used when drawing the unfocused, hollow cursor.
* Encoding of `BTN_BACK` and `BTN_FORWARD`, when sending a mouse input
escape sequence to the terminal application.
[1694]: https://codeberg.org/dnkl/foot/issues/1694
[1717]: https://codeberg.org/dnkl/foot/issues/1717

View file

@ -1686,6 +1686,7 @@ static const struct {
const char *name;
int code;
} button_map[] = {
/* System defined */
{"BTN_LEFT", BTN_LEFT},
{"BTN_RIGHT", BTN_RIGHT},
{"BTN_MIDDLE", BTN_MIDDLE},
@ -1694,6 +1695,12 @@ static const struct {
{"BTN_FORWARD", BTN_FORWARD},
{"BTN_BACK", BTN_BACK},
{"BTN_TASK", BTN_TASK},
/* Foot custom, to be able to map scroll events to mouse bindings */
{"BTN_WHEEL_BACK", BTN_WHEEL_BACK},
{"BTN_WHEEL_FORWARD", BTN_WHEEL_FORWARD},
{"BTN_WHEEL_LEFT", BTN_WHEEL_LEFT},
{"BTN_WHEEL_RIGHT", BTN_WHEEL_RIGHT},
};
static int
@ -2989,8 +2996,8 @@ static void
add_default_mouse_bindings(struct config *conf)
{
const struct config_key_binding bindings[] = {
{BIND_ACTION_SCROLLBACK_UP_MOUSE, m("none"), {.m = {BTN_BACK, 1}}},
{BIND_ACTION_SCROLLBACK_DOWN_MOUSE, m("none"), {.m = {BTN_FORWARD, 1}}},
{BIND_ACTION_SCROLLBACK_UP_MOUSE, m("none"), {.m = {BTN_WHEEL_BACK, 1}}},
{BIND_ACTION_SCROLLBACK_DOWN_MOUSE, m("none"), {.m = {BTN_WHEEL_FORWARD, 1}}},
{BIND_ACTION_PRIMARY_PASTE, m("none"), {.m = {BTN_MIDDLE, 1}}},
{BIND_ACTION_SELECT_BEGIN, m("none"), {.m = {BTN_LEFT, 1}}},
{BIND_ACTION_SELECT_BEGIN_BLOCK, m(XKB_MOD_NAME_CTRL), {.m = {BTN_LEFT, 1}}},
@ -3000,8 +3007,8 @@ add_default_mouse_bindings(struct config *conf)
{BIND_ACTION_SELECT_WORD_WS, m(XKB_MOD_NAME_CTRL), {.m = {BTN_LEFT, 2}}},
{BIND_ACTION_SELECT_QUOTE, m("none"), {.m = {BTN_LEFT, 3}}},
{BIND_ACTION_SELECT_ROW, m("none"), {.m = {BTN_LEFT, 4}}},
{BIND_ACTION_FONT_SIZE_UP, m("Control"), {.m = {BTN_BACK, 1}}},
{BIND_ACTION_FONT_SIZE_DOWN, m("Control"), {.m = {BTN_FORWARD, 1}}},
{BIND_ACTION_FONT_SIZE_UP, m("Control"), {.m = {BTN_WHEEL_BACK, 1}}},
{BIND_ACTION_FONT_SIZE_DOWN, m("Control"), {.m = {BTN_WHEEL_FORWARD, 1}}},
};
conf->bindings.mouse.count = ALEN(bindings);

View file

@ -1156,10 +1156,13 @@ The trailing *COUNT* (number of times the button has to be clicked) is
optional and specifies the click count required to trigger the
binding. The default if *COUNT* is omitted is _1_.
To map wheel events (i.e. scrolling), use the button names *BTN_BACK*
(up) and *BTN_FORWARD* (down). Note that these events never generate a
*COUNT* larger than 1. That is, *BTN_BACK+2*, for example, will never
trigger.
To map wheel events (i.e. scrolling), use the button names
*BTN_WHEEL_BACK* (up) and *BTN_WHEEL_FORWARD* (down). Note that these
events never generate a *COUNT* larger than 1. That is,
*BTN_WHEEL_BACK+2*, for example, will never trigger.
Foot also recognizes tiltable wheels; to map these, use
*BTN_WHEEL_LEFT* and *BTN_WHEEL_RIGHT*.
A modifier+button combination can only be mapped to *one* action. Lets
say you want to bind *BTN\_MIDDLE* to *fullscreen*. Since
@ -1187,7 +1190,7 @@ actions listed under *key-bindings* can be used here as well.
Alt screen: send fake _KeyUP_ events to the client application, if
alternate scroll mode is enabled.
Default: _BTN_BACK_
Default: _BTN\_WHEEL\_BACK_
*scrollback-down-mouse*
Normal screen: scrolls down the contents.
@ -1195,7 +1198,7 @@ actions listed under *key-bindings* can be used here as well.
Alt screen: send fake _KeyDOWN_ events to the client application, if
alternate scroll mode is enabled.
Default: _BTN_FORWARD_
Default: _BTN\_WHEEL\_FORWARD_
*select-begin*
Begin an interactive selection. The selection is finalized, and
@ -1269,12 +1272,12 @@ actions listed under *key-bindings* can be used here as well.
Pastes from the _primary selection_. Default: _BTN\_MIDDLE_.
*font-increase*
Increases the font size by 0.5pt. Default: _Control+BTN\_BACK_
(also defined in *key-bindings*).
Increases the font size by 0.5pt. Default:
_Control+BTN\_WHEEL\_BACK_ (also defined in *key-bindings*).
*font-decrease*
Decreases the font size by 0.5pt. Default: _Control+BTN\_FORWARD_
(also defined in *key-bindings*).
Decreases the font size by 0.5pt. Default:
_Control+BTN\_WHEEL\_FORWARD_ (also defined in *key-bindings*).
# TWEAK

View file

@ -213,8 +213,10 @@
# \x03=Mod4+c # Map Super+c -> Ctrl+c
[mouse-bindings]
# scrollback-up-mouse=BTN_BACK
# scrollback-down-mouse=BTN_FORWARD
# scrollback-up-mouse=BTN_WHEEL_BACK
# scrollback-down-mouse=BTN_WHEEL_FORWARD
# font-increase=Control+BTN_WHEEL_BACK
# font-decrease=Control+BTN_WHEEL_FORWARD
# selection-override-modifiers=Shift
# primary-paste=BTN_MIDDLE
# select-begin=BTN_LEFT

View file

@ -2708,7 +2708,7 @@ mouse_scroll(struct seat *seat, int amount, enum wl_pointer_axis axis)
xassert(term != NULL);
int button = axis == WL_POINTER_AXIS_VERTICAL_SCROLL
? amount < 0 ? BTN_BACK : BTN_FORWARD
? amount < 0 ? BTN_WHEEL_BACK : BTN_WHEEL_FORWARD
: amount < 0 ? BTN_WHEEL_LEFT : BTN_WHEEL_RIGHT;
amount = abs(amount);

View file

@ -21,6 +21,8 @@
* Mouse buttons are in the range 0x110 - 0x11f, with joystick defines
* starting at 0x120.
*/
#define BTN_WHEEL_BACK 0x11c
#define BTN_WHEEL_FORWARD 0x11d
#define BTN_WHEEL_LEFT 0x11e
#define BTN_WHEEL_RIGHT 0x11f

View file

@ -3192,17 +3192,23 @@ term_kbd_focus_out(struct terminal *term)
static int
linux_mouse_button_to_x(int button)
{
/* Note: on X11, scroll events where reported as buttons. Not so
* on Wayland. We manually map scroll events to custom "button"
* defines (BTN_WHEEL_*).
*/
switch (button) {
case BTN_LEFT: return 1;
case BTN_MIDDLE: return 2;
case BTN_RIGHT: return 3;
case BTN_BACK: return 4;
case BTN_FORWARD: return 5;
case BTN_WHEEL_LEFT: return 6; /* Foot custom define */
case BTN_WHEEL_RIGHT: return 7; /* Foot custom define */
case BTN_SIDE: return 8;
case BTN_EXTRA: return 9;
case BTN_TASK: return -1; /* TODO: ??? */
case BTN_LEFT: return 1;
case BTN_MIDDLE: return 2;
case BTN_RIGHT: return 3;
case BTN_WHEEL_BACK: return 4; /* Foot custom define */
case BTN_WHEEL_FORWARD: return 5; /* Foot custom define */
case BTN_WHEEL_LEFT: return 6; /* Foot custom define */
case BTN_WHEEL_RIGHT: return 7; /* Foot custom define */
case BTN_SIDE: return 8;
case BTN_EXTRA: return 9;
case BTN_FORWARD: return 10;
case BTN_BACK: return 11;
case BTN_TASK: return 12; /* Guessing... */
default:
LOG_WARN("unrecognized mouse button: %d (0x%x)", button, button);