Setting for hide window when it loses focus (#13478)

<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Added setting for for hide window when it loses focus.
Works on normal window and quake window.

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> 
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #10660
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

- Enable **Settings > Appearance > Automatically hide window**
- Terminal window should be minimized on taskbar when it loses focus
- Quake window should be minimized on system tray when it loses focus
- Enable also **Settings > Appearance > Hide Terminal in the notification area when it is minimized**
- Terminal window should be minimized on system tray when it loses focus
- Quake window should be minimized on system tray when it loses focus
This commit is contained in:
Davide Giacometti 2022-07-14 13:32:54 +02:00 committed by GitHub
parent dc161d8018
commit 56016c92f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 58 additions and 2 deletions

View File

@ -1968,6 +1968,11 @@
"useAnyExisting"
],
"type": "string"
},
"autoHideWindow": {
"default": false,
"description": "If enabled, Terminal window will be hidden as soon as it loses focus.",
"type": "boolean"
}
},
"required": [

View File

@ -1500,6 +1500,17 @@ namespace winrt::TerminalApp::implementation
return _root ? _root->AlwaysOnTop() : false;
}
bool AppLogic::AutoHideWindow()
{
if (!_loadedInitialSettings)
{
// Load settings if we haven't already
LoadSettings();
}
return _settings.GlobalSettings().AutoHideWindow();
}
Windows::Foundation::Collections::IMapView<Microsoft::Terminal::Control::KeyChord, Microsoft::Terminal::Settings::Model::Command> AppLogic::GlobalHotkeys()
{
return _settings.GlobalSettings().ActionMap().GlobalHotkeys();

View File

@ -79,6 +79,7 @@ namespace winrt::TerminalApp::implementation
bool Fullscreen() const;
void Maximized(bool newMaximized);
bool AlwaysOnTop() const;
bool AutoHideWindow();
bool ShouldUsePersistedLayout();
bool ShouldImmediatelyHandoffToElevated();

View File

@ -70,6 +70,7 @@ namespace TerminalApp
Boolean Fullscreen { get; };
void Maximized(Boolean newMaximized);
Boolean AlwaysOnTop { get; };
Boolean AutoHideWindow { get; };
void IdentifyWindow();
String WindowName;

View File

@ -120,6 +120,12 @@
<ToggleSwitch IsOn="{x:Bind ViewModel.MinimizeToNotificationArea, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Automatically hide window -->
<local:SettingContainer x:Uid="Globals_AutoHideWindow">
<ToggleSwitch IsOn="{x:Bind ViewModel.AutoHideWindow, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</StackPanel>
</ScrollViewer>
</Page>

View File

@ -42,6 +42,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, UseAcrylicInTabRow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, ShowTitleInTitlebar);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, AlwaysOnTop);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, AutoHideWindow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, AlwaysShowNotificationIcon);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, MinimizeToNotificationArea);

View File

@ -33,6 +33,7 @@ namespace Microsoft.Terminal.Settings.Editor
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, UseAcrylicInTabRow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, ShowTitleInTitlebar);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, AlwaysOnTop);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, AutoHideWindow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, AlwaysShowNotificationIcon);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, MinimizeToNotificationArea);
}

View File

@ -317,7 +317,6 @@
</data>
<data name="Globals_FirstWindowPreference.HelpText" xml:space="preserve">
<value>What should be shown when the first terminal is created.</value>
<comment></comment>
</data>
<data name="Globals_FirstWindowPreferenceDefaultProfile.Content" xml:space="preserve">
<value>Open a tab with the default profile</value>
@ -1450,4 +1449,12 @@
<value>Bold font with bright colors</value>
<comment>An option to choose from for the "intense text format" setting. When selected, "intense" text will be rendered as both bold text and in a brighter color</comment>
</data>
</root>
<data name="Globals_AutoHideWindow.Header" xml:space="preserve">
<value>Automatically hide window</value>
<comment>Header for a control to toggle the "Automatically hide window" setting. If enabled, the window will be hidden as soon as it loses focus.</comment>
</data>
<data name="Globals_AutoHideWindow.HelpText" xml:space="preserve">
<value>If enabled, the window will be hidden as soon as it loses focus.</value>
<comment>A description for what the "Automatically hide window" setting does.</comment>
</data>
</root>

View File

@ -82,6 +82,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(Boolean, DebugFeaturesEnabled);
INHERITABLE_SETTING(Boolean, StartOnUserLogin);
INHERITABLE_SETTING(Boolean, AlwaysOnTop);
INHERITABLE_SETTING(Boolean, AutoHideWindow);
INHERITABLE_SETTING(TabSwitcherMode, TabSwitcherMode);
INHERITABLE_SETTING(Boolean, DisableAnimations);
INHERITABLE_SETTING(String, StartupActions);

View File

@ -51,6 +51,7 @@ Author(s):
X(bool, DebugFeaturesEnabled, "debugFeatures", debugFeaturesDefault) \
X(bool, StartOnUserLogin, "startOnUserLogin", false) \
X(bool, AlwaysOnTop, "alwaysOnTop", false) \
X(bool, AutoHideWindow, "autoHideWindow", false) \
X(Model::TabSwitcherMode, TabSwitcherMode, "tabSwitcherMode", Model::TabSwitcherMode::InOrder) \
X(bool, DisableAnimations, "disableAnimations", false) \
X(hstring, StartupActions, "startupActions", L"") \

View File

@ -103,6 +103,7 @@ AppHost::AppHost() noexcept :
_window->ShouldExitFullscreen({ &_logic, &winrt::TerminalApp::AppLogic::RequestExitFullscreen });
_window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop());
_window->SetAutoHideWindow(_logic.AutoHideWindow());
_window->MakeWindow();
@ -1393,6 +1394,7 @@ void AppHost::_HandleSettingsChanged(const winrt::Windows::Foundation::IInspecta
}
_window->SetMinimizeToNotificationAreaBehavior(_logic.GetMinimizeToNotificationArea());
_window->SetAutoHideWindow(_logic.AutoHideWindow());
_updateTheme();
}

View File

@ -442,6 +442,18 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
const bool activated = LOWORD(wparam) != 0;
_WindowActivatedHandlers(activated);
if (_autoHideWindow && !activated)
{
if (_isQuakeWindow || _minimizeToNotificationArea)
{
HideWindow();
}
else
{
ShowWindow(GetHandle(), SW_MINIMIZE);
}
}
break;
}
@ -1626,6 +1638,11 @@ void IslandWindow::IsQuakeWindow(bool isQuakeWindow) noexcept
}
}
void IslandWindow::SetAutoHideWindow(bool autoHideWindow) noexcept
{
_autoHideWindow = autoHideWindow;
}
// Method Description:
// - Enter quake mode for the monitor this window is currently on. This involves
// resizing it to the top half of the monitor.

View File

@ -55,6 +55,7 @@ public:
bool IsQuakeWindow() const noexcept;
void IsQuakeWindow(bool isQuakeWindow) noexcept;
void SetAutoHideWindow(bool autoHideWindow) noexcept;
void HideWindow();
@ -135,6 +136,7 @@ protected:
void _moveToMonitor(const MONITORINFO activeMonitor);
bool _isQuakeWindow{ false };
bool _autoHideWindow{ false };
void _enterQuakeMode();
til::rect _getQuakeModeSize(HMONITOR hmon);