Improve input handling and scrolling behavior for high-resolution trackpads.

- Added precise fractional mouse wheel delta handling with per-step command emission.
- Introduced scroll accumulators (`wheel_accum_y_`, `wheel_accum_x_`) for high-resolution trackpad input.
- Replaced hardcoded ESC delay with configurable `kEscDelayMs` constant in `TerminalFrontend`.
- Enabled mouse position reporting and reduced CPU usage during idle with optimized `timeout()` setting.
This commit is contained in:
2025-12-05 20:42:46 -08:00
parent 3f4c60d311
commit 12cc04d7e0
4 changed files with 38 additions and 20 deletions

View File

@@ -42,13 +42,15 @@ TerminalFrontend::Init(Editor &ed)
meta(stdscr, TRUE);
// Make ESC key sequences resolve quickly so ESC+<key> works as meta
#ifdef set_escdelay
set_escdelay(50);
set_escdelay(TerminalFrontend::kEscDelayMs);
#endif
nodelay(stdscr, TRUE);
// Make getch() block briefly instead of busy-looping; reduces CPU when idle
// Equivalent to nodelay(FALSE) with a small timeout.
timeout(16); // ~16ms (about 60Hz)
curs_set(1);
// Enable mouse support if available
mouseinterval(0);
mousemask(ALL_MOUSE_EVENTS, nullptr);
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
int r = 0, c = 0;
getmaxyx(stdscr, r, c);
@@ -94,9 +96,6 @@ TerminalFrontend::Step(Editor &ed, bool &running)
if (mi.hasCommand) {
Execute(ed, mi.id, mi.arg, mi.count);
}
} else {
// Avoid busy loop
usleep(1000);
}
if (ed.QuitRequested()) {