Skip to content

Commit

Permalink
cleanup for review
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jul 6, 2020
1 parent 52084d5 commit fcb2d48
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 70 deletions.
101 changes: 41 additions & 60 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,67 +482,78 @@ void _SetWindowLongWHelper(const HWND hWnd, const int nIndex, const LONG dwNewLo
}
}

// Method Description:
// - This is a helper to figure out what the window styles should be, given the
// current state of flags like borderless mode and fullscreen mode.
// Arguments:
// - <none>
// Return Value:
// - a LONG with the appropriate flags set for our current window mode, to be used with GWL_STYLE
LONG IslandWindow::_getCurrentWindowStyle() const
{
auto windowStyle = GetWindowLongW(GetHandle(), GWL_STYLE);

// If we're both fullscreen and borderless, fullscreen mode takes precedence.

if (_fullscreen)
{
// When moving to fullscreen, remove WS_OVERLAPPEDWINDOW, which specifies
// styles for non-fullscreen windows (e.g. caption bar), and add the
// WS_POPUP style to allow us to size ourselves to the monitor size.
// Do the reverse when restoring from fullscreen.
// Doing these modifications to that window will cause a vista-style
// window frame to briefly appear when entering and exiting fullscreen.
WI_ClearFlag(windowStyle, WS_BORDER);
WI_ClearFlag(windowStyle, WS_SIZEBOX);
WI_ClearAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);

WI_SetFlag(windowStyle, WS_POPUP);
return windowStyle;
}
else if (_borderless && !_fullscreen)
{
// When moving to borderless, remove WS_OVERLAPPEDWINDOW, which
// specifies styles for non-fullscreen windows (e.g. caption bar), and
// add the WS_BORDER and WS_SIZEBOX styles. This allows us to still have
// a small resizing frame, but without a full titlebar, nor caption
// buttons.

WI_ClearAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
WI_ClearFlag(windowStyle, WS_POPUP);

WI_SetFlag(windowStyle, WS_BORDER);
WI_SetFlag(windowStyle, WS_SIZEBOX);
return windowStyle;
}

// Here, we're not in either fullscreen or borderless mode. Return to
// WS_OVERLAPPEDWINDOW.
WI_ClearFlag(windowStyle, WS_POPUP);
WI_ClearFlag(windowStyle, WS_BORDER);
WI_ClearFlag(windowStyle, WS_SIZEBOX);

WI_SetAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);

return windowStyle;
}

