Fix mouse drag tracking in terminal applications#214
Merged
kdj0c merged 2 commits intokmscon:mainfrom Jan 13, 2026
Merged
Conversation
Contributor
|
Thanks for your contribution. It looks good to me, the only comment I have would be to add a define in uterm_input_internal.h: And use that when no button is pressed. |
a2673fc to
a90bd0d
Compare
Contributor
Author
|
Thank you for the review! I have updated the commits to use Changes:
The code is now more readable and maintainable. |
When an application like Vim activates mouse tracking (SGR mode with any-event tracking), motion events during drag (button held + movement) were not including button state information. This caused visual selection in Vim to only update on button release instead of showing real-time feedback during drag. Changes: - Add BUTTON_NONE constant (255) to represent no button pressed - Add pressed_button field (uint8_t) to uterm_input_pointer struct to track which button is currently pressed (BUTTON_NONE, 0=left, 1=right, 2=middle) - Initialize pressed_button to BUTTON_NONE in uterm_input_dev initialization - Update pressed_button state in pointer_dev_button() on press/release - Include button state in UTERM_MOVED events sent by pointer_dev_send_move() - Now motion events during drag properly indicate which button is pressed This fixes the lag/delay in visual selection for applications using mouse tracking under kmscon, bringing behavior in line with X terminal emulators.
The previous patch tracked button state correctly but used the wrong encoding when forwarding motion events to libtsm. In X10/SGR mouse tracking protocol: - Button press/release events use button numbers: 0 (left), 1 (right), 2 (middle) - Motion with button pressed (drag) uses: button + 32 This commit adds the +32 offset in forward_pointer_event() for UTERM_MOVED events when a button is pressed, so libtsm correctly interprets them as drag events rather than hover motion. Now visual selection in Vim should update in real-time during mouse drag.
a90bd0d to
ec0f6e5
Compare
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 kmscon, allowing applications like Vim to properly display visual selection in real-time during mouse drag operations.
Problem
When applications activate mouse tracking (e.g., Vim with
set mouse=a ttymouse=sgr), visual selection would only update after releasing the mouse button, not during the drag itself. This worked fine in X terminal emulators but not in kmscon.Root Cause
kmscon was not tracking or transmitting button state during mouse motion events. When the user dragged with a button pressed:
Solution
Commit 1: Track button state
pressed_buttonfield touterm_input_pointerstructureUTERM_MOVEDeventsCommit 2: Encode drags correctly
Testing
Tested with Vim visual selection under kmscon:
Works with all modern mouse tracking modes (SGR, PIXEL, modes 1002/1003).
Related
This requires corresponding fixes in libtsm: kmscon/libtsm#11