diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp
index 138d4a7d24..1a22cfc5b3 100644
--- a/src/cascadia/TerminalApp/App.cpp
+++ b/src/cascadia/TerminalApp/App.cpp
@@ -77,22 +77,24 @@ namespace winrt::TerminalApp::implementation
/// Details about the launch request and process.
void App::OnLaunched(const LaunchActivatedEventArgs& /*e*/)
{
+ // TODO! UWP mode is straight up not supported anymore, yea?
+ //
// if this is a UWP... it means its our problem to hook up the content to the window here.
- if (_isUwp)
- {
- auto content = Window::Current().Content();
- if (content == nullptr)
- {
- auto logic = Logic();
- logic.RunAsUwp(); // Must set UWP status first, settings might change based on it.
- logic.ReloadSettings();
- logic.Create();
+ //if (_isUwp)
+ //{
+ // auto content = Window::Current().Content();
+ // if (content == nullptr)
+ // {
+ // auto logic = Logic();
+ // logic.RunAsUwp(); // Must set UWP status first, settings might change based on it.
+ // logic.ReloadSettings();
+ // logic.Create();
- auto page = logic.GetRoot().as();
+ // auto page = logic.GetRoot().as();
- Window::Current().Content(page);
- Window::Current().Activate();
- }
- }
+ // Window::Current().Content(page);
+ // Window::Current().Activate();
+ // }
+ //}
}
}
diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp
index 4381e24e0b..ad77ccdc3c 100644
--- a/src/cascadia/TerminalApp/AppLogic.cpp
+++ b/src/cascadia/TerminalApp/AppLogic.cpp
@@ -6,7 +6,6 @@
#include "../inc/WindowingBehavior.h"
#include "AppLogic.g.cpp"
#include "FindTargetWindowResult.g.cpp"
-#include
#include
#include
@@ -31,49 +30,14 @@ namespace winrt
using IInspectable = Windows::Foundation::IInspectable;
}
-static constexpr std::wstring_view StartupTaskName = L"StartTerminalOnLoginTask";
+////////////////////////////////////////////////////////////////////////////////
+// TODO! This section probably should be in TerminalWindow with the warnings
+
// clang-format off
-// !!! IMPORTANT !!!
-// Make sure that these keys are in the same order as the
-// SettingsLoadWarnings/Errors enum is!
-static const std::array settingsLoadWarningsLabels {
- USES_RESOURCE(L"MissingDefaultProfileText"),
- USES_RESOURCE(L"DuplicateProfileText"),
- USES_RESOURCE(L"UnknownColorSchemeText"),
- USES_RESOURCE(L"InvalidBackgroundImage"),
- USES_RESOURCE(L"InvalidIcon"),
- USES_RESOURCE(L"AtLeastOneKeybindingWarning"),
- USES_RESOURCE(L"TooManyKeysForChord"),
- USES_RESOURCE(L"MissingRequiredParameter"),
- USES_RESOURCE(L"FailedToParseCommandJson"),
- USES_RESOURCE(L"FailedToWriteToSettings"),
- USES_RESOURCE(L"InvalidColorSchemeInCmd"),
- USES_RESOURCE(L"InvalidSplitSize"),
- USES_RESOURCE(L"FailedToParseStartupActions"),
- USES_RESOURCE(L"FailedToParseSubCommands"),
- USES_RESOURCE(L"UnknownTheme"),
- USES_RESOURCE(L"DuplicateRemainingProfilesEntry"),
-};
static const std::array settingsLoadErrorsLabels {
USES_RESOURCE(L"NoProfilesText"),
USES_RESOURCE(L"AllProfilesHiddenText")
};
-// clang-format on
-
-static_assert(settingsLoadWarningsLabels.size() == static_cast(SettingsLoadWarnings::WARNINGS_SIZE));
-static_assert(settingsLoadErrorsLabels.size() == static_cast(SettingsLoadErrors::ERRORS_SIZE));
-
-// Function Description:
-// - General-purpose helper for looking up a localized string for a
-// warning/error. First will look for the given key in the provided map of
-// keys->strings, where the values in the map are ResourceKeys. If it finds
-// one, it will lookup the localized string from that ResourceKey.
-// - If it does not find a key, it'll return an empty string
-// Arguments:
-// - key: the value to use to look for a resource key in the given map
-// - map: A map of keys->Resource keys.
-// Return Value:
-// - the localized string for the given type, if it exists.
template
winrt::hstring _GetMessageText(uint32_t index, const T& keys)
{
@@ -83,20 +47,6 @@ winrt::hstring _GetMessageText(uint32_t index, const T& keys)
}
return {};
}
-
-// Function Description:
-// - Gets the text from our ResourceDictionary for the given
-// SettingsLoadWarning. If there is no such text, we'll return nullptr.
-// - The warning should have an entry in settingsLoadWarningsLabels.
-// Arguments:
-// - warning: the SettingsLoadWarnings value to get the localized text for.
-// Return Value:
-// - localized text for the given warning
-static winrt::hstring _GetWarningText(SettingsLoadWarnings warning)
-{
- return _GetMessageText(static_cast(warning), settingsLoadWarningsLabels);
-}
-
// Function Description:
// - Gets the text from our ResourceDictionary for the given
// SettingsLoadError. If there is no such text, we'll return nullptr.
@@ -110,30 +60,11 @@ static winrt::hstring _GetErrorText(SettingsLoadErrors error)
return _GetMessageText(static_cast(error), settingsLoadErrorsLabels);
}
-// Function Description:
-// - Creates a Run of text to display an error message. The text is yellow or
-// red for dark/light theme, respectively.
-// Arguments:
-// - text: The text of the error message.
-// - resources: The application's resource loader.
-// Return Value:
-// - The fully styled text run.
-static Documents::Run _BuildErrorRun(const winrt::hstring& text, const ResourceDictionary& resources)
-{
- Documents::Run textRun;
- textRun.Text(text);
+// clang-format on
- // Color the text red (light theme) or yellow (dark theme) based on the system theme
- auto key = winrt::box_value(L"ErrorTextBrush");
- if (resources.HasKey(key))
- {
- auto g = resources.Lookup(key);
- auto brush = g.try_as();
- textRun.Foreground(brush);
- }
+////////////////////////////////////////////////////////////////////////////////
- return textRun;
-}
+static constexpr std::wstring_view StartupTaskName = L"StartTerminalOnLoginTask";
namespace winrt::TerminalApp::implementation
{
@@ -187,7 +118,6 @@ namespace winrt::TerminalApp::implementation
// make sure that there's a terminal page for callers of
// SetTitleBarContent
_isElevated = ::Microsoft::Console::Utils::IsElevated();
- _root = winrt::make_self();
_reloadSettings = std::make_shared>(winrt::Windows::System::DispatcherQueue::GetForCurrentThread(), std::chrono::milliseconds(100), [weakSelf = get_weak()]() {
if (auto self{ weakSelf.get() })
@@ -201,13 +131,6 @@ namespace winrt::TerminalApp::implementation
});
}
- // Method Description:
- // - Implements the IInitializeWithWindow interface from shobjidl_core.
- HRESULT AppLogic::Initialize(HWND hwnd)
- {
- return _root->Initialize(hwnd);
- }
-
// Method Description:
// - Called around the codebase to discover if this is a UWP where we need to turn off specific settings.
// Arguments:
@@ -257,8 +180,6 @@ namespace winrt::TerminalApp::implementation
// this as a MTA, before the app is Create()'d
WINRT_ASSERT(_loadedInitialSettings);
- _root->DialogPresenter(*this);
-
// In UWP mode, we cannot handle taking over the title bar for tabs,
// so this setting is overridden to false no matter what the preference is.
if (_isUwp)
@@ -266,39 +187,8 @@ namespace winrt::TerminalApp::implementation
_settings.GlobalSettings().ShowTabsInTitlebar(false);
}
- // Pay attention, that even if some command line arguments were parsed (like launch mode),
- // we will not use the startup actions from settings.
- // While this simplifies the logic, we might want to reconsider this behavior in the future.
- if (!_hasCommandLineArguments && _hasSettingsStartupActions)
+ // TODO! These used to be in `_root->Initialized`. Where do they belong now?
{
- _root->SetStartupActions(_settingsAppArgs.GetStartupActions());
- }
-
- _root->SetSettings(_settings, false);
- _root->Loaded({ this, &AppLogic::_OnLoaded });
- _root->Initialized([this](auto&&, auto&&) {
- // GH#288 - When we finish initialization, if the user wanted us
- // launched _fullscreen_, toggle fullscreen mode. This will make sure
- // that the window size is _first_ set up as something sensible, so
- // leaving fullscreen returns to a reasonable size.
- const auto launchMode = this->GetLaunchMode();
- if (IsQuakeWindow() || WI_IsFlagSet(launchMode, LaunchMode::FocusMode))
- {
- _root->SetFocusMode(true);
- }
-
- // The IslandWindow handles (creating) the maximized state
- // we just want to record it here on the page as well.
- if (WI_IsFlagSet(launchMode, LaunchMode::MaximizedMode))
- {
- _root->Maximized(true);
- }
-
- if (WI_IsFlagSet(launchMode, LaunchMode::FullscreenMode) && !IsQuakeWindow())
- {
- _root->SetFullscreen(true);
- }
-
// Both LoadSettings and ReloadSettings are supposed to call this function,
// but LoadSettings skips it, so that the UI starts up faster.
// Now that the UI is present we can do them with a less significant UX impact.
@@ -329,16 +219,11 @@ namespace winrt::TerminalApp::implementation
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
- });
- _root->Create();
+ };
_ApplyLanguageSettingChange();
- _RefreshThemeRoutine();
_ApplyStartupTaskStateChange();
- auto args = winrt::make_self(RS_(L"SettingsMenuItem"), SystemMenuChangeAction::Add, SystemMenuItemHandler(this, &AppLogic::_OpenSettingsUI));
- _SystemMenuChangeRequestedHandlers(*this, *args);
-
TraceLoggingWrite(
g_hTerminalAppProvider,
"AppCreated",
@@ -348,459 +233,6 @@ namespace winrt::TerminalApp::implementation
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
- void AppLogic::Quit()
- {
- if (_root)
- {
- _root->CloseWindow(true);
- }
- }
-
- // Method Description:
- // - Show a ContentDialog with buttons to take further action. Uses the
- // FrameworkElements provided as the title and content of this dialog, and
- // displays buttons (or a single button). Two buttons (primary and secondary)
- // will be displayed if this is an warning dialog for closing the terminal,
- // this allows the users to abandon the closing action. Otherwise, a single
- // close button will be displayed.
- // - Only one dialog can be visible at a time. If another dialog is visible
- // when this is called, nothing happens.
- // Arguments:
- // - dialog: the dialog object that is going to show up
- // Return value:
- // - an IAsyncOperation with the dialog result
- winrt::Windows::Foundation::IAsyncOperation AppLogic::ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog)
- {
- // DON'T release this lock in a wil::scope_exit. The scope_exit will get
- // called when we await, which is not what we want.
- std::unique_lock lock{ _dialogLock, std::try_to_lock };
- if (!lock)
- {
- // Another dialog is visible.
- co_return ContentDialogResult::None;
- }
-
- _dialog = dialog;
-
- // IMPORTANT: This is necessary as documented in the ContentDialog MSDN docs.
- // Since we're hosting the dialog in a Xaml island, we need to connect it to the
- // xaml tree somehow.
- dialog.XamlRoot(_root->XamlRoot());
-
- // IMPORTANT: Set the requested theme of the dialog, because the
- // PopupRoot isn't directly in the Xaml tree of our root. So the dialog
- // won't inherit our RequestedTheme automagically.
- // GH#5195, GH#3654 Because we cannot set RequestedTheme at the application level,
- // we occasionally run into issues where parts of our UI end up themed incorrectly.
- // Dialogs, for example, live under a different Xaml root element than the rest of
- // our application. This makes our popup menus and buttons "disappear" when the
- // user wants Terminal to be in a different theme than the rest of the system.
- // This hack---and it _is_ a hack--walks up a dialog's ancestry and forces the
- // theme on each element up to the root. We're relying a bit on Xaml's implementation
- // details here, but it does have the desired effect.
- // It's not enough to set the theme on the dialog alone.
- auto themingLambda{ [this](const Windows::Foundation::IInspectable& sender, const RoutedEventArgs&) {
- auto theme{ _settings.GlobalSettings().CurrentTheme() };
- auto requestedTheme{ theme.RequestedTheme() };
- auto element{ sender.try_as() };
- while (element)
- {
- element.RequestedTheme(requestedTheme);
- element = element.Parent().try_as();
- }
- } };
-
- themingLambda(dialog, nullptr); // if it's already in the tree
- auto loadedRevoker{ dialog.Loaded(winrt::auto_revoke, themingLambda) }; // if it's not yet in the tree
-
- // Display the dialog.
- co_return co_await dialog.ShowAsync(Controls::ContentDialogPlacement::Popup);
-
- // After the dialog is dismissed, the dialog lock (held by `lock`) will
- // be released so another can be shown
- }
-
- // Method Description:
- // - Dismiss the (only) visible ContentDialog
- void AppLogic::DismissDialog()
- {
- if (auto localDialog = std::exchange(_dialog, nullptr))
- {
- localDialog.Hide();
- }
- }
-
- // Method Description:
- // - Displays a dialog for errors found while loading or validating the
- // settings. Uses the resources under the provided title and content keys
- // as the title and first content of the dialog, then also displays a
- // message for whatever exception was found while validating the settings.
- // - Only one dialog can be visible at a time. If another dialog is visible
- // when this is called, nothing happens. See ShowDialog for details
- // Arguments:
- // - titleKey: The key to use to lookup the title text from our resources.
- // - contentKey: The key to use to lookup the content text from our resources.
- void AppLogic::_ShowLoadErrorsDialog(const winrt::hstring& titleKey,
- const winrt::hstring& contentKey,
- HRESULT settingsLoadedResult)
- {
- auto title = GetLibraryResourceString(titleKey);
- auto buttonText = RS_(L"Ok");
-
- Controls::TextBlock warningsTextBlock;
- // Make sure you can copy-paste
- warningsTextBlock.IsTextSelectionEnabled(true);
- // Make sure the lines of text wrap
- warningsTextBlock.TextWrapping(TextWrapping::Wrap);
-
- winrt::Windows::UI::Xaml::Documents::Run errorRun;
- const auto errorLabel = GetLibraryResourceString(contentKey);
- errorRun.Text(errorLabel);
- warningsTextBlock.Inlines().Append(errorRun);
- warningsTextBlock.Inlines().Append(Documents::LineBreak{});
-
- if (FAILED(settingsLoadedResult))
- {
- if (!_settingsLoadExceptionText.empty())
- {
- warningsTextBlock.Inlines().Append(_BuildErrorRun(_settingsLoadExceptionText, ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Resources()));
- warningsTextBlock.Inlines().Append(Documents::LineBreak{});
- }
- }
-
- // Add a note that we're using the default settings in this case.
- winrt::Windows::UI::Xaml::Documents::Run usingDefaultsRun;
- const auto usingDefaultsText = RS_(L"UsingDefaultSettingsText");
- usingDefaultsRun.Text(usingDefaultsText);
- warningsTextBlock.Inlines().Append(Documents::LineBreak{});
- warningsTextBlock.Inlines().Append(usingDefaultsRun);
-
- Controls::ContentDialog dialog;
- dialog.Title(winrt::box_value(title));
- dialog.Content(winrt::box_value(warningsTextBlock));
- dialog.CloseButtonText(buttonText);
- dialog.DefaultButton(Controls::ContentDialogButton::Close);
-
- ShowDialog(dialog);
- }
-
- // Method Description:
- // - Displays a dialog for warnings found while loading or validating the
- // settings. Displays messages for whatever warnings were found while
- // validating the settings.
- // - Only one dialog can be visible at a time. If another dialog is visible
- // when this is called, nothing happens. See ShowDialog for details
- void AppLogic::_ShowLoadWarningsDialog()
- {
- auto title = RS_(L"SettingsValidateErrorTitle");
- auto buttonText = RS_(L"Ok");
-
- Controls::TextBlock warningsTextBlock;
- // Make sure you can copy-paste
- warningsTextBlock.IsTextSelectionEnabled(true);
- // Make sure the lines of text wrap
- warningsTextBlock.TextWrapping(TextWrapping::Wrap);
-
- for (const auto& warning : _warnings)
- {
- // Try looking up the warning message key for each warning.
- const auto warningText = _GetWarningText(warning);
- if (!warningText.empty())
- {
- warningsTextBlock.Inlines().Append(_BuildErrorRun(warningText, ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Resources()));
- warningsTextBlock.Inlines().Append(Documents::LineBreak{});
- }
- }
-
- Controls::ContentDialog dialog;
- dialog.Title(winrt::box_value(title));
- dialog.Content(winrt::box_value(warningsTextBlock));
- dialog.CloseButtonText(buttonText);
- dialog.DefaultButton(Controls::ContentDialogButton::Close);
-
- ShowDialog(dialog);
- }
-
- // Method Description:
- // - Triggered when the application is finished loading. If we failed to load
- // the settings, then this will display the error dialog. This is done
- // here instead of when loading the settings, because we need our UI to be
- // visible to display the dialog, and when we're loading the settings,
- // the UI might not be visible yet.
- // Arguments:
- // -
- void AppLogic::_OnLoaded(const IInspectable& /*sender*/,
- const RoutedEventArgs& /*eventArgs*/)
- {
- if (_settings.GlobalSettings().InputServiceWarning())
- {
- const auto keyboardServiceIsDisabled = !_IsKeyboardServiceEnabled();
- if (keyboardServiceIsDisabled)
- {
- _root->ShowKeyboardServiceWarning();
- }
- }
-
- if (FAILED(_settingsLoadedResult))
- {
- const winrt::hstring titleKey = USES_RESOURCE(L"InitialJsonParseErrorTitle");
- const winrt::hstring textKey = USES_RESOURCE(L"InitialJsonParseErrorText");
- _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult);
- }
- else if (_settingsLoadedResult == S_FALSE)
- {
- _ShowLoadWarningsDialog();
- }
- }
-
- // Method Description:
- // - Helper for determining if the "Touch Keyboard and Handwriting Panel
- // Service" is enabled. If it isn't, we want to be able to display a
- // warning to the user, because they won't be able to type in the
- // Terminal.
- // Return Value:
- // - true if the service is enabled, or if we fail to query the service. We
- // return true in that case, to be less noisy (though, that is unexpected)
- bool AppLogic::_IsKeyboardServiceEnabled()
- {
- if (IsUwp())
- {
- return true;
- }
-
- // If at any point we fail to open the service manager, the service,
- // etc, then just quick return true to disable the dialog. We'd rather
- // not be noisy with this dialog if we failed for some reason.
-
- // Open the service manager. This will return 0 if it failed.
- wil::unique_schandle hManager{ OpenSCManagerW(nullptr, nullptr, 0) };
-
- if (LOG_LAST_ERROR_IF(!hManager.is_valid()))
- {
- return true;
- }
-
- // Get a handle to the keyboard service
- wil::unique_schandle hService{ OpenServiceW(hManager.get(), TabletInputServiceKey.data(), SERVICE_QUERY_STATUS) };
-
- // Windows 11 doesn't have a TabletInputService.
- // (It was renamed to TextInputManagementService, because people kept thinking that a
- // service called "tablet-something" is system-irrelevant on PCs and can be disabled.)
- if (!hService.is_valid())
- {
- return true;
- }
-
- // Get the current state of the service
- SERVICE_STATUS status{ 0 };
- if (!LOG_IF_WIN32_BOOL_FALSE(QueryServiceStatus(hService.get(), &status)))
- {
- return true;
- }
-
- const auto state = status.dwCurrentState;
- return (state == SERVICE_RUNNING || state == SERVICE_START_PENDING);
- }
-
- // Method Description:
- // - Get the size in pixels of the client area we'll need to launch this
- // terminal app. This method will use the default profile's settings to do
- // this calculation, as well as the _system_ dpi scaling. See also
- // TermControl::GetProposedDimensions.
- // Arguments:
- // -
- // Return Value:
- // - a point containing the requested dimensions in pixels.
- winrt::Windows::Foundation::Size AppLogic::GetLaunchDimensions(uint32_t dpi)
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- winrt::Windows::Foundation::Size proposedSize{};
-
- const auto scale = static_cast(dpi) / static_cast(USER_DEFAULT_SCREEN_DPI);
- if (const auto layout = _root->LoadPersistedLayout(_settings))
- {
- if (layout.InitialSize())
- {
- proposedSize = layout.InitialSize().Value();
- // The size is saved as a non-scaled real pixel size,
- // so we need to scale it appropriately.
- proposedSize.Height = proposedSize.Height * scale;
- proposedSize.Width = proposedSize.Width * scale;
- }
- }
-
- if (_appArgs.GetSize().has_value() || (proposedSize.Width == 0 && proposedSize.Height == 0))
- {
- // Use the default profile to determine how big of a window we need.
- const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr, nullptr) };
-
- const til::size emptySize{};
- const auto commandlineSize = _appArgs.GetSize().value_or(emptySize);
- proposedSize = TermControl::GetProposedDimensions(settings.DefaultSettings(),
- dpi,
- commandlineSize.width,
- commandlineSize.height);
- }
-
- // GH#2061 - If the global setting "Always show tab bar" is
- // set or if "Show tabs in title bar" is set, then we'll need to add
- // the height of the tab bar here.
- if (_settings.GlobalSettings().ShowTabsInTitlebar())
- {
- // If we're showing the tabs in the titlebar, we need to use a
- // TitlebarControl here to calculate how much space to reserve.
- //
- // We'll create a fake TitlebarControl, and we'll propose an
- // available size to it with Measure(). After Measure() is called,
- // the TitlebarControl's DesiredSize will contain the _unscaled_
- // size that the titlebar would like to use. We'll use that as part
- // of the height calculation here.
- auto titlebar = TitlebarControl{ static_cast(0) };
- titlebar.Measure({ SHRT_MAX, SHRT_MAX });
- proposedSize.Height += (titlebar.DesiredSize().Height) * scale;
- }
- else if (_settings.GlobalSettings().AlwaysShowTabs())
- {
- // Otherwise, let's use a TabRowControl to calculate how much extra
- // space we'll need.
- //
- // Similarly to above, we'll measure it with an arbitrarily large
- // available space, to make sure we get all the space it wants.
- auto tabControl = TabRowControl();
- tabControl.Measure({ SHRT_MAX, SHRT_MAX });
-
- // For whatever reason, there's about 10px of unaccounted-for space
- // in the application. I couldn't tell you where these 10px are
- // coming from, but they need to be included in this math.
- proposedSize.Height += (tabControl.DesiredSize().Height + 10) * scale;
- }
-
- return proposedSize;
- }
-
- // Method Description:
- // - Get the launch mode in json settings file. Now there
- // two launch mode: default, maximized. Default means the window
- // will launch according to the launch dimensions provided. Maximized
- // means the window will launch as a maximized window
- // Arguments:
- // -
- // Return Value:
- // - LaunchMode enum that indicates the launch mode
- LaunchMode AppLogic::GetLaunchMode()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- // GH#4620/#5801 - If the user passed --maximized or --fullscreen on the
- // commandline, then use that to override the value from the settings.
- const auto valueFromSettings = _settings.GlobalSettings().LaunchMode();
- const auto valueFromCommandlineArgs = _appArgs.GetLaunchMode();
- if (const auto layout = _root->LoadPersistedLayout(_settings))
- {
- if (layout.LaunchMode())
- {
- return layout.LaunchMode().Value();
- }
- }
- return valueFromCommandlineArgs.has_value() ?
- valueFromCommandlineArgs.value() :
- valueFromSettings;
- }
-
- // Method Description:
- // - Get the user defined initial position from Json settings file.
- // This position represents the top left corner of the Terminal window.
- // This setting is optional, if not provided, we will use the system
- // default size, which is provided in IslandWindow::MakeWindow.
- // Arguments:
- // - defaultInitialX: the system default x coordinate value
- // - defaultInitialY: the system default y coordinate value
- // Return Value:
- // - a point containing the requested initial position in pixels.
- TerminalApp::InitialPosition AppLogic::GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY)
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- auto initialPosition{ _settings.GlobalSettings().InitialPosition() };
-
- if (const auto layout = _root->LoadPersistedLayout(_settings))
- {
- if (layout.InitialPosition())
- {
- initialPosition = layout.InitialPosition().Value();
- }
- }
-
- // Commandline args trump everything else
- if (_appArgs.GetPosition().has_value())
- {
- initialPosition = _appArgs.GetPosition().value();
- }
-
- return {
- initialPosition.X ? initialPosition.X.Value() : defaultInitialX,
- initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY
- };
- }
-
- bool AppLogic::CenterOnLaunch()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
- // If the position has been specified on the commandline, don't center on launch
- return _settings.GlobalSettings().CenterOnLaunch() && !_appArgs.GetPosition().has_value();
- }
-
- winrt::Windows::UI::Xaml::ElementTheme AppLogic::GetRequestedTheme()
- {
- return Theme().RequestedTheme();
- }
-
- bool AppLogic::GetShowTabsInTitlebar()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _settings.GlobalSettings().ShowTabsInTitlebar();
- }
-
- bool AppLogic::GetInitialAlwaysOnTop()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _settings.GlobalSettings().AlwaysOnTop();
- }
-
- // Method Description:
- // - See Pane::CalcSnappedDimension
- float AppLogic::CalcSnappedDimension(const bool widthOrHeight, const float dimension) const
- {
- return _root->CalcSnappedDimension(widthOrHeight, dimension);
- }
-
// Method Description:
// - Attempt to load the settings. If we fail for any reason, returns an error.
// Return Value:
@@ -868,6 +300,11 @@ namespace winrt::TerminalApp::implementation
return hr;
}
+ bool AppLogic::HasSettingsStartupActions() const noexcept
+ {
+ return _hasSettingsStartupActions;
+ }
+
// Call this function after loading your _settings.
// It handles any CPU intensive settings updates (like updating the Jumplist)
// which should thus only occur if the settings file actually changed.
@@ -957,18 +394,6 @@ namespace winrt::TerminalApp::implementation
}
CATCH_LOG()
- // Method Description:
- // - Update the current theme of the application. This will trigger our
- // RequestedThemeChanged event, to have our host change the theme of the
- // root of the application.
- // Arguments:
- // - newTheme: The ElementTheme to apply to our elements.
- void AppLogic::_RefreshThemeRoutine()
- {
- // Propagate the event to the host layer, so it can update its own UI
- _RequestedThemeChangedHandlers(*this, Theme());
- }
-
// Function Description:
// Returns the current app package or nullptr.
// TRANSITIONAL
@@ -1053,10 +478,14 @@ namespace winrt::TerminalApp::implementation
}
else
{
- const winrt::hstring titleKey = USES_RESOURCE(L"ReloadJsonParseErrorTitle");
- const winrt::hstring textKey = USES_RESOURCE(L"ReloadJsonParseErrorText");
- _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult);
- return;
+ // TODO! Arg should be a SettingsLoadEventArgs{ result, warnings, error, settings}
+ //
+ // _SettingsChangedHandlers(*this, make_self( _settingsLoadedResult, warnings, _settingsLoadExceptionText, settings}))
+
+ // const winrt::hstring titleKey = USES_RESOURCE(L"ReloadJsonParseErrorTitle");
+ // const winrt::hstring textKey = USES_RESOURCE(L"ReloadJsonParseErrorText");
+ // _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult);
+ // return;
}
}
@@ -1067,28 +496,19 @@ namespace winrt::TerminalApp::implementation
return;
}
- if (_settingsLoadedResult == S_FALSE)
- {
- _ShowLoadWarningsDialog();
- }
+ // if (_settingsLoadedResult == S_FALSE)
+ // {
+ // _ShowLoadWarningsDialog();
+ // }
// Here, we successfully reloaded the settings, and created a new
// TerminalSettings object.
- // Update the settings in TerminalPage
- _root->SetSettings(_settings, true);
-
_ApplyLanguageSettingChange();
- _RefreshThemeRoutine();
_ApplyStartupTaskStateChange();
_ProcessLazySettingsChanges();
- _SettingsChangedHandlers(*this, nullptr);
- }
-
- void AppLogic::_OpenSettingsUI()
- {
- _root->OpenSettingsUI();
+ _SettingsChangedHandlers(*this, _settings);
}
// Method Description:
@@ -1098,207 +518,6 @@ namespace winrt::TerminalApp::implementation
return _settings;
}
- UIElement AppLogic::GetRoot() noexcept
- {
- return _root.as();
- }
-
- // Method Description:
- // - Gets the title of the currently focused terminal control. If there
- // isn't a control selected for any reason, returns "Terminal"
- // Arguments:
- // -
- // Return Value:
- // - the title of the focused control if there is one, else "Terminal"
- hstring AppLogic::Title()
- {
- if (_root)
- {
- return _root->Title();
- }
- return { L"Terminal" };
- }
-
- // Method Description:
- // - Used to tell the app that the titlebar has been clicked. The App won't
- // actually receive any clicks in the titlebar area, so this is a helper
- // to clue the app in that a click has happened. The App will use this as
- // a indicator that it needs to dismiss any open flyouts.
- // Arguments:
- // -
- // Return Value:
- // -
- void AppLogic::TitlebarClicked()
- {
- if (_root)
- {
- _root->TitlebarClicked();
- }
- }
-
- // Method Description:
- // - Used to tell the PTY connection that the window visibility has changed.
- // The underlying PTY might need to expose window visibility status to the
- // client application for the `::GetConsoleWindow()` API.
- // Arguments:
- // - showOrHide - True is show; false is hide.
- // Return Value:
- // -
- void AppLogic::WindowVisibilityChanged(const bool showOrHide)
- {
- if (_root)
- {
- _root->WindowVisibilityChanged(showOrHide);
- }
- }
-
- // Method Description:
- // - Implements the F7 handler (per GH#638)
- // - Implements the Alt handler (per GH#6421)
- // Return value:
- // - whether the key was handled
- bool AppLogic::OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down)
- {
- if (_root)
- {
- // Manually bubble the OnDirectKeyEvent event up through the focus tree.
- auto xamlRoot{ _root->XamlRoot() };
- auto focusedObject{ Windows::UI::Xaml::Input::FocusManager::GetFocusedElement(xamlRoot) };
- do
- {
- if (auto keyListener{ focusedObject.try_as() })
- {
- if (keyListener.OnDirectKeyEvent(vkey, scanCode, down))
- {
- return true;
- }
- // otherwise, keep walking. bubble the event manually.
- }
-
- if (auto focusedElement{ focusedObject.try_as() })
- {
- focusedObject = focusedElement.Parent();
-
- // Parent() seems to return null when the focusedElement is created from an ItemTemplate.
- // Use the VisualTreeHelper's GetParent as a fallback.
- if (!focusedObject)
- {
- focusedObject = winrt::Windows::UI::Xaml::Media::VisualTreeHelper::GetParent(focusedElement);
- }
- }
- else
- {
- break; // we hit a non-FE object, stop bubbling.
- }
- } while (focusedObject);
- }
- return false;
- }
-
- // Method Description:
- // - Used to tell the app that the 'X' button has been clicked and
- // the user wants to close the app. We kick off the close warning
- // experience.
- // Arguments:
- // -
- // Return Value:
- // -
- void AppLogic::CloseWindow(LaunchPosition pos)
- {
- if (_root)
- {
- // If persisted layout is enabled and we are the last window closing
- // we should save our state.
- if (_root->ShouldUsePersistedLayout(_settings) && _numOpenWindows == 1)
- {
- if (const auto layout = _root->GetWindowLayout())
- {
- layout.InitialPosition(pos);
- const auto state = ApplicationState::SharedInstance();
- state.PersistedWindowLayouts(winrt::single_threaded_vector({ layout }));
- }
- }
-
- _root->CloseWindow(false);
- }
- }
-
- winrt::TerminalApp::TaskbarState AppLogic::TaskbarState()
- {
- if (_root)
- {
- return _root->TaskbarState();
- }
- return {};
- }
-
- winrt::Windows::UI::Xaml::Media::Brush AppLogic::TitlebarBrush()
- {
- if (_root)
- {
- return _root->TitlebarBrush();
- }
- return { nullptr };
- }
- void AppLogic::WindowActivated(const bool activated)
- {
- _root->WindowActivated(activated);
- }
-
- bool AppLogic::HasCommandlineArguments() const noexcept
- {
- return _hasCommandLineArguments;
- }
-
- bool AppLogic::HasSettingsStartupActions() const noexcept
- {
- return _hasSettingsStartupActions;
- }
-
- // Method Description:
- // - Sets the initial commandline to process on startup, and attempts to
- // parse it. Commands will be parsed into a list of ShortcutActions that
- // will be processed on TerminalPage::Create().
- // - This function will have no effective result after Create() is called.
- // - This function returns 0, unless a there was a non-zero result from
- // trying to parse one of the commands provided. In that case, no commands
- // after the failing command will be parsed, and the non-zero code
- // returned.
- // Arguments:
- // - args: an array of strings to process as a commandline. These args can contain spaces
- // Return Value:
- // - the result of the first command who's parsing returned a non-zero code,
- // or 0. (see AppLogic::_ParseArgs)
- int32_t AppLogic::SetStartupCommandline(array_view args)
- {
- const auto result = _appArgs.ParseArgs(args);
- if (result == 0)
- {
- // If the size of the arguments list is 1,
- // then it contains only the executable name and no other arguments.
- _hasCommandLineArguments = args.size() > 1;
- _appArgs.ValidateStartupCommands();
- if (const auto idx = _appArgs.GetPersistedLayoutIdx())
- {
- _root->SetPersistedLayoutIdx(idx.value());
- }
- _root->SetStartupActions(_appArgs.GetStartupActions());
-
- // Check if we were started as a COM server for inbound connections of console sessions
- // coming out of the operating system default application feature. If so,
- // tell TerminalPage to start the listener as we have to make sure it has the chance
- // to register a handler to hear about the requests first and is all ready to receive
- // them before the COM server registers itself. Otherwise, the request might come
- // in and be routed to an event with no handlers or a non-ready Page.
- if (_appArgs.IsHandoffListener())
- {
- _root->SetInboundListener(true);
- }
- }
-
- return result;
- }
-
// Method Description:
// - Triggers the setup of the listener for incoming console connections
// from the operating system.
@@ -1308,43 +527,27 @@ namespace winrt::TerminalApp::implementation
// -
void AppLogic::SetInboundListener()
{
- _root->SetInboundListener(false);
+ // TODO!
+ // _root->SetInboundListener(false);
}
- // Method Description:
- // - Parse the provided commandline arguments into actions, and try to
- // perform them immediately.
- // - This function returns 0, unless a there was a non-zero result from
- // trying to parse one of the commands provided. In that case, no commands
- // after the failing command will be parsed, and the non-zero code
- // returned.
- // - If a non-empty cwd is provided, the entire terminal exe will switch to
- // that CWD while we handle these actions, then return to the original
- // CWD.
- // Arguments:
- // - args: an array of strings to process as a commandline. These args can contain spaces
- // - cwd: The directory to use as the CWD while performing these actions.
- // Return Value:
- // - the result of the first command who's parsing returned a non-zero code,
- // or 0. (see AppLogic::_ParseArgs)
- int32_t AppLogic::ExecuteCommandline(array_view args,
- const winrt::hstring& cwd)
+ bool AppLogic::ShouldImmediatelyHandoffToElevated()
{
- ::TerminalApp::AppCommandlineArgs appArgs;
- auto result = appArgs.ParseArgs(args);
- if (result == 0)
- {
- auto actions = winrt::single_threaded_vector(std::move(appArgs.GetStartupActions()));
+ // TODO! Merge that code in here.
+ // * Probably need to pass in the startupActions that the first window is being started with
+ // * Or like, a reference to the first TerminalWindow object, or something
- _root->ProcessStartupActions(actions, false, cwd);
+ // return _root != nullptr ? _root->ShouldImmediatelyHandoffToElevated(_settings) : false;
+ return false;
+ }
+ void AppLogic::HandoffToElevated()
+ {
+ // TODO! Merge that code in here.
- if (appArgs.IsHandoffListener())
- {
- _root->SetInboundListener(true);
- }
- }
- // Return the result of parsing with commandline, though it may or may not be used.
- return result;
+ // if (_root)
+ // {
+ // _root->HandoffToElevated(_settings);
+ // }
}
// Method Description:
@@ -1468,229 +671,28 @@ namespace winrt::TerminalApp::implementation
return winrt::make(WindowingBehaviorUseNew);
}
- // Method Description:
- // - If there were any errors parsing the commandline that was used to
- // initialize the terminal, this will return a string containing that
- // message. If there were no errors, this message will be blank.
- // - If the user requested help on any command (using --help), this will
- // contain the help message.
- // - If the user requested the version number (using --version), this will
- // contain the version string.
- // Arguments:
- // -
- // Return Value:
- // - the help text or error message for the provided commandline, if one
- // exists, otherwise the empty string.
- winrt::hstring AppLogic::ParseCommandlineMessage()
- {
- return winrt::to_hstring(_appArgs.GetExitMessage());
- }
-
- // Method Description:
- // - Returns true if we should exit the application before even starting the
- // window. We might want to do this if we're displaying an error message or
- // the version string, or if we want to open the settings file.
- // Arguments:
- // -
- // Return Value:
- // - true iff we should exit the application before even starting the window
- bool AppLogic::ShouldExitEarly()
- {
- return _appArgs.ShouldExitEarly();
- }
-
- bool AppLogic::FocusMode() const
- {
- return _root ? _root->FocusMode() : false;
- }
-
- bool AppLogic::Fullscreen() const
- {
- return _root ? _root->Fullscreen() : false;
- }
-
- void AppLogic::Maximized(bool newMaximized)
- {
- if (_root)
- {
- _root->Maximized(newMaximized);
- }
- }
-
- bool AppLogic::AlwaysOnTop() const
- {
- return _root ? _root->AlwaysOnTop() : false;
- }
-
- bool AppLogic::AutoHideWindow()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _settings.GlobalSettings().AutoHideWindow();
- }
-
Windows::Foundation::Collections::IMapView AppLogic::GlobalHotkeys()
{
return _settings.GlobalSettings().ActionMap().GlobalHotkeys();
}
- bool AppLogic::ShouldUsePersistedLayout()
- {
- return _root != nullptr ? _root->ShouldUsePersistedLayout(_settings) : false;
- }
-
- bool AppLogic::ShouldImmediatelyHandoffToElevated()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _root != nullptr ? _root->ShouldImmediatelyHandoffToElevated(_settings) : false;
- }
- void AppLogic::HandoffToElevated()
- {
- if (_root)
- {
- _root->HandoffToElevated(_settings);
- }
- }
-
- void AppLogic::SaveWindowLayoutJsons(const Windows::Foundation::Collections::IVector& layouts)
- {
- std::vector converted;
- converted.reserve(layouts.Size());
-
- for (const auto& json : layouts)
- {
- if (json != L"")
- {
- converted.emplace_back(WindowLayout::FromJson(json));
- }
- }
-
- ApplicationState::SharedInstance().PersistedWindowLayouts(winrt::single_threaded_vector(std::move(converted)));
- }
-
- hstring AppLogic::GetWindowLayoutJson(LaunchPosition position)
- {
- if (_root != nullptr)
- {
- if (const auto layout = _root->GetWindowLayout())
- {
- layout.InitialPosition(position);
- return WindowLayout::ToJson(layout);
- }
- }
- return L"";
- }
-
- void AppLogic::IdentifyWindow()
- {
- if (_root)
- {
- _root->IdentifyWindow();
- }
- }
-
- winrt::hstring AppLogic::WindowName()
- {
- return _root ? _root->WindowName() : L"";
- }
- void AppLogic::WindowName(const winrt::hstring& name)
- {
- if (_root)
- {
- _root->WindowName(name);
- }
- }
- uint64_t AppLogic::WindowId()
- {
- return _root ? _root->WindowId() : 0;
- }
- void AppLogic::WindowId(const uint64_t& id)
- {
- if (_root)
- {
- _root->WindowId(id);
- }
- }
-
- void AppLogic::SetPersistedLayoutIdx(const uint32_t idx)
- {
- if (_root)
- {
- _root->SetPersistedLayoutIdx(idx);
- }
- }
-
- void AppLogic::SetNumberOfOpenWindows(const uint64_t num)
- {
- _numOpenWindows = num;
- if (_root)
- {
- _root->SetNumberOfOpenWindows(num);
- }
- }
-
- void AppLogic::RenameFailed()
- {
- if (_root)
- {
- _root->RenameFailed();
- }
- }
-
- bool AppLogic::IsQuakeWindow() const noexcept
- {
- return _root->IsQuakeWindow();
- }
-
- void AppLogic::RequestExitFullscreen()
- {
- _root->SetFullscreen(false);
- }
-
- bool AppLogic::GetMinimizeToNotificationArea()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _settings.GlobalSettings().MinimizeToNotificationArea();
- }
-
- bool AppLogic::GetAlwaysShowNotificationIcon()
- {
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
-
- return _settings.GlobalSettings().AlwaysShowNotificationIcon();
- }
-
- bool AppLogic::GetShowTitleInTitlebar()
- {
- return _settings.GlobalSettings().ShowTitleInTitlebar();
- }
-
Microsoft::Terminal::Settings::Model::Theme AppLogic::Theme()
{
- if (!_loadedInitialSettings)
- {
- // Load settings if we haven't already
- ReloadSettings();
- }
return _settings.GlobalSettings().CurrentTheme();
}
+ TerminalApp::TerminalWindow AppLogic::CreateNewWindow()
+ {
+ if (_settings == nullptr)
+ {
+ ReloadSettings();
+ }
+ auto window = winrt::make_self(_settings);
+ this->SettingsChanged({ window->get_weak(), &implementation::TerminalWindow::UpdateSettingsHandler });
+ if (_hasSettingsStartupActions)
+ {
+ window->SetSettingsStartupArgs(_settingsAppArgs.GetStartupActions());
+ }
+ return *window;
+ }
}
diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h
index 5534979b97..ffe744b897 100644
--- a/src/cascadia/TerminalApp/AppLogic.h
+++ b/src/cascadia/TerminalApp/AppLogic.h
@@ -5,10 +5,11 @@
#include "AppLogic.g.h"
#include "FindTargetWindowResult.g.h"
-#include "SystemMenuChangeArgs.g.h"
+
#include "Jumplist.h"
#include "LanguageProfileNotifier.h"
-#include "TerminalPage.h"
+#include "AppCommandlineArgs.h"
+#include "TerminalWindow.h"
#include
#include
@@ -36,18 +37,7 @@ namespace winrt::TerminalApp::implementation
FindTargetWindowResult(id, L""){};
};
- struct SystemMenuChangeArgs : SystemMenuChangeArgsT
- {
- WINRT_PROPERTY(winrt::hstring, Name, L"");
- WINRT_PROPERTY(SystemMenuChangeAction, Action, SystemMenuChangeAction::Add);
- WINRT_PROPERTY(SystemMenuItemHandler, Handler, nullptr);
-
- public:
- SystemMenuChangeArgs(const winrt::hstring& name, SystemMenuChangeAction action, SystemMenuItemHandler handler = nullptr) :
- _Name{ name }, _Action{ action }, _Handler{ handler } {};
- };
-
- struct AppLogic : AppLogicT
+ struct AppLogic : AppLogicT
{
public:
static AppLogic* Current() noexcept;
@@ -56,124 +46,48 @@ namespace winrt::TerminalApp::implementation
AppLogic();
~AppLogic() = default;
- STDMETHODIMP Initialize(HWND hwnd);
-
void Create();
bool IsUwp() const noexcept;
void RunAsUwp();
bool IsElevated() const noexcept;
void ReloadSettings();
+ bool HasSettingsStartupActions() const noexcept;
+
[[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept;
- void Quit();
-
- bool HasCommandlineArguments() const noexcept;
- bool HasSettingsStartupActions() const noexcept;
- int32_t SetStartupCommandline(array_view actions);
- int32_t ExecuteCommandline(array_view actions, const winrt::hstring& cwd);
TerminalApp::FindTargetWindowResult FindTargetWindow(array_view actions);
- winrt::hstring ParseCommandlineMessage();
- bool ShouldExitEarly();
-
- bool FocusMode() const;
- bool Fullscreen() const;
- void Maximized(bool newMaximized);
- bool AlwaysOnTop() const;
- bool AutoHideWindow();
-
- bool ShouldUsePersistedLayout();
bool ShouldImmediatelyHandoffToElevated();
void HandoffToElevated();
- hstring GetWindowLayoutJson(Microsoft::Terminal::Settings::Model::LaunchPosition position);
- void SaveWindowLayoutJsons(const Windows::Foundation::Collections::IVector& layouts);
- void IdentifyWindow();
- void RenameFailed();
- winrt::hstring WindowName();
- void WindowName(const winrt::hstring& name);
- uint64_t WindowId();
- void WindowId(const uint64_t& id);
- void SetPersistedLayoutIdx(const uint32_t idx);
- void SetNumberOfOpenWindows(const uint64_t num);
- bool IsQuakeWindow() const noexcept;
- void RequestExitFullscreen();
-
- Windows::Foundation::Size GetLaunchDimensions(uint32_t dpi);
- bool CenterOnLaunch();
- TerminalApp::InitialPosition GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY);
- winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme();
- Microsoft::Terminal::Settings::Model::LaunchMode GetLaunchMode();
- bool GetShowTabsInTitlebar();
- bool GetInitialAlwaysOnTop();
- float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;
-
- Windows::UI::Xaml::UIElement GetRoot() noexcept;
void SetInboundListener();
- hstring Title();
- void TitlebarClicked();
- bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);
-
- void CloseWindow(Microsoft::Terminal::Settings::Model::LaunchPosition position);
- void WindowVisibilityChanged(const bool showOrHide);
-
- winrt::TerminalApp::TaskbarState TaskbarState();
- winrt::Windows::UI::Xaml::Media::Brush TitlebarBrush();
- void WindowActivated(const bool activated);
-
- bool GetMinimizeToNotificationArea();
- bool GetAlwaysShowNotificationIcon();
- bool GetShowTitleInTitlebar();
-
- winrt::Windows::Foundation::IAsyncOperation ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
- void DismissDialog();
-
Windows::Foundation::Collections::IMapView GlobalHotkeys();
Microsoft::Terminal::Settings::Model::Theme Theme();
- // -------------------------------- WinRT Events ---------------------------------
- // PropertyChanged is surprisingly not a typed event, so we'll define that one manually.
- // Usually we'd just do
- // WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
- //
- // But what we're doing here is exposing the Page's PropertyChanged _as
- // our own event_. It's a FORWARDED_CALLBACK, essentially.
- winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) { return _root->PropertyChanged(handler); }
- void PropertyChanged(winrt::event_token const& token) { _root->PropertyChanged(token); }
+ TerminalApp::TerminalWindow CreateNewWindow();
- TYPED_EVENT(RequestedThemeChanged, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Settings::Model::Theme);
TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
- TYPED_EVENT(SystemMenuChangeRequested, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::SystemMenuChangeArgs);
private:
bool _isUwp{ false };
bool _isElevated{ false };
- // If you add controls here, but forget to null them either here or in
- // the ctor, you're going to have a bad time. It'll mysteriously fail to
- // activate the AppLogic.
- // ALSO: If you add any UIElements as roots here, make sure they're
- // updated in _ApplyTheme. The root currently is _root.
- winrt::com_ptr _root{ nullptr };
Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr };
winrt::hstring _settingsLoadExceptionText;
HRESULT _settingsLoadedResult = S_OK;
bool _loadedInitialSettings = false;
- uint64_t _numOpenWindows{ 0 };
-
- std::shared_mutex _dialogLock;
- winrt::Windows::UI::Xaml::Controls::ContentDialog _dialog;
-
- ::TerminalApp::AppCommandlineArgs _appArgs;
+ bool _hasSettingsStartupActions{ false };
::TerminalApp::AppCommandlineArgs _settingsAppArgs;
std::shared_ptr> _reloadSettings;
til::throttled_func_trailing<> _reloadState;
+ std::vector _warnings;
+
// These fields invoke _reloadSettings and must be destroyed before _reloadSettings.
// (C++ destroys members in reverse-declaration-order.)
winrt::com_ptr _languageProfileNotifier;
@@ -182,46 +96,13 @@ namespace winrt::TerminalApp::implementation
static TerminalApp::FindTargetWindowResult _doFindTargetWindow(winrt::array_view args,
const Microsoft::Terminal::Settings::Model::WindowingMode& windowingBehavior);
- void _ShowLoadErrorsDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey, HRESULT settingsLoadedResult);
- void _ShowLoadWarningsDialog();
- bool _IsKeyboardServiceEnabled();
-
void _ApplyLanguageSettingChange() noexcept;
- void _RefreshThemeRoutine();
fire_and_forget _ApplyStartupTaskStateChange();
- void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
-
[[nodiscard]] HRESULT _TryLoadSettings() noexcept;
void _ProcessLazySettingsChanges();
void _RegisterSettingsChange();
fire_and_forget _DispatchReloadSettings();
- void _OpenSettingsUI();
-
- bool _hasCommandLineArguments{ false };
- bool _hasSettingsStartupActions{ false };
- std::vector _warnings;
-
- // These are events that are handled by the TerminalPage, but are
- // exposed through the AppLogic. This macro is used to forward the event
- // directly to them.
- FORWARDED_TYPED_EVENT(SetTitleBarContent, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement, _root, SetTitleBarContent);
- FORWARDED_TYPED_EVENT(TitleChanged, winrt::Windows::Foundation::IInspectable, winrt::hstring, _root, TitleChanged);
- FORWARDED_TYPED_EVENT(LastTabClosed, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs, _root, LastTabClosed);
- FORWARDED_TYPED_EVENT(FocusModeChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, FocusModeChanged);
- FORWARDED_TYPED_EVENT(FullscreenChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, FullscreenChanged);
- FORWARDED_TYPED_EVENT(ChangeMaximizeRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, ChangeMaximizeRequested);
- FORWARDED_TYPED_EVENT(AlwaysOnTopChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, AlwaysOnTopChanged);
- FORWARDED_TYPED_EVENT(RaiseVisualBell, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, RaiseVisualBell);
- FORWARDED_TYPED_EVENT(SetTaskbarProgress, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, SetTaskbarProgress);
- FORWARDED_TYPED_EVENT(IdentifyWindowsRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IdentifyWindowsRequested);
- FORWARDED_TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs, _root, RenameWindowRequested);
- FORWARDED_TYPED_EVENT(IsQuakeWindowChanged, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IsQuakeWindowChanged);
- FORWARDED_TYPED_EVENT(SummonWindowRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, SummonWindowRequested);
- FORWARDED_TYPED_EVENT(CloseRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, CloseRequested);
- FORWARDED_TYPED_EVENT(OpenSystemMenu, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, OpenSystemMenu);
- FORWARDED_TYPED_EVENT(QuitRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, QuitRequested);
- FORWARDED_TYPED_EVENT(ShowWindowChanged, Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs, _root, ShowWindowChanged);
#ifdef UNIT_TESTING
friend class TerminalAppLocalTests::CommandlineTest;
diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl
index b7a92ea110..7946403aee 100644
--- a/src/cascadia/TerminalApp/AppLogic.idl
+++ b/src/cascadia/TerminalApp/AppLogic.idl
@@ -1,41 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
-
-import "TerminalPage.idl";
-import "ShortcutActionDispatch.idl";
-import "IDirectKeyListener.idl";
+import "TerminalWindow.idl";
namespace TerminalApp
{
- struct InitialPosition
- {
- Int64 X;
- Int64 Y;
- };
-
[default_interface] runtimeclass FindTargetWindowResult
{
Int32 WindowId { get; };
String WindowName { get; };
};
- delegate void SystemMenuItemHandler();
-
- enum SystemMenuChangeAction
- {
- Add = 0,
- Remove = 1
- };
-
- [default_interface] runtimeclass SystemMenuChangeArgs {
- String Name { get; };
- SystemMenuChangeAction Action { get; };
- SystemMenuItemHandler Handler { get; };
- };
-
// See IDialogPresenter and TerminalPage's DialogPresenter for more
// information.
- [default_interface] runtimeclass AppLogic : IDirectKeyListener, IDialogPresenter, Windows.UI.Xaml.Data.INotifyPropertyChanged
+ [default_interface] runtimeclass AppLogic
{
AppLogic();
@@ -50,94 +27,24 @@ namespace TerminalApp
void RunAsUwp();
Boolean IsElevated();
- Boolean HasCommandlineArguments();
Boolean HasSettingsStartupActions();
- Int32 SetStartupCommandline(String[] commands);
- Int32 ExecuteCommandline(String[] commands, String cwd);
- String ParseCommandlineMessage { get; };
- Boolean ShouldExitEarly { get; };
-
- void Quit();
void ReloadSettings();
- Windows.UI.Xaml.UIElement GetRoot();
void SetInboundListener();
- String Title { get; };
-
- Boolean FocusMode { get; };
- Boolean Fullscreen { get; };
- void Maximized(Boolean newMaximized);
- Boolean AlwaysOnTop { get; };
- Boolean AutoHideWindow { get; };
-
- void IdentifyWindow();
- String WindowName;
- UInt64 WindowId;
- void SetPersistedLayoutIdx(UInt32 idx);
- void SetNumberOfOpenWindows(UInt64 num);
- void RenameFailed();
- void RequestExitFullscreen();
- Boolean IsQuakeWindow();
-
- Windows.Foundation.Size GetLaunchDimensions(UInt32 dpi);
- Boolean CenterOnLaunch { get; };
-
- InitialPosition GetInitialPosition(Int64 defaultInitialX, Int64 defaultInitialY);
- Windows.UI.Xaml.ElementTheme GetRequestedTheme();
- Microsoft.Terminal.Settings.Model.LaunchMode GetLaunchMode();
- Boolean GetShowTabsInTitlebar();
- Boolean GetInitialAlwaysOnTop();
- Single CalcSnappedDimension(Boolean widthOrHeight, Single dimension);
- void TitlebarClicked();
- void CloseWindow(Microsoft.Terminal.Settings.Model.LaunchPosition position);
- void WindowVisibilityChanged(Boolean showOrHide);
-
- TaskbarState TaskbarState{ get; };
- Windows.UI.Xaml.Media.Brush TitlebarBrush { get; };
- void WindowActivated(Boolean activated);
-
- Boolean ShouldUsePersistedLayout();
- Boolean ShouldImmediatelyHandoffToElevated();
- void HandoffToElevated();
- String GetWindowLayoutJson(Microsoft.Terminal.Settings.Model.LaunchPosition position);
- void SaveWindowLayoutJsons(Windows.Foundation.Collections.IVector layouts);
-
- Boolean GetMinimizeToNotificationArea();
- Boolean GetAlwaysShowNotificationIcon();
- Boolean GetShowTitleInTitlebar();
-
Microsoft.Terminal.Settings.Model.Theme Theme { get; };
FindTargetWindowResult FindTargetWindow(String[] args);
+ TerminalWindow CreateNewWindow();
+
+ Boolean ShouldImmediatelyHandoffToElevated();
+ void HandoffToElevated();
+
Windows.Foundation.Collections.IMapView GlobalHotkeys();
- // See IDialogPresenter and TerminalPage's DialogPresenter for more
- // information.
- Windows.Foundation.IAsyncOperation ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
- void DismissDialog();
-
- event Windows.Foundation.TypedEventHandler