aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-07-13 08:24:11 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-07-13 08:41:10 +0000
commit1136108c9780eae9fae252a1bca5089f19fcd57d (patch)
tree89cc11fabcbb5096fe4117266aa6bc0eedda61fa
parentchangelog: remove entry for change that hasn't yet been merged (diff)
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
-rw-r--r--CHANGELOG.md12
-rw-r--r--config.c15
-rw-r--r--doc/foot.ini.5.scd23
-rw-r--r--foot.ini6
-rw-r--r--input.c2
-rw-r--r--input.h2
-rw-r--r--terminal.c26
7 files changed, 59 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3f7dffb..4a2d530c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/config.c b/config.c
index b7bc1f09..5d9a0b75 100644
--- a/config.c
+++ b/config.c
@@ -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);
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index f3c0aea6..680768e0 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -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
diff --git a/foot.ini b/foot.ini
index 23652d5e..7ae9ba1b 100644
--- a/foot.ini
+++ b/foot.ini
@@ -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
diff --git a/input.c b/input.c
index 5c7de859..68cb9314 100644
--- a/input.c
+++ b/input.c
@@ -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);
diff --git a/input.h b/input.h
index 2ea1c6a9..34342bbf 100644
--- a/input.h
+++ b/input.h
@@ -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
diff --git a/terminal.c b/terminal.c
index d08bb74d..6e83d9a0 100644
--- a/terminal.c
+++ b/terminal.c
@@ -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);