Skip to content

Commit

Permalink
Fix InitialPosition loss of fidelity
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Aug 24, 2020
1 parent f4b187b commit 269f005
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 54 deletions.
12 changes: 5 additions & 7 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,19 @@ namespace winrt::TerminalApp::implementation
// - defaultInitialY: the system default y coordinate value
// Return Value:
// - a point containing the requested initial position in pixels.
winrt::Windows::Foundation::Point AppLogic::GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY)
TerminalApp::InitialPosition AppLogic::GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY)
{
if (!_loadedInitialSettings)
{
// Load settings if we haven't already
LoadSettings();
}

const auto globals{ _settings->GlobalSettings() };
winrt::Windows::Foundation::Point point{
/* X */ gsl::narrow_cast<float>(globals.HasInitialPositionX() ? globals.InitialPositionX() : defaultInitialX),
/* Y */ gsl::narrow_cast<float>(globals.HasInitialPositionY() ? globals.InitialPositionY() : defaultInitialY)
const auto initialPosition{ _settings->GlobalSettings().InitialPosition() };
return {
initialPosition.X ? initialPosition.X.Value() : defaultInitialX,
initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY
};

return point;
}

winrt::Windows::UI::Xaml::ElementTheme AppLogic::GetRequestedTheme()
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace winrt::TerminalApp::implementation
bool AlwaysOnTop() const;

Windows::Foundation::Size GetLaunchDimensions(uint32_t dpi);
winrt::Windows::Foundation::Point GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY);
TerminalApp::InitialPosition GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY);
winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme();
LaunchMode GetLaunchMode();
bool GetShowTabsInTitlebar();
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import "IDirectKeyListener.idl";

namespace TerminalApp
{
struct InitialPosition
{
Int64 X;
Int64 Y;
};

enum LaunchMode
{
DefaultMode,
Expand Down Expand Up @@ -47,7 +53,7 @@ namespace TerminalApp

Windows.Foundation.Size GetLaunchDimensions(UInt32 dpi);

Windows.Foundation.Point GetLaunchInitialPositions(Int32 defaultInitialX, Int32 defaultInitialY);
InitialPosition GetInitialPosition(Int64 defaultInitialX, Int64 defaultInitialY);
Windows.UI.Xaml.ElementTheme GetRequestedTheme();
LaunchMode GetLaunchMode();
Boolean GetShowTabsInTitlebar();
Expand Down
22 changes: 1 addition & 21 deletions src/cascadia/TerminalApp/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)

JsonUtils::GetValueForKey(json, InitialColsKey, _InitialCols);

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

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

Expand Down Expand Up @@ -234,23 +234,3 @@ winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Termina
{
return _commands.GetView();
}

bool GlobalAppSettings::HasInitialPositionX() const
{
return _initialPosition.x.has_value();
}

bool GlobalAppSettings::HasInitialPositionY() const
{
return _initialPosition.y.has_value();
}

int32_t GlobalAppSettings::InitialPositionX() const
{
return _initialPosition.x.value();
}

int32_t GlobalAppSettings::InitialPositionY() const
{
return _initialPosition.y.value();
}
8 changes: 1 addition & 7 deletions src/cascadia/TerminalApp/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Author(s):
#pragma once

#include "GlobalAppSettings.g.h"
#include "SettingsTypes.h"

#include "AppKeyBindings.h"
#include "Command.h"
Expand Down Expand Up @@ -57,11 +56,6 @@ namespace winrt::TerminalApp::implementation
guid DefaultProfile() const;
hstring UnparsedDefaultProfile() const;

bool HasInitialPositionX() const;
bool HasInitialPositionY() const;
int32_t InitialPositionX() const;
int32_t InitialPositionY() const;

GETSET_PROPERTY(int32_t, InitialRows); // default value set in constructor
GETSET_PROPERTY(int32_t, InitialCols); // default value set in constructor
GETSET_PROPERTY(bool, AlwaysShowTabs, true);
Expand All @@ -75,6 +69,7 @@ namespace winrt::TerminalApp::implementation
GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0);
GETSET_PROPERTY(bool, WarnAboutLargePaste, true);
GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true);
GETSET_PROPERTY(winrt::TerminalApp::LaunchPosition, InitialPosition, nullptr, nullptr);
GETSET_PROPERTY(winrt::TerminalApp::LaunchMode, LaunchMode, winrt::TerminalApp::LaunchMode::DefaultMode);
GETSET_PROPERTY(bool, SnapToGridOnResize, true);
GETSET_PROPERTY(bool, ForceFullRepaintRendering, false);
Expand All @@ -88,7 +83,6 @@ namespace winrt::TerminalApp::implementation
private:
hstring _unparsedDefaultProfile;
guid _defaultProfile;
LaunchPosition _initialPosition;

com_ptr<AppKeyBindings> _keybindings;
std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings;
Expand Down
13 changes: 7 additions & 6 deletions src/cascadia/TerminalApp/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import "TerminalSettings.idl";

namespace TerminalApp
{
struct LaunchPosition
{
Windows.Foundation.IReference<Int32> X;
Windows.Foundation.IReference<Int32> Y;
};

[default_interface] runtimeclass GlobalAppSettings {
GlobalAppSettings();

Expand All @@ -28,6 +34,7 @@ namespace TerminalApp
Microsoft.Terminal.TerminalControl.CopyFormat CopyFormatting;
Boolean WarnAboutLargePaste;
Boolean WarnAboutMultiLinePaste;
LaunchPosition InitialPosition;
LaunchMode LaunchMode;
Boolean SnapToGridOnResize;
Boolean ForceFullRepaintRendering;
Expand All @@ -38,12 +45,6 @@ namespace TerminalApp
Boolean AlwaysOnTop;
Boolean UseTabSwitcher;

Boolean HasInitialPositionX();
Boolean HasInitialPositionY();
Int32 InitialPositionX { get; };
Int32 InitialPositionY { get; };


Windows.Foundation.Collections.IMapView<String, ColorScheme> GetColorSchemes();
void AddColorScheme(ColorScheme scheme);

Expand Down
6 changes: 0 additions & 6 deletions src/cascadia/TerminalApp/SettingsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ Module Name:

namespace winrt::TerminalApp
{
struct LaunchPosition
{
std::optional<int> x;
std::optional<int> y;
};

enum class ExpandCommandType : uint32_t
{
None = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ struct ::TerminalApp::JsonUtils::ConversionTrait<::winrt::TerminalApp::LaunchPos
int32_t position = std::stoi(token);
if (initialPosIndex == 0)
{
ret.x.emplace(position);
ret.X = position;
}

if (initialPosIndex == 1)
{
ret.y.emplace(position);
ret.Y = position;
}
}
catch (...)
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, winrt::Ter
launchMode = _logic.GetLaunchMode();

// Acquire the actual initial position
winrt::Windows::Foundation::Point initialPosition = _logic.GetLaunchInitialPositions(proposedRect.left, proposedRect.top);
proposedRect.left = gsl::narrow_cast<long>(initialPosition.X);
proposedRect.top = gsl::narrow_cast<long>(initialPosition.Y);
auto initialPos = _logic.GetInitialPosition(proposedRect.left, proposedRect.top);
proposedRect.left = static_cast<long>(initialPos.X);
proposedRect.top = static_cast<long>(initialPos.Y);

long adjustedHeight = 0;
long adjustedWidth = 0;
Expand Down

0 comments on commit 269f005

Please sign in to comment.