feat: default gtk darkTheme option to nativeTheme.shouldUseDarkColors for better platform support (#20138)
* feat: default gtk darkTheme option to nativeTheme.shouldUseDarkColors for better platform support * chore: update syntax for PR feedback * refactor: only define SetGTKDarkThemeEnabled when needed Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
parent
a3e28788ce
commit
6ecf729487
8 changed files with 38 additions and 36 deletions
|
@ -34,6 +34,7 @@
|
|||
#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"
|
||||
|
@ -212,10 +213,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 = false;
|
||||
if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
|
||||
SetGTKDarkThemeEnabled(use_dark_theme);
|
||||
}
|
||||
bool use_dark_theme =
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
|
||||
options.Get(options::kDarkTheme, &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.
|
||||
|
@ -325,25 +326,6 @@ NativeWindowViews::~NativeWindowViews() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
|
||||
#if defined(USE_X11)
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
if (use_dark_theme) {
|
||||
XChangeProperty(xdisplay, GetAcceleratedWidget(),
|
||||
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
|
||||
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
|
||||
PropModeReplace,
|
||||
reinterpret_cast<const unsigned char*>("dark"), 4);
|
||||
} else {
|
||||
XChangeProperty(xdisplay, GetAcceleratedWidget(),
|
||||
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
|
||||
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
|
||||
PropModeReplace,
|
||||
reinterpret_cast<const unsigned char*>("light"), 5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetContentView(views::View* view) {
|
||||
if (content_view()) {
|
||||
root_view_->RemoveChildView(content_view());
|
||||
|
@ -1292,6 +1274,25 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_X11)
|
||||
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
if (use_dark_theme) {
|
||||
XChangeProperty(xdisplay, GetAcceleratedWidget(),
|
||||
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
|
||||
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
|
||||
PropModeReplace,
|
||||
reinterpret_cast<const unsigned char*>("dark"), 4);
|
||||
} else {
|
||||
XChangeProperty(xdisplay, GetAcceleratedWidget(),
|
||||
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
|
||||
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
|
||||
PropModeReplace,
|
||||
reinterpret_cast<const unsigned char*>("light"), 5);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
||||
bool active) {
|
||||
if (changed_widget != widget())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue