Skip to content

Comments

Forward mouse wheel events to applications in mouse tracking mode#178

Merged
kdj0c merged 1 commit intokmscon:mainfrom
jtollet:feature/mouse-wheel-forwarding
Dec 17, 2025
Merged

Forward mouse wheel events to applications in mouse tracking mode#178
kdj0c merged 1 commit intokmscon:mainfrom
jtollet:feature/mouse-wheel-forwarding

Conversation

@jtollet
Copy link
Contributor

@jtollet jtollet commented Dec 14, 2025

Fixes mouse wheel support in applications that use mouse tracking mode (e.g., vim, less, tmux).

Problem

When an application enables mouse tracking (like vim with ), kmscon was not forwarding mouse wheel events to the application. The wheel events were only used for scrolling kmscon's own terminal history, even when the application explicitly requested mouse input.

Solution

This PR adds support for forwarding mouse wheel events to applications by converting them to button events following the xterm mouse protocol:

  • Wheel up → button 4
  • Wheel down → button 5

Behavior

  • With mouse tracking enabled (vim , less, etc.): Mouse wheel scrolls the application content
  • Without mouse tracking (shell prompt): Mouse wheel scrolls kmscon terminal history (existing behavior preserved)

Changes

  • Modified in :
    • Added case to handle wheel events
    • Convert wheel direction to button 4/5 according to xterm protocol
    • Added local variable to allow modification before forwarding

Testing

  • Tested with vim (): wheel scrolls vim content ✓
  • Tested with bash: wheel scrolls terminal history ✓
  • Tested with less: wheel scrolls less content ✓

This fix brings kmscon's mouse wheel behavior in line with other terminal emulators like xterm, urxvt, and gnome-terminal.

When an application enables mouse tracking (e.g., vim with 'set mouse=a'),
kmscon now forwards mouse wheel events to the application by converting
them to button events (button 4 for scroll up, button 5 for scroll down),
following the xterm mouse protocol.

Previously, wheel events were only handled by kmscon itself for scrolling
the terminal history, even when an application requested mouse tracking.

This change allows:
- Mouse wheel to scroll content in applications like vim, less, etc.
  when they enable mouse mode
- Mouse wheel to continue scrolling kmscon history when no application
  has enabled mouse tracking (shell prompt)

Changes:
- Add UTERM_WHEEL case to forward_pointer_event()
- Convert wheel events to button 4/5 according to xterm protocol
- Use local button variable to allow modification before forwarding
@kdj0c
Copy link
Contributor

kdj0c commented Dec 14, 2025

Thanks, that's a useful addition to kmscon.
The commits looks good to me.

@jtollet
Copy link
Contributor Author

jtollet commented Dec 14, 2025

There's an update to be done in libtsm too: kmscon/libtsm#5

@kdj0c kdj0c merged commit b99b3bc into kmscon:main Dec 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants