Skip to content

Commit

Permalink
PRE-MERGE #14944 Add support for running the Terminal without _any_ w…
Browse files Browse the repository at this point in the history
…indows
  • Loading branch information
carlos-zamora committed Mar 3, 2023
2 parents dbdc672 + 4182742 commit 6a9254e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ namespace winrt::TerminalApp::implementation
return _settings.GlobalSettings().IsolatedMode();
}

bool AppLogic::AllowHeadless()
{
if (!_loadedInitialSettings)
{
// Load settings if we haven't already
ReloadSettings();
}
return _settings.GlobalSettings().AllowHeadless();
}

TerminalApp::TerminalWindow AppLogic::CreateNewWindow()
{
if (_settings == nullptr)
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 @@ -66,6 +66,7 @@ namespace winrt::TerminalApp::implementation

Microsoft::Terminal::Settings::Model::Theme Theme();
bool IsolatedMode();
bool AllowHeadless();

TerminalApp::TerminalWindow CreateNewWindow();

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 @@ -45,6 +45,7 @@ namespace TerminalApp

Microsoft.Terminal.Settings.Model.Theme Theme { get; };
Boolean IsolatedMode { get; };
Boolean AllowHeadless { get; };

FindTargetWindowResult FindTargetWindow(String[] args);

Expand Down
5 changes: 1 addition & 4 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// WHILE also making sure that upon re-saving the commands, we don't
// actually serialize the results of the expansion. I don't think it is.

auto warnings{ winrt::single_threaded_vector<SettingsLoadWarnings>() };

std::vector<Model::ColorScheme> sortedSchemes;
sortedSchemes.reserve(schemes.Size());

Expand All @@ -921,8 +919,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

Command::ExpandCommands(copyOfCommands,
profiles,
winrt::param::vector_view<Model::ColorScheme>{ sortedSchemes },
warnings);
winrt::param::vector_view<Model::ColorScheme>{ sortedSchemes });

_ExpandedMapCache = copyOfCommands;
}
Expand Down
21 changes: 9 additions & 12 deletions src/cascadia/TerminalSettingsModel/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// - <none>
void Command::ExpandCommands(IMap<winrt::hstring, Model::Command> commands,
IVectorView<Model::Profile> profiles,
IVectorView<Model::ColorScheme> schemes,
IVector<SettingsLoadWarnings> warnings)
IVectorView<Model::ColorScheme> schemes)
{
std::vector<winrt::hstring> commandsToRemove;
std::vector<Model::Command> commandsToAdd;
Expand All @@ -491,7 +490,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
auto cmd{ get_self<implementation::Command>(nameAndCmd.Value()) };

auto newCommands = _expandCommand(cmd, profiles, schemes, warnings);
auto newCommands = _expandCommand(cmd, profiles, schemes);
if (newCommands.size() > 0)
{
commandsToRemove.push_back(nameAndCmd.Key());
Expand Down Expand Up @@ -529,21 +528,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Arguments:
// - expandable: the Command to potentially turn into more commands
// - profiles: A list of all the profiles that this command should be expanded on.
// - warnings: If there were any warnings during parsing, they'll be
// appended to this vector.
// Return Value:
// - and empty vector if the command wasn't expandable, otherwise a list of
// the newly-created commands.
std::vector<Model::Command> Command::_expandCommand(Command* const expandable,
IVectorView<Model::Profile> profiles,
IVectorView<Model::ColorScheme> schemes,
IVector<SettingsLoadWarnings>& warnings)
IVectorView<Model::ColorScheme> schemes)
{
std::vector<Model::Command> newCommands;

if (expandable->HasNestedCommands())
{
ExpandCommands(expandable->_subcommands, profiles, schemes, warnings);
ExpandCommands(expandable->_subcommands, profiles, schemes);
}

if (expandable->_IterateOn == ExpandCommandType::None)
Expand All @@ -564,18 +560,19 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
const auto actualDataEnd = newJsonString.data() + newJsonString.size();
if (!reader->parse(actualDataStart, actualDataEnd, &newJsonValue, &errs))
{
warnings.Append(SettingsLoadWarnings::FailedToParseCommandJson);
// If we encounter a re-parsing error, just stop processing the rest of the commands.
return false;
}

// Pass the new json back though FromJson, to get the new expanded value.
std::vector<SettingsLoadWarnings> newWarnings;
if (auto newCmd{ Command::FromJson(newJsonValue, newWarnings) })
// FromJson requires that we pass in a vector to hang on to the
// warnings, but ultimately, we don't care about warnings during
// expansion.
std::vector<SettingsLoadWarnings> unused;
if (auto newCmd{ Command::FromJson(newJsonValue, unused) })
{
newCommands.push_back(*newCmd);
}
std::for_each(newWarnings.begin(), newWarnings.end(), [warnings](auto& warn) { warnings.Append(warn); });
return true;
};

Expand Down
6 changes: 2 additions & 4 deletions src/cascadia/TerminalSettingsModel/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

static void ExpandCommands(Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command> commands,
Windows::Foundation::Collections::IVectorView<Model::Profile> profiles,
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes,
Windows::Foundation::Collections::IVector<SettingsLoadWarnings> warnings);
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes);

