Skip to content

Commit

Permalink
Add Alt-modified mousewheel mode
Browse files Browse the repository at this point in the history
When enabled, this sends Alt-modified cursor up/down keycodes for
mousewheel events. If the Alt key is pressed, unmodified keycodes are
sent. The mode does not affect page up/down codes.

In the nano editor from version 4.0, the Alt+Up/Down keycodes scroll the
window instead of moving the cursor. Scrolling straight away is the
proper action for the mousewheel, whereas moving the cursor only scrolls
once the cursor reaches the top or bottom.

Less scrolls with or without the Alt modifier. Vim and mined at least
tolerate Alt+Up/Down, apparently handling it the same as unmodified
Up/Down, and they have proper mousewheel support using full mouse
reporting mode anyway.
  • Loading branch information
ak2 committed Sep 8, 2023
1 parent aab9f93 commit ca409d1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/term.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// term.c (part of mintty)
// Copyright 2008-12 Andy Koppe, 2016-2020 Thomas Wolff
// Copyright 2008-23 Andy Koppe, 2016-2020 Thomas Wolff
// Adapted from code from PuTTY-0.60 by Simon Tatham and team.
// Licensed under the terms of the GNU General Public License v3 or later.

Expand Down Expand Up @@ -346,6 +346,7 @@ term_reset(bool full)
term.wheel_reporting_xterm = false;
term.wheel_reporting = true;
term.app_wheel = false;
term.alt_wheel = false;
term.echoing = false;
term.bracketed_paste = false;
term.wide_indic = false;
Expand Down
3 changes: 2 additions & 1 deletion src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ struct term {
bool bell_popup; // xterm: popOnBell; switchable with CSI ? 1043 h/l
bool wheel_reporting_xterm; // xterm: alternateScroll
bool wheel_reporting; // similar, but default true
bool app_wheel; // format for wheel_reporting
bool app_wheel; // dedicated wheel codes instead of cursor codes
bool alt_wheel; // add Alt modifier to wheel cursor codes
int modify_other_keys;
bool newline_mode;
bool report_focus;
Expand Down
7 changes: 4 additions & 3 deletions src/termmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,10 @@ term_mouse_wheel(bool horizontal, int delta, int lines_per_notch, mod_keys mods,
: (up ? "\e[5~" : "\e[6~"));
}
else {
send_keys(count, alt ? (up ? "\e[1;3A" : "\e[1;3B") :
term.app_cursor_keys ? (up ? "\eOA" : "\eOB")
: (up ? "\e[A" : "\e[B"));
send_keys(count,
alt ^ term.alt_wheel ? (up ? "\e[1;3A" : "\e[1;3B") :
term.app_cursor_keys ? (up ? "\eOA" : "\eOB")
: (up ? "\e[A" : "\e[B"));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/termout.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// termout.c (part of mintty)
// Copyright 2008-22 Andy Koppe, 2017-22 Thomas Wolff
// Copyright 2008-23 Andy Koppe, 2017-22 Thomas Wolff
// Adapted from code from PuTTY-0.60 by Simon Tatham and team.
// Licensed under the terms of the GNU General Public License v3 or later.

Expand Down Expand Up @@ -2311,6 +2311,8 @@ set_modes(bool state)
term.wheel_reporting = state;
when 7787: /* 'W': Application mousewheel mode */
term.app_wheel = state;
when 7777: /* 'M': Alt-Modified mousewheel mode */
term.alt_wheel = state;
when 7796: /* Bidi disable in current line */
if (state)
term.lines[term.curs.y]->lattr |= LATTR_NOBIDI;
Expand Down Expand Up @@ -2495,6 +2497,8 @@ get_mode(bool privatemode, int arg)
return 2 - term.wheel_reporting;
when 7787: /* 'W': Application mousewheel mode */
return 2 - term.app_wheel;
when 7777: /* 'M': Alt-Modified mousewheel mode */
return 2 - term.alt_wheel;
when 7796: /* Bidi disable in current line */
return 2 - !!(term.lines[term.curs.y]->lattr & LATTR_NOBIDI);
when 77096: /* Bidi disable */
Expand Down
18 changes: 17 additions & 1 deletion wiki/CtrlSeqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,23 @@ to private sequences (see below). To support these subtle differences,
both can be switched independently.

By default, mousewheel events are reported as cursor key presses, which enables
mousewheel scrolling in applications such as **[less](http://www.greenwoodsoftware.com/less)** without requiring any configuration. Alternatively, mousewheel reporting can be switched to _application mousewheel mode_, where the mousewheel sends its own separate keycodes that allow an application to treat the mousewheel differently from cursor keys:
mousewheel scrolling in applications such as
**[less](http://www.greenwoodsoftware.com/less)** without requiring any
configuration.

The cursor keycodes sent for mousewheel events can optionally have the Alt
modifier applied, to distinguish them from plain Up/Down key presses.
For example, in the nano editor, Alt+Up/Down scrolls the window immediately,
whereas plain Up/Down moves the cursor.

_Alt-modified mousewheel mode_ is controlled by these sequences:

| **sequence** | **mode** |
|:--------------|:--------------|
| `^[[?7777l` | unmodified |
| `^[[?7777h` | Alt-modified |

Alternatively, mousewheel reporting can be switched to _application mousewheel mode_, where the mousewheel sends its own separate keycodes that allow an application to treat the mousewheel differently from cursor keys:

| **event** | **code** |
|:------------|:------------|
Expand Down

0 comments on commit ca409d1

Please sign in to comment.