// Method Description:
// - Enable or disable borderless mode. When entering borderless mode, we'll
// need to manually hide the entire titlebar.
// - When we're entering borderless we need to do some additional modification
// of our window styles. However, the NonClientIslandWindow very explicitly
// _doesn't_ need to do these steps.
// Arguments:
// - borderlessEnabled: If true, we're entering borderless mode. If false, we're leaving.
// Return Value:
// - <none>
void IslandWindow::_SetIsBorderless(const bool borderlessEnabled)
{
// It is possible to enter _SetIsFullscreen even if we're already in full
// screen. Use the old is in fullscreen flag to gate checks that rely on the
// current state.
// const auto oldIsInBorderless = _borderless;
_borderless = borderlessEnabled;

HWND const hWnd = GetHandle();

// // First, modify regular window styles as appropriate
// auto windowStyle = GetWindowLongW(hWnd, GWL_STYLE);

// // When moving to fullscreen, remove WS_OVERLAPPEDWINDOW, which specifies
// // styles for non-fullscreen windows (e.g. caption bar), and add the
// // WS_POPUP style to allow us to size ourselves to the monitor size.
// // Do the reverse when restoring from fullscreen.
// // Doing these modifications to that window will cause a vista-style
// // window frame to briefly appear when entering and exiting fullscreen.
// if (_borderless && !_fullscreen)
// {
// WI_ClearAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
// // WI_SetFlag(windowStyle, WS_POPUP);
// WI_SetFlag(windowStyle, WS_BORDER);
// WI_SetFlag(windowStyle, WS_SIZEBOX);
// }
// else if (!_borderless && !_fullscreen)
// {
// // WI_ClearFlag(windowStyle, WS_POPUP);
// WI_ClearFlag(windowStyle, WS_BORDER);
// WI_ClearFlag(windowStyle, WS_SIZEBOX);
// WI_SetAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
// }

// First, modify regular window styles as appropriate
auto windowStyle = _getCurrentWindowStyle();
_SetWindowLongWHelper(hWnd, GWL_STYLE, windowStyle);

Expand Down Expand Up @@ -571,10 +582,6 @@ void IslandWindow::_SetIsBorderless(const bool borderlessEnabled)
// - When entering fullscreen mode, we'll save the current window size and
// location, and expand to take the entire monitor size. When leaving, we'll
// use that saved size to restore back to.
// - When we're entering fullscreen we need to do some additional modification
// of our window styles. However, the NonClientIslandWindow very explicitly
// _doesn't_ need to do these steps. Subclasses should override
// _ShouldUpdateStylesOnFullscreen to disable setting these window styles.
// Arguments:
// - fullscreenEnabled true if we should enable fullscreen mode, false to disable.
// Return Value:
Expand All @@ -590,35 +597,7 @@ void IslandWindow::_SetIsFullscreen(const bool fullscreenEnabled)
HWND const hWnd = GetHandle();

// First, modify regular window styles as appropriate
// auto windowStyle = GetWindowLongW(hWnd, GWL_STYLE);
auto windowStyle = _getCurrentWindowStyle();
// // When moving to fullscreen, remove WS_OVERLAPPEDWINDOW, which specifies
// // styles for non-fullscreen windows (e.g. caption bar), and add the
// // WS_POPUP style to allow us to size ourselves to the monitor size.
// // Do the reverse when restoring from fullscreen.
// // Doing these modifications to that window will cause a vista-style
// // window frame to briefly appear when entering and exiting fullscreen.
// if (_fullscreen)
// {
// WI_ClearAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
// WI_SetFlag(windowStyle, WS_POPUP);
// }
// else
// {
// WI_ClearFlag(windowStyle, WS_POPUP);
// }
// if (!_borderless)
// {
// WI_SetAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
// }
// else
// {
// WI_ClearAllFlags(windowStyle, WS_OVERLAPPEDWINDOW);
// // WI_SetFlag(windowStyle, WS_POPUP);
// WI_SetFlag(windowStyle, WS_BORDER);
// WI_SetFlag(windowStyle, WS_SIZEBOX);
// }

_SetWindowLongWHelper(hWnd, GWL_STYLE, windowStyle);

// Now modify extended window styles as appropriate
Expand All @@ -628,6 +607,8 @@ void IslandWindow::_SetIsFullscreen(const bool fullscreenEnabled)
WI_UpdateFlag(exWindowStyle, WS_EX_WINDOWEDGE, !_fullscreen);
_SetWindowLongWHelper(hWnd, GWL_EXSTYLE, exWindowStyle);

// When entering/exiting fullscreen mode, we also need to backup/restore the
// current window size, and resize the window to match the new state.
_BackupWindowSizes(oldIsInFullscreen);
_ApplyWindowSize();
}
Expand Down
24 changes: 14 additions & 10 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,11 @@ void NonClientIslandWindow::_ResizeDragBarWindow() noexcept
{
const til::rectangle rect{ _GetDragAreaRect() };
if (_IsTitlebarVisible() && rect.size().area() > 0)
// if ((_IsTitlebarVisible() || _borderless) && rect.size().area() > 0)
{
SetWindowPos(_dragBarWindow.get(),
HWND_TOP,
rect.left<int>(),
rect.top<int>() + _GetTopBorderHeight(),
// rect.top<int>() + (_borderless ? 1 : _GetTopBorderHeight()),
rect.width<int>(),
rect.height<int>(),
SWP_NOACTIVATE | SWP_SHOWWINDOW);
Expand Down Expand Up @@ -268,7 +266,6 @@ int NonClientIslandWindow::_GetTopBorderHeight() const noexcept
if (_isMaximized || (!_IsTitlebarVisible()))
{
// no border when maximized
// return (_borderless && !_fullscreen) ? 1 : 0; // This line seems to work really well, but the titlebar is then white when we lose focus, and that's horrible.
return 0;
}

Expand Down Expand Up @@ -619,8 +616,7 @@ SIZE NonClientIslandWindow::GetTotalNonClientExclusiveSize(UINT dpi) const noexc

// If we have a titlebar, this is being called after we've initialized, and
// we can just ask that titlebar how big it wants to be.
auto titleBarHeight = _titlebar ? static_cast<LONG>(_titlebar.ActualHeight()) : 0;
titleBarHeight += (_borderless && !_fullscreen) ? 1 : 0;
const auto titleBarHeight = _titlebar ? static_cast<LONG>(_titlebar.ActualHeight()) : 0;

return {
islandFrame.right - islandFrame.left,
Expand Down Expand Up @@ -660,10 +656,6 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
// so it should work fine.
margins.cyTopHeight = -frame.top;
}
// else if (_borderless)
// {
// margins.cyTopHeight = -1;
// }

// Extend the frame into the client area. microsoft/terminal#2735 - Just log
// the failure here, don't crash. If DWM crashes for any reason, calling
Expand Down Expand Up @@ -819,11 +811,23 @@ void NonClientIslandWindow::OnApplicationThemeChanged(const ElementTheme& reques
_theme = requestedTheme;
}

// Method Description:
// - Enable or disable borderless mode. When entering borderless mode, we'll
// need to manually hide the entire titlebar.
// - See also IslandWindow::_SetIsBorderless, which does similar, but different work.
// Arguments:
// - borderlessEnabled: If true, we're entering borderless mode. If false, we're leaving.
// Return Value:
// - <none>
void NonClientIslandWindow::_SetIsBorderless(const bool borderlessEnabled)
{
_borderless = borderlessEnabled;

// IslandWindow::_SetIsBorderless(borderlessEnabled);
// Explicitly _don't_ call IslandWindow::_SetIsBorderless. That version will
// change the window styles appropriately for the window with the detault
// titlebar, but for the tabs-in-titlebar mode, we can just get rid of the
// title bar entirely.

if (_titlebar)
{
_titlebar.Visibility(_IsTitlebarVisible() ? Visibility::Visible : Visibility::Collapsed);
Expand Down

1 comment on commit fcb2d48

@github-actions

This comment was marked as resolved.

Please sign in to comment.