]>
Dogcows Code - chaz/tint2/blob - src/config.c
e281b8a006f6f0d5713a71d59041b896cd28f9f8
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>
42 #include "systraybar.h"
53 char *config_path
= 0;
54 char *thumbnail_path
= 0;
56 // --------------------------------------------------
57 // backward compatibility
58 static int save_file_config
;
59 static int old_task_icon_size
;
60 static char *old_task_font
;
61 static char *old_time1_font
;
62 static char *old_time2_font
;
63 static Area
*area_task
, *area_task_active
;
66 static char *old_bat1_font
;
67 static char *old_bat2_font
;
70 // temporary list of background
71 static GSList
*list_back
;
77 // get monitor and desktop config
81 // append full transparency background
82 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
84 memset(&panel_config
, 0, sizeof(Panel
));
85 panel_config
.g_task
.alpha
= 100;
86 panel_config
.g_task
.alpha_active
= 100;
89 // window manager's menu default value == false
97 // cleanup background list
99 for (l0
= list_back
; l0
; l0
= l0
->next
) {
102 g_slist_free(list_back
);
107 void copy_file(const char *pathSrc
, const char *pathDest
)
109 FILE *fileSrc
, *fileDest
;
113 fileSrc
= fopen(pathSrc
, "rb");
114 if (fileSrc
== NULL
) return;
116 fileDest
= fopen(pathDest
, "wb");
117 if (fileDest
== NULL
) return;
119 while ((nb
= fread(line
, 1, 100, fileSrc
)) > 0) fwrite(line
, 1, nb
, fileDest
);
126 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
130 if (*value1
) free (*value1
);
131 if (*value2
) free (*value2
);
132 if (*value3
) free (*value3
);
134 if ((b
= strchr (value
, ' '))) {
142 *value1
= strdup (value
);
146 if ((c
= strchr (b
, ' '))) {
154 *value2
= strdup (b
);
159 *value3
= strdup (c
);
165 int hex_char_to_int (char c
)
169 if (c
>= '0' && c
<= '9') r
= c
- '0';
170 else if (c
>= 'a' && c
<= 'f') r
= c
- 'a' + 10;
171 else if (c
>= 'A' && c
<= 'F') r
= c
- 'A' + 10;
178 int hex_to_rgb (char *hex
, int *r
, int *g
, int *b
)
182 if (hex
== NULL
|| hex
[0] != '#') return (0);
186 *r
= hex_char_to_int (hex
[1]);
187 *g
= hex_char_to_int (hex
[2]);
188 *b
= hex_char_to_int (hex
[3]);
190 else if (len
== 6 + 1) {
191 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
192 *g
= hex_char_to_int (hex
[3]) * 16 + hex_char_to_int (hex
[4]);
193 *b
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
195 else if (len
== 12 + 1) {
196 *r
= hex_char_to_int (hex
[1]) * 16 + hex_char_to_int (hex
[2]);
197 *g
= hex_char_to_int (hex
[5]) * 16 + hex_char_to_int (hex
[6]);
198 *b
= hex_char_to_int (hex
[9]) * 16 + hex_char_to_int (hex
[10]);
206 void get_color (char *hex
, double *rgb
)
209 hex_to_rgb (hex
, &r
, &g
, &b
);
211 rgb
[0] = (r
/ 255.0);
212 rgb
[1] = (g
/ 255.0);
213 rgb
[2] = (b
/ 255.0);
217 void get_action (char *event
, int *action
)
219 if (strcmp (event
, "none") == 0)
221 else if (strcmp (event
, "close") == 0)
223 else if (strcmp (event
, "toggle") == 0)
225 else if (strcmp (event
, "iconify") == 0)
227 else if (strcmp (event
, "shade") == 0)
229 else if (strcmp (event
, "toggle_iconify") == 0)
230 *action
= TOGGLE_ICONIFY
;
231 else if (strcmp (event
, "maximize_restore") == 0)
232 *action
= MAXIMIZE_RESTORE
;
233 else if (strcmp (event
, "desktop_left") == 0)
234 *action
= DESKTOP_LEFT
;
235 else if (strcmp (event
, "desktop_right") == 0)
236 *action
= DESKTOP_RIGHT
;
240 void add_entry (char *key
, char *value
)
242 char *value1
=0, *value2
=0, *value3
=0;
244 /* Background and border */
245 if (strcmp (key
, "rounded") == 0) {
246 // 'rounded' is the first parameter => alloc a new background
247 Area
*a
= calloc(1, sizeof(Area
));
248 a
->pix
.border
.rounded
= atoi (value
);
249 list_back
= g_slist_append(list_back
, a
);
251 else if (strcmp (key
, "border_width") == 0) {
252 Area
*a
= g_slist_last(list_back
)->data
;
253 a
->pix
.border
.width
= atoi (value
);
255 else if (strcmp (key
, "background_color") == 0) {
256 Area
*a
= g_slist_last(list_back
)->data
;
257 extract_values(value
, &value1
, &value2
, &value3
);
258 get_color (value1
, a
->pix
.back
.color
);
259 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
260 else a
->pix
.back
.alpha
= 0.5;
262 else if (strcmp (key
, "border_color") == 0) {
263 Area
*a
= g_slist_last(list_back
)->data
;
264 extract_values(value
, &value1
, &value2
, &value3
);
265 get_color (value1
, a
->pix
.border
.color
);
266 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
267 else a
->pix
.border
.alpha
= 0.5;
271 else if (strcmp (key
, "panel_monitor") == 0) {
272 if (strcmp (value
, "all") == 0) panel_config
.monitor
= -1;
274 panel_config
.monitor
= atoi (value
);
275 if (panel_config
.monitor
> 0) panel_config
.monitor
-= 1;
278 else if (strcmp (key
, "panel_size") == 0) {
279 extract_values(value
, &value1
, &value2
, &value3
);
282 if ((b
= strchr (value1
, '%'))) {
284 panel_config
.pourcentx
= 1;
286 panel_config
.initial_width
= atof(value1
);
288 if ((b
= strchr (value2
, '%'))) {
290 panel_config
.pourcenty
= 1;
292 panel_config
.initial_height
= atof(value2
);
295 else if (strcmp (key
, "panel_margin") == 0) {
296 extract_values(value
, &value1
, &value2
, &value3
);
297 panel_config
.marginx
= atoi (value1
);
298 if (value2
) panel_config
.marginy
= atoi (value2
);
300 else if (strcmp (key
, "panel_padding") == 0) {
301 extract_values(value
, &value1
, &value2
, &value3
);
302 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
303 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
304 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
306 else if (strcmp (key
, "panel_position") == 0) {
307 extract_values(value
, &value1
, &value2
, &value3
);
308 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
310 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
311 else panel_position
= CENTER
;
314 if (!value2
) panel_position
|= CENTER
;
316 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
318 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
319 else panel_position
|= CENTER
;
322 if (!value3
) panel_horizontal
= 1;
324 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
325 else panel_horizontal
= 1;
328 else if (strcmp (key
, "font_shadow") == 0)
329 panel_config
.g_task
.font_shadow
= atoi (value
);
330 else if (strcmp (key
, "panel_background_id") == 0) {
331 int id
= atoi (value
);
332 Area
*a
= g_slist_nth_data(list_back
, id
);
333 memcpy(&panel_config
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
334 memcpy(&panel_config
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
336 else if (strcmp (key
, "wm_menu") == 0)
337 wm_menu
= atoi (value
);
338 else if (strcmp (key
, "panel_dock") == 0)
339 panel_dock
= atoi (value
);
340 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
341 max_tick_urgent
= (atoi (value
) * 2) + 1;
344 else if (strcmp (key
, "battery") == 0) {
345 #ifdef ENABLE_BATTERY
347 panel_config
.battery
.area
.on_screen
= 1;
350 fprintf(stderr
, "tint2 is build without battery support\n");
353 else if (strcmp (key
, "battery_low_status") == 0) {
354 #ifdef ENABLE_BATTERY
355 battery_low_status
= atoi(value
);
356 if(battery_low_status
< 0 || battery_low_status
> 100)
357 battery_low_status
= 0;
360 else if (strcmp (key
, "battery_low_cmd") == 0) {
361 #ifdef ENABLE_BATTERY
362 if (battery_low_cmd
) g_free(battery_low_cmd
);
363 if (strlen(value
) > 0) battery_low_cmd
= strdup (value
);
364 else battery_low_cmd
= 0;
367 else if (strcmp (key
, "bat1_font") == 0) {
368 #ifdef ENABLE_BATTERY
369 if (save_file_config
) old_bat1_font
= strdup (value
);
370 if (bat1_font_desc
) pango_font_description_free(bat1_font_desc
);
371 bat1_font_desc
= pango_font_description_from_string (value
);
374 else if (strcmp (key
, "bat2_font") == 0) {
375 #ifdef ENABLE_BATTERY
376 if (save_file_config
) old_bat2_font
= strdup (value
);
377 if (bat2_font_desc
) pango_font_description_free(bat2_font_desc
);
378 bat2_font_desc
= pango_font_description_from_string (value
);
381 else if (strcmp (key
, "battery_font_color") == 0) {
382 #ifdef ENABLE_BATTERY
383 extract_values(value
, &value1
, &value2
, &value3
);
384 get_color (value1
, panel_config
.battery
.font
.color
);
385 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
386 else panel_config
.battery
.font
.alpha
= 0.5;
389 else if (strcmp (key
, "battery_padding") == 0) {
390 #ifdef ENABLE_BATTERY
391 extract_values(value
, &value1
, &value2
, &value3
);
392 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
393 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
394 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
397 else if (strcmp (key
, "battery_background_id") == 0) {
398 #ifdef ENABLE_BATTERY
399 int id
= atoi (value
);
400 Area
*a
= g_slist_nth_data(list_back
, id
);
401 memcpy(&panel_config
.battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
402 memcpy(&panel_config
.battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
407 else if (strcmp (key
, "time1_format") == 0) {
408 if (time1_format
) g_free(time1_format
);
409 if (strlen(value
) > 0) {
410 time1_format
= strdup (value
);
411 panel_config
.clock
.area
.on_screen
= 1;
415 panel_config
.clock
.area
.on_screen
= 0;
418 else if (strcmp (key
, "time2_format") == 0) {
419 if (time2_format
) g_free(time2_format
);
420 if (strlen(value
) > 0) time2_format
= strdup (value
);
421 else time2_format
= 0;
423 else if (strcmp (key
, "time1_font") == 0) {
424 if (save_file_config
) old_time1_font
= strdup (value
);
425 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
426 time1_font_desc
= pango_font_description_from_string (value
);
428 else if (strcmp (key
, "time2_font") == 0) {
429 if (save_file_config
) old_time2_font
= strdup (value
);
430 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
431 time2_font_desc
= pango_font_description_from_string (value
);
433 else if (strcmp (key
, "clock_font_color") == 0) {
434 extract_values(value
, &value1
, &value2
, &value3
);
435 get_color (value1
, panel_config
.clock
.font
.color
);
436 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
437 else panel_config
.clock
.font
.alpha
= 0.5;
439 else if (strcmp (key
, "clock_padding") == 0) {
440 extract_values(value
, &value1
, &value2
, &value3
);
441 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
442 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
443 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
445 else if (strcmp (key
, "clock_background_id") == 0) {
446 int id
= atoi (value
);
447 Area
*a
= g_slist_nth_data(list_back
, id
);
448 memcpy(&panel_config
.clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
449 memcpy(&panel_config
.clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
451 else if (strcmp(key
, "clock_lclick_command") == 0) {
452 if (clock_lclick_command
) g_free(clock_lclick_command
);
453 if (strlen(value
) > 0) clock_lclick_command
= strdup(value
);
454 else clock_lclick_command
= 0;
456 else if (strcmp(key
, "clock_rclick_command") == 0) {
457 if (clock_rclick_command
) g_free(clock_rclick_command
);
458 if (strlen(value
) > 0) clock_rclick_command
= strdup(value
);
459 else clock_rclick_command
= 0;
463 else if (strcmp (key
, "taskbar_mode") == 0) {
464 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
465 else panel_mode
= SINGLE_DESKTOP
;
467 else if (strcmp (key
, "taskbar_padding") == 0) {
468 extract_values(value
, &value1
, &value2
, &value3
);
469 panel_config
.g_taskbar
.paddingxlr
= panel_config
.g_taskbar
.paddingx
= atoi (value1
);
470 if (value2
) panel_config
.g_taskbar
.paddingy
= atoi (value2
);
471 if (value3
) panel_config
.g_taskbar
.paddingx
= atoi (value3
);
473 else if (strcmp (key
, "taskbar_background_id") == 0) {
474 int id
= atoi (value
);
475 Area
*a
= g_slist_nth_data(list_back
, id
);
476 memcpy(&panel_config
.g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
477 memcpy(&panel_config
.g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
479 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
480 int id
= atoi (value
);
481 Area
*a
= g_slist_nth_data(list_back
, id
);
482 memcpy(&panel_config
.g_taskbar
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
483 memcpy(&panel_config
.g_taskbar
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
484 panel_config
.g_taskbar
.use_active
= 1;
488 else if (strcmp (key
, "task_text") == 0)
489 panel_config
.g_task
.text
= atoi (value
);
490 else if (strcmp (key
, "task_icon") == 0)
491 panel_config
.g_task
.icon
= atoi (value
);
492 else if (strcmp (key
, "task_centered") == 0)
493 panel_config
.g_task
.centered
= atoi (value
);
494 else if (strcmp (key
, "task_width") == 0) {
495 // old parameter : just for backward compatibility
496 panel_config
.g_task
.maximum_width
= atoi (value
);
497 panel_config
.g_task
.maximum_height
= 30;
499 else if (strcmp (key
, "task_maximum_size") == 0) {
500 extract_values(value
, &value1
, &value2
, &value3
);
501 panel_config
.g_task
.maximum_width
= atoi (value1
);
502 panel_config
.g_task
.maximum_height
= 30;
504 panel_config
.g_task
.maximum_height
= atoi (value2
);
506 else if (strcmp (key
, "task_padding") == 0) {
507 extract_values(value
, &value1
, &value2
, &value3
);
508 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
509 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
510 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
512 else if (strcmp (key
, "task_font") == 0) {
513 if (save_file_config
) old_task_font
= strdup (value
);
514 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
515 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
517 else if (strcmp (key
, "task_font_color") == 0) {
518 extract_values(value
, &value1
, &value2
, &value3
);
519 get_color (value1
, panel_config
.g_task
.font
.color
);
520 if (value2
) panel_config
.g_task
.font
.alpha
= (atoi (value2
) / 100.0);
521 else panel_config
.g_task
.font
.alpha
= 0.1;
523 else if (strcmp (key
, "task_active_font_color") == 0) {
524 extract_values(value
, &value1
, &value2
, &value3
);
525 get_color (value1
, panel_config
.g_task
.font_active
.color
);
526 if (value2
) panel_config
.g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
527 else panel_config
.g_task
.font_active
.alpha
= 0.1;
529 else if (strcmp (key
, "task_icon_asb") == 0) {
530 extract_values(value
, &value1
, &value2
, &value3
);
531 panel_config
.g_task
.alpha
= atoi(value1
);
532 panel_config
.g_task
.saturation
= atoi(value2
);
533 panel_config
.g_task
.brightness
= atoi(value3
);
535 else if (strcmp (key
, "task_active_icon_asb") == 0) {
536 extract_values(value
, &value1
, &value2
, &value3
);
537 panel_config
.g_task
.alpha_active
= atoi(value1
);
538 panel_config
.g_task
.saturation_active
= atoi(value2
);
539 panel_config
.g_task
.brightness_active
= atoi(value3
);
541 else if (strcmp (key
, "task_background_id") == 0) {
542 int id
= atoi (value
);
543 Area
*a
= g_slist_nth_data(list_back
, id
);
544 memcpy(&panel_config
.g_task
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
545 memcpy(&panel_config
.g_task
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
547 else if (strcmp (key
, "task_active_background_id") == 0) {
548 int id
= atoi (value
);
549 Area
*a
= g_slist_nth_data(list_back
, id
);
550 memcpy(&panel_config
.g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
551 memcpy(&panel_config
.g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
555 else if (strcmp (key
, "systray_padding") == 0) {
556 extract_values(value
, &value1
, &value2
, &value3
);
557 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
558 if (value2
) systray
.area
.paddingy
= atoi (value2
);
559 if (value3
) systray
.area
.paddingx
= atoi (value3
);
560 systray
.area
.on_screen
= 1;
562 else if (strcmp (key
, "systray_background_id") == 0) {
563 int id
= atoi (value
);
564 Area
*a
= g_slist_nth_data(list_back
, id
);
565 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
566 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
568 else if (strcmp(key
, "systray_sort") == 0) {
569 if (strcmp(value
, "descending") == 0)
571 else if (strcmp(value
, "ascending") == 0)
573 else if (strcmp(value
, "left2right") == 0)
575 else if (strcmp(value
, "right2left") == 0)
580 else if (strcmp (key
, "tooltip") == 0)
581 g_tooltip
.enabled
= atoi(value
);
582 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
583 double timeout
= atof(value
);
584 int sec
= (int)timeout
;
585 int usec
= (timeout
-sec
)*1e6
;
586 g_tooltip
.show_timeout
.it_value
= (struct timeval
){.tv_sec
=sec
, .tv_usec
=usec
};
588 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
589 double timeout
= atof(value
);
590 int sec
= (int)timeout
;
591 int usec
= (timeout
-sec
)*1e6
;
592 g_tooltip
.hide_timeout
.it_value
= (struct timeval
){.tv_sec
=sec
, .tv_usec
=usec
};
594 else if (strcmp (key
, "tooltip_padding") == 0) {
595 extract_values(value
, &value1
, &value2
, &value3
);
596 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
597 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
599 else if (strcmp (key
, "tooltip_background_id") == 0) {
600 int id
= atoi (value
);
601 Area
*a
= g_slist_nth_data(list_back
, id
);
602 memcpy(&g_tooltip
.background_color
, &a
->pix
.back
, sizeof(Color
));
603 memcpy(&g_tooltip
.border
, &a
->pix
.border
, sizeof(Border
));
605 else if (strcmp (key
, "tooltip_font_color") == 0) {
606 extract_values(value
, &value1
, &value2
, &value3
);
607 get_color(value1
, g_tooltip
.font_color
.color
);
608 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
609 else g_tooltip
.font_color
.alpha
= 0.1;
611 else if (strcmp (key
, "tooltip_font") == 0) {
612 if (g_tooltip
.font_desc
) pango_font_description_free(g_tooltip
.font_desc
);
613 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
617 else if (strcmp (key
, "mouse_middle") == 0)
618 get_action (value
, &mouse_middle
);
619 else if (strcmp (key
, "mouse_right") == 0)
620 get_action (value
, &mouse_right
);
621 else if (strcmp (key
, "mouse_scroll_up") == 0)
622 get_action (value
, &mouse_scroll_up
);
623 else if (strcmp (key
, "mouse_scroll_down") == 0)
624 get_action (value
, &mouse_scroll_down
);
627 /* Read tint-0.6 config for backward compatibility */
628 else if (strcmp (key
, "panel_mode") == 0) {
629 save_file_config
= 1;
630 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
631 else panel_mode
= MULTI_DESKTOP
;
633 else if (strcmp (key
, "panel_rounded") == 0) {
634 Area
*a
= calloc(1, sizeof(Area
));
635 a
->pix
.border
.rounded
= atoi (value
);
636 list_back
= g_slist_append(list_back
, a
);
638 else if (strcmp (key
, "panel_border_width") == 0) {
639 Area
*a
= g_slist_last(list_back
)->data
;
640 a
->pix
.border
.width
= atoi (value
);
642 else if (strcmp (key
, "panel_background_color") == 0) {
643 Area
*a
= g_slist_last(list_back
)->data
;
644 extract_values(value
, &value1
, &value2
, &value3
);
645 get_color (value1
, a
->pix
.back
.color
);
646 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
647 else a
->pix
.back
.alpha
= 0.5;
649 else if (strcmp (key
, "panel_border_color") == 0) {
650 Area
*a
= g_slist_last(list_back
)->data
;
651 extract_values(value
, &value1
, &value2
, &value3
);
652 get_color (value1
, a
->pix
.border
.color
);
653 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
654 else a
->pix
.border
.alpha
= 0.5;
656 else if (strcmp (key
, "task_text_centered") == 0)
657 panel_config
.g_task
.centered
= atoi (value
);
658 else if (strcmp (key
, "task_margin") == 0) {
659 panel_config
.g_taskbar
.paddingxlr
= 0;
660 panel_config
.g_taskbar
.paddingx
= atoi (value
);
662 else if (strcmp (key
, "task_icon_size") == 0)
663 old_task_icon_size
= atoi (value
);
664 else if (strcmp (key
, "task_rounded") == 0) {
665 area_task
= calloc(1, sizeof(Area
));
666 area_task
->pix
.border
.rounded
= atoi (value
);
667 list_back
= g_slist_append(list_back
, area_task
);
669 area_task_active
= calloc(1, sizeof(Area
));
670 area_task_active
->pix
.border
.rounded
= atoi (value
);
671 list_back
= g_slist_append(list_back
, area_task_active
);
673 else if (strcmp (key
, "task_background_color") == 0) {
674 extract_values(value
, &value1
, &value2
, &value3
);
675 get_color (value1
, area_task
->pix
.back
.color
);
676 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
677 else area_task
->pix
.back
.alpha
= 0.5;
679 else if (strcmp (key
, "task_active_background_color") == 0) {
680 extract_values(value
, &value1
, &value2
, &value3
);
681 get_color (value1
, area_task_active
->pix
.back
.color
);
682 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
683 else area_task_active
->pix
.back
.alpha
= 0.5;
685 else if (strcmp (key
, "task_border_width") == 0) {
686 area_task
->pix
.border
.width
= atoi (value
);
687 area_task_active
->pix
.border
.width
= atoi (value
);
689 else if (strcmp (key
, "task_border_color") == 0) {
690 extract_values(value
, &value1
, &value2
, &value3
);
691 get_color (value1
, area_task
->pix
.border
.color
);
692 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
693 else area_task
->pix
.border
.alpha
= 0.5;
695 else if (strcmp (key
, "task_active_border_color") == 0) {
696 extract_values(value
, &value1
, &value2
, &value3
);
697 get_color (value1
, area_task_active
->pix
.border
.color
);
698 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
699 else area_task_active
->pix
.border
.alpha
= 0.5;
703 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
705 if (value1
) free (value1
);
706 if (value2
) free (value2
);
707 if (value3
) free (value3
);
711 int parse_line (const char *line
)
713 char *a
, *b
, *key
, *value
;
715 /* Skip useless lines */
716 if ((line
[0] == '#') || (line
[0] == '\n')) return 0;
717 if (!(a
= strchr (line
, '='))) return 0;
719 /* overwrite '=' with '\0' */
724 /* overwrite '\n' with '\0' if '\n' present */
725 if ((b
= strchr (a
, '\n'))) b
[0] = '\0';
732 add_entry (key
, value
);
740 void config_finish ()
742 if (panel_config
.monitor
> (server
.nb_monitor
-1)) {
743 // server.nb_monitor minimum value is 1 (see get_monitors())
744 // and panel_config->monitor is higher
745 fprintf(stderr
, "warning : monitor not found. tint2 default to all monitors.\n");
746 panel_config
.monitor
= 0;
749 // TODO: user can configure layout => ordered objects in panel.area.list
750 // clock and systray before taskbar because resize(clock) can resize others object ??
753 #ifdef ENABLE_BATTERY
765 const gchar
* const * system_dirs
;
769 save_file_config
= 0;
771 // follow XDG specification
773 // check tint2rc in user directory
774 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
775 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
776 i
= config_read_file (path1
);
777 config_path
= strdup(path1
);
783 if (save_file_config
) {
784 fprintf(stderr
, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
788 // check old tintrc config file
789 path1
= g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL
);
790 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
791 save_file_config
= 1;
792 config_read_file (path1
);
797 // copy tint2rc from system directory to user directory
800 system_dirs
= g_get_system_config_dirs();
801 for (i
= 0; system_dirs
[i
]; i
++) {
802 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
804 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
810 // copy file in user directory (path1)
811 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
812 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
815 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
816 copy_file(path2
, path1
);
819 i
= config_read_file (path1
);
820 config_path
= strdup(path1
);
828 int config_read_file (const char *path
)
833 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
838 while (fgets(line
, sizeof(line
), fp
) != NULL
)
843 if (save_file_config
)
847 g_free(old_task_font
);
850 if (old_time1_font
) {
851 g_free(old_time1_font
);
854 if (old_time2_font
) {
855 g_free(old_time2_font
);
864 fprintf(stderr
, "tint2 : convert user's config file\n");
869 if (old_task_icon_size
) {
870 panel_config
.g_task
.area
.paddingy
= ((int)panel_config
.initial_height
- (2 * panel_config
.area
.paddingy
) - old_task_icon_size
) / 2;
873 dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
874 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
877 path
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
878 fp
= fopen(path
, "w");
880 if (fp
== NULL
) return;
882 fputs("#---------------------------------------------\n", fp
);
883 fputs("# TINT2 CONFIG FILE\n", fp
);
884 fputs("#---------------------------------------------\n\n", fp
);
885 fputs("#---------------------------------------------\n", fp
);
886 fputs("# BACKGROUND AND BORDER\n", fp
);
887 fputs("#---------------------------------------------\n", fp
);
890 l0
= list_back
->next
;
893 fprintf(fp
, "rounded = %d\n", a
->pix
.border
.rounded
);
894 fprintf(fp
, "border_width = %d\n", a
->pix
.border
.width
);
895 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));
896 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));
901 fputs("#---------------------------------------------\n", fp
);
902 fputs("# PANEL\n", fp
);
903 fputs("#---------------------------------------------\n", fp
);
904 fputs("panel_monitor = all\n", fp
);
905 if (panel_position
& BOTTOM
) fputs("panel_position = bottom", fp
);
906 else fputs("panel_position = top", fp
);
907 if (panel_position
& LEFT
) fputs(" left horizontal\n", fp
);
908 else if (panel_position
& RIGHT
) fputs(" right horizontal\n", fp
);
909 else fputs(" center horizontal\n", fp
);
910 fprintf(fp
, "panel_size = %d %d\n", (int)panel_config
.initial_width
, (int)panel_config
.initial_height
);
911 fprintf(fp
, "panel_margin = %d %d\n", panel_config
.marginx
, panel_config
.marginy
);
912 fprintf(fp
, "panel_padding = %d %d %d\n", panel_config
.area
.paddingxlr
, panel_config
.area
.paddingy
, panel_config
.area
.paddingx
);
913 fprintf(fp
, "font_shadow = %d\n", panel_config
.g_task
.font_shadow
);
914 fputs("panel_background_id = 1\n", fp
);
915 fputs("wm_menu = 0\n", fp
);
917 fputs("\n#---------------------------------------------\n", fp
);
918 fputs("# TASKBAR\n", fp
);
919 fputs("#---------------------------------------------\n", fp
);
920 if (panel_mode
== MULTI_DESKTOP
) fputs("taskbar_mode = multi_desktop\n", fp
);
921 else fputs("taskbar_mode = single_desktop\n", fp
);
922 fprintf(fp
, "taskbar_padding = 0 0 %d\n", panel_config
.g_taskbar
.paddingx
);
923 fputs("taskbar_background_id = 0\n", fp
);
925 fputs("\n#---------------------------------------------\n", fp
);
926 fputs("# TASK\n", fp
);
927 fputs("#---------------------------------------------\n", fp
);
928 if (old_task_icon_size
) fputs("task_icon = 1\n", fp
);
929 else fputs("task_icon = 0\n", fp
);
930 fputs("task_text = 1\n", fp
);
931 fprintf(fp
, "task_maximum_size = %d %d\n", panel_config
.g_task
.maximum_width
, panel_config
.g_task
.maximum_height
);
932 fprintf(fp
, "task_centered = %d\n", panel_config
.g_task
.centered
);
933 fprintf(fp
, "task_padding = %d %d\n", panel_config
.g_task
.area
.paddingx
, panel_config
.g_task
.area
.paddingy
);
934 fprintf(fp
, "task_font = %s\n", old_task_font
);
935 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));
936 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));
937 fputs("task_background_id = 2\n", fp
);
938 fputs("task_active_background_id = 3\n", fp
);
940 fputs("\n#---------------------------------------------\n", fp
);
941 fputs("# SYSTRAYBAR\n", fp
);
942 fputs("#---------------------------------------------\n", fp
);
943 fputs("systray_padding = 4 3 4\n", fp
);
944 fputs("systray_background_id = 0\n", fp
);
946 fputs("\n#---------------------------------------------\n", fp
);
947 fputs("# CLOCK\n", fp
);
948 fputs("#---------------------------------------------\n", fp
);
949 if (time1_format
) fprintf(fp
, "time1_format = %s\n", time1_format
);
950 else fputs("#time1_format = %H:%M\n", fp
);
951 fprintf(fp
, "time1_font = %s\n", old_time1_font
);
952 if (time2_format
) fprintf(fp
, "time2_format = %s\n", time2_format
);
953 else fputs("#time2_format = %A %d %B\n", fp
);
954 fprintf(fp
, "time2_font = %s\n", old_time2_font
);
955 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));
956 fputs("clock_padding = 2 2\n", fp
);
957 fputs("clock_background_id = 0\n", fp
);
958 fputs("#clock_lclick_command = xclock\n", fp
);
959 fputs("clock_rclick_command = orage\n", fp
);
961 #ifdef ENABLE_BATTERY
962 fputs("\n#---------------------------------------------\n", fp
);
963 fputs("# BATTERY\n", fp
);
964 fputs("#---------------------------------------------\n", fp
);
965 fprintf(fp
, "battery = %d\n", panel_config
.battery
.area
.on_screen
);
966 fprintf(fp
, "battery_low_status = %d\n", battery_low_status
);
967 fprintf(fp
, "battery_low_cmd = %s\n", battery_low_cmd
);
968 fprintf(fp
, "bat1_font = %s\n", old_bat1_font
);
969 fprintf(fp
, "bat2_font = %s\n", old_bat2_font
);
970 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));
971 fputs("battery_padding = 2 2\n", fp
);
972 fputs("battery_background_id = 0\n", fp
);
975 fputs("\n#---------------------------------------------\n", fp
);
976 fputs("# MOUSE ACTION ON TASK\n", fp
);
977 fputs("#---------------------------------------------\n", fp
);
978 if (mouse_middle
== NONE
) fputs("mouse_middle = none\n", fp
);
979 else if (mouse_middle
== CLOSE
) fputs("mouse_middle = close\n", fp
);
980 else if (mouse_middle
== TOGGLE
) fputs("mouse_middle = toggle\n", fp
);
981 else if (mouse_middle
== ICONIFY
) fputs("mouse_middle = iconify\n", fp
);
982 else if (mouse_middle
== SHADE
) fputs("mouse_middle = shade\n", fp
);
983 else fputs("mouse_middle = toggle_iconify\n", fp
);
985 if (mouse_right
== NONE
) fputs("mouse_right = none\n", fp
);
986 else if (mouse_right
== CLOSE
) fputs("mouse_right = close\n", fp
);
987 else if (mouse_right
== TOGGLE
) fputs("mouse_right = toggle\n", fp
);
988 else if (mouse_right
== ICONIFY
) fputs("mouse_right = iconify\n", fp
);
989 else if (mouse_right
== SHADE
) fputs("mouse_right = shade\n", fp
);
990 else fputs("mouse_right = toggle_iconify\n", fp
);
992 if (mouse_scroll_up
== NONE
) fputs("mouse_scroll_up = none\n", fp
);
993 else if (mouse_scroll_up
== CLOSE
) fputs("mouse_scroll_up = close\n", fp
);
994 else if (mouse_scroll_up
== TOGGLE
) fputs("mouse_scroll_up = toggle\n", fp
);
995 else if (mouse_scroll_up
== ICONIFY
) fputs("mouse_scroll_up = iconify\n", fp
);
996 else if (mouse_scroll_up
== SHADE
) fputs("mouse_scroll_up = shade\n", fp
);
997 else fputs("mouse_scroll_up = toggle_iconify\n", fp
);
999 if (mouse_scroll_down
== NONE
) fputs("mouse_scroll_down = none\n", fp
);
1000 else if (mouse_scroll_down
== CLOSE
) fputs("mouse_scroll_down = close\n", fp
);
1001 else if (mouse_scroll_down
== TOGGLE
) fputs("mouse_scroll_down = toggle\n", fp
);
1002 else if (mouse_scroll_down
== ICONIFY
) fputs("mouse_scroll_down = iconify\n", fp
);
1003 else if (mouse_scroll_down
== SHADE
) fputs("mouse_scroll_down = shade\n", fp
);
1004 else fputs("mouse_scroll_down = toggle_iconify\n", fp
);
This page took 0.088244 seconds and 3 git commands to generate.