No issues found
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3 * st-icon-colors.c: Colors for colorizing a symbolic icon
4 *
5 * Copyright 2010 Red Hat, Inc.
6 * Copyright 2010 Florian Mç«Żllner
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation, either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "st-icon-colors.h"
23
24 /**
25 * st_icon_colors_new:
26 *
27 * Creates a new #StIconColors. All colors are initialized to transparent black.
28 *
29 * Return value: a newly created #StIconColors. Free with st_icon_colors_unref()
30 */
31 StIconColors *
32 st_icon_colors_new (void)
33 {
34 StIconColors *colors;
35
36 colors = g_slice_new0 (StIconColors);
37 colors->ref_count = 1;
38
39 return colors;
40 }
41
42 /**
43 * st_icon_colors_ref:
44 * @colors: a #StIconColors
45 *
46 * Atomically increments the reference count of @colors by one.
47 *
48 * Returns: the passed in #StIconColors.
49 */
50 StIconColors *
51 st_icon_colors_ref (StIconColors *colors)
52 {
53 g_return_val_if_fail (colors != NULL, NULL);
54 g_return_val_if_fail (colors->ref_count > 0, colors);
55
56 g_atomic_int_inc ((volatile int *)&colors->ref_count);
57 return colors;
58 }
59
60 /**
61 * st_icon_colors_unref:
62 * @colors: a #StIconColors
63 *
64 * Atomically decrements the reference count of @colors by one.
65 * If the reference count drops to 0, all memory allocated by the
66 * #StIconColors is released.
67 */
68 void
69 st_icon_colors_unref (StIconColors *colors)
70 {
71 g_return_if_fail (colors != NULL);
72 g_return_if_fail (colors->ref_count > 0);
73
74 if (g_atomic_int_dec_and_test ((volatile int *)&colors->ref_count))
75 g_slice_free (StIconColors, colors);
76 }
77
78 /**
79 * st_icon_colors_copy:
80 * @colors: a #StIconColors
81 *
82 * Creates a new StIconColors structure that is a copy of the passed
83 * in @colors. You would use this function instead of st_icon_colors_ref()
84 * if you were planning to change colors in the result.
85 *
86 * Returns: a newly created #StIconColors.
87 */
88 StIconColors *
89 st_icon_colors_copy (StIconColors *colors)
90 {
91 StIconColors *copy;
92
93 g_return_val_if_fail (colors != NULL, NULL);
94
95 copy = st_icon_colors_new ();
96
97 copy->foreground = colors->foreground;
98 copy->warning = colors->warning;
99 copy->error = colors->error;
100 copy->success = colors->success;
101
102 return copy;
103 }
104
105 G_DEFINE_BOXED_TYPE (StIconColors,
106 st_icon_colors,
107 st_icon_colors_ref,
108 st_icon_colors_unref)