]>
Dogcows Code - chaz/tint2/blob - src/config.c
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 // --------------------------------------------------
53 // backward compatibility
54 static int save_file_config
;
55 static int old_task_icon_size
;
56 static char *old_task_font
;
57 static char *old_time1_font
;
58 static char *old_time2_font
;
59 static Area
*area_task
, *area_task_active
;
62 static char *old_bat1_font
;
63 static char *old_bat2_font
;
67 static Panel
*panel_config
= 0;
69 // temporary list of background
70 static GSList
*list_back
;
77 // get monitor and desktop config
78 get_monitors_and_desktops();
80 // append full transparency background
81 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
83 panel_config
= calloc(1, sizeof(Panel
));
84 // window manager's menu default value == false
95 // cleanup background list
97 for (l0
= list_back
; l0
; l0
= l0
->next
) {
100 g_slist_free(list_back
);
105 void copy_file(const char *pathSrc
, const char *pathDest
)
107 FILE *fileSrc
, *fileDest
;
111 fileSrc
= fopen(pathSrc
, "rb");
112 if (fileSrc
== NULL
) return;
114 fileDest
= fopen(pathDest
, "wb");
115 if (fileDest
== NULL
) return;
117 while ((nb
= fread(line
, 1, 100, fileSrc
)) > 0) fwrite(line
, 1, nb
, fileDest
);
124 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
128 if (*value1
) free (*value1
);
129 if (*value2
) free (*value2
);
130 if (*value3
) free (*value3
);
132 if ((b
= strchr (value
, ' '))) {
140 *value1
= strdup (value
);
144 if ((c
= strchr (b
, ' '))) {
152 *value2
= strdup (b
);
157 *value3
= strdup (c
);
163 int hex_char_to_int (char c
)
167 if (c
>= '0' && c
<= '9') r
= c
- '0';
168 else if (c
>= 'a' && c
<= 'f') r
= c
- 'a' + 10;
169 else if (c
>= 'A' && c
<= 'F') r
= c
- 'A' + 10;
176 int hex_to_rgb (char *hex
, int *r
, int *g
, int *b
)
180 if (hex
== NULL
|| hex
[0] != '#') return (0);
184 *r
= hex_char_to_int (hex
[1]);
185 *g
= hex_char_to_int (hex
[2]);
186 *b
= hex_char_to_int (hex
[3]);
188 else if (len
== 6 + 1) {
189 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
190 *g
= hex_char_to_int (hex
[3]) * 16 + hex_char_to_int (hex
[4]);
191 *b
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
193 else if (len
== 12 + 1) {
194 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
195 *g
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
196 *b
= hex_char_to_int (hex
[9]) * 16 + hex_char_to_int (hex
[10]);
204 void get_color (char *hex
, double *rgb
)
207 hex_to_rgb (hex
, &r
, &g
, &b
);
209 rgb
[0] = (r
/ 255.0);
210 rgb
[1] = (g
/ 255.0);
211 rgb
[2] = (b
/ 255.0);
215 void get_action (char *event
, int *action
)
217 if (strcmp (event
, "none") == 0)
219 else if (strcmp (event
, "close") == 0)
221 else if (strcmp (event
, "toggle") == 0)
223 else if (strcmp (event
, "iconify") == 0)
225 else if (strcmp (event
, "shade") == 0)
227 else if (strcmp (event
, "toggle_iconify") == 0)
228 *action
= TOGGLE_ICONIFY
;
232 void add_entry (char *key
, char *value
)
234 char *value1
=0, *value2
=0, *value3
=0;
236 /* Background and border */
237 if (strcmp (key
, "rounded") == 0) {
238 // 'rounded' is the first parameter => alloc a new background
239 Area
*a
= calloc(1, sizeof(Area
));
240 a
->pix
.border
.rounded
= atoi (value
);
241 list_back
= g_slist_append(list_back
, a
);
243 else if (strcmp (key
, "border_width") == 0) {
244 Area
*a
= g_slist_last(list_back
)->data
;
245 a
->pix
.border
.width
= atoi (value
);
247 else if (strcmp (key
, "background_color") == 0) {
248 Area
*a
= g_slist_last(list_back
)->data
;
249 extract_values(value
, &value1
, &value2
, &value3
);
250 get_color (value1
, a
->pix
.back
.color
);
251 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
252 else a
->pix
.back
.alpha
= 0.5;
254 else if (strcmp (key
, "border_color") == 0) {
255 Area
*a
= g_slist_last(list_back
)->data
;
256 extract_values(value
, &value1
, &value2
, &value3
);
257 get_color (value1
, a
->pix
.border
.color
);
258 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
259 else a
->pix
.border
.alpha
= 0.5;
263 else if (strcmp (key
, "panel_monitor") == 0) {
264 if (strcmp (value
, "all") == 0) panel_config
->monitor
= -1;
266 panel_config
->monitor
= atoi (value
);
267 if (panel_config
->monitor
> 0) panel_config
->monitor
-= 1;
270 else if (strcmp (key
, "panel_size") == 0) {
271 extract_values(value
, &value1
, &value2
, &value3
);
274 if ((b
= strchr (value1
, '%'))) {
276 panel_config
->pourcentx
= 1;
278 panel_config
->initial_width
= atof(value1
);
280 if ((b
= strchr (value2
, '%'))) {
282 panel_config
->pourcenty
= 1;
284 panel_config
->initial_height
= atof(value2
);
287 else if (strcmp (key
, "panel_margin") == 0) {
288 extract_values(value
, &value1
, &value2
, &value3
);
289 panel_config
->marginx
= atoi (value1
);
290 if (value2
) panel_config
->marginy
= atoi (value2
);
292 else if (strcmp (key
, "panel_padding") == 0) {
293 extract_values(value
, &value1
, &value2
, &value3
);
294 panel_config
->area
.paddingxlr
= panel_config
->area
.paddingx
= atoi (value1
);
295 if (value2
) panel_config
->area
.paddingy
= atoi (value2
);
296 if (value3
) panel_config
->area
.paddingx
= atoi (value3
);
298 else if (strcmp (key
, "panel_position") == 0) {
299 extract_values(value
, &value1
, &value2
, &value3
);
300 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
302 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
303 else panel_position
= CENTER
;
306 if (!value2
) panel_position
|= CENTER
;
308 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
310 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
311 else panel_position
|= CENTER
;
314 if (!value3
) panel_horizontal
= 1;
316 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
317 else panel_horizontal
= 1;
320 else if (strcmp (key
, "font_shadow") == 0)
321 panel_config
->g_task
.font_shadow
= atoi (value
);
322 else if (strcmp (key
, "panel_background_id") == 0) {
323 int id
= atoi (value
);
324 Area
*a
= g_slist_nth_data(list_back
, id
);
325 memcpy(&panel_config
->area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
326 memcpy(&panel_config
->area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
328 else if (strcmp (key
, "wm_menu") == 0)
329 wm_menu
= atoi (value
);
330 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
331 max_tick_urgent
= (atoi (value
) * 2) + 1;
334 else if (strcmp (key
, "battery") == 0) {
335 #ifdef ENABLE_BATTERY
337 panel_config
->battery
.area
.on_screen
= 1;
340 printf("tint2 is build without battery support\n");
343 else if (strcmp (key
, "battery_low_status") == 0) {
344 #ifdef ENABLE_BATTERY
345 battery_low_status
= atoi(value
);
346 if(battery_low_status
< 0 || battery_low_status
> 100)
347 battery_low_status
= 0;
350 else if (strcmp (key
, "battery_low_cmd") == 0) {
351 #ifdef ENABLE_BATTERY
352 if (battery_low_cmd
) g_free(battery_low_cmd
);
353 if (strlen(value
) > 0) battery_low_cmd
= strdup (value
);
354 else battery_low_cmd
= 0;
357 else if (strcmp (key
, "bat1_font") == 0) {
358 #ifdef ENABLE_BATTERY
359 if (save_file_config
) old_bat1_font
= strdup (value
);
360 if (bat1_font_desc
) pango_font_description_free(bat1_font_desc
);
361 bat1_font_desc
= pango_font_description_from_string (value
);
364 else if (strcmp (key
, "bat2_font") == 0) {
365 #ifdef ENABLE_BATTERY
366 if (save_file_config
) old_bat2_font
= strdup (value
);
367 if (bat2_font_desc
) pango_font_description_free(bat2_font_desc
);
368 bat2_font_desc
= pango_font_description_from_string (value
);
371 else if (strcmp (key
, "battery_font_color") == 0) {
372 #ifdef ENABLE_BATTERY
373 extract_values(value
, &value1
, &value2
, &value3
);
374 get_color (value1
, panel_config
->battery
.font
.color
);
375 if (value2
) panel_config
->battery
.font
.alpha
= (atoi (value2
) / 100.0);
376 else panel_config
->battery
.font
.alpha
= 0.5;
379 else if (strcmp (key
, "battery_padding") == 0) {
380 #ifdef ENABLE_BATTERY
381 extract_values(value
, &value1
, &value2
, &value3
);
382 panel_config
->battery
.area
.paddingxlr
= panel_config
->battery
.area
.paddingx
= atoi (value1
);
383 if (value2
) panel_config
->battery
.area
.paddingy
= atoi (value2
);
384 if (value3
) panel_config
->battery
.area
.paddingx
= atoi (value3
);
387 else if (strcmp (key
, "battery_background_id") == 0) {
388 #ifdef ENABLE_BATTERY
389 int id
= atoi (value
);
390 Area
*a
= g_slist_nth_data(list_back
, id
);
391 memcpy(&panel_config
->battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
392 memcpy(&panel_config
->battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
397 else if (strcmp (key
, "time1_format") == 0) {
398 if (time1_format
) g_free(time1_format
);
399 if (strlen(value
) > 0) {
400 time1_format
= strdup (value
);
401 panel_config
->clock
.area
.on_screen
= 1;
405 panel_config
->clock
.area
.on_screen
= 0;
408 else if (strcmp (key
, "time2_format") == 0) {
409 if (time2_format
) g_free(time2_format
);
410 if (strlen(value
) > 0) time2_format
= strdup (value
);
411 else time2_format
= 0;
413 else if (strcmp (key
, "time1_font") == 0) {
414 if (save_file_config
) old_time1_font
= strdup (value
);
415 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
416 time1_font_desc
= pango_font_description_from_string (value
);
418 else if (strcmp (key
, "time2_font") == 0) {
419 if (save_file_config
) old_time2_font
= strdup (value
);
420 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
421 time2_font_desc
= pango_font_description_from_string (value
);
423 else if (strcmp (key
, "clock_font_color") == 0) {
424 extract_values(value
, &value1
, &value2
, &value3
);
425 get_color (value1
, panel_config
->clock
.font
.color
);
426 if (value2
) panel_config
->clock
.font
.alpha
= (atoi (value2
) / 100.0);
427 else panel_config
->clock
.font
.alpha
= 0.5;
429 else if (strcmp (key
, "clock_padding") == 0) {
430 extract_values(value
, &value1
, &value2
, &value3
);
431 panel_config
->clock
.area
.paddingxlr
= panel_config
->clock
.area
.paddingx
= atoi (value1
);
432 if (value2
) panel_config
->clock
.area
.paddingy
= atoi (value2
);
433 if (value3
) panel_config
->clock
.area
.paddingx
= atoi (value3
);
435 else if (strcmp (key
, "clock_background_id") == 0) {
436 int id
= atoi (value
);
437 Area
*a
= g_slist_nth_data(list_back
, id
);
438 memcpy(&panel_config
->clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
439 memcpy(&panel_config
->clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
441 else if (strcmp(key
, "clock_lclick_command") == 0) {
442 if (clock_lclick_command
) g_free(clock_lclick_command
);
443 if (strlen(value
) > 0) clock_lclick_command
= strdup(value
);
444 else clock_lclick_command
= 0;
446 else if (strcmp(key
, "clock_rclick_command") == 0) {
447 if (clock_rclick_command
) g_free(clock_rclick_command
);
448 if (strlen(value
) > 0) clock_rclick_command
= strdup(value
);
449 else clock_rclick_command
= 0;
453 else if (strcmp (key
, "taskbar_mode") == 0) {
454 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
455 else panel_mode
= SINGLE_DESKTOP
;
457 else if (strcmp (key
, "taskbar_padding") == 0) {
458 extract_values(value
, &value1
, &value2
, &value3
);
459 panel_config
->g_taskbar
.paddingxlr
= panel_config
->g_taskbar
.paddingx
= atoi (value1
);
460 if (value2
) panel_config
->g_taskbar
.paddingy
= atoi (value2
);
461 if (value3
) panel_config
->g_taskbar
.paddingx
= atoi (value3
);
463 else if (strcmp (key
, "taskbar_background_id") == 0) {
464 int id
= atoi (value
);
465 Area
*a
= g_slist_nth_data(list_back
, id
);
466 memcpy(&panel_config
->g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
467 memcpy(&panel_config
->g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
471 else if (strcmp (key
, "task_text") == 0)
472 panel_config
->g_task
.text
= atoi (value
);
473 else if (strcmp (key
, "task_icon") == 0)
474 panel_config
->g_task
.icon
= atoi (value
);
475 else if (strcmp (key
, "task_centered") == 0)
476 panel_config
->g_task
.centered
= atoi (value
);
477 else if (strcmp (key
, "task_width") == 0) {
478 // old parameter : just for backward compatibility
479 panel_config
->g_task
.maximum_width
= atoi (value
);
480 panel_config
->g_task
.maximum_height
= 30;
482 else if (strcmp (key
, "task_maximum_size") == 0) {
483 extract_values(value
, &value1
, &value2
, &value3
);
484 panel_config
->g_task
.maximum_width
= atoi (value1
);
485 panel_config
->g_task
.maximum_height
= 30;
487 panel_config
->g_task
.maximum_height
= atoi (value2
);
489 else if (strcmp (key
, "task_padding") == 0) {
490 extract_values(value
, &value1
, &value2
, &value3
);
491 panel_config
->g_task
.area
.paddingxlr
= panel_config
->g_task
.area
.paddingx
= atoi (value1
);
492 if (value2
) panel_config
->g_task
.area
.paddingy
= atoi (value2
);
493 if (value3
) panel_config
->g_task
.area
.paddingx
= atoi (value3
);
495 else if (strcmp (key
, "task_font") == 0) {
496 if (save_file_config
) old_task_font
= strdup (value
);
497 if (panel_config
->g_task
.font_desc
) pango_font_description_free(panel_config
->g_task
.font_desc
);
498 panel_config
->g_task
.font_desc
= pango_font_description_from_string (value
);
500 else if (strcmp (key
, "task_font_color") == 0) {
501 extract_values(value
, &value1
, &value2
, &value3
);
502 get_color (value1
, panel_config
->g_task
.font
.color
);
503 if (value2
) panel_config
->g_task
.font
.alpha
= (atoi (value2
) / 100.0);
504 else panel_config
->g_task
.font
.alpha
= 0.1;
506 else if (strcmp (key
, "task_active_font_color") == 0) {
507 extract_values(value
, &value1
, &value2
, &value3
);
508 get_color (value1
, panel_config
->g_task
.font_active
.color
);
509 if (value2
) panel_config
->g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
510 else panel_config
->g_task
.font_active
.alpha
= 0.1;
512 else if (strcmp (key
, "task_background_id") == 0) {
513 int id
= atoi (value
);
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 Area
*a
= g_slist_nth_data(list_back
, id
);
521 memcpy(&panel_config
->g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
522 memcpy(&panel_config
->g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
526 else if (strcmp (key
, "systray_padding") == 0) {
527 extract_values(value
, &value1
, &value2
, &value3
);
528 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
529 if (value2
) systray
.area
.paddingy
= atoi (value2
);
530 if (value3
) systray
.area
.paddingx
= atoi (value3
);
531 systray
.area
.on_screen
= 1;
533 else if (strcmp (key
, "systray_background_id") == 0) {
534 int id
= atoi (value
);
535 Area
*a
= g_slist_nth_data(list_back
, id
);
536 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
537 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
541 else if (strcmp (key
, "mouse_middle") == 0)
542 get_action (value
, &mouse_middle
);
543 else if (strcmp (key
, "mouse_right") == 0)
544 get_action (value
, &mouse_right
);
545 else if (strcmp (key
, "mouse_scroll_up") == 0)
546 get_action (value
, &mouse_scroll_up
);
547 else if (strcmp (key
, "mouse_scroll_down") == 0)
548 get_action (value
, &mouse_scroll_down
);
551 /* Read tint-0.6 config for backward compatibility */
552 else if (strcmp (key
, "panel_mode") == 0) {
553 save_file_config
= 1;
554 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
555 else panel_mode
= MULTI_DESKTOP
;
557 else if (strcmp (key
, "panel_rounded") == 0) {
558 Area
*a
= calloc(1, sizeof(Area
));
559 a
->pix
.border
.rounded
= atoi (value
);
560 list_back
= g_slist_append(list_back
, a
);
562 else if (strcmp (key
, "panel_border_width") == 0) {
563 Area
*a
= g_slist_last(list_back
)->data
;
564 a
->pix
.border
.width
= atoi (value
);
566 else if (strcmp (key
, "panel_background_color") == 0) {
567 Area
*a
= g_slist_last(list_back
)->data
;
568 extract_values(value
, &value1
, &value2
, &value3
);
569 get_color (value1
, a
->pix
.back
.color
);
570 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
571 else a
->pix
.back
.alpha
= 0.5;
573 else if (strcmp (key
, "panel_border_color") == 0) {
574 Area
*a
= g_slist_last(list_back
)->data
;
575 extract_values(value
, &value1
, &value2
, &value3
);
576 get_color (value1
, a
->pix
.border
.color
);
577 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
578 else a
->pix
.border
.alpha
= 0.5;
580 else if (strcmp (key
, "task_text_centered") == 0)
581 panel_config
->g_task
.centered
= atoi (value
);
582 else if (strcmp (key
, "task_margin") == 0) {
583 panel_config
->g_taskbar
.paddingxlr
= 0;
584 panel_config
->g_taskbar
.paddingx
= atoi (value
);
586 else if (strcmp (key
, "task_icon_size") == 0)
587 old_task_icon_size
= atoi (value
);
588 else if (strcmp (key
, "task_rounded") == 0) {
589 area_task
= calloc(1, sizeof(Area
));
590 area_task
->pix
.border
.rounded
= atoi (value
);
591 list_back
= g_slist_append(list_back
, area_task
);
593 area_task_active
= calloc(1, sizeof(Area
));
594 area_task_active
->pix
.border
.rounded
= atoi (value
);
595 list_back
= g_slist_append(list_back
, area_task_active
);
597 else if (strcmp (key
, "task_background_color") == 0) {
598 extract_values(value
, &value1
, &value2
, &value3
);
599 get_color (value1
, area_task
->pix
.back
.color
);
600 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
601 else area_task
->pix
.back
.alpha
= 0.5;
603 else if (strcmp (key
, "task_active_background_color") == 0) {
604 extract_values(value
, &value1
, &value2
, &value3
);
605 get_color (value1
, area_task_active
->pix
.back
.color
);
606 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
607 else area_task_active
->pix
.back
.alpha
= 0.5;
609 else if (strcmp (key
, "task_border_width") == 0) {
610 area_task
->pix
.border
.width
= atoi (value
);
611 area_task_active
->pix
.border
.width
= atoi (value
);
613 else if (strcmp (key
, "task_border_color") == 0) {
614 extract_values(value
, &value1
, &value2
, &value3
);
615 get_color (value1
, area_task
->pix
.border
.color
);
616 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
617 else area_task
->pix
.border
.alpha
= 0.5;
619 else if (strcmp (key
, "task_active_border_color") == 0) {
620 extract_values(value
, &value1
, &value2
, &value3
);
621 get_color (value1
, area_task_active
->pix
.border
.color
);
622 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
623 else area_task_active
->pix
.border
.alpha
= 0.5;
627 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
629 if (value1
) free (value1
);
630 if (value2
) free (value2
);
631 if (value3
) free (value3
);
635 int parse_line (const char *line
)
637 char *a
, *b
, *key
, *value
;
639 /* Skip useless lines */
640 if ((line
[0] == '#') || (line
[0] == '\n')) return 0;
641 if (!(a
= strchr (line
, '='))) return 0;
643 /* overwrite '=' with '\0' */
648 /* overwrite '\n' with '\0' if '\n' present */
649 if ((b
= strchr (a
, '\n'))) b
[0] = '\0';
656 add_entry (key
, value
);
664 void config_finish ()
666 if (panel_config
->monitor
> (server
.nb_monitor
-1)) {
667 fprintf(stderr
, "tint2 exit : monitor %d not found.\n", panel_config
->monitor
+1);
673 if (panel_config
->monitor
>= 0) {
676 panel1
= calloc(nb_panel
, sizeof(Panel
));
677 memcpy(panel1
, panel_config
, sizeof(Panel
));
678 panel1
->monitor
= panel_config
->monitor
;
682 nb_panel
= server
.nb_monitor
;
683 panel1
= calloc(nb_panel
, sizeof(Panel
));
685 for (i
=0 ; i
< nb_panel
; i
++) {
686 memcpy(&panel1
[i
], panel_config
, sizeof(Panel
));
687 panel1
[i
].monitor
= i
;
691 // TODO: user can configure layout => ordered objects in panel.area.list
692 // clock and systray before taskbar because resize(clock) can resize others object ??
695 #ifdef ENABLE_BATTERY
704 task_refresh_tasklist();
710 const gchar
* const * system_dirs
;
714 save_file_config
= 0;
716 // follow XDG specification
718 // check tint2rc in user directory
719 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
720 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
721 i
= config_read_file (path1
);
727 if (save_file_config
) {
728 fprintf(stderr
, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
732 // check old tintrc config file
733 path1
= g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL
);
734 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
735 save_file_config
= 1;
736 config_read_file (path1
);
741 // copy tint2rc from system directory to user directory
744 system_dirs
= g_get_system_config_dirs();
745 for (i
= 0; system_dirs
[i
]; i
++) {
746 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
748 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
754 // copy file in user directory (path1)
755 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
756 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
759 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
760 copy_file(path2
, path1
);
763 i
= config_read_file (path1
);
771 int config_read_file (const char *path
)
776 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
781 while (fgets(line
, sizeof(line
), fp
) != NULL
)
786 if (save_file_config
)
790 g_free(old_task_font
);
793 if (old_time1_font
) {
794 g_free(old_time1_font
);
797 if (old_time2_font
) {
798 g_free(old_time2_font
);
807 fprintf(stderr
, "tint2 : convert user's config file\n");
812 if (old_task_icon_size
) {
813 panel_config
->g_task
.area
.paddingy
= ((int)panel_config
->initial_height
- (2 * panel_config
->area
.paddingy
) - old_task_icon_size
) / 2;
816 dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
817 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
820 path
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
821 fp
= fopen(path
, "w");
823 if (fp
== NULL
) return;
825 fputs("#---------------------------------------------\n", fp
);
826 fputs("# TINT2 CONFIG FILE\n", fp
);
827 fputs("#---------------------------------------------\n\n", fp
);
828 fputs("#---------------------------------------------\n", fp
);
829 fputs("# BACKGROUND AND BORDER\n", fp
);
830 fputs("#---------------------------------------------\n", fp
);
833 l0
= list_back
->next
;
836 fprintf(fp
, "rounded = %d\n", a
->pix
.border
.rounded
);
837 fprintf(fp
, "border_width = %d\n", a
->pix
.border
.width
);
838 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));
839 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));
844 fputs("#---------------------------------------------\n", fp
);
845 fputs("# PANEL\n", fp
);
846 fputs("#---------------------------------------------\n", fp
);
847 fputs("panel_monitor = all\n", fp
);
848 if (panel_position
& BOTTOM
) fputs("panel_position = bottom", fp
);
849 else fputs("panel_position = top", fp
);
850 if (panel_position
& LEFT
) fputs(" left horizontal\n", fp
);
851 else if (panel_position
& RIGHT
) fputs(" right horizontal\n", fp
);
852 else fputs(" center horizontal\n", fp
);
853 fprintf(fp
, "panel_size = %d %d\n", (int)panel_config
->initial_width
, (int)panel_config
->initial_height
);
854 fprintf(fp
, "panel_margin = %d %d\n", panel_config
->marginx
, panel_config
->marginy
);
855 fprintf(fp
, "panel_padding = %d %d %d\n", panel_config
->area
.paddingxlr
, panel_config
->area
.paddingy
, panel_config
->area
.paddingx
);
856 fprintf(fp
, "font_shadow = %d\n", panel_config
->g_task
.font_shadow
);
857 fputs("panel_background_id = 1\n", fp
);
858 fputs("wm_menu = 0\n", fp
);
860 fputs("\n#---------------------------------------------\n", fp
);
861 fputs("# TASKBAR\n", fp
);
862 fputs("#---------------------------------------------\n", fp
);
863 if (panel_mode
== MULTI_DESKTOP
) fputs("taskbar_mode = multi_desktop\n", fp
);
864 else fputs("taskbar_mode = single_desktop\n", fp
);
865 fprintf(fp
, "taskbar_padding = 0 0 %d\n", panel_config
->g_taskbar
.paddingx
);
866 fputs("taskbar_background_id = 0\n", fp
);
868 fputs("\n#---------------------------------------------\n", fp
);
869 fputs("# TASK\n", fp
);
870 fputs("#---------------------------------------------\n", fp
);
871 if (old_task_icon_size
) fputs("task_icon = 1\n", fp
);
872 else fputs("task_icon = 0\n", fp
);
873 fputs("task_text = 1\n", fp
);
874 fprintf(fp
, "task_maximum_size = %d %d\n", panel_config
->g_task
.maximum_width
, panel_config
->g_task
.maximum_height
);
875 fprintf(fp
, "task_centered = %d\n", panel_config
->g_task
.centered
);
876 fprintf(fp
, "task_padding = %d %d\n", panel_config
->g_task
.area
.paddingx
, panel_config
->g_task
.area
.paddingy
);
877 fprintf(fp
, "task_font = %s\n", old_task_font
);
878 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));
879 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));
880 fputs("task_background_id = 2\n", fp
);
881 fputs("task_active_background_id = 3\n", fp
);
883 fputs("\n#---------------------------------------------\n", fp
);
884 fputs("# SYSTRAYBAR\n", fp
);
885 fputs("#---------------------------------------------\n", fp
);
886 fputs("systray_padding = 4 3 4\n", fp
);
887 fputs("systray_background_id = 0\n", fp
);
889 fputs("\n#---------------------------------------------\n", fp
);
890 fputs("# CLOCK\n", fp
);
891 fputs("#---------------------------------------------\n", fp
);
892 if (time1_format
) fprintf(fp
, "time1_format = %s\n", time1_format
);
893 else fputs("#time1_format = %H:%M\n", fp
);
894 fprintf(fp
, "time1_font = %s\n", old_time1_font
);
895 if (time2_format
) fprintf(fp
, "time2_format = %s\n", time2_format
);
896 else fputs("#time2_format = %A %d %B\n", fp
);
897 fprintf(fp
, "time2_font = %s\n", old_time2_font
);
898 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));
899 fputs("clock_padding = 2 2\n", fp
);
900 fputs("clock_background_id = 0\n", fp
);
901 fputs("#clock_lclick_command = xclock\n", fp
);
902 fputs("clock_rclick_command = orage\n", fp
);
904 #ifdef ENABLE_BATTERY
905 fputs("\n#---------------------------------------------\n", fp
);
906 fputs("# BATTERY\n", fp
);
907 fputs("#---------------------------------------------\n", fp
);
908 fprintf(fp
, "battery = %d\n", panel_config
->battery
.area
.on_screen
);
909 fprintf(fp
, "battery_low_status = %d\n", battery_low_status
);
910 fprintf(fp
, "battery_low_cmd = %s\n", battery_low_cmd
);
911 fprintf(fp
, "bat1_font = %s\n", old_bat1_font
);
912 fprintf(fp
, "bat2_font = %s\n", old_bat2_font
);
913 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));
914 fputs("battery_padding = 2 2\n", fp
);
915 fputs("battery_background_id = 0\n", fp
);
918 fputs("\n#---------------------------------------------\n", fp
);
919 fputs("# MOUSE ACTION ON TASK\n", fp
);
920 fputs("#---------------------------------------------\n", fp
);
921 if (mouse_middle
== NONE
) fputs("mouse_middle = none\n", fp
);
922 else if (mouse_middle
== CLOSE
) fputs("mouse_middle = close\n", fp
);
923 else if (mouse_middle
== TOGGLE
) fputs("mouse_middle = toggle\n", fp
);
924 else if (mouse_middle
== ICONIFY
) fputs("mouse_middle = iconify\n", fp
);
925 else if (mouse_middle
== SHADE
) fputs("mouse_middle = shade\n", fp
);
926 else fputs("mouse_middle = toggle_iconify\n", fp
);
928 if (mouse_right
== NONE
) fputs("mouse_right = none\n", fp
);
929 else if (mouse_right
== CLOSE
) fputs("mouse_right = close\n", fp
);
930 else if (mouse_right
== TOGGLE
) fputs("mouse_right = toggle\n", fp
);
931 else if (mouse_right
== ICONIFY
) fputs("mouse_right = iconify\n", fp
);
932 else if (mouse_right
== SHADE
) fputs("mouse_right = shade\n", fp
);
933 else fputs("mouse_right = toggle_iconify\n", fp
);
935 if (mouse_scroll_up
== NONE
) fputs("mouse_scroll_up = none\n", fp
);
936 else if (mouse_scroll_up
== CLOSE
) fputs("mouse_scroll_up = close\n", fp
);
937 else if (mouse_scroll_up
== TOGGLE
) fputs("mouse_scroll_up = toggle\n", fp
);
938 else if (mouse_scroll_up
== ICONIFY
) fputs("mouse_scroll_up = iconify\n", fp
);
939 else if (mouse_scroll_up
== SHADE
) fputs("mouse_scroll_up = shade\n", fp
);
940 else fputs("mouse_scroll_up = toggle_iconify\n", fp
);
942 if (mouse_scroll_down
== NONE
) fputs("mouse_scroll_down = none\n", fp
);
943 else if (mouse_scroll_down
== CLOSE
) fputs("mouse_scroll_down = close\n", fp
);
944 else if (mouse_scroll_down
== TOGGLE
) fputs("mouse_scroll_down = toggle\n", fp
);
945 else if (mouse_scroll_down
== ICONIFY
) fputs("mouse_scroll_down = iconify\n", fp
);
946 else if (mouse_scroll_down
== SHADE
) fputs("mouse_scroll_down = shade\n", fp
);
947 else fputs("mouse_scroll_down = toggle_iconify\n", fp
);
This page took 0.085268 seconds and 4 git commands to generate.