]>
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>
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 // append full transparency background
78 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
80 // tint2 could reload config, so we cleanup objects
86 // panel's default value
87 memset(&panel_config
, 0, sizeof(Panel
));
88 panel_config
.g_task
.alpha
= 100;
89 panel_config
.g_task
.alpha_active
= 100;
92 // window manager's menu default value == false
100 // cleanup background list
102 for (l0
= list_back
; l0
; l0
= l0
->next
) {
105 g_slist_free(list_back
);
110 void extract_values (const char *value
, char **value1
, char **value2
, char **value3
)
114 if (*value1
) free (*value1
);
115 if (*value2
) free (*value2
);
116 if (*value3
) free (*value3
);
118 if ((b
= strchr (value
, ' '))) {
126 *value1
= strdup (value
);
130 if ((c
= strchr (b
, ' '))) {
138 *value2
= strdup (b
);
143 *value3
= strdup (c
);
149 void get_action (char *event
, int *action
)
151 if (strcmp (event
, "none") == 0)
153 else if (strcmp (event
, "close") == 0)
155 else if (strcmp (event
, "toggle") == 0)
157 else if (strcmp (event
, "iconify") == 0)
159 else if (strcmp (event
, "shade") == 0)
161 else if (strcmp (event
, "toggle_iconify") == 0)
162 *action
= TOGGLE_ICONIFY
;
163 else if (strcmp (event
, "maximize_restore") == 0)
164 *action
= MAXIMIZE_RESTORE
;
165 else if (strcmp (event
, "desktop_left") == 0)
166 *action
= DESKTOP_LEFT
;
167 else if (strcmp (event
, "desktop_right") == 0)
168 *action
= DESKTOP_RIGHT
;
172 void add_entry (char *key
, char *value
)
174 char *value1
=0, *value2
=0, *value3
=0;
176 /* Background and border */
177 if (strcmp (key
, "rounded") == 0) {
178 // 'rounded' is the first parameter => alloc a new background
179 Area
*a
= calloc(1, sizeof(Area
));
180 a
->pix
.border
.rounded
= atoi (value
);
181 list_back
= g_slist_append(list_back
, a
);
183 else if (strcmp (key
, "border_width") == 0) {
184 Area
*a
= g_slist_last(list_back
)->data
;
185 a
->pix
.border
.width
= atoi (value
);
187 else if (strcmp (key
, "background_color") == 0) {
188 Area
*a
= g_slist_last(list_back
)->data
;
189 extract_values(value
, &value1
, &value2
, &value3
);
190 get_color (value1
, a
->pix
.back
.color
);
191 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
192 else a
->pix
.back
.alpha
= 0.5;
194 else if (strcmp (key
, "border_color") == 0) {
195 Area
*a
= g_slist_last(list_back
)->data
;
196 extract_values(value
, &value1
, &value2
, &value3
);
197 get_color (value1
, a
->pix
.border
.color
);
198 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
199 else a
->pix
.border
.alpha
= 0.5;
203 else if (strcmp (key
, "panel_monitor") == 0) {
204 if (strcmp (value
, "all") == 0) panel_config
.monitor
= -1;
206 panel_config
.monitor
= atoi (value
);
207 if (panel_config
.monitor
> 0) panel_config
.monitor
-= 1;
209 if (panel_config
.monitor
> (server
.nb_monitor
-1)) {
210 // server.nb_monitor minimum value is 1 (see get_monitors())
211 fprintf(stderr
, "warning : monitor not found. tint2 default to all monitors.\n");
212 panel_config
.monitor
= 0;
215 else if (strcmp (key
, "panel_size") == 0) {
216 extract_values(value
, &value1
, &value2
, &value3
);
219 if ((b
= strchr (value1
, '%'))) {
221 panel_config
.pourcentx
= 1;
223 panel_config
.area
.width
= atoi(value1
);
224 if (panel_config
.area
.width
== 0) {
226 panel_config
.area
.width
= 100;
227 panel_config
.pourcentx
= 1;
230 if ((b
= strchr (value2
, '%'))) {
232 panel_config
.pourcenty
= 1;
234 panel_config
.area
.height
= atoi(value2
);
237 else if (strcmp (key
, "panel_margin") == 0) {
238 extract_values(value
, &value1
, &value2
, &value3
);
239 panel_config
.marginx
= atoi (value1
);
240 if (value2
) panel_config
.marginy
= atoi (value2
);
242 else if (strcmp (key
, "panel_padding") == 0) {
243 extract_values(value
, &value1
, &value2
, &value3
);
244 panel_config
.area
.paddingxlr
= panel_config
.area
.paddingx
= atoi (value1
);
245 if (value2
) panel_config
.area
.paddingy
= atoi (value2
);
246 if (value3
) panel_config
.area
.paddingx
= atoi (value3
);
248 else if (strcmp (key
, "panel_position") == 0) {
249 extract_values(value
, &value1
, &value2
, &value3
);
250 if (strcmp (value1
, "top") == 0) panel_position
= TOP
;
252 if (strcmp (value1
, "bottom") == 0) panel_position
= BOTTOM
;
253 else panel_position
= CENTER
;
256 if (!value2
) panel_position
|= CENTER
;
258 if (strcmp (value2
, "left") == 0) panel_position
|= LEFT
;
260 if (strcmp (value2
, "right") == 0) panel_position
|= RIGHT
;
261 else panel_position
|= CENTER
;
264 if (!value3
) panel_horizontal
= 1;
266 if (strcmp (value3
, "vertical") == 0) panel_horizontal
= 0;
267 else panel_horizontal
= 1;
270 else if (strcmp (key
, "font_shadow") == 0)
271 panel_config
.g_task
.font_shadow
= atoi (value
);
272 else if (strcmp (key
, "panel_background_id") == 0) {
273 int id
= atoi (value
);
274 Area
*a
= g_slist_nth_data(list_back
, id
);
275 memcpy(&panel_config
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
276 memcpy(&panel_config
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
278 else if (strcmp (key
, "wm_menu") == 0)
279 wm_menu
= atoi (value
);
280 else if (strcmp (key
, "panel_dock") == 0)
281 panel_dock
= atoi (value
);
282 else if (strcmp (key
, "urgent_nb_of_blink") == 0)
283 max_tick_urgent
= (atoi (value
) * 2) + 1;
286 else if (strcmp (key
, "battery") == 0) {
287 #ifdef ENABLE_BATTERY
292 fprintf(stderr
, "tint2 is build without battery support\n");
295 else if (strcmp (key
, "battery_low_status") == 0) {
296 #ifdef ENABLE_BATTERY
297 battery_low_status
= atoi(value
);
298 if(battery_low_status
< 0 || battery_low_status
> 100)
299 battery_low_status
= 0;
302 else if (strcmp (key
, "battery_low_cmd") == 0) {
303 #ifdef ENABLE_BATTERY
304 if (strlen(value
) > 0)
305 battery_low_cmd
= strdup (value
);
308 else if (strcmp (key
, "bat1_font") == 0) {
309 #ifdef ENABLE_BATTERY
310 if (save_file_config
) old_bat1_font
= strdup (value
);
311 if (bat1_font_desc
) pango_font_description_free(bat1_font_desc
);
312 bat1_font_desc
= pango_font_description_from_string (value
);
315 else if (strcmp (key
, "bat2_font") == 0) {
316 #ifdef ENABLE_BATTERY
317 if (save_file_config
) old_bat2_font
= strdup (value
);
318 if (bat2_font_desc
) pango_font_description_free(bat2_font_desc
);
319 bat2_font_desc
= pango_font_description_from_string (value
);
322 else if (strcmp (key
, "battery_font_color") == 0) {
323 #ifdef ENABLE_BATTERY
324 extract_values(value
, &value1
, &value2
, &value3
);
325 get_color (value1
, panel_config
.battery
.font
.color
);
326 if (value2
) panel_config
.battery
.font
.alpha
= (atoi (value2
) / 100.0);
327 else panel_config
.battery
.font
.alpha
= 0.5;
330 else if (strcmp (key
, "battery_padding") == 0) {
331 #ifdef ENABLE_BATTERY
332 extract_values(value
, &value1
, &value2
, &value3
);
333 panel_config
.battery
.area
.paddingxlr
= panel_config
.battery
.area
.paddingx
= atoi (value1
);
334 if (value2
) panel_config
.battery
.area
.paddingy
= atoi (value2
);
335 if (value3
) panel_config
.battery
.area
.paddingx
= atoi (value3
);
338 else if (strcmp (key
, "battery_background_id") == 0) {
339 #ifdef ENABLE_BATTERY
340 int id
= atoi (value
);
341 Area
*a
= g_slist_nth_data(list_back
, id
);
342 memcpy(&panel_config
.battery
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
343 memcpy(&panel_config
.battery
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
348 else if (strcmp (key
, "time1_format") == 0) {
349 if (strlen(value
) > 0) {
350 time1_format
= strdup (value
);
354 else if (strcmp (key
, "time2_format") == 0) {
355 if (strlen(value
) > 0)
356 time2_format
= strdup (value
);
358 else if (strcmp (key
, "time1_font") == 0) {
359 if (save_file_config
) old_time1_font
= strdup (value
);
360 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
361 time1_font_desc
= pango_font_description_from_string (value
);
363 else if (strcmp (key
, "time2_font") == 0) {
364 if (save_file_config
) old_time2_font
= strdup (value
);
365 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
366 time2_font_desc
= pango_font_description_from_string (value
);
368 else if (strcmp (key
, "clock_font_color") == 0) {
369 extract_values(value
, &value1
, &value2
, &value3
);
370 get_color (value1
, panel_config
.clock
.font
.color
);
371 if (value2
) panel_config
.clock
.font
.alpha
= (atoi (value2
) / 100.0);
372 else panel_config
.clock
.font
.alpha
= 0.5;
374 else if (strcmp (key
, "clock_padding") == 0) {
375 extract_values(value
, &value1
, &value2
, &value3
);
376 panel_config
.clock
.area
.paddingxlr
= panel_config
.clock
.area
.paddingx
= atoi (value1
);
377 if (value2
) panel_config
.clock
.area
.paddingy
= atoi (value2
);
378 if (value3
) panel_config
.clock
.area
.paddingx
= atoi (value3
);
380 else if (strcmp (key
, "clock_background_id") == 0) {
381 int id
= atoi (value
);
382 Area
*a
= g_slist_nth_data(list_back
, id
);
383 memcpy(&panel_config
.clock
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
384 memcpy(&panel_config
.clock
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
386 else if (strcmp(key
, "clock_lclick_command") == 0) {
387 if (strlen(value
) > 0)
388 clock_lclick_command
= strdup(value
);
390 else if (strcmp(key
, "clock_rclick_command") == 0) {
391 if (strlen(value
) > 0)
392 clock_rclick_command
= strdup(value
);
396 else if (strcmp (key
, "taskbar_mode") == 0) {
397 if (strcmp (value
, "multi_desktop") == 0) panel_mode
= MULTI_DESKTOP
;
398 else panel_mode
= SINGLE_DESKTOP
;
400 else if (strcmp (key
, "taskbar_padding") == 0) {
401 extract_values(value
, &value1
, &value2
, &value3
);
402 panel_config
.g_taskbar
.paddingxlr
= panel_config
.g_taskbar
.paddingx
= atoi (value1
);
403 if (value2
) panel_config
.g_taskbar
.paddingy
= atoi (value2
);
404 if (value3
) panel_config
.g_taskbar
.paddingx
= atoi (value3
);
406 else if (strcmp (key
, "taskbar_background_id") == 0) {
407 int id
= atoi (value
);
408 Area
*a
= g_slist_nth_data(list_back
, id
);
409 memcpy(&panel_config
.g_taskbar
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
410 memcpy(&panel_config
.g_taskbar
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
412 else if (strcmp (key
, "taskbar_active_background_id") == 0) {
413 int id
= atoi (value
);
414 Area
*a
= g_slist_nth_data(list_back
, id
);
415 memcpy(&panel_config
.g_taskbar
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
416 memcpy(&panel_config
.g_taskbar
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
417 panel_config
.g_taskbar
.use_active
= 1;
421 else if (strcmp (key
, "task_text") == 0)
422 panel_config
.g_task
.text
= atoi (value
);
423 else if (strcmp (key
, "task_icon") == 0)
424 panel_config
.g_task
.icon
= atoi (value
);
425 else if (strcmp (key
, "task_centered") == 0)
426 panel_config
.g_task
.centered
= atoi (value
);
427 else if (strcmp (key
, "task_width") == 0) {
428 // old parameter : just for backward compatibility
429 panel_config
.g_task
.maximum_width
= atoi (value
);
430 panel_config
.g_task
.maximum_height
= 30;
432 else if (strcmp (key
, "task_maximum_size") == 0) {
433 extract_values(value
, &value1
, &value2
, &value3
);
434 panel_config
.g_task
.maximum_width
= atoi (value1
);
435 panel_config
.g_task
.maximum_height
= 30;
437 panel_config
.g_task
.maximum_height
= atoi (value2
);
439 else if (strcmp (key
, "task_padding") == 0) {
440 extract_values(value
, &value1
, &value2
, &value3
);
441 panel_config
.g_task
.area
.paddingxlr
= panel_config
.g_task
.area
.paddingx
= atoi (value1
);
442 if (value2
) panel_config
.g_task
.area
.paddingy
= atoi (value2
);
443 if (value3
) panel_config
.g_task
.area
.paddingx
= atoi (value3
);
445 else if (strcmp (key
, "task_font") == 0) {
446 if (save_file_config
) old_task_font
= strdup (value
);
447 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
448 panel_config
.g_task
.font_desc
= pango_font_description_from_string (value
);
450 else if (strcmp (key
, "task_font_color") == 0) {
451 extract_values(value
, &value1
, &value2
, &value3
);
452 get_color (value1
, panel_config
.g_task
.font
.color
);
453 if (value2
) panel_config
.g_task
.font
.alpha
= (atoi (value2
) / 100.0);
454 else panel_config
.g_task
.font
.alpha
= 0.1;
456 else if (strcmp (key
, "task_active_font_color") == 0) {
457 extract_values(value
, &value1
, &value2
, &value3
);
458 get_color (value1
, panel_config
.g_task
.font_active
.color
);
459 if (value2
) panel_config
.g_task
.font_active
.alpha
= (atoi (value2
) / 100.0);
460 else panel_config
.g_task
.font_active
.alpha
= 0.1;
462 else if (strcmp (key
, "task_icon_asb") == 0) {
463 extract_values(value
, &value1
, &value2
, &value3
);
464 panel_config
.g_task
.alpha
= atoi(value1
);
465 panel_config
.g_task
.saturation
= atoi(value2
);
466 panel_config
.g_task
.brightness
= atoi(value3
);
468 else if (strcmp (key
, "task_active_icon_asb") == 0) {
469 extract_values(value
, &value1
, &value2
, &value3
);
470 panel_config
.g_task
.alpha_active
= atoi(value1
);
471 panel_config
.g_task
.saturation_active
= atoi(value2
);
472 panel_config
.g_task
.brightness_active
= atoi(value3
);
474 else if (strcmp (key
, "task_background_id") == 0) {
475 int id
= atoi (value
);
476 Area
*a
= g_slist_nth_data(list_back
, id
);
477 memcpy(&panel_config
.g_task
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
478 memcpy(&panel_config
.g_task
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
480 else if (strcmp (key
, "task_active_background_id") == 0) {
481 int id
= atoi (value
);
482 Area
*a
= g_slist_nth_data(list_back
, id
);
483 memcpy(&panel_config
.g_task
.area
.pix_active
.back
, &a
->pix
.back
, sizeof(Color
));
484 memcpy(&panel_config
.g_task
.area
.pix_active
.border
, &a
->pix
.border
, sizeof(Border
));
488 else if (strcmp (key
, "systray") == 0) {
492 else if (strcmp (key
, "systray_padding") == 0) {
493 extract_values(value
, &value1
, &value2
, &value3
);
494 systray
.area
.paddingxlr
= systray
.area
.paddingx
= atoi (value1
);
495 if (value2
) systray
.area
.paddingy
= atoi (value2
);
496 if (value3
) systray
.area
.paddingx
= atoi (value3
);
498 else if (strcmp (key
, "systray_background_id") == 0) {
499 int id
= atoi (value
);
500 Area
*a
= g_slist_nth_data(list_back
, id
);
501 memcpy(&systray
.area
.pix
.back
, &a
->pix
.back
, sizeof(Color
));
502 memcpy(&systray
.area
.pix
.border
, &a
->pix
.border
, sizeof(Border
));
504 else if (strcmp(key
, "systray_sort") == 0) {
505 if (strcmp(value
, "descending") == 0)
507 else if (strcmp(value
, "ascending") == 0)
509 else if (strcmp(value
, "left2right") == 0)
511 else if (strcmp(value
, "right2left") == 0)
516 else if (strcmp (key
, "tooltip") == 0)
517 g_tooltip
.enabled
= atoi(value
);
518 else if (strcmp (key
, "tooltip_show_timeout") == 0) {
519 double timeout
= atof(value
);
520 int sec
= (int)timeout
;
521 int usec
= (timeout
-sec
)*1e6
;
522 g_tooltip
.show_timeout
.it_value
= (struct timeval
){.tv_sec
=sec
, .tv_usec
=usec
};
524 else if (strcmp (key
, "tooltip_hide_timeout") == 0) {
525 double timeout
= atof(value
);
526 int sec
= (int)timeout
;
527 int usec
= (timeout
-sec
)*1e6
;
528 g_tooltip
.hide_timeout
.it_value
= (struct timeval
){.tv_sec
=sec
, .tv_usec
=usec
};
530 else if (strcmp (key
, "tooltip_padding") == 0) {
531 extract_values(value
, &value1
, &value2
, &value3
);
532 if (value1
) g_tooltip
.paddingx
= atoi(value1
);
533 if (value2
) g_tooltip
.paddingy
= atoi(value2
);
535 else if (strcmp (key
, "tooltip_background_id") == 0) {
536 int id
= atoi (value
);
537 Area
*a
= g_slist_nth_data(list_back
, id
);
538 memcpy(&g_tooltip
.background_color
, &a
->pix
.back
, sizeof(Color
));
539 memcpy(&g_tooltip
.border
, &a
->pix
.border
, sizeof(Border
));
541 else if (strcmp (key
, "tooltip_font_color") == 0) {
542 extract_values(value
, &value1
, &value2
, &value3
);
543 get_color(value1
, g_tooltip
.font_color
.color
);
544 if (value2
) g_tooltip
.font_color
.alpha
= (atoi (value2
) / 100.0);
545 else g_tooltip
.font_color
.alpha
= 0.1;
547 else if (strcmp (key
, "tooltip_font") == 0) {
548 if (g_tooltip
.font_desc
) pango_font_description_free(g_tooltip
.font_desc
);
549 g_tooltip
.font_desc
= pango_font_description_from_string(value
);
553 else if (strcmp (key
, "mouse_middle") == 0)
554 get_action (value
, &mouse_middle
);
555 else if (strcmp (key
, "mouse_right") == 0)
556 get_action (value
, &mouse_right
);
557 else if (strcmp (key
, "mouse_scroll_up") == 0)
558 get_action (value
, &mouse_scroll_up
);
559 else if (strcmp (key
, "mouse_scroll_down") == 0)
560 get_action (value
, &mouse_scroll_down
);
563 /* Read tint-0.6 config for backward compatibility */
564 else if (strcmp (key
, "panel_mode") == 0) {
565 save_file_config
= 1;
566 if (strcmp (value
, "single_desktop") == 0) panel_mode
= SINGLE_DESKTOP
;
567 else panel_mode
= MULTI_DESKTOP
;
569 else if (strcmp (key
, "panel_rounded") == 0) {
570 Area
*a
= calloc(1, sizeof(Area
));
571 a
->pix
.border
.rounded
= atoi (value
);
572 list_back
= g_slist_append(list_back
, a
);
574 else if (strcmp (key
, "panel_border_width") == 0) {
575 Area
*a
= g_slist_last(list_back
)->data
;
576 a
->pix
.border
.width
= atoi (value
);
578 else if (strcmp (key
, "panel_background_color") == 0) {
579 Area
*a
= g_slist_last(list_back
)->data
;
580 extract_values(value
, &value1
, &value2
, &value3
);
581 get_color (value1
, a
->pix
.back
.color
);
582 if (value2
) a
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
583 else a
->pix
.back
.alpha
= 0.5;
585 else if (strcmp (key
, "panel_border_color") == 0) {
586 Area
*a
= g_slist_last(list_back
)->data
;
587 extract_values(value
, &value1
, &value2
, &value3
);
588 get_color (value1
, a
->pix
.border
.color
);
589 if (value2
) a
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
590 else a
->pix
.border
.alpha
= 0.5;
592 else if (strcmp (key
, "task_text_centered") == 0)
593 panel_config
.g_task
.centered
= atoi (value
);
594 else if (strcmp (key
, "task_margin") == 0) {
595 panel_config
.g_taskbar
.paddingxlr
= 0;
596 panel_config
.g_taskbar
.paddingx
= atoi (value
);
598 else if (strcmp (key
, "task_icon_size") == 0)
599 old_task_icon_size
= atoi (value
);
600 else if (strcmp (key
, "task_rounded") == 0) {
601 area_task
= calloc(1, sizeof(Area
));
602 area_task
->pix
.border
.rounded
= atoi (value
);
603 list_back
= g_slist_append(list_back
, area_task
);
605 area_task_active
= calloc(1, sizeof(Area
));
606 area_task_active
->pix
.border
.rounded
= atoi (value
);
607 list_back
= g_slist_append(list_back
, area_task_active
);
609 else if (strcmp (key
, "task_background_color") == 0) {
610 extract_values(value
, &value1
, &value2
, &value3
);
611 get_color (value1
, area_task
->pix
.back
.color
);
612 if (value2
) area_task
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
613 else area_task
->pix
.back
.alpha
= 0.5;
615 else if (strcmp (key
, "task_active_background_color") == 0) {
616 extract_values(value
, &value1
, &value2
, &value3
);
617 get_color (value1
, area_task_active
->pix
.back
.color
);
618 if (value2
) area_task_active
->pix
.back
.alpha
= (atoi (value2
) / 100.0);
619 else area_task_active
->pix
.back
.alpha
= 0.5;
621 else if (strcmp (key
, "task_border_width") == 0) {
622 area_task
->pix
.border
.width
= atoi (value
);
623 area_task_active
->pix
.border
.width
= atoi (value
);
625 else if (strcmp (key
, "task_border_color") == 0) {
626 extract_values(value
, &value1
, &value2
, &value3
);
627 get_color (value1
, area_task
->pix
.border
.color
);
628 if (value2
) area_task
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
629 else area_task
->pix
.border
.alpha
= 0.5;
631 else if (strcmp (key
, "task_active_border_color") == 0) {
632 extract_values(value
, &value1
, &value2
, &value3
);
633 get_color (value1
, area_task_active
->pix
.border
.color
);
634 if (value2
) area_task_active
->pix
.border
.alpha
= (atoi (value2
) / 100.0);
635 else area_task_active
->pix
.border
.alpha
= 0.5;
639 fprintf(stderr
, "tint2 : invalid option \"%s\", correct your config file\n", key
);
641 if (value1
) free (value1
);
642 if (value2
) free (value2
);
643 if (value3
) free (value3
);
649 const gchar
* const * system_dirs
;
653 save_file_config
= 0;
655 // follow XDG specification
657 // check tint2rc in user directory
658 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
659 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
660 i
= config_read_file (path1
);
661 config_path
= strdup(path1
);
667 if (save_file_config
) {
668 fprintf(stderr
, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
672 // check old tintrc config file
673 path1
= g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL
);
674 if (g_file_test (path1
, G_FILE_TEST_EXISTS
)) {
675 save_file_config
= 1;
676 config_read_file (path1
);
681 // copy tint2rc from system directory to user directory
684 system_dirs
= g_get_system_config_dirs();
685 for (i
= 0; system_dirs
[i
]; i
++) {
686 path2
= g_build_filename(system_dirs
[i
], "tint2", "tint2rc", NULL
);
688 if (g_file_test(path2
, G_FILE_TEST_EXISTS
)) break;
694 // copy file in user directory (path1)
695 char *dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
696 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
699 path1
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
700 copy_file(path2
, path1
);
703 i
= config_read_file (path1
);
704 config_path
= strdup(path1
);
712 int config_read_file (const char *path
)
718 if ((fp
= fopen(path
, "r")) == NULL
) return 0;
723 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
724 if (parse_line(line
, &key
, &value
)) {
725 add_entry (key
, value
);
732 if (save_file_config
)
736 g_free(old_task_font
);
739 if (old_time1_font
) {
740 g_free(old_time1_font
);
743 if (old_time2_font
) {
744 g_free(old_time2_font
);
753 fprintf(stderr
, "tint2 : convert user's config file\n");
758 if (old_task_icon_size
) {
759 panel_config
.g_task
.area
.paddingy
= ((int)panel_config
.area
.height
- (2 * panel_config
.area
.paddingy
) - old_task_icon_size
) / 2;
762 dir
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
763 if (!g_file_test (dir
, G_FILE_TEST_IS_DIR
)) g_mkdir(dir
, 0777);
766 path
= g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL
);
767 fp
= fopen(path
, "w");
769 if (fp
== NULL
) return;
771 fputs("#---------------------------------------------\n", fp
);
772 fputs("# TINT2 CONFIG FILE\n", fp
);
773 fputs("#---------------------------------------------\n\n", fp
);
774 fputs("#---------------------------------------------\n", fp
);
775 fputs("# BACKGROUND AND BORDER\n", fp
);
776 fputs("#---------------------------------------------\n", fp
);
779 l0
= list_back
->next
;
782 fprintf(fp
, "rounded = %d\n", a
->pix
.border
.rounded
);
783 fprintf(fp
, "border_width = %d\n", a
->pix
.border
.width
);
784 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));
785 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));
790 fputs("#---------------------------------------------\n", fp
);
791 fputs("# PANEL\n", fp
);
792 fputs("#---------------------------------------------\n", fp
);
793 fputs("panel_monitor = all\n", fp
);
794 if (panel_position
& BOTTOM
) fputs("panel_position = bottom", fp
);
795 else fputs("panel_position = top", fp
);
796 if (panel_position
& LEFT
) fputs(" left horizontal\n", fp
);
797 else if (panel_position
& RIGHT
) fputs(" right horizontal\n", fp
);
798 else fputs(" center horizontal\n", fp
);
799 fprintf(fp
, "panel_size = %d %d\n", panel_config
.area
.width
, panel_config
.area
.height
);
800 fprintf(fp
, "panel_margin = %d %d\n", panel_config
.marginx
, panel_config
.marginy
);
801 fprintf(fp
, "panel_padding = %d %d %d\n", panel_config
.area
.paddingxlr
, panel_config
.area
.paddingy
, panel_config
.area
.paddingx
);
802 fprintf(fp
, "font_shadow = %d\n", panel_config
.g_task
.font_shadow
);
803 fputs("panel_background_id = 1\n", fp
);
804 fputs("wm_menu = 0\n", fp
);
806 fputs("\n#---------------------------------------------\n", fp
);
807 fputs("# TASKBAR\n", fp
);
808 fputs("#---------------------------------------------\n", fp
);
809 if (panel_mode
== MULTI_DESKTOP
) fputs("taskbar_mode = multi_desktop\n", fp
);
810 else fputs("taskbar_mode = single_desktop\n", fp
);
811 fprintf(fp
, "taskbar_padding = 0 0 %d\n", panel_config
.g_taskbar
.paddingx
);
812 fputs("taskbar_background_id = 0\n", fp
);
814 fputs("\n#---------------------------------------------\n", fp
);
815 fputs("# TASK\n", fp
);
816 fputs("#---------------------------------------------\n", fp
);
817 if (old_task_icon_size
) fputs("task_icon = 1\n", fp
);
818 else fputs("task_icon = 0\n", fp
);
819 fputs("task_text = 1\n", fp
);
820 fprintf(fp
, "task_maximum_size = %d %d\n", panel_config
.g_task
.maximum_width
, panel_config
.g_task
.maximum_height
);
821 fprintf(fp
, "task_centered = %d\n", panel_config
.g_task
.centered
);
822 fprintf(fp
, "task_padding = %d %d\n", panel_config
.g_task
.area
.paddingx
, panel_config
.g_task
.area
.paddingy
);
823 fprintf(fp
, "task_font = %s\n", old_task_font
);
824 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));
825 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));
826 fputs("task_background_id = 2\n", fp
);
827 fputs("task_active_background_id = 3\n", fp
);
829 fputs("\n#---------------------------------------------\n", fp
);
830 fputs("# SYSTRAYBAR\n", fp
);
831 fputs("#---------------------------------------------\n", fp
);
832 fputs("systray_padding = 4 3 4\n", fp
);
833 fputs("systray_background_id = 0\n", fp
);
835 fputs("\n#---------------------------------------------\n", fp
);
836 fputs("# CLOCK\n", fp
);
837 fputs("#---------------------------------------------\n", fp
);
838 if (time1_format
) fprintf(fp
, "time1_format = %s\n", time1_format
);
839 else fputs("#time1_format = %H:%M\n", fp
);
840 fprintf(fp
, "time1_font = %s\n", old_time1_font
);
841 if (time2_format
) fprintf(fp
, "time2_format = %s\n", time2_format
);
842 else fputs("#time2_format = %A %d %B\n", fp
);
843 fprintf(fp
, "time2_font = %s\n", old_time2_font
);
844 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));
845 fputs("clock_padding = 2 2\n", fp
);
846 fputs("clock_background_id = 0\n", fp
);
847 fputs("#clock_lclick_command = xclock\n", fp
);
848 fputs("clock_rclick_command = orage\n", fp
);
850 #ifdef ENABLE_BATTERY
851 fputs("\n#---------------------------------------------\n", fp
);
852 fputs("# BATTERY\n", fp
);
853 fputs("#---------------------------------------------\n", fp
);
854 fprintf(fp
, "battery = %d\n", panel_config
.battery
.area
.on_screen
);
855 fprintf(fp
, "battery_low_status = %d\n", battery_low_status
);
856 fprintf(fp
, "battery_low_cmd = %s\n", battery_low_cmd
);
857 fprintf(fp
, "bat1_font = %s\n", old_bat1_font
);
858 fprintf(fp
, "bat2_font = %s\n", old_bat2_font
);
859 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));
860 fputs("battery_padding = 2 2\n", fp
);
861 fputs("battery_background_id = 0\n", fp
);
864 fputs("\n#---------------------------------------------\n", fp
);
865 fputs("# MOUSE ACTION ON TASK\n", fp
);
866 fputs("#---------------------------------------------\n", fp
);
867 if (mouse_middle
== NONE
) fputs("mouse_middle = none\n", fp
);
868 else if (mouse_middle
== CLOSE
) fputs("mouse_middle = close\n", fp
);
869 else if (mouse_middle
== TOGGLE
) fputs("mouse_middle = toggle\n", fp
);
870 else if (mouse_middle
== ICONIFY
) fputs("mouse_middle = iconify\n", fp
);
871 else if (mouse_middle
== SHADE
) fputs("mouse_middle = shade\n", fp
);
872 else fputs("mouse_middle = toggle_iconify\n", fp
);
874 if (mouse_right
== NONE
) fputs("mouse_right = none\n", fp
);
875 else if (mouse_right
== CLOSE
) fputs("mouse_right = close\n", fp
);
876 else if (mouse_right
== TOGGLE
) fputs("mouse_right = toggle\n", fp
);
877 else if (mouse_right
== ICONIFY
) fputs("mouse_right = iconify\n", fp
);
878 else if (mouse_right
== SHADE
) fputs("mouse_right = shade\n", fp
);
879 else fputs("mouse_right = toggle_iconify\n", fp
);
881 if (mouse_scroll_up
== NONE
) fputs("mouse_scroll_up = none\n", fp
);
882 else if (mouse_scroll_up
== CLOSE
) fputs("mouse_scroll_up = close\n", fp
);
883 else if (mouse_scroll_up
== TOGGLE
) fputs("mouse_scroll_up = toggle\n", fp
);
884 else if (mouse_scroll_up
== ICONIFY
) fputs("mouse_scroll_up = iconify\n", fp
);
885 else if (mouse_scroll_up
== SHADE
) fputs("mouse_scroll_up = shade\n", fp
);
886 else fputs("mouse_scroll_up = toggle_iconify\n", fp
);
888 if (mouse_scroll_down
== NONE
) fputs("mouse_scroll_down = none\n", fp
);
889 else if (mouse_scroll_down
== CLOSE
) fputs("mouse_scroll_down = close\n", fp
);
890 else if (mouse_scroll_down
== TOGGLE
) fputs("mouse_scroll_down = toggle\n", fp
);
891 else if (mouse_scroll_down
== ICONIFY
) fputs("mouse_scroll_down = iconify\n", fp
);
892 else if (mouse_scroll_down
== SHADE
) fputs("mouse_scroll_down = shade\n", fp
);
893 else fputs("mouse_scroll_down = toggle_iconify\n", fp
);
This page took 0.093188 seconds and 5 git commands to generate.