pidgin/pidgin

df2674f2d982
Parents 493d2a76c01b
Children cf58ec89b1e4
Rename the pidgin_style_* api to pidgin_style_context_*

Testing Done:
Compiled and ran locally.

Reviewed at https://reviews.imfreedom.org/r/409/
--- a/doc/reference/pidgin/pidgin-docs.xml Mon Jan 11 00:06:00 2021 -0600
+++ b/doc/reference/pidgin/pidgin-docs.xml Mon Jan 11 00:20:09 2021 -0600
@@ -79,7 +79,7 @@
<xi:include href="xml/pidginpresence.xml" />
<xi:include href="xml/pidginpresenceicon.xml" />
<xi:include href="xml/pidginstock.xml" />
- <xi:include href="xml/pidginstyle.xml" />
+ <xi:include href="xml/pidginstylecontext.xml" />
<xi:include href="xml/pidgintalkatu.xml" />
<xi:include href="xml/pidgintooltip.xml" />
<xi:include href="xml/pidginwindow.xml" />
--- a/pidgin/gtkblist.c Mon Jan 11 00:06:00 2021 -0600
+++ b/pidgin/gtkblist.c Mon Jan 11 00:20:09 2021 -0600
@@ -54,7 +54,7 @@
#include "pidgin/pidginlog.h"
#include "pidgin/pidginmooddialog.h"
#include "pidgin/pidginplugininfo.h"
-#include "pidgin/pidginstyle.h"
+#include "pidgin/pidginstylecontext.h"
#include "pidgin/pidgintooltip.h"
#include "pidgin/pidginwindow.h"
#include "pidginmenutray.h"
@@ -3894,7 +3894,7 @@
theme = pidgin_blist_get_theme();
name_color = NULL;
- dim_grey = pidgin_style_is_dark(NULL) ? "light slate grey" : "dim grey";
+ dim_grey = pidgin_style_context_is_dark(NULL) ? "light slate grey" : "dim grey";
if (theme) {
if (purple_presence_is_idle(presence)) {
@@ -5899,7 +5899,7 @@
textcolor = pidgin_theme_font_get_color_describe(pair);
else
/* If no theme them default to making idle buddy names grey */
- textcolor = pidgin_style_is_dark(NULL) ? "light slate grey" : "dim grey";
+ textcolor = pidgin_style_context_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 Mon Jan 11 00:06:00 2021 -0600
+++ b/pidgin/gtkconv.c Mon Jan 11 00:20:09 2021 -0600
@@ -59,7 +59,7 @@
#include "pidginmessage.h"
#include "pidginpresenceicon.h"
#include "pidginstock.h"
-#include "pidginstyle.h"
+#include "pidginstylecontext.h"
#include "pidgintooltip.h"
#include "pidginwindow.h"
@@ -7869,8 +7869,8 @@
gdk_rgba_parse(&nick_highlight, DEFAULT_HIGHLIGHT_COLOR);
gdk_rgba_parse(&send_color, DEFAULT_SEND_COLOR);
- pidgin_style_adjust_contrast(NULL, &nick_highlight);
- pidgin_style_adjust_contrast(NULL, &send_color);
+ pidgin_style_context_adjust_contrast(NULL, &nick_highlight);
+ pidgin_style_context_adjust_contrast(NULL, &send_color);
srand(background.red * 65535 + background.green * 65535 + background.blue * 65535 + 1);
--- a/pidgin/meson.build Mon Jan 11 00:06:00 2021 -0600
+++ b/pidgin/meson.build Mon Jan 11 00:20:09 2021 -0600
@@ -60,7 +60,7 @@
'pidginpresenceicon.c',
'pidginprotocolchooser.c',
'pidginprotocolstore.c',
- 'pidginstyle.c',
+ 'pidginstylecontext.c',
'pidgintalkatu.c',
'pidgintooltip.c',
'pidginwindow.c',
@@ -131,7 +131,7 @@
'pidginpresenceicon.h',
'pidginprotocolchooser.h',
'pidginprotocolstore.h',
- 'pidginstyle.h',
+ 'pidginstylecontext.h',
'pidgintalkatu.h',
'pidgintooltip.h',
'pidginwindow.h',
--- a/pidgin/pidginstyle.c Mon Jan 11 00:06:00 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/*
- * 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);
- }
-}
--- a/pidgin/pidginstyle.h Mon Jan 11 00:06:00 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * 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 */
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidginstylecontext.c Mon Jan 11 00:20:09 2021 -0600
@@ -0,0 +1,76 @@
+/*
+ * 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/pidginstylecontext.h"
+
+/* Assume light mode */
+static gboolean dark_mode_have_cache = FALSE;
+static gboolean dark_mode_cached_value = FALSE;
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+gboolean
+pidgin_style_context_is_dark(GtkStyleContext *context) {
+ GdkRGBA bg;
+ gdouble luminance = 0.0;
+
+ if(context == NULL) {
+ if(dark_mode_have_cache) {
+ return dark_mode_cached_value;
+ }
+
+ context = gtk_style_context_new();
+ } else {
+ g_object_ref(G_OBJECT(context));
+ }
+
+ gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL,
+ GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &bg,
+ NULL);
+ g_object_unref(G_OBJECT(context));
+
+ /* 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);
+
+ dark_mode_cached_value = (luminance < 0x7FFF);
+ dark_mode_have_cache = TRUE;
+
+ return dark_mode_cached_value;
+}
+
+void
+pidgin_style_context_adjust_contrast(GtkStyleContext *context, GdkRGBA *rgba) {
+ if(pidgin_style_context_is_dark(context)) {
+ 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/pidginstylecontext.h Mon Jan 11 00:20:09 2021 -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:pidginstylecontext
+ * @section_id: pidgin-pidginstylecontext
+ * @short_description: Dark theme helpers.
+ * @title: GtkStyleContext Helpers
+ *
+ * A collection of API to help with handling dark themes.
+ */
+
+#ifndef PIDGIN_STYLE_CONTEXT_H
+#define PIDGIN_STYLE_CONTEXT_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+/**
+ * pidgin_style_context_is_dark:
+ * @context: The #GtkStyleContext to 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_context_is_dark(GtkStyleContext *context);
+
+/**
+ * pidgin_style_context_adjust_contrast:
+ * @context: The #GtkStyleContext 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_context_adjust_contrast(GtkStyleContext *context, GdkRGBA *color);
+
+G_END_DECLS
+
+#endif /* PIDGIN_STYLE_CONTEXT_H */
+
--- a/po/POTFILES.in Mon Jan 11 00:06:00 2021 -0600
+++ b/po/POTFILES.in Mon Jan 11 00:20:09 2021 -0600
@@ -350,7 +350,7 @@
pidgin/pidginpresence.c
pidgin/pidginpresenceicon.c
pidgin/pidginstock.c
-pidgin/pidginstyle.c
+pidgin/pidginstylecontext.c
pidgin/pidgintalkatu.c
pidgin/pidgintooltip.c
pidgin/pidginwindow.c