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