diff options
author | Gary Kramlich <grim@reaperworld.com> | 2017-09-03 01:28:21 -0500 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2017-09-03 01:28:21 -0500 |
commit | c06d216ca13f8bc12ec2bbe0c1772ef615d4919f (patch) | |
tree | 6335f57204772089b3fcbd805a8d25932f62342b | |
parent | 0aac8b7dec380f33ab8dc6d53a9c8f1c5963489e (diff) | |
download | pidgin-c06d216ca13f8bc12ec2bbe0c1772ef615d4919f.tar.gz |
Namespace the contrast stuff and move it to it's own file/namespace
-rw-r--r-- | pidgin/Makefile.am | 2 | ||||
-rw-r--r-- | pidgin/gtkblist.c | 5 | ||||
-rw-r--r-- | pidgin/gtkconv.c | 7 | ||||
-rw-r--r-- | pidgin/gtkimhtml.c | 46 | ||||
-rw-r--r-- | pidgin/gtkstyle.c | 70 | ||||
-rw-r--r-- | pidgin/gtkstyle.h | 59 |
6 files changed, 140 insertions, 49 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 2ac442e178..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" @@ -4281,7 +4282,7 @@ pidgin_blist_get_name_markup(PurpleBuddy *b, gboolean selected, gboolean aliased theme = pidgin_blist_get_theme(); name_color = NULL; - dim_grey = gtk_is_dark_mode(NULL) ? "light slate grey" : "dim grey"; + dim_grey = pidgin_style_is_dark(NULL) ? "light slate grey" : "dim grey"; if (theme) { if (purple_presence_is_idle(presence)) { @@ -6537,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 = gtk_is_dark_mode(NULL) ? "light slate grey" : "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 4dd9c5a245..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" @@ -8213,7 +8214,7 @@ pidgin_conversations_set_tab_colors(void) (parent && now && parent->rc_style == now->rc_style)) { GdkColor color; gdk_color_parse(styles[iter].color, &color); - gtk_adjust_color_dark_mode(gtk_widget_get_default_style(), &color); + pidgin_style_adjust_contrast(gtk_widget_get_default_style(), &color); g_string_append_printf(str, "style \"%s\" {\n" "fg[ACTIVE] = \"%s\"\n" @@ -10271,8 +10272,8 @@ generate_nick_colors(guint *color_count, GdkColor background) gdk_color_parse(DEFAULT_HIGHLIGHT_COLOR, &nick_highlight); gdk_color_parse(DEFAULT_SEND_COLOR, &send_color); - gtk_adjust_color_dark_mode(NULL, &nick_highlight); - gtk_adjust_color_dark_mode(NULL, &send_color); + pidgin_style_adjust_contrast(NULL, &nick_highlight); + pidgin_style_adjust_contrast(NULL, &send_color); srand(background.red + background.green + background.blue + 1); diff --git a/pidgin/gtkimhtml.c b/pidgin/gtkimhtml.c index 8fe52130d8..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> @@ -426,49 +427,6 @@ static void gtk_imhtml_size_allocate(GtkWidget *widget, GtkAllocation *alloc) gtk_imhtml_scroll_to_end(imhtml, FALSE); } -/* Assume light mode */ -static gboolean dark_mode_cache = FALSE; - -gboolean -gtk_is_dark_mode(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 -gtk_adjust_color_dark_mode(GtkStyle *style, GdkColor *color) { - if (gtk_is_dark_mode(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); - } -} - #define DEFAULT_SEND_COLOR "#204a87" #define DEFAULT_RECV_COLOR "#cc0000" #define DEFAULT_HIGHLIGHT_COLOR "#AF7F00" @@ -512,7 +470,7 @@ gtk_imhtml_style_set(GtkWidget *widget, GtkStyle *prev_style) } else { GdkColor defcolor; gdk_color_parse(styles[i].def, &defcolor); - gtk_adjust_color_dark_mode(gtk_widget_get_style(widget), &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_ */ |