Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,15 @@
},
"launchMode": {
"default": "default",
"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.",
"description": "Defines whether the terminal will launch as minimized, 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\" (\"minimizedFocus\") will result in launching the terminal in a maximized (minimized) window with the focus mode enabled.",
"enum": [
"fullscreen",
"maximized",
"default",
"focus",
"maximizedFocus"
"maximizedFocus",
"minimized",
"minimizedFocus"
],
"type": "string"
},
Expand Down
27 changes: 23 additions & 4 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,47 @@ void AppCommandlineArgs::_buildParser()

// Launch mode related flags
// -M,--maximized: Maximizes the window on launch
// -m,--minimized: Minimizes 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)
// While fullscreen excludes maximized, minimized and focus modes, the user can combine between the minimized/maximized and focused (-fm / -fM)
auto maximizedCallback = [this](int64_t /*count*/) {
_launchMode = (_launchMode.has_value() && _launchMode.value() == LaunchMode::FocusMode) ?
LaunchMode::MaximizedFocusMode :
LaunchMode::MaximizedMode;
};
auto minimizedCallback = [this](int64_t /*count*/) {
_launchMode = (_launchMode.has_value() && _launchMode.value() == LaunchMode::FocusMode) ?
LaunchMode::MinFocusMode :
LaunchMode::MinimizedMode;
};
auto fullscreenCallback = [this](int64_t /*count*/) {
_launchMode = LaunchMode::FullscreenMode;
};
auto focusCallback = [this](int64_t /*count*/) {
_launchMode = (_launchMode.has_value() && _launchMode.value() == LaunchMode::MaximizedMode) ?
LaunchMode::MaximizedFocusMode :
LaunchMode::FocusMode;
if (_launchMode.has_value() && _launchMode.value() == LaunchMode::MaximizedMode)
{
_launchMode = LaunchMode::MaximizedFocusMode;
return;
}

if (_launchMode.has_value() && _launchMode.value() == LaunchMode::MinimizedMode)
{
_launchMode = LaunchMode::MinFocusMode;
return;
}

_launchMode = LaunchMode::FocusMode;
};

auto maximized = _app.add_flag_function("-M,--maximized", maximizedCallback, RS_A(L"CmdMaximizedDesc"));
auto minimized = _app.add_flag_function("-m,--minimized", minimizedCallback, RS_A(L"CmdMinimizedDesc"));
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);
minimized->excludes(maximized);
minimized->excludes(fullscreen);

// Subcommands
_buildNewTabParser();
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@ namespace winrt::TerminalApp::implementation
{
_root->ToggleFullscreen();
}
else if (launchMode == LaunchMode::FocusMode || launchMode == LaunchMode::MaximizedFocusMode)
else if (launchMode == LaunchMode::FocusMode || launchMode == LaunchMode::MaximizedFocusMode || launchMode == LaunchMode::MinFocusMode)
{
_root->ToggleFocusMode();
}

if (launchMode == LaunchMode::MinFocusMode || launchMode == LaunchMode::MinimizedMode)
{
_minimizedHandlers(*this, nullptr);
}
});
_root->Create();

Expand Down Expand Up @@ -1066,4 +1071,5 @@ namespace winrt::TerminalApp::implementation
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(AppLogic, RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(AppLogic, Minimized, _minimizedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace winrt::TerminalApp::implementation

// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(Minimized, _minimizedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);

private:
bool _isUwp{ false };
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 @@ -59,6 +59,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.ElementTheme> RequestedThemeChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> Minimized;
event Windows.Foundation.TypedEventHandler<Object, Object> FocusModeChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> FullscreenChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> AlwaysOnTopChanged;
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@
<data name="CmdMaximizedDesc" xml:space="preserve">
<value>Launch the window maximized</value>
</data>
<data name="CmdMinimizedDesc" xml:space="preserve">
<value>Launch the window minimized</value>
</data>
<data name="CmdFullscreenDesc" xml:space="preserve">
<value>Launch the window in fullscreen mode</value>
</data>
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ namespace Microsoft.Terminal.Settings.Model

enum LaunchMode
{
DefaultMode,
DefaultMode,
MaximizedMode,
FullscreenMode,
FocusMode,
MaximizedFocusMode,
MinimizedMode,
MinFocusMode,
};

[default_interface] runtimeclass GlobalAppSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ JSON_ENUM_MAPPER(::winrt::Windows::UI::Xaml::ElementTheme)

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::LaunchMode)
{
JSON_MAPPINGS(5) = {
JSON_MAPPINGS(7) = {
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 },
pair_type{ "minimized", ValueType::MinimizedMode },
pair_type{ "minimizedFocus", ValueType::MinFocusMode },
};
};

Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void AppHost::Initialize()
_logic.FullscreenChanged({ this, &AppHost::_FullscreenChanged });
_logic.FocusModeChanged({ this, &AppHost::_FocusModeChanged });
_logic.AlwaysOnTopChanged({ this, &AppHost::_AlwaysOnTopChanged });
_logic.Minimized({ this, &AppHost::_Minimized });

_logic.Create();

Expand Down Expand Up @@ -379,6 +380,12 @@ void AppHost::_AlwaysOnTopChanged(const winrt::Windows::Foundation::IInspectable
_window->SetAlwaysOnTop(_logic.AlwaysOnTop());
}

void AppHost::_Minimized(const winrt::Windows::Foundation::IInspectable&,
const winrt::Windows::Foundation::IInspectable&)
{
_window->Minimize();
}

// Method Description:
// - Called when the IslandWindow has received a WM_MOUSEWHEEL message. This can
// happen on some laptops, where their trackpads won't scroll inactive windows
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ class AppHost
const winrt::Windows::Foundation::IInspectable& arg);
void _AlwaysOnTopChanged(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& arg);
void _Minimized(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& arg);
void _WindowMouseWheeled(const til::point coord, const int32_t delta);
};
5 changes: 5 additions & 0 deletions src/cascadia/WindowsTerminal/BaseWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ class BaseWindow
_currentDpi = GetDpiForWindow(_window.get());
}

void Minimize()
{
PostMessage(_window.get(), WM_SYSCOMMAND, SC_MINIMIZE, 0);
}

protected:
using base_type = BaseWindow<T>;
wil::unique_hwnd _window;
Expand Down