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)
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 panel_items_order
= strcat(panel_items_order
, "C");
381 panel_items_order
= strdup("C");
383 if (strlen(value
) > 0) {
384 time1_format
= strdup (value
);
388 else if (strcmp (key
, "time2_format") == 0) {
389 if (strlen(value
) > 0)
390 time2_format
= strdup (value
);
392 else if (strcmp (key
, "time1_font") == 0) {
393 time1_font_desc
= pango_font_description_from_string (value
);
395 else if (strcmp(key
, "time1_timezone") == 0) {
396 if (strlen(value
) > 0)
397 time1_timezone
= strdup(value
);
399 else if (strcmp(key
, "time2_timezone") == 0) {
400 if (strlen(value
) > 0)
401 time2_timezone
= strdup(value
);
403 else if (strcmp (key
, "time2_font") == 0) {
404 time2_font_desc
= pango_font_description_from_string (value
);
406 else if (strcmp (key
, "clock_font_color") == 0) {
407 extract_values(value
, &value1
, &value2
, &value3
);
408 get_color (value1
, panel_config
.clock
.font
.color
);
409 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
410 else panel_config
.clock
.font
.alpha
= 0.5;
412 else if (strcmp (key
, "clock_padding") == 0) {
413 extract_values(value
, &value1
, &value2
, &value3
);
414 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
415 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
416 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
418 else if (strcmp (key
, "clock_background_id") == 0) {
419 int id
= atoi (value
);
420 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
421 panel_config
.clock
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
423 else if (strcmp(key
, "clock_tooltip") == 0) {
424 if (strlen(value
) > 0)
425 time_tooltip_format
= strdup (value
);
427 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
428 if (strlen(value
) > 0)
429 time_tooltip_timezone
= strdup(value
);
431 else if (strcmp(key
, "clock_lclick_command") == 0) {
432 if (strlen(value
) > 0)
433 clock_lclick_command
= strdup(value
);
435 else if (strcmp(key
, "clock_rclick_command") == 0) {
436 if (strlen(value
) > 0)
437 clock_rclick_command
= strdup(value
);
441 else if (strcmp (key
, "taskbar_mode") == 0) {
442 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
443 else panel_mode
= SINGLE_DESKTOP
;
445 else if (strcmp (key
, "taskbar_padding") == 0) {
446 extract_values(value
, &value1
, &value2
, &value3
);
447 panel_config
.g_taskbar
.area
.paddingxlr
= panel_config
.g_taskbar
.area
.paddingx
= atoi (value1
);
448 if (value2
) panel_config
.g_taskbar
.area
.paddingy
= atoi (value2
);
449 if (value3
) panel_config
.g_taskbar
.area
.paddingx
= atoi (value3
);
451 else if (strcmp (key
, "taskbar_background_id") == 0) {
452 int id
= atoi (value
);
453 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
454 panel_config
.g_taskbar
.bg
= &g_array_index(backgrounds
, Background
, id
);
455 if (panel_config
.g_taskbar
.bg_active
== 0)
456 panel_config
.g_taskbar
.bg_active
= panel_config
.g_taskbar
.bg
;
457 panel_config
.g_taskbar
.area
.bg
= panel_config
.g_taskbar
.bg
;
459 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
460 int id
= atoi (value
);
461 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
462 panel_config
.g_taskbar
.bg_active
= &g_array_index(backgrounds
, Background
, id
);
464 else if (strcmp (key
, "taskbar_name") == 0) {
465 taskbarname_enabled
= atoi (value
);
467 else if (strcmp (key
, "taskbar_name_background_id") == 0) {
469 else if (strcmp (key
, "taskbar_name_active_background_id") == 0) {
471 else if (strcmp (key
, "taskbar_font_color") == 0) {
473 else if (strcmp (key
, "taskbar_active_font_color") == 0) {
477 else if (strcmp (key
, "task_text") == 0)
478 panel_config
.g_task
.text
= atoi (value
);
479 else if (strcmp (key
, "task_icon") == 0)
480 panel_config
.g_task
.icon
= atoi (value
);
481 else if (strcmp (key
, "task_centered") == 0)
482 panel_config
.g_task
.centered
= atoi (value
);
483 else if (strcmp (key
, "task_width") == 0) {
484 // old parameter : just for backward compatibility
485 panel_config
.g_task
.maximum_width
= atoi (value
);
486 panel_config
.g_task
.maximum_height
= 30;
488 else if (strcmp (key
, "task_maximum_size") == 0) {
489 extract_values(value
, &value1
, &value2
, &value3
);
490 panel_config
.g_task
.maximum_width
= atoi (value1
);
491 panel_config
.g_task
.maximum_height
= 30;
493 panel_config
.g_task
.maximum_height
= atoi (value2
);
495 else if (strcmp (key
, "task_padding") == 0) {
496 extract_values(value
, &value1
, &value2
, &value3
);
497 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
498 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
499 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
501 else if (strcmp (key
, "task_font") == 0) {
502 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
504 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
505 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
506 int status
= get_task_status(split
[1]);
508 extract_values(value
, &value1
, &value2
, &value3
);
510 if (value2
) alpha
= (atoi (value2
) / 100.0);
511 get_color (value1
, panel_config
.g_task
.font
[status
].color
);
512 panel_config
.g_task
.font
[status
].alpha
= alpha
;
513 panel_config
.g_task
.config_font_mask
|= (1<<status
);
515 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
516 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
517 int status
= get_task_status(split
[1]);
519 extract_values(value
, &value1
, &value2
, &value3
);
520 panel_config
.g_task
.alpha
[status
] = atoi(value1
);
521 panel_config
.g_task
.saturation
[status
] = atoi(value2
);
522 panel_config
.g_task
.brightness
[status
] = atoi(value3
);
523 panel_config
.g_task
.config_asb_mask
|= (1<<status
);
525 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
526 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
527 int status
= get_task_status(split
[1]);
529 int id
= atoi (value
);
530 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
531 panel_config
.g_task
.background
[status
] = &g_array_index(backgrounds
, Background
, id
);
532 panel_config
.g_task
.config_background_mask
|= (1<<status
);
533 if (status
== TASK_NORMAL
) panel_config
.g_task
.area
.bg
= panel_config
.g_task
.background
[TASK_NORMAL
];
537 else if (strcmp (key
, "systray_padding") == 0) {
538 extract_values(value
, &value1
, &value2
, &value3
);
539 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
540 if (value2
) systray
.area
.paddingy
= atoi (value2
);
541 if (value3
) systray
.area
.paddingx
= atoi (value3
);
543 else if (strcmp (key
, "systray_background_id") == 0) {
544 int id
= atoi (value
);
545 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
546 systray
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
548 else if (strcmp(key
, "systray_sort") == 0) {
549 if (strcmp(value
, "descending") == 0)
551 else if (strcmp(value
, "ascending") == 0)
553 else if (strcmp(value
, "left2right") == 0)
555 else if (strcmp(value
, "right2left") == 0)
558 else if (strcmp(key
, "systray_icon_size") == 0) {
559 systray_max_icon_size
= atoi(value
);
561 else if (strcmp(key
, "systray_icon_asb") == 0) {
562 extract_values(value
, &value1
, &value2
, &value3
);
563 systray
.alpha
= atoi(value1
);
564 systray
.saturation
= atoi(value2
);
565 systray
.brightness
= atoi(value3
);
569 else if (strcmp (key
, "launcher_padding") == 0) {
570 extract_values(value
, &value1
, &value2
, &value3
);
571 panel_config
.launcher
.area
.paddingxlr
= panel_config
.launcher
.area
.paddingx
= atoi (value1
);
572 if (value2
) panel_config
.launcher
.area
.paddingy
= atoi (value2
);
573 if (value3
) panel_config
.launcher
.area
.paddingx
= atoi (value3
);
575 else if (strcmp (key
, "launcher_background_id") == 0) {
576 int id
= atoi (value
);
577 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
578 panel_config
.launcher
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
580 else if (strcmp(key
, "launcher_icon_size") == 0) {
581 launcher_max_icon_size
= atoi(value
);
583 else if (strcmp(key
, "launcher_item_app") == 0) {
584 char *app
= strdup(value
);
585 panel_config
.launcher
.list_apps
= g_slist_append(panel_config
.launcher
.list_apps
, app
);
587 else if (strcmp(key
, "launcher_icon_theme") == 0) {
588 char *app
= strdup(value
);
589 panel_config
.launcher
.icon_theme_names
= g_slist_append(panel_config
.launcher
.icon_theme_names
, app
);
593 else if (strcmp (key
, "tooltip") == 0)
594 g_tooltip
.enabled
= atoi(value
);
595 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
596 int timeout_msec
= 1000*atof(value
);
597 g_tooltip
.show_timeout_msec
= timeout_msec
;
599 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
600 int timeout_msec
= 1000*atof(value
);
601 g_tooltip
.hide_timeout_msec
= timeout_msec
;
603 else if (strcmp (key
, "tooltip_padding") == 0) {
604 extract_values(value
, &value1
, &value2
, &value3
);
605 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
606 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
608 else if (strcmp (key
, "tooltip_background_id") == 0) {
609 int id
= atoi (value
);
610 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
611 g_tooltip
.bg
= &g_array_index(backgrounds
, Background
, id
);
613 else if (strcmp (key
, "tooltip_font_color") == 0) {
614 extract_values(value
, &value1
, &value2
, &value3
);
615 get_color(value1
, g_tooltip
.font_color
.color
);
616 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
617 else g_tooltip
.font_color
.alpha
= 0.1;
619 else if (strcmp (key
, "tooltip_font") == 0) {
620 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
624 else if (strcmp (key
, "mouse_middle") == 0)
625 get_action (value
, &mouse_middle
);
626 else if (strcmp (key
, "mouse_right") == 0)
627 get_action (value
, &mouse_right
);
628 else if (strcmp (key
, "mouse_scroll_up") == 0)
629 get_action (value
, &mouse_scroll_up
);
630 else if (strcmp (key
, "mouse_scroll_down") == 0)
631 get_action (value
, &mouse_scroll_down
);
633 /* autohide options */
634 else if (strcmp(key
, "autohide") == 0)
635 panel_autohide
= atoi(value
);
636 else if (strcmp(key
, "autohide_show_timeout") == 0)
637 panel_autohide_show_timeout
= 1000*atof(value
);
638 else if (strcmp(key
, "autohide_hide_timeout") == 0)
639 panel_autohide_hide_timeout
= 1000*atof(value
);
640 else if (strcmp(key
, "strut_policy") == 0) {
641 if (strcmp(value
, "follow_size") == 0)
642 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
643 else if (strcmp(value
, "none") == 0)
644 panel_strut_policy
= STRUT_NONE
;
646 panel_strut_policy
= STRUT_MINIMUM
;
648 else if (strcmp(key
, "autohide_height") == 0) {
649 panel_autohide_height
= atoi(value
);
650 if (panel_autohide_height
== 0) {
651 // autohide need height > 0
652 panel_autohide_height
= 1;
657 else if (strcmp(key
, "systray") == 0) {
658 if (new_config_file
== 0) {
659 systray_enabled
= atoi(value
);
660 if (systray_enabled
) {
661 if (panel_items_order
)
662 panel_items_order
= strcat(panel_items_order
, "S");
664 panel_items_order
= strdup("S");
668 else if (strcmp(key
, "battery") == 0) {
669 if (new_config_file
== 0) {
670 battery_enabled
= atoi(value
);
671 if (battery_enabled
) {
672 if (panel_items_order
)
673 panel_items_order
= strcat(panel_items_order
, "B");
675 panel_items_order
= strdup("B");
680 fprintf(stderr
, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key
);
682 if (value1
) free (value1
);
683 if (value2
) free (value2
);
684 if (value3
) free (value3
);
690 const gchar
* const * system_dirs
;
694 // follow XDG specification
695 // check tint2rc in user directory
696 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
697 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
698 i
= config_read_file (path1
);
699 config_path
= strdup(path1
);
705 // copy tint2rc from system directory to user directory
707 system_dirs
= g_get_system_config_dirs();
708 for (i
= 0; system_dirs
[i
]; i
++) {
709 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
711 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
717 // copy file in user directory (path1)
718 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
719 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
722 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
723 copy_file(path2
, path1
);
726 i
= config_read_file (path1
);
727 config_path
= strdup(path1
);
735 int config_read_file (const char *path
)
741 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
743 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
744 if (parse_line(line
, &key
, &value
)) {
745 add_entry (key
, value
);
752 // append Taskbar item
753 if (new_config_file
== 0) {
755 if (panel_items_order
) {
756 char *tmp
= strdup("T");
757 panel_items_order
= strcat(tmp
, panel_items_order
);
760 panel_items_order
= strdup("T");