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 "systraybar.h"
55 char *config_path
= 0;
56 char *snapshot_path
= 0;
58 // --------------------------------------------------
59 // backward compatibility
60 static int old_task_icon_size
;
62 static int bg_task_active
;
63 // detect if it's an old config file
65 static int old_config_file
;
71 g_array_free(backgrounds
, 1);
72 backgrounds
= g_array_new(0, 0, sizeof(Background
));
74 // append full transparency background
75 Background transparent_bg
;
76 memset(&transparent_bg
, 0, sizeof(Background
));
77 g_array_append_val(backgrounds
, transparent_bg
);
79 // tint2 could reload config, so we cleanup objects
87 // panel's default value
88 if (panel_config
.g_task
.font_desc
) {
89 pango_font_description_free(panel_config
.g_task
.font_desc
);
91 memset(&panel_config
, 0, sizeof(Panel
));
93 for (i
=0; i
<TASK_STATE_COUNT
; ++i
)
94 panel_config
.g_task
.alpha
[i
] = 100;
99 // window manager's menu default value == false
103 // flush pango cache if possible
104 //pango_xft_shutdown_display(server.dsp, server.screen);
105 //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen);
106 //pango_fc_font_map_shutdown(font_map);
110 void cleanup_config()
115 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
119 if (*value1
) free (*value1
);
120 if (*value2
) free (*value2
);
121 if (*value3
) free (*value3
);
123 if ((b
= strchr (value
, ' '))) {
131 *value1
= strdup (value
);
135 if ((c
= strchr (b
, ' '))) {
143 *value2
= strdup (b
);
148 *value3
= strdup (c
);
154 void get_action (char *event
, int *action
)
156 if (strcmp (event
, "none") == 0)
158 else if (strcmp (event
, "close") == 0)
160 else if (strcmp (event
, "toggle") == 0)
162 else if (strcmp (event
, "iconify") == 0)
164 else if (strcmp (event
, "shade") == 0)
166 else if (strcmp (event
, "toggle_iconify") == 0)
167 *action
= TOGGLE_ICONIFY
;
168 else if (strcmp (event
, "maximize_restore") == 0)
169 *action
= MAXIMIZE_RESTORE
;
170 else if (strcmp (event
, "desktop_left") == 0)
171 *action
= DESKTOP_LEFT
;
172 else if (strcmp (event
, "desktop_right") == 0)
173 *action
= DESKTOP_RIGHT
;
174 else if (strcmp (event
, "next_task") == 0)
176 else if (strcmp (event
, "prev_task") == 0)
181 int get_task_status(char* status
)
183 if (strcmp(status
, "active") == 0)
185 if (strcmp(status
, "iconified") == 0)
186 return TASK_ICONIFIED
;
187 if (strcmp(status
, "urgent") == 0)
193 void add_entry (char *key
, char *value
)
195 char *value1
=0, *value2
=0, *value3
=0;
197 /* Background and border */
198 if (strcmp (key
, "rounded") == 0) {
199 // 'rounded' is the first parameter => alloc a new background
201 bg
.border
.rounded
= atoi(value
);
202 g_array_append_val(backgrounds
, bg
);
204 else if (strcmp (key
, "border_width") == 0) {
205 g_array_index(backgrounds
, Background
, backgrounds
->len
-1).border
.width
= atoi(value
);
207 else if (strcmp (key
, "background_color") == 0) {
208 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
209 extract_values(value
, &value1
, &value2
, &value3
);
210 get_color (value1
, bg
->back
.color
);
211 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
212 else bg
->back
.alpha
= 0.5;
214 else if (strcmp (key
, "border_color") == 0) {
215 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
216 extract_values(value
, &value1
, &value2
, &value3
);
217 get_color (value1
, bg
->border
.color
);
218 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
219 else bg
->border
.alpha
= 0.5;
223 else if (strcmp (key
, "panel_monitor") == 0) {
224 if (strcmp (value
, "all") == 0) panel_config
.monitor
= -1;
226 panel_config
.monitor
= atoi (value
);
227 if (panel_config
.monitor
> 0) panel_config
.monitor
-= 1;
230 else if (strcmp (key
, "panel_size") == 0) {
231 extract_values(value
, &value1
, &value2
, &value3
);
234 if ((b
= strchr (value1
, '%'))) {
236 panel_config
.pourcentx
= 1;
238 panel_config
.area
.width
= atoi(value1
);
239 if (panel_config
.area
.width
== 0) {
241 panel_config
.area
.width
= 100;
242 panel_config
.pourcentx
= 1;
245 if ((b
= strchr (value2
, '%'))) {
247 panel_config
.pourcenty
= 1;
249 panel_config
.area
.height
= atoi(value2
);
252 else if (strcmp (key
, "panel_margin") == 0) {
253 extract_values(value
, &value1
, &value2
, &value3
);
254 panel_config
.marginx
= atoi (value1
);
255 if (value2
) panel_config
.marginy
= atoi (value2
);
257 else if (strcmp (key
, "panel_padding") == 0) {
258 extract_values(value
, &value1
, &value2
, &value3
);
259 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
260 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
261 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
263 else if (strcmp (key
, "panel_position") == 0) {
264 extract_values(value
, &value1
, &value2
, &value3
);
265 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
267 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
268 else panel_position
= CENTER
;
271 if (!value2
) panel_position
|= CENTER
;
273 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
275 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
276 else panel_position
|= CENTER
;
279 if (!value3
) panel_horizontal
= 1;
281 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
282 else panel_horizontal
= 1;
285 else if (strcmp (key
, "font_shadow") == 0)
286 panel_config
.g_task
.font_shadow
= atoi (value
);
287 else if (strcmp (key
, "panel_background_id") == 0) {
288 int id
= atoi (value
);
289 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
290 panel_config
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
292 else if (strcmp (key
, "wm_menu") == 0)
293 wm_menu
= atoi (value
);
294 else if (strcmp (key
, "panel_dock") == 0)
295 panel_dock
= atoi (value
);
296 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
297 max_tick_urgent
= (atoi (value
) * 2) + 1;
298 else if (strcmp (key
, "panel_layer") == 0) {
299 if (strcmp(value
, "bottom") == 0)
300 panel_layer
= BOTTOM_LAYER
;
301 else if (strcmp(value
, "normal") == 0)
302 panel_layer
= NORMAL_LAYER
;
303 else if (strcmp(value
, "top") == 0)
304 panel_layer
= TOP_LAYER
;
308 else if (strcmp (key
, "battery") == 0) {
309 #ifdef ENABLE_BATTERY
314 fprintf(stderr
, "tint2 is build without battery support\n");
317 else if (strcmp (key
, "battery_low_status") == 0) {
318 #ifdef ENABLE_BATTERY
319 battery_low_status
= atoi(value
);
320 if(battery_low_status
< 0 || battery_low_status
> 100)
321 battery_low_status
= 0;
324 else if (strcmp (key
, "battery_low_cmd") == 0) {
325 #ifdef ENABLE_BATTERY
326 if (strlen(value
) > 0)
327 battery_low_cmd
= strdup (value
);
330 else if (strcmp (key
, "bat1_font") == 0) {
331 #ifdef ENABLE_BATTERY
332 bat1_font_desc
= pango_font_description_from_string (value
);
335 else if (strcmp (key
, "bat2_font") == 0) {
336 #ifdef ENABLE_BATTERY
337 bat2_font_desc
= pango_font_description_from_string (value
);
340 else if (strcmp (key
, "battery_font_color") == 0) {
341 #ifdef ENABLE_BATTERY
342 extract_values(value
, &value1
, &value2
, &value3
);
343 get_color (value1
, panel_config
.battery
.font
.color
);
344 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
345 else panel_config
.battery
.font
.alpha
= 0.5;
348 else if (strcmp (key
, "battery_padding") == 0) {
349 #ifdef ENABLE_BATTERY
350 extract_values(value
, &value1
, &value2
, &value3
);
351 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
352 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
353 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
356 else if (strcmp (key
, "battery_background_id") == 0) {
357 #ifdef ENABLE_BATTERY
358 int id
= atoi (value
);
359 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
360 panel_config
.battery
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
365 else if (strcmp (key
, "time1_format") == 0) {
366 if (strlen(value
) > 0) {
367 time1_format
= strdup (value
);
371 else if (strcmp (key
, "time2_format") == 0) {
372 if (strlen(value
) > 0)
373 time2_format
= strdup (value
);
375 else if (strcmp (key
, "time1_font") == 0) {
376 time1_font_desc
= pango_font_description_from_string (value
);
378 else if (strcmp(key
, "time1_timezone") == 0) {
379 if (strlen(value
) > 0)
380 time1_timezone
= strdup(value
);
382 else if (strcmp(key
, "time2_timezone") == 0) {
383 if (strlen(value
) > 0)
384 time2_timezone
= strdup(value
);
386 else if (strcmp (key
, "time2_font") == 0) {
387 time2_font_desc
= pango_font_description_from_string (value
);
389 else if (strcmp (key
, "clock_font_color") == 0) {
390 extract_values(value
, &value1
, &value2
, &value3
);
391 get_color (value1
, panel_config
.clock
.font
.color
);
392 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
393 else panel_config
.clock
.font
.alpha
= 0.5;
395 else if (strcmp (key
, "clock_padding") == 0) {
396 extract_values(value
, &value1
, &value2
, &value3
);
397 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
398 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
399 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
401 else if (strcmp (key
, "clock_background_id") == 0) {
402 int id
= atoi (value
);
403 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
404 panel_config
.clock
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
406 else if (strcmp(key
, "clock_tooltip") == 0) {
407 if (strlen(value
) > 0)
408 time_tooltip_format
= strdup (value
);
410 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
411 if (strlen(value
) > 0)
412 time_tooltip_timezone
= strdup(value
);
414 else if (strcmp(key
, "clock_lclick_command") == 0) {
415 if (strlen(value
) > 0)
416 clock_lclick_command
= strdup(value
);
418 else if (strcmp(key
, "clock_rclick_command") == 0) {
419 if (strlen(value
) > 0)
420 clock_rclick_command
= strdup(value
);
424 else if (strcmp (key
, "taskbar_mode") == 0) {
425 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
426 else panel_mode
= SINGLE_DESKTOP
;
428 else if (strcmp (key
, "taskbar_padding") == 0) {
429 extract_values(value
, &value1
, &value2
, &value3
);
430 panel_config
.g_taskbar
.area
.paddingxlr
= panel_config
.g_taskbar
.area
.paddingx
= atoi (value1
);
431 if (value2
) panel_config
.g_taskbar
.area
.paddingy
= atoi (value2
);
432 if (value3
) panel_config
.g_taskbar
.area
.paddingx
= atoi (value3
);
434 else if (strcmp (key
, "taskbar_background_id") == 0) {
435 int id
= atoi (value
);
436 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
437 panel_config
.g_taskbar
.bg
= &g_array_index(backgrounds
, Background
, id
);
438 panel_config
.g_taskbar
.area
.bg
= panel_config
.g_taskbar
.bg
;
440 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
441 int id
= atoi (value
);
442 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
443 panel_config
.g_taskbar
.bg_active
= &g_array_index(backgrounds
, Background
, id
);
444 panel_config
.g_taskbar
.use_active
= 1;
448 else if (strcmp (key
, "task_text") == 0)
449 panel_config
.g_task
.text
= atoi (value
);
450 else if (strcmp (key
, "task_icon") == 0)
451 panel_config
.g_task
.icon
= atoi (value
);
452 else if (strcmp (key
, "task_centered") == 0)
453 panel_config
.g_task
.centered
= atoi (value
);
454 else if (strcmp (key
, "task_width") == 0) {
455 // old parameter : just for backward compatibility
456 panel_config
.g_task
.maximum_width
= atoi (value
);
457 panel_config
.g_task
.maximum_height
= 30;
459 else if (strcmp (key
, "task_maximum_size") == 0) {
460 extract_values(value
, &value1
, &value2
, &value3
);
461 panel_config
.g_task
.maximum_width
= atoi (value1
);
462 panel_config
.g_task
.maximum_height
= 30;
464 panel_config
.g_task
.maximum_height
= atoi (value2
);
466 else if (strcmp (key
, "task_padding") == 0) {
467 extract_values(value
, &value1
, &value2
, &value3
);
468 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
469 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
470 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
472 else if (strcmp (key
, "task_font") == 0) {
473 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
475 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
476 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
477 int status
= get_task_status(split
[1]);
479 extract_values(value
, &value1
, &value2
, &value3
);
481 if (value2
) alpha
= (atoi (value2
) / 100.0);
482 get_color (value1
, panel_config
.g_task
.font
[status
].color
);
483 panel_config
.g_task
.font
[status
].alpha
= alpha
;
484 panel_config
.g_task
.config_font_mask
|= (1<<status
);
486 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
487 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
488 int status
= get_task_status(split
[1]);
490 extract_values(value
, &value1
, &value2
, &value3
);
491 panel_config
.g_task
.alpha
[status
] = atoi(value1
);
492 panel_config
.g_task
.saturation
[status
] = atoi(value2
);
493 panel_config
.g_task
.brightness
[status
] = atoi(value3
);
494 panel_config
.g_task
.config_asb_mask
|= (1<<status
);
496 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
497 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
498 int status
= get_task_status(split
[1]);
500 int id
= atoi (value
);
501 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
502 panel_config
.g_task
.background
[status
] = &g_array_index(backgrounds
, Background
, id
);
503 panel_config
.g_task
.config_background_mask
|= (1<<status
);
504 if (status
== TASK_NORMAL
) panel_config
.g_task
.area
.bg
= panel_config
.g_task
.background
[TASK_NORMAL
];
508 else if (strcmp (key
, "systray") == 0) {
509 systray_enabled
= atoi(value
);
510 // systray is latest option added. files without 'systray' are old.
513 else if (strcmp (key
, "systray_padding") == 0) {
516 extract_values(value
, &value1
, &value2
, &value3
);
517 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
518 if (value2
) systray
.area
.paddingy
= atoi (value2
);
519 if (value3
) systray
.area
.paddingx
= atoi (value3
);
521 else if (strcmp (key
, "systray_background_id") == 0) {
522 int id
= atoi (value
);
523 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
524 systray
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
526 else if (strcmp(key
, "systray_sort") == 0) {
527 if (strcmp(value
, "descending") == 0)
529 else if (strcmp(value
, "ascending") == 0)
531 else if (strcmp(value
, "left2right") == 0)
533 else if (strcmp(value
, "right2left") == 0)
536 else if (strcmp(key
, "systray_icon_size") == 0) {
537 systray_max_icon_size
= atoi(value
);
539 else if (strcmp(key
, "systray_icon_asb") == 0) {
540 extract_values(value
, &value1
, &value2
, &value3
);
541 systray
.alpha
= atoi(value1
);
542 systray
.saturation
= atoi(value2
);
543 systray
.brightness
= atoi(value3
);
547 else if (strcmp (key
, "tooltip") == 0)
548 g_tooltip
.enabled
= atoi(value
);
549 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
550 int timeout_msec
= 1000*atof(value
);
551 g_tooltip
.show_timeout_msec
= timeout_msec
;
553 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
554 int timeout_msec
= 1000*atof(value
);
555 g_tooltip
.hide_timeout_msec
= timeout_msec
;
557 else if (strcmp (key
, "tooltip_padding") == 0) {
558 extract_values(value
, &value1
, &value2
, &value3
);
559 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
560 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
562 else if (strcmp (key
, "tooltip_background_id") == 0) {
563 int id
= atoi (value
);
564 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
565 g_tooltip
.bg
= &g_array_index(backgrounds
, Background
, id
);
567 else if (strcmp (key
, "tooltip_font_color") == 0) {
568 extract_values(value
, &value1
, &value2
, &value3
);
569 get_color(value1
, g_tooltip
.font_color
.color
);
570 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
571 else g_tooltip
.font_color
.alpha
= 0.1;
573 else if (strcmp (key
, "tooltip_font") == 0) {
574 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
578 else if (strcmp (key
, "mouse_middle") == 0)
579 get_action (value
, &mouse_middle
);
580 else if (strcmp (key
, "mouse_right") == 0)
581 get_action (value
, &mouse_right
);
582 else if (strcmp (key
, "mouse_scroll_up") == 0)
583 get_action (value
, &mouse_scroll_up
);
584 else if (strcmp (key
, "mouse_scroll_down") == 0)
585 get_action (value
, &mouse_scroll_down
);
587 /* autohide options */
588 else if (strcmp(key
, "autohide") == 0)
589 panel_autohide
= atoi(value
);
590 else if (strcmp(key
, "autohide_show_timeout") == 0)
591 panel_autohide_show_timeout
= 1000*atof(value
);
592 else if (strcmp(key
, "autohide_hide_timeout") == 0)
593 panel_autohide_hide_timeout
= 1000*atof(value
);
594 else if (strcmp(key
, "strut_policy") == 0) {
595 if (strcmp(value
, "follow_size") == 0)
596 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
598 panel_strut_policy
= STRUT_MINIMUM
;
600 else if (strcmp(key
, "autohide_height") == 0)
601 panel_autohide_height
= atoi(value
);
604 // QUESTION: Do we still need backwards compatibility???
605 /* Read tint-0.6 config for backward compatibility */
606 else if (strcmp (key
, "panel_mode") == 0) {
607 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
608 else panel_mode
= MULTI_DESKTOP
;
610 else if (strcmp (key
, "panel_rounded") == 0) {
612 bg
.border
.rounded
= atoi(value
);
613 g_array_append_val(backgrounds
, bg
);
615 else if (strcmp (key
, "panel_border_width") == 0) {
616 g_array_index(backgrounds
, Background
, backgrounds
->len
-1).border
.width
= atoi(value
);
618 else if (strcmp (key
, "panel_background_color") == 0) {
619 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
620 extract_values(value
, &value1
, &value2
, &value3
);
621 get_color (value1
, bg
->back
.color
);
622 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
623 else bg
->back
.alpha
= 0.5;
625 else if (strcmp (key
, "panel_border_color") == 0) {
626 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
627 extract_values(value
, &value1
, &value2
, &value3
);
628 get_color (value1
, bg
->border
.color
);
629 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
630 else bg
->border
.alpha
= 0.5;
632 else if (strcmp (key
, "task_text_centered") == 0)
633 panel_config
.g_task
.centered
= atoi (value
);
634 else if (strcmp (key
, "task_margin") == 0) {
635 panel_config
.g_taskbar
.area
.paddingxlr
= 0;
636 panel_config
.g_taskbar
.area
.paddingx
= atoi (value
);
638 else if (strcmp (key
, "task_icon_size") == 0)
639 old_task_icon_size
= atoi (value
);
640 else if (strcmp (key
, "task_rounded") == 0) {
642 bg
.border
.rounded
= atoi(value
);
643 g_array_append_val(backgrounds
, bg
);
644 g_array_append_val(backgrounds
, bg
);
645 bg_task
= backgrounds
->len
-2;
646 bg_task_active
= backgrounds
->len
-1;
648 else if (strcmp (key
, "task_background_color") == 0) {
649 Background
* bg
= &g_array_index(backgrounds
, Background
, bg_task
);
650 extract_values(value
, &value1
, &value2
, &value3
);
651 get_color (value1
, bg
->back
.color
);
652 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
653 else bg
->back
.alpha
= 0.5;
655 else if (strcmp (key
, "task_active_background_color") == 0) {
656 Background
* bg
= &g_array_index(backgrounds
, Background
, bg_task_active
);
657 extract_values(value
, &value1
, &value2
, &value3
);
658 get_color (value1
, bg
->back
.color
);
659 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
660 else bg
->back
.alpha
= 0.5;
662 else if (strcmp (key
, "task_border_width") == 0) {
663 Background
* bg
= &g_array_index(backgrounds
, Background
, bg_task
);
664 bg
->border
.width
= atoi (value
);
665 bg
= &g_array_index(backgrounds
, Background
, bg_task_active
);
666 bg
->border
.width
= atoi (value
);
668 else if (strcmp (key
, "task_border_color") == 0) {
669 Background
* bg
= &g_array_index(backgrounds
, Background
, bg_task
);
670 extract_values(value
, &value1
, &value2
, &value3
);
671 get_color (value1
, bg
->border
.color
);
672 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
673 else bg
->border
.alpha
= 0.5;
675 else if (strcmp (key
, "task_active_border_color") == 0) {
676 Background
* bg
= &g_array_index(backgrounds
, Background
, bg_task_active
);
677 extract_values(value
, &value1
, &value2
, &value3
);
678 get_color (value1
, bg
->border
.color
);
679 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
680 else bg
->border
.alpha
= 0.5;
684 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
686 if (value1
) free (value1
);
687 if (value2
) free (value2
);
688 if (value3
) free (value3
);
694 const gchar
* const * system_dirs
;
698 // follow XDG specification
699 // check tint2rc in user directory
700 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
701 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
702 i
= config_read_file (path1
);
703 config_path
= strdup(path1
);
709 // copy tint2rc from system directory to user directory
711 system_dirs
= g_get_system_config_dirs();
712 for (i
= 0; system_dirs
[i
]; i
++) {
713 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
715 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
721 // copy file in user directory (path1)
722 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
723 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
726 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
727 copy_file(path2
, path1
);
730 i
= config_read_file (path1
);
731 config_path
= strdup(path1
);
739 int config_read_file (const char *path
)
745 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
747 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
748 if (parse_line(line
, &key
, &value
)) {
749 add_entry (key
, value
);
756 if (old_task_icon_size
) {
757 panel_config
.g_task
.area
.paddingy
= ((int)panel_config
.area
.height
- (2 * panel_config
.area
.paddingy
) - old_task_icon_size
) / 2;