]>
Dogcows Code - chaz/tint2/blob - src/config.c
a2d6fa83dbc4301b1443ac2a87f98830303fd607
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
;
229 else if (strcmp (event
, "maximize_restore") == 0)
230 *action
= MAXIMIZE_RESTORE
;
231 else if (strcmp (event
, "desktop_left") == 0)
232 *action
= DESKTOP_LEFT
;
233 else if (strcmp (event
, "desktop_right") == 0)
234 *action
= DESKTOP_RIGHT
;
238 void add_entry (char *key
, char *value
)
240 char *value1
=0, *value2
=0, *value3
=0;
242 /* Background and border */
243 if (strcmp (key
, "rounded") == 0) {
244 // 'rounded' is the first parameter => alloc a new background
245 Area
*a
= calloc(1, sizeof(Area
));
246 a
->pix
.border
.rounded
= atoi (value
);
247 list_back
= g_slist_append(list_back
, a
);
249 else if (strcmp (key
, "border_width") == 0) {
250 Area
*a
= g_slist_last(list_back
)->data
;
251 a
->pix
.border
.width
= atoi (value
);
253 else if (strcmp (key
, "background_color") == 0) {
254 Area
*a
= g_slist_last(list_back
)->data
;
255 extract_values(value
, &value1
, &value2
, &value3
);
256 get_color (value1
, a
->pix
.back
.color
);
257 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
258 else a
->pix
.back
.alpha
= 0.5;
260 else if (strcmp (key
, "border_color") == 0) {
261 Area
*a
= g_slist_last(list_back
)->data
;
262 extract_values(value
, &value1
, &value2
, &value3
);
263 get_color (value1
, a
->pix
.border
.color
);
264 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
265 else a
->pix
.border
.alpha
= 0.5;
269 else if (strcmp (key
, "panel_monitor") == 0) {
270 if (strcmp (value
, "all") == 0) panel_config
->monitor
= -1;
272 panel_config
->monitor
= atoi (value
);
273 if (panel_config
->monitor
> 0) panel_config
->monitor
-= 1;
276 else if (strcmp (key
, "panel_size") == 0) {
277 extract_values(value
, &value1
, &value2
, &value3
);
280 if ((b
= strchr (value1
, '%'))) {
282 panel_config
->pourcentx
= 1;
284 panel_config
->initial_width
= atof(value1
);
286 if ((b
= strchr (value2
, '%'))) {
288 panel_config
->pourcenty
= 1;
290 panel_config
->initial_height
= atof(value2
);
293 else if (strcmp (key
, "panel_margin") == 0) {
294 extract_values(value
, &value1
, &value2
, &value3
);
295 panel_config
->marginx
= atoi (value1
);
296 if (value2
) panel_config
->marginy
= atoi (value2
);
298 else if (strcmp (key
, "panel_padding") == 0) {
299 extract_values(value
, &value1
, &value2
, &value3
);
300 panel_config
->area
.paddingxlr
= panel_config
->area
.paddingx
= atoi (value1
);
301 if (value2
) panel_config
->area
.paddingy
= atoi (value2
);
302 if (value3
) panel_config
->area
.paddingx
= atoi (value3
);
304 else if (strcmp (key
, "panel_position") == 0) {
305 extract_values(value
, &value1
, &value2
, &value3
);
306 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
308 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
309 else panel_position
= CENTER
;
312 if (!value2
) panel_position
|= CENTER
;
314 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
316 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
317 else panel_position
|= CENTER
;
320 if (!value3
) panel_horizontal
= 1;
322 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
323 else panel_horizontal
= 1;
326 else if (strcmp (key
, "font_shadow") == 0)
327 panel_config
->g_task
.font_shadow
= atoi (value
);
328 else if (strcmp (key
, "panel_background_id") == 0) {
329 int id
= atoi (value
);
330 Area
*a
= g_slist_nth_data(list_back
, id
);
331 memcpy(&panel_config
->area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
332 memcpy(&panel_config
->area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
334 else if (strcmp (key
, "wm_menu") == 0)
335 wm_menu
= atoi (value
);
336 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
337 max_tick_urgent
= (atoi (value
) * 2) + 1;
340 else if (strcmp (key
, "battery") == 0) {
341 #ifdef ENABLE_BATTERY
343 panel_config
->battery
.area
.on_screen
= 1;
346 printf("tint2 is build without battery support\n");
349 else if (strcmp (key
, "battery_low_status") == 0) {
350 #ifdef ENABLE_BATTERY
351 battery_low_status
= atoi(value
);
352 if(battery_low_status
< 0 || battery_low_status
> 100)
353 battery_low_status
= 0;
356 else if (strcmp (key
, "battery_low_cmd") == 0) {
357 #ifdef ENABLE_BATTERY
358 if (battery_low_cmd
) g_free(battery_low_cmd
);
359 if (strlen(value
) > 0) battery_low_cmd
= strdup (value
);
360 else battery_low_cmd
= 0;
363 else if (strcmp (key
, "bat1_font") == 0) {
364 #ifdef ENABLE_BATTERY
365 if (save_file_config
) old_bat1_font
= strdup (value
);
366 if (bat1_font_desc
) pango_font_description_free(bat1_font_desc
);
367 bat1_font_desc
= pango_font_description_from_string (value
);
370 else if (strcmp (key
, "bat2_font") == 0) {
371 #ifdef ENABLE_BATTERY
372 if (save_file_config
) old_bat2_font
= strdup (value
);
373 if (bat2_font_desc
) pango_font_description_free(bat2_font_desc
);
374 bat2_font_desc
= pango_font_description_from_string (value
);
377 else if (strcmp (key
, "battery_font_color") == 0) {
378 #ifdef ENABLE_BATTERY
379 extract_values(value
, &value1
, &value2
, &value3
);
380 get_color (value1
, panel_config
->battery
.font
.color
);
381 if (value2
) panel_config
->battery
.font
.alpha
= (atoi (value2
) / 100.0);
382 else panel_config
->battery
.font
.alpha
= 0.5;
385 else if (strcmp (key
, "battery_padding") == 0) {
386 #ifdef ENABLE_BATTERY
387 extract_values(value
, &value1
, &value2
, &value3
);
388 panel_config
->battery
.area
.paddingxlr
= panel_config
->battery
.area
.paddingx
= atoi (value1
);
389 if (value2
) panel_config
->battery
.area
.paddingy
= atoi (value2
);
390 if (value3
) panel_config
->battery
.area
.paddingx
= atoi (value3
);
393 else if (strcmp (key
, "battery_background_id") == 0) {
394 #ifdef ENABLE_BATTERY
395 int id
= atoi (value
);
396 Area
*a
= g_slist_nth_data(list_back
, id
);
397 memcpy(&panel_config
->battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
398 memcpy(&panel_config
->battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
403 else if (strcmp (key
, "time1_format") == 0) {
404 if (time1_format
) g_free(time1_format
);
405 if (strlen(value
) > 0) {
406 time1_format
= strdup (value
);
407 panel_config
->clock
.area
.on_screen
= 1;
411 panel_config
->clock
.area
.on_screen
= 0;
414 else if (strcmp (key
, "time2_format") == 0) {
415 if (time2_format
) g_free(time2_format
);
416 if (strlen(value
) > 0) time2_format
= strdup (value
);
417 else time2_format
= 0;
419 else if (strcmp (key
, "time1_font") == 0) {
420 if (save_file_config
) old_time1_font
= strdup (value
);
421 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
422 time1_font_desc
= pango_font_description_from_string (value
);
424 else if (strcmp (key
, "time2_font") == 0) {
425 if (save_file_config
) old_time2_font
= strdup (value
);
426 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
427 time2_font_desc
= pango_font_description_from_string (value
);
429 else if (strcmp (key
, "clock_font_color") == 0) {
430 extract_values(value
, &value1
, &value2
, &value3
);
431 get_color (value1
, panel_config
->clock
.font
.color
);
432 if (value2
) panel_config
->clock
.font
.alpha
= (atoi (value2
) / 100.0);
433 else panel_config
->clock
.font
.alpha
= 0.5;
435 else if (strcmp (key
, "clock_padding") == 0) {
436 extract_values(value
, &value1
, &value2
, &value3
);
437 panel_config
->clock
.area
.paddingxlr
= panel_config
->clock
.area
.paddingx
= atoi (value1
);
438 if (value2
) panel_config
->clock
.area
.paddingy
= atoi (value2
);
439 if (value3
) panel_config
->clock
.area
.paddingx
= atoi (value3
);
441 else if (strcmp (key
, "clock_background_id") == 0) {
442 int id
= atoi (value
);
443 Area
*a
= g_slist_nth_data(list_back
, id
);
444 memcpy(&panel_config
->clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
445 memcpy(&panel_config
->clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
447 else if (strcmp(key
, "clock_lclick_command") == 0) {
448 if (clock_lclick_command
) g_free(clock_lclick_command
);
449 if (strlen(value
) > 0) clock_lclick_command
= strdup(value
);
450 else clock_lclick_command
= 0;
452 else if (strcmp(key
, "clock_rclick_command") == 0) {
453 if (clock_rclick_command
) g_free(clock_rclick_command
);
454 if (strlen(value
) > 0) clock_rclick_command
= strdup(value
);
455 else clock_rclick_command
= 0;
459 else if (strcmp (key
, "taskbar_mode") == 0) {
460 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
461 else panel_mode
= SINGLE_DESKTOP
;
463 else if (strcmp (key
, "taskbar_padding") == 0) {
464 extract_values(value
, &value1
, &value2
, &value3
);
465 panel_config
->g_taskbar
.paddingxlr
= panel_config
->g_taskbar
.paddingx
= atoi (value1
);
466 if (value2
) panel_config
->g_taskbar
.paddingy
= atoi (value2
);
467 if (value3
) panel_config
->g_taskbar
.paddingx
= atoi (value3
);
469 else if (strcmp (key
, "taskbar_background_id") == 0) {
470 int id
= atoi (value
);
471 Area
*a
= g_slist_nth_data(list_back
, id
);
472 memcpy(&panel_config
->g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
473 memcpy(&panel_config
->g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
477 else if (strcmp (key
, "task_text") == 0)
478 panel_config
->g_task
.text
= atoi (value
);
479 else if (strcmp (key
, "task_icon") == 0)
480 panel_config
->g_task
.icon
= atoi (value
);
481 else if (strcmp (key
, "task_centered") == 0)
482 panel_config
->g_task
.centered
= atoi (value
);
483 else if (strcmp (key
, "task_width") == 0) {
484 // old parameter : just for backward compatibility
485 panel_config
->g_task
.maximum_width
= atoi (value
);
486 panel_config
->g_task
.maximum_height
= 30;
488 else if (strcmp (key
, "task_maximum_size") == 0) {
489 extract_values(value
, &value1
, &value2
, &value3
);
490 panel_config
->g_task
.maximum_width
= atoi (value1
);
491 panel_config
->g_task
.maximum_height
= 30;
493 panel_config
->g_task
.maximum_height
= atoi (value2
);
495 else if (strcmp (key
, "task_padding") == 0) {
496 extract_values(value
, &value1
, &value2
, &value3
);
497 panel_config
->g_task
.area
.paddingxlr
= panel_config
->g_task
.area
.paddingx
= atoi (value1
);
498 if (value2
) panel_config
->g_task
.area
.paddingy
= atoi (value2
);
499 if (value3
) panel_config
->g_task
.area
.paddingx
= atoi (value3
);
501 else if (strcmp (key
, "task_font") == 0) {
502 if (save_file_config
) old_task_font
= strdup (value
);
503 if (panel_config
->g_task
.font_desc
) pango_font_description_free(panel_config
->g_task
.font_desc
);
504 panel_config
->g_task
.font_desc
= pango_font_description_from_string (value
);
506 else if (strcmp (key
, "task_font_color") == 0) {
507 extract_values(value
, &value1
, &value2
, &value3
);
508 get_color (value1
, panel_config
->g_task
.font
.color
);
509 if (value2
) panel_config
->g_task
.font
.alpha
= (atoi (value2
) / 100.0);
510 else panel_config
->g_task
.font
.alpha
= 0.1;
512 else if (strcmp (key
, "task_active_font_color") == 0) {
513 extract_values(value
, &value1
, &value2
, &value3
);
514 get_color (value1
, panel_config
->g_task
.font_active
.color
);
515 if (value2
) panel_config
->g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
516 else panel_config
->g_task
.font_active
.alpha
= 0.1;
518 else if (strcmp (key
, "task_icon_hsb") == 0) {
519 extract_values(value
, &value1
, &value2
, &value3
);
520 panel_config
->g_task
.hue
= atoi(value1
);
521 panel_config
->g_task
.saturation
= atoi(value2
);
522 panel_config
->g_task
.brightness
= atoi(value3
);
524 else if (strcmp (key
, "task_active_icon_hsb") == 0) {
525 extract_values(value
, &value1
, &value2
, &value3
);
526 panel_config
->g_task
.hue_active
= atoi(value1
);
527 panel_config
->g_task
.saturation_active
= atoi(value2
);
528 panel_config
->g_task
.brightness_active
= atoi(value3
);
530 else if (strcmp (key
, "task_background_id") == 0) {
531 int id
= atoi (value
);
532 Area
*a
= g_slist_nth_data(list_back
, id
);
533 memcpy(&panel_config
->g_task
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
534 memcpy(&panel_config
->g_task
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
536 else if (strcmp (key
, "task_active_background_id") == 0) {
537 int id
= atoi (value
);
538 Area
*a
= g_slist_nth_data(list_back
, id
);
539 memcpy(&panel_config
->g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
540 memcpy(&panel_config
->g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
544 else if (strcmp (key
, "systray_padding") == 0) {
545 extract_values(value
, &value1
, &value2
, &value3
);
546 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
547 if (value2
) systray
.area
.paddingy
= atoi (value2
);
548 if (value3
) systray
.area
.paddingx
= atoi (value3
);
549 systray
.area
.on_screen
= 1;
551 else if (strcmp (key
, "systray_background_id") == 0) {
552 int id
= atoi (value
);
553 Area
*a
= g_slist_nth_data(list_back
, id
);
554 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
555 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
559 else if (strcmp (key
, "mouse_middle") == 0)
560 get_action (value
, &mouse_middle
);
561 else if (strcmp (key
, "mouse_right") == 0)
562 get_action (value
, &mouse_right
);
563 else if (strcmp (key
, "mouse_scroll_up") == 0)
564 get_action (value
, &mouse_scroll_up
);
565 else if (strcmp (key
, "mouse_scroll_down") == 0)
566 get_action (value
, &mouse_scroll_down
);
569 /* Read tint-0.6 config for backward compatibility */
570 else if (strcmp (key
, "panel_mode") == 0) {
571 save_file_config
= 1;
572 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
573 else panel_mode
= MULTI_DESKTOP
;
575 else if (strcmp (key
, "panel_rounded") == 0) {
576 Area
*a
= calloc(1, sizeof(Area
));
577 a
->pix
.border
.rounded
= atoi (value
);
578 list_back
= g_slist_append(list_back
, a
);
580 else if (strcmp (key
, "panel_border_width") == 0) {
581 Area
*a
= g_slist_last(list_back
)->data
;
582 a
->pix
.border
.width
= atoi (value
);
584 else if (strcmp (key
, "panel_background_color") == 0) {
585 Area
*a
= g_slist_last(list_back
)->data
;
586 extract_values(value
, &value1
, &value2
, &value3
);
587 get_color (value1
, a
->pix
.back
.color
);
588 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
589 else a
->pix
.back
.alpha
= 0.5;
591 else if (strcmp (key
, "panel_border_color") == 0) {
592 Area
*a
= g_slist_last(list_back
)->data
;
593 extract_values(value
, &value1
, &value2
, &value3
);
594 get_color (value1
, a
->pix
.border
.color
);
595 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
596 else a
->pix
.border
.alpha
= 0.5;
598 else if (strcmp (key
, "task_text_centered") == 0)
599 panel_config
->g_task
.centered
= atoi (value
);
600 else if (strcmp (key
, "task_margin") == 0) {
601 panel_config
->g_taskbar
.paddingxlr
= 0;
602 panel_config
->g_taskbar
.paddingx
= atoi (value
);
604 else if (strcmp (key
, "task_icon_size") == 0)
605 old_task_icon_size
= atoi (value
);
606 else if (strcmp (key
, "task_rounded") == 0) {
607 area_task
= calloc(1, sizeof(Area
));
608 area_task
->pix
.border
.rounded
= atoi (value
);
609 list_back
= g_slist_append(list_back
, area_task
);
611 area_task_active
= calloc(1, sizeof(Area
));
612 area_task_active
->pix
.border
.rounded
= atoi (value
);
613 list_back
= g_slist_append(list_back
, area_task_active
);
615 else if (strcmp (key
, "task_background_color") == 0) {
616 extract_values(value
, &value1
, &value2
, &value3
);
617 get_color (value1
, area_task
->pix
.back
.color
);
618 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
619 else area_task
->pix
.back
.alpha
= 0.5;
621 else if (strcmp (key
, "task_active_background_color") == 0) {
622 extract_values(value
, &value1
, &value2
, &value3
);
623 get_color (value1
, area_task_active
->pix
.back
.color
);
624 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
625 else area_task_active
->pix
.back
.alpha
= 0.5;
627 else if (strcmp (key
, "task_border_width") == 0) {
628 area_task
->pix
.border
.width
= atoi (value
);
629 area_task_active
->pix
.border
.width
= atoi (value
);
631 else if (strcmp (key
, "task_border_color") == 0) {
632 extract_values(value
, &value1
, &value2
, &value3
);
633 get_color (value1
, area_task
->pix
.border
.color
);
634 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
635 else area_task
->pix
.border
.alpha
= 0.5;
637 else if (strcmp (key
, "task_active_border_color") == 0) {
638 extract_values(value
, &value1
, &value2
, &value3
);
639 get_color (value1
, area_task_active
->pix
.border
.color
);
640 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
641 else area_task_active
->pix
.border
.alpha
= 0.5;
645 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
647 if (value1
) free (value1
);
648 if (value2
) free (value2
);
649 if (value3
) free (value3
);
653 int parse_line (const char *line
)
655 char *a
, *b
, *key
, *value
;
657 /* Skip useless lines */
658 if ((line
[0] == '#') || (line
[0] == '\n')) return 0;
659 if (!(a
= strchr (line
, '='))) return 0;
661 /* overwrite '=' with '\0' */
666 /* overwrite '\n' with '\0' if '\n' present */
667 if ((b
= strchr (a
, '\n'))) b
[0] = '\0';
674 add_entry (key
, value
);
682 void config_finish ()
684 if (panel_config
->monitor
> (server
.nb_monitor
-1)) {
685 // server.nb_monitor minimum value is 1 (see get_monitors_and_desktops())
686 // and panel_config->monitor is higher
687 fprintf(stderr
, "warning : monitor not found. tint2 default to monitor 1.\n");
688 panel_config
->monitor
= 0;
693 if (panel_config
->monitor
>= 0) {
696 panel1
= calloc(nb_panel
, sizeof(Panel
));
697 memcpy(panel1
, panel_config
, sizeof(Panel
));
698 panel1
->monitor
= panel_config
->monitor
;
702 nb_panel
= server
.nb_monitor
;
703 panel1
= calloc(nb_panel
, sizeof(Panel
));
705 for (i
=0 ; i
< nb_panel
; i
++) {
706 memcpy(&panel1
[i
], panel_config
, sizeof(Panel
));
707 panel1
[i
].monitor
= i
;
711 // TODO: user can configure layout => ordered objects in panel.area.list
712 // clock and systray before taskbar because resize(clock) can resize others object ??
715 #ifdef ENABLE_BATTERY
724 task_refresh_tasklist();
730 const gchar
* const * system_dirs
;
734 save_file_config
= 0;
736 // follow XDG specification
738 // check tint2rc in user directory
739 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
740 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
741 i
= config_read_file (path1
);
747 if (save_file_config
) {
748 fprintf(stderr
, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
752 // check old tintrc config file
753 path1
= g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL
);
754 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
755 save_file_config
= 1;
756 config_read_file (path1
);
761 // copy tint2rc from system directory to user directory
764 system_dirs
= g_get_system_config_dirs();
765 for (i
= 0; system_dirs
[i
]; i
++) {
766 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
768 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
774 // copy file in user directory (path1)
775 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
776 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
779 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
780 copy_file(path2
, path1
);
783 i
= config_read_file (path1
);
791 int config_read_file (const char *path
)
796 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
801 while (fgets(line
, sizeof(line
), fp
) != NULL
)
806 if (save_file_config
)
810 g_free(old_task_font
);
813 if (old_time1_font
) {
814 g_free(old_time1_font
);
817 if (old_time2_font
) {
818 g_free(old_time2_font
);
827 fprintf(stderr
, "tint2 : convert user's config file\n");
832 if (old_task_icon_size
) {
833 panel_config
->g_task
.area
.paddingy
= ((int)panel_config
->initial_height
- (2 * panel_config
->area
.paddingy
) - old_task_icon_size
) / 2;
836 dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
837 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
840 path
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
841 fp
= fopen(path
, "w");
843 if (fp
== NULL
) return;
845 fputs("#---------------------------------------------\n", fp
);
846 fputs("# TINT2 CONFIG FILE\n", fp
);
847 fputs("#---------------------------------------------\n\n", fp
);
848 fputs("#---------------------------------------------\n", fp
);
849 fputs("# BACKGROUND AND BORDER\n", fp
);
850 fputs("#---------------------------------------------\n", fp
);
853 l0
= list_back
->next
;
856 fprintf(fp
, "rounded = %d\n", a
->pix
.border
.rounded
);
857 fprintf(fp
, "border_width = %d\n", a
->pix
.border
.width
);
858 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));
859 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));
864 fputs("#---------------------------------------------\n", fp
);
865 fputs("# PANEL\n", fp
);
866 fputs("#---------------------------------------------\n", fp
);
867 fputs("panel_monitor = all\n", fp
);
868 if (panel_position
& BOTTOM
) fputs("panel_position = bottom", fp
);
869 else fputs("panel_position = top", fp
);
870 if (panel_position
& LEFT
) fputs(" left horizontal\n", fp
);
871 else if (panel_position
& RIGHT
) fputs(" right horizontal\n", fp
);
872 else fputs(" center horizontal\n", fp
);
873 fprintf(fp
, "panel_size = %d %d\n", (int)panel_config
->initial_width
, (int)panel_config
->initial_height
);
874 fprintf(fp
, "panel_margin = %d %d\n", panel_config
->marginx
, panel_config
->marginy
);
875 fprintf(fp
, "panel_padding = %d %d %d\n", panel_config
->area
.paddingxlr
, panel_config
->area
.paddingy
, panel_config
->area
.paddingx
);
876 fprintf(fp
, "font_shadow = %d\n", panel_config
->g_task
.font_shadow
);
877 fputs("panel_background_id = 1\n", fp
);
878 fputs("wm_menu = 0\n", fp
);
880 fputs("\n#---------------------------------------------\n", fp
);
881 fputs("# TASKBAR\n", fp
);
882 fputs("#---------------------------------------------\n", fp
);
883 if (panel_mode
== MULTI_DESKTOP
) fputs("taskbar_mode = multi_desktop\n", fp
);
884 else fputs("taskbar_mode = single_desktop\n", fp
);
885 fprintf(fp
, "taskbar_padding = 0 0 %d\n", panel_config
->g_taskbar
.paddingx
);
886 fputs("taskbar_background_id = 0\n", fp
);
888 fputs("\n#---------------------------------------------\n", fp
);
889 fputs("# TASK\n", fp
);
890 fputs("#---------------------------------------------\n", fp
);
891 if (old_task_icon_size
) fputs("task_icon = 1\n", fp
);
892 else fputs("task_icon = 0\n", fp
);
893 fputs("task_text = 1\n", fp
);
894 fprintf(fp
, "task_maximum_size = %d %d\n", panel_config
->g_task
.maximum_width
, panel_config
->g_task
.maximum_height
);
895 fprintf(fp
, "task_centered = %d\n", panel_config
->g_task
.centered
);
896 fprintf(fp
, "task_padding = %d %d\n", panel_config
->g_task
.area
.paddingx
, panel_config
->g_task
.area
.paddingy
);
897 fprintf(fp
, "task_font = %s\n", old_task_font
);
898 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));
899 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));
900 fputs("task_background_id = 2\n", fp
);
901 fputs("task_active_background_id = 3\n", fp
);
903 fputs("\n#---------------------------------------------\n", fp
);
904 fputs("# SYSTRAYBAR\n", fp
);
905 fputs("#---------------------------------------------\n", fp
);
906 fputs("systray_padding = 4 3 4\n", fp
);
907 fputs("systray_background_id = 0\n", fp
);
909 fputs("\n#---------------------------------------------\n", fp
);
910 fputs("# CLOCK\n", fp
);
911 fputs("#---------------------------------------------\n", fp
);
912 if (time1_format
) fprintf(fp
, "time1_format = %s\n", time1_format
);
913 else fputs("#time1_format = %H:%M\n", fp
);
914 fprintf(fp
, "time1_font = %s\n", old_time1_font
);
915 if (time2_format
) fprintf(fp
, "time2_format = %s\n", time2_format
);
916 else fputs("#time2_format = %A %d %B\n", fp
);
917 fprintf(fp
, "time2_font = %s\n", old_time2_font
);
918 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));
919 fputs("clock_padding = 2 2\n", fp
);
920 fputs("clock_background_id = 0\n", fp
);
921 fputs("#clock_lclick_command = xclock\n", fp
);
922 fputs("clock_rclick_command = orage\n", fp
);
924 #ifdef ENABLE_BATTERY
925 fputs("\n#---------------------------------------------\n", fp
);
926 fputs("# BATTERY\n", fp
);
927 fputs("#---------------------------------------------\n", fp
);
928 fprintf(fp
, "battery = %d\n", panel_config
->battery
.area
.on_screen
);
929 fprintf(fp
, "battery_low_status = %d\n", battery_low_status
);
930 fprintf(fp
, "battery_low_cmd = %s\n", battery_low_cmd
);
931 fprintf(fp
, "bat1_font = %s\n", old_bat1_font
);
932 fprintf(fp
, "bat2_font = %s\n", old_bat2_font
);
933 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));
934 fputs("battery_padding = 2 2\n", fp
);
935 fputs("battery_background_id = 0\n", fp
);
938 fputs("\n#---------------------------------------------\n", fp
);
939 fputs("# MOUSE ACTION ON TASK\n", fp
);
940 fputs("#---------------------------------------------\n", fp
);
941 if (mouse_middle
== NONE
) fputs("mouse_middle = none\n", fp
);
942 else if (mouse_middle
== CLOSE
) fputs("mouse_middle = close\n", fp
);
943 else if (mouse_middle
== TOGGLE
) fputs("mouse_middle = toggle\n", fp
);
944 else if (mouse_middle
== ICONIFY
) fputs("mouse_middle = iconify\n", fp
);
945 else if (mouse_middle
== SHADE
) fputs("mouse_middle = shade\n", fp
);
946 else fputs("mouse_middle = toggle_iconify\n", fp
);
948 if (mouse_right
== NONE
) fputs("mouse_right = none\n", fp
);
949 else if (mouse_right
== CLOSE
) fputs("mouse_right = close\n", fp
);
950 else if (mouse_right
== TOGGLE
) fputs("mouse_right = toggle\n", fp
);
951 else if (mouse_right
== ICONIFY
) fputs("mouse_right = iconify\n", fp
);
952 else if (mouse_right
== SHADE
) fputs("mouse_right = shade\n", fp
);
953 else fputs("mouse_right = toggle_iconify\n", fp
);
955 if (mouse_scroll_up
== NONE
) fputs("mouse_scroll_up = none\n", fp
);
956 else if (mouse_scroll_up
== CLOSE
) fputs("mouse_scroll_up = close\n", fp
);
957 else if (mouse_scroll_up
== TOGGLE
) fputs("mouse_scroll_up = toggle\n", fp
);
958 else if (mouse_scroll_up
== ICONIFY
) fputs("mouse_scroll_up = iconify\n", fp
);
959 else if (mouse_scroll_up
== SHADE
) fputs("mouse_scroll_up = shade\n", fp
);
960 else fputs("mouse_scroll_up = toggle_iconify\n", fp
);
962 if (mouse_scroll_down
== NONE
) fputs("mouse_scroll_down = none\n", fp
);
963 else if (mouse_scroll_down
== CLOSE
) fputs("mouse_scroll_down = close\n", fp
);
964 else if (mouse_scroll_down
== TOGGLE
) fputs("mouse_scroll_down = toggle\n", fp
);
965 else if (mouse_scroll_down
== ICONIFY
) fputs("mouse_scroll_down = iconify\n", fp
);
966 else if (mouse_scroll_down
== SHADE
) fputs("mouse_scroll_down = shade\n", fp
);
967 else fputs("mouse_scroll_down = toggle_iconify\n", fp
);
This page took 0.090749 seconds and 4 git commands to generate.