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_padding") == 0) {
470 extract_values(value
, &value1
, &value2
, &value3
);
471 panel_config
.g_taskbar
.area_name
.paddingxlr
= panel_config
.g_taskbar
.area_name
.paddingx
= atoi (value1
);
473 else if (strcmp (key
, "taskbar_name_background_id") == 0) {
474 int id
= atoi (value
);
475 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
476 panel_config
.g_taskbar
.background_name
[TASKBAR_NORMAL
] = &g_array_index(backgrounds
, Background
, id
);
477 if (panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] == 0)
478 panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] = panel_config
.g_taskbar
.background_name
[TASKBAR_NORMAL
];
480 else if (strcmp (key
, "taskbar_name_active_background_id") == 0) {
481 int id
= atoi (value
);
482 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
483 panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] = &g_array_index(backgrounds
, Background
, id
);
485 else if (strcmp (key
, "taskbar_name_font") == 0) {
486 taskbarname_font_desc
= pango_font_description_from_string (value
);
488 else if (strcmp (key
, "taskbar_name_font_color") == 0) {
489 extract_values(value
, &value1
, &value2
, &value3
);
490 get_color (value1
, taskbarname_font
.color
);
491 if (value2
) taskbarname_font
.alpha
= (atoi (value2
) / 100.0);
492 else taskbarname_font
.alpha
= 0.5;
494 else if (strcmp (key
, "taskbar_name_active_font_color") == 0) {
495 extract_values(value
, &value1
, &value2
, &value3
);
496 get_color (value1
, taskbarname_active_font
.color
);
497 if (value2
) taskbarname_active_font
.alpha
= (atoi (value2
) / 100.0);
498 else taskbarname_active_font
.alpha
= 0.5;
502 else if (strcmp (key
, "task_text") == 0)
503 panel_config
.g_task
.text
= atoi (value
);
504 else if (strcmp (key
, "task_icon") == 0)
505 panel_config
.g_task
.icon
= atoi (value
);
506 else if (strcmp (key
, "task_centered") == 0)
507 panel_config
.g_task
.centered
= atoi (value
);
508 else if (strcmp (key
, "task_width") == 0) {
509 // old parameter : just for backward compatibility
510 panel_config
.g_task
.maximum_width
= atoi (value
);
511 panel_config
.g_task
.maximum_height
= 30;
513 else if (strcmp (key
, "task_maximum_size") == 0) {
514 extract_values(value
, &value1
, &value2
, &value3
);
515 panel_config
.g_task
.maximum_width
= atoi (value1
);
516 panel_config
.g_task
.maximum_height
= 30;
518 panel_config
.g_task
.maximum_height
= atoi (value2
);
520 else if (strcmp (key
, "task_padding") == 0) {
521 extract_values(value
, &value1
, &value2
, &value3
);
522 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
523 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
524 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
526 else if (strcmp (key
, "task_font") == 0) {
527 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
529 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
530 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
531 int status
= get_task_status(split
[1]);
533 extract_values(value
, &value1
, &value2
, &value3
);
535 if (value2
) alpha
= (atoi (value2
) / 100.0);
536 get_color (value1
, panel_config
.g_task
.font
[status
].color
);
537 panel_config
.g_task
.font
[status
].alpha
= alpha
;
538 panel_config
.g_task
.config_font_mask
|= (1<<status
);
540 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
541 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
542 int status
= get_task_status(split
[1]);
544 extract_values(value
, &value1
, &value2
, &value3
);
545 panel_config
.g_task
.alpha
[status
] = atoi(value1
);
546 panel_config
.g_task
.saturation
[status
] = atoi(value2
);
547 panel_config
.g_task
.brightness
[status
] = atoi(value3
);
548 panel_config
.g_task
.config_asb_mask
|= (1<<status
);
550 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
551 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
552 int status
= get_task_status(split
[1]);
554 int id
= atoi (value
);
555 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
556 panel_config
.g_task
.background
[status
] = &g_array_index(backgrounds
, Background
, id
);
557 panel_config
.g_task
.config_background_mask
|= (1<<status
);
558 if (status
== TASK_NORMAL
) panel_config
.g_task
.area
.bg
= panel_config
.g_task
.background
[TASK_NORMAL
];
560 // "tooltip" is deprecated but here for backwards compatibility
561 else if (strcmp (key
, "task_tooltip") == 0 || strcmp(key
, "tooltip") == 0)
562 panel_config
.g_task
.tooltip_enabled
= atoi(value
);
565 else if (strcmp (key
, "systray_padding") == 0) {
566 if (new_config_file
== 0 && systray_enabled
== 0) {
568 if (panel_items_order
) {
569 char* tmp
= g_strconcat(panel_items_order
, "S", NULL
);
570 g_free( panel_items_order
);
571 panel_items_order
= tmp
;
574 panel_items_order
= g_strdup("S");
576 extract_values(value
, &value1
, &value2
, &value3
);
577 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
578 if (value2
) systray
.area
.paddingy
= atoi (value2
);
579 if (value3
) systray
.area
.paddingx
= atoi (value3
);
581 else if (strcmp (key
, "systray_background_id") == 0) {
582 int id
= atoi (value
);
583 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
584 systray
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
586 else if (strcmp(key
, "systray_sort") == 0) {
587 if (strcmp(value
, "descending") == 0)
589 else if (strcmp(value
, "ascending") == 0)
591 else if (strcmp(value
, "left2right") == 0)
593 else if (strcmp(value
, "right2left") == 0)
596 else if (strcmp(key
, "systray_icon_size") == 0) {
597 systray_max_icon_size
= atoi(value
);
599 else if (strcmp(key
, "systray_icon_asb") == 0) {
600 extract_values(value
, &value1
, &value2
, &value3
);
601 systray
.alpha
= atoi(value1
);
602 systray
.saturation
= atoi(value2
);
603 systray
.brightness
= atoi(value3
);
607 else if (strcmp (key
, "launcher_padding") == 0) {
608 extract_values(value
, &value1
, &value2
, &value3
);
609 panel_config
.launcher
.area
.paddingxlr
= panel_config
.launcher
.area
.paddingx
= atoi (value1
);
610 if (value2
) panel_config
.launcher
.area
.paddingy
= atoi (value2
);
611 if (value3
) panel_config
.launcher
.area
.paddingx
= atoi (value3
);
613 else if (strcmp (key
, "launcher_background_id") == 0) {
614 int id
= atoi (value
);
615 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
616 panel_config
.launcher
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
618 else if (strcmp(key
, "launcher_icon_size") == 0) {
619 launcher_max_icon_size
= atoi(value
);
621 else if (strcmp(key
, "launcher_item_app") == 0) {
622 char *app
= strdup(value
);
623 panel_config
.launcher
.list_apps
= g_slist_append(panel_config
.launcher
.list_apps
, app
);
625 else if (strcmp(key
, "launcher_icon_theme") == 0) {
626 // if XSETTINGS manager running, tint2 use it.
627 if (!icon_theme_name
)
628 icon_theme_name
= strdup(value
);
632 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
633 int timeout_msec
= 1000*atof(value
);
634 g_tooltip
.show_timeout_msec
= timeout_msec
;
636 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
637 int timeout_msec
= 1000*atof(value
);
638 g_tooltip
.hide_timeout_msec
= timeout_msec
;
640 else if (strcmp (key
, "tooltip_padding") == 0) {
641 extract_values(value
, &value1
, &value2
, &value3
);
642 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
643 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
645 else if (strcmp (key
, "tooltip_background_id") == 0) {
646 int id
= atoi (value
);
647 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
648 g_tooltip
.bg
= &g_array_index(backgrounds
, Background
, id
);
650 else if (strcmp (key
, "tooltip_font_color") == 0) {
651 extract_values(value
, &value1
, &value2
, &value3
);
652 get_color(value1
, g_tooltip
.font_color
.color
);
653 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
654 else g_tooltip
.font_color
.alpha
= 0.1;
656 else if (strcmp (key
, "tooltip_font") == 0) {
657 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
661 else if (strcmp (key
, "mouse_middle") == 0)
662 get_action (value
, &mouse_middle
);
663 else if (strcmp (key
, "mouse_right") == 0)
664 get_action (value
, &mouse_right
);
665 else if (strcmp (key
, "mouse_scroll_up") == 0)
666 get_action (value
, &mouse_scroll_up
);
667 else if (strcmp (key
, "mouse_scroll_down") == 0)
668 get_action (value
, &mouse_scroll_down
);
670 /* autohide options */
671 else if (strcmp(key
, "autohide") == 0)
672 panel_autohide
= atoi(value
);
673 else if (strcmp(key
, "autohide_show_timeout") == 0)
674 panel_autohide_show_timeout
= 1000*atof(value
);
675 else if (strcmp(key
, "autohide_hide_timeout") == 0)
676 panel_autohide_hide_timeout
= 1000*atof(value
);
677 else if (strcmp(key
, "strut_policy") == 0) {
678 if (strcmp(value
, "follow_size") == 0)
679 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
680 else if (strcmp(value
, "none") == 0)
681 panel_strut_policy
= STRUT_NONE
;
683 panel_strut_policy
= STRUT_MINIMUM
;
685 else if (strcmp(key
, "autohide_height") == 0) {
686 panel_autohide_height
= atoi(value
);
687 if (panel_autohide_height
== 0) {
688 // autohide need height > 0
689 panel_autohide_height
= 1;
694 else if (strcmp(key
, "systray") == 0) {
695 if (new_config_file
== 0) {
696 systray_enabled
= atoi(value
);
697 if (systray_enabled
) {
698 if (panel_items_order
) {
699 char* tmp
= g_strconcat(panel_items_order
, "S", NULL
);
700 g_free( panel_items_order
);
701 panel_items_order
= tmp
;
704 panel_items_order
= g_strdup("S");
708 else if (strcmp(key
, "battery") == 0) {
709 if (new_config_file
== 0) {
710 battery_enabled
= atoi(value
);
711 if (battery_enabled
) {
712 if (panel_items_order
) {
713 char* tmp
= g_strconcat(panel_items_order
, "B", NULL
);
714 g_free( panel_items_order
);
715 panel_items_order
= tmp
;
718 panel_items_order
= g_strdup("B");
723 fprintf(stderr
, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key
);
725 if (value1
) free (value1
);
726 if (value2
) free (value2
);
727 if (value3
) free (value3
);
733 const gchar
* const * system_dirs
;
737 // follow XDG specification
738 // check tint2rc in user directory
739 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
740 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
741 i
= config_read_file (path1
);
742 config_path
= strdup(path1
);
748 // copy tint2rc from system directory to user directory
750 system_dirs
= g_get_system_config_dirs();
751 for (i
= 0; system_dirs
[i
]; i
++) {
752 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
754 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
760 // copy file in user directory (path1)
761 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
762 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
765 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
766 copy_file(path2
, path1
);
769 i
= config_read_file (path1
);
770 config_path
= strdup(path1
);
778 int config_read_file (const char *path
)
784 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
786 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
787 if (parse_line(line
, &key
, &value
)) {
788 add_entry (key
, value
);
795 // append Taskbar item
796 if (new_config_file
== 0) {
798 if (panel_items_order
) {
799 char* tmp
= g_strconcat( "T", panel_items_order
, NULL
);
800 g_free(panel_items_order
);
801 panel_items_order
= tmp
;
804 panel_items_order
= g_strdup("T");