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 a dark titlebar when we've requested dark theme #14536

Merged
75 commits merged into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8c3c8fe
Revert "Remove the `useMica` key (#13872)"
zadjii-msft Sep 6, 2022
0a3a537
Clip the drag rect to the right side of the window. I don't think thi…
zadjii-msft Sep 6, 2022
2fcc420
add support for transparent titlebars back, for testing.
zadjii-msft Sep 6, 2022
337c5e9
hey this works - let's clean it up and figure out what is/n't important
zadjii-msft Sep 6, 2022
c77173b
Add better support in the Theme objects themselves for transparency
zadjii-msft Sep 6, 2022
df6d4cd
way easier
zadjii-msft Sep 6, 2022
2895a34
notes, mostly
zadjii-msft Sep 6, 2022
3d5d88a
inintial buggy fix for syncing OS themes
Sep 23, 2022
5f54750
fixed control preview bug
Oct 3, 2022
43cc9fa
Code cleanup
Oct 3, 2022
e4c2d20
Code cleanup
Oct 3, 2022
b1c5342
updated bug, where custom themes would not update the color scheme
Oct 10, 2022
e4f3625
updated bug, where custom themes would not update the color scheme
Oct 11, 2022
c16b998
PR lhecker comments
Oct 13, 2022
4e40eff
formatting fix
Oct 19, 2022
367d38c
formatting fix
Oct 20, 2022
c42965e
Merge branch 'main' into dev/migrie/f/transparent-tab-row-002
zadjii-msft Nov 2, 2022
e9f8569
hey, we can use the real api now
zadjii-msft Nov 3, 2022
4964d8b
Merge remote-tracking branch 'origin/main' into dev/migrie/f/transpar…
zadjii-msft Nov 14, 2022
9058c41
runformat
zadjii-msft Nov 14, 2022
28cf394
Migrate spelling-0.0.21 changes from main
DHowett Nov 14, 2022
fdc2c80
Merge remote-tracking branch 'origin/main' into ThemeControlledColorS…
zadjii-msft Nov 14, 2022
8e08d75
I think this is going to be way easier to manage
zadjii-msft Nov 15, 2022
a0e28f1
UI is better. Not good, but better
zadjii-msft Nov 15, 2022
b64b032
hot reloading
zadjii-msft Nov 15, 2022
1b81da9
cleanup some todos
zadjii-msft Nov 15, 2022
d71c56e
schema too folks
zadjii-msft Nov 15, 2022
e70ac18
goodbye LoadSettings, ReloadSettings is my best friend now
zadjii-msft Nov 15, 2022
11460d6
yep. This is just as dumb as it seems
zadjii-msft Nov 16, 2022
b969353
tests man, tests (thread)
zadjii-msft Nov 16, 2022
c823fe6
these weren't me!
zadjii-msft Nov 16, 2022
816c249
Merge remote-tracking branch 'origin/main' into dev/migrie/f/transpar…
zadjii-msft Nov 30, 2022
4e51484
Merge remote-tracking branch 'origin/main' into ThemeControlledColorS…
zadjii-msft Nov 30, 2022
74cf07e
Merge remote-tracking branch 'origin/main' into dev/migrie/f/transpar…
zadjii-msft Dec 1, 2022
28a718a
REAALLY
zadjii-msft Dec 1, 2022
c652e95
uhg
zadjii-msft Dec 1, 2022
9f251dd
Merge remote-tracking branch 'origin/main' into ThemeControlledColorS…
zadjii-msft Dec 1, 2022
1260705
remove this scheme
zadjii-msft Dec 1, 2022
109ecd9
Merge remote-tracking branch 'origin/main' into ThemeControlledColorS…
zadjii-msft Dec 2, 2022
1aa3675
first off, plumbing
zadjii-msft Dec 2, 2022
a14574a
secondly, this is _awesome
zadjii-msft Dec 2, 2022
fc6ef60
Just a comment
zadjii-msft Dec 2, 2022
ef6f660
Merge remote-tracking branch 'origin/main' into ThemeControlledColorS…
zadjii-msft Dec 6, 2022
c56a424
yea I dig it
zadjii-msft Dec 6, 2022
156e952
Merge branch 'ThemeControlledColorSchemeSwitch' into dev/migrie/f/the…
zadjii-msft Dec 6, 2022
77d00ee
prep for review
zadjii-msft Dec 6, 2022
a10dfe4
spel
zadjii-msft Dec 6, 2022
14f38f3
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Dec 6, 2022
a22f433
Merge remote-tracking branch 'origin/main' into dev/migrie/f/transpar…
zadjii-msft Dec 8, 2022
976688a
THIS WONT WORK Don't blow away titlebar This should satisfy the remai…
zadjii-msft Dec 8, 2022
6dd6726
also, account for how transparent a titlebar might be
zadjii-msft Dec 8, 2022
5fb76f0
Attempt to sync titlebar & mica effect to window theme. I need the th…
zadjii-msft Dec 8, 2022
84c694b
Merge remote-tracking branch 'origin/dev/migrie/f/theme-theme-switch-…
zadjii-msft Dec 8, 2022
9ff12c8
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Dec 8, 2022
f11220f
dead code and spel
zadjii-msft Dec 8, 2022
0fac998
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Dec 9, 2022
85d6f92
why DONT we just not
zadjii-msft Dec 9, 2022
c176c71
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Dec 9, 2022
239e349
Merge remote-tracking branch 'origin/main' into dev/migrie/b/dark-tit…
zadjii-msft Dec 12, 2022
40afe5e
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Dec 12, 2022
0c26003
Merge branch 'dev/migrie/f/theme-theme-switch-switch' into dev/migrie…
zadjii-msft Dec 12, 2022
bc1b385
Merge remote-tracking branch 'origin/main' into dev/migrie/f/theme-th…
zadjii-msft Jan 12, 2023
7666478
minor nits
zadjii-msft Jan 12, 2023
04532b3
Merge remote-tracking branch 'origin/main' into HEAD
DHowett Jan 13, 2023
fa72cb4
Merge commit '766647833b9d2c7917ed0d831067ac539dba76bd' into dev/migr…
DHowett Jan 13, 2023
10ccaf1
Merge commit '04532b3723f23b6b8c503be8077c05fbba5f4448' into dev/migr…
DHowett Jan 13, 2023
ca0b205
Merge remote-tracking branch 'origin/main' into dev/migrie/b/dark-tit…
zadjii-msft Jan 13, 2023
feda2be
Okay, this is more sensible
zadjii-msft Jan 16, 2023
b605cd3
Merge remote-tracking branch 'origin/main' into dev/migrie/b/dark-tit…
zadjii-msft Jan 16, 2023
4059dcc
straight up, I don't like this rule
zadjii-msft Jan 16, 2023
d02bbcd
Merge remote-tracking branch 'origin/main' into dev/migrie/b/dark-tit…
zadjii-msft Jan 18, 2023
d7d0065
hey we don't need this anymore
zadjii-msft Jan 18, 2023
be568cf
in retrospect, maybe we do want this
zadjii-msft Jan 18, 2023
c0ada4b
Merge remote-tracking branch 'origin/main' into dev/migrie/b/dark-tit…
zadjii-msft Jan 18, 2023
85f1e99
okay we dont need it, we need it, but not this
zadjii-msft Jan 19, 2023
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
3 changes: 1 addition & 2 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "../../types/inc/Utils.hpp"
#include "JsonUtils.h"
#include "KeyChordSerialization.h"
#include "SettingsUtils.h"

