summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2017-09-22 03:08:09 +0000
committerGary Kramlich <grim@reaperworld.com>2017-09-22 03:08:09 +0000
commit0fe2280965184b5d9777f1f65a8b079ce91573d8 (patch)
tree48dacd18832edb4b93f8f9e24a0cbfc574aa11e8
parent785855509fa278c12192414e8b4f9397476e5d80 (diff)
parent79ba7ecbe6cd634ce0bce3bdb7f536e68b194677 (diff)
downloadpidgin-0fe2280965184b5d9777f1f65a8b079ce91573d8.tar.gz
Merged in rw_grim/pidgin/release-2.x.y (pull request #254)
Fixes for dark color themes Approved-by: Eion Robb <eionrobb@gmail.com>
-rw-r--r--pidgin/Makefile.am2
-rw-r--r--pidgin/gtkblist.c15
-rw-r--r--pidgin/gtkconv.c89
-rw-r--r--pidgin/gtkimhtml.c2
-rw-r--r--pidgin/gtkstyle.c70
-rw-r--r--pidgin/gtkstyle.h59
6 files changed, 198 insertions, 39 deletions
diff --git a/pidgin/Makefile.am b/pidgin/Makefile.am
index 84d927ba59..09fa65ca39 100644
--- a/pidgin/Makefile.am
+++ b/pidgin/Makefile.am
@@ -81,6 +81,7 @@ pidgin_SOURCES = \
gtksourceview-marshal.c \
gtkstatus-icon-theme.c \
gtkstatusbox.c \
+ gtkstyle.c \
gtkthemes.c \
gtkutils.c \
gtkwhiteboard.c \
@@ -131,6 +132,7 @@ pidgin_headers = \
gtksourceview-marshal.h \
gtkstatus-icon-theme.h \
gtkstatusbox.h \
+ gtkstyle.h \
pidginstock.h \
gtkthemes.h \
gtkutils.h \
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
index 125788e920..029db85d76 100644
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -60,6 +60,7 @@
#include "gtkstatusbox.h"
#include "gtkscrollbook.h"
#include "gtksmiley.h"
+#include "gtkstyle.h"
#include "gtkblist-theme.h"
#include "gtkblist-theme-loader.h"
#include "gtkutils.h"
@@ -4178,7 +4179,7 @@ theme_font_get_face_default(PidginThemeFont *font, const char *def)
gchar *
pidgin_blist_get_name_markup(PurpleBuddy *b, gboolean selected, gboolean aliased)
{
- const char *name, *name_color, *name_font, *status_color, *status_font;
+ const char *name, *name_color, *name_font, *status_color, *status_font, *dim_grey;
char *text = NULL;
PurplePlugin *prpl;
PurplePluginProtocolInfo *prpl_info = NULL;
@@ -4281,13 +4282,15 @@ pidgin_blist_get_name_markup(PurpleBuddy *b, gboolean selected, gboolean aliased
theme = pidgin_blist_get_theme();
name_color = NULL;
+ dim_grey = pidgin_style_is_dark(NULL) ? "light slate grey" : "dim grey";
+
if (theme) {
if (purple_presence_is_idle(presence)) {
namefont = statusfont = pidgin_blist_theme_get_idle_text_info(theme);
- name_color = "dim grey";
+ name_color = dim_grey;
} else if (!purple_presence_is_online(presence)) {
namefont = pidgin_blist_theme_get_offline_text_info(theme);
- name_color = "dim grey";
+ name_color = dim_grey;
statusfont = pidgin_blist_theme_get_status_text_info(theme);
} else if (purple_presence_is_available(presence)) {
namefont = pidgin_blist_theme_get_online_text_info(theme);
@@ -4301,14 +4304,14 @@ pidgin_blist_get_name_markup(PurpleBuddy *b, gboolean selected, gboolean aliased
&& (purple_presence_is_idle(presence)
|| !purple_presence_is_online(presence)))
{
- name_color = "dim grey";
+ name_color = dim_grey;
}
}
name_color = theme_font_get_color_default(namefont, name_color);
name_font = theme_font_get_face_default(namefont, "");
- status_color = theme_font_get_color_default(statusfont, "dim grey");
+ status_color = theme_font_get_color_default(statusfont, dim_grey);
status_font = theme_font_get_face_default(statusfont, "");
if (aliased && selected) {
@@ -6535,7 +6538,7 @@ static void buddy_node(PurpleBuddy *buddy, GtkTreeIter *iter, PurpleBlistNode *n
textcolor = pidgin_theme_font_get_color_describe(pair);
else
/* If no theme them default to making idle buddy names grey */
- textcolor = "dim grey";
+ textcolor = pidgin_style_is_dark(NULL) ? "light slate grey" : "dim grey";
if (textcolor) {
idle = g_strdup_printf("<span color='%s' font_desc='%s'>%d:%02d</span>",
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
index b98c6375ef..d04997e682 100644
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -63,6 +63,7 @@
#include "gtkpounce.h"
#include "gtkprefs.h"
#include "gtkprivacy.h"
+#include "gtkstyle.h"
#include "gtkthemes.h"
#include "gtkutils.h"
#include "pidginstock.h"
@@ -8176,41 +8177,57 @@ pidgin_conversations_init(void)
purple_signal_connect(purple_conversations_get_handle(), "wrote-chat-msg", handle,
PURPLE_CALLBACK(wrote_msg_update_unseen_cb), NULL);
- {
- /* Set default tab colors */
- GString *str = g_string_new(NULL);
- GtkSettings *settings = gtk_settings_get_default();
- GtkStyle *parent = gtk_rc_get_style_by_paths(settings, "tab-container.tab-label*", NULL, G_TYPE_NONE), *now;
- struct {
- const char *stylename;
- const char *labelname;
- const char *color;
- } styles[] = {
- {"pidgin_tab_label_typing_default", "tab-label-typing", "#4e9a06"},
- {"pidgin_tab_label_typed_default", "tab-label-typed", "#c4a000"},
- {"pidgin_tab_label_attention_default", "tab-label-attention", "#006aff"},
- {"pidgin_tab_label_unreadchat_default", "tab-label-unreadchat", "#cc0000"},
- {"pidgin_tab_label_event_default", "tab-label-event", "#888a85"},
- {NULL, NULL, NULL}
- };
- int iter;
- for (iter = 0; styles[iter].stylename; iter++) {
- now = gtk_rc_get_style_by_paths(settings, styles[iter].labelname, NULL, G_TYPE_NONE);
- if (parent == now ||
- (parent && now && parent->rc_style == now->rc_style)) {
- g_string_append_printf(str, "style \"%s\" {\n"
- "fg[ACTIVE] = \"%s\"\n"
- "}\n"
- "widget \"*%s\" style \"%s\"\n",
- styles[iter].stylename,
- styles[iter].color,
- styles[iter].labelname, styles[iter].stylename);
- }
+}
+
+/* Invalidate the first tab color set */
+static gboolean tab_color_fuse = TRUE;
+
+static void
+pidgin_conversations_set_tab_colors(void)
+{
+ /* Set default tab colors */
+ GString *str = g_string_new(NULL);
+ GtkSettings *settings = gtk_settings_get_default();
+ GtkStyle *parent = gtk_rc_get_style_by_paths(settings, "tab-container.tab-label*", NULL, G_TYPE_NONE), *now;
+ struct {
+ const char *stylename;
+ const char *labelname;
+ const char *color;
+ } styles[] = {
+ {"pidgin_tab_label_typing_default", "tab-label-typing", "#4e9a06"},
+ {"pidgin_tab_label_typed_default", "tab-label-typed", "#c4a000"},
+ {"pidgin_tab_label_attention_default", "tab-label-attention", "#006aff"},
+ {"pidgin_tab_label_unreadchat_default", "tab-label-unreadchat", "#cc0000"},
+ {"pidgin_tab_label_event_default", "tab-label-event", "#888a85"},
+ {NULL, NULL, NULL}
+ };
+ int iter;
+
+ if(tab_color_fuse) {
+ tab_color_fuse = FALSE;
+ return;
+ }
+
+ for (iter = 0; styles[iter].stylename; iter++) {
+ now = gtk_rc_get_style_by_paths(settings, styles[iter].labelname, NULL, G_TYPE_NONE);
+ if (parent == now ||
+ (parent && now && parent->rc_style == now->rc_style)) {
+ GdkColor color;
+ gdk_color_parse(styles[iter].color, &color);
+ pidgin_style_adjust_contrast(gtk_widget_get_default_style(), &color);
+
+ g_string_append_printf(str, "style \"%s\" {\n"
+ "fg[ACTIVE] = \"%s\"\n"
+ "}\n"
+ "widget \"*%s\" style \"%s\"\n",
+ styles[iter].stylename,
+ gdk_color_to_string(&color),
+ styles[iter].labelname, styles[iter].stylename);
}
- gtk_rc_parse_string(str->str);
- g_string_free(str, TRUE);
- gtk_rc_reset_styles(settings);
}
+ gtk_rc_parse_string(str->str);
+ g_string_free(str, TRUE);
+ gtk_rc_reset_styles(settings);
}
void
@@ -9385,6 +9402,9 @@ pidgin_conv_window_new()
gtk_window_iconify(GTK_WINDOW(win->window));
#endif
+ /* Fix colours */
+ pidgin_conversations_set_tab_colors();
+
return win;
}
@@ -10252,6 +10272,9 @@ generate_nick_colors(guint *color_count, GdkColor background)
gdk_color_parse(DEFAULT_HIGHLIGHT_COLOR, &nick_highlight);
gdk_color_parse(DEFAULT_SEND_COLOR, &send_color);
+ pidgin_style_adjust_contrast(NULL, &nick_highlight);
+ pidgin_style_adjust_contrast(NULL, &send_color);
+
srand(background.red + background.green + background.blue + 1);
breakout_time = time(NULL) + 3;
diff --git a/pidgin/gtkimhtml.c b/pidgin/gtkimhtml.c
index 777db0bef4..283900c314 100644
--- a/pidgin/gtkimhtml.c
+++ b/pidgin/gtkimhtml.c
@@ -44,6 +44,7 @@
#include "gtksourceiter.h"
#include "gtksourceundomanager.h"
#include "gtksourceview-marshal.h"
+#include "gtkstyle.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdkkeysyms.h>
@@ -469,6 +470,7 @@ gtk_imhtml_style_set(GtkWidget *widget, GtkStyle *prev_style)
} else {
GdkColor defcolor;
gdk_color_parse(styles[i].def, &defcolor);
+ pidgin_style_adjust_contrast(gtk_widget_get_style(widget), &defcolor);
g_object_set(tag, "foreground-gdk", &defcolor, NULL);
}
}
diff --git a/pidgin/gtkstyle.c b/pidgin/gtkstyle.c
new file mode 100644
index 0000000000..a1985fe700
--- /dev/null
+++ b/pidgin/gtkstyle.c
@@ -0,0 +1,70 @@
+/*
+ * @file gtkstyle.c GTK+ Style utility functions
+ * @ingroup pidgin
+ */
+
+/* pidgin
+ *
+ * Pidgin is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ */
+#include "gtkstyle.h"
+
+/* Assume light mode */
+static gboolean dark_mode_cache = FALSE;
+
+gboolean
+pidgin_style_is_dark(GtkStyle *style) {
+ GdkColor bg;
+
+ if (!style) {
+ return dark_mode_cache;
+ }
+
+ bg = style->base[GTK_STATE_NORMAL];
+
+ if (bg.red != 0xFFFF || bg.green != 0xFFFF || bg.blue != 0xFFFF) {
+ dark_mode_cache = ((int) bg.red + (int) bg.green + (int) bg.blue) < (65536 * 3 / 2);
+ }
+
+ return dark_mode_cache;
+}
+
+void
+pidgin_style_adjust_contrast(GtkStyle *style, GdkColor *color) {
+ if (pidgin_style_is_dark(style)) {
+ gdouble r, g, b, h, s, v;
+
+ r = ((gdouble) color->red) / 65535.0;
+ g = ((gdouble) color->green) / 65535.0;
+ b = ((gdouble) color->blue) / 65535.0;
+
+ gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
+
+ v += 0.3;
+ v = v > 1.0 ? 1.0 : v;
+ s = 0.7;
+
+ gtk_hsv_to_rgb(h, s, v, &r, &g, &b);
+
+ color->red = (guint16) (r * 65535.0);
+ color->green = (guint16) (g * 65535.0);
+ color->blue = (guint16) (b * 65535.0);
+ }
+}
diff --git a/pidgin/gtkstyle.h b/pidgin/gtkstyle.h
new file mode 100644
index 0000000000..0b65a226f6
--- /dev/null
+++ b/pidgin/gtkstyle.h
@@ -0,0 +1,59 @@
+/**
+ * @file gtkstyle.h GTK+ Style utility functions
+ * @ingroup pidgin
+ */
+
+/* pidgin
+ *
+ * Pidgin is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+#ifndef _PIDGINSTYLE_H_
+#define _PIDGINSTYLE_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+/*@{*/
+
+/**
+ * Returns TRUE if dark mode is enabled and foreground colours should be invertred
+ *
+ * @param style The GtkStyle in use, or NULL to use a cached version.
+ *
+ * @return @c TRUE if dark mode, @c FALSE otherwise
+ */
+
+gboolean pidgin_style_is_dark(GtkStyle *style);
+
+/**
+ * Lighten a color if dark mode is enabled.
+ *
+ * @param style The GtkStyle in use.
+ *
+ * @param color Color to be lightened. Transformed color will be written here.
+ */
+
+void pidgin_style_adjust_contrast(GtkStyle *style, GdkColor *color);
+
+/*@}*/
+
+G_END_DECLS
+
+#endif /* _PIDGINSTYLE_H_ */