static std::vector<SettingsLoadWarnings> LayerJson(Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command>& commands,
const Json::Value& json);
Expand Down Expand Up @@ -80,8 +79,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

static std::vector<Model::Command> _expandCommand(Command* const expandable,
Windows::Foundation::Collections::IVectorView<Model::Profile> profiles,
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes,
Windows::Foundation::Collections::IVector<SettingsLoadWarnings>& warnings);
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes);
friend class SettingsModelLocalTests::DeserializationTests;
friend class SettingsModelLocalTests::CommandTests;
};
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalSettingsModel/Command.idl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace Microsoft.Terminal.Settings.Model

static void ExpandCommands(Windows.Foundation.Collections.IMap<String, Command> commands,
Windows.Foundation.Collections.IVectorView<Profile> profiles,
Windows.Foundation.Collections.IVectorView<ColorScheme> schemes,
Windows.Foundation.Collections.IVector<SettingsLoadWarnings> warnings);
Windows.Foundation.Collections.IVectorView<ColorScheme> schemes);
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(IVector<NewTabMenuEntry>, NewTabMenu);
INHERITABLE_SETTING(Boolean, EnableColorSelection);
INHERITABLE_SETTING(Boolean, IsolatedMode);
INHERITABLE_SETTING(Boolean, AllowHeadless);

Windows.Foundation.Collections.IMapView<String, ColorScheme> ColorSchemes();
void AddColorScheme(ColorScheme scheme);
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 @@ -63,6 +63,7 @@ Author(s):
X(bool, TrimPaste, "trimPaste", true) \
X(bool, EnableColorSelection, "experimental.enableColorSelection", false) \
X(winrt::Windows::Foundation::Collections::IVector<Model::NewTabMenuEntry>, NewTabMenu, "newTabMenu", winrt::single_threaded_vector<Model::NewTabMenuEntry>({ Model::RemainingProfilesEntry{} })) \
X(bool, AllowHeadless, "compatibility.allowHeadless", true) \
X(bool, IsolatedMode, "compatibility.isolatedMode", false)

#define MTSM_PROFILE_SETTINGS(X) \
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co
}),
_windows.end());

if (_windows.size() == 0)
// When we run out of windows, exit our process if and only if:
// * We're not allowed to run headless OR
// * we've explicitly been told to "quit", which should fully exit the Terminal.
if (_windows.size() == 0 &&
(_quitting || !_app.Logic().AllowHeadless()))
{
_close();
}
Expand Down Expand Up @@ -232,6 +236,8 @@ void WindowEmperor::_numberOfWindowsChanged(const winrt::Windows::Foundation::II
void WindowEmperor::_quitAllRequested(const winrt::Windows::Foundation::IInspectable&,
const winrt::Microsoft::Terminal::Remoting::QuitAllRequestedArgs& args)
{
_quitting = true;

// Make sure that the current timer is destroyed so that it doesn't attempt
// to run while we are in the middle of quitting.
if (_getWindowLayoutThrottler.has_value())
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/WindowEmperor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class WindowEmperor
std::vector<winrt::Microsoft::Terminal::Settings::Model::GlobalSummonArgs> _hotkeys;

std::unique_ptr<NotificationIcon> _notificationIcon;
bool _quitting{ false };

void _becomeMonarch();
void _numberOfWindowsChanged(const winrt::Windows::Foundation::IInspectable&, const winrt::Windows::Foundation::IInspectable&);
Expand Down

0 comments on commit 6a9254e

Please sign in to comment.