aboutsummaryrefslogtreecommitdiffstats
path: root/matchbox/mb-wm-theme-xml.c
blob: 49562d42592877d731539b27bfe7dc0f9002ce0d (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 *  Matchbox Window Manager 2 - A lightweight window manager not for the
 *                            desktop.
 *
 *  Authored By Tomas Frydrych <tf@o-hand.com>
 *
 *  Copyright (c) 2007 OpenedHand Ltd - http://o-hand.com
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */

#include "mb-wm-theme-xml.h"
#include "mb-wm-theme.h"

/*****************************************************************
 * XML Parser stuff
 */
MBWMXmlButton *
mb_wm_xml_button_new ()
{
  MBWMXmlButton * b = mb_wm_util_malloc0 (sizeof (MBWMXmlButton));

  b->x = -1;
  b->y = -1;
  b->active_x = -1;
  b->active_y = -1;
  b->inactive_x = -1;
  b->inactive_y = -1;

  return b;
}

void
mb_wm_xml_button_free (MBWMXmlButton * b)
{
  free (b);
}

MBWMXmlDecor *
mb_wm_xml_decor_new ()
{
  MBWMXmlDecor * d = mb_wm_util_malloc0 (sizeof (MBWMXmlDecor));
  return d;
}

void
mb_wm_xml_decor_free (MBWMXmlDecor * d)
{
  GList * l;

  if (!d)
    return;

  l = d->buttons;
  while (l)
    {
      MBWMXmlButton * b = l->data;
      GList * n = l->next;
      mb_wm_xml_button_free (b);
      g_list_free_1 (l);

      l = n;
    }

  if (d->font_family)
    free (d->font_family);

  free (d);
}

MBWMXmlClient *
mb_wm_xml_client_new ()
{
  MBWMXmlClient * c = mb_wm_util_malloc0 (sizeof (MBWMXmlClient));

  c->x      = -1;
  c->y      = -1;
  c->width  = -1;
  c->height = -1;

  return c;
}

void
mb_wm_xml_client_free (MBWMXmlClient * c)
{
  GList * l;

  if (!c)
    return;

  l = c->decors;
  while (l)
    {
      MBWMXmlDecor * d = l->data;
      GList * n = l->next;
      mb_wm_xml_decor_free (d);
      g_list_free_1 (l);

      l = n;
    }

  free (c);
}

void
mb_wm_xml_clr_from_string (MBWMColor * clr, const char *s)
{
  int  r, g, b, a;

  if (!s || *s != '#')
    {
      clr->set = False;
      return;
    }

  sscanf (s+1,"%2x%2x%2x%2x", &r, &g, &b, &a);
  clr->r = (double) r / 255.0;
  clr->g = (double) g / 255.0;
  clr->b = (double) b / 255.0;
  clr->a = (double) a / 255.0;

  clr->set = True;
}

MBWMXmlClient *
mb_wm_xml_client_find_by_type (GList *l, MBWMClientType type)
{
  while (l)
    {
      MBWMXmlClient * c = l->data;
      if (c->type == type)
	return c;

      l = l->next;
    }

  return NULL;
}

MBWMXmlDecor *
mb_wm_xml_decor_find_by_type (GList *l, MBWMDecorType type)
{
  while (l)
    {
      MBWMXmlDecor * d = l->data;
      if (d->type == type)
	return d;

      l = l->next;
    }

  return NULL;
}

MBWMXmlButton *
mb_wm_xml_button_find_by_type (GList *l, MBWMDecorButtonType type)
{
  while (l)
    {
      MBWMXmlButton * b = l->data;
      if (b->type == type)
	return b;

      l = l->next;
    }

  return NULL;
}

#if 0
void
mb_wm_xml_client_dump (GList * l)
{
  printf ("=== XML Clients =====\n");
  while (l)
    {
      MBWMXmlClient * c = l->data;
      GList *l2 = c->decors;
      printf ("===== client type %d =====\n", c->type);

      while (l2)
	{
	  MBWMXmlDecor * d = l2->data;
	  GList *l3 = d->buttons;
	  printf ("======= decor type %d =====\n", d->type);

	  while (l3)
	    {
	      MBWMXmlButton * b = l3->data;
	      printf ("========= button type %d =====\n", d->type);

	      l3 = l3->next;
	    }

	  l2 = l2->next;
	}

      l = l->next;
    }
  printf ("=== XML Clients End =====\n");
}
#endif