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
;
61 static Area
*area_task
;
62 static Area
*area_task_active
;
63 // detect if it's an old config file
65 static int old_config_file
;
67 // temporary list of background
68 static GSList
*list_back
;
69 static int back_count
;
75 // append full transparency background
76 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
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
));
92 panel_config
.g_task
.alpha
= 100;
93 panel_config
.g_task
.alpha_active
= 100;
98 // window manager's menu default value == false
102 // flush pango cache if possible
103 //pango_xft_shutdown_display(server.dsp, server.screen);
104 //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen);
105 //pango_fc_font_map_shutdown(font_map);
109 void cleanup_config()
111 // cleanup background list
113 for (l0
= list_back
; l0
; l0
= l0
->next
) {
116 g_slist_free(list_back
);
121 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
125 if (*value1
) free (*value1
);
126 if (*value2
) free (*value2
);
127 if (*value3
) free (*value3
);
129 if ((b
= strchr (value
, ' '))) {
137 *value1
= strdup (value
);
141 if ((c
= strchr (b
, ' '))) {
149 *value2
= strdup (b
);
154 *value3
= strdup (c
);
160 void get_action (char *event
, int *action
)
162 if (strcmp (event
, "none") == 0)
164 else if (strcmp (event
, "close") == 0)
166 else if (strcmp (event
, "toggle") == 0)
168 else if (strcmp (event
, "iconify") == 0)
170 else if (strcmp (event
, "shade") == 0)
172 else if (strcmp (event
, "toggle_iconify") == 0)
173 *action
= TOGGLE_ICONIFY
;
174 else if (strcmp (event
, "maximize_restore") == 0)
175 *action
= MAXIMIZE_RESTORE
;
176 else if (strcmp (event
, "desktop_left") == 0)
177 *action
= DESKTOP_LEFT
;
178 else if (strcmp (event
, "desktop_right") == 0)
179 *action
= DESKTOP_RIGHT
;
180 else if (strcmp (event
, "next_task") == 0)
182 else if (strcmp (event
, "prev_task") == 0)
187 void add_entry (char *key
, char *value
)
189 char *value1
=0, *value2
=0, *value3
=0;
191 /* Background and border */
192 if (strcmp (key
, "rounded") == 0) {
193 // 'rounded' is the first parameter => alloc a new background
194 Area
*a
= calloc(1, sizeof(Area
));
195 a
->pix
.border
.rounded
= atoi (value
);
196 list_back
= g_slist_append(list_back
, a
);
199 else if (strcmp (key
, "border_width") == 0) {
200 Area
*a
= g_slist_last(list_back
)->data
;
201 a
->pix
.border
.width
= atoi (value
);
203 else if (strcmp (key
, "background_color") == 0) {
204 Area
*a
= g_slist_last(list_back
)->data
;
205 extract_values(value
, &value1
, &value2
, &value3
);
206 get_color (value1
, a
->pix
.back
.color
);
207 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
208 else a
->pix
.back
.alpha
= 0.5;
210 else if (strcmp (key
, "border_color") == 0) {
211 Area
*a
= g_slist_last(list_back
)->data
;
212 extract_values(value
, &value1
, &value2
, &value3
);
213 get_color (value1
, a
->pix
.border
.color
);
214 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
215 else a
->pix
.border
.alpha
= 0.5;
219 else if (strcmp (key
, "panel_monitor") == 0) {
220 if (strcmp (value
, "all") == 0) panel_config
.monitor
= -1;
222 panel_config
.monitor
= atoi (value
);
223 if (panel_config
.monitor
> 0) panel_config
.monitor
-= 1;
225 if (panel_config
.monitor
> (server
.nb_monitor
-1)) {
226 // server.nb_monitor minimum value is 1 (see get_monitors())
227 fprintf(stderr
, "warning : monitor not found. tint2 default to all monitors.\n");
228 panel_config
.monitor
= 0;
231 else if (strcmp (key
, "panel_size") == 0) {
232 extract_values(value
, &value1
, &value2
, &value3
);
235 if ((b
= strchr (value1
, '%'))) {
237 panel_config
.pourcentx
= 1;
239 panel_config
.area
.width
= atoi(value1
);
240 if (panel_config
.area
.width
== 0) {
242 panel_config
.area
.width
= 100;
243 panel_config
.pourcentx
= 1;
246 if ((b
= strchr (value2
, '%'))) {
248 panel_config
.pourcenty
= 1;
250 panel_config
.area
.height
= atoi(value2
);
253 else if (strcmp (key
, "panel_margin") == 0) {
254 extract_values(value
, &value1
, &value2
, &value3
);
255 panel_config
.marginx
= atoi (value1
);
256 if (value2
) panel_config
.marginy
= atoi (value2
);
258 else if (strcmp (key
, "panel_padding") == 0) {
259 extract_values(value
, &value1
, &value2
, &value3
);
260 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
261 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
262 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
264 else if (strcmp (key
, "panel_position") == 0) {
265 extract_values(value
, &value1
, &value2
, &value3
);
266 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
268 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
269 else panel_position
= CENTER
;
272 if (!value2
) panel_position
|= CENTER
;
274 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
276 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
277 else panel_position
|= CENTER
;
280 if (!value3
) panel_horizontal
= 1;
282 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
283 else panel_horizontal
= 1;
286 else if (strcmp (key
, "font_shadow") == 0)
287 panel_config
.g_task
.font_shadow
= atoi (value
);
288 else if (strcmp (key
, "panel_background_id") == 0) {
289 int id
= atoi (value
);
290 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
291 Area
*a
= g_slist_nth_data(list_back
, id
);
292 memcpy(&panel_config
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
293 memcpy(&panel_config
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
295 else if (strcmp (key
, "wm_menu") == 0)
296 wm_menu
= atoi (value
);
297 else if (strcmp (key
, "panel_dock") == 0)
298 panel_dock
= atoi (value
);
299 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
300 max_tick_urgent
= (atoi (value
) * 2) + 1;
301 else if (strcmp (key
, "real_transparency") == 0)
302 real_transparency
= atoi(value
);
303 else if (strcmp (key
, "panel_layer") == 0) {
304 if (strcmp(value
, "bottom") == 0)
305 panel_layer
= BOTTOM_LAYER
;
306 else if (strcmp(value
, "normal") == 0)
307 panel_layer
= NORMAL_LAYER
;
308 else if (strcmp(value
, "top") == 0)
309 panel_layer
= TOP_LAYER
;
313 else if (strcmp (key
, "battery") == 0) {
314 #ifdef ENABLE_BATTERY
319 fprintf(stderr
, "tint2 is build without battery support\n");
322 else if (strcmp (key
, "battery_low_status") == 0) {
323 #ifdef ENABLE_BATTERY
324 battery_low_status
= atoi(value
);
325 if(battery_low_status
< 0 || battery_low_status
> 100)
326 battery_low_status
= 0;
329 else if (strcmp (key
, "battery_low_cmd") == 0) {
330 #ifdef ENABLE_BATTERY
331 if (strlen(value
) > 0)
332 battery_low_cmd
= strdup (value
);
335 else if (strcmp (key
, "bat1_font") == 0) {
336 #ifdef ENABLE_BATTERY
337 bat1_font_desc
= pango_font_description_from_string (value
);
340 else if (strcmp (key
, "bat2_font") == 0) {
341 #ifdef ENABLE_BATTERY
342 bat2_font_desc
= pango_font_description_from_string (value
);
345 else if (strcmp (key
, "battery_font_color") == 0) {
346 #ifdef ENABLE_BATTERY
347 extract_values(value
, &value1
, &value2
, &value3
);
348 get_color (value1
, panel_config
.battery
.font
.color
);
349 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
350 else panel_config
.battery
.font
.alpha
= 0.5;
353 else if (strcmp (key
, "battery_padding") == 0) {
354 #ifdef ENABLE_BATTERY
355 extract_values(value
, &value1
, &value2
, &value3
);
356 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
357 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
358 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
361 else if (strcmp (key
, "battery_background_id") == 0) {
362 #ifdef ENABLE_BATTERY
363 int id
= atoi (value
);
364 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
365 Area
*a
= g_slist_nth_data(list_back
, id
);
366 memcpy(&panel_config
.battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
367 memcpy(&panel_config
.battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
372 else if (strcmp (key
, "time1_format") == 0) {
373 if (strlen(value
) > 0) {
374 time1_format
= strdup (value
);
378 else if (strcmp (key
, "time2_format") == 0) {
379 if (strlen(value
) > 0)
380 time2_format
= strdup (value
);
382 else if (strcmp (key
, "time1_font") == 0) {
383 time1_font_desc
= pango_font_description_from_string (value
);
385 else if (strcmp(key
, "time1_timezone") == 0) {
386 if (strlen(value
) > 0)
387 time1_timezone
= strdup(value
);
389 else if (strcmp(key
, "time2_timezone") == 0) {
390 if (strlen(value
) > 0)
391 time2_timezone
= strdup(value
);
393 else if (strcmp (key
, "time2_font") == 0) {
394 time2_font_desc
= pango_font_description_from_string (value
);
396 else if (strcmp (key
, "clock_font_color") == 0) {
397 extract_values(value
, &value1
, &value2
, &value3
);
398 get_color (value1
, panel_config
.clock
.font
.color
);
399 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
400 else panel_config
.clock
.font
.alpha
= 0.5;
402 else if (strcmp (key
, "clock_padding") == 0) {
403 extract_values(value
, &value1
, &value2
, &value3
);
404 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
405 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
406 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
408 else if (strcmp (key
, "clock_background_id") == 0) {
409 int id
= atoi (value
);
410 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
411 Area
*a
= g_slist_nth_data(list_back
, id
);
412 memcpy(&panel_config
.clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
413 memcpy(&panel_config
.clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
415 else if (strcmp(key
, "clock_tooltip") == 0) {
416 if (strlen(value
) > 0)
417 time_tooltip_format
= strdup (value
);
419 else if (strcmp(key
, "clock_tooltip_timezone") == 0) {
420 if (strlen(value
) > 0)
421 time_tooltip_timezone
= strdup(value
);
423 else if (strcmp(key
, "clock_lclick_command") == 0) {
424 if (strlen(value
) > 0)
425 clock_lclick_command
= strdup(value
);
427 else if (strcmp(key
, "clock_rclick_command") == 0) {
428 if (strlen(value
) > 0)
429 clock_rclick_command
= strdup(value
);
433 else if (strcmp (key
, "taskbar_mode") == 0) {
434 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
435 else panel_mode
= SINGLE_DESKTOP
;
437 else if (strcmp (key
, "taskbar_padding") == 0) {
438 extract_values(value
, &value1
, &value2
, &value3
);
439 panel_config
.g_taskbar
.paddingxlr
= panel_config
.g_taskbar
.paddingx
= atoi (value1
);
440 if (value2
) panel_config
.g_taskbar
.paddingy
= atoi (value2
);
441 if (value3
) panel_config
.g_taskbar
.paddingx
= atoi (value3
);
443 else if (strcmp (key
, "taskbar_background_id") == 0) {
444 int id
= atoi (value
);
445 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
446 Area
*a
= g_slist_nth_data(list_back
, id
);
447 memcpy(&panel_config
.g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
448 memcpy(&panel_config
.g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
450 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
451 int id
= atoi (value
);
452 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
453 Area
*a
= g_slist_nth_data(list_back
, id
);
454 memcpy(&panel_config
.g_taskbar
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
455 memcpy(&panel_config
.g_taskbar
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
456 panel_config
.g_taskbar
.use_active
= 1;
460 else if (strcmp (key
, "task_text") == 0)
461 panel_config
.g_task
.text
= atoi (value
);
462 else if (strcmp (key
, "task_icon") == 0)
463 panel_config
.g_task
.icon
= atoi (value
);
464 else if (strcmp (key
, "task_centered") == 0)
465 panel_config
.g_task
.centered
= atoi (value
);
466 else if (strcmp (key
, "task_width") == 0) {
467 // old parameter : just for backward compatibility
468 panel_config
.g_task
.maximum_width
= atoi (value
);
469 panel_config
.g_task
.maximum_height
= 30;
471 else if (strcmp (key
, "task_maximum_size") == 0) {
472 extract_values(value
, &value1
, &value2
, &value3
);
473 panel_config
.g_task
.maximum_width
= atoi (value1
);
474 panel_config
.g_task
.maximum_height
= 30;
476 panel_config
.g_task
.maximum_height
= atoi (value2
);
478 else if (strcmp (key
, "task_padding") == 0) {
479 extract_values(value
, &value1
, &value2
, &value3
);
480 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
481 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
482 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
484 else if (strcmp (key
, "task_font") == 0) {
485 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
487 else if (strcmp (key
, "task_font_color") == 0) {
488 extract_values(value
, &value1
, &value2
, &value3
);
489 get_color (value1
, panel_config
.g_task
.font
.color
);
490 if (value2
) panel_config
.g_task
.font
.alpha
= (atoi (value2
) / 100.0);
491 else panel_config
.g_task
.font
.alpha
= 0.1;
493 else if (strcmp (key
, "task_active_font_color") == 0) {
494 extract_values(value
, &value1
, &value2
, &value3
);
495 get_color (value1
, panel_config
.g_task
.font_active
.color
);
496 if (value2
) panel_config
.g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
497 else panel_config
.g_task
.font_active
.alpha
= 0.1;
499 else if (strcmp (key
, "task_icon_asb") == 0) {
500 extract_values(value
, &value1
, &value2
, &value3
);
501 panel_config
.g_task
.alpha
= atoi(value1
);
502 panel_config
.g_task
.saturation
= atoi(value2
);
503 panel_config
.g_task
.brightness
= atoi(value3
);
505 else if (strcmp (key
, "task_active_icon_asb") == 0) {
506 extract_values(value
, &value1
, &value2
, &value3
);
507 panel_config
.g_task
.alpha_active
= atoi(value1
);
508 panel_config
.g_task
.saturation_active
= atoi(value2
);
509 panel_config
.g_task
.brightness_active
= atoi(value3
);
511 else if (strcmp (key
, "task_background_id") == 0) {
512 int id
= atoi (value
);
513 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
514 Area
*a
= g_slist_nth_data(list_back
, id
);
515 memcpy(&panel_config
.g_task
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
516 memcpy(&panel_config
.g_task
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
518 else if (strcmp (key
, "task_active_background_id") == 0) {
519 int id
= atoi (value
);
520 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
521 Area
*a
= g_slist_nth_data(list_back
, id
);
522 memcpy(&panel_config
.g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
523 memcpy(&panel_config
.g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
527 else if (strcmp (key
, "systray") == 0) {
528 systray_enabled
= atoi(value
);
529 // systray is latest option added. files without 'systray' are old.
532 else if (strcmp (key
, "systray_padding") == 0) {
535 extract_values(value
, &value1
, &value2
, &value3
);
536 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
537 if (value2
) systray
.area
.paddingy
= atoi (value2
);
538 if (value3
) systray
.area
.paddingx
= atoi (value3
);
540 else if (strcmp (key
, "systray_background_id") == 0) {
541 int id
= atoi (value
);
542 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
543 Area
*a
= g_slist_nth_data(list_back
, id
);
544 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
545 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
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
, "tooltip") == 0)
569 g_tooltip
.enabled
= atoi(value
);
570 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
571 int timeout_msec
= 1000*atof(value
);
572 g_tooltip
.show_timeout_msec
= timeout_msec
;
574 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
575 int timeout_msec
= 1000*atof(value
);
576 g_tooltip
.hide_timeout_msec
= timeout_msec
;
578 else if (strcmp (key
, "tooltip_padding") == 0) {
579 extract_values(value
, &value1
, &value2
, &value3
);
580 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
581 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
583 else if (strcmp (key
, "tooltip_background_id") == 0) {
584 int id
= atoi (value
);
585 id
= (id
< back_count
&& id
>= 0) ? id
: 0;
586 Area
*a
= g_slist_nth_data(list_back
, id
);
587 memcpy(&g_tooltip
.background_color
, &a
->pix
.back
, sizeof(Color
));
588 memcpy(&g_tooltip
.border
, &a
->pix
.border
, sizeof(Border
));
590 else if (strcmp (key
, "tooltip_font_color") == 0) {
591 extract_values(value
, &value1
, &value2
, &value3
);
592 get_color(value1
, g_tooltip
.font_color
.color
);
593 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
594 else g_tooltip
.font_color
.alpha
= 0.1;
596 else if (strcmp (key
, "tooltip_font") == 0) {
597 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
601 else if (strcmp (key
, "mouse_middle") == 0)
602 get_action (value
, &mouse_middle
);
603 else if (strcmp (key
, "mouse_right") == 0)
604 get_action (value
, &mouse_right
);
605 else if (strcmp (key
, "mouse_scroll_up") == 0)
606 get_action (value
, &mouse_scroll_up
);
607 else if (strcmp (key
, "mouse_scroll_down") == 0)
608 get_action (value
, &mouse_scroll_down
);
610 /* autohide options */
611 else if (strcmp(key
, "autohide") == 0)
612 panel_autohide
= atoi(value
);
613 else if (strcmp(key
, "autohide_show_timeout") == 0)
614 panel_autohide_show_timeout
= 1000*atof(value
);
615 else if (strcmp(key
, "autohide_hide_timeout") == 0)
616 panel_autohide_hide_timeout
= 1000*atof(value
);
617 else if (strcmp(key
, "strut_policy") == 0) {
618 if (strcmp(value
, "follow_size") == 0)
619 panel_strut_policy
= STRUT_FOLLOW_SIZE
;
621 panel_strut_policy
= STRUT_MINIMUM
;
623 else if (strcmp(key
, "autohide_height") == 0)
624 panel_autohide_height
= atoi(value
);
627 /* Read tint-0.6 config for backward compatibility */
628 else if (strcmp (key
, "panel_mode") == 0) {
629 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
630 else panel_mode
= MULTI_DESKTOP
;
632 else if (strcmp (key
, "panel_rounded") == 0) {
633 Area
*a
= calloc(1, sizeof(Area
));
634 a
->pix
.border
.rounded
= atoi (value
);
635 list_back
= g_slist_append(list_back
, a
);
637 else if (strcmp (key
, "panel_border_width") == 0) {
638 Area
*a
= g_slist_last(list_back
)->data
;
639 a
->pix
.border
.width
= atoi (value
);
641 else if (strcmp (key
, "panel_background_color") == 0) {
642 Area
*a
= g_slist_last(list_back
)->data
;
643 extract_values(value
, &value1
, &value2
, &value3
);
644 get_color (value1
, a
->pix
.back
.color
);
645 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
646 else a
->pix
.back
.alpha
= 0.5;
648 else if (strcmp (key
, "panel_border_color") == 0) {
649 Area
*a
= g_slist_last(list_back
)->data
;
650 extract_values(value
, &value1
, &value2
, &value3
);
651 get_color (value1
, a
->pix
.border
.color
);
652 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
653 else a
->pix
.border
.alpha
= 0.5;
655 else if (strcmp (key
, "task_text_centered") == 0)
656 panel_config
.g_task
.centered
= atoi (value
);
657 else if (strcmp (key
, "task_margin") == 0) {
658 panel_config
.g_taskbar
.paddingxlr
= 0;
659 panel_config
.g_taskbar
.paddingx
= atoi (value
);
661 else if (strcmp (key
, "task_icon_size") == 0)
662 old_task_icon_size
= atoi (value
);
663 else if (strcmp (key
, "task_rounded") == 0) {
664 area_task
= calloc(1, sizeof(Area
));
665 area_task
->pix
.border
.rounded
= atoi (value
);
666 list_back
= g_slist_append(list_back
, area_task
);
668 area_task_active
= calloc(1, sizeof(Area
));
669 area_task_active
->pix
.border
.rounded
= atoi (value
);
670 list_back
= g_slist_append(list_back
, area_task_active
);
672 else if (strcmp (key
, "task_background_color") == 0) {
673 extract_values(value
, &value1
, &value2
, &value3
);
674 get_color (value1
, area_task
->pix
.back
.color
);
675 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
676 else area_task
->pix
.back
.alpha
= 0.5;
678 else if (strcmp (key
, "task_active_background_color") == 0) {
679 extract_values(value
, &value1
, &value2
, &value3
);
680 get_color (value1
, area_task_active
->pix
.back
.color
);
681 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
682 else area_task_active
->pix
.back
.alpha
= 0.5;
684 else if (strcmp (key
, "task_border_width") == 0) {
685 area_task
->pix
.border
.width
= atoi (value
);
686 area_task_active
->pix
.border
.width
= atoi (value
);
688 else if (strcmp (key
, "task_border_color") == 0) {
689 extract_values(value
, &value1
, &value2
, &value3
);
690 get_color (value1
, area_task
->pix
.border
.color
);
691 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
692 else area_task
->pix
.border
.alpha
= 0.5;
694 else if (strcmp (key
, "task_active_border_color") == 0) {
695 extract_values(value
, &value1
, &value2
, &value3
);
696 get_color (value1
, area_task_active
->pix
.border
.color
);
697 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
698 else area_task_active
->pix
.border
.alpha
= 0.5;
702 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
704 if (value1
) free (value1
);
705 if (value2
) free (value2
);
706 if (value3
) free (value3
);
712 const gchar
* const * system_dirs
;
716 // follow XDG specification
717 // check tint2rc in user directory
718 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
719 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
720 i
= config_read_file (path1
);
721 config_path
= strdup(path1
);
727 // copy tint2rc from system directory to user directory
729 system_dirs
= g_get_system_config_dirs();
730 for (i
= 0; system_dirs
[i
]; i
++) {
731 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
733 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
739 // copy file in user directory (path1)
740 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
741 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
744 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
745 copy_file(path2
, path1
);
748 i
= config_read_file (path1
);
749 config_path
= strdup(path1
);
757 int config_read_file (const char *path
)
763 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
765 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
766 if (parse_line(line
, &key
, &value
)) {
767 add_entry (key
, value
);
774 if (old_task_icon_size
) {
775 panel_config
.g_task
.area
.paddingy
= ((int)panel_config
.area
.height
- (2 * panel_config
.area
.paddingy
) - old_task_icon_size
) / 2;