pidgin/pidgin

Parents ac53ccf25e25
Children 5933c91abf0c
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 "gtkroomlist.h"
#include "gtkstatusbox.h"
#include "gtkscrollbook.h"
-#include "gtkstyle.h"
#include "gtkblist-theme.h"
#include "gtkblist-theme-loader.h"
#include "gtkutils.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 "gtkpounce.h"
#include "gtkprefs.h"
#include "gtkprivacy.h"
-#include "gtkstyle.h"
#include "gtkutils.h"
#include "pidginclosebutton.h"
#include "pidginconversationwindow.h"
@@ -60,6 +59,7 @@
#include "pidginmenutray.h"
#include "pidginmessage.h"
#include "pidginstock.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
- * @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, GdkRGBA *rgba) {
- if (pidgin_style_is_dark(style)) {
- gdouble h, s, v;
-
- gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v);
-
- v += 0.3;
- v = v > 1.0 ? 1.0 : v;
- s = 0.7;
-
- 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
- *
- * 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
- */
-
-#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION)
-# error "only <pidgin.h> may be included directly"
-#endif
-
-/**
- * SECTION:gtkstyle
- * @section_id: pidgin-gtkstyle
- * @short_description: <filename>gtkstyle.h</filename>
- * @title: Style API
- */
-
-#ifndef _PIDGINSTYLE_H_
-#define _PIDGINSTYLE_H_
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-/**
- * 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);
-
-G_END_DECLS
-
-#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 @@
'gtksmiley-theme.c',
'gtkstatus-icon-theme.c',
'gtkstatusbox.c',
- 'gtkstyle.c',
'gtkutils.c',
'gtkwhiteboard.c',
'gtkxfer.c',
@@ -59,6 +58,7 @@
'pidginpluginsmenu.c',
'pidginprotocolchooser.c',
'pidginprotocolstore.c',
+ 'pidginstyle.c',
'pidgintalkatu.c',
'pidgintooltip.c',
'pidginwindow.c',
@@ -92,7 +92,6 @@
'gtksmiley-theme.h',
'gtkstatus-icon-theme.h',
'gtkstatusbox.h',
- 'gtkstyle.h',
'pidginstock.h',
'gtkutils.h',
'gtkwhiteboard.h',
@@ -128,6 +127,7 @@
'pidginpluginsmenu.h',
'pidginprotocolchooser.h',
'pidginprotocolstore.h',
+ 'pidginstyle.h',
'pidgintalkatu.h',
'pidgintooltip.h',
'pidginwindow.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
+ * 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 library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "pidgin/pidginstyle.h"
+
+/* Assume light mode */
+static gboolean dark_mode_have_cache = FALSE;
+static gboolean dark_mode_cached_value = FALSE;
+
+gboolean
+pidgin_style_is_dark(GtkStyle *style) {
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
+ GdkColor bg;
+ gdouble luminance = 0.0;
+
+ if(style == NULL) {
+ 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;
+}
+
+void
+pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *rgba) {
+ if (pidgin_style_is_dark(style)) {
+ gdouble h, s, v;
+
+ gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v);
+
+ v += 0.3;
+ v = v > 1.0 ? 1.0 : v;
+ s = 0.7;
+
+ 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
+ * 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 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"
+#endif
+
+/**
+ * SECTION:pidginstyle
+ * @section_id: pidgin-pidginstyle
+ * @short_description: <filename>gtkstyle.h</filename>
+ * @title: Style API
+ *
+ * The style API contains some helpers regarding #GtkStyle.
+ */
+
+#ifndef PIDGIN_STYLE_H
+#define PIDGIN_STYLE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+/**
+ * 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
+ * inverted.
+ */
+
+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
+ * here.
+ *
+ * Lighten a color if dark mode is enabled.
+ */
+
+void pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *color);
+
+G_END_DECLS
+
+#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/gtksmiley-theme.c
pidgin/gtkstatusbox.c
pidgin/gtkstatus-icon-theme.c
-pidgin/gtkstyle.c
pidgin/gtkutils.c
pidgin/gtkwhiteboard.c
pidgin/gtkxfer.c
@@ -352,6 +351,7 @@
pidgin/pidginmenutray.c
pidgin/pidginmessage.c
pidgin/pidginstock.c
+pidgin/pidginstyle.c
pidgin/pidgintalkatu.c
pidgin/pidgintooltip.c
pidgin/pidginwindow.c