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

Use standard 1px window borders on NC Island Window #3394

Merged
merged 36 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6744d21
test things
Oct 31, 2019
1d33e22
Fix DwmExtendFrameIntoClientArea values
Oct 31, 2019
1dd0ee6
Fix WM_NCHITTEST handling
Oct 31, 2019
cd73d35
Position the XAML island window correctly
Oct 31, 2019
02a5e18
Fix weird colors in drag bar and hide old title bar buttons
Oct 31, 2019
19d67a5
Fix the window's position when maximized
Oct 31, 2019
214f086
Add comment
Oct 31, 2019
e08d973
Add support for dark theme on the frame
Oct 31, 2019
e37ace4
Changes for PR
Oct 31, 2019
046633c
DRY shared code between conhost and new terminal
Oct 31, 2019
a7132a3
Add noexcept in ThemeUtils
Oct 31, 2019
43b364f
Fix drag bar and remove dead code
Nov 1, 2019
dcbc115
Remove dead code and use cached DPI
Nov 1, 2019
f95693c
Refactor code
Nov 1, 2019
f55f4df
Remove impossible TODO
Nov 1, 2019
d3ab79f
More refactoring
Nov 1, 2019
3b7b6b3
format
Nov 1, 2019
d16c141
little changes for PR
Nov 1, 2019
f58702e
Refactor and found better way to just have the border at the top
Nov 1, 2019
41938c9
Add comment
Nov 1, 2019
75c1954
Use system metrics instead of hardcoding resize border height
Nov 2, 2019
424bbc4
Fix code that worked but that wasn't right
Nov 2, 2019
4c8b8e5
Changes for review
Nov 2, 2019
9b1b5e1
Revert "Refactor and found better way to just have the border at the …
Nov 2, 2019
1c85587
More changes for review
Nov 2, 2019
e8db54c
Fix comments
Nov 2, 2019
5764926
Use theme from app settings instead of system theme. Improve comments…
Nov 3, 2019
e448cfe
Changes for review
Nov 3, 2019
ace60e7
Fix initial position DPI handling bug and apply review changes
Nov 4, 2019
e0d0619
nit
Nov 4, 2019
02ae511
Fix thick borders with DPI > 96
Nov 4, 2019
48cd380
Update TODO
Nov 4, 2019
89eb7b4
fix comment
Nov 4, 2019
792969a
sorry I push too fast before reviewing my own code
Nov 4, 2019
8ae87fc
format
Nov 4, 2019
dc46679
Revert TODO update
Nov 4, 2019
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
14 changes: 13 additions & 1 deletion src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ namespace winrt::TerminalApp::implementation
TerminalSettings settings = _settings->MakeSettings(std::nullopt);

// TODO MSFT:21150597 - If the global setting "Always show tab bar" is
// set, then we'll need to add the height of the tab bar here.
// set or if "Show tabs in title bar" is set, then we'll need to add
// the height of the tab bar here.

return TermControl::GetProposedDimensions(settings, dpi);
}
Expand Down Expand Up @@ -397,6 +398,17 @@ namespace winrt::TerminalApp::implementation
return point;
}

winrt::Windows::UI::Xaml::ElementTheme App::GetRequestedTheme()
{
if (!_loadedInitialSettings)
{
// Load settings if we haven't already
LoadSettings();
}

return _settings->GlobalSettings().GetRequestedTheme();
}

bool App::GetShowTabsInTitlebar()
{
if (!_loadedInitialSettings)
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace winrt::TerminalApp::implementation

Windows::Foundation::Point GetLaunchDimensions(uint32_t dpi);
winrt::Windows::Foundation::Point GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY);
winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme();
LaunchMode GetLaunchMode();
bool GetShowTabsInTitlebar();

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/App.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace TerminalApp

Windows.Foundation.Point GetLaunchDimensions(UInt32 dpi);
Windows.Foundation.Point GetLaunchInitialPositions(Int32 defaultInitialX, Int32 defaultInitialY);
Windows.UI.Xaml.ElementTheme GetRequestedTheme();
LaunchMode GetLaunchMode();
Boolean GetShowTabsInTitlebar();
void TitlebarClicked();
Expand Down
55 changes: 13 additions & 42 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ AppHost::AppHost() noexcept :

