From 79e0b77320faabe844e9cb09633c7aa305ea04bb Mon Sep 17 00:00:00 2001 From: khvitaly Date: Sat, 30 Jan 2021 10:21:02 +0200 Subject: [PATCH 1/4] Teach terminal control to gain focus on pointer hover --- src/cascadia/TerminalControl/TermControl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 0a6b453e8ee..ca086293a35 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1353,10 +1353,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation const auto cursorPosition = point.Position(); const auto terminalPosition = _GetTerminalPosition(cursorPosition); - if (!_focused && (_terminal->GetHyperlinkAtPosition(terminalPosition).empty())) + if (!_focused) { - args.Handled(true); - return; + Focus(FocusState::Pointer); } if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse || ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Pen) From 6a7c357f446869f2e56bf05b443769ec62678392 Mon Sep 17 00:00:00 2001 From: khvitaly Date: Thu, 4 Feb 2021 22:01:18 +0200 Subject: [PATCH 2/4] Introduce settign for enabling FFM mode --- src/cascadia/TerminalApp/TerminalSettings.cpp | 1 + src/cascadia/TerminalApp/TerminalSettings.h | 1 + src/cascadia/TerminalControl/IControlSettings.idl | 1 + src/cascadia/TerminalControl/TermControl.cpp | 8 +++++++- .../TerminalSettingsEditor/Interaction.xaml | 13 ++++++++++--- .../Resources/en-US/Resources.resw | 6 ++++++ .../TerminalSettingsModel/GlobalAppSettings.cpp | 5 +++++ .../TerminalSettingsModel/GlobalAppSettings.h | 1 + .../TerminalSettingsModel/GlobalAppSettings.idl | 4 ++++ src/cascadia/TerminalSettingsModel/defaults.json | 1 + .../UnitTests_TerminalCore/MockTermSettings.h | 3 +++ 11 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalSettings.cpp b/src/cascadia/TerminalApp/TerminalSettings.cpp index 38ccfe45bbc..6a087df3381 100644 --- a/src/cascadia/TerminalApp/TerminalSettings.cpp +++ b/src/cascadia/TerminalApp/TerminalSettings.cpp @@ -206,6 +206,7 @@ namespace winrt::TerminalApp::implementation _WordDelimiters = globalSettings.WordDelimiters(); _CopyOnSelect = globalSettings.CopyOnSelect(); + _FocusFollowMouse = globalSettings.FocusFollowMouse(); _ForceFullRepaintRendering = globalSettings.ForceFullRepaintRendering(); _SoftwareRendering = globalSettings.SoftwareRendering(); _ForceVTInput = globalSettings.ForceVTInput(); diff --git a/src/cascadia/TerminalApp/TerminalSettings.h b/src/cascadia/TerminalApp/TerminalSettings.h index f8ec65e2e27..2533a079507 100644 --- a/src/cascadia/TerminalApp/TerminalSettings.h +++ b/src/cascadia/TerminalApp/TerminalSettings.h @@ -67,6 +67,7 @@ namespace winrt::TerminalApp::implementation GETSET_PROPERTY(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT); GETSET_PROPERTY(hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS); GETSET_PROPERTY(bool, CopyOnSelect, false); + GETSET_PROPERTY(bool, FocusFollowMouse, false); GETSET_PROPERTY(Windows::Foundation::IReference, TabColor, nullptr); diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index cfca032ce8d..0c80d68b1e3 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -39,6 +39,7 @@ namespace Microsoft.Terminal.TerminalControl Microsoft.Terminal.TerminalControl.IKeyBindings KeyBindings; Boolean CopyOnSelect; + Boolean FocusFollowMouse; String Commandline; String StartingDirectory; diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index f2d1477854b..0e07f7118ba 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1353,11 +1353,17 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation const auto cursorPosition = point.Position(); const auto terminalPosition = _GetTerminalPosition(cursorPosition); - if (!_focused) + if (!_focused && _settings.FocusFollowMouse()) { Focus(FocusState::Pointer); } + if (!_focused && (_terminal->GetHyperlinkAtPosition(terminalPosition).empty())) + { + args.Handled(true); + return; + } + if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse || ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Pen) { if (_CanSendVTMouseInput()) diff --git a/src/cascadia/TerminalSettingsEditor/Interaction.xaml b/src/cascadia/TerminalSettingsEditor/Interaction.xaml index f9ac804a1f0..17ca4871199 100644 --- a/src/cascadia/TerminalSettingsEditor/Interaction.xaml +++ b/src/cascadia/TerminalSettingsEditor/Interaction.xaml @@ -15,13 +15,13 @@ the MIT License. See LICENSE in the project root for license information. --> - + - + @@ -51,7 +51,7 @@ the MIT License. See LICENSE in the project root for license information. --> - + ItemsSource="{x:Bind TabSwitcherModeList}" ItemTemplate="{StaticResource EnumRadioButtonTemplate}"/> + + + + + diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 6744f2da54f..4f41c4b8033 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -838,4 +838,10 @@ This color scheme name is already in use. + + Enable Focus Follow Mouse mode + + + When checked, the terminal will focus pane on mouse hover. + diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp index 4d2d904f878..61846613bc0 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp @@ -41,6 +41,7 @@ static constexpr std::string_view LegacyUseTabSwitcherModeKey{ "useTabSwitcher" static constexpr std::string_view TabSwitcherModeKey{ "tabSwitcherMode" }; static constexpr std::string_view DisableAnimationsKey{ "disableAnimations" }; static constexpr std::string_view StartupActionsKey{ "startupActions" }; +static constexpr std::string_view FocusFollowMouseKey{ "focusFollowMouse" }; static constexpr std::string_view DebugFeaturesKey{ "debugFeatures" }; @@ -116,6 +117,7 @@ winrt::com_ptr GlobalAppSettings::Copy() const globals->_TabSwitcherMode = _TabSwitcherMode; globals->_DisableAnimations = _DisableAnimations; globals->_StartupActions = _StartupActions; + globals->_FocusFollowMouse = _FocusFollowMouse; globals->_UnparsedDefaultProfile = _UnparsedDefaultProfile; globals->_validDefaultProfile = _validDefaultProfile; @@ -304,6 +306,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, StartupActionsKey, _StartupActions); + JsonUtils::GetValueForKey(json, FocusFollowMouseKey, _FocusFollowMouse); + // This is a helper lambda to get the keybindings and commands out of both // and array of objects. We'll use this twice, once on the legacy // `keybindings` key, and again on the newer `bindings` key. @@ -399,6 +403,7 @@ Json::Value GlobalAppSettings::ToJson() const JsonUtils::SetValueForKey(json, TabSwitcherModeKey, _TabSwitcherMode); JsonUtils::SetValueForKey(json, DisableAnimationsKey, _DisableAnimations); JsonUtils::SetValueForKey(json, StartupActionsKey, _StartupActions); + JsonUtils::SetValueForKey(json, FocusFollowMouseKey, _FocusFollowMouse); // clang-format on // TODO GH#8100: keymap needs to be serialized here diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h index 8e1e65942b4..bfa47d63718 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h @@ -87,6 +87,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation GETSET_SETTING(Model::TabSwitcherMode, TabSwitcherMode, Model::TabSwitcherMode::InOrder); GETSET_SETTING(bool, DisableAnimations, false); GETSET_SETTING(hstring, StartupActions, L""); + GETSET_SETTING(bool, FocusFollowMouse, false); private: guid _defaultProfile; diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index 6f0fc41dac1..e9ffca476db 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -146,5 +146,9 @@ namespace Microsoft.Terminal.Settings.Model Boolean HasStartupActions(); void ClearStartupActions(); String StartupActions(); + + Boolean HasFocusFollowMouse(); + void ClearFocusFollowMouse(); + Boolean FocusFollowMouse; } } diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 372205ab02b..cf8338bc19a 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -27,6 +27,7 @@ "snapToGridOnResize": true, "disableAnimations": false, "startupActions": "", + "focusFollowMouse": false, "profiles": [ diff --git a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h index e55e17b9612..3100c7f5f60 100644 --- a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h +++ b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h @@ -35,6 +35,7 @@ namespace TerminalCoreUnitTests uint32_t CursorHeight() { return 42UL; } winrt::hstring WordDelimiters() { return winrt::hstring(DEFAULT_WORD_DELIMITERS); } bool CopyOnSelect() { return _copyOnSelect; } + bool FocusFollowMouse() { return _focusFollowMouse; } winrt::hstring StartingTitle() { return _startingTitle; } bool SuppressApplicationTitle() { return _suppressApplicationTitle; } uint32_t SelectionBackground() { return COLOR_WHITE; } @@ -56,6 +57,7 @@ namespace TerminalCoreUnitTests void CursorHeight(uint32_t) {} void WordDelimiters(winrt::hstring) {} void CopyOnSelect(bool copyOnSelect) { _copyOnSelect = copyOnSelect; } + void FocusFollowMouse(bool focusFollowMouse) { _focusFollowMouse = focusFollowMouse; } void StartingTitle(winrt::hstring const& value) { _startingTitle = value; } void SuppressApplicationTitle(bool suppressApplicationTitle) { _suppressApplicationTitle = suppressApplicationTitle; } void SelectionBackground(uint32_t) {} @@ -69,6 +71,7 @@ namespace TerminalCoreUnitTests int32_t _initialRows; int32_t _initialCols; bool _copyOnSelect{ false }; + bool _focusFollowMouse{ false }; bool _suppressApplicationTitle{ false }; winrt::hstring _startingTitle; }; From cea79684d6a33b02b25d1e356dceeea0865d4106 Mon Sep 17 00:00:00 2001 From: khvitaly Date: Tue, 9 Feb 2021 23:36:39 +0200 Subject: [PATCH 3/4] Add ffm setting to json schema --- doc/cascadia/profiles.schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 417ab32e280..9a43234411a 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -635,6 +635,11 @@ "description": "When set to true, a selection is immediately copied to your clipboard upon creation. When set to false, the selection persists and awaits further action.", "type": "boolean" }, + "focusFollowMouse": { + "default": false, + "description": "When set to true, the terminal will focus the pane on mouse hover.", + "type": "boolean" + }, "copyFormatting": { "default": true, "description": "When set to `true`, the color and font formatting of selected text is also copied to your clipboard. When set to `false`, only plain text is copied to your clipboard. An array of specific formats can also be used. Supported array values include `html` and `rtf`. Plain text is always copied.", From 939c912f6f7178523d459a231d660c14458a2952 Mon Sep 17 00:00:00 2001 From: khvitaly Date: Tue, 9 Feb 2021 23:37:09 +0200 Subject: [PATCH 4/4] Fix spelling in ffm tool tip --- .../TerminalSettingsEditor/Resources/en-US/Resources.resw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index c1cda12edf8..bb8ac02dc49 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -829,6 +829,6 @@ Enable Focus Follow Mouse mode - When checked, the terminal will focus pane on mouse hover. + When checked, the terminal will the focus pane on mouse hover.