diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index db7e46cb944..a63cc4363a9 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -543,18 +543,18 @@ }, "initialCols": { "default": 120, - "description": "The number of columns displayed in the window upon first load.", + "description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.", "maximum": 999, "minimum": 1, "type": "integer" }, "initialPosition": { "$ref": "#/definitions/Coordinates", - "description": "The position of the top left corner of the window upon first load. On a system with multiple displays, these coordinates are relative to the top left of the primary display. If \"launchMode\" is set to maximized, the window will be maximized on the monitor specified by those coordinates." + "description": "The position of the top left corner of the window upon first load. On a system with multiple displays, these coordinates are relative to the top left of the primary display. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), the window will be maximized on the monitor specified by those coordinates." }, "initialRows": { "default": 30, - "description": "The number of rows displayed in the window upon first load.", + "description": "The number of rows displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.", "maximum": 999, "minimum": 1, "type": "integer" @@ -566,11 +566,13 @@ }, "launchMode": { "default": "default", - "description": "Defines whether the terminal will launch as maximized, full screen, or in a window.", + "description": "Defines whether the terminal will launch as maximized, full screen, or in a window. Setting this to \"focus\" is equivalent to launching the terminal in the \"default\" mode, but with the focus mode enabled. Similar, setting this to \"maximizedFocus\" will result in launching the terminal in a maximized window with the focus mode enabled.", "enum": [ "fullscreen", "maximized", - "default" + "default", + "focus", + "maximizedFocus" ], "type": "string" }, diff --git a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp index 897bc4984f2..0c9fe6df64e 100644 --- a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp +++ b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp @@ -57,6 +57,7 @@ namespace TerminalAppLocalTests TEST_METHOD(TestSimpleExecuteCommandlineAction); TEST_METHOD(TestMultipleCommandExecuteCommandlineAction); TEST_METHOD(TestInvalidExecuteCommandlineAction); + TEST_METHOD(TestLaunchMode); private: void _buildCommandlinesHelper(AppCommandlineArgs& appArgs, @@ -1132,4 +1133,95 @@ namespace TerminalAppLocalTests auto actions = implementation::TerminalPage::ConvertExecuteCommandlineToActions(args); VERIFY_ARE_EQUAL(0u, actions.size()); } + + void CommandlineTest::TestLaunchMode() + { + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_FALSE(appArgs.GetLaunchMode().has_value()); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"-F" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::FullscreenMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--fullscreen" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::FullscreenMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"-M" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--maximized" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"-f" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::FocusMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--focus" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::FocusMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"-fM" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedFocusMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--maximized", L"--focus" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedFocusMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--maximized", L"--focus", L"--focus" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedFocusMode); + } + { + AppCommandlineArgs appArgs{}; + std::vector rawCommands{ L"wt.exe", L"--maximized", L"--focus", L"--maximized" }; + _buildCommandlinesHelper(appArgs, 1u, rawCommands); + + VERIFY_IS_TRUE(appArgs.GetLaunchMode().has_value()); + VERIFY_ARE_EQUAL(appArgs.GetLaunchMode().value(), LaunchMode::MaximizedFocusMode); + } + } } diff --git a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp index 5e077a99eeb..413956a0aa0 100644 --- a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp +++ b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp @@ -171,18 +171,30 @@ void AppCommandlineArgs::_buildParser() }; _app.add_flag_function("-v,--version", versionCallback, RS_A(L"CmdVersionDesc")); - // Maximized and Fullscreen flags + // Launch mode related flags // -M,--maximized: Maximizes the window on launch // -F,--fullscreen: Fullscreens the window on launch + // -f,--focus: Sets the terminal into the Focus mode + // While fullscreen excludes both maximized and focus mode, the user can combine between the maximized and focused (-fM) auto maximizedCallback = [this](int64_t /*count*/) { - _launchMode = winrt::Microsoft::Terminal::Settings::Model::LaunchMode::MaximizedMode; + _launchMode = (_launchMode.has_value() && _launchMode.value() == LaunchMode::FocusMode) ? + LaunchMode::MaximizedFocusMode : + LaunchMode::MaximizedMode; }; auto fullscreenCallback = [this](int64_t /*count*/) { - _launchMode = winrt::Microsoft::Terminal::Settings::Model::LaunchMode::FullscreenMode; + _launchMode = LaunchMode::FullscreenMode; }; + auto focusCallback = [this](int64_t /*count*/) { + _launchMode = (_launchMode.has_value() && _launchMode.value() == LaunchMode::MaximizedMode) ? + LaunchMode::MaximizedFocusMode : + LaunchMode::FocusMode; + }; + auto maximized = _app.add_flag_function("-M,--maximized", maximizedCallback, RS_A(L"CmdMaximizedDesc")); auto fullscreen = _app.add_flag_function("-F,--fullscreen", fullscreenCallback, RS_A(L"CmdFullscreenDesc")); + auto focus = _app.add_flag_function("-f,--focus", focusCallback, RS_A(L"CmdFocusDesc")); maximized->excludes(fullscreen); + focus->excludes(fullscreen); // Subcommands _buildNewTabParser(); diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index e49b0147b6a..112387f8676 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -265,6 +265,10 @@ namespace winrt::TerminalApp::implementation { _root->ToggleFullscreen(); } + else if (launchMode == LaunchMode::FocusMode || launchMode == LaunchMode::MaximizedFocusMode) + { + _root->ToggleFocusMode(); + } }); _root->Create(); diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 7ab24f60555..7a707e1961c 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -285,6 +285,9 @@ Launch the window in fullscreen mode + + Launch the window in focus mode + Press the button to open a new terminal tab with your default profile. Open the flyout to select which profile you want to open. @@ -454,4 +457,4 @@ Cancel - \ No newline at end of file + diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index 5a748738719..38bd8545d7f 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -22,6 +22,8 @@ namespace Microsoft.Terminal.Settings.Model DefaultMode, MaximizedMode, FullscreenMode, + FocusMode, + MaximizedFocusMode, }; [default_interface] runtimeclass GlobalAppSettings { diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index 8f28dbfcfc4..9564646890b 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -165,10 +165,12 @@ JSON_ENUM_MAPPER(::winrt::Windows::UI::Xaml::ElementTheme) JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::LaunchMode) { - JSON_MAPPINGS(3) = { + JSON_MAPPINGS(5) = { pair_type{ "default", ValueType::DefaultMode }, pair_type{ "maximized", ValueType::MaximizedMode }, pair_type{ "fullscreen", ValueType::FullscreenMode }, + pair_type{ "focus", ValueType::FocusMode }, + pair_type{ "maximizedFocus", ValueType::MaximizedFocusMode }, }; }; diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 4312fb59df8..ebef2bb248a 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -139,7 +139,7 @@ void IslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) noexce } int nCmdShow = SW_SHOW; - if (launchMode == LaunchMode::MaximizedMode) + if (launchMode == LaunchMode::MaximizedMode || launchMode == LaunchMode::MaximizedFocusMode) { nCmdShow = SW_MAXIMIZE; }