diff --git a/CHANGELOG.md b/CHANGELOG.md index 20a0a687..85e4facb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,12 @@ (https://codeberg.org/dnkl/foot/issues/128). * **scrollback-up-line** and **scrollback-down-line** key bindings. They scroll up/down a single line in the scrollback. +* **mouse.alternate-scroll-mode** option to `foot.ini`. This option + controls the initial state of the _Alternate Scroll Mode_, and + defaults to `yes`. When enabled, mouse events are translated to + up/down key events in the alternate screen, letting you scroll in + e.g. `less` and other applications without enabling native mouse + support in them (https://codeberg.org/dnkl/foot/issues/135). ### Removed diff --git a/config.c b/config.c index de4e24c9..418c9c37 100644 --- a/config.c +++ b/config.c @@ -764,6 +764,9 @@ parse_section_mouse(const char *key, const char *value, struct config *conf, if (strcmp(key, "hide-when-typing") == 0) conf->mouse.hide_when_typing = str_to_bool(value); + else if (strcmp(key, "alternate-scroll-mode") == 0) + conf->mouse.alternate_scroll_mode = str_to_bool(value); + else { LOG_AND_NOTIFY_ERR("%s:%d: [mouse]: %s: invalid key", path, lineno, key); return false; @@ -1907,6 +1910,7 @@ config_load(struct config *conf, const char *conf_path, }, .mouse = { .hide_when_typing = false, + .alternate_scroll_mode = true, }, .csd = { .preferred = CONF_CSD_PREFER_SERVER, diff --git a/config.h b/config.h index 9a897e62..1c0edc58 100644 --- a/config.h +++ b/config.h @@ -119,6 +119,7 @@ struct config { struct { bool hide_when_typing; + bool alternate_scroll_mode; } mouse; struct { diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 30c36b51..4513de05 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -143,6 +143,24 @@ applications can change these at runtime. *hide-when-typing* Boolean. When enabled, the mouse cursor is hidden while typing. +*alternate-scroll-mode* + Boolean. This option controls the initial value for the _alternate + scroll mode_. When this mode is enabled, mouse scroll events are + translated to _up_/_down_ key events when displaying the alternate + screen. + + This lets you scroll with the mouse in e.g. pagers (like _less_) + without enabling native mouse support in them. + + Alternate scrolling is *not* used if the application enables + native mouse support. + + This option can be modified by applications at run-time using the + escape sequences *CSI ? 1007 h* (enable) and *CSI ? 1007 l` + (disable). + + Default: _yes_. + # SECTION: colors diff --git a/foot.ini b/foot.ini index 7c49be5a..5e8dc47e 100644 --- a/foot.ini +++ b/foot.ini @@ -23,6 +23,7 @@ [mouse] # hide-when-typing=no +# alternate-scroll-mode=yes [colors] # alpha=1.0 diff --git a/terminal.c b/terminal.c index 9d68167d..5e0dc65a 100644 --- a/terminal.c +++ b/terminal.c @@ -964,6 +964,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .grid = &term->normal, .composed_count = 0, .composed = NULL, + .alt_scrolling = conf->mouse.alternate_scroll_mode, .meta = { .esc_prefix = true, .eight_bit = true,