pidgin/gtkstyle.c

Fri, 29 Mar 2019 20:05:41 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Fri, 29 Mar 2019 20:05:41 -0400
changeset 39523
415b0705e48b
parent 39277
68c17ba18f33
permissions
-rw-r--r--

sametime: Move MIME handling to a separate file.

38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * @file gtkstyle.c GTK+ Style utility functions
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * @ingroup pidgin
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
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 /* pidgin
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 *
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * 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
9 * 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
10 * source distribution.
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 *
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * 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
13 * 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
14 * 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
15 * (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
16 *
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * 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
18 * 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
19 * 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
20 * 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
21 *
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 *
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 */
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include "gtkstyle.h"
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 /* Assume light mode */
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 static gboolean dark_mode_cache = FALSE;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 gboolean
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 pidgin_style_is_dark(GtkStyle *style) {
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GdkColor bg;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 if (!style) {
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 return dark_mode_cache;
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
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 bg = style->base[GTK_STATE_NORMAL];
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 if (bg.red != 0xFFFF || bg.green != 0xFFFF || bg.blue != 0xFFFF) {
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 dark_mode_cache = ((int) bg.red + (int) bg.green + (int) bg.blue) < (65536 * 3 / 2);
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 }
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 return dark_mode_cache;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 }
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 void
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
50 pidgin_style_adjust_contrast(GtkStyle *style, GdkRGBA *rgba) {
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 if (pidgin_style_is_dark(style)) {
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
52 gdouble h, s, v;
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
54 gtk_rgb_to_hsv(rgba->red, rgba->green, rgba->blue, &h, &s, &v);
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 v += 0.3;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 v = v > 1.0 ? 1.0 : v;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 s = 0.7;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
60 gtk_hsv_to_rgb(h, s, v, &rgba->red, &rgba->green, &rgba->blue);
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 }
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 }

mercurial