fix: revert 6ecf729 to fix Linux titlebar dark mode (#25055)

Fixes #24741
This commit is contained in:
Charles Kerr 2020-08-20 15:53:06 -05:00 committed by GitHub
parent 2d502b8ac6
commit d9a1c453ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 33 deletions

View file

@ -34,7 +34,6 @@
#include "ui/base/hit_test.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
#include "ui/views/controls/webview/webview.h"
@ -215,10 +214,10 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
window_state_watcher_ = std::make_unique<WindowStateWatcher>(this);
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
bool use_dark_theme =
ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
options.Get(options::kDarkTheme, &use_dark_theme);
SetGTKDarkThemeEnabled(use_dark_theme);
bool use_dark_theme = false;
if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
SetGTKDarkThemeEnabled(use_dark_theme);
}
// Before the window is mapped the SetWMSpecState can not work, so we have
// to manually set the _NET_WM_STATE.
@ -329,6 +328,20 @@ NativeWindowViews::~NativeWindowViews() {
#endif
}
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
#if defined(USE_X11)
if (use_dark_theme) {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "dark");
} else {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "light");
}
#endif
}
void NativeWindowViews::SetContentView(views::View* view) {
if (content_view()) {
root_view_->RemoveChildView(content_view());
@ -1291,20 +1304,6 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
}
#endif
#if defined(USE_X11)
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
if (use_dark_theme) {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "dark");
} else {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "light");
}
}
#endif
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
bool active) {
if (changed_widget != widget())