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

Setting for hide window when it loses focus #13478

Merged
3 commits merged into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -1505,6 +1505,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 @@ -1392,6 +1393,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