Mon, 18 Jan 2021 00:05:05 -0600
Greatly simplify the nick color generation and properly detect dark themes.
Instead of randomly adjusting colors based on some seed colors we now hash a user's name and use the first 2 bytes of the digest to determine the hue to color their nick. We then adjust it according to the background color.
This isn't perfect as you can see in the screen shot, but there are some tweaks we can do later to account for that. I skipped them for now as this gets us 90% of the way there with like 50% of the work.
Testing Done:
Compiled and ran locally with Adwaita, Adwaita-Dark, and Arc-Dark themes.
Bugs closed: PIDGIN-17463
Reviewed at https://reviews.imfreedom.org/r/423/
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
1 | /* |
|
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
2 | * Pidgin - Internet Messenger |
|
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * Pidgin is the legal property of its developers, whose names are too numerous |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * source distribution. |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * This program is free software; you can redistribute it and/or modify |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * it under the terms of the GNU General Public License as published by |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * (at your option) any later version. |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * This program is distributed in the hope that it will be useful, |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | * GNU General Public License for more details. |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | * |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
20 | * along with this library; if not, see <https://www.gnu.org/licenses/>. |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | */ |
|
38816
9fd4f68ed211
Clean up gobject-introspection for gtkstyle.h
Gary Kramlich <grim@reaperworld.com>
parents:
38699
diff
changeset
|
22 | |
|
40502
875489636847
pidgin.h phase3: create pidgin.h and force its usage
Gary Kramlich <grim@reaperworld.com>
parents:
39277
diff
changeset
|
23 | #if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) |
|
875489636847
pidgin.h phase3: create pidgin.h and force its usage
Gary Kramlich <grim@reaperworld.com>
parents:
39277
diff
changeset
|
24 | # error "only <pidgin.h> may be included directly" |
|
875489636847
pidgin.h phase3: create pidgin.h and force its usage
Gary Kramlich <grim@reaperworld.com>
parents:
39277
diff
changeset
|
25 | #endif |
|
875489636847
pidgin.h phase3: create pidgin.h and force its usage
Gary Kramlich <grim@reaperworld.com>
parents:
39277
diff
changeset
|
26 | |
|
38816
9fd4f68ed211
Clean up gobject-introspection for gtkstyle.h
Gary Kramlich <grim@reaperworld.com>
parents:
38699
diff
changeset
|
27 | /** |
|
40695
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
28 | * SECTION:pidginstylecontext |
|
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
29 | * @section_id: pidgin-pidginstylecontext |
|
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
30 | * @short_description: Dark theme helpers. |
|
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
31 | * @title: GtkStyleContext Helpers |
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
32 | * |
|
40695
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
33 | * A collection of API to help with handling dark themes. |
|
38816
9fd4f68ed211
Clean up gobject-introspection for gtkstyle.h
Gary Kramlich <grim@reaperworld.com>
parents:
38699
diff
changeset
|
34 | */ |
|
9fd4f68ed211
Clean up gobject-introspection for gtkstyle.h
Gary Kramlich <grim@reaperworld.com>
parents:
38699
diff
changeset
|
35 | |
|
40695
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
36 | #ifndef PIDGIN_STYLE_CONTEXT_H |
|
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
37 | #define PIDGIN_STYLE_CONTEXT_H |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | #include <gtk/gtk.h> |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | G_BEGIN_DECLS |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | /** |
|
40713
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
44 | * pidgin_style_context_get_background_color: |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
45 | * @color: (out): A return address of a #GdkRGBA for the background color. |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
46 | * |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
47 | * Gets the background color for #GtkWindow in the currently selected theme |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
48 | * and sets @color to that value. |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
49 | * |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
50 | * Since: 3.0.0 |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
51 | */ |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
52 | void pidgin_style_context_get_background_color(GdkRGBA *color); |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
53 | |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
54 | /** |
|
40695
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
55 | * pidgin_style_context_is_dark: |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | * |
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
57 | * Gets whether or not dark mode is enabled. |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | * |
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
59 | * Returns: %TRUE if dark mode is enabled and foreground colours should be |
|
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
60 | * inverted. |
|
40713
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
61 | * |
|
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
62 | * Since: 3.0.0 |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | */ |
|
40713
766bbe6061ec
Greatly simplify the nick color generation and properly detect dark themes.
Gary Kramlich <grim@reaperworld.com>
parents:
40695
diff
changeset
|
64 | gboolean pidgin_style_context_is_dark(void); |
|
38699
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | G_END_DECLS |
|
e7b5011e4728
Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | |
|
40695
df2674f2d982
Rename the pidgin_style_* api to pidgin_style_context_*
Gary Kramlich <grim@reaperworld.com>
parents:
40592
diff
changeset
|
68 | #endif /* PIDGIN_STYLE_CONTEXT_H */ |
|
40592
559881c7bf92
Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents:
40502
diff
changeset
|
69 |