Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alternate scroll mode in Terminal #12569

Merged
25 commits merged into from
Apr 12, 2022
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
83466a4
I think this is the conhost half of the changes
zadjii-msft Feb 23, 2022
e94e08c
This quite nearly implements everything for the Terminal half
zadjii-msft Feb 23, 2022
dd702c7
Most of the remaining todos, comments
zadjii-msft Feb 23, 2022
1209fa4
one last comment
zadjii-msft Feb 23, 2022
bf24cdd
more comments are always good
zadjii-msft Feb 23, 2022
97029f6
Add support for alternate scroll mode in Terminal
zadjii-msft Feb 24, 2022
dff1b94
spel
zadjii-msft Feb 24, 2022
60d2c2e
fix tests
zadjii-msft Feb 24, 2022
54dc304
Stashing this for now. I think this does the save/restore cursor stuf…
zadjii-msft Feb 28, 2022
57094b7
start writing tests
zadjii-msft Mar 8, 2022
69d0973
make this test way more elaborate
zadjii-msft Mar 8, 2022
0a1ed70
I thought this was a test for https://github.com/microsoft/terminal/p…
zadjii-msft Mar 8, 2022
9453aa5
More test cleanup. Make sure viewport doesnt move
zadjii-msft Mar 8, 2022
e658431
Merge remote-tracking branch 'origin/main' into dev/migrie/b/alt-buff…
zadjii-msft Mar 8, 2022
1e5a41e
Merge branch 'dev/migrie/b/alt-buffer-terminal' into dev/migrie/b/332…
zadjii-msft Mar 8, 2022
0e5d022
spel
zadjii-msft Mar 8, 2022
0cfb463
Merge remote-tracking branch 'origin/main' into dev/migrie/b/alt-buff…
zadjii-msft Mar 16, 2022
bf3d79e
fine that's not a word
zadjii-msft Mar 16, 2022
7237fce
thats not a word either
zadjii-msft Mar 17, 2022
65b4571
notes from j4james
zadjii-msft Mar 17, 2022
7c3e808
Merge remote-tracking branch 'origin/main' into dev/migrie/b/alt-buff…
zadjii-msft Apr 1, 2022
002fbbc
Merge remote-tracking branch 'origin/main' into dev/migrie/b/alt-buff…
zadjii-msft Apr 12, 2022
f209d98
fix the urls in the alt buffer
zadjii-msft Apr 12, 2022
e988182
Merge commit 'f209d98e4310d8df57ca5b0d4e36700a140ba0bd' into dev/migr…
DHowett Apr 12, 2022
913f1d4
Merge remote-tracking branch 'origin/main' into dev/migrie/b/3321-alt…
DHowett Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
@@ -1381,6 +1381,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _terminal != nullptr && _terminal->IsTrackingMouseInput();
}
bool ControlCore::ShouldSendAlternateScroll(const unsigned int uiButton,
const int32_t delta) const
{
return _terminal != nullptr && _terminal->ShouldSendAlternateScroll(uiButton, delta);
}

Core::Point ControlCore::CursorPosition() const
{
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void CursorOn(const bool isCursorOn);

bool IsVtMouseModeEnabled() const;
bool ShouldSendAlternateScroll(const unsigned int uiButton, const int32_t delta) const;
Core::Point CursorPosition() const;

bool HasSelection() const;
21 changes: 19 additions & 2 deletions src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
@@ -409,8 +409,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
const til::point terminalPosition = _getTerminalPosition(til::point{ pixelPosition });

// Short-circuit isReadOnly check to avoid warning dialog
if (!_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers))
// Short-circuit isReadOnly check to avoid warning dialog.
//
// GH#3321: Alternate scroll mode is a special type of mouse input mode
// where the terminal sends arrow keys when the user mouse wheels, but
// the client app doesn't care for other mouse input. It's tracked
// separately from _canSendVTMouseInput.
if (!_core->IsInReadOnlyMode() &&
(_canSendVTMouseInput(modifiers) || _shouldSendAlternateScroll(modifiers, delta)))
{
// Most mouse event handlers call
// _trySendMouseEvent(point);
@@ -571,6 +577,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core->IsVtMouseModeEnabled();
}

bool ControlInteractivity::_shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const int32_t delta)
{
// If the user is holding down Shift, suppress mouse events
// TODO GH#4875: disable/customize this functionality
if (modifiers.IsShiftPressed())
{
return false;
}
return _core->ShouldSendAlternateScroll(WM_MOUSEWHEEL, delta);
}

// Method Description:
// - Sets selection's end position to match supplied cursor position, e.g. while mouse dragging.
// Arguments:
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.h
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void _hyperlinkHandler(const std::wstring_view uri);
bool _canSendVTMouseInput(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers);
bool _shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const int32_t delta);

