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 "focus follows mouse" mode #8965

Merged
8 commits merged into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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 @@ -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<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 @@ -1367,6 +1367,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>
Don-Vito marked this conversation as resolved.
Show resolved Hide resolved
</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 focus pane on mouse hover.</value>
Don-Vito marked this conversation as resolved.
Show resolved Hide resolved
</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