if (_useNonClientArea)
{
_window = std::make_unique<NonClientIslandWindow>();
_window = std::make_unique<NonClientIslandWindow>(_app.GetRequestedTheme());
}
else
{
Expand Down Expand Up @@ -188,54 +188,25 @@ void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, winrt::Ter

auto initialSize = _app.GetLaunchDimensions(dpix);

const short _currentWidth = Utils::ClampToShortMax(
const short islandWidth = Utils::ClampToShortMax(
static_cast<long>(ceil(initialSize.X)), 1);
const short _currentHeight = Utils::ClampToShortMax(
const short islandHeight = Utils::ClampToShortMax(
static_cast<long>(ceil(initialSize.Y)), 1);

// Create a RECT from our requested client size
auto nonClient = Viewport::FromDimensions({ _currentWidth,
_currentHeight })
.ToRect();
RECT islandFrame = {};
bool succeeded = AdjustWindowRectExForDpi(&islandFrame, WS_OVERLAPPEDWINDOW, false, 0, dpix);
// If we failed to get the correct window size for whatever reason, log
// the error and go on. We'll use whatever the control proposed as the
// size of our window, which will be at least close.
LOG_LAST_ERROR_IF(!succeeded);

// Get the size of a window we'd need to host that client rect. This will
// add the titlebar space.
if (_useNonClientArea)
{
// If we're in NC tabs mode, do the math ourselves. Get the margins
// we're using for the window - this will include the size of the
// titlebar content.
const auto pNcWindow = static_cast<NonClientIslandWindow*>(_window.get());
const MARGINS margins = pNcWindow->GetFrameMargins();
nonClient.left = 0;
nonClient.top = 0;
nonClient.right = margins.cxLeftWidth + nonClient.right + margins.cxRightWidth;
nonClient.bottom = margins.cyTopHeight + nonClient.bottom + margins.cyBottomHeight;
}
else
{
bool succeeded = AdjustWindowRectExForDpi(&nonClient, WS_OVERLAPPEDWINDOW, false, 0, dpix);
if (!succeeded)
{
// If we failed to get the correct window size for whatever reason, log
// the error and go on. We'll use whatever the control proposed as the
// size of our window, which will be at least close.
LOG_LAST_ERROR();
nonClient = Viewport::FromDimensions({ _currentWidth,
_currentHeight })
.ToRect();
}

// For client island scenario, there is an invisible border of 8 pixels.
// We need to remove this border to guarantee the left edge of the window
// coincides with the screen
const auto pCWindow = static_cast<IslandWindow*>(_window.get());
const RECT frame = pCWindow->GetFrameBorderMargins(dpix);
proposedRect.left += frame.left;
islandFrame.top = -NonClientIslandWindow::topBorderVisibleHeight;
}

adjustedHeight = nonClient.bottom - nonClient.top;
adjustedWidth = nonClient.right - nonClient.left;
adjustedWidth = -islandFrame.left + islandWidth + islandFrame.right;
Copy link
Member

Choose a reason for hiding this comment

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

I'd maybe add a comment on why we don't need to do anything for the !_useNonClientArea case here

adjustedHeight = -islandFrame.top + islandHeight + islandFrame.bottom;
}

const COORD origin{ gsl::narrow<short>(proposedRect.left),
Expand Down Expand Up @@ -294,5 +265,5 @@ void AppHost::_UpdateTitleBarContent(const winrt::Windows::Foundation::IInspecta
// - <none>
void AppHost::_UpdateTheme(const winrt::TerminalApp::App&, const winrt::Windows::UI::Xaml::ElementTheme& arg)
{
_window->UpdateTheme(arg);
_window->OnApplicationThemeChanged(arg);
}
18 changes: 15 additions & 3 deletions src/cascadia/WindowsTerminal/BaseWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ class BaseWindow
WINRT_ASSERT(that);
WINRT_ASSERT(!that->_window);
that->_window = wil::unique_hwnd(window);
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(that));

EnableNonClientDpiScaling(window);
that->_currentDpi = GetDpiForWindow(window);
return that->_OnNcCreate(wparam, lparam);
}
else if (T* that = GetThisFromHandle(window))
{
Expand Down Expand Up @@ -245,6 +243,20 @@ class BaseWindow
std::wstring _title = L"";

bool _minimized = false;

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
virtual [[nodiscard]] LRESULT _OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
SetWindowLongPtr(_window.get(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));

EnableNonClientDpiScaling(_window.get());
_currentDpi = GetDpiForWindow(_window.get());

return DefWindowProc(_window.get(), WM_NCCREATE, wParam, lParam);
};
};

template<typename T>
Expand Down
11 changes: 1 addition & 10 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,6 @@ IRawElementProviderSimple* IslandWindow::_GetUiaProvider()
return _pUiaProvider;
}

RECT IslandWindow::GetFrameBorderMargins(unsigned int currentDpi)
{
const auto windowStyle = GetWindowStyle(_window.get());
const auto targetStyle = windowStyle & ~WS_DLGFRAME;
RECT frame{};
AdjustWindowRectExForDpi(&frame, targetStyle, false, GetWindowExStyle(_window.get()), currentDpi);
return frame;
}

// Method Description:
// - Called when the window has been resized (or maximized)
// Arguments:
Expand Down Expand Up @@ -300,7 +291,7 @@ void IslandWindow::OnAppInitialized()
// - arg: the ElementTheme to use as the new theme for the UI
// Return Value:
// - <none>
void IslandWindow::UpdateTheme(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme)
void IslandWindow::OnApplicationThemeChanged(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme)
{
_rootGrid.RequestedTheme(requestedTheme);
// Invalidate the window rect, so that we'll repaint any elements we're
Expand Down
4 changes: 1 addition & 3 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ class IslandWindow :

[[nodiscard]] virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
IRawElementProviderSimple* _GetUiaProvider();
RECT GetFrameBorderMargins(unsigned int currentDpi);
void OnResize(const UINT width, const UINT height) override;
void OnMinimize() override;
void OnRestore() override;
virtual void OnAppInitialized();
virtual void SetContent(winrt::Windows::UI::Xaml::UIElement content);
virtual void OnApplicationThemeChanged(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme);

virtual void Initialize();

void SetCreateCallback(std::function<void(const HWND, const RECT, winrt::TerminalApp::LaunchMode& launchMode)> pfn) noexcept;

void UpdateTheme(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme);

#pragma region IUiaWindow
void ChangeViewport(const SMALL_RECT /*NewWindow*/)
{
Expand Down
Loading