mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-25 21:35:33 +00:00
Implement theme-aware red text colors for dark theme legibility
Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com>
This commit is contained in:
committed by
Alexander Shaduri
co-authored by
ashaduri
parent
ef30450c5f
commit
6de9bb897d
@@ -13,10 +13,37 @@ Copyright:
|
||||
#define WARNING_COLORS_H
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "storage_property.h"
|
||||
|
||||
|
||||
/// Check if a dark GTK theme is currently active
|
||||
inline bool is_dark_theme_active()
|
||||
{
|
||||
// Try to get the GTK settings to check for dark theme preference
|
||||
Glib::RefPtr<Gtk::Settings> settings = Gtk::Settings::get_default();
|
||||
if (settings) {
|
||||
// Check if the application prefers dark theme
|
||||
bool prefer_dark = false;
|
||||
settings->get_property("gtk-application-prefer-dark-theme", prefer_dark);
|
||||
if (prefer_dark) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check theme name for common dark theme identifiers
|
||||
Glib::ustring theme_name;
|
||||
settings->get_property("gtk-theme-name", theme_name);
|
||||
std::string theme_str = theme_name.lowercase();
|
||||
if (theme_str.find("dark") != std::string::npos ||
|
||||
theme_str.find("black") != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// Get colors for tree rows according to warning severity.
|
||||
/// \return true if the colors were changed.
|
||||
@@ -45,14 +72,16 @@ inline bool app_property_get_row_highlight_colors(WarningLevel warning, std::str
|
||||
/// \return true if the color was changed.
|
||||
inline bool app_property_get_label_highlight_color(WarningLevel warning, std::string& fg)
|
||||
{
|
||||
bool dark_theme = is_dark_theme_active();
|
||||
|
||||
if (warning == WarningLevel::Notice) {
|
||||
fg = "#770000"; // very dark red
|
||||
fg = dark_theme ? "#FF9999" : "#770000"; // lighter red for dark themes, very dark red for light themes
|
||||
|
||||
} else if (warning == WarningLevel::Warning) {
|
||||
fg = "#C00000"; // dark red
|
||||
fg = dark_theme ? "#FF6666" : "#C00000"; // lighter red for dark themes, dark red for light themes
|
||||
|
||||
} else if (warning == WarningLevel::Alert) {
|
||||
fg = "#FF0000"; // red
|
||||
fg = dark_theme ? "#FF4444" : "#FF0000"; // lighter/pink red for dark themes, bright red for light themes
|
||||
}
|
||||
|
||||
return !(fg.empty());
|
||||
|
||||
@@ -2444,7 +2444,10 @@ gboolean GscInfoWindow::test_idle_callback(void* data)
|
||||
break;
|
||||
case SelfTestStatusSeverity::Error:
|
||||
if (!result_main_msg.empty()) { // Highlight in red
|
||||
result_main_msg = "<span color=\"#FF0000\">"s + result_main_msg + "</span>";
|
||||
std::string alert_color;
|
||||
// Use the same color as Alert level warnings for consistency
|
||||
app_property_get_label_highlight_color(WarningLevel::Alert, alert_color);
|
||||
result_main_msg = "<span color=\"" + alert_color + "\">"s + result_main_msg + "</span>";
|
||||
}
|
||||
result_details_msg += "\n"s + _("Check the Self-Test Log for more information.");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user