Sun, 03 Sep 2017 01:28:21 -0500
Namespace the contrast stuff and move it to it's own file/namespace
| pidgin/Makefile.am | file | annotate | diff | comparison | revisions | |
| pidgin/gtkblist.c | file | annotate | diff | comparison | revisions | |
| pidgin/gtkconv.c | file | annotate | diff | comparison | revisions | |
| pidgin/gtkimhtml.c | file | annotate | diff | comparison | revisions | |
| pidgin/gtkstyle.c | file | annotate | diff | comparison | revisions | |
| pidgin/gtkstyle.h | file | annotate | diff | comparison | revisions |
--- a/pidgin/Makefile.am Thu Aug 24 21:18:49 2017 -0500 +++ b/pidgin/Makefile.am Sun Sep 03 01:28:21 2017 -0500 @@ -81,6 +81,7 @@ gtksourceview-marshal.c \ gtkstatus-icon-theme.c \ gtkstatusbox.c \ + gtkstyle.c \ gtkthemes.c \ gtkutils.c \ gtkwhiteboard.c \ @@ -131,6 +132,7 @@ gtksourceview-marshal.h \ gtkstatus-icon-theme.h \ gtkstatusbox.h \ + gtkstyle.h \ pidginstock.h \ gtkthemes.h \ gtkutils.h \
--- a/pidgin/gtkblist.c Thu Aug 24 21:18:49 2017 -0500 +++ b/pidgin/gtkblist.c Sun Sep 03 01:28:21 2017 -0500 @@ -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 @@ 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 @@ 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>",
--- a/pidgin/gtkconv.c Thu Aug 24 21:18:49 2017 -0500 +++ b/pidgin/gtkconv.c Sun Sep 03 01:28:21 2017 -0500 @@ -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 @@ (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 @@ 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);
--- a/pidgin/gtkimhtml.c Thu Aug 24 21:18:49 2017 -0500 +++ b/pidgin/gtkimhtml.c Sun Sep 03 01:28:21 2017 -0500 @@ -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 @@ 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 @@ } 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); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkstyle.c Sun Sep 03 01:28:21 2017 -0500 @@ -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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkstyle.h Sun Sep 03 01:28:21 2017 -0500 @@ -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_ */