pidgin/pidginstyle.c

Sun, 20 Dec 2020 00:51:00 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Sun, 20 Dec 2020 00:51:00 -0600
changeset 40663
2453bef0abe7
parent 40592
559881c7bf92
permissions
-rw-r--r--

Cleanup local IP getters

* Rename `purple_network_get_my_ip` to `purple_network_discover_my_ip`.
Nothing actually cares about what it returns, so stop returning anything.
* Use libnice to replace `purple_network_get_local_system_ip`.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/296/

38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
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: 39277
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 * 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: 39277
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 */
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
22
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
23 #include "pidgin/pidginstyle.h"
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /* Assume light mode */
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
26 static gboolean dark_mode_have_cache = FALSE;
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
27 static gboolean dark_mode_cached_value = FALSE;
38699
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 gboolean
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 pidgin_style_is_dark(GtkStyle *style) {
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
31 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
32
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 GdkColor bg;
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
34 gdouble luminance = 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
35
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
36 if(style == NULL) {
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
37 if(dark_mode_have_cache) {
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
38 return dark_mode_cached_value;
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
39 }
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
40
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
41 style = gtk_widget_get_default_style();
38699
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
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 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
45
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
46 /* magic values are taken from https://en.wikipedia.org/wiki/Luma_(video)
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
47 * Rec._601_luma_versus_Rec._709_luma_coefficients.
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
48 */
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
49 luminance = (0.299 * bg.red) + (0.587 * bg.green) + (0.114 * bg.blue);
38699
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
40592
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
51 G_GNUC_END_IGNORE_DEPRECATIONS
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
52
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
53 dark_mode_cached_value = (luminance < 0x7FFF);
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
54 dark_mode_have_cache = TRUE;
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
55
559881c7bf92 Rename gtkstyle.[ch] to pidginstyle.[ch] and fix up the dark mode check.
Gary Kramlich <grim@reaperworld.com>
parents: 39277
diff changeset
56 return dark_mode_cached_value;
38699
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
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 void
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
60 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
61 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
62 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
63
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
64 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
65
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 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
67 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
68 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
69
39277
68c17ba18f33 pidgin: Fix GdkColor vs GdkRGBA -Wincompatible-pointer-types warnings
Mike Ruprecht <cmaiku@gmail.com>
parents: 38699
diff changeset
70 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
71 }
e7b5011e4728 Namespace the contrast stuff and move it to it's own file/namespace
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 }

mercurial