pidgin/pidginstyle.c

changeset 40592
559881c7bf92
parent 39277
68c17ba18f33
equal deleted inserted replaced
40591:ac53ccf25e25 40592:559881c7bf92
1 /*
2 * Pidgin - Internet Messenger
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
4 *
5 * Pidgin is the legal property of its developers, whose names are too numerous
6 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * source distribution.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this library; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23 #include "pidgin/pidginstyle.h"
24
25 /* Assume light mode */
26 static gboolean dark_mode_have_cache = FALSE;
27 static gboolean dark_mode_cached_value = FALSE;
28
29 gboolean
30 pidgin_style_is_dark(GtkStyle *style) {
31 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
32
33 GdkColor bg;
34 gdouble luminance = 0.0;
35
36 if(style == NULL) {
37 if(dark_mode_have_cache) {
38 return dark_mode_cached_value;
39 }
40
41 style = gtk_widget_get_default_style();
42 }
43
44 bg = style->base[GTK_STATE_NORMAL];
45
46 /* magic values are taken from https://en.wikipedia.org/wiki/Luma_(video)
47 * Rec._601_luma_versus_Rec._709_luma_coefficients.
48 */
49 luminance = (0.299 * bg.red) + (0.587 * bg.green) + (0.114 * bg.blue);
50
51 G_GNUC_END_IGNORE_DEPRECATIONS
52
53 dark_mode_cached_value = (luminance < 0x7FFF);
54 dark_mode_have_cache = TRUE;
55
56 return dark_mode_cached_value;
57 }
58
59 void
60 pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *rgba) {
61 if (pidgin_style_is_dark(style)) {
62 gdouble h, s, v;
63
64 gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v);
65
66 v += 0.3;
67 v = v > 1.0 ? 1.0 : v;
68 s = 0.7;
69
70 gtk_hsv_to_rgb(h, s, v, &rgba->red, &rgba->green, &rgba->blue);
71 }
72 }

mercurial