]> Dogcows Code - chaz/tint2/blob - src/config.c
*add* clock supports timezones
[chaz/tint2] / src / config.c
1 /**************************************************************************
2 *
3 * Tint2 : read/write config file
4 *
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
7 *
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.
11 *
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 **************************************************************************/
20
21 #include <sys/stat.h>
22 #include <sys/time.h>
23 #include <unistd.h>
24 #include <cairo.h>
25 #include <cairo-xlib.h>
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <glib/gstdio.h>
34 #include <pango/pangocairo.h>
35 #include <pango/pangoxft.h>
36 #include <Imlib2.h>
37
38 #include "common.h"
39 #include "server.h"
40 #include "panel.h"
41 #include "task.h"
42 #include "taskbar.h"
43 #include "systraybar.h"
44 #include "clock.h"
45 #include "config.h"
46 #include "window.h"
47 #include "tooltip.h"
48 #include "timer.h"
49
50 #ifdef ENABLE_BATTERY
51 #include "battery.h"
52 #endif
53
54 // global path
55 char *config_path = 0;
56 char *snapshot_path = 0;
57
58 // --------------------------------------------------
59 // backward compatibility
60 static int old_task_icon_size;
61 static Area *area_task;
62 static Area *area_task_active;
63 // detect if it's an old config file
64 // ==1
65 static int old_config_file;
66
67 // temporary list of background
68 static GSList *list_back;
69
70
71
72 void init_config()
73 {
74 // append full transparency background
75 list_back = g_slist_append(0, calloc(1, sizeof(Area)));
76
77 // tint2 could reload config, so we cleanup objects
78 cleanup_systray();
79 #ifdef ENABLE_BATTERY
80 cleanup_battery();
81 #endif
82 cleanup_clock();
83 cleanup_tooltip();
84
85 // panel's default value
86 if (panel_config.g_task.font_desc) {
87 pango_font_description_free(panel_config.g_task.font_desc);
88 }
89 memset(&panel_config, 0, sizeof(Panel));
90 panel_config.g_task.alpha = 100;
91 panel_config.g_task.alpha_active = 100;
92 systray.sort = 3;
93 old_config_file = 1;
94
95 // window manager's menu default value == false
96 wm_menu = 0;
97 max_tick_urgent = 7;
98
99 // flush pango cache if possible
100 //pango_xft_shutdown_display(server.dsp, server.screen);
101 //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen);
102 //pango_fc_font_map_shutdown(font_map);
103 }
104
105
106 void cleanup_config()
107 {
108 // cleanup background list
109 GSList *l0;
110 for (l0 = list_back; l0 ; l0 = l0->next) {
111 free(l0->data);
112 }
113 g_slist_free(list_back);
114 list_back = NULL;
115 }
116
117
118 void extract_values (const char *value, char **value1, char **value2, char **value3)
119 {
120 char *b=0, *c=0;
121
122 if (*value1) free (*value1);
123 if (*value2) free (*value2);
124 if (*value3) free (*value3);
125
126 if ((b = strchr (value, ' '))) {
127 b[0] = '\0';
128 b++;
129 }
130 else {
131 *value2 = 0;
132 *value3 = 0;
133 }
134 *value1 = strdup (value);
135 g_strstrip(*value1);
136
137 if (b) {
138 if ((c = strchr (b, ' '))) {
139 c[0] = '\0';
140 c++;
141 }
142 else {
143 c = 0;
144 *value3 = 0;
145 }
146 *value2 = strdup (b);
147 g_strstrip(*value2);
148 }
149
150 if (c) {
151 *value3 = strdup (c);
152 g_strstrip(*value3);
153 }
154 }
155
156
157 void get_action (char *event, int *action)
158 {
159 if (strcmp (event, "none") == 0)
160 *action = NONE;
161 else if (strcmp (event, "close") == 0)
162 *action = CLOSE;
163 else if (strcmp (event, "toggle") == 0)
164 *action = TOGGLE;
165 else if (strcmp (event, "iconify") == 0)
166 *action = ICONIFY;
167 else if (strcmp (event, "shade") == 0)
168 *action = SHADE;
169 else if (strcmp (event, "toggle_iconify") == 0)
170 *action = TOGGLE_ICONIFY;
171 else if (strcmp (event, "maximize_restore") == 0)
172 *action = MAXIMIZE_RESTORE;
173 else if (strcmp (event, "desktop_left") == 0)
174 *action = DESKTOP_LEFT;
175 else if (strcmp (event, "desktop_right") == 0)
176 *action = DESKTOP_RIGHT;
177 else if (strcmp (event, "next_task") == 0)
178 *action = NEXT_TASK;
179 else if (strcmp (event, "prev_task") == 0)
180 *action = PREV_TASK;
181 }
182
183
184 void add_entry (char *key, char *value)
185 {
186 char *value1=0, *value2=0, *value3=0;
187
188 /* Background and border */
189 if (strcmp (key, "rounded") == 0) {
190 // 'rounded' is the first parameter => alloc a new background
191 Area *a = calloc(1, sizeof(Area));
192 a->pix.border.rounded = atoi (value);
193 list_back = g_slist_append(list_back, a);
194 }
195 else if (strcmp (key, "border_width") == 0) {
196 Area *a = g_slist_last(list_back)->data;
197 a->pix.border.width = atoi (value);
198 }
199 else if (strcmp (key, "background_color") == 0) {
200 Area *a = g_slist_last(list_back)->data;
201 extract_values(value, &value1, &value2, &value3);
202 get_color (value1, a->pix.back.color);
203 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
204 else a->pix.back.alpha = 0.5;
205 }
206 else if (strcmp (key, "border_color") == 0) {
207 Area *a = g_slist_last(list_back)->data;
208 extract_values(value, &value1, &value2, &value3);
209 get_color (value1, a->pix.border.color);
210 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
211 else a->pix.border.alpha = 0.5;
212 }
213
214 /* Panel */
215 else if (strcmp (key, "panel_monitor") == 0) {
216 if (strcmp (value, "all") == 0) panel_config.monitor = -1;
217 else {
218 panel_config.monitor = atoi (value);
219 if (panel_config.monitor > 0) panel_config.monitor -= 1;
220 }
221 if (panel_config.monitor > (server.nb_monitor-1)) {
222 // server.nb_monitor minimum value is 1 (see get_monitors())
223 fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n");
224 panel_config.monitor = 0;
225 }
226 }
227 else if (strcmp (key, "panel_size") == 0) {
228 extract_values(value, &value1, &value2, &value3);
229
230 char *b;
231 if ((b = strchr (value1, '%'))) {
232 b[0] = '\0';
233 panel_config.pourcentx = 1;
234 }
235 panel_config.area.width = atoi(value1);
236 if (panel_config.area.width == 0) {
237 // full width mode
238 panel_config.area.width = 100;
239 panel_config.pourcentx = 1;
240 }
241 if (value2) {
242 if ((b = strchr (value2, '%'))) {
243 b[0] = '\0';
244 panel_config.pourcenty = 1;
245 }
246 panel_config.area.height = atoi(value2);
247 }
248 }
249 else if (strcmp (key, "panel_margin") == 0) {
250 extract_values(value, &value1, &value2, &value3);
251 panel_config.marginx = atoi (value1);
252 if (value2) panel_config.marginy = atoi (value2);
253 }
254 else if (strcmp (key, "panel_padding") == 0) {
255 extract_values(value, &value1, &value2, &value3);
256 panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
257 if (value2) panel_config.area.paddingy = atoi (value2);
258 if (value3) panel_config.area.paddingx = atoi (value3);
259 }
260 else if (strcmp (key, "panel_position") == 0) {
261 extract_values(value, &value1, &value2, &value3);
262 if (strcmp (value1, "top") == 0) panel_position = TOP;
263 else {
264 if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
265 else panel_position = CENTER;
266 }
267
268 if (!value2) panel_position |= CENTER;
269 else {
270 if (strcmp (value2, "left") == 0) panel_position |= LEFT;
271 else {
272 if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
273 else panel_position |= CENTER;
274 }
275 }
276 if (!value3) panel_horizontal = 1;
277 else {
278 if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
279 else panel_horizontal = 1;
280 }
281 }
282 else if (strcmp (key, "font_shadow") == 0)
283 panel_config.g_task.font_shadow = atoi (value);
284 else if (strcmp (key, "panel_background_id") == 0) {
285 int id = atoi (value);
286 Area *a = g_slist_nth_data(list_back, id);
287 memcpy(&panel_config.area.pix.back, &a->pix.back, sizeof(Color));
288 memcpy(&panel_config.area.pix.border, &a->pix.border, sizeof(Border));
289 }
290 else if (strcmp (key, "wm_menu") == 0)
291 wm_menu = atoi (value);
292 else if (strcmp (key, "panel_dock") == 0)
293 panel_dock = atoi (value);
294 else if (strcmp (key, "urgent_nb_of_blink") == 0)
295 max_tick_urgent = (atoi (value) * 2) + 1;
296
297 /* Battery */
298 else if (strcmp (key, "battery") == 0) {
299 #ifdef ENABLE_BATTERY
300 if(atoi(value) == 1)
301 battery_enabled = 1;
302 #else
303 if(atoi(value) == 1)
304 fprintf(stderr, "tint2 is build without battery support\n");
305 #endif
306 }
307 else if (strcmp (key, "battery_low_status") == 0) {
308 #ifdef ENABLE_BATTERY
309 battery_low_status = atoi(value);
310 if(battery_low_status < 0 || battery_low_status > 100)
311 battery_low_status = 0;
312 #endif
313 }
314 else if (strcmp (key, "battery_low_cmd") == 0) {
315 #ifdef ENABLE_BATTERY
316 if (strlen(value) > 0)
317 battery_low_cmd = strdup (value);
318 #endif
319 }
320 else if (strcmp (key, "bat1_font") == 0) {
321 #ifdef ENABLE_BATTERY
322 bat1_font_desc = pango_font_description_from_string (value);
323 #endif
324 }
325 else if (strcmp (key, "bat2_font") == 0) {
326 #ifdef ENABLE_BATTERY
327 bat2_font_desc = pango_font_description_from_string (value);
328 #endif
329 }
330 else if (strcmp (key, "battery_font_color") == 0) {
331 #ifdef ENABLE_BATTERY
332 extract_values(value, &value1, &value2, &value3);
333 get_color (value1, panel_config.battery.font.color);
334 if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
335 else panel_config.battery.font.alpha = 0.5;
336 #endif
337 }
338 else if (strcmp (key, "battery_padding") == 0) {
339 #ifdef ENABLE_BATTERY
340 extract_values(value, &value1, &value2, &value3);
341 panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
342 if (value2) panel_config.battery.area.paddingy = atoi (value2);
343 if (value3) panel_config.battery.area.paddingx = atoi (value3);
344 #endif
345 }
346 else if (strcmp (key, "battery_background_id") == 0) {
347 #ifdef ENABLE_BATTERY
348 int id = atoi (value);
349 Area *a = g_slist_nth_data(list_back, id);
350 memcpy(&panel_config.battery.area.pix.back, &a->pix.back, sizeof(Color));
351 memcpy(&panel_config.battery.area.pix.border, &a->pix.border, sizeof(Border));
352 #endif
353 }
354
355 /* Clock */
356 else if (strcmp (key, "time1_format") == 0) {
357 if (strlen(value) > 0) {
358 time1_format = strdup (value);
359 clock_enabled = 1;
360 }
361 }
362 else if (strcmp (key, "time2_format") == 0) {
363 if (strlen(value) > 0)
364 time2_format = strdup (value);
365 }
366 else if (strcmp (key, "time1_font") == 0) {
367 time1_font_desc = pango_font_description_from_string (value);
368 }
369 else if (strcmp(key, "time1_timezone") == 0) {
370 if (strlen(value) > 0)
371 time1_timezone = strdup(value);
372 }
373 else if (strcmp(key, "time2_timezone") == 0) {
374 if (strlen(value) > 0)
375 time2_timezone = strdup(value);
376 }
377 else if (strcmp (key, "time2_font") == 0) {
378 time2_font_desc = pango_font_description_from_string (value);
379 }
380 else if (strcmp (key, "clock_font_color") == 0) {
381 extract_values(value, &value1, &value2, &value3);
382 get_color (value1, panel_config.clock.font.color);
383 if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
384 else panel_config.clock.font.alpha = 0.5;
385 }
386 else if (strcmp (key, "clock_padding") == 0) {
387 extract_values(value, &value1, &value2, &value3);
388 panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
389 if (value2) panel_config.clock.area.paddingy = atoi (value2);
390 if (value3) panel_config.clock.area.paddingx = atoi (value3);
391 }
392 else if (strcmp (key, "clock_background_id") == 0) {
393 int id = atoi (value);
394 Area *a = g_slist_nth_data(list_back, id);
395 memcpy(&panel_config.clock.area.pix.back, &a->pix.back, sizeof(Color));
396 memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border));
397 }
398 else if (strcmp(key, "clock_tooltip") == 0) {
399 if (strlen(value) > 0)
400 time_tooltip_format = strdup (value);
401 }
402 else if (strcmp(key, "clock_tooltip_timezone") == 0) {
403 if (strlen(value) > 0)
404 time_tooltip_timezone = strdup(value);
405 }
406 else if (strcmp(key, "clock_lclick_command") == 0) {
407 if (strlen(value) > 0)
408 clock_lclick_command = strdup(value);
409 }
410 else if (strcmp(key, "clock_rclick_command") == 0) {
411 if (strlen(value) > 0)
412 clock_rclick_command = strdup(value);
413 }
414
415 /* Taskbar */
416 else if (strcmp (key, "taskbar_mode") == 0) {
417 if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
418 else panel_mode = SINGLE_DESKTOP;
419 }
420 else if (strcmp (key, "taskbar_padding") == 0) {
421 extract_values(value, &value1, &value2, &value3);
422 panel_config.g_taskbar.paddingxlr = panel_config.g_taskbar.paddingx = atoi (value1);
423 if (value2) panel_config.g_taskbar.paddingy = atoi (value2);
424 if (value3) panel_config.g_taskbar.paddingx = atoi (value3);
425 }
426 else if (strcmp (key, "taskbar_background_id") == 0) {
427 int id = atoi (value);
428 Area *a = g_slist_nth_data(list_back, id);
429 memcpy(&panel_config.g_taskbar.pix.back, &a->pix.back, sizeof(Color));
430 memcpy(&panel_config.g_taskbar.pix.border, &a->pix.border, sizeof(Border));
431 }
432 else if (strcmp (key, "taskbar_active_background_id") == 0) {
433 int id = atoi (value);
434 Area *a = g_slist_nth_data(list_back, id);
435 memcpy(&panel_config.g_taskbar.pix_active.back, &a->pix.back, sizeof(Color));
436 memcpy(&panel_config.g_taskbar.pix_active.border, &a->pix.border, sizeof(Border));
437 panel_config.g_taskbar.use_active = 1;
438 }
439
440 /* Task */
441 else if (strcmp (key, "task_text") == 0)
442 panel_config.g_task.text = atoi (value);
443 else if (strcmp (key, "task_icon") == 0)
444 panel_config.g_task.icon = atoi (value);
445 else if (strcmp (key, "task_centered") == 0)
446 panel_config.g_task.centered = atoi (value);
447 else if (strcmp (key, "task_width") == 0) {
448 // old parameter : just for backward compatibility
449 panel_config.g_task.maximum_width = atoi (value);
450 panel_config.g_task.maximum_height = 30;
451 }
452 else if (strcmp (key, "task_maximum_size") == 0) {
453 extract_values(value, &value1, &value2, &value3);
454 panel_config.g_task.maximum_width = atoi (value1);
455 panel_config.g_task.maximum_height = 30;
456 if (value2)
457 panel_config.g_task.maximum_height = atoi (value2);
458 }
459 else if (strcmp (key, "task_padding") == 0) {
460 extract_values(value, &value1, &value2, &value3);
461 panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
462 if (value2) panel_config.g_task.area.paddingy = atoi (value2);
463 if (value3) panel_config.g_task.area.paddingx = atoi (value3);
464 }
465 else if (strcmp (key, "task_font") == 0) {
466 panel_config.g_task.font_desc = pango_font_description_from_string (value);
467 }
468 else if (strcmp (key, "task_font_color") == 0) {
469 extract_values(value, &value1, &value2, &value3);
470 get_color (value1, panel_config.g_task.font.color);
471 if (value2) panel_config.g_task.font.alpha = (atoi (value2) / 100.0);
472 else panel_config.g_task.font.alpha = 0.1;
473 }
474 else if (strcmp (key, "task_active_font_color") == 0) {
475 extract_values(value, &value1, &value2, &value3);
476 get_color (value1, panel_config.g_task.font_active.color);
477 if (value2) panel_config.g_task.font_active.alpha = (atoi (value2) / 100.0);
478 else panel_config.g_task.font_active.alpha = 0.1;
479 }
480 else if (strcmp (key, "task_icon_asb") == 0) {
481 extract_values(value, &value1, &value2, &value3);
482 panel_config.g_task.alpha = atoi(value1);
483 panel_config.g_task.saturation = atoi(value2);
484 panel_config.g_task.brightness = atoi(value3);
485 }
486 else if (strcmp (key, "task_active_icon_asb") == 0) {
487 extract_values(value, &value1, &value2, &value3);
488 panel_config.g_task.alpha_active = atoi(value1);
489 panel_config.g_task.saturation_active = atoi(value2);
490 panel_config.g_task.brightness_active = atoi(value3);
491 }
492 else if (strcmp (key, "task_background_id") == 0) {
493 int id = atoi (value);
494 Area *a = g_slist_nth_data(list_back, id);
495 memcpy(&panel_config.g_task.area.pix.back, &a->pix.back, sizeof(Color));
496 memcpy(&panel_config.g_task.area.pix.border, &a->pix.border, sizeof(Border));
497 }
498 else if (strcmp (key, "task_active_background_id") == 0) {
499 int id = atoi (value);
500 Area *a = g_slist_nth_data(list_back, id);
501 memcpy(&panel_config.g_task.area.pix_active.back, &a->pix.back, sizeof(Color));
502 memcpy(&panel_config.g_task.area.pix_active.border, &a->pix.border, sizeof(Border));
503 }
504
505 /* Systray */
506 else if (strcmp (key, "systray") == 0) {
507 systray_enabled = atoi(value);
508 // systray is latest option added. files without 'systray' are old.
509 old_config_file = 0;
510 }
511 else if (strcmp (key, "systray_padding") == 0) {
512 if (old_config_file)
513 systray_enabled = 1;
514 extract_values(value, &value1, &value2, &value3);
515 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
516 if (value2) systray.area.paddingy = atoi (value2);
517 if (value3) systray.area.paddingx = atoi (value3);
518 }
519 else if (strcmp (key, "systray_background_id") == 0) {
520 int id = atoi (value);
521 Area *a = g_slist_nth_data(list_back, id);
522 memcpy(&systray.area.pix.back, &a->pix.back, sizeof(Color));
523 memcpy(&systray.area.pix.border, &a->pix.border, sizeof(Border));
524 }
525 else if (strcmp(key, "systray_sort") == 0) {
526 if (strcmp(value, "descending") == 0)
527 systray.sort = -1;
528 else if (strcmp(value, "ascending") == 0)
529 systray.sort = 1;
530 else if (strcmp(value, "left2right") == 0)
531 systray.sort = 2;
532 else if (strcmp(value, "right2left") == 0)
533 systray.sort = 3;
534 }
535
536 /* Tooltip */
537 else if (strcmp (key, "tooltip") == 0)
538 g_tooltip.enabled = atoi(value);
539 else if (strcmp (key, "tooltip_show_timeout") == 0) {
540 int timeout_msec = 1000*atof(value);
541 g_tooltip.show_timeout_msec = timeout_msec;
542 }
543 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
544 int timeout_msec = 1000*atof(value);
545 g_tooltip.hide_timeout_msec = timeout_msec;
546 }
547 else if (strcmp (key, "tooltip_padding") == 0) {
548 extract_values(value, &value1, &value2, &value3);
549 if (value1) g_tooltip.paddingx = atoi(value1);
550 if (value2) g_tooltip.paddingy = atoi(value2);
551 }
552 else if (strcmp (key, "tooltip_background_id") == 0) {
553 int id = atoi (value);
554 Area *a = g_slist_nth_data(list_back, id);
555 memcpy(&g_tooltip.background_color, &a->pix.back, sizeof(Color));
556 memcpy(&g_tooltip.border, &a->pix.border, sizeof(Border));
557 }
558 else if (strcmp (key, "tooltip_font_color") == 0) {
559 extract_values(value, &value1, &value2, &value3);
560 get_color(value1, g_tooltip.font_color.color);
561 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
562 else g_tooltip.font_color.alpha = 0.1;
563 }
564 else if (strcmp (key, "tooltip_font") == 0) {
565 g_tooltip.font_desc = pango_font_description_from_string(value);
566 }
567
568 /* Mouse actions */
569 else if (strcmp (key, "mouse_middle") == 0)
570 get_action (value, &mouse_middle);
571 else if (strcmp (key, "mouse_right") == 0)
572 get_action (value, &mouse_right);
573 else if (strcmp (key, "mouse_scroll_up") == 0)
574 get_action (value, &mouse_scroll_up);
575 else if (strcmp (key, "mouse_scroll_down") == 0)
576 get_action (value, &mouse_scroll_down);
577
578
579 /* Read tint-0.6 config for backward compatibility */
580 else if (strcmp (key, "panel_mode") == 0) {
581 if (strcmp (value, "single_desktop") == 0) panel_mode = SINGLE_DESKTOP;
582 else panel_mode = MULTI_DESKTOP;
583 }
584 else if (strcmp (key, "panel_rounded") == 0) {
585 Area *a = calloc(1, sizeof(Area));
586 a->pix.border.rounded = atoi (value);
587 list_back = g_slist_append(list_back, a);
588 }
589 else if (strcmp (key, "panel_border_width") == 0) {
590 Area *a = g_slist_last(list_back)->data;
591 a->pix.border.width = atoi (value);
592 }
593 else if (strcmp (key, "panel_background_color") == 0) {
594 Area *a = g_slist_last(list_back)->data;
595 extract_values(value, &value1, &value2, &value3);
596 get_color (value1, a->pix.back.color);
597 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
598 else a->pix.back.alpha = 0.5;
599 }
600 else if (strcmp (key, "panel_border_color") == 0) {
601 Area *a = g_slist_last(list_back)->data;
602 extract_values(value, &value1, &value2, &value3);
603 get_color (value1, a->pix.border.color);
604 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
605 else a->pix.border.alpha = 0.5;
606 }
607 else if (strcmp (key, "task_text_centered") == 0)
608 panel_config.g_task.centered = atoi (value);
609 else if (strcmp (key, "task_margin") == 0) {
610 panel_config.g_taskbar.paddingxlr = 0;
611 panel_config.g_taskbar.paddingx = atoi (value);
612 }
613 else if (strcmp (key, "task_icon_size") == 0)
614 old_task_icon_size = atoi (value);
615 else if (strcmp (key, "task_rounded") == 0) {
616 area_task = calloc(1, sizeof(Area));
617 area_task->pix.border.rounded = atoi (value);
618 list_back = g_slist_append(list_back, area_task);
619
620 area_task_active = calloc(1, sizeof(Area));
621 area_task_active->pix.border.rounded = atoi (value);
622 list_back = g_slist_append(list_back, area_task_active);
623 }
624 else if (strcmp (key, "task_background_color") == 0) {
625 extract_values(value, &value1, &value2, &value3);
626 get_color (value1, area_task->pix.back.color);
627 if (value2) area_task->pix.back.alpha = (atoi (value2) / 100.0);
628 else area_task->pix.back.alpha = 0.5;
629 }
630 else if (strcmp (key, "task_active_background_color") == 0) {
631 extract_values(value, &value1, &value2, &value3);
632 get_color (value1, area_task_active->pix.back.color);
633 if (value2) area_task_active->pix.back.alpha = (atoi (value2) / 100.0);
634 else area_task_active->pix.back.alpha = 0.5;
635 }
636 else if (strcmp (key, "task_border_width") == 0) {
637 area_task->pix.border.width = atoi (value);
638 area_task_active->pix.border.width = atoi (value);
639 }
640 else if (strcmp (key, "task_border_color") == 0) {
641 extract_values(value, &value1, &value2, &value3);
642 get_color (value1, area_task->pix.border.color);
643 if (value2) area_task->pix.border.alpha = (atoi (value2) / 100.0);
644 else area_task->pix.border.alpha = 0.5;
645 }
646 else if (strcmp (key, "task_active_border_color") == 0) {
647 extract_values(value, &value1, &value2, &value3);
648 get_color (value1, area_task_active->pix.border.color);
649 if (value2) area_task_active->pix.border.alpha = (atoi (value2) / 100.0);
650 else area_task_active->pix.border.alpha = 0.5;
651 }
652
653 else
654 fprintf(stderr, "tint2 : invalid option \"%s\", correct your config file\n", key);
655
656 if (value1) free (value1);
657 if (value2) free (value2);
658 if (value3) free (value3);
659 }
660
661
662 int config_read ()
663 {
664 const gchar * const * system_dirs;
665 char *path1;
666 gint i;
667
668 // follow XDG specification
669 // check tint2rc in user directory
670 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
671 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
672 i = config_read_file (path1);
673 config_path = strdup(path1);
674 g_free(path1);
675 return i;
676 }
677 g_free(path1);
678
679 // copy tint2rc from system directory to user directory
680 char *path2 = 0;
681 system_dirs = g_get_system_config_dirs();
682 for (i = 0; system_dirs[i]; i++) {
683 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
684
685 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
686 g_free (path2);
687 path2 = 0;
688 }
689
690 if (path2) {
691 // copy file in user directory (path1)
692 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
693 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
694 g_free(dir);
695
696 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
697 copy_file(path2, path1);
698 g_free(path2);
699
700 i = config_read_file (path1);
701 config_path = strdup(path1);
702 g_free(path1);
703 return i;
704 }
705 return 0;
706 }
707
708
709 int config_read_file (const char *path)
710 {
711 FILE *fp;
712 char line[512];
713 char *key, *value;
714
715 if ((fp = fopen(path, "r")) == NULL) return 0;
716
717 while (fgets(line, sizeof(line), fp) != NULL) {
718 if (parse_line(line, &key, &value)) {
719 add_entry (key, value);
720 free (key);
721 free (value);
722 }
723 }
724 fclose (fp);
725
726 if (old_task_icon_size) {
727 panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
728 }
729 return 1;
730 }
731
732
733
This page took 0.078822 seconds and 5 git commands to generate.