Skip to content

Commit

Permalink
Fixes Github #100: Problems with dark Adwaita theme in GTK 3.14 (repo…
Browse files Browse the repository at this point in the history
…rted by majutsushi)
  • Loading branch information
lwindolf committed Oct 11, 2014
1 parent 61d08d7 commit 1aff252
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ To be released
(suggested by DanMan)
* Fixes Github #98: Stop calling Atom person constructs w/ URI invalid
(patch by Aristotle Pagaltzis)
* Fixes Github #100: Problems with dark Adwaita theme in GTK 3.14
(reported by majutsushi)


2014-08-24 Lars Windolf <[email protected]>
Expand Down
43 changes: 41 additions & 2 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ render_calculate_theme_color (const gchar *name, GdkColor themeColor)
return tc;
}

static gint
render_get_rgb_distance (GdkColor *c1, GdkColor *c2)
{
return abs(
(299 * c1->red/256 +
587 * c1->green/256 +
114 * c1->blue/256) -
(299 * c2->red/256 +
587 * c2->green/256 +
114 * c2->blue/256)
) / 1000;
}

void
render_init_theme_colors (GtkWidget *widget)
{
Expand All @@ -197,8 +210,18 @@ render_init_theme_colors (GtkWidget *widget)
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-LIGHT", style->light[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-DARK", style->dark[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-MID", style->mid[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-BASE", style->base[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-TEXT", style->text[GTK_STATE_NORMAL]));

/* Sanity check text+base color as this causes many problems on dark
themes. If brightness distance is not enough we set text to fg/bg
which is always safe. */
if (render_get_rgb_distance (&style->base[GTK_STATE_NORMAL], &style->text[GTK_STATE_NORMAL]) > 150) {
// FIXME: Use theme labels instead of GTK-COLOR-<something> (e.g. CSS-BACKGROUND)
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-BASE", style->base[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-TEXT", style->text[GTK_STATE_NORMAL]));
} else {
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-BASE", style->bg[GTK_STATE_NORMAL]));
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("GTK-COLOR-TEXT", style->fg[GTK_STATE_NORMAL]));
}

color = NULL;
gtk_widget_style_get (widget, "link-color", &color, NULL);
Expand Down Expand Up @@ -231,6 +254,22 @@ render_init_theme_colors (GtkWidget *widget)
if (textAvg > bgAvg) {
debug0 (DEBUG_HTML, "Dark GTK theme detected.");
darkTheme = TRUE;
}

if (darkTheme) {
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_BG", style->text[GTK_STATE_NORMAL]));
/* Try nice foreground with 'fg' color (note: distance 50 is enough because it should be non-intrusive) */
if (render_get_rgb_distance (&style->text[GTK_STATE_NORMAL], &style->fg[GTK_STATE_NORMAL]) > 50)
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_FG", style->fg[GTK_STATE_NORMAL]));
else
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_FG", style->bg[GTK_STATE_NORMAL]));
} else {
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_FG", style->bg[GTK_STATE_NORMAL]));
/* Try nice foreground with 'dark' color (note: distance 50 is enough because it should be non-intrusive) */
if (render_get_rgb_distance (&style->dark[GTK_STATE_NORMAL], &style->bg[GTK_STATE_NORMAL]) > 50)
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_BG", style->dark[GTK_STATE_NORMAL]));
else
themeColors = g_slist_append (themeColors, render_calculate_theme_color ("FEEDLIST_UNREAD_BG", style->fg[GTK_STATE_NORMAL]));
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/ui/feed_list_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,8 @@ feed_list_node_update (const gchar *nodeId)
if (!countColor) {
const gchar *bg = NULL, *fg = NULL;

if (render_is_dark_theme ()) {
bg = render_get_theme_color ("GTK-COLOR-TEXT");
fg = render_get_theme_color ("GTK-COLOR-BG");
} else {
bg = render_get_theme_color ("GTK-COLOR-DARK");
fg = render_get_theme_color ("GTK-COLOR-BG");
}

bg = render_get_theme_color ("FEEDLIST_UNREAD_BG");
fg = render_get_theme_color ("FEEDLIST_UNREAD_FG");
if (fg && bg) {
countColor = g_strdup_printf ("foreground='#%s' background='#%s'", fg, bg);
debug1 (DEBUG_HTML, "Feed list unread CSS: %s\n", countColor);
Expand Down

0 comments on commit 1aff252

Please sign in to comment.