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 get_action (char *event
, int *action
)
82 if (strcmp (event
, "none") == 0)
84 else if (strcmp (event
, "close") == 0)
86 else if (strcmp (event
, "toggle") == 0)
88 else if (strcmp (event
, "iconify") == 0)
90 else if (strcmp (event
, "shade") == 0)
92 else if (strcmp (event
, "toggle_iconify") == 0)
93 *action
= TOGGLE_ICONIFY
;
94 else if (strcmp (event
, "maximize_restore") == 0)
95 *action
= MAXIMIZE_RESTORE
;
96 else if (strcmp (event
, "desktop_left") == 0)
97 *action
= DESKTOP_LEFT
;
98 else if (strcmp (event
, "desktop_right") == 0)
99 *action
= DESKTOP_RIGHT
;
100 else if (strcmp (event
, "next_task") == 0)
102 else if (strcmp (event
, "prev_task") == 0)
107 int get_task_status(char* status
)
109 if (strcmp(status
, "active") == 0)
111 if (strcmp(status
, "iconified") == 0)
112 return TASK_ICONIFIED
;
113 if (strcmp(status
, "urgent") == 0)
119 int config_get_monitor(char* monitor
)
121 if (strcmp(monitor
, "all") != 0) {
123 int ret_int
= strtol(monitor
, &endptr
, 10);
127 // monitor specified by name, not by index
129 for (i
=0; i
<server
.nb_monitor
; ++i
) {
130 if (server
.monitor
[i
].names
== 0)
131 // xrandr can't identify monitors
134 while (server
.monitor
[i
].names
[j
] != 0) {
135 if (strcmp(monitor
, server
.monitor
[i
].names
[j
++]) == 0)
141 // monitor == "all" or monitor not found or xrandr can't identify monitors
145 void add_entry (char *key
, char *value
)
147 char *value1
=0, *value2
=0, *value3
=0;
149 /* Background and border */
150 if (strcmp (key
, "rounded") == 0) {
151 // 'rounded' is the first parameter => alloc a new background
153 bg
.border
.rounded
= atoi(value
);
154 g_array_append_val(backgrounds
, bg
);
156 else if (strcmp (key
, "border_width") == 0) {
157 g_array_index(backgrounds
, Background
, backgrounds
->len
-1).border
.width
= atoi(value
);
159 else if (strcmp (key
, "background_color") == 0) {
160 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
161 extract_values(value
, &value1
, &value2
, &value3
);
162 get_color (value1
, bg
->back
.color
);
163 if (value2
) bg
->back
.alpha
= (atoi (value2
) / 100.0);
164 else bg
->back
.alpha
= 0.5;
166 else if (strcmp (key
, "border_color") == 0) {
167 Background
* bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
168 extract_values(value
, &value1
, &value2
, &value3
);
169 get_color (value1
, bg
->border
.color
);
170 if (value2
) bg
->border
.alpha
= (atoi (value2
) / 100.0);
171 else bg
->border
.alpha
= 0.5;
175 else if (strcmp (key
, "panel_monitor") == 0) {
176 panel_config
.monitor
= config_get_monitor(value
);
178 else if (strcmp (key
, "panel_size") == 0) {
179 extract_values(value
, &value1
, &value2
, &value3
);
182 if ((b
= strchr (value1
, '%'))) {
184 panel_config
.pourcentx
= 1;
186 panel_config
.area
.width
= atoi(value1
);
187 if (panel_config
.area
.width
== 0) {
189 panel_config
.area
.width
= 100;
190 panel_config
.pourcentx
= 1;
193 if ((b
= strchr (value2
, '%'))) {
195 panel_config
.pourcenty
= 1;
197 panel_config
.area
.height
= atoi(value2
);
200 else if (strcmp (key
, "panel_items") == 0) {
202 panel_items_order
= strdup(value
);
204 for (j
=0 ; j
< strlen(panel_items_order
) ; j
++) {
205 if (panel_items_order
[j
] == 'L')
206 launcher_enabled
= 1;
207 if (panel_items_order
[j
] == 'T')
209 if (panel_items_order
[j
] == 'B') {
210 #ifdef ENABLE_BATTERY
213 fprintf(stderr
, "tint2 is build without battery support\n");
216 if (panel_items_order
[j
] == 'S') {
217 // systray disabled in snapshot mode
218 if (snapshot_path
== 0)
221 if (panel_items_order
[j
] == 'C')
225 else if (strcmp (key
, "panel_margin") == 0) {
226 extract_values(value
, &value1
, &value2
, &value3
);
227 panel_config
.marginx
= atoi (value1
);
228 if (value2
) panel_config
.marginy
= atoi (value2
);
230 else if (strcmp (key
, "panel_padding") == 0) {
231 extract_values(value
, &value1
, &value2
, &value3
);
232 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
233 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
234 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
236 else if (strcmp (key
, "panel_position") == 0) {
237 extract_values(value
, &value1
, &value2
, &value3
);
238 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
240 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
241 else panel_position
= CENTER
;
244 if (!value2
) panel_position
|= CENTER
;
246 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
248 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
249 else panel_position
|= CENTER
;
252 if (!value3
) panel_horizontal
= 1;
254 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
255 else panel_horizontal
= 1;
258 else if (strcmp (key
, "font_shadow") == 0)
259 panel_config
.g_task
.font_shadow
= atoi (value
);
260 else if (strcmp (key
, "panel_background_id") == 0) {
261 int id
= atoi (value
);
262 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
263 panel_config
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
265 else if (strcmp (key
, "wm_menu") == 0)
266 wm_menu
= atoi (value
);
267 else if (strcmp (key
, "panel_dock") == 0)
268 panel_dock
= atoi (value
);
269 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
270 max_tick_urgent
= atoi (value
);
271 else if (strcmp (key
, "panel_layer") == 0) {
272 if (strcmp(value
, "bottom") == 0)
273 panel_layer
= BOTTOM_LAYER
;
274 else if (strcmp(value
, "top") == 0)
275 panel_layer
= TOP_LAYER
;
277 panel_layer
= NORMAL_LAYER
;
281 else if (strcmp (key
, "battery_low_status") == 0) {
282 #ifdef ENABLE_BATTERY
283 battery_low_status
= atoi(value
);
284 if(battery_low_status
< 0 || battery_low_status
> 100)
285 battery_low_status
= 0;
288 else if (strcmp (key
, "battery_low_cmd") == 0) {
289 #ifdef ENABLE_BATTERY
290 if (strlen(value
) > 0)
291 battery_low_cmd
= strdup (value
);
294 else if (strcmp (key
, "bat1_font") == 0) {
295 #ifdef ENABLE_BATTERY
296 bat1_font_desc
= pango_font_description_from_string (value
);
299 else if (strcmp (key
, "bat2_font") == 0) {
300 #ifdef ENABLE_BATTERY
301 bat2_font_desc
= pango_font_description_from_string (value
);
304 else if (strcmp (key
, "battery_font_color") == 0) {
305 #ifdef ENABLE_BATTERY
306 extract_values(value
, &value1
, &value2
, &value3
);
307 get_color (value1
, panel_config
.battery
.font
.color
);
308 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
309 else panel_config
.battery
.font
.alpha
= 0.5;
312 else if (strcmp (key
, "battery_padding") == 0) {
313 #ifdef ENABLE_BATTERY
314 extract_values(value
, &value1
, &value2
, &value3
);
315 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
316 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
317 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
320 else if (strcmp (key
, "battery_background_id") == 0) {
321 #ifdef ENABLE_BATTERY
322 int id
= atoi (value
);
323 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
324 panel_config
.battery
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
327 else if (strcmp (key
, "battery_hide") == 0) {
328 #ifdef ENABLE_BATTERY
329 percentage_hide
= atoi (value
);
330 if (percentage_hide
== 0)
331 percentage_hide
= 101;
336 else if (strcmp (key
, "time1_format") == 0) {
337 if (new_config_file
== 0) {
339 if (panel_items_order
) {
340 char* tmp
= g_strconcat(panel_items_order
, "C", NULL
);
341 g_free( panel_items_order
);
342 panel_items_order
= tmp
;
345 panel_items_order
= g_strdup("C");
347 if (strlen(value
) > 0) {
348 time1_format
= strdup (value
);
352 else if (strcmp (key
, "time2_format") == 0) {
353 if (strlen(value
) > 0)
354 time2_format
= strdup (value
);
356 else if (strcmp (key
, "time1_font") == 0) {
357 time1_font_desc
= pango_font_description_from_string (value
);
359 else if (strcmp(key
, "time1_timezone") == 0) {
360 if (strlen(value
) > 0)
361 time1_timezone
= strdup(value
);
363 else if (strcmp(key
, "time2_timezone") == 0) {
364 if (strlen(value
) > 0)
365 time2_timezone
= strdup(value
);
367 else if (strcmp (key
, "time2_font") == 0) {
368 time2_font_desc
= pango_font_description_from_string (value
);
370 else if (strcmp (key
, "clock_font_color") == 0) {
371 extract_values(value
, &value1
, &value2
, &value3
);
372 get_color (value1
, panel_config
.clock
.font
.color
);
373 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
374 else panel_config
.clock
.font
.alpha
= 0.5;
376 else if (strcmp (key
, "clock_padding") == 0) {
377 extract_values(value
, &value1
, &value2
, &value3
);
378 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
379 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
380 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
382 else if (strcmp (key
, "clock_background_id") == 0) {
383 int id
= atoi (value
);
384 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
385 panel_config
.clock
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
387 else if (strcmp(key
, "clock_tooltip") == 0) {
388 if (strlen(value
) > 0)
389 time_tooltip_format
= strdup (value
);
391 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
392 if (strlen(value
) > 0)
393 time_tooltip_timezone
= strdup(value
);
395 else if (strcmp(key
, "clock_lclick_command") == 0) {
396 if (strlen(value
) > 0)
397 clock_lclick_command
= strdup(value
);
399 else if (strcmp(key
, "clock_rclick_command") == 0) {
400 if (strlen(value
) > 0)
401 clock_rclick_command
= strdup(value
);
405 else if (strcmp (key
, "taskbar_mode") == 0) {
406 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
407 else panel_mode
= SINGLE_DESKTOP
;
409 else if (strcmp (key
, "taskbar_padding") == 0) {
410 extract_values(value
, &value1
, &value2
, &value3
);
411 panel_config
.g_taskbar
.area
.paddingxlr
= panel_config
.g_taskbar
.area
.paddingx
= atoi (value1
);
412 if (value2
) panel_config
.g_taskbar
.area
.paddingy
= atoi (value2
);
413 if (value3
) panel_config
.g_taskbar
.area
.paddingx
= atoi (value3
);
415 else if (strcmp (key
, "taskbar_background_id") == 0) {
416 int id
= atoi (value
);
417 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
418 panel_config
.g_taskbar
.background
[TASKBAR_NORMAL
] = &g_array_index(backgrounds
, Background
, id
);
419 if (panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] == 0)
420 panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] = panel_config
.g_taskbar
.background
[TASKBAR_NORMAL
];
422 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
423 int id
= atoi (value
);
424 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
425 panel_config
.g_taskbar
.background
[TASKBAR_ACTIVE
] = &g_array_index(backgrounds
, Background
, id
);
427 else if (strcmp (key
, "taskbar_name") == 0) {
428 taskbarname_enabled
= atoi (value
);
430 else if (strcmp (key
, "taskbar_name_padding") == 0) {
431 extract_values(value
, &value1
, &value2
, &value3
);
432 panel_config
.g_taskbar
.area_name
.paddingxlr
= panel_config
.g_taskbar
.area_name
.paddingx
= atoi (value1
);
434 else if (strcmp (key
, "taskbar_name_background_id") == 0) {
435 int id
= atoi (value
);
436 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
437 panel_config
.g_taskbar
.background_name
[TASKBAR_NORMAL
] = &g_array_index(backgrounds
, Background
, id
);
438 if (panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] == 0)
439 panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] = panel_config
.g_taskbar
.background_name
[TASKBAR_NORMAL
];
441 else if (strcmp (key
, "taskbar_name_active_background_id") == 0) {
442 int id
= atoi (value
);
443 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
444 panel_config
.g_taskbar
.background_name
[TASKBAR_ACTIVE
] = &g_array_index(backgrounds
, Background
, id
);
446 else if (strcmp (key
, "taskbar_name_font") == 0) {
447 taskbarname_font_desc
= pango_font_description_from_string (value
);
449 else if (strcmp (key
, "taskbar_name_font_color") == 0) {
450 extract_values(value
, &value1
, &value2
, &value3
);
451 get_color (value1
, taskbarname_font
.color
);
452 if (value2
) taskbarname_font
.alpha
= (atoi (value2
) / 100.0);
453 else taskbarname_font
.alpha
= 0.5;
455 else if (strcmp (key
, "taskbar_name_active_font_color") == 0) {
456 extract_values(value
, &value1
, &value2
, &value3
);
457 get_color (value1
, taskbarname_active_font
.color
);
458 if (value2
) taskbarname_active_font
.alpha
= (atoi (value2
) / 100.0);
459 else taskbarname_active_font
.alpha
= 0.5;
463 else if (strcmp (key
, "task_text") == 0)
464 panel_config
.g_task
.text
= atoi (value
);
465 else if (strcmp (key
, "task_icon") == 0)
466 panel_config
.g_task
.icon
= atoi (value
);
467 else if (strcmp (key
, "task_centered") == 0)
468 panel_config
.g_task
.centered
= atoi (value
);
469 else if (strcmp (key
, "task_width") == 0) {
470 // old parameter : just for backward compatibility
471 panel_config
.g_task
.maximum_width
= atoi (value
);
472 panel_config
.g_task
.maximum_height
= 30;
474 else if (strcmp (key
, "task_maximum_size") == 0) {
475 extract_values(value
, &value1
, &value2
, &value3
);
476 panel_config
.g_task
.maximum_width
= atoi (value1
);
477 panel_config
.g_task
.maximum_height
= 30;
479 panel_config
.g_task
.maximum_height
= atoi (value2
);
481 else if (strcmp (key
, "task_padding") == 0) {
482 extract_values(value
, &value1
, &value2
, &value3
);
483 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
484 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
485 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
487 else if (strcmp (key
, "task_font") == 0) {
488 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
490 else if (g_regex_match_simple("task.*_font_color", key
, 0, 0)) {
491 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
492 int status
= get_task_status(split
[1]);
494 extract_values(value
, &value1
, &value2
, &value3
);
496 if (value2
) alpha
= (atoi (value2
) / 100.0);
497 get_color (value1
, panel_config
.g_task
.font
[status
].color
);
498 panel_config
.g_task
.font
[status
].alpha
= alpha
;
499 panel_config
.g_task
.config_font_mask
|= (1<<status
);
501 else if (g_regex_match_simple("task.*_icon_asb", key
, 0, 0)) {
502 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
503 int status
= get_task_status(split
[1]);
505 extract_values(value
, &value1
, &value2
, &value3
);
506 panel_config
.g_task
.alpha
[status
] = atoi(value1
);
507 panel_config
.g_task
.saturation
[status
] = atoi(value2
);
508 panel_config
.g_task
.brightness
[status
] = atoi(value3
);
509 panel_config
.g_task
.config_asb_mask
|= (1<<status
);
511 else if (g_regex_match_simple("task.*_background_id", key
, 0, 0)) {
512 gchar
** split
= g_regex_split_simple("_", key
, 0, 0);
513 int status
= get_task_status(split
[1]);
515 int id
= atoi (value
);
516 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
517 panel_config
.g_task
.background
[status
] = &g_array_index(backgrounds
, Background
, id
);
518 panel_config
.g_task
.config_background_mask
|= (1<<status
);
519 if (status
== TASK_NORMAL
) panel_config
.g_task
.area
.bg
= panel_config
.g_task
.background
[TASK_NORMAL
];
521 // "tooltip" is deprecated but here for backwards compatibility
522 else if (strcmp (key
, "task_tooltip") == 0 || strcmp(key
, "tooltip") == 0)
523 panel_config
.g_task
.tooltip_enabled
= atoi(value
);
526 else if (strcmp (key
, "systray_padding") == 0) {
527 if (new_config_file
== 0 && systray_enabled
== 0) {
529 if (panel_items_order
) {
530 char* tmp
= g_strconcat(panel_items_order
, "S", NULL
);
531 g_free( panel_items_order
);
532 panel_items_order
= tmp
;
535 panel_items_order
= g_strdup("S");
537 extract_values(value
, &value1
, &value2
, &value3
);
538 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
539 if (value2
) systray
.area
.paddingy
= atoi (value2
);
540 if (value3
) systray
.area
.paddingx
= atoi (value3
);
542 else if (strcmp (key
, "systray_background_id") == 0) {
543 int id
= atoi (value
);
544 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
545 systray
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
547 else if (strcmp(key
, "systray_sort") == 0) {
548 if (strcmp(value
, "descending") == 0)
550 else if (strcmp(value
, "ascending") == 0)
552 else if (strcmp(value
, "left2right") == 0)
554 else if (strcmp(value
, "right2left") == 0)
557 else if (strcmp(key
, "systray_icon_size") == 0) {
558 systray_max_icon_size
= atoi(value
);
560 else if (strcmp(key
, "systray_icon_asb") == 0) {
561 extract_values(value
, &value1
, &value2
, &value3
);
562 systray
.alpha
= atoi(value1
);
563 systray
.saturation
= atoi(value2
);
564 systray
.brightness
= atoi(value3
);
568 else if (strcmp (key
, "launcher_padding") == 0) {
569 extract_values(value
, &value1
, &value2
, &value3
);
570 panel_config
.launcher
.area
.paddingxlr
= panel_config
.launcher
.area
.paddingx
= atoi (value1
);
571 if (value2
) panel_config
.launcher
.area
.paddingy
= atoi (value2
);
572 if (value3
) panel_config
.launcher
.area
.paddingx
= atoi (value3
);
574 else if (strcmp (key
, "launcher_background_id") == 0) {
575 int id
= atoi (value
);
576 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
577 panel_config
.launcher
.area
.bg
= &g_array_index(backgrounds
, Background
, id
);
579 else if (strcmp(key
, "launcher_icon_size") == 0) {
580 launcher_max_icon_size
= atoi(value
);
582 else if (strcmp(key
, "launcher_item_app") == 0) {
583 char *app
= strdup(value
);
584 panel_config
.launcher
.list_apps
= g_slist_append(panel_config
.launcher
.list_apps
, app
);
586 else if (strcmp(key
, "launcher_icon_theme") == 0) {
587 // if XSETTINGS manager running, tint2 use it.
588 if (!icon_theme_name
)
589 icon_theme_name
= strdup(value
);
591 else if (strcmp(key
, "launcher_icon_asb") == 0) {
592 extract_values(value
, &value1
, &value2
, &value3
);
593 launcher_alpha
= atoi(value1
);
594 launcher_saturation
= atoi(value2
);
595 launcher_brightness
= atoi(value3
);
597 else if (strcmp(key
, "launcher_tooltip") == 0) {
598 launcher_tooltip_enabled
= atoi(value
);
602 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
603 int timeout_msec
= 1000*atof(value
);
604 g_tooltip
.show_timeout_msec
= timeout_msec
;
606 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
607 int timeout_msec
= 1000*atof(value
);
608 g_tooltip
.hide_timeout_msec
= timeout_msec
;
610 else if (strcmp (key
, "tooltip_padding") == 0) {
611 extract_values(value
, &value1
, &value2
, &value3
);
612 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
613 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
615 else if (strcmp (key
, "tooltip_background_id") == 0) {
616 int id
= atoi (value
);
617 id
= (id
< backgrounds
->len
&& id
>= 0) ? id
: 0;
618 g_tooltip
.bg
= &g_array_index(backgrounds
, Background
, id
);
620 else if (strcmp (key
, "tooltip_font_color") == 0) {
621 extract_values(value
, &value1
, &value2
, &value3
);
622 get_color(value1
, g_tooltip
.font_color
.color
);
623 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
624 else g_tooltip
.font_color
.alpha
= 0.1;
626 else if (strcmp (key
, "tooltip_font") == 0) {
627 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
631 else if (strcmp (key
, "mouse_middle") == 0)
632 get_action (value
, &mouse_middle
);
633 else if (strcmp (key
, "mouse_right") == 0)
634 get_action (value
, &mouse_right
);
635 else if (strcmp (key
, "mouse_scroll_up") == 0)
636 get_action (value
, &mouse_scroll_up
);
637 else if (strcmp (key
, "mouse_scroll_down") == 0)
638 get_action (value
, &mouse_scroll_down
);
640 /* autohide options */
641 else if (strcmp(key
, "autohide") == 0)
642 panel_autohide
= atoi(value
);
643 else if (strcmp(key
, "autohide_show_timeout") == 0)
644 panel_autohide_show_timeout
= 1000*atof(value
);
645 else if (strcmp(key
, "autohide_hide_timeout") == 0)
646 panel_autohide_hide_timeout
= 1000*atof(value
);
647 else if (strcmp(key
, "strut_policy") == 0) {
648 if (strcmp(value
, "follow_size") == 0)
649 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
650 else if (strcmp(value
, "none") == 0)
651 panel_strut_policy
= STRUT_NONE
;
653 panel_strut_policy
= STRUT_MINIMUM
;
655 else if (strcmp(key
, "autohide_height") == 0) {
656 panel_autohide_height
= atoi(value
);
657 if (panel_autohide_height
== 0) {
658 // autohide need height > 0
659 panel_autohide_height
= 1;
664 else if (strcmp(key
, "systray") == 0) {
665 if (new_config_file
== 0) {
666 systray_enabled
= atoi(value
);
667 if (systray_enabled
) {
668 if (panel_items_order
) {
669 char* tmp
= g_strconcat(panel_items_order
, "S", NULL
);
670 g_free( panel_items_order
);
671 panel_items_order
= tmp
;
674 panel_items_order
= g_strdup("S");
678 else if (strcmp(key
, "battery") == 0) {
679 if (new_config_file
== 0) {
680 battery_enabled
= atoi(value
);
681 if (battery_enabled
) {
682 if (panel_items_order
) {
683 char* tmp
= g_strconcat(panel_items_order
, "B", NULL
);
684 g_free( panel_items_order
);
685 panel_items_order
= tmp
;
688 panel_items_order
= g_strdup("B");
693 fprintf(stderr
, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key
);
695 if (value1
) free (value1
);
696 if (value2
) free (value2
);
697 if (value3
) free (value3
);
703 const gchar
* const * system_dirs
;
707 // follow XDG specification
708 // check tint2rc in user directory
709 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
710 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
711 i
= config_read_file (path1
);
712 config_path
= strdup(path1
);
718 // copy tint2rc from system directory to user directory
720 system_dirs
= g_get_system_config_dirs();
721 for (i
= 0; system_dirs
[i
]; i
++) {
722 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
724 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
730 // copy file in user directory (path1)
731 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
732 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
735 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
736 copy_file(path2
, path1
);
739 i
= config_read_file (path1
);
740 config_path
= strdup(path1
);
748 int config_read_file (const char *path
)
754 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
756 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
757 if (parse_line(line
, &key
, &value
)) {
758 add_entry (key
, value
);
765 // append Taskbar item
766 if (new_config_file
== 0) {
768 if (panel_items_order
) {
769 char* tmp
= g_strconcat( "T", panel_items_order
, NULL
);
770 g_free(panel_items_order
);
771 panel_items_order
= tmp
;
774 panel_items_order
= g_strdup("T");