1 /**************************************************************************
3 * Tint2 : read/write config file
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
25 #include <cairo-xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
33 #include <glib/gstdio.h>
34 #include <pango/pangocairo.h>
35 #include <pango/pangoxft.h>
43 #include "taskbarname.h"
44 #include "systraybar.h"
60 // --------------------------------------------------
61 // backward compatibility
62 // detect if it's an old config file (==1)
63 static int new_config_file
;
75 if (config_path
) g_free(config_path
);
76 if (snapshot_path
) g_free(snapshot_path
);
80 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
84 if (*value1
) free (*value1
);
85 if (*value2
) free (*value2
);
86 if (*value3
) free (*value3
);
88 if ((b
= strchr (value
, ' '))) {
96 *value1
= strdup (value
);
100 if ((c
= strchr (b
, ' '))) {
108 *value2
= strdup (b
);
113 *value3
= strdup (c
);
119 void get_action (char *event
, int *action
)
121 if (strcmp (event
, "none") == 0)
123 else if (strcmp (event
, "close") == 0)
125 else if (strcmp (event
, "toggle") == 0)
127 else if (strcmp (event
, "iconify") == 0)
129 else if (strcmp (event
, "shade") == 0)
131 else if (strcmp (event
, "toggle_iconify") == 0)
132 *action
= TOGGLE_ICONIFY
;
133 else if (strcmp (event
, "maximize_restore") == 0)
134 *action
= MAXIMIZE_RESTORE
;
135 else if (strcmp (event
, "desktop_left") == 0)
136 *action
= DESKTOP_LEFT
;
137 else if (strcmp (event
, "desktop_right") == 0)
138 *action
= DESKTOP_RIGHT
;
139 else if (strcmp (event
, "next_task") == 0)
141 else if (strcmp (event
, "prev_task") == 0)
146 int get_task_status(char* status
)
148 if (strcmp(status
, "active") == 0)
150 if (strcmp(status
, "iconified") == 0)
151 return TASK_ICONIFIED
;
152 if (strcmp(status
, "urgent") == 0)
158 int config_get_monitor(char* monitor
)
160 if (strcmp(monitor
, "all") != 0) {
162 int ret_int
= strtol(monitor
, &endptr
, 10);
166 // monitor specified by name, not by index
168 for (i
=0; i
<server
.nb_monitor
; ++i
) {
169 if (server
.monitor
[i
].names
== 0)
170 // xrandr can't identify monitors
173 while (server
.monitor
[i
].names
[j
] != 0) {
174 if (strcmp(monitor
, server
.monitor
[i
].names
[j
++]) == 0)
180 // monitor == "all" or monitor not found or xrandr can't identify monitors
184 void add_entry (char *key
, char *value
)
186 char *value1
=0, *value2
=0, *value3
=0;
188 /* Background and border */
189 if (strcmp (key
, "rounded") == 0) {
190 // 'rounded' is the first parameter => alloc a new background
192 bg
.border
.rounded
= atoi(value
);
193 g_array_append_val(backgrounds
, bg
);
195 else if (strcmp (key
, "border_width") == 0) {
196 g_array_index(backgrounds
, Background
, backgrounds
->len
-1).border
.width
= atoi(value
);
198 else if (strcmp (key
, "background_color") == 0) {
199 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
200 extract_values(value
, &value1
, &value2
, &value3
);
201 get_color (value1
, bg
->back
.color
);
202 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
203 else bg
->back
.alpha
= 0.5;
205 else if (strcmp (key
, "border_color") == 0) {
206 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
207 extract_values(value
, &value1
, &value2
, &value3
);
208 get_color (value1
, bg
->border
.color
);
209 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
210 else bg
->border
.alpha
= 0.5;
214 else if (strcmp (key
, "panel_monitor") == 0) {
215 panel_config
.monitor
= config_get_monitor(value
);
217 else if (strcmp (key
, "panel_size") == 0) {
218 extract_values(value
, &value1
, &value2
, &value3
);
221 if ((b
= strchr (value1
, '%'))) {
223 panel_config
.pourcentx
= 1;
225 panel_config
.area
.width
= atoi(value1
);
226 if (panel_config
.area
.width
== 0) {
228 panel_config
.area
.width
= 100;
229 panel_config
.pourcentx
= 1;
232 if ((b
= strchr (value2
, '%'))) {
234 panel_config
.pourcenty
= 1;
236 panel_config
.area
.height
= atoi(value2
);
239 else if (strcmp (key
, "panel_items") == 0) {
241 panel_items_order
= strdup(value
);
243 for (j
=0 ; j
< strlen(panel_items_order
) ; j
++) {
244 if (panel_items_order
[j
] == 'L')
245 launcher_enabled
= 1;
246 if (panel_items_order
[j
] == 'T')
248 if (panel_items_order
[j
] == 'B') {
249 #ifdef ENABLE_BATTERY
252 fprintf(stderr
, "tint2 is build without battery support\n");
255 if (panel_items_order
[j
] == 'S') {
256 // systray disabled in snapshot mode
257 if (snapshot_path
== 0)
260 if (panel_items_order
[j
] == 'C')
264 else if (strcmp (key
, "panel_margin") == 0) {
265 extract_values(value
, &value1
, &value2
, &value3
);
266 panel_config
.marginx
= atoi (value1
);
267 if (value2
) panel_config
.marginy
= atoi (value2
);
269 else if (strcmp (key
, "panel_padding") == 0) {
270 extract_values(value
, &value1
, &value2
, &value3
);
271 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
272 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
273 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
275 else if (strcmp (key
, "panel_position") == 0) {
276 extract_values(value
, &value1
, &value2
, &value3
);
277 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
279 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
280 else panel_position
= CENTER
;
283 if (!value2
) panel_position
|= CENTER
;
285 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
287 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
288 else panel_position
|= CENTER
;
291 if (!value3
) panel_horizontal
= 1;
293 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
294 else panel_horizontal
= 1;
297 else if (strcmp (key
, "font_shadow") == 0)
298 panel_config
.g_task
.font_shadow
= atoi (value
);
299 else if (strcmp (key
, "panel_background_id") == 0) {
300 int id
= atoi (value
);
301 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
302 panel_config
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
304 else if (strcmp (key
, "wm_menu") == 0)
305 wm_menu
= atoi (value
);
306 else if (strcmp (key
, "panel_dock") == 0)
307 panel_dock
= atoi (value
);
308 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
309 max_tick_urgent
= atoi (value
);
310 else if (strcmp (key
, "panel_layer") == 0) {
311 if (strcmp(value
, "bottom") == 0)
312 panel_layer
= BOTTOM_LAYER
;
313 else if (strcmp(value
, "top") == 0)
314 panel_layer
= TOP_LAYER
;
316 panel_layer
= NORMAL_LAYER
;
320 else if (strcmp (key
, "battery_low_status") == 0) {
321 #ifdef ENABLE_BATTERY
322 battery_low_status
= atoi(value
);
323 if(battery_low_status
< 0 || battery_low_status
> 100)
324 battery_low_status
= 0;
327 else if (strcmp (key
, "battery_low_cmd") == 0) {
328 #ifdef ENABLE_BATTERY
329 if (strlen(value
) > 0)
330 battery_low_cmd
= strdup (value
);
333 else if (strcmp (key
, "bat1_font") == 0) {
334 #ifdef ENABLE_BATTERY
335 bat1_font_desc
= pango_font_description_from_string (value
);
338 else if (strcmp (key
, "bat2_font") == 0) {
339 #ifdef ENABLE_BATTERY
340 bat2_font_desc
= pango_font_description_from_string (value
);
343 else if (strcmp (key
, "battery_font_color") == 0) {
344 #ifdef ENABLE_BATTERY
345 extract_values(value
, &value1
, &value2
, &value3
);
346 get_color (value1
, panel_config
.battery
.font
.color
);
347 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
348 else panel_config
.battery
.font
.alpha
= 0.5;
351 else if (strcmp (key
, "battery_padding") == 0) {
352 #ifdef ENABLE_BATTERY
353 extract_values(value
, &value1
, &value2
, &value3
);
354 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
355 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
356 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
359 else if (strcmp (key
, "battery_background_id") == 0) {
360 #ifdef ENABLE_BATTERY
361 int id
= atoi (value
);
362 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
363 panel_config
.battery
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
366 else if (strcmp (key
, "battery_hide") == 0) {
367 #ifdef ENABLE_BATTERY
368 percentage_hide
= atoi (value
);
369 if (percentage_hide
== 0)
370 percentage_hide
= 101;
375 else if (strcmp (key
, "time1_format") == 0) {
376 if (new_config_file
== 0) {
378 if (panel_items_order
) {
379 char* tmp
= g_strconcat(panel_items_order
, "C", NULL
);
380 g_free( panel_items_order
);
381 panel_items_order
= tmp
;
384 panel_items_order
= g_strdup("C");
386 if (strlen(value
) > 0) {
387 time1_format
= strdup (value
);
391 else if (strcmp (key
, "time2_format") == 0) {
392 if (strlen(value
) > 0)
393 time2_format
= strdup (value
);
395 else if (strcmp (key
, "time1_font") == 0) {
396 time1_font_desc
= pango_font_description_from_string (value
);
398 else if (strcmp(key
, "time1_timezone") == 0) {
399 if (strlen(value
) > 0)
400 time1_timezone
= strdup(value
);
402 else if (strcmp(key
, "time2_timezone") == 0) {
403 if (strlen(value
) > 0)
404 time2_timezone
= strdup(value
);
406 else if (strcmp (key
, "time2_font") == 0) {
407 time2_font_desc
= pango_font_description_from_string (value
);
409 else if (strcmp (key
, "clock_font_color") == 0) {
410 extract_values(value
, &value1
, &value2
, &value3
);
411 get_color (value1
, panel_config
.clock
.font
.color
);
412 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
413 else panel_config
.clock
.font
.alpha
= 0.5;
415 else if (strcmp (key
, "clock_padding") == 0) {
416 extract_values(value
, &value1
, &value2
, &value3
);
417 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
418 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
419 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
421 else if (strcmp (key
, "clock_background_id") == 0) {
422 int id
= atoi (value
);
423 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
424 panel_config
.clock
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
426 else if (strcmp(key
, "clock_tooltip") == 0) {
427 if (strlen(value
) > 0)
428 time_tooltip_format
= strdup (value
);
430 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
431 if (strlen(value
) > 0)
432 time_tooltip_timezone
= strdup(value
);
434 else if (strcmp(key
, "clock_lclick_command") == 0) {
435 if (strlen(value
) > 0)
436 clock_lclick_command
= strdup(value
);
438 else if (strcmp(key
, "clock_rclick_command") == 0) {
439 if (strlen(value
) > 0)
440 clock_rclick_command
= strdup(value
);
444 else if (strcmp (key
, "taskbar_mode") == 0) {
445 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
446 else panel_mode
= SINGLE_DESKTOP
;
448 else if (strcmp (key
, "taskbar_padding") == 0) {
449 extract_values(value
, &value1
, &value2
, &value3
);
450 panel_config
.g_taskbar
.area
.paddingxlr
= panel_config
.g_taskbar
.area
.paddingx
= atoi (value1
);
451 if (value2
) panel_config
.g_taskbar
.area
.paddingy
= atoi (value2
);
452 if (value3
) panel_config
.g_taskbar
.area
.paddingx
= atoi (value3
);
454 else if (strcmp (key
, "taskbar_background_id") == 0) {
455 int id
= atoi (value
);
456 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
457 panel_config
.g_taskbar
.background
[TASKBAR_NORMAL
] = &g_array_index(backgrounds
, Background
, id
);
458 if (panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] == 0)
459 panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] = panel_config
.g_taskbar
.background
[TASKBAR_NORMAL
];
461 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
462 int id
= atoi (value
);
463 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
464 panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] = &g_array_index(backgrounds
, Background
, id
);
466 else if (strcmp (key
, "taskbar_name") == 0) {
467 taskbarname_enabled
= atoi (value
);
469 else if (strcmp (key
, "taskbar_name_background_id") == 0) {
471 else if (strcmp (key
, "taskbar_name_active_background_id") == 0) {
473 else if (strcmp (key
, "taskbar_name_font") == 0) {
475 else if (strcmp (key
, "taskbar_name_font_color") == 0) {
477 else if (strcmp (key
, "taskbar_name_active_font_color") == 0) {
481 else if (strcmp (key
, "task_text") == 0)
482 panel_config
.g_task
.text
= atoi (value
);
483 else if (strcmp (key
, "task_icon") == 0)
484 panel_config
.g_task
.icon
= atoi (value
);
485 else if (strcmp (key
, "task_centered") == 0)
486 panel_config
.g_task
.centered
= atoi (value
);
487 else if (strcmp (key
, "task_width") == 0) {
488 // old parameter : just for backward compatibility
489 panel_config
.g_task
.maximum_width
= atoi (value
);
490 panel_config
.g_task
.maximum_height
= 30;
492 else if (strcmp (key
, "task_maximum_size") == 0) {
493 extract_values(value
, &value1
, &value2
, &value3
);
494 panel_config
.g_task
.maximum_width
= atoi (value1
);
495 panel_config
.g_task
.maximum_height
= 30;
497 panel_config
.g_task
.maximum_height
= atoi (value2
);
499 else if (strcmp (key
, "task_padding") == 0) {
500 extract_values(value
, &value1
, &value2
, &value3
);
501 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
502 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
503 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
505 else if (strcmp (key
, "task_font") == 0) {
506 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
508 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
509 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
510 int status
= get_task_status(split
[1]);
512 extract_values(value
, &value1
, &value2
, &value3
);
514 if (value2
) alpha
= (atoi (value2
) / 100.0);
515 get_color (value1
, panel_config
.g_task
.font
[status
].color
);
516 panel_config
.g_task
.font
[status
].alpha
= alpha
;
517 panel_config
.g_task
.config_font_mask
|= (1<<status
);
519 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
520 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
521 int status
= get_task_status(split
[1]);
523 extract_values(value
, &value1
, &value2
, &value3
);
524 panel_config
.g_task
.alpha
[status
] = atoi(value1
);
525 panel_config
.g_task
.saturation
[status
] = atoi(value2
);
526 panel_config
.g_task
.brightness
[status
] = atoi(value3
);
527 panel_config
.g_task
.config_asb_mask
|= (1<<status
);
529 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
530 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
531 int status
= get_task_status(split
[1]);
533 int id
= atoi (value
);
534 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
535 panel_config
.g_task
.background
[status
] = &g_array_index(backgrounds
, Background
, id
);
536 panel_config
.g_task
.config_background_mask
|= (1<<status
);
537 if (status
== TASK_NORMAL
) panel_config
.g_task
.area
.bg
= panel_config
.g_task
.background
[TASK_NORMAL
];
541 else if (strcmp (key
, "systray_padding") == 0) {
542 extract_values(value
, &value1
, &value2
, &value3
);
543 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
544 if (value2
) systray
.area
.paddingy
= atoi (value2
);
545 if (value3
) systray
.area
.paddingx
= atoi (value3
);
547 else if (strcmp (key
, "systray_background_id") == 0) {
548 int id
= atoi (value
);
549 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
550 systray
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
552 else if (strcmp(key
, "systray_sort") == 0) {
553 if (strcmp(value
, "descending") == 0)
555 else if (strcmp(value
, "ascending") == 0)
557 else if (strcmp(value
, "left2right") == 0)
559 else if (strcmp(value
, "right2left") == 0)
562 else if (strcmp(key
, "systray_icon_size") == 0) {
563 systray_max_icon_size
= atoi(value
);
565 else if (strcmp(key
, "systray_icon_asb") == 0) {
566 extract_values(value
, &value1
, &value2
, &value3
);
567 systray
.alpha
= atoi(value1
);
568 systray
.saturation
= atoi(value2
);
569 systray
.brightness
= atoi(value3
);
573 else if (strcmp (key
, "launcher_padding") == 0) {
574 extract_values(value
, &value1
, &value2
, &value3
);
575 panel_config
.launcher
.area
.paddingxlr
= panel_config
.launcher
.area
.paddingx
= atoi (value1
);
576 if (value2
) panel_config
.launcher
.area
.paddingy
= atoi (value2
);
577 if (value3
) panel_config
.launcher
.area
.paddingx
= atoi (value3
);
579 else if (strcmp (key
, "launcher_background_id") == 0) {
580 int id
= atoi (value
);
581 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
582 panel_config
.launcher
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
584 else if (strcmp(key
, "launcher_icon_size") == 0) {
585 launcher_max_icon_size
= atoi(value
);
587 else if (strcmp(key
, "launcher_item_app") == 0) {
588 char *app
= strdup(value
);
589 panel_config
.launcher
.list_apps
= g_slist_append(panel_config
.launcher
.list_apps
, app
);
591 else if (strcmp(key
, "launcher_icon_theme") == 0) {
592 // if XSETTINGS manager running, tint2 use it.
593 if (!icon_theme_name
)
594 icon_theme_name
= strdup(value
);
598 else if (strcmp (key
, "tooltip") == 0)
599 g_tooltip
.enabled
= atoi(value
);
600 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
601 int timeout_msec
= 1000*atof(value
);
602 g_tooltip
.show_timeout_msec
= timeout_msec
;
604 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
605 int timeout_msec
= 1000*atof(value
);
606 g_tooltip
.hide_timeout_msec
= timeout_msec
;
608 else if (strcmp (key
, "tooltip_padding") == 0) {
609 extract_values(value
, &value1
, &value2
, &value3
);
610 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
611 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
613 else if (strcmp (key
, "tooltip_background_id") == 0) {
614 int id
= atoi (value
);
615 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
616 g_tooltip
.bg
= &g_array_index(backgrounds
, Background
, id
);
618 else if (strcmp (key
, "tooltip_font_color") == 0) {
619 extract_values(value
, &value1
, &value2
, &value3
);
620 get_color(value1
, g_tooltip
.font_color
.color
);
621 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
622 else g_tooltip
.font_color
.alpha
= 0.1;
624 else if (strcmp (key
, "tooltip_font") == 0) {
625 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
629 else if (strcmp (key
, "mouse_middle") == 0)
630 get_action (value
, &mouse_middle
);
631 else if (strcmp (key
, "mouse_right") == 0)
632 get_action (value
, &mouse_right
);
633 else if (strcmp (key
, "mouse_scroll_up") == 0)
634 get_action (value
, &mouse_scroll_up
);
635 else if (strcmp (key
, "mouse_scroll_down") == 0)
636 get_action (value
, &mouse_scroll_down
);
638 /* autohide options */
639 else if (strcmp(key
, "autohide") == 0)
640 panel_autohide
= atoi(value
);
641 else if (strcmp(key
, "autohide_show_timeout") == 0)
642 panel_autohide_show_timeout
= 1000*atof(value
);
643 else if (strcmp(key
, "autohide_hide_timeout") == 0)
644 panel_autohide_hide_timeout
= 1000*atof(value
);
645 else if (strcmp(key
, "strut_policy") == 0) {
646 if (strcmp(value
, "follow_size") == 0)
647 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
648 else if (strcmp(value
, "none") == 0)
649 panel_strut_policy
= STRUT_NONE
;
651 panel_strut_policy
= STRUT_MINIMUM
;
653 else if (strcmp(key
, "autohide_height") == 0) {
654 panel_autohide_height
= atoi(value
);
655 if (panel_autohide_height
== 0) {
656 // autohide need height > 0
657 panel_autohide_height
= 1;
662 else if (strcmp(key
, "systray") == 0) {
663 if (new_config_file
== 0) {
664 systray_enabled
= atoi(value
);
665 if (systray_enabled
) {
666 if (panel_items_order
) {
667 char* tmp
= g_strconcat(panel_items_order
, "S", NULL
);
668 g_free( panel_items_order
);
669 panel_items_order
= tmp
;
672 panel_items_order
= g_strdup("S");
676 else if (strcmp(key
, "battery") == 0) {
677 if (new_config_file
== 0) {
678 battery_enabled
= atoi(value
);
679 if (battery_enabled
) {
680 if (panel_items_order
) {
681 char* tmp
= g_strconcat(panel_items_order
, "B", NULL
);
682 g_free( panel_items_order
);
683 panel_items_order
= tmp
;
686 panel_items_order
= g_strdup("B");
691 fprintf(stderr
, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key
);
693 if (value1
) free (value1
);
694 if (value2
) free (value2
);
695 if (value3
) free (value3
);
701 const gchar
* const * system_dirs
;
705 // follow XDG specification
706 // check tint2rc in user directory
707 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
708 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
709 i
= config_read_file (path1
);
710 config_path
= strdup(path1
);
716 // copy tint2rc from system directory to user directory
718 system_dirs
= g_get_system_config_dirs();
719 for (i
= 0; system_dirs
[i
]; i
++) {
720 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
722 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
728 // copy file in user directory (path1)
729 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
730 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
733 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
734 copy_file(path2
, path1
);
737 i
= config_read_file (path1
);
738 config_path
= strdup(path1
);
746 int config_read_file (const char *path
)
752 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
754 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
755 if (parse_line(line
, &key
, &value
)) {
756 add_entry (key
, value
);
763 // append Taskbar item
764 if (new_config_file
== 0) {
766 if (panel_items_order
) {
767 char* tmp
= g_strconcat( "T", panel_items_order
, NULL
);
768 g_free(panel_items_order
);
769 panel_items_order
= tmp
;
772 panel_items_order
= g_strdup("T");