]> Dogcows Code - chaz/tint2/blob - src/launcher/xsettings-common.c
launcher_apps_dir-v2.patch
[chaz/tint2] / src / launcher / xsettings-common.c
1 /*
2 * Copyright © 2001 Red Hat, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Red Hat not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. Red Hat makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
13 *
14 * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 * Author: Owen Taylor, Red Hat, Inc.
22 */
23 #include "string.h"
24 #include "stdlib.h"
25
26 #include <X11/Xlib.h>
27 #include <X11/Xmd.h> /* For CARD32 */
28
29 #include "xsettings-common.h"
30
31 XSettingsSetting *
32 xsettings_setting_copy (XSettingsSetting *setting)
33 {
34 XSettingsSetting *result;
35 size_t str_len;
36
37 result = malloc (sizeof *result);
38 if (!result)
39 return NULL;
40
41 str_len = strlen (setting->name);
42 result->name = malloc (str_len + 1);
43 if (!result->name)
44 goto err;
45
46 memcpy (result->name, setting->name, str_len + 1);
47
48 result->type = setting->type;
49
50 switch (setting->type)
51 {
52 case XSETTINGS_TYPE_INT:
53 result->data.v_int = setting->data.v_int;
54 break;
55 case XSETTINGS_TYPE_COLOR:
56 result->data.v_color = setting->data.v_color;
57 break;
58 case XSETTINGS_TYPE_STRING:
59 str_len = strlen (setting->data.v_string);
60 result->data.v_string = malloc (str_len + 1);
61 if (!result->data.v_string)
62 goto err;
63
64 memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
65 break;
66 default:
67 break;
68 }
69
70 result->last_change_serial = setting->last_change_serial;
71
72 return result;
73
74 err:
75 if (result->name)
76 free (result->name);
77 free (result);
78
79 return NULL;
80 }
81
82 XSettingsList *
83 xsettings_list_copy (XSettingsList *list)
84 {
85 XSettingsList *new = NULL;
86 XSettingsList *old_iter = list;
87 XSettingsList *new_iter = NULL;
88
89 while (old_iter)
90 {
91 XSettingsList *new_node;
92
93 new_node = malloc (sizeof *new_node);
94 if (!new_node)
95 goto error;
96
97 new_node->setting = xsettings_setting_copy (old_iter->setting);
98 if (!new_node->setting)
99 {
100 free (new_node);
101 goto error;
102 }
103
104 if (new_iter)
105 new_iter->next = new_node;
106 else
107 new = new_node;
108
109 new_iter = new_node;
110
111 old_iter = old_iter->next;
112 }
113
114 return new;
115
116 error:
117 xsettings_list_free (new);
118 return NULL;
119 }
120
121 int
122 xsettings_setting_equal (XSettingsSetting *setting_a,
123 XSettingsSetting *setting_b)
124 {
125 if (setting_a->type != setting_b->type)
126 return 0;
127
128 if (strcmp (setting_a->name, setting_b->name) != 0)
129 return 0;
130
131 switch (setting_a->type)
132 {
133 case XSETTINGS_TYPE_INT:
134 return setting_a->data.v_int == setting_b->data.v_int;
135 case XSETTINGS_TYPE_COLOR:
136 return (setting_a->data.v_color.red == setting_b->data.v_color.red &&
137 setting_a->data.v_color.green == setting_b->data.v_color.green &&
138 setting_a->data.v_color.blue == setting_b->data.v_color.blue &&
139 setting_a->data.v_color.alpha == setting_b->data.v_color.alpha);
140 case XSETTINGS_TYPE_STRING:
141 return strcmp (setting_a->data.v_string, setting_b->data.v_string) == 0;
142 default:
143 break;
144 }
145
146 return 0;
147 }
148
149 void
150 xsettings_setting_free (XSettingsSetting *setting)
151 {
152 if (setting->type == XSETTINGS_TYPE_STRING)
153 free (setting->data.v_string);
154
155 if (setting->name)
156 free (setting->name);
157
158 free (setting);
159 }
160
161 void
162 xsettings_list_free (XSettingsList *list)
163 {
164 while (list)
165 {
166 XSettingsList *next = list->next;
167
168 xsettings_setting_free (list->setting);
169 free (list);
170
171 list = next;
172 }
173 }
174
175 XSettingsResult
176 xsettings_list_insert (XSettingsList **list,
177 XSettingsSetting *setting)
178 {
179 XSettingsList *node;
180 XSettingsList *iter;
181 XSettingsList *last = NULL;
182
183 node = malloc (sizeof *node);
184 if (!node)
185 return XSETTINGS_NO_MEM;
186 node->setting = setting;
187
188 iter = *list;
189 while (iter)
190 {
191 int cmp = strcmp (setting->name, iter->setting->name);
192
193 if (cmp < 0)
194 break;
195 else if (cmp == 0)
196 {
197 free (node);
198 return XSETTINGS_DUPLICATE_ENTRY;
199 }
200
201 last = iter;
202 iter = iter->next;
203 }
204
205 if (last)
206 last->next = node;
207 else
208 *list = node;
209
210 node->next = iter;
211
212 return XSETTINGS_SUCCESS;
213 }
214
215 XSettingsResult
216 xsettings_list_delete (XSettingsList **list,
217 const char *name)
218 {
219 XSettingsList *iter;
220 XSettingsList *last = NULL;
221
222 iter = *list;
223 while (iter)
224 {
225 if (strcmp (name, iter->setting->name) == 0)
226 {
227 if (last)
228 last->next = iter->next;
229 else
230 *list = iter->next;
231
232 xsettings_setting_free (iter->setting);
233 free (iter);
234
235 return XSETTINGS_SUCCESS;
236 }
237
238 last = iter;
239 iter = iter->next;
240 }
241
242 return XSETTINGS_FAILED;
243 }
244
245 XSettingsSetting *
246 xsettings_list_lookup (XSettingsList *list,
247 const char *name)
248 {
249 XSettingsList *iter;
250
251 iter = list;
252 while (iter)
253 {
254 if (strcmp (name, iter->setting->name) == 0)
255 return iter->setting;
256
257 iter = iter->next;
258 }
259
260 return NULL;
261 }
262
263 char
264 xsettings_byte_order (void)
265 {
266 CARD32 myint = 0x01020304;
267 return (*(char *)&myint == 1) ? MSBFirst : LSBFirst;
268 }
This page took 0.0442 seconds and 4 git commands to generate.