microsoft / microsoft/terminal

Spurious double clicks

Open
#14,474 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Input Help Wanted Issue-Bug Priority-2 Product-Conpty
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

### Windows Terminal version

Current main

### Windows build number

10.0.19044.2251

### Other Software

Any win32 console app with mouse support, e.g. Far Manager

### Steps to reproduce

Single-clicking intensively in different places in any console application with mouse support running in the Windows Terminal.

Code for repro
```c++
#include
#include "windows.h"

int main()
{
auto reply = INPUT_RECORD{};
auto count = DWORD{};
auto input = ::GetStdHandle(STD_INPUT_HANDLE);
::SetConsoleMode(input, ENABLE_EXTENDED_FLAGS | ENABLE_MOUSE_INPUT);
while (::ReadConsoleInputW(input, &reply, 1, &count) && count)
{
if (reply.EventType == MOUSE_EVENT
&& reply.Event.MouseEvent.dwEventFlags & DOUBLE_CLICK)
{
std::cout << "DOUBLE_CLICK\n";
}
else if (reply.EventType == KEY_EVENT
&& reply.Event.KeyEvent.wVirtualKeyCode == 27)
{
break;
}
}
}
```

### Expected Behavior

No spurious double clicks.

### Actual Behavior

Spurious double clicks are triggered randomly

https://user-images.githubusercontent.com/11535558/205082756-30e04223-fb40-407b-8766-fc74c8893674.mp4

Apparently this is due to the SGR mouse tracking protocol misinterpretation. Mouse drag is interpreted as a single click and its last position is remembered as with a normal click, and when the button is released, a false double click occurs:

https://github.com/microsoft/terminal/blob/52cc523ed292a916f28cbd75f6c165285942e21c/src/terminal/parser/InputStateMachineEngine.cpp#L843-L971

Everything works as expected If dragging is silently ignored (see possible fix below).

Possible fix:
terminal\src\terminal\parser\InputStateMachineEngine.cpp:873:
```c++
const auto buttonID = (sgrEncoding & 0x3) | ((sgrEncoding & 0xC0) >> 4) | ((sgrEncoding & 0x20) >> 5) * 3;
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in terminal/src/terminal/parser/InputStateMachineEngine.cpp around the SGR mouse handling at lines 843-971, then compile and run the provided C++ console reproducer in Windows Terminal. Verify that intensive single-clicking and dragging in a mouse-aware Win32 console application no longer produce spurious DOUBLE_CLICK events.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.