diff --git a/doc/cascadia/SettingsSchema.md b/doc/cascadia/SettingsSchema.md index a82977b6e8..0a41c6964b 100644 --- a/doc/cascadia/SettingsSchema.md +++ b/doc/cascadia/SettingsSchema.md @@ -47,6 +47,7 @@ Properties listed below are specific to each unique profile. | `snapOnInput` | Optional | Boolean | `true` | When set to `true`, the window will scroll to the command input line when typing. When set to `false`, the window will not scroll when you start typing. | | `source` | Optional | String | | Stores the name of the profile generator that originated this profile. _There are no discoverable values for this field._ | | `startingDirectory` | Optional | String | `%USERPROFILE%` | The directory the shell starts in when it is loaded. | +| `suppressApplicationTitle` | Optional | Boolean | | When set to `true`, `tabTitle` overrides the default title of the tab and any title change messages from the application will be suppressed. When set to `false`, `tabTitle` behaves as normal. | | `tabTitle` | Optional | String | | If set, will replace the `name` as the title to pass to the shell on startup. Some shells (like `bash`) may choose to ignore this initial value, while others (`cmd`, `powershell`) may use this value over the lifetime of the application. | | `useAcrylic` | Optional | Boolean | `false` | When set to `true`, the window will have an acrylic background. When set to `false`, the window will have a plain, untextured background. | diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 9f4b52fa4c..8c7ab820e8 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -520,6 +520,10 @@ "description": "The directory the shell starts in when it is loaded.", "type": "string" }, + "suppressApplicationTitle": { + "description": "When set to `true`, `tabTitle` overrides the default title of the tab and any title change messages from the application will be suppressed. When set to `false`, `tabTitle` behaves as normal.", + "type": "boolean" + }, "tabTitle": { "description": "If set, will replace the name as the title to pass to the shell on startup. Some shells (like bash) may choose to ignore this initial value, while others (cmd, powershell) may use this value over the lifetime of the application.", "type": "string" diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index 70165a87c5..1aee85c918 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -27,6 +27,7 @@ static constexpr std::string_view BackgroundKey{ "background" }; static constexpr std::string_view SelectionBackgroundKey{ "selectionBackground" }; static constexpr std::string_view ColorTableKey{ "colorTable" }; static constexpr std::string_view TabTitleKey{ "tabTitle" }; +static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" }; static constexpr std::string_view HistorySizeKey{ "historySize" }; static constexpr std::string_view SnapOnInputKey{ "snapOnInput" }; static constexpr std::string_view CursorColorKey{ "cursorColor" }; @@ -93,6 +94,7 @@ Profile::Profile(const std::optional& guid) : _selectionBackground{}, _colorTable{}, _tabTitle{}, + _suppressApplicationTitle{}, _historySize{ DEFAULT_HISTORY_SIZE }, _snapOnInput{ true }, _cursorColor{ DEFAULT_CURSOR_COLOR }, @@ -187,6 +189,11 @@ TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map schemeName) noexcept; std::optional& GetSchemeName() noexcept; void SetTabTitle(std::wstring tabTitle) noexcept; + void SetSuppressApplicationTitle(bool suppressApplicationTitle) noexcept; void SetAcrylicOpacity(double opacity) noexcept; void SetCommandline(std::wstring cmdline) noexcept; void SetStartingDirectory(std::wstring startingDirectory) noexcept; @@ -86,6 +87,7 @@ public: winrt::hstring GetExpandedBackgroundImagePath() const; bool GetCloseOnExit() const noexcept; + bool GetSuppressApplicationTitle() const noexcept; bool IsHidden() const noexcept; void GenerateGuidIfNecessary() noexcept; @@ -122,6 +124,7 @@ private: std::optional _selectionBackground; std::array _colorTable; std::optional _tabTitle; + bool _suppressApplicationTitle; int32_t _historySize; bool _snapOnInput; uint32_t _cursorColor; diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 845dad723b..3480434192 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -139,6 +139,10 @@ void Terminal::UpdateSettings(winrt::Microsoft::Terminal::Settings::ICoreSetting _copyOnSelect = settings.CopyOnSelect(); + _suppressApplicationTitle = settings.SuppressApplicationTitle(); + + _startingTitle = settings.StartingTitle(); + // TODO:MSFT:21327402 - if HistorySize has changed, resize the buffer so we // have a smaller scrollback. We should do this carefully - if the new buffer // size is smaller than where the mutable viewport currently is, we'll want diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index a57744d74c..02858dc59c 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -162,12 +162,14 @@ private: std::unique_ptr<::Microsoft::Console::VirtualTerminal::TerminalInput> _terminalInput; std::wstring _title; + std::wstring _startingTitle; std::array _colorTable; COLORREF _defaultFg; COLORREF _defaultBg; bool _snapOnInput; + bool _suppressApplicationTitle; #pragma region Text Selection enum class SelectionExpansionMode diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 001b62690d..5876d5d3be 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -365,11 +365,24 @@ bool Terminal::EraseInDisplay(const DispatchTypes::EraseType eraseType) bool Terminal::SetWindowTitle(std::wstring_view title) { + // Set the title on Terminal load + if (_title.empty()) + { + _title = title; + _pfnTitleChanged(title); + } + _title = title; - if (_pfnTitleChanged) + // If this is removed, the tab object assumes the application title is the title + if (_suppressApplicationTitle) { - _pfnTitleChanged(title); + _title = _startingTitle; + } + + if (_pfnTitleChanged && !_suppressApplicationTitle) + { + _pfnTitleChanged(_title); } return true; diff --git a/src/cascadia/TerminalSettings/IControlSettings.idl b/src/cascadia/TerminalSettings/IControlSettings.idl index 03de440714..fad4f3435c 100644 --- a/src/cascadia/TerminalSettings/IControlSettings.idl +++ b/src/cascadia/TerminalSettings/IControlSettings.idl @@ -32,7 +32,6 @@ namespace Microsoft.Terminal.Settings String Commandline; String StartingDirectory; - String StartingTitle; String EnvironmentVariables; String BackgroundImage; diff --git a/src/cascadia/TerminalSettings/ICoreSettings.idl b/src/cascadia/TerminalSettings/ICoreSettings.idl index b715bd7086..7eb1f392f5 100644 --- a/src/cascadia/TerminalSettings/ICoreSettings.idl +++ b/src/cascadia/TerminalSettings/ICoreSettings.idl @@ -27,6 +27,8 @@ namespace Microsoft.Terminal.Settings UInt32 CursorColor; CursorStyle CursorShape; UInt32 CursorHeight; + String StartingTitle; + Boolean SuppressApplicationTitle; String WordDelimiters; Boolean CopyOnSelect; }; diff --git a/src/cascadia/TerminalSettings/TerminalSettings.cpp b/src/cascadia/TerminalSettings/TerminalSettings.cpp index ff13952ad6..06d3a778e6 100644 --- a/src/cascadia/TerminalSettings/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettings/TerminalSettings.cpp @@ -321,6 +321,16 @@ namespace winrt::Microsoft::Terminal::Settings::implementation _startingTitle = value; } + bool TerminalSettings::SuppressApplicationTitle() + { + return _suppressApplicationTitle; + } + + void TerminalSettings::SuppressApplicationTitle(bool value) + { + _suppressApplicationTitle = value; + } + hstring TerminalSettings::EnvironmentVariables() { return _envVars; diff --git a/src/cascadia/TerminalSettings/terminalsettings.h b/src/cascadia/TerminalSettings/terminalsettings.h index ecc2781a46..b672f6a940 100644 --- a/src/cascadia/TerminalSettings/terminalsettings.h +++ b/src/cascadia/TerminalSettings/terminalsettings.h @@ -90,6 +90,9 @@ namespace winrt::Microsoft::Terminal::Settings::implementation hstring StartingTitle(); void StartingTitle(hstring const& value); + bool SuppressApplicationTitle(); + void SuppressApplicationTitle(bool value); + hstring EnvironmentVariables(); void EnvironmentVariables(hstring const& value); @@ -125,6 +128,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation hstring _commandline; hstring _startingDir; hstring _startingTitle; + bool _suppressApplicationTitle; hstring _envVars; Settings::IKeyBindings _keyBindings; Settings::ScrollbarState _scrollbarState; diff --git a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h index 4b624189b0..f5490727cf 100644 --- a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h +++ b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h @@ -33,6 +33,8 @@ namespace TerminalCoreUnitTests uint32_t CursorHeight() { return 42UL; } winrt::hstring WordDelimiters() { return winrt::to_hstring(DEFAULT_WORD_DELIMITERS.c_str()); } bool CopyOnSelect() { return _copyOnSelect; } + winrt::hstring StartingTitle() { return _startingTitle; } + bool SuppressApplicationTitle() { return _suppressApplicationTitle; } uint32_t SelectionBackground() { return COLOR_WHITE; } // other implemented methods @@ -50,6 +52,8 @@ namespace TerminalCoreUnitTests void CursorHeight(uint32_t) {} void WordDelimiters(winrt::hstring) {} void CopyOnSelect(bool copyOnSelect) { _copyOnSelect = copyOnSelect; } + void StartingTitle(winrt::hstring const& value) { _startingTitle = value; } + void SuppressApplicationTitle(bool suppressApplicationTitle) { _suppressApplicationTitle = suppressApplicationTitle; } void SelectionBackground(uint32_t) {} // other unimplemented methods @@ -60,5 +64,7 @@ namespace TerminalCoreUnitTests int32_t _initialRows; int32_t _initialCols; bool _copyOnSelect{ false }; + bool _suppressApplicationTitle{ false }; + winrt::hstring _startingTitle; }; }