Fix mouse drag tracking in SGR and PIXEL modes#11
Merged
kdj0c merged 2 commits intokmscon:mainfrom Jan 14, 2026
Merged
Conversation
This commit fixes two issues in libtsm mouse tracking: 1. Mode 1002 (Button-event) drag support: The code was rejecting ALL MOVED events in mode 1002, but per spec mode 1002 should accept drags (motion with button pressed, button >= 32). Added is_drag check to allow MOVED events with button >= 32 in mode 1002. 2. Hardcoded reply_flags in SGR mode: When handling MOVED events in SGR mode, reply_flags was hardcoded to 35, ignoring the actual button parameter. Now uses the button value passed in (which includes the +32 offset for drags from kmscon). Mode behavior now: - Mode 1000 (X10): No drags (as before) - Mode 1002 (BTN): Clicks + drags (button pressed motion) - NOW FIXED - Mode 1003 (ANY): Clicks + drags + hover (all motion) - works as before This allows Vim visual selection to update in real-time during mouse drag.
The PIXEL mode (1016) had the same bug as SGR mode - hardcoded reply_flags = 35 for MOVED events, ignoring the actual button value. This commit applies the same fix to PIXEL mode as was done for SGR mode, allowing drag events to work correctly in pixel coordinate mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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