Merge pull request #4292 from nraffp/4291

respect gtk color scheme variant for gtk css variable
This commit is contained in:
Alexis Rouillard
2025-07-13 09:06:25 +02:00
committed by GitHub

View File

@ -151,15 +151,19 @@ void waybar::Client::handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> mon
const std::string waybar::Client::getStyle(const std::string &style, const std::string waybar::Client::getStyle(const std::string &style,
std::optional<Appearance> appearance = std::nullopt) { std::optional<Appearance> appearance = std::nullopt) {
auto gtk_settings = Gtk::Settings::get_default();
std::optional<std::string> css_file; std::optional<std::string> css_file;
if (style.empty()) { if (style.empty()) {
std::vector<std::string> search_files; std::vector<std::string> search_files;
switch (appearance.value_or(portal->getAppearance())) { switch (appearance.value_or(portal->getAppearance())) {
case waybar::Appearance::LIGHT: case waybar::Appearance::LIGHT:
search_files.emplace_back("style-light.css"); search_files.emplace_back("style-light.css");
gtk_settings->property_gtk_application_prefer_dark_theme() = false;
break; break;
case waybar::Appearance::DARK: case waybar::Appearance::DARK:
search_files.emplace_back("style-dark.css"); search_files.emplace_back("style-dark.css");
gtk_settings->property_gtk_application_prefer_dark_theme() = true;
break; break;
case waybar::Appearance::UNKNOWN: case waybar::Appearance::UNKNOWN:
break; break;
@ -169,9 +173,11 @@ const std::string waybar::Client::getStyle(const std::string &style,
} else { } else {
css_file = style; css_file = style;
} }
if (!css_file) { if (!css_file) {
throw std::runtime_error("Missing required resource files"); throw std::runtime_error("Missing required resource files");
} }
spdlog::info("Using CSS file {}", css_file.value()); spdlog::info("Using CSS file {}", css_file.value());
return css_file.value(); return css_file.value();
}; };