Skip to content

Commit

Permalink
Add support for "focus follows mouse" mode (#8965)
Browse files Browse the repository at this point in the history
## PR Checklist
* [x] Closes #6459
* [x] CLA signed.
* [ ] Tests added/passed
* [x] Documentation updated here: MicrosoftDocs/terminal#248
* [x] Schema updated.
* [x] I've discussed this with core contributors already.
  • Loading branch information
Don-Vito authored Feb 9, 2021
1 parent 6af49a5 commit 47f4b41
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ namespace winrt::TerminalApp::implementation

_WordDelimiters = globalSettings.WordDelimiters();
_CopyOnSelect = globalSettings.CopyOnSelect();
_FocusFollowMouse = globalSettings.FocusFollowMouse();
_ForceFullRepaintRendering = globalSettings.ForceFullRepaintRendering();
_SoftwareRendering = globalSettings.SoftwareRendering();
_ForceVTInput = globalSettings.ForceVTInput();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace winrt::TerminalApp::implementation
GETSET_SETTING(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT);
GETSET_SETTING(hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS);
GETSET_SETTING(bool, CopyOnSelect, false);
GETSET_SETTING(bool, FocusFollowMouse, false);

GETSET_SETTING(Windows::Foundation::IReference<uint32_t>, TabColor, nullptr);

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Microsoft.Terminal.TerminalControl
Microsoft.Terminal.TerminalControl.IKeyBindings KeyBindings;

Boolean CopyOnSelect;
Boolean FocusFollowMouse;

String Commandline;
String StartingDirectory;
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
const auto cursorPosition = point.Position();
const auto terminalPosition = _GetTerminalPosition(cursorPosition);

if (!_focused && _settings.FocusFollowMouse())
{
Focus(FocusState::Pointer);
}

if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse || ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Pen)
{
if (_focused && _CanSendVTMouseInput())
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Interaction.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ the MIT License. See LICENSE in the project root for license information. -->
ItemsSource="{x:Bind TabSwitcherModeList}"
ItemTemplate="{StaticResource EnumRadioButtonTemplate}"/>
</local:SettingContainer>

<!-- Focus Follow Mouse Mode-->
<local:SettingContainer x:Uid="Globals_FocusFollowMouse">
<ToggleSwitch IsOn="{x:Bind State.Globals.FocusFollowMouse, Mode=TwoWay}"/>
</local:SettingContainer>
</StackPanel>
</ScrollViewer>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -825,4 +825,10 @@
<value>a lower layer</value>
<comment>This is the object of "SettingContainer_OverrideIntro".</comment>
</data>
<data name="Globals_FocusFollowMouse.Header" xml:space="preserve">
<value>Enable Focus Follow Mouse mode</value>
</data>
<data name="Globals_FocusFollowMouse.HelpText" xml:space="preserve">
<value>When checked, the terminal will the focus pane on mouse hover.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };

Expand Down Expand Up @@ -116,6 +117,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
globals->_TabSwitcherMode = _TabSwitcherMode;
globals->_DisableAnimations = _DisableAnimations;
globals->_StartupActions = _StartupActions;
globals->_FocusFollowMouse = _FocusFollowMouse;

globals->_UnparsedDefaultProfile = _UnparsedDefaultProfile;
globals->_validDefaultProfile = _validDefaultProfile;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,9 @@ namespace Microsoft.Terminal.Settings.Model
Boolean HasStartupActions();
void ClearStartupActions();
String StartupActions();

Boolean HasFocusFollowMouse();
void ClearFocusFollowMouse();
Boolean FocusFollowMouse;
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"snapToGridOnResize": true,
"disableAnimations": false,
"startupActions": "",
"focusFollowMouse": false,

"profiles":
[
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/UnitTests_TerminalCore/MockTermSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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) {}
Expand All @@ -69,6 +71,7 @@ namespace TerminalCoreUnitTests
int32_t _initialRows;
int32_t _initialCols;
bool _copyOnSelect{ false };
bool _focusFollowMouse{ false };
bool _suppressApplicationTitle{ false };
winrt::hstring _startingTitle;
};
Expand Down

0 comments on commit 47f4b41

Please sign in to comment.