summaryrefslogtreecommitdiffstats
path: root/plugins/xsettings/xsettings-common.c
blob: 53c421a197103bb438a4f569b7da5f744320fd22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright © 2001 Red Hat, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Red Hat not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  Red Hat makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Owen Taylor, Red Hat, Inc.
 */

#include <glib.h>

#include "string.h"
#include "stdlib.h"

#include <X11/Xlib.h>
#include <X11/Xmd.h>		/* For CARD32 */

#include "xsettings-common.h"

XSettingsSetting *
xsettings_setting_new (const gchar *name)
{
  XSettingsSetting *result;

  result = g_new0 (XSettingsSetting, 1);
  result->name = g_strdup (name);

  return result;
}

static gboolean
xsettings_variant_equal0 (GVariant *a,
                          GVariant *b)
{
  if (a == b)
    return TRUE;

  if (!a || !b)
    return FALSE;

  return g_variant_equal (a, b);
}

GVariant *
xsettings_setting_get (XSettingsSetting *setting)
{
  gint i;

  for (i = G_N_ELEMENTS (setting->value) - 1; 0 <= i; i--)
    if (setting->value[i])
      return setting->value[i];

  return NULL;
}

void
xsettings_setting_set (XSettingsSetting *setting,
                       gint              tier,
                       GVariant         *value,
                       guint32           serial)
{
  GVariant *old_value;

  old_value = xsettings_setting_get (setting);
  if (old_value)
    g_variant_ref (old_value);

  if (setting->value[tier])
    g_variant_unref (setting->value[tier]);
  setting->value[tier] = value ? g_variant_ref_sink (value) : NULL;

  if (!xsettings_variant_equal0 (old_value, xsettings_setting_get (setting)))
    setting->last_change_serial = serial;

  if (old_value)
    g_variant_unref (old_value);
}

void
xsettings_setting_free (XSettingsSetting *setting)
{
  gint i;

  for (i = 0; i < G_N_ELEMENTS (setting->value); i++)
    if (setting->value[i])
      g_variant_unref (setting->value[i]);

  g_free (setting->name);
  g_free (setting);
}

char
xsettings_byte_order (void)
{
  CARD32 myint = 0x01020304;
  return (*(char *)&myint == 1) ? MSBFirst : LSBFirst;
}