#include "GlobalAppSettings.g.cpp"

Expand Down Expand Up @@ -213,7 +212,7 @@ Json::Value GlobalAppSettings::ToJson() const

winrt::Microsoft::Terminal::Settings::Model::Theme GlobalAppSettings::CurrentTheme() noexcept
{
auto requestedTheme = IsSystemInDarkTheme() ?
auto requestedTheme = Model::Theme::IsSystemInDarkTheme() ?
winrt::Windows::UI::Xaml::ElementTheme::Dark :
winrt::Windows::UI::Xaml::ElementTheme::Light;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
<ClInclude Include="WslDistroGenerator.h" />
<ClInclude Include="SshHostGenerator.h" />
<ClInclude Include="ModelSerializationHelpers.h" />
<ClInclude Include="SettingsUtils.h" />
</ItemGroup>
<!-- ========================= Cpp Files ======================== -->
<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions src/cascadia/TerminalSettingsModel/SettingsUtils.h

This file was deleted.

13 changes: 1 addition & 12 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@

#include "TerminalSettings.g.cpp"
#include "TerminalSettingsCreateResult.g.cpp"
#include "SettingsUtils.h"

using namespace winrt::Microsoft::Terminal::Control;
using namespace Microsoft::Console::Utils;

// I'm not even joking, this is the recommended way to do this:
// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes#know-when-dark-mode-is-enabled
bool IsSystemInDarkTheme()
{
static auto isColorLight = [](const winrt::Windows::UI::Color& clr) -> bool {
return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
};
return isColorLight(winrt::Windows::UI::ViewManagement::UISettings().GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Foreground));
};

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
static std::tuple<Windows::UI::Xaml::HorizontalAlignment, Windows::UI::Xaml::VerticalAlignment> ConvertConvergedAlignment(ConvergedAlignment alignment)
Expand Down Expand Up @@ -204,7 +193,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto requestedTheme = currentTheme.RequestedTheme();
if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default)
{
requestedTheme = IsSystemInDarkTheme() ?
requestedTheme = Model::Theme::IsSystemInDarkTheme() ?
winrt::Windows::UI::Xaml::ElementTheme::Dark :
winrt::Windows::UI::Xaml::ElementTheme::Light;
}
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,13 @@ winrt::com_ptr<ThemePair> ThemePair::Copy() const
pair->_LightName = _LightName;
return pair;
}

