Skip to content

Commit

Permalink
7124: Add focus and maximizedFocus launch modes (#7873)
Browse files Browse the repository at this point in the history
This commit introduces two new launch modes: focus and maximizedFocus. 
* Focused mode, behaves like a default mode, but with the Focus Mode
  enabled.
* Maximized focused mode, behaves like a Maximized mode, but with the
  Focus Mode enabled.

There two ways to invoke these new modes:
* In the settings file: you set the "launchMode" to either "focus" or
  "maximizedFocus"
* In the command line options, you can path -f / --focus, which is
  mutually exclusive with the --fullscreen, but can be combined with the
  --maximized:
  * Passing -f / --focus will launch the terminal in the "focus" mode
  * Passing -fM / --focus --maximized will launch the terminal in the
    "maximizedFocus" mode

This should resolve a relevant part in the command line arguments
mega-thread #4632

Closes #7124
Closes #7825
Closes #7875
  • Loading branch information
Don-Vito authored Oct 14, 2020
1 parent cb732a4 commit f86045e
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 11 deletions.
12 changes: 7 additions & 5 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,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"
Expand All @@ -571,11 +571,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"
},
Expand Down
92 changes: 92 additions & 0 deletions src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace TerminalAppLocalTests
TEST_METHOD(TestSimpleExecuteCommandlineAction);
TEST_METHOD(TestMultipleCommandExecuteCommandlineAction);
TEST_METHOD(TestInvalidExecuteCommandlineAction);
TEST_METHOD(TestLaunchMode);

private:
void _buildCommandlinesHelper(AppCommandlineArgs& appArgs,
Expand Down Expand Up @@ -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<const wchar_t*> rawCommands{ L"wt.exe" };
_buildCommandlinesHelper(appArgs, 1u, rawCommands);

VERIFY_IS_FALSE(appArgs.GetLaunchMode().has_value());
}
{
AppCommandlineArgs appArgs{};
std::vector<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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<const wchar_t*> 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);
}
}
}
18 changes: 15 additions & 3 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ namespace winrt::TerminalApp::implementation
{
_root->ToggleFullscreen();
}
else if (launchMode == LaunchMode::FocusMode || launchMode == LaunchMode::MaximizedFocusMode)
{
_root->ToggleFocusMode();
}
});
_root->Create();

Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@
<data name="CmdFullscreenDesc" xml:space="preserve">
<value>Launch the window in fullscreen mode</value>
</data>
<data name="CmdFocusDesc" xml:space="preserve">
<value>Launch the window in focus mode</value>
</data>
<data name="NewTabSplitButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.HelpText" xml:space="preserve">
<value>Press the button to open a new terminal tab with your default profile. Open the flyout to select which profile you want to open.</value>
</data>
Expand Down Expand Up @@ -457,4 +460,4 @@
<data name="CouldNotOpenUriDialog.PrimaryButtonText" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
</root>
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Microsoft.Terminal.Settings.Model
DefaultMode,
MaximizedMode,
FullscreenMode,
FocusMode,
MaximizedFocusMode,
};

[default_interface] runtimeclass GlobalAppSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f86045e

Please sign in to comment.