-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Switch to the I-beam cursor when hovering over the terminal #5028
Changes from 6 commits
0f38659
2e04851
1ae08d4
6db3c8f
698bca2
61e46e3
34f83a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1075,6 +1075,7 @@ IAction | |
IApi | ||
IApplication | ||
IBase | ||
IBeam | ||
icacls | ||
iccex | ||
icch | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
_lastMouseClickTimestamp{}, | ||
_lastMouseClickPos{}, | ||
_selectionNeedsToBeCopied{ false }, | ||
_searchBox{ nullptr } | ||
_searchBox{ nullptr }, | ||
_textCursor{ Windows::UI::Core::CoreCursorType::IBeam, 0 }, | ||
_pointerCursor{ Windows::UI::Core::CoreCursorType::Arrow, 0 } | ||
{ | ||
_EnsureStaticInitialization(); | ||
InitializeComponent(); | ||
|
@@ -588,6 +590,12 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
|
||
auto inputFn = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1); | ||
_terminal->SetWriteInputCallback(inputFn); | ||
_terminal->SetMouseModeChangedCallback([weakThis = get_weak()]() { | ||
if (auto strongThis{ weakThis.get() }) | ||
{ | ||
strongThis->_TerminalMouseModeChanged(); | ||
} | ||
}); | ||
|
||
_SwapChainRoutine(); | ||
|
||
|
@@ -714,6 +722,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
e.OriginalKey() == VirtualKey::RightWindows) | ||
|
||
{ | ||
if (!_closing && e.OriginalKey() == VirtualKey::Shift) | ||
{ | ||
// If the user presses or releases shift, check whether we're in mouse mode and the cursor needs updating | ||
_TerminalMouseModeChanged(); | ||
} | ||
e.Handled(true); | ||
return; | ||
} | ||
|
@@ -765,6 +778,23 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
e.Handled(handled); | ||
} | ||
|
||
void TermControl::_KeyUpHandler(winrt::Windows::Foundation::IInspectable const& /*sender*/, | ||
Input::KeyRoutedEventArgs const& e) | ||
{ | ||
// If the current focused element is a child element of searchbox, | ||
// we do not send this event up to terminal | ||
if (_searchBox && _searchBox->ContainsFocus()) | ||
{ | ||
return; | ||
} | ||
|
||
if (!_closing && e.OriginalKey() == VirtualKey::Shift) | ||
{ | ||
// If the user presses or releases shift, check whether we're in mouse mode and the cursor needs updating | ||
_TerminalMouseModeChanged(); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - Send this particular key event to the terminal. | ||
// See Terminal::SendKeyEvent for more information. | ||
|
@@ -888,6 +918,18 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
return _terminal->IsTrackingMouseInput(); | ||
} | ||
|
||
// Method Description: | ||
// - Handles changes in mouse mode state | ||
winrt::fire_and_forget TermControl::_TerminalMouseModeChanged() | ||
{ | ||
co_await Dispatcher(); | ||
DHowett-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (_oldCursor) // if we have an active cursor transition | ||
{ | ||
auto coreWindow = Window::Current().CoreWindow(); | ||
coreWindow.PointerCursor(_CanSendVTMouseInput() ? _pointerCursor : _textCursor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a helper method that's just "set the |
||
} | ||
} | ||
|
||
// Method Description: | ||
// - handle a mouse click event. Begin selection process. | ||
// Arguments: | ||
|
@@ -1147,6 +1189,45 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
args.Handled(true); | ||
} | ||
|
||
// Method Description: | ||
// - Event handler for the PointerEntered event. We use this for cursor manipulation. | ||
// Arguments: | ||
// - sender: the XAML element responding to the pointer input | ||
// - args: event data | ||
void TermControl::_PointerEnteredHandler(Windows::Foundation::IInspectable const& /*sender*/, | ||
Input::PointerRoutedEventArgs const& /*args*/) | ||
{ | ||
if (_closing) | ||
{ | ||
return; | ||
} | ||
|
||
auto coreWindow = Window::Current().CoreWindow(); | ||
_oldCursor = coreWindow.PointerCursor(); | ||
|
||
if (_terminal->IsTrackingMouseInput()) | ||
{ | ||
return; | ||
} | ||
|
||
coreWindow.PointerCursor(_textCursor); | ||
DHowett-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Method Description: | ||
// - Event handler for the PointerExited event. We use this for cursor manipulation. | ||
// Arguments: | ||
// - sender: the XAML element responding to the pointer input | ||
// - args: event data | ||
void TermControl::_PointerExitedHandler(Windows::Foundation::IInspectable const& /*sender*/, | ||
Input::PointerRoutedEventArgs const& /*args*/) | ||
{ | ||
if (auto oldCursor{ std::exchange(_oldCursor, std::nullopt) }) | ||
{ | ||
auto coreWindow = Window::Current().CoreWindow(); | ||
coreWindow.PointerCursor(*oldCursor); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - Event handler for the PointerWheelChanged event. This is raised in | ||
// response to mouse wheel changes. Depending upon what modifier keys are | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
|
||
winrt::Windows::UI::Xaml::Controls::SwapChainPanel::LayoutUpdated_revoker _layoutUpdatedRevoker; | ||
|
||
std::optional<winrt::Windows::UI::Core::CoreCursor> _oldCursor; // when we toggle the cursor, we have to save it here to restore it | ||
winrt::Windows::UI::Core::CoreCursor _textCursor; | ||
winrt::Windows::UI::Core::CoreCursor _pointerCursor; | ||
Comment on lines
+171
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Correct me if I'm wrong) It looks like you only set these in the constructor. Why not just make them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they're winrt objects. it sucks. |
||
|
||
void _ApplyUISettings(); | ||
void _InitializeBackgroundBrush(); | ||
winrt::fire_and_forget _BackgroundColorChanged(const uint32_t color); | ||
|
@@ -175,10 +179,13 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
void _SetFontSize(int fontSize); | ||
void _TappedHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& e); | ||
void _KeyDownHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); | ||
void _KeyUpHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); | ||
void _CharacterHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::CharacterReceivedRoutedEventArgs const& e); | ||
void _PointerPressedHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _PointerMovedHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _PointerReleasedHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _PointerEnteredHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _PointerExitedHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _MouseWheelHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e); | ||
void _ScrollbarChangeHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs const& e); | ||
void _GotFocusHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); | ||
|
@@ -216,6 +223,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation | |
bool _TrySendKeyEvent(const WORD vkey, const WORD scanCode, ::Microsoft::Terminal::Core::ControlKeyStates modifiers); | ||
bool _TrySendMouseEvent(Windows::UI::Input::PointerPoint const& point); | ||
bool _CanSendVTMouseInput(); | ||
winrt::fire_and_forget _TerminalMouseModeChanged(); | ||
|
||
const COORD _GetTerminalPosition(winrt::Windows::Foundation::Point cursorPosition); | ||
const unsigned int _NumberOfClicks(winrt::Windows::Foundation::Point clickPos, Timestamp clickTime); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this bit would go away with #4748?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!