Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CenterOnLaunch property #8414

Closed
wants to merge 3 commits into from
Closed
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
37 changes: 33 additions & 4 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pch.h"
#include "AppLogic.h"
#include "AppLogic.g.cpp"
#include "wtypes.h"
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

#include <LibraryResources.h>
Expand Down Expand Up @@ -636,11 +637,39 @@ namespace winrt::TerminalApp::implementation
LoadSettings();
}

UINT dpi = USER_DEFAULT_SCREEN_DPI;
int _width = 0;
int _height = 0;
Comment on lines +641 to +642
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int _width = 0;
int _height = 0;
int desktopWidth = 0;
int desktopHeight = 0;

We generally use _ to denote that it's a member. So let's remove that to be consistent.

And added desktop since you introduced appWidth and appHeight below. That way there's a better distinction between the two 😉

GetDesktopResolution(_width, _height);
const auto initialPosition{ _settings.GlobalSettings().InitialPosition() };
return {
initialPosition.X ? initialPosition.X.Value() : defaultInitialX,
initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY
};
const auto CentreOnLaunch{ _settings.GlobalSettings().CentreOnLaunch() };
const auto dimensions = GetLaunchDimensions(dpi);
const auto appWidth = dimensions.Width;
const auto appHeight = dimensions.Height;

if (CentreOnLaunch)
{
return {
(_width / 2) - (static_cast<int>(appWidth) / 2),
(_height / 2) - (static_cast<int>(appHeight) / 2)
};
}
else
{
return {
initialPosition.X ? initialPosition.X.Value() : defaultInitialX,
initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY
};
}
}

void AppLogic::GetDesktopResolution(int& width, int& height)
{
RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktop);
width = desktop.right;
height = desktop.bottom;
}

winrt::Windows::UI::Xaml::ElementTheme AppLogic::GetRequestedTheme()
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 @@ -34,6 +34,7 @@ namespace winrt::TerminalApp::implementation
bool Fullscreen() const;
bool AlwaysOnTop() const;

void GetDesktopResolution(int& horizontal, int& vertical);
Windows::Foundation::Size GetLaunchDimensions(uint32_t dpi);
TerminalApp::InitialPosition GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY);
winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme();
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static constexpr std::string_view AlwaysShowTabsKey{ "alwaysShowTabs" };
static constexpr std::string_view InitialRowsKey{ "initialRows" };
static constexpr std::string_view InitialColsKey{ "initialCols" };
static constexpr std::string_view InitialPositionKey{ "initialPosition" };
static constexpr std::string_view CentreOnLaunchKey{ "centreOnLaunch" };
static constexpr std::string_view ShowTitleInTitlebarKey{ "showTerminalTitleInTitlebar" };
static constexpr std::string_view ThemeKey{ "theme" };
static constexpr std::string_view TabWidthModeKey{ "tabWidthMode" };
Expand Down Expand Up @@ -104,6 +105,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
globals->_WarnAboutLargePaste = _WarnAboutLargePaste;
globals->_WarnAboutMultiLinePaste = _WarnAboutMultiLinePaste;
globals->_InitialPosition = _InitialPosition;
globals->_CentreOnLaunch = _CentreOnLaunch;
globals->_LaunchMode = _LaunchMode;
globals->_SnapToGridOnResize = _SnapToGridOnResize;
globals->_ForceFullRepaintRendering = _ForceFullRepaintRendering;
Expand Down Expand Up @@ -257,6 +259,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)

JsonUtils::GetValueForKey(json, InitialPositionKey, _InitialPosition);

JsonUtils::GetValueForKey(json, CentreOnLaunchKey, _CentreOnLaunch);

JsonUtils::GetValueForKey(json, ShowTitleInTitlebarKey, _ShowTitleInTitlebar);

JsonUtils::GetValueForKey(json, ShowTabsInTitlebarKey, _ShowTabsInTitlebar);
Expand Down Expand Up @@ -369,6 +373,7 @@ Json::Value GlobalAppSettings::ToJson() const
JsonUtils::SetValueForKey(json, InitialRowsKey, _InitialRows);
JsonUtils::SetValueForKey(json, InitialColsKey, _InitialCols);
JsonUtils::SetValueForKey(json, InitialPositionKey, _InitialPosition);
JsonUtils::SetValueForKey(json, CentreOnLaunchKey, _CentreOnLaunch);
JsonUtils::SetValueForKey(json, ShowTitleInTitlebarKey, _ShowTitleInTitlebar);
JsonUtils::SetValueForKey(json, ShowTabsInTitlebarKey, _ShowTabsInTitlebar);
JsonUtils::SetValueForKey(json, WordDelimitersKey, _WordDelimiters);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
GETSET_SETTING(bool, WarnAboutLargePaste, true);
GETSET_SETTING(bool, WarnAboutMultiLinePaste, true);
GETSET_SETTING(Model::LaunchPosition, InitialPosition, nullptr, nullptr);
GETSET_SETTING(bool, CentreOnLaunch, false);
GETSET_SETTING(Model::LaunchMode, LaunchMode, LaunchMode::DefaultMode);
GETSET_SETTING(bool, SnapToGridOnResize, true);
GETSET_SETTING(bool, ForceFullRepaintRendering, false);
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ namespace Microsoft.Terminal.Settings.Model
void ClearInitialPosition();
LaunchPosition InitialPosition;

Boolean HasCentreOnLaunch();
void ClearCentreOnLaunch();
Boolean CentreOnLaunch;

Boolean HasLaunchMode();
void ClearLaunchMode();
LaunchMode LaunchMode;
Expand Down