Skip to content

Commit

Permalink
Fix bugs with theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Depoire--Ferrer committed Jun 10, 2020
1 parent 58254a4 commit d1a074e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<!-- Define resources for Dark mode here -->
<SolidColorBrush x:Key="TabViewFocusedBackground" Color="#FF4D4D4D" />
<SolidColorBrush x:Key="TabViewUnfocusedBackground" Color="#FF333333" />
<SolidColorBrush x:Key="TabViewFocusedBackground" Color="#FF333333" />
<SolidColorBrush x:Key="TabViewUnfocusedBackground" Color="#FF474747" />
</ResourceDictionary>

<ResourceDictionary x:Key="Light">
<!-- Define resources for Light mode here -->
<SolidColorBrush x:Key="TabViewFocusedBackground" Color="#FFDDDDDD" />
<SolidColorBrush x:Key="TabViewUnfocusedBackground" Color="#FFB3B3B3" />
<SolidColorBrush x:Key="TabViewFocusedBackground" Color="#FFCCCCCC" />
<SolidColorBrush x:Key="TabViewUnfocusedBackground" Color="#FFDDDDDD" />
</ResourceDictionary>

</ResourceDictionary.ThemeDictionaries>
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ AppHost::AppHost() noexcept :

if (_useNonClientArea)
{
_window = std::make_unique<NonClientIslandWindow>(_logic.GetRequestedTheme());
_window = std::make_unique<NonClientIslandWindow>();
}
else
{
Expand Down Expand Up @@ -170,6 +170,9 @@ void AppHost::Initialize()
_window->SetContent(_logic.GetRoot());
_window->OnAppInitialized();

// set theme initially
_window->OnApplicationThemeChanged(_logic.GetRequestedTheme());

// THIS IS A HACK
//
// We've got a weird crash that happens terribly inconsistently, but pretty
Expand Down
39 changes: 4 additions & 35 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ using namespace ::Microsoft::Console::Types;

static constexpr int AutohideTaskbarSize = 2;

NonClientIslandWindow::NonClientIslandWindow(const ElementTheme& requestedTheme) noexcept :
NonClientIslandWindow::NonClientIslandWindow() noexcept :
IslandWindow{},
_backgroundBrushColor{ 0, 0, 0 },
_theme{ requestedTheme }
_backgroundBrushColor{ 0, 0, 0 }
{
}

Expand Down Expand Up @@ -690,39 +689,12 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
return ret;
}

// Set the frame's theme before it is rendered (WM_NCPAINT) so that it is
// rendered with the correct theme.
_UpdateFrameTheme();
// we always want a dark border
LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

return TRUE;
}

// Method Description:
// - Updates the window frame's theme depending on the application theme (light
// or dark). This doesn't invalidate the old frame so it will not be
// rerendered until the user resizes or focuses/unfocuses the window.
// Return Value:
// - <none>
void NonClientIslandWindow::_UpdateFrameTheme() const
{
bool isDarkMode;

switch (_theme)
{
case ElementTheme::Light:
isDarkMode = false;
break;
case ElementTheme::Dark:
isDarkMode = true;
break;
default:
isDarkMode = Application::Current().RequestedTheme() == ApplicationTheme::Dark;
break;
}

LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), isDarkMode));
}

// Method Description:
// - Update the input sink windows.
// - These windows are used to capture clicks on the non-client area.
Expand Down Expand Up @@ -815,9 +787,6 @@ void NonClientIslandWindow::_UpdateInputSinkWindows()
void NonClientIslandWindow::OnApplicationThemeChanged(const ElementTheme& requestedTheme)
{
IslandWindow::OnApplicationThemeChanged(requestedTheme);

_theme = requestedTheme;
_UpdateFrameTheme();
}

void NonClientIslandWindow::_PostSyscommand(const WPARAM wParam)
Expand Down
5 changes: 1 addition & 4 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NonClientIslandWindow : public IslandWindow
// this is the same for all DPIs
static constexpr const int topBorderVisibleHeight = 1;

NonClientIslandWindow(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme) noexcept;
NonClientIslandWindow() noexcept;
virtual ~NonClientIslandWindow() override;

void MakeWindow() noexcept override;
Expand Down Expand Up @@ -62,8 +62,6 @@ class NonClientIslandWindow : public IslandWindow

std::vector<InputSinkWindow> _inputSinkWindows;

winrt::Windows::UI::Xaml::ElementTheme _theme;

bool _isMaximized{ false };

void _PostSyscommand(const WPARAM wParam);
Expand Down Expand Up @@ -92,6 +90,5 @@ class NonClientIslandWindow : public IslandWindow
void _UpdateFrameMargins() const noexcept;
void _UpdateMaximizedState();
void _UpdateIslandPosition(const UINT windowWidth, const UINT windowHeight);
void _UpdateFrameTheme() const;
void _UpdateInputSinkWindows();
};

0 comments on commit d1a074e

Please sign in to comment.