Skip to content

Commit

Permalink
Setting for hide window when it loses focus (#13478)
Browse files Browse the repository at this point in the history
<!-- 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
  • Loading branch information
davidegiacometti authored Jul 14, 2022
1 parent dc161d8 commit 56016c9
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace winrt::TerminalApp::implementation
bool Fullscreen() const;
void Maximized(bool newMaximized);
bool AlwaysOnTop() const;
bool AutoHideWindow();

bool ShouldUsePersistedLayout();
bool ShouldImmediatelyHandoffToElevated();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace TerminalApp
Boolean Fullscreen { get; };
void Maximized(Boolean newMaximized);
Boolean AlwaysOnTop { get; };
Boolean AutoHideWindow { get; };

void IdentifyWindow();
String WindowName;
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"") \
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ AppHost::AppHost() noexcept :
_window->ShouldExitFullscreen({ &_logic, &winrt::TerminalApp::AppLogic::RequestExitFullscreen });

_window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop());
_window->SetAutoHideWindow(_logic.AutoHideWindow());

_window->MakeWindow();

Expand Down Expand Up @@ -1393,6 +1394,7 @@ void AppHost::_HandleSettingsChanged(const winrt::Windows::Foundation::IInspecta
}

_window->SetMinimizeToNotificationAreaBehavior(_logic.GetMinimizeToNotificationArea());
_window->SetAutoHideWindow(_logic.AutoHideWindow());
_updateTheme();
}

Expand Down
17 changes: 17 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class IslandWindow :

bool IsQuakeWindow() const noexcept;
void IsQuakeWindow(bool isQuakeWindow) noexcept;
void SetAutoHideWindow(bool autoHideWindow) noexcept;

void HideWindow();

Expand Down Expand Up @@ -135,6 +136,7 @@ class IslandWindow :
void _moveToMonitor(const MONITORINFO activeMonitor);

bool _isQuakeWindow{ false };
bool _autoHideWindow{ false };

void _enterQuakeMode();
til::rect _getQuakeModeSize(HMONITOR hmon);
Expand Down

0 comments on commit 56016c9

Please sign in to comment.