]>
Dogcows Code - chaz/tint2/blob - src/config.c
6b79b2430f3ae040eb90326baec29d5f7fb5ffaf
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>
41 #include "systraybar.h"
52 char *config_path
= 0;
53 char *thumbnail_path
= 0;
55 // --------------------------------------------------
56 // backward compatibility
57 static int save_file_config
;
58 static int old_task_icon_size
;
59 static char *old_task_font
;
60 static char *old_time1_font
;
61 static char *old_time2_font
;
62 static Area
*area_task
, *area_task_active
;
65 static char *old_bat1_font
;
66 static char *old_bat2_font
;
70 static Panel
*panel_config
= 0;
72 // temporary list of background
73 static GSList
*list_back
;
80 // get monitor and desktop config
81 get_monitors_and_desktops();
83 // append full transparency background
84 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
86 panel_config
= calloc(1, sizeof(Panel
));
89 // window manager's menu default value == false
100 // cleanup background list
102 for (l0
= list_back
; l0
; l0
= l0
->next
) {
105 g_slist_free(list_back
);
110 void copy_file(const char *pathSrc
, const char *pathDest
)
112 FILE *fileSrc
, *fileDest
;
116 fileSrc
= fopen(pathSrc
, "rb");
117 if (fileSrc
== NULL
) return;
119 fileDest
= fopen(pathDest
, "wb");
120 if (fileDest
== NULL
) return;
122 while ((nb
= fread(line
, 1, 100, fileSrc
)) > 0) fwrite(line
, 1, nb
, fileDest
);
129 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
133 if (*value1
) free (*value1
);
134 if (*value2
) free (*value2
);
135 if (*value3
) free (*value3
);
137 if ((b
= strchr (value
, ' '))) {
145 *value1
= strdup (value
);
149 if ((c
= strchr (b
, ' '))) {
157 *value2
= strdup (b
);
162 *value3
= strdup (c
);
168 int hex_char_to_int (char c
)
172 if (c
>= '0' && c
<= '9') r
= c
- '0';
173 else if (c
>= 'a' && c
<= 'f') r
= c
- 'a' + 10;
174 else if (c
>= 'A' && c
<= 'F') r
= c
- 'A' + 10;
181 int hex_to_rgb (char *hex
, int *r
, int *g
, int *b
)
185 if (hex
== NULL
|| hex
[0] != '#') return (0);
189 *r
= hex_char_to_int (hex
[1]);
190 *g
= hex_char_to_int (hex
[2]);
191 *b
= hex_char_to_int (hex
[3]);
193 else if (len
== 6 + 1) {
194 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
195 *g
= hex_char_to_int (hex
[3]) * 16 + hex_char_to_int (hex
[4]);
196 *b
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
198 else if (len
== 12 + 1) {
199 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
200 *g
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
201 *b
= hex_char_to_int (hex
[9]) * 16 + hex_char_to_int (hex
[10]);
209 void get_color (char *hex
, double *rgb
)
212 hex_to_rgb (hex
, &r
, &g
, &b
);
214 rgb
[0] = (r
/ 255.0);
215 rgb
[1] = (g
/ 255.0);
216 rgb
[2] = (b
/ 255.0);
220 void get_action (char *event
, int *action
)
222 if (strcmp (event
, "none") == 0)
224 else if (strcmp (event
, "close") == 0)
226 else if (strcmp (event
, "toggle") == 0)
228 else if (strcmp (event
, "iconify") == 0)
230 else if (strcmp (event
, "shade") == 0)
232 else if (strcmp (event
, "toggle_iconify") == 0)
233 *action
= TOGGLE_ICONIFY
;
234 else if (strcmp (event
, "maximize_restore") == 0)
235 *action
= MAXIMIZE_RESTORE
;
236 else if (strcmp (event
, "desktop_left") == 0)
237 *action
= DESKTOP_LEFT
;
238 else if (strcmp (event
, "desktop_right") == 0)
239 *action
= DESKTOP_RIGHT
;
243 void add_entry (char *key
, char *value
)
245 char *value1
=0, *value2
=0, *value3
=0;
247 /* Background and border */
248 if (strcmp (key
, "rounded") == 0) {
249 // 'rounded' is the first parameter => alloc a new background
250 Area
*a
= calloc(1, sizeof(Area
));
251 a
->pix
.border
.rounded
= atoi (value
);
252 list_back
= g_slist_append(list_back
, a
);
254 else if (strcmp (key
, "border_width") == 0) {
255 Area
*a
= g_slist_last(list_back
)->data
;
256 a
->pix
.border
.width
= atoi (value
);
258 else if (strcmp (key
, "background_color") == 0) {
259 Area
*a
= g_slist_last(list_back
)->data
;
260 extract_values(value
, &value1
, &value2
, &value3
);
261 get_color (value1
, a
->pix
.back
.color
);
262 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
263 else a
->pix
.back
.alpha
= 0.5;
265 else if (strcmp (key
, "border_color") == 0) {
266 Area
*a
= g_slist_last(list_back
)->data
;
267 extract_values(value
, &value1
, &value2
, &value3
);
268 get_color (value1
, a
->pix
.border
.color
);
269 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
270 else a
->pix
.border
.alpha
= 0.5;
274 else if (strcmp (key
, "panel_monitor") == 0) {
275 if (strcmp (value
, "all") == 0) panel_config
->monitor
= -1;
277 panel_config
->monitor
= atoi (value
);
278 if (panel_config
->monitor
> 0) panel_config
->monitor
-= 1;
281 else if (strcmp (key
, "panel_size") == 0) {
282 extract_values(value
, &value1
, &value2
, &value3
);
285 if ((b
= strchr (value1
, '%'))) {
287 panel_config
->pourcentx
= 1;
289 panel_config
->initial_width
= atof(value1
);
291 if ((b
= strchr (value2
, '%'))) {
293 panel_config
->pourcenty
= 1;
295 panel_config
->initial_height
= atof(value2
);
298 else if (strcmp (key
, "panel_margin") == 0) {
299 extract_values(value
, &value1
, &value2
, &value3
);
300 panel_config
->marginx
= atoi (value1
);
301 if (value2
) panel_config
->marginy
= atoi (value2
);
303 else if (strcmp (key
, "panel_padding") == 0) {
304 extract_values(value
, &value1
, &value2
, &value3
);
305 panel_config
->area
.paddingxlr
= panel_config
->area
.paddingx
= atoi (value1
);
306 if (value2
) panel_config
->area
.paddingy
= atoi (value2
);
307 if (value3
) panel_config
->area
.paddingx
= atoi (value3
);
309 else if (strcmp (key
, "panel_position") == 0) {
310 extract_values(value
, &value1
, &value2
, &value3
);
311 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
313 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
314 else panel_position
= CENTER
;
317 if (!value2
) panel_position
|= CENTER
;
319 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
321 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
322 else panel_position
|= CENTER
;
325 if (!value3
) panel_horizontal
= 1;
327 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
328 else panel_horizontal
= 1;
331 else if (strcmp (key
, "font_shadow") == 0)
332 panel_config
->g_task
.font_shadow
= atoi (value
);
333 else if (strcmp (key
, "panel_background_id") == 0) {
334 int id
= atoi (value
);
335 Area
*a
= g_slist_nth_data(list_back
, id
);
336 memcpy(&panel_config
->area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
337 memcpy(&panel_config
->area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
339 else if (strcmp (key
, "wm_menu") == 0)
340 wm_menu
= atoi (value
);
341 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
342 max_tick_urgent
= (atoi (value
) * 2) + 1;
345 else if (strcmp (key
, "battery") == 0) {
346 #ifdef ENABLE_BATTERY
348 panel_config
->battery
.area
.on_screen
= 1;
351 fprintf(stderr
, "tint2 is build without battery support\n");
354 else if (strcmp (key
, "battery_low_status") == 0) {
355 #ifdef ENABLE_BATTERY
356 battery_low_status
= atoi(value
);
357 if(battery_low_status
< 0 || battery_low_status
> 100)
358 battery_low_status
= 0;
361 else if (strcmp (key
, "battery_low_cmd") == 0) {
362 #ifdef ENABLE_BATTERY
363 if (battery_low_cmd
) g_free(battery_low_cmd
);
364 if (strlen(value
) > 0) battery_low_cmd
= strdup (value
);
365 else battery_low_cmd
= 0;
368 else if (strcmp (key
, "bat1_font") == 0) {
369 #ifdef ENABLE_BATTERY
370 if (save_file_config
) old_bat1_font
= strdup (value
);
371 if (bat1_font_desc
) pango_font_description_free(bat1_font_desc
);
372 bat1_font_desc
= pango_font_description_from_string (value
);
375 else if (strcmp (key
, "bat2_font") == 0) {
376 #ifdef ENABLE_BATTERY
377 if (save_file_config
) old_bat2_font
= strdup (value
);
378 if (bat2_font_desc
) pango_font_description_free(bat2_font_desc
);
379 bat2_font_desc
= pango_font_description_from_string (value
);
382 else if (strcmp (key
, "battery_font_color") == 0) {
383 #ifdef ENABLE_BATTERY
384 extract_values(value
, &value1
, &value2
, &value3
);
385 get_color (value1
, panel_config
->battery
.font
.color
);
386 if (value2
) panel_config
->battery
.font
.alpha
= (atoi (value2
) / 100.0);
387 else panel_config
->battery
.font
.alpha
= 0.5;
390 else if (strcmp (key
, "battery_padding") == 0) {
391 #ifdef ENABLE_BATTERY
392 extract_values(value
, &value1
, &value2
, &value3
);
393 panel_config
->battery
.area
.paddingxlr
= panel_config
->battery
.area
.paddingx
= atoi (value1
);
394 if (value2
) panel_config
->battery
.area
.paddingy
= atoi (value2
);
395 if (value3
) panel_config
->battery
.area
.paddingx
= atoi (value3
);
398 else if (strcmp (key
, "battery_background_id") == 0) {
399 #ifdef ENABLE_BATTERY
400 int id
= atoi (value
);
401 Area
*a
= g_slist_nth_data(list_back
, id
);
402 memcpy(&panel_config
->battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
403 memcpy(&panel_config
->battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
408 else if (strcmp (key
, "time1_format") == 0) {
409 if (time1_format
) g_free(time1_format
);
410 if (strlen(value
) > 0) {
411 time1_format
= strdup (value
);
412 panel_config
->clock
.area
.on_screen
= 1;
416 panel_config
->clock
.area
.on_screen
= 0;
419 else if (strcmp (key
, "time2_format") == 0) {
420 if (time2_format
) g_free(time2_format
);
421 if (strlen(value
) > 0) time2_format
= strdup (value
);
422 else time2_format
= 0;
424 else if (strcmp (key
, "time1_font") == 0) {
425 if (save_file_config
) old_time1_font
= strdup (value
);
426 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
427 time1_font_desc
= pango_font_description_from_string (value
);
429 else if (strcmp (key
, "time2_font") == 0) {
430 if (save_file_config
) old_time2_font
= strdup (value
);
431 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
432 time2_font_desc
= pango_font_description_from_string (value
);
434 else if (strcmp (key
, "clock_font_color") == 0) {
435 extract_values(value
, &value1
, &value2
, &value3
);
436 get_color (value1
, panel_config
->clock
.font
.color
);
437 if (value2
) panel_config
->clock
.font
.alpha
= (atoi (value2
) / 100.0);
438 else panel_config
->clock
.font
.alpha
= 0.5;
440 else if (strcmp (key
, "clock_padding") == 0) {
441 extract_values(value
, &value1
, &value2
, &value3
);
442 panel_config
->clock
.area
.paddingxlr
= panel_config
->clock
.area
.paddingx
= atoi (value1
);
443 if (value2
) panel_config
->clock
.area
.paddingy
= atoi (value2
);
444 if (value3
) panel_config
->clock
.area
.paddingx
= atoi (value3
);
446 else if (strcmp (key
, "clock_background_id") == 0) {
447 int id
= atoi (value
);
448 Area
*a
= g_slist_nth_data(list_back
, id
);
449 memcpy(&panel_config
->clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
450 memcpy(&panel_config
->clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
452 else if (strcmp(key
, "clock_lclick_command") == 0) {
453 if (clock_lclick_command
) g_free(clock_lclick_command
);
454 if (strlen(value
) > 0) clock_lclick_command
= strdup(value
);
455 else clock_lclick_command
= 0;
457 else if (strcmp(key
, "clock_rclick_command") == 0) {
458 if (clock_rclick_command
) g_free(clock_rclick_command
);
459 if (strlen(value
) > 0) clock_rclick_command
= strdup(value
);
460 else clock_rclick_command
= 0;
464 else if (strcmp (key
, "taskbar_mode") == 0) {
465 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
466 else panel_mode
= SINGLE_DESKTOP
;
468 else if (strcmp (key
, "taskbar_padding") == 0) {
469 extract_values(value
, &value1
, &value2
, &value3
);
470 panel_config
->g_taskbar
.paddingxlr
= panel_config
->g_taskbar
.paddingx
= atoi (value1
);
471 if (value2
) panel_config
->g_taskbar
.paddingy
= atoi (value2
);
472 if (value3
) panel_config
->g_taskbar
.paddingx
= atoi (value3
);
474 else if (strcmp (key
, "taskbar_background_id") == 0) {
475 int id
= atoi (value
);
476 Area
*a
= g_slist_nth_data(list_back
, id
);
477 memcpy(&panel_config
->g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
478 memcpy(&panel_config
->g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
480 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
481 int id
= atoi (value
);
482 Area
*a
= g_slist_nth_data(list_back
, id
);
483 memcpy(&panel_config
->g_taskbar
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
484 memcpy(&panel_config
->g_taskbar
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
485 panel_config
->g_taskbar
.use_active
= 1;
489 else if (strcmp (key
, "task_text") == 0)
490 panel_config
->g_task
.text
= atoi (value
);
491 else if (strcmp (key
, "task_icon") == 0)
492 panel_config
->g_task
.icon
= atoi (value
);
493 else if (strcmp (key
, "task_centered") == 0)
494 panel_config
->g_task
.centered
= atoi (value
);
495 else if (strcmp (key
, "task_width") == 0) {
496 // old parameter : just for backward compatibility
497 panel_config
->g_task
.maximum_width
= atoi (value
);
498 panel_config
->g_task
.maximum_height
= 30;
500 else if (strcmp (key
, "task_maximum_size") == 0) {
501 extract_values(value
, &value1
, &value2
, &value3
);
502 panel_config
->g_task
.maximum_width
= atoi (value1
);
503 panel_config
->g_task
.maximum_height
= 30;
505 panel_config
->g_task
.maximum_height
= atoi (value2
);
507 else if (strcmp (key
, "task_padding") == 0) {
508 extract_values(value
, &value1
, &value2
, &value3
);
509 panel_config
->g_task
.area
.paddingxlr
= panel_config
->g_task
.area
.paddingx
= atoi (value1
);
510 if (value2
) panel_config
->g_task
.area
.paddingy
= atoi (value2
);
511 if (value3
) panel_config
->g_task
.area
.paddingx
= atoi (value3
);
513 else if (strcmp (key
, "task_font") == 0) {
514 if (save_file_config
) old_task_font
= strdup (value
);
515 if (panel_config
->g_task
.font_desc
) pango_font_description_free(panel_config
->g_task
.font_desc
);
516 panel_config
->g_task
.font_desc
= pango_font_description_from_string (value
);
518 else if (strcmp (key
, "task_font_color") == 0) {
519 extract_values(value
, &value1
, &value2
, &value3
);
520 get_color (value1
, panel_config
->g_task
.font
.color
);
521 if (value2
) panel_config
->g_task
.font
.alpha
= (atoi (value2
) / 100.0);
522 else panel_config
->g_task
.font
.alpha
= 0.1;
524 else if (strcmp (key
, "task_active_font_color") == 0) {
525 extract_values(value
, &value1
, &value2
, &value3
);
526 get_color (value1
, panel_config
->g_task
.font_active
.color
);
527 if (value2
) panel_config
->g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
528 else panel_config
->g_task
.font_active
.alpha
= 0.1;
530 else if (strcmp (key
, "task_icon_hsb") == 0) {
531 extract_values(value
, &value1
, &value2
, &value3
);
532 panel_config
->g_task
.hue
= atoi(value1
);
533 panel_config
->g_task
.saturation
= atoi(value2
);
534 panel_config
->g_task
.brightness
= atoi(value3
);
536 else if (strcmp (key
, "task_active_icon_hsb") == 0) {
537 extract_values(value
, &value1
, &value2
, &value3
);
538 panel_config
->g_task
.hue_active
= atoi(value1
);
539 panel_config
->g_task
.saturation_active
= atoi(value2
);
540 panel_config
->g_task
.brightness_active
= atoi(value3
);
542 else if (strcmp (key
, "task_background_id") == 0) {
543 int id
= atoi (value
);
544 Area
*a
= g_slist_nth_data(list_back
, id
);
545 memcpy(&panel_config
->g_task
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
546 memcpy(&panel_config
->g_task
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
548 else if (strcmp (key
, "task_active_background_id") == 0) {
549 int id
= atoi (value
);
550 Area
*a
= g_slist_nth_data(list_back
, id
);
551 memcpy(&panel_config
->g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
552 memcpy(&panel_config
->g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
556 else if (strcmp (key
, "systray_padding") == 0) {
557 extract_values(value
, &value1
, &value2
, &value3
);
558 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
559 if (value2
) systray
.area
.paddingy
= atoi (value2
);
560 if (value3
) systray
.area
.paddingx
= atoi (value3
);
561 systray
.area
.on_screen
= 1;
563 else if (strcmp (key
, "systray_background_id") == 0) {
564 int id
= atoi (value
);
565 Area
*a
= g_slist_nth_data(list_back
, id
);
566 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
567 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
569 else if (strcmp(key
, "systray_sort") == 0) {
570 if (strcmp(value
, "desc") == 0)
577 else if (strcmp (key
, "mouse_middle") == 0)
578 get_action (value
, &mouse_middle
);
579 else if (strcmp (key
, "mouse_right") == 0)
580 get_action (value
, &mouse_right
);
581 else if (strcmp (key
, "mouse_scroll_up") == 0)
582 get_action (value
, &mouse_scroll_up
);
583 else if (strcmp (key
, "mouse_scroll_down") == 0)
584 get_action (value
, &mouse_scroll_down
);
587 /* Read tint-0.6 config for backward compatibility */
588 else if (strcmp (key
, "panel_mode") == 0) {
589 save_file_config
= 1;
590 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
591 else panel_mode
= MULTI_DESKTOP
;
593 else if (strcmp (key
, "panel_rounded") == 0) {
594 Area
*a
= calloc(1, sizeof(Area
));
595 a
->pix
.border
.rounded
= atoi (value
);
596 list_back
= g_slist_append(list_back
, a
);
598 else if (strcmp (key
, "panel_border_width") == 0) {
599 Area
*a
= g_slist_last(list_back
)->data
;
600 a
->pix
.border
.width
= atoi (value
);
602 else if (strcmp (key
, "panel_background_color") == 0) {
603 Area
*a
= g_slist_last(list_back
)->data
;
604 extract_values(value
, &value1
, &value2
, &value3
);
605 get_color (value1
, a
->pix
.back
.color
);
606 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
607 else a
->pix
.back
.alpha
= 0.5;
609 else if (strcmp (key
, "panel_border_color") == 0) {
610 Area
*a
= g_slist_last(list_back
)->data
;
611 extract_values(value
, &value1
, &value2
, &value3
);
612 get_color (value1
, a
->pix
.border
.color
);
613 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
614 else a
->pix
.border
.alpha
= 0.5;
616 else if (strcmp (key
, "task_text_centered") == 0)
617 panel_config
->g_task
.centered
= atoi (value
);
618 else if (strcmp (key
, "task_margin") == 0) {
619 panel_config
->g_taskbar
.paddingxlr
= 0;
620 panel_config
->g_taskbar
.paddingx
= atoi (value
);
622 else if (strcmp (key
, "task_icon_size") == 0)
623 old_task_icon_size
= atoi (value
);
624 else if (strcmp (key
, "task_rounded") == 0) {
625 area_task
= calloc(1, sizeof(Area
));
626 area_task
->pix
.border
.rounded
= atoi (value
);
627 list_back
= g_slist_append(list_back
, area_task
);
629 area_task_active
= calloc(1, sizeof(Area
));
630 area_task_active
->pix
.border
.rounded
= atoi (value
);
631 list_back
= g_slist_append(list_back
, area_task_active
);
633 else if (strcmp (key
, "task_background_color") == 0) {
634 extract_values(value
, &value1
, &value2
, &value3
);
635 get_color (value1
, area_task
->pix
.back
.color
);
636 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
637 else area_task
->pix
.back
.alpha
= 0.5;
639 else if (strcmp (key
, "task_active_background_color") == 0) {
640 extract_values(value
, &value1
, &value2
, &value3
);
641 get_color (value1
, area_task_active
->pix
.back
.color
);
642 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
643 else area_task_active
->pix
.back
.alpha
= 0.5;
645 else if (strcmp (key
, "task_border_width") == 0) {
646 area_task
->pix
.border
.width
= atoi (value
);
647 area_task_active
->pix
.border
.width
= atoi (value
);
649 else if (strcmp (key
, "task_border_color") == 0) {
650 extract_values(value
, &value1
, &value2
, &value3
);
651 get_color (value1
, area_task
->pix
.border
.color
);
652 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
653 else area_task
->pix
.border
.alpha
= 0.5;
655 else if (strcmp (key
, "task_active_border_color") == 0) {
656 extract_values(value
, &value1
, &value2
, &value3
);
657 get_color (value1
, area_task_active
->pix
.border
.color
);
658 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
659 else area_task_active
->pix
.border
.alpha
= 0.5;
663 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
665 if (value1
) free (value1
);
666 if (value2
) free (value2
);
667 if (value3
) free (value3
);
671 int parse_line (const char *line
)
673 char *a
, *b
, *key
, *value
;
675 /* Skip useless lines */
676 if ((line
[0] == '#') || (line
[0] == '\n')) return 0;
677 if (!(a
= strchr (line
, '='))) return 0;
679 /* overwrite '=' with '\0' */
684 /* overwrite '\n' with '\0' if '\n' present */
685 if ((b
= strchr (a
, '\n'))) b
[0] = '\0';
692 add_entry (key
, value
);
700 void config_finish ()
702 if (panel_config
->monitor
> (server
.nb_monitor
-1)) {
703 // server.nb_monitor minimum value is 1 (see get_monitors_and_desktops())
704 // and panel_config->monitor is higher
705 fprintf(stderr
, "warning : monitor not found. tint2 default to monitor 1.\n");
706 panel_config
->monitor
= 0;
711 if (panel_config
->monitor
>= 0) {
714 panel1
= calloc(nb_panel
, sizeof(Panel
));
715 memcpy(panel1
, panel_config
, sizeof(Panel
));
716 panel1
->monitor
= panel_config
->monitor
;
720 nb_panel
= server
.nb_monitor
;
721 panel1
= calloc(nb_panel
, sizeof(Panel
));
723 for (i
=0 ; i
< nb_panel
; i
++) {
724 memcpy(&panel1
[i
], panel_config
, sizeof(Panel
));
725 panel1
[i
].monitor
= i
;
729 // TODO: user can configure layout => ordered objects in panel.area.list
730 // clock and systray before taskbar because resize(clock) can resize others object ??
733 #ifdef ENABLE_BATTERY
742 task_refresh_tasklist();
748 const gchar
* const * system_dirs
;
752 save_file_config
= 0;
754 // follow XDG specification
756 // check tint2rc in user directory
757 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
758 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
759 i
= config_read_file (path1
);
760 config_path
= strdup(path1
);
766 if (save_file_config
) {
767 fprintf(stderr
, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
771 // check old tintrc config file
772 path1
= g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL
);
773 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
774 save_file_config
= 1;
775 config_read_file (path1
);
780 // copy tint2rc from system directory to user directory
783 system_dirs
= g_get_system_config_dirs();
784 for (i
= 0; system_dirs
[i
]; i
++) {
785 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
787 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
793 // copy file in user directory (path1)
794 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
795 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
798 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
799 copy_file(path2
, path1
);
802 i
= config_read_file (path1
);
803 config_path
= strdup(path1
);
811 int config_read_file (const char *path
)
816 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
821 while (fgets(line
, sizeof(line
), fp
) != NULL
)
826 if (save_file_config
)
830 g_free(old_task_font
);
833 if (old_time1_font
) {
834 g_free(old_time1_font
);
837 if (old_time2_font
) {
838 g_free(old_time2_font
);
847 fprintf(stderr
, "tint2 : convert user's config file\n");
852 if (old_task_icon_size
) {
853 panel_config
->g_task
.area
.paddingy
= ((int)panel_config
->initial_height
- (2 * panel_config
->area
.paddingy
) - old_task_icon_size
) / 2;
856 dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
857 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
860 path
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
861 fp
= fopen(path
, "w");
863 if (fp
== NULL
) return;
865 fputs("#---------------------------------------------\n", fp
);
866 fputs("# TINT2 CONFIG FILE\n", fp
);
867 fputs("#---------------------------------------------\n\n", fp
);
868 fputs("#---------------------------------------------\n", fp
);
869 fputs("# BACKGROUND AND BORDER\n", fp
);
870 fputs("#---------------------------------------------\n", fp
);
873 l0
= list_back
->next
;
876 fprintf(fp
, "rounded = %d\n", a
->pix
.border
.rounded
);
877 fprintf(fp
, "border_width = %d\n", a
->pix
.border
.width
);
878 fprintf(fp
, "background_color = #%02x%02x%02x %d\n", (int)(a
->pix
.back
.color
[0]*255), (int)(a
->pix
.back
.color
[1]*255), (int)(a
->pix
.back
.color
[2]*255), (int)(a
->pix
.back
.alpha
*100));
879 fprintf(fp
, "border_color = #%02x%02x%02x %d\n\n", (int)(a
->pix
.border
.color
[0]*255), (int)(a
->pix
.border
.color
[1]*255), (int)(a
->pix
.border
.color
[2]*255), (int)(a
->pix
.border
.alpha
*100));
884 fputs("#---------------------------------------------\n", fp
);
885 fputs("# PANEL\n", fp
);
886 fputs("#---------------------------------------------\n", fp
);
887 fputs("panel_monitor = all\n", fp
);
888 if (panel_position
& BOTTOM
) fputs("panel_position = bottom", fp
);
889 else fputs("panel_position = top", fp
);
890 if (panel_position
& LEFT
) fputs(" left horizontal\n", fp
);
891 else if (panel_position
& RIGHT
) fputs(" right horizontal\n", fp
);
892 else fputs(" center horizontal\n", fp
);
893 fprintf(fp
, "panel_size = %d %d\n", (int)panel_config
->initial_width
, (int)panel_config
->initial_height
);
894 fprintf(fp
, "panel_margin = %d %d\n", panel_config
->marginx
, panel_config
->marginy
);
895 fprintf(fp
, "panel_padding = %d %d %d\n", panel_config
->area
.paddingxlr
, panel_config
->area
.paddingy
, panel_config
->area
.paddingx
);
896 fprintf(fp
, "font_shadow = %d\n", panel_config
->g_task
.font_shadow
);
897 fputs("panel_background_id = 1\n", fp
);
898 fputs("wm_menu = 0\n", fp
);
900 fputs("\n#---------------------------------------------\n", fp
);
901 fputs("# TASKBAR\n", fp
);
902 fputs("#---------------------------------------------\n", fp
);
903 if (panel_mode
== MULTI_DESKTOP
) fputs("taskbar_mode = multi_desktop\n", fp
);
904 else fputs("taskbar_mode = single_desktop\n", fp
);
905 fprintf(fp
, "taskbar_padding = 0 0 %d\n", panel_config
->g_taskbar
.paddingx
);
906 fputs("taskbar_background_id = 0\n", fp
);
908 fputs("\n#---------------------------------------------\n", fp
);
909 fputs("# TASK\n", fp
);
910 fputs("#---------------------------------------------\n", fp
);
911 if (old_task_icon_size
) fputs("task_icon = 1\n", fp
);
912 else fputs("task_icon = 0\n", fp
);
913 fputs("task_text = 1\n", fp
);
914 fprintf(fp
, "task_maximum_size = %d %d\n", panel_config
->g_task
.maximum_width
, panel_config
->g_task
.maximum_height
);
915 fprintf(fp
, "task_centered = %d\n", panel_config
->g_task
.centered
);
916 fprintf(fp
, "task_padding = %d %d\n", panel_config
->g_task
.area
.paddingx
, panel_config
->g_task
.area
.paddingy
);
917 fprintf(fp
, "task_font = %s\n", old_task_font
);
918 fprintf(fp
, "task_font_color = #%02x%02x%02x %d\n", (int)(panel_config
->g_task
.font
.color
[0]*255), (int)(panel_config
->g_task
.font
.color
[1]*255), (int)(panel_config
->g_task
.font
.color
[2]*255), (int)(panel_config
->g_task
.font
.alpha
*100));
919 fprintf(fp
, "task_active_font_color = #%02x%02x%02x %d\n", (int)(panel_config
->g_task
.font_active
.color
[0]*255), (int)(panel_config
->g_task
.font_active
.color
[1]*255), (int)(panel_config
->g_task
.font_active
.color
[2]*255), (int)(panel_config
->g_task
.font_active
.alpha
*100));
920 fputs("task_background_id = 2\n", fp
);
921 fputs("task_active_background_id = 3\n", fp
);
923 fputs("\n#---------------------------------------------\n", fp
);
924 fputs("# SYSTRAYBAR\n", fp
);
925 fputs("#---------------------------------------------\n", fp
);
926 fputs("systray_padding = 4 3 4\n", fp
);
927 fputs("systray_background_id = 0\n", fp
);
929 fputs("\n#---------------------------------------------\n", fp
);
930 fputs("# CLOCK\n", fp
);
931 fputs("#---------------------------------------------\n", fp
);
932 if (time1_format
) fprintf(fp
, "time1_format = %s\n", time1_format
);
933 else fputs("#time1_format = %H:%M\n", fp
);
934 fprintf(fp
, "time1_font = %s\n", old_time1_font
);
935 if (time2_format
) fprintf(fp
, "time2_format = %s\n", time2_format
);
936 else fputs("#time2_format = %A %d %B\n", fp
);
937 fprintf(fp
, "time2_font = %s\n", old_time2_font
);
938 fprintf(fp
, "clock_font_color = #%02x%02x%02x %d\n", (int)(panel_config
->clock
.font
.color
[0]*255), (int)(panel_config
->clock
.font
.color
[1]*255), (int)(panel_config
->clock
.font
.color
[2]*255), (int)(panel_config
->clock
.font
.alpha
*100));
939 fputs("clock_padding = 2 2\n", fp
);
940 fputs("clock_background_id = 0\n", fp
);
941 fputs("#clock_lclick_command = xclock\n", fp
);
942 fputs("clock_rclick_command = orage\n", fp
);
944 #ifdef ENABLE_BATTERY
945 fputs("\n#---------------------------------------------\n", fp
);
946 fputs("# BATTERY\n", fp
);
947 fputs("#---------------------------------------------\n", fp
);
948 fprintf(fp
, "battery = %d\n", panel_config
->battery
.area
.on_screen
);
949 fprintf(fp
, "battery_low_status = %d\n", battery_low_status
);
950 fprintf(fp
, "battery_low_cmd = %s\n", battery_low_cmd
);
951 fprintf(fp
, "bat1_font = %s\n", old_bat1_font
);
952 fprintf(fp
, "bat2_font = %s\n", old_bat2_font
);
953 fprintf(fp
, "battery_font_color = #%02x%02x%02x %d\n", (int)(panel_config
->battery
.font
.color
[0]*255), (int)(panel_config
->battery
.font
.color
[1]*255), (int)(panel_config
->battery
.font
.color
[2]*255), (int)(panel_config
->battery
.font
.alpha
*100));
954 fputs("battery_padding = 2 2\n", fp
);
955 fputs("battery_background_id = 0\n", fp
);
958 fputs("\n#---------------------------------------------\n", fp
);
959 fputs("# MOUSE ACTION ON TASK\n", fp
);
960 fputs("#---------------------------------------------\n", fp
);
961 if (mouse_middle
== NONE
) fputs("mouse_middle = none\n", fp
);
962 else if (mouse_middle
== CLOSE
) fputs("mouse_middle = close\n", fp
);
963 else if (mouse_middle
== TOGGLE
) fputs("mouse_middle = toggle\n", fp
);
964 else if (mouse_middle
== ICONIFY
) fputs("mouse_middle = iconify\n", fp
);
965 else if (mouse_middle
== SHADE
) fputs("mouse_middle = shade\n", fp
);
966 else fputs("mouse_middle = toggle_iconify\n", fp
);
968 if (mouse_right
== NONE
) fputs("mouse_right = none\n", fp
);
969 else if (mouse_right
== CLOSE
) fputs("mouse_right = close\n", fp
);
970 else if (mouse_right
== TOGGLE
) fputs("mouse_right = toggle\n", fp
);
971 else if (mouse_right
== ICONIFY
) fputs("mouse_right = iconify\n", fp
);
972 else if (mouse_right
== SHADE
) fputs("mouse_right = shade\n", fp
);
973 else fputs("mouse_right = toggle_iconify\n", fp
);
975 if (mouse_scroll_up
== NONE
) fputs("mouse_scroll_up = none\n", fp
);
976 else if (mouse_scroll_up
== CLOSE
) fputs("mouse_scroll_up = close\n", fp
);
977 else if (mouse_scroll_up
== TOGGLE
) fputs("mouse_scroll_up = toggle\n", fp
);
978 else if (mouse_scroll_up
== ICONIFY
) fputs("mouse_scroll_up = iconify\n", fp
);
979 else if (mouse_scroll_up
== SHADE
) fputs("mouse_scroll_up = shade\n", fp
);
980 else fputs("mouse_scroll_up = toggle_iconify\n", fp
);
982 if (mouse_scroll_down
== NONE
) fputs("mouse_scroll_down = none\n", fp
);
983 else if (mouse_scroll_down
== CLOSE
) fputs("mouse_scroll_down = close\n", fp
);
984 else if (mouse_scroll_down
== TOGGLE
) fputs("mouse_scroll_down = toggle\n", fp
);
985 else if (mouse_scroll_down
== ICONIFY
) fputs("mouse_scroll_down = iconify\n", fp
);
986 else if (mouse_scroll_down
== SHADE
) fputs("mouse_scroll_down = shade\n", fp
);
987 else fputs("mouse_scroll_down = toggle_iconify\n", fp
);
This page took 0.087964 seconds and 4 git commands to generate.