Fix mouse drag tracking in SGR and PIXEL modes #11
+21
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes mouse drag tracking in libtsm for SGR (mode 1006) and PIXEL (mode 1016) modes, enabling applications like Vim to display visual selection in real-time during mouse drags.
Problem
When applications activated mouse tracking, drag operations (mouse motion with button pressed) were not working correctly:
This caused applications like Vim to only update selection on button release, not during the drag.
Root Causes
Issue 1: Mode 1002 filter too strict
The code was rejecting ALL MOVED events in mode 1002, but per spec mode 1002 should accept drags (motion with button pressed, button >= 32).
Issue 2: Hardcoded button value
When handling MOVED events in SGR/PIXEL modes, reply_flags was hardcoded to 35, ignoring the actual button parameter passed in.
Solution
Commit 1: Accept drags in mode 1002
button >= 32 && button <= 34(protocol encoding)Commit 2: Use actual button value in SGR/PIXEL modes
reply_flags = 35;hardcodeTesting
Tested with Vim under kmscon with
set mouse=a ttymouse=sgr:All unit tests pass (7/7).
Protocol Reference
Mouse tracking protocol encoding:
Related
This works in conjunction with fixes in kmscon: kmscon/kmscon#214