]> Pileus Git - ~andy/gtk/blob - gdk/x11/xsettings-common.c
xsettings: Remove XSettingsList type
[~andy/gtk] / gdk / x11 / 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
24 #include "config.h"
25
26 #include "xsettings-common.h"
27
28 #include "string.h"
29 #include "stdlib.h"
30
31 #include <X11/Xlib.h>
32 #include <X11/Xmd.h>            /* For CARD32 */
33
34 XSettingsSetting *
35 xsettings_setting_copy (XSettingsSetting *setting)
36 {
37   XSettingsSetting *result;
38   size_t str_len;
39   
40   result = malloc (sizeof *result);
41   if (!result)
42     return NULL;
43
44   str_len = strlen (setting->name);
45   result->name = malloc (str_len + 1);
46   if (!result->name)
47     goto err;
48
49   memcpy (result->name, setting->name, str_len + 1);
50
51   result->type = setting->type;
52
53   switch (setting->type)
54     {
55     case XSETTINGS_TYPE_INT:
56       result->data.v_int = setting->data.v_int;
57       break;
58     case XSETTINGS_TYPE_COLOR:
59       result->data.v_color = setting->data.v_color;
60       break;
61     case XSETTINGS_TYPE_STRING:
62       str_len = strlen (setting->data.v_string);
63       result->data.v_string = malloc (str_len + 1);
64       if (!result->data.v_string)
65         goto err;
66
67       memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
68       break;
69     }
70
71   result->last_change_serial = setting->last_change_serial;
72
73   return result;
74
75  err:
76   if (result->name)
77     free (result->name);
78   free (result);
79   
80   return NULL;
81 }
82
83 int
84 xsettings_setting_equal (XSettingsSetting *setting_a,
85                          XSettingsSetting *setting_b)
86 {
87   if (setting_a->type != setting_b->type)
88     return 0;
89
90   if (strcmp (setting_a->name, setting_b->name) != 0)
91     return 0;
92
93   switch (setting_a->type)
94     {
95     case XSETTINGS_TYPE_INT:
96       return setting_a->data.v_int == setting_b->data.v_int;
97     case XSETTINGS_TYPE_COLOR:
98       return (setting_a->data.v_color.red == setting_b->data.v_color.red &&
99               setting_a->data.v_color.green == setting_b->data.v_color.green &&
100               setting_a->data.v_color.blue == setting_b->data.v_color.blue &&
101               setting_a->data.v_color.alpha == setting_b->data.v_color.alpha);
102     case XSETTINGS_TYPE_STRING:
103       return strcmp (setting_a->data.v_string, setting_b->data.v_string) == 0;
104     }
105
106   return 0;
107 }
108
109 void
110 xsettings_setting_free (XSettingsSetting *setting)
111 {
112   if (setting->type == XSETTINGS_TYPE_STRING)
113     free (setting->data.v_string);
114
115   if (setting->name)
116     free (setting->name);
117   
118   free (setting);
119 }
120