pidgin/gtkstyle.c

Thu, 09 Nov 2017 17:31:16 +0000

author
cmeerw@quadriceps.cmeerw.net
date
Thu, 09 Nov 2017 17:31:16 +0000
branch
fix-15687
changeset 38754
ce9ac4939540
parent 38699
e7b5011e4728
child 39277
68c17ba18f33
permissions
-rw-r--r--

Fixes #15687 by registering for chat-joined for chats (instead of
conversation-created) as persistent chats can be re-joined after
re-connection.

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
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 pidgin_style_adjust_contrast(GtkStyle *style, GdkColor *color) {
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)) {
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 gdouble r, g, b, h, s, v;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 r = ((gdouble) color->red) / 65535.0;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 g = ((gdouble) color->green) / 65535.0;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 b = ((gdouble) color->blue) / 65535.0;
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 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
61 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
62 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
63
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 gtk_hsv_to_rgb(h, s, v, &r, &g, &b);
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 color->red = (guint16) (r * 65535.0);
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 color->green = (guint16) (g * 65535.0);
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 color->blue = (guint16) (b * 65535.0);
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 }
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 }

mercurial