// I'm not even joking, this is the recommended way to do this:
// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes#know-when-dark-mode-is-enabled
bool Theme::IsSystemInDarkTheme()
{
static auto isColorLight = [](const winrt::Windows::UI::Color& clr) -> bool {
return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
};
return isColorLight(winrt::Windows::UI::ViewManagement::UISettings().GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Foreground));
};
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

winrt::Windows::UI::Xaml::ElementTheme RequestedTheme() const noexcept;

static bool IsSystemInDarkTheme();

WINRT_PROPERTY(winrt::hstring, Name);

MTSM_THEME_SETTINGS(THEME_SETTINGS_INITIALIZE)
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace Microsoft.Terminal.Settings.Model

// A helper for retrieving the RequestedTheme out of the window property
Windows.UI.Xaml.ElementTheme RequestedTheme { get; };
static Boolean IsSystemInDarkTheme();

}
}
20 changes: 20 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,20 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou
}
}

bool _isActuallyDarkTheme(const auto requestedTheme)
{
switch (requestedTheme)
{
case winrt::Windows::UI::Xaml::ElementTheme::Light:
return false;
case winrt::Windows::UI::Xaml::ElementTheme::Dark:
return true;
case winrt::Windows::UI::Xaml::ElementTheme::Default:
default:
return Theme::IsSystemInDarkTheme();
}
}

void AppHost::_updateTheme()
{
auto theme = _logic.Theme();
Expand All @@ -1353,6 +1367,12 @@ void AppHost::_updateTheme()
const auto b = _logic.TitlebarBrush();
const auto opacity = b ? ThemeColor::ColorFromBrush(b).A / 255.0 : 0.0;
_window->UseMica(theme.Window() ? theme.Window().UseMica() : false, opacity);

// This is a hack to make the window borders dark instead of light.
// It must be done before WM_NCPAINT so that the borders are rendered with
// the correct theme.
// For more information, see GH#6620.
LOG_IF_FAILED(TerminalTrySetDarkTheme(_window->GetHandle(), _isActuallyDarkTheme(theme.RequestedTheme())));
}

void AppHost::_HandleSettingsChanged(const winrt::Windows::Foundation::IInspectable& /*sender*/,
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/WindowsTerminal/BaseWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseWindow
WINRT_ASSERT(!that->_window);
that->_window = wil::unique_hwnd(window);

return that->_OnNcCreate(wparam, lparam);
return that->OnNcCreate(wparam, lparam);
}
else if (T* that = GetThisFromHandle(window))
{
Expand Down Expand Up @@ -214,7 +214,7 @@ class BaseWindow
// - 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
virtual [[nodiscard]] LRESULT OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
SetWindowLongPtr(_window.get(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));

Expand Down
26 changes: 26 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1913,3 +1913,29 @@ void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/
const int attribute = newValue ? DWMSBT_MAINWINDOW : DWMSBT_NONE;
std::ignore = DwmSetWindowAttribute(GetHandle(), DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute));
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT IslandWindow::OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
const auto ret = BaseWindow::OnNcCreate(wParam, lParam);
if (!ret)
{
return FALSE;
}

// This is a hack to make the window borders dark instead of light.
// It must be done before WM_NCPAINT so that the borders are rendered with
// the correct theme.
// For more information, see GH#6620.
//
// Theoretically, we don't need this anymore, since _updateTheme will update
// the darkness of our window. However, we're keeping this call to prevent
// the window from appearing as a white rectangle for a frame before we load
// the rest of the settings.
LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

return TRUE;
}
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class IslandWindow :
HWND GetInteropHandle() const;

[[nodiscard]] virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;

[[nodiscard]] LRESULT OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept override;

void OnResize(const UINT width, const UINT height) override;
void OnMinimize() override;
void OnRestore() override;
Expand Down
21 changes: 0 additions & 21 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,27 +1044,6 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
return 0;
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT NonClientIslandWindow::_OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
const auto ret = IslandWindow::_OnNcCreate(wParam, lParam);
if (!ret)
{
return FALSE;
}

// This is a hack to make the window borders dark instead of light.
// It must be done before WM_NCPAINT so that the borders are rendered with
// the correct theme.
// For more information, see GH#6620.
LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

return TRUE;
}

// Method Description:
// - Called when the app wants to change its theme. We'll update the frame
// theme to match the new theme.
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class NonClientIslandWindow : public IslandWindow
int _GetTopBorderHeight() const noexcept;
LRESULT _dragBarNcHitTest(const til::point pointer);

[[nodiscard]] LRESULT _OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept override;
[[nodiscard]] LRESULT _OnNcCalcSize(const WPARAM wParam, const LPARAM lParam) noexcept;
[[nodiscard]] LRESULT _OnNcHitTest(POINT ptMouse) const noexcept;
[[nodiscard]] LRESULT _OnPaint() noexcept;
Expand Down