chore: add SetGTKDarkThemeEnabled(enabled) internal helper to allow dynamic theme selection on linux (#19964)
This is just a after-creation setter for the `darkTheme` constructor option. This is delibrately a method and not a property as there is no getter.
This commit is contained in:
parent
bedc5f7da9
commit
cc9436f288
6 changed files with 30 additions and 6 deletions
|
@ -889,6 +889,10 @@ void TopLevelWindow::CloseFilePreview() {
|
||||||
window_->CloseFilePreview();
|
window_->CloseFilePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TopLevelWindow::SetGTKDarkThemeEnabled(bool use_dark_theme) {
|
||||||
|
window_->SetGTKDarkThemeEnabled(use_dark_theme);
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> TopLevelWindow::GetContentView() const {
|
v8::Local<v8::Value> TopLevelWindow::GetContentView() const {
|
||||||
if (content_view_.IsEmpty())
|
if (content_view_.IsEmpty())
|
||||||
return v8::Null(isolate());
|
return v8::Null(isolate());
|
||||||
|
|
|
@ -202,6 +202,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||||
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
|
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
|
||||||
void PreviewFile(const std::string& path, mate::Arguments* args);
|
void PreviewFile(const std::string& path, mate::Arguments* args);
|
||||||
void CloseFilePreview();
|
void CloseFilePreview();
|
||||||
|
void SetGTKDarkThemeEnabled(bool use_dark_theme);
|
||||||
|
|
||||||
// Public getters of NativeWindow.
|
// Public getters of NativeWindow.
|
||||||
v8::Local<v8::Value> GetContentView() const;
|
v8::Local<v8::Value> GetContentView() const;
|
||||||
|
|
|
@ -228,6 +228,8 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
const std::string& display_name);
|
const std::string& display_name);
|
||||||
virtual void CloseFilePreview();
|
virtual void CloseFilePreview();
|
||||||
|
|
||||||
|
virtual void SetGTKDarkThemeEnabled(bool use_dark_theme) = 0;
|
||||||
|
|
||||||
// Converts between content bounds and window bounds.
|
// Converts between content bounds and window bounds.
|
||||||
virtual gfx::Rect ContentBoundsToWindowBounds(
|
virtual gfx::Rect ContentBoundsToWindowBounds(
|
||||||
const gfx::Rect& bounds) const = 0;
|
const gfx::Rect& bounds) const = 0;
|
||||||
|
|
|
@ -137,6 +137,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
const std::vector<mate::PersistentDictionary>& items) override;
|
const std::vector<mate::PersistentDictionary>& items) override;
|
||||||
void RefreshTouchBarItem(const std::string& item_id) override;
|
void RefreshTouchBarItem(const std::string& item_id) override;
|
||||||
void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override;
|
void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override;
|
||||||
|
void SetGTKDarkThemeEnabled(bool use_dark_theme) override {}
|
||||||
|
|
||||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
|
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
|
||||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
|
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
|
||||||
|
|
|
@ -214,12 +214,7 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options,
|
||||||
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
|
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
|
||||||
bool use_dark_theme = false;
|
bool use_dark_theme = false;
|
||||||
if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
|
if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
|
||||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
SetGTKDarkThemeEnabled(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before the window is mapped the SetWMSpecState can not work, so we have
|
// Before the window is mapped the SetWMSpecState can not work, so we have
|
||||||
|
@ -330,6 +325,25 @@ NativeWindowViews::~NativeWindowViews() {
|
||||||
#endif
|
#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) {
|
void NativeWindowViews::SetContentView(views::View* view) {
|
||||||
if (content_view()) {
|
if (content_view()) {
|
||||||
root_view_->RemoveChildView(content_view());
|
root_view_->RemoveChildView(content_view());
|
||||||
|
|
|
@ -125,6 +125,8 @@ class NativeWindowViews : public NativeWindow,
|
||||||
|
|
||||||
bool IsVisibleOnAllWorkspaces() override;
|
bool IsVisibleOnAllWorkspaces() override;
|
||||||
|
|
||||||
|
void SetGTKDarkThemeEnabled(bool use_dark_theme) override;
|
||||||
|
|
||||||
content::DesktopMediaID GetDesktopMediaID() const override;
|
content::DesktopMediaID GetDesktopMediaID() const override;
|
||||||
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
||||||
NativeWindowHandle GetNativeWindowHandle() const override;
|
NativeWindowHandle GetNativeWindowHandle() const override;
|
||||||
|
|
Loading…
Reference in a new issue