Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Testing Done:
* Ran with arc-dark and adwatia.
* Stepped through the debugger to make sure it was detected right.
* Joined a muc with both themes, the colors change but there're impossible to see as most of that code is elsewhere and not addressed in this review request.
* Also noticed that nicks in mucs are doubled, not sure what, but it's that way with out this patch as well.
Reviewed at https://reviews.imfreedom.org/r/208/
--- a/doc/reference/pidgin/pidgin-docs.xml Tue Nov 10 01:10:33 2020 -0600
+++ b/doc/reference/pidgin/pidgin-docs.xml Tue Nov 10 01:11:31 2020 -0600
@@ -46,7 +46,6 @@
<xi:include href="xml/gtksmiley-theme.xml" />
<xi:include href="xml/gtkstatus-icon-theme.xml" />
<xi:include href="xml/gtkstatusbox.xml" />
- <xi:include href="xml/gtkstyle.xml" />
<xi:include href="xml/gtkutils.xml" />
<xi:include href="xml/gtkwhiteboard.xml" />
<xi:include href="xml/gtkxfer.xml" />
@@ -79,6 +78,7 @@
<xi:include href="xml/pidginpluginsdialog.xml" />
<xi:include href="xml/pidginpluginsmenu.xml" />
<xi:include href="xml/pidginstock.xml" />
+ <xi:include href="xml/pidginstyle.xml" /> <xi:include href="xml/pidgintalkatu.xml" />
<xi:include href="xml/pidgintooltip.xml" />
<xi:include href="xml/pidginwindow.xml" />
--- a/pidgin/gtkblist.c Tue Nov 10 01:10:33 2020 -0600
+++ b/pidgin/gtkblist.c Tue Nov 10 01:11:31 2020 -0600
@@ -37,7 +37,6 @@
#include "gtkstatusbox.h"
#include "gtkscrollbook.h"
#include "gtkblist-theme.h"
#include "gtkblist-theme-loader.h"
@@ -55,6 +54,7 @@
#include "pidgin/pidginlog.h"
#include "pidgin/pidginmooddialog.h"
#include "pidgin/pidginplugininfo.h"
+#include "pidgin/pidginstyle.h" #include "pidgin/pidgintooltip.h"
#include "pidgin/pidginwindow.h"
#include "pidginmenutray.h"
--- a/pidgin/gtkconv.c Tue Nov 10 01:10:33 2020 -0600
+++ b/pidgin/gtkconv.c Tue Nov 10 01:11:31 2020 -0600
@@ -49,7 +49,6 @@
#include "pidginclosebutton.h"
#include "pidginconversationwindow.h"
@@ -60,6 +59,7 @@
#include "pidginmenutray.h"
#include "pidginmessage.h"
+#include "pidginstyle.h" #include "pidgintooltip.h"
#include "pidginwindow.h"
--- a/pidgin/gtkstyle.c Tue Nov 10 01:10:33 2020 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
- * @file gtkstyle.c GTK+ Style utility functions
- * 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
- * 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
-static gboolean dark_mode_cache = FALSE;
-pidgin_style_is_dark(GtkStyle *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;
-pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *rgba) {
- if (pidgin_style_is_dark(style)) {
- gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v);
- gtk_hsv_to_rgb(h, s, v, &rgba->red, &rgba->green, &rgba->blue);
--- a/pidgin/gtkstyle.h Tue Nov 10 01:10:33 2020 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
- * 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
- * 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
-#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION)
-# error "only <pidgin.h> may be included directly"
- * @section_id: pidgin-gtkstyle
- * @short_description: <filename>gtkstyle.h</filename>
- * pidgin_style_is_dark:
- * @style: The GtkStyle in use, or NULL to use a cached version.
- * Returns whether or not dark mode is enabled.
- * Returns: TRUE if dark mode is enabled and foreground colours should be invertred
-gboolean pidgin_style_is_dark(GtkStyle *style);
- * pidgin_style_adjust_contrast:
- * @style: The GtkStyle in use.
- * @color: Color to be lightened. Transformed color will be written here.
- * Lighten a color if dark mode is enabled.
-void pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *color);
-#endif /* _PIDGINSTYLE_H_ */
--- a/pidgin/meson.build Tue Nov 10 01:10:33 2020 -0600
+++ b/pidgin/meson.build Tue Nov 10 01:11:31 2020 -0600
@@ -25,7 +25,6 @@
'gtkstatus-icon-theme.c',
@@ -59,6 +58,7 @@
'pidginprotocolchooser.c',
@@ -92,7 +92,6 @@
'gtkstatus-icon-theme.h',
@@ -128,6 +127,7 @@
'pidginprotocolchooser.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginstyle.c Tue Nov 10 01:11:31 2020 -0600
@@ -0,0 +1,72 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * 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 + * 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 library; if not, see <https://www.gnu.org/licenses/>. +#include "pidgin/pidginstyle.h" +static gboolean dark_mode_have_cache = FALSE; +static gboolean dark_mode_cached_value = FALSE; +pidgin_style_is_dark(GtkStyle *style) { + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gdouble luminance = 0.0; + if(dark_mode_have_cache) { + return dark_mode_cached_value; + style = gtk_widget_get_default_style(); + bg = style->base[GTK_STATE_NORMAL]; + /* magic values are taken from https://en.wikipedia.org/wiki/Luma_(video) + * Rec._601_luma_versus_Rec._709_luma_coefficients. + luminance = (0.299 * bg.red) + (0.587 * bg.green) + (0.114 * bg.blue); + G_GNUC_END_IGNORE_DEPRECATIONS + dark_mode_cached_value = (luminance < 0x7FFF); + dark_mode_have_cache = TRUE; + return dark_mode_cached_value; +pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *rgba) { + if (pidgin_style_is_dark(style)) { + gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v); + gtk_hsv_to_rgb(h, s, v, &rgba->red, &rgba->green, &rgba->blue); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginstyle.h Tue Nov 10 01:11:31 2020 -0600
@@ -0,0 +1,69 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * 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 + * 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 library; if not, see <https://www.gnu.org/licenses/>. +#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) +# error "only <pidgin.h> may be included directly" + * @section_id: pidgin-pidginstyle + * @short_description: <filename>gtkstyle.h</filename> + * The style API contains some helpers regarding #GtkStyle. + * pidgin_style_is_dark: + * @style: The #GtkStyle in use, or %NULL to use a cached version. + * Gets whether or not dark mode is enabled. + * Returns: %TRUE if dark mode is enabled and foreground colours should be +gboolean pidgin_style_is_dark(GtkStyle *style); + * pidgin_style_adjust_contrast: + * @style: The #GtkStyle in use. + * @color: (inout): Color to be lightened. Transformed color will be written + * Lighten a color if dark mode is enabled. +void pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *color); +#endif /* PIDGIN_STYLE_H */ --- a/po/POTFILES.in Tue Nov 10 01:10:33 2020 -0600
+++ b/po/POTFILES.in Tue Nov 10 01:11:31 2020 -0600
@@ -328,7 +328,6 @@
pidgin/gtkstatus-icon-theme.c
@@ -352,6 +351,7 @@