8 #include "properties.h"
9 #include "properties_rw.h"
12 void add_entry (char *key
, char *value
);
13 void hex2gdk(char *hex
, GdkColor
*color
);
17 void config_read_file (const char *path
)
23 if ((fp
= fopen(path
, "r")) == NULL
) return;
25 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
26 if (parse_line(line
, &key
, &value
)) {
27 add_entry (key
, value
);
36 void config_save_file(const char *path
) {
37 //printf("config_save_file : %s\n", path);
41 void add_entry (char *key
, char *value
)
43 char *value1
=0, *value2
=0, *value3
=0;
45 /* Background and border */
46 if (strcmp (key
, "rounded") == 0) {
47 // 'rounded' is the first parameter => alloc a new background
49 //bg.border.rounded = atoi(value);
50 //g_array_append_val(backgrounds, bg);
52 else if (strcmp (key
, "border_width") == 0) {
53 //g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
55 else if (strcmp (key
, "background_color") == 0) {
56 extract_values(value
, &value1
, &value2
, &value3
);
57 //Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
58 //get_color (value1, bg->back.color);
59 //if (value2) bg->back.alpha = (atoi (value2) / 100.0);
60 //else bg->back.alpha = 0.5;
62 else if (strcmp (key
, "border_color") == 0) {
63 extract_values(value
, &value1
, &value2
, &value3
);
64 //Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
65 //get_color (value1, bg->border.color);
66 //if (value2) bg->border.alpha = (atoi (value2) / 100.0);
67 //else bg->border.alpha = 0.5;
71 else if (strcmp (key
, "panel_size") == 0) {
72 extract_values(value
, &value1
, &value2
, &value3
);
74 if ((b
= strchr (value1
, '%'))) {
76 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_width_type
), 0);
79 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_width_type
), 1);
80 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_width
), atof(value1
));
81 if (atoi(value1
) == 0) {
83 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_width
), 100);
84 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_width_type
), 0);
86 if ((b
= strchr (value2
, '%'))) {
88 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_height_type
), 0);
91 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_height_type
), 1);
92 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_height
), atof(value2
));
94 else if (strcmp (key
, "panel_items") == 0) {
95 gtk_entry_set_text(GTK_ENTRY(items_order
), value
);
97 else if (strcmp (key
, "panel_margin") == 0) {
98 extract_values(value
, &value1
, &value2
, &value3
);
99 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_margin_x
), atof(value1
));
100 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_margin_y
), atof(value1
));
102 else if (strcmp (key
, "panel_padding") == 0) {
103 extract_values(value
, &value1
, &value2
, &value3
);
104 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_padding_x
), atof(value1
));
105 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_spacing
), atof(value1
));
106 if (value2
) gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_padding_y
), atof(value2
));
107 if (value3
) gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_spacing
), atof(value3
));
109 else if (strcmp (key
, "panel_position") == 0) {
110 extract_values(value
, &value1
, &value2
, &value3
);
112 if (strcmp (value1, "top") == 0) panel_position = TOP;
114 if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
115 else panel_position = CENTER;
118 if (!value2) panel_position |= CENTER;
120 if (strcmp (value2, "left") == 0) panel_position |= LEFT;
122 if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
123 else panel_position |= CENTER;
126 if (!value3) panel_horizontal = 1;
128 if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
129 else panel_horizontal = 1;
133 else if (strcmp (key
, "panel_background_id") == 0) {
134 //int id = atoi (value);
135 //id = (id < backgrounds->len && id >= 0) ? id : 0;
136 //panel_config.area.bg = &g_array_index(backgrounds, Background, id);
138 else if (strcmp (key
, "wm_menu") == 0) {
139 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(panel_wm_menu
), atoi(value
));
141 else if (strcmp (key
, "panel_dock") == 0) {
142 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(panel_dock
), atoi(value
));
144 else if (strcmp (key
, "panel_layer") == 0) {
145 if (strcmp(value
, "bottom") == 0)
146 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_layer
), 2);
147 else if (strcmp(value
, "top") == 0)
148 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_layer
), 0);
150 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_layer
), 1);
152 else if (strcmp (key
, "panel_monitor") == 0) {
153 //panel_config.monitor = config_get_monitor(value);
155 else if (strcmp (key
, "font_shadow") == 0) {
156 //panel_config.g_task.font_shadow = atoi (value);
158 else if (strcmp (key
, "urgent_nb_of_blink") == 0) {
159 //max_tick_urgent = atoi (value);
162 /* autohide options */
163 else if (strcmp(key
, "autohide") == 0) {
164 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(panel_autohide
), atoi(value
));
166 else if (strcmp(key
, "autohide_show_timeout") == 0) {
167 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_autohide_show_time
), atof(value
));
169 else if (strcmp(key
, "autohide_hide_timeout") == 0) {
170 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_autohide_hide_time
), atof(value
));
172 else if (strcmp(key
, "strut_policy") == 0) {
173 if (strcmp(value
, "follow_size") == 0)
174 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_strut_policy
), 0);
175 else if (strcmp(value
, "none") == 0)
176 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_strut_policy
), 2);
178 gtk_combo_box_set_active(GTK_COMBO_BOX(panel_combo_strut_policy
), 1);
180 else if (strcmp(key
, "autohide_height") == 0) {
181 if (atoi(value
) == 0) {
182 // autohide need height > 0
183 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_autohide_size
), 1);
186 gtk_spin_button_set_value(GTK_SPIN_BUTTON(panel_autohide_size
), atof(value
));
190 else if (strcmp (key
, "battery_low_status") == 0) {
191 #ifdef ENABLE_BATTERY
192 //battery_low_status = atoi(value);
193 //if(battery_low_status < 0 || battery_low_status > 100)
194 //battery_low_status = 0;
197 else if (strcmp (key
, "battery_low_cmd") == 0) {
198 #ifdef ENABLE_BATTERY
199 //if (strlen(value) > 0)
200 //battery_low_cmd = strdup (value);
203 else if (strcmp (key
, "bat1_font") == 0) {
204 #ifdef ENABLE_BATTERY
205 //bat1_font_desc = pango_font_description_from_string (value);
208 else if (strcmp (key
, "bat2_font") == 0) {
209 #ifdef ENABLE_BATTERY
210 //bat2_font_desc = pango_font_description_from_string (value);
213 else if (strcmp (key
, "battery_font_color") == 0) {
214 #ifdef ENABLE_BATTERY
215 extract_values(value
, &value1
, &value2
, &value3
);
216 //get_color (value1, panel_config.battery.font.color);
217 //if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
218 //else panel_config.battery.font.alpha = 0.5;
221 else if (strcmp (key
, "battery_padding") == 0) {
222 #ifdef ENABLE_BATTERY
223 extract_values(value
, &value1
, &value2
, &value3
);
224 //panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
225 //if (value2) panel_config.battery.area.paddingy = atoi (value2);
226 //if (value3) panel_config.battery.area.paddingx = atoi (value3);
229 else if (strcmp (key
, "battery_background_id") == 0) {
230 #ifdef ENABLE_BATTERY
231 //int id = atoi (value);
232 //id = (id < backgrounds->len && id >= 0) ? id : 0;
233 //panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id);
236 else if (strcmp (key
, "battery_hide") == 0) {
237 #ifdef ENABLE_BATTERY
238 //percentage_hide = atoi (value);
239 //if (percentage_hide == 0)
240 // percentage_hide = 101;
245 else if (strcmp (key
, "time1_format") == 0) {
246 //if (strlen(value) > 0) {
247 //time1_format = strdup (value);
251 else if (strcmp (key
, "time2_format") == 0) {
252 //if (strlen(value) > 0)
253 //time2_format = strdup (value);
255 else if (strcmp (key
, "time1_font") == 0) {
256 //time1_font_desc = pango_font_description_from_string (value);
258 else if (strcmp(key
, "time1_timezone") == 0) {
259 //if (strlen(value) > 0)
260 //time1_timezone = strdup(value);
262 else if (strcmp(key
, "time2_timezone") == 0) {
263 //if (strlen(value) > 0)
264 //time2_timezone = strdup(value);
266 else if (strcmp (key
, "time2_font") == 0) {
267 //time2_font_desc = pango_font_description_from_string (value);
269 else if (strcmp (key
, "clock_font_color") == 0) {
270 extract_values(value
, &value1
, &value2
, &value3
);
271 //get_color (value1, panel_config.clock.font.color);
272 //if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
273 //else panel_config.clock.font.alpha = 0.5;
275 else if (strcmp (key
, "clock_padding") == 0) {
276 extract_values(value
, &value1
, &value2
, &value3
);
277 //panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
278 //if (value2) panel_config.clock.area.paddingy = atoi (value2);
279 //if (value3) panel_config.clock.area.paddingx = atoi (value3);
281 else if (strcmp (key
, "clock_background_id") == 0) {
282 //int id = atoi (value);
283 //id = (id < backgrounds->len && id >= 0) ? id : 0;
284 //panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id);
286 else if (strcmp(key
, "clock_tooltip") == 0) {
287 //if (strlen(value) > 0)
288 //time_tooltip_format = strdup (value);
290 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
291 //if (strlen(value) > 0)
292 //time_tooltip_timezone = strdup(value);
294 else if (strcmp(key
, "clock_lclick_command") == 0) {
295 //if (strlen(value) > 0)
296 //clock_lclick_command = strdup(value);
298 else if (strcmp(key
, "clock_rclick_command") == 0) {
299 //if (strlen(value) > 0)
300 //clock_rclick_command = strdup(value);
304 else if (strcmp (key
, "taskbar_mode") == 0) {
305 if (strcmp (value
, "multi_desktop") == 0)
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(taskbar_show_desktop
), 1);
308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(taskbar_show_desktop
), 0);
310 else if (strcmp (key
, "taskbar_padding") == 0) {
311 extract_values(value
, &value1
, &value2
, &value3
);
312 gtk_spin_button_set_value(GTK_SPIN_BUTTON(taskbar_padding_x
), atof(value1
));
313 gtk_spin_button_set_value(GTK_SPIN_BUTTON(taskbar_spacing
), atof(value1
));
314 if (value2
) gtk_spin_button_set_value(GTK_SPIN_BUTTON(taskbar_padding_y
), atof(value2
));
315 if (value3
) gtk_spin_button_set_value(GTK_SPIN_BUTTON(taskbar_spacing
), atof(value3
));
317 else if (strcmp (key
, "taskbar_background_id") == 0) {
318 //int id = atoi (value);
319 //id = (id < backgrounds->len && id >= 0) ? id : 0;
320 //panel_config.g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
321 //if (panel_config.g_taskbar.background[TASKBAR_ACTIVE] == 0)
322 //panel_config.g_taskbar.background[TASKBAR_ACTIVE] = panel_config.g_taskbar.background[TASKBAR_NORMAL];
324 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
325 //int id = atoi (value);
326 //id = (id < backgrounds->len && id >= 0) ? id : 0;
327 //panel_config.g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
329 else if (strcmp (key
, "taskbar_name") == 0) {
330 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(taskbar_show_name
), atoi(value
));
332 else if (strcmp (key
, "taskbar_name_padding") == 0) {
333 extract_values(value
, &value1
, &value2
, &value3
);
334 gtk_spin_button_set_value(GTK_SPIN_BUTTON(taskbar_name_padding_x
), atof(value1
));
336 else if (strcmp (key
, "taskbar_name_background_id") == 0) {
337 //int id = atoi (value);
338 //id = (id < backgrounds->len && id >= 0) ? id : 0;
339 //panel_config.g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
340 //if (panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] == 0)
341 //panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = panel_config.g_taskbar.background_name[TASKBAR_NORMAL];
343 else if (strcmp (key
, "taskbar_name_active_background_id") == 0) {
344 //int id = atoi (value);
345 //id = (id < backgrounds->len && id >= 0) ? id : 0;
346 //panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
348 else if (strcmp (key
, "taskbar_name_font") == 0) {
349 gtk_font_button_set_font_name(GTK_FONT_BUTTON(taskbar_name_font
), value
);
351 else if (strcmp (key
, "taskbar_name_font_color") == 0) {
352 extract_values(value
, &value1
, &value2
, &value3
);
354 hex2gdk(value1
, &col
);
355 gtk_color_button_set_color(GTK_COLOR_BUTTON(taskbar_name_inactive_color
), &col
);
357 int alpha
= atoi(value2
);
358 gtk_color_button_set_alpha(GTK_COLOR_BUTTON(taskbar_name_inactive_color
), (alpha
*65535)/100);
361 else if (strcmp (key
, "taskbar_name_active_font_color") == 0) {
362 extract_values(value
, &value1
, &value2
, &value3
);
364 hex2gdk(value1
, &col
);
365 gtk_color_button_set_color(GTK_COLOR_BUTTON(taskbar_name_active_color
), &col
);
367 int alpha
= atoi(value2
);
368 gtk_color_button_set_alpha(GTK_COLOR_BUTTON(taskbar_name_active_color
), (alpha
*65535)/100);
373 else if (strcmp (key
, "task_text") == 0) {
374 //panel_config.g_task.text = atoi (value);
376 else if (strcmp (key
, "task_icon") == 0) {
377 //panel_config.g_task.icon = atoi (value);
379 else if (strcmp (key
, "task_centered") == 0) {
380 //panel_config.g_task.centered = atoi (value);
382 else if (strcmp (key
, "task_width") == 0) {
383 // old parameter : just for backward compatibility
384 //panel_config.g_task.maximum_width = atoi (value);
385 //panel_config.g_task.maximum_height = 30;
387 else if (strcmp (key
, "task_maximum_size") == 0) {
388 extract_values(value
, &value1
, &value2
, &value3
);
389 //panel_config.g_task.maximum_width = atoi (value1);
390 //panel_config.g_task.maximum_height = 30;
392 //panel_config.g_task.maximum_height = atoi (value2);
394 else if (strcmp (key
, "task_padding") == 0) {
395 extract_values(value
, &value1
, &value2
, &value3
);
396 //panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
397 //if (value2) panel_config.g_task.area.paddingy = atoi (value2);
398 //if (value3) panel_config.g_task.area.paddingx = atoi (value3);
400 else if (strcmp (key
, "task_font") == 0) {
401 //panel_config.g_task.font_desc = pango_font_description_from_string (value);
403 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
404 /*gchar** split = g_regex_split_simple("_", key, 0, 0);
405 int status = get_task_status(split[1]);
407 extract_values(value, &value1, &value2, &value3);
409 if (value2) alpha = (atoi (value2) / 100.0);
410 get_color (value1, panel_config.g_task.font[status].color);
411 panel_config.g_task.font[status].alpha = alpha;
412 panel_config.g_task.config_font_mask |= (1<<status);
415 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
416 /*gchar** split = g_regex_split_simple("_", key, 0, 0);
417 int status = get_task_status(split[1]);
419 extract_values(value, &value1, &value2, &value3);
420 panel_config.g_task.alpha[status] = atoi(value1);
421 panel_config.g_task.saturation[status] = atoi(value2);
422 panel_config.g_task.brightness[status] = atoi(value3);
423 panel_config.g_task.config_asb_mask |= (1<<status);
426 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
427 /*gchar** split = g_regex_split_simple("_", key, 0, 0);
428 int status = get_task_status(split[1]);
430 int id = atoi (value);
431 id = (id < backgrounds->len && id >= 0) ? id : 0;
432 panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
433 panel_config.g_task.config_background_mask |= (1<<status);
434 if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
437 // "tooltip" is deprecated but here for backwards compatibility
438 else if (strcmp (key
, "task_tooltip") == 0 || strcmp(key
, "tooltip") == 0) {
439 //panel_config.g_task.tooltip_enabled = atoi(value);
443 else if (strcmp (key
, "systray_padding") == 0) {
444 extract_values(value
, &value1
, &value2
, &value3
);
445 //systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
446 //if (value2) systray.area.paddingy = atoi (value2);
447 //if (value3) systray.area.paddingx = atoi (value3);
449 else if (strcmp (key
, "systray_background_id") == 0) {
450 //int id = atoi (value);
451 //id = (id < backgrounds->len && id >= 0) ? id : 0;
452 //systray.area.bg = &g_array_index(backgrounds, Background, id);
454 else if (strcmp(key
, "systray_sort") == 0) {
455 if (strcmp(value
, "descending") == 0)
456 gtk_combo_box_set_active(GTK_COMBO_BOX(systray_icon_order
), 1);
457 else if (strcmp(value
, "ascending") == 0)
458 gtk_combo_box_set_active(GTK_COMBO_BOX(systray_icon_order
), 0);
459 else if (strcmp(value
, "right2left") == 0)
460 gtk_combo_box_set_active(GTK_COMBO_BOX(systray_icon_order
), 3);
461 else // default to left2right
462 gtk_combo_box_set_active(GTK_COMBO_BOX(systray_icon_order
), 2);
464 else if (strcmp(key
, "systray_icon_size") == 0) {
465 //systray_max_icon_size = atoi(value);
467 else if (strcmp(key
, "systray_icon_asb") == 0) {
468 extract_values(value
, &value1
, &value2
, &value3
);
469 //systray.alpha = atoi(value1);
470 //systray.saturation = atoi(value2);
471 //systray.brightness = atoi(value3);
475 else if (strcmp (key
, "launcher_padding") == 0) {
476 extract_values(value
, &value1
, &value2
, &value3
);
477 //panel_config.launcher.area.paddingxlr = panel_config.launcher.area.paddingx = atoi (value1);
478 //if (value2) panel_config.launcher.area.paddingy = atoi (value2);
479 //if (value3) panel_config.launcher.area.paddingx = atoi (value3);
481 else if (strcmp (key
, "launcher_background_id") == 0) {
482 //int id = atoi (value);
483 //id = (id < backgrounds->len && id >= 0) ? id : 0;
484 //panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id);
486 else if (strcmp(key
, "launcher_icon_size") == 0) {
487 //launcher_max_icon_size = atoi(value);
489 else if (strcmp(key
, "launcher_item_app") == 0) {
490 //char *app = strdup(value);
491 //panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app);
493 else if (strcmp(key
, "launcher_icon_theme") == 0) {
494 // if XSETTINGS manager running, tint2 use it.
495 //icon_theme_name = strdup(value);
499 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
500 //int timeout_msec = 1000*atof(value);
502 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
503 //int timeout_msec = 1000*atof(value);
505 else if (strcmp (key
, "tooltip_padding") == 0) {
506 extract_values(value
, &value1
, &value2
, &value3
);
507 //if (value1) g_tooltip.paddingx = atoi(value1);
508 //if (value2) g_tooltip.paddingy = atoi(value2);
510 else if (strcmp (key
, "tooltip_background_id") == 0) {
511 //int id = atoi (value);
512 //id = (id < backgrounds->len && id >= 0) ? id : 0;
513 //g_tooltip.bg = &g_array_index(backgrounds, Background, id);
515 else if (strcmp (key
, "tooltip_font_color") == 0) {
516 extract_values(value
, &value1
, &value2
, &value3
);
517 //get_color(value1, g_tooltip.font_color.color);
518 //if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
519 //else g_tooltip.font_color.alpha = 0.1;
521 else if (strcmp (key
, "tooltip_font") == 0) {
522 //g_tooltip.font_desc = pango_font_description_from_string(value);
526 else if (strcmp (key
, "mouse_middle") == 0) {
527 //get_action (value, &mouse_middle);
529 else if (strcmp (key
, "mouse_right") == 0) {
531 else if (strcmp (key
, "mouse_scroll_up") == 0) {
533 else if (strcmp (key
, "mouse_scroll_down") == 0) {
536 if (value1
) free (value1
);
537 if (value2
) free (value2
);
538 if (value3
) free (value3
);
542 void hex2gdk(char *hex
, GdkColor
*color
)
544 if (hex
== NULL
|| hex
[0] != '#') return;
546 color
->red
= 257 * (hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]));
547 color
->green
= 257 * (hex_char_to_int (hex
[3]) * 16 + hex_char_to_int (hex
[4]));
548 color
->blue
= 257 * (hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]));