void _sendPastedTextToConnection(std::wstring_view wstr);
til::point _getTerminalPosition(const til::point pixelPosition);
14 changes: 14 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
@@ -536,6 +536,20 @@ bool Terminal::IsTrackingMouseInput() const noexcept
return _terminalInput->IsTrackingMouseInput();
}

// Routine Description:
// - Relays if we are in alternate scroll mode, a special type of mouse input
// mode where scrolling sends the arrow keypresses, but the app doesn't
// otherwise want mouse input.
// Parameters:
// - <none>
// Return value:
// - true, if we are tracking mouse input. False, otherwise
bool Terminal::ShouldSendAlternateScroll(const unsigned int uiButton,
const int32_t delta) const noexcept
{
return _terminalInput->ShouldSendAlternateScroll(uiButton, ::base::saturated_cast<short>(delta));
}

// Method Description:
// - Given a coord, get the URI at that location
// Arguments:
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@ class Microsoft::Terminal::Core::Terminal final :

void TrySnapOnInput() override;
bool IsTrackingMouseInput() const noexcept;
bool ShouldSendAlternateScroll(const unsigned int uiButton, const int32_t delta) const noexcept;

std::wstring GetHyperlinkAtPosition(const COORD position);
uint16_t GetHyperlinkIdAtPosition(const COORD position);
8 changes: 8 additions & 0 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
@@ -630,6 +630,10 @@ void Terminal::UseAlternateScreenBuffer()
// update all the hyperlinks on the screen
_updateUrlDetection();

// GH#3321: Make sure we let the TerminalInput know that we switched
// buffers. This might affect how we interpret certain mouse events.
_terminalInput->UseAlternateScreenBuffer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this part belongs in the original alt buffer PR -- since UseAlternateScreenBuffer isn't new.


// Update scrollbars
_NotifyScrollEvent();

@@ -674,6 +678,10 @@ void Terminal::UseMainScreenBuffer()
_mainBuffer->ClearPatternRecognizers();
_updateUrlDetection();

// GH#3321: Make sure we let the TerminalInput know that we switched
// buffers. This might affect how we interpret certain mouse events.
_terminalInput->UseMainScreenBuffer();

// Update scrollbars
_NotifyScrollEvent();

13 changes: 7 additions & 6 deletions src/terminal/input/mouseInput.cpp
Original file line number Diff line number Diff line change
@@ -321,7 +321,7 @@ bool TerminalInput::HandleMouse(const COORD position,
// on the wheel, accumulate delta until we hit the amount required to dispatch one
// "line" worth of scroll.
// Mark the event as "handled" if we would have otherwise emitted a scroll event.
return IsTrackingMouseInput() || _ShouldSendAlternateScroll(button, delta);
return IsTrackingMouseInput() || ShouldSendAlternateScroll(button, delta);
}

// We're ready to send this event through, but first we need to clear the accumulated;
@@ -330,7 +330,7 @@ bool TerminalInput::HandleMouse(const COORD position,
}

bool success = false;
if (_ShouldSendAlternateScroll(button, delta))
if (ShouldSendAlternateScroll(button, delta))
{
success = _SendAlternateScroll(delta);
}
@@ -539,11 +539,12 @@ std::wstring TerminalInput::_GenerateSGRSequence(const COORD position,
// - delta: The scroll wheel delta of the input event
// Return value:
// True iff the alternate buffer is active and alternate scroll mode is enabled and the event is a mouse wheel event.
bool TerminalInput::_ShouldSendAlternateScroll(const unsigned int button, const short delta) const noexcept
bool TerminalInput::ShouldSendAlternateScroll(const unsigned int button, const short delta) const noexcept
{
return _mouseInputState.inAlternateBuffer &&
_inputMode.test(Mode::AlternateScroll) &&
(button == WM_MOUSEWHEEL || button == WM_MOUSEHWHEEL) && delta != 0;
const bool inAltBuffer{ _mouseInputState.inAlternateBuffer };
const bool inAltScroll{ _inputMode.test(Mode::AlternateScroll) };
const bool wasMouseWheel{ (button == WM_MOUSEWHEEL || button == WM_MOUSEHWHEEL) && delta != 0 };
return inAltBuffer && inAltScroll && wasMouseWheel;
}

// Routine Description:
2 changes: 1 addition & 1 deletion src/terminal/input/terminalInput.hpp
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ namespace Microsoft::Console::VirtualTerminal
const MouseButtonState state);

bool IsTrackingMouseInput() const noexcept;
bool ShouldSendAlternateScroll(const unsigned int button, const short delta) const noexcept;
#pragma endregion

#pragma region MouseInputState Management
@@ -127,7 +128,6 @@ namespace Microsoft::Console::VirtualTerminal
const short modifierKeyState,
const short delta);

bool _ShouldSendAlternateScroll(const unsigned int button, const short delta) const noexcept;
bool _SendAlternateScroll(const short delta) const noexcept;

static constexpr unsigned int s_GetPressedButton(const MouseButtonState state) noexcept;