2
* Copyright (C) 2007 Neil Jagdish Patel <njpatel@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
19
* Author : Neil Jagdish Patel <njpatel@gmail.com>
23
#include "awn-settings.h"
27
#include "awn-config-client.h"
29
#define FORCE_MONITOR "force_monitor" /*bool*/
30
#define MONITOR_WIDTH "monitor_width" /*int*/
31
#define MONITOR_HEIGHT "monitor_height" /*int*/
32
#define PANEL_MODE "panel_mode" /*bool*/
33
#define AUTO_HIDE "auto_hide" /*bool*/
34
#define AUTO_HIDE_DELAY "auto_hide_delay" /*int*/
35
#define KEEP_BELOW "keep_below" /*bool*/
38
#define ROUNDED_CORNERS "rounded_corners" /*bool*/
39
#define CORNER_RADIUS "corner_radius" /*float*/
40
#define RENDER_PATTERN "render_pattern" /*bool*/
41
#define PATTERN_URI "pattern_uri" /*string*/
42
#define PATTERN_ALPHA "pattern_alpha" /*float*/
43
#define GLASS_STEP_1 "glass_step_1" /*string*/
44
#define GLASS_STEP_2 "glass_step_2" /*string*/
45
#define GLASS_HISTEP_1 "glass_histep_1" /*string*/
46
#define GLASS_HISTEP_2 "glass_histep_2" /*string*/
47
#define BORDER_COLOR "border_color" /*string*/
48
#define HILIGHT_COLOR "hilight_color" /*string*/
49
#define SHOW_SEPARATOR "show_separator" /*bool*/
50
#define SEP_COLOR "sep_color" /*string*/
51
#define BAR_HEIGHT "bar_height" /*int*/
52
#define BAR_ANGLE "bar_angle" /*int, between 0 and 90*/
53
#define ICON_OFFSET "icon_offset" /*float*/
54
#define BAR_POS "bar_pos" /*float, between 0 and 1 */
56
#define CURVES_SYMMETRY "curves_symmetry" /*float, between 0 and 1*/
57
#define CURVINESS "curviness" /*float, between 0 and 1*/
59
#define WINMAN "window_manager"
60
#define SHOW_ALL_WINS "show_all_windows" /*bool*/
61
#define LAUNCHERS "launchers" /*str list*/
64
#define ACTIVE_PNG "active_png" /*string*/
65
#define USE_PNG "use_png" /*bool*/
66
#define ARROW_COLOR "arrow_color" /*color*/
67
#define ARROW_OFFSET "arrow_offset" /*offset*/
68
#define TASKS_H_ARROWS "tasks_have_arrows" /*bool*/
69
#define NAME_CHANGE_NOTIFY "name_change_notify" /*bool*/
70
#define ALPHA_EFFECT "alpha_effect" /*bool*/
71
#define ICON_EFFECT "icon_effect" /*int*/
72
#define HOVER_BOUNCE_EFFECT "hover_bounce_effect" /*bool*/
75
#define TEXT_COLOR "text_color" /*color*/
76
#define SHADOW_COLOR "shadow_color" /*color*/
77
#define BACKGROUND "background" /*color*/
78
#define FONT_FACE "font_face" /*string*/
81
static AwnSettings *settings = NULL;
82
static AwnConfigClient *client = NULL;
85
static void awn_load_bool (AwnConfigClient *client, const gchar *group,
86
const gchar* key, gboolean *data, gboolean def);
87
static void awn_load_string (AwnConfigClient *client, const gchar *group,
88
const gchar* key, gchar **data, const gchar *def);
89
static void awn_load_float (AwnConfigClient *client, const gchar *group,
90
const gchar* key, gfloat *data, gfloat def);
91
static void awn_load_int (AwnConfigClient *client, const gchar *group,
92
const gchar* key, gint *data, gint def);
93
static void awn_load_color (AwnConfigClient *client, const gchar *group,
94
const gchar* key, AwnColor *color, const gchar * def);
95
static void awn_load_string_list (AwnConfigClient *client, const gchar *group,
96
const gchar* key, GSList **data, GSList *def);
98
static void awn_notify_bool (AwnConfigClientNotifyEntry *entry, gboolean* data);
99
static void awn_notify_string (AwnConfigClientNotifyEntry *entry, gchar** data);
100
static void awn_notify_float (AwnConfigClientNotifyEntry *entry, gfloat* data);
101
static void awn_notify_int (AwnConfigClientNotifyEntry *entry, gint* data);
102
static void awn_notify_color (AwnConfigClientNotifyEntry *entry, AwnColor *data);
104
static void hex2float(gchar* HexColor, gfloat* FloatColor);
106
AwnSettings* awn_get_settings(void)
108
//assert(settings != NULL);
109
if (settings) return settings;
110
else return awn_settings_new();
120
screen = gdk_screen_get_default();
122
width = gdk_screen_get_width(screen);
123
height = gdk_screen_get_height(screen);
128
AwnSettings *s = NULL;
130
s = g_new(AwnSettings, 1);
132
client = awn_config_client_new ();
134
s->icon_theme = gtk_icon_theme_get_default();
135
/* general settings */
136
awn_config_client_ensure_group (client, AWN_CONFIG_CLIENT_DEFAULT_GROUP);
137
awn_load_bool(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, FORCE_MONITOR, &s->force_monitor, FALSE);
138
awn_load_int(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, MONITOR_WIDTH, &s->monitor_width, width);
139
awn_load_int(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, MONITOR_HEIGHT, &s->monitor_height, height);
140
awn_load_bool(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, PANEL_MODE, &s->panel_mode, FALSE);
141
awn_load_bool(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, AUTO_HIDE, &s->auto_hide, FALSE);
142
awn_load_int(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, AUTO_HIDE_DELAY, &s->auto_hide_delay, 1000);
143
awn_load_bool(client, AWN_CONFIG_CLIENT_DEFAULT_GROUP, KEEP_BELOW, &s->keep_below, FALSE);
147
awn_config_client_ensure_group (client, BAR);
149
awn_load_int(client, BAR, BAR_HEIGHT, &s->bar_height,48);
150
awn_load_float(client, BAR, BAR_POS, &s->bar_pos,0.5);
151
awn_load_int(client, BAR, BAR_ANGLE, &s->bar_angle,0);
152
awn_load_int(client, BAR, ICON_OFFSET, &s->icon_offset,10);
153
awn_load_bool(client, BAR, ROUNDED_CORNERS, &s->rounded_corners, TRUE);
154
awn_load_float(client, BAR, CORNER_RADIUS, &s->corner_radius, 10.0);
155
awn_load_bool(client, BAR, RENDER_PATTERN, &s->render_pattern, FALSE);
156
awn_load_string(client, BAR, PATTERN_URI, &s->pattern_uri, "~");
157
awn_load_float(client, BAR, PATTERN_ALPHA, &s->pattern_alpha, 1.0);
159
awn_load_color(client, BAR, GLASS_STEP_1, &s->g_step_1, "454545C8");
160
awn_load_color(client, BAR, GLASS_STEP_2, &s->g_step_2, "010101BE");
161
awn_load_color(client, BAR, GLASS_HISTEP_1, &s->g_histep_1, "FFFFFF0B");
162
awn_load_color(client, BAR, GLASS_HISTEP_2, &s->g_histep_2, "FFFFFF0A");
164
awn_load_color(client, BAR, BORDER_COLOR, &s->border_color, "000000CC");
165
awn_load_color(client, BAR, HILIGHT_COLOR, &s->hilight_color, "FFFFFF11");
167
awn_load_bool(client, BAR, SHOW_SEPARATOR, &s->show_separator, TRUE);
168
awn_load_color(client, BAR, SEP_COLOR, &s->sep_color, "FFFFFF00");
170
awn_load_float(client, BAR, CURVES_SYMMETRY, &s->curves_symmetry,0.7);
171
awn_load_float(client, BAR, CURVINESS, &s->curviness,1.0);
173
/* Window Manager settings */
174
awn_config_client_ensure_group (client, WINMAN);
175
awn_load_bool(client, WINMAN, SHOW_ALL_WINS, &s->show_all_windows, TRUE);
176
awn_load_string_list(client, WINMAN, LAUNCHERS, &s->launchers, NULL);
179
awn_config_client_ensure_group (client, APP);
180
awn_load_string(client, APP, ACTIVE_PNG, &s->active_png, "~");
181
awn_load_bool(client, APP, USE_PNG, &s->use_png, FALSE);
182
awn_load_color(client, APP, ARROW_COLOR, &s->arrow_color, "FFFFFF66");
183
awn_load_int(client, APP, ARROW_OFFSET, &s->arrow_offset, 2);
184
awn_load_bool(client, APP, TASKS_H_ARROWS, &s->tasks_have_arrows, FALSE);
185
awn_load_bool(client, APP, NAME_CHANGE_NOTIFY, &s->name_change_notify, FALSE);
186
awn_load_bool(client, APP, ALPHA_EFFECT, &s->alpha_effect, FALSE);
187
awn_load_int(client, APP, ICON_EFFECT, &s->icon_effect, 0);
190
awn_config_client_ensure_group (client, TITLE);
191
awn_load_color(client, TITLE, TEXT_COLOR, &s->text_color, "FFFFFFFF");
192
awn_load_color(client, TITLE, SHADOW_COLOR, &s->shadow_color, "1B3B12E1");
193
awn_load_color(client, TITLE, BACKGROUND, &s->background, "000000AA");
194
awn_load_string(client, TITLE, FONT_FACE, &s->font_face, "Sans 11");
196
s->task_width = settings->bar_height + 12;
198
/* make the custom icons directory */
199
gchar *path = g_build_filename (g_get_home_dir (),
200
".config/awn/custom-icons",
202
g_mkdir_with_parents (path, 0755);
209
awn_notify_bool (AwnConfigClientNotifyEntry *entry, gboolean* data)
211
*data = entry->value.bool_val;
214
//g_print("%s/%s is true\n", entry->group, entry->key);
218
awn_notify_string (AwnConfigClientNotifyEntry *entry, gchar** data)
220
*data = entry->value.str_val;
222
//g_print("%s/%s is %s\n", entry->group, entry->key, *data);
226
awn_notify_float (AwnConfigClientNotifyEntry *entry, gfloat* data)
228
*data = entry->value.float_val;
229
//g_print("%s/%s is %f\n", entry->group, entry->key, *data);
233
awn_notify_int (AwnConfigClientNotifyEntry *entry, gint* data)
235
*data = entry->value.int_val;
236
//g_print("%s/%s is %f\n", entry->group, entry->key, *data);
240
awn_notify_color (AwnConfigClientNotifyEntry *entry, AwnColor* color)
244
hex2float (entry->value.str_val, colors);
246
color->red = colors[0];
247
color->green = colors[1];
248
color->blue = colors[2];
249
color->alpha = colors[3];
254
awn_load_bool(AwnConfigClient *client, const gchar *group, const gchar* key, gboolean *data, gboolean def)
256
if (awn_config_client_entry_exists (client, group, key)) {
257
*data = awn_config_client_get_bool (client, group, key, NULL);
259
g_print("%s unset, setting now\n", key);
260
awn_config_client_set_bool (client, group, key, def, NULL);
263
awn_config_client_notify_add (client, group, key, (AwnConfigClientNotifyFunc)awn_notify_bool, data);
267
awn_load_string(AwnConfigClient *client, const gchar *group, const gchar* key, gchar **data, const gchar *def)
269
if (awn_config_client_entry_exists (client, group, key)) {
270
*data = awn_config_client_get_string (client, group, key, NULL);
272
g_print("%s unset, setting now\n", key);
273
awn_config_client_set_string (client, group, key, (gchar*)def, NULL);
274
*data = g_strdup(def);
277
awn_config_client_notify_add (client, group, key, (AwnConfigClientNotifyFunc)awn_notify_string, data);
281
awn_load_float(AwnConfigClient *client, const gchar *group, const gchar* key, gfloat *data, gfloat def)
283
if (awn_config_client_entry_exists (client, group, key)) {
284
*data = awn_config_client_get_float (client, group, key, NULL);
286
g_print("%s unset, setting now\n", key);
287
awn_config_client_set_float (client, group, key, def, NULL);
291
awn_config_client_notify_add (client, group, key, (AwnConfigClientNotifyFunc)awn_notify_float, data);
295
awn_load_int(AwnConfigClient *client, const gchar *group, const gchar* key, gint *data, gint def)
297
if (awn_config_client_entry_exists (client, group, key)) {
298
*data = awn_config_client_get_int (client, group, key, NULL);
300
g_print("%s unset, setting now\n", key);
301
awn_config_client_set_int (client, group, key, def, NULL);
305
awn_config_client_notify_add (client, group, key, (AwnConfigClientNotifyFunc)awn_notify_int, data);
309
awn_load_color(AwnConfigClient *client, const gchar *group, const gchar* key, AwnColor *color, const gchar * def)
312
if (awn_config_client_entry_exists (client, group, key)) {
313
hex2float (awn_config_client_get_string (client, group, key, NULL), colors);
315
g_print("%s unset, setting now\n", key);
316
awn_config_client_set_string (client, group, key, (gchar*)def, NULL);
317
hex2float ( (gchar*)def, colors);
319
color->red = colors[0];
320
color->green = colors[1];
321
color->blue = colors[2];
322
color->alpha = colors[3];
324
awn_config_client_notify_add (client, group, key, (AwnConfigClientNotifyFunc)awn_notify_color, color);
328
awn_load_string_list(AwnConfigClient *client, const gchar *group, const gchar* key, GSList **data, GSList *def)
330
if (awn_config_client_entry_exists (client, group, key)) {
331
*data = awn_config_client_get_list (client, group, key, AWN_CONFIG_CLIENT_LIST_TYPE_STRING, NULL);
333
g_print("%s unset, setting now\n", key);
334
awn_config_client_set_list (client, group, key, AWN_CONFIG_CLIENT_LIST_TYPE_STRING, def, NULL);
342
if ((hexchar >= '0') && (hexchar <= '9')) return hexchar - '0';
343
if ((hexchar >= 'A') && (hexchar <= 'F')) return hexchar - 'A' + 10;
344
if ((hexchar >= 'a') && (hexchar <= 'f')) return hexchar - 'a' + 10;
346
return -1; // Wrong character
351
hex2float(gchar* HexColor, gfloat* FloatColor)
353
gchar* HexColorPtr = HexColor;
356
for (i = 0; i < 4; i++)
358
gint IntColor = (getdec(HexColorPtr[0]) * 16) +
359
getdec(HexColorPtr[1]);
361
FloatColor[i] = (gfloat) IntColor / 255.0;