feat: add immersive dark mode on windows (#33624)
* feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
parent
21ef8501e7
commit
4c7c0b41c2
10 changed files with 55 additions and 182 deletions
|
@ -7,13 +7,10 @@
|
|||
#include "base/win/windows_version.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "shell/browser/ui/views/win_frame_view.h"
|
||||
#include "shell/browser/win/dark_mode.h"
|
||||
#include "ui/base/win/hwnd_metrics.h"
|
||||
#include "ui/base/win/shell.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIN_DARK_MODE_WINDOW_UI)
|
||||
#include "shell/browser/win/dark_mode.h"
|
||||
#endif
|
||||
|
||||
namespace electron {
|
||||
|
||||
ElectronDesktopWindowTreeHostWin::ElectronDesktopWindowTreeHostWin(
|
||||
|
@ -29,14 +26,13 @@ bool ElectronDesktopWindowTreeHostWin::PreHandleMSG(UINT message,
|
|||
WPARAM w_param,
|
||||
LPARAM l_param,
|
||||
LRESULT* result) {
|
||||
#if BUILDFLAG(ENABLE_WIN_DARK_MODE_WINDOW_UI)
|
||||
if (message == WM_NCCREATE) {
|
||||
HWND const hwnd = GetAcceleratedWidget();
|
||||
auto const theme_source =
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->theme_source();
|
||||
win::SetDarkModeForWindow(hwnd, theme_source);
|
||||
const bool dark_mode_supported = win::IsDarkModeSupported();
|
||||
if (dark_mode_supported && message == WM_NCCREATE) {
|
||||
win::SetDarkModeForWindow(GetAcceleratedWidget());
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->AddObserver(this);
|
||||
} else if (dark_mode_supported && message == WM_DESTROY) {
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
return native_window_view_->PreHandleMSG(message, w_param, l_param, result);
|
||||
}
|
||||
|
@ -99,4 +95,9 @@ bool ElectronDesktopWindowTreeHostWin::GetClientAreaInsets(
|
|||
return false;
|
||||
}
|
||||
|
||||
void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated(
|
||||
ui::NativeTheme* observed_theme) {
|
||||
win::SetDarkModeForWindow(GetAcceleratedWidget());
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace electron {
|
||||
|
||||
class ElectronDesktopWindowTreeHostWin
|
||||
: public views::DesktopWindowTreeHostWin {
|
||||
class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
|
||||
public ::ui::NativeThemeObserver {
|
||||
public:
|
||||
ElectronDesktopWindowTreeHostWin(
|
||||
NativeWindowViews* native_window_view,
|
||||
|
@ -37,6 +37,9 @@ class ElectronDesktopWindowTreeHostWin
|
|||
bool GetClientAreaInsets(gfx::Insets* insets,
|
||||
HMONITOR monitor) const override;
|
||||
|
||||
// ui::NativeThemeObserver:
|
||||
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
||||
|
||||
private:
|
||||
NativeWindowViews* native_window_view_; // weak ref
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue