]> Dogcows Code - chaz/tint2/blob - src/config.c
*fix* issue 213
[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 // detect if it's an old config file
62 // ==1
63 static int old_config_file;
64
65
66 void init_config()
67 {
68 if (backgrounds)
69 g_array_free(backgrounds, 1);
70 backgrounds = g_array_new(0, 0, sizeof(Background));
71
72 // append full transparency background
73 Background transparent_bg;
74 memset(&transparent_bg, 0, sizeof(Background));
75 g_array_append_val(backgrounds, transparent_bg);
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 int i;
91 for (i=0; i<TASK_STATE_COUNT; ++i)
92 panel_config.g_task.alpha[i] = 100;
93 systray.alpha = 100;
94 systray.sort = 3;
95 old_config_file = 1;
96
97 // window manager's menu default value == false
98 wm_menu = 0;
99 max_tick_urgent = 7;
100 panel_config.g_taskbar.bg = panel_config.g_taskbar.bg_active = 0;
101
102 // flush pango cache if possible
103 //pango_xft_shutdown_display(server.dsp, server.screen);
104 //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen);
105 //pango_fc_font_map_shutdown(font_map);
106 }
107
108
109 void cleanup_config()
110 {
111 }
112
113
114 void extract_values (const char *value, char **value1, char **value2, char **value3)
115 {
116 char *b=0, *c=0;
117
118 if (*value1) free (*value1);
119 if (*value2) free (*value2);
120 if (*value3) free (*value3);
121
122 if ((b = strchr (value, ' '))) {
123 b[0] = '\0';
124 b++;
125 }
126 else {
127 *value2 = 0;
128 *value3 = 0;
129 }
130 *value1 = strdup (value);
131 g_strstrip(*value1);
132
133 if (b) {
134 if ((c = strchr (b, ' '))) {
135 c[0] = '\0';
136 c++;
137 }
138 else {
139 c = 0;
140 *value3 = 0;
141 }
142 *value2 = strdup (b);
143 g_strstrip(*value2);
144 }
145
146 if (c) {
147 *value3 = strdup (c);
148 g_strstrip(*value3);
149 }
150 }
151
152
153 void get_action (char *event, int *action)
154 {
155 if (strcmp (event, "none") == 0)
156 *action = NONE;
157 else if (strcmp (event, "close") == 0)
158 *action = CLOSE;
159 else if (strcmp (event, "toggle") == 0)
160 *action = TOGGLE;
161 else if (strcmp (event, "iconify") == 0)
162 *action = ICONIFY;
163 else if (strcmp (event, "shade") == 0)
164 *action = SHADE;
165 else if (strcmp (event, "toggle_iconify") == 0)
166 *action = TOGGLE_ICONIFY;
167 else if (strcmp (event, "maximize_restore") == 0)
168 *action = MAXIMIZE_RESTORE;
169 else if (strcmp (event, "desktop_left") == 0)
170 *action = DESKTOP_LEFT;
171 else if (strcmp (event, "desktop_right") == 0)
172 *action = DESKTOP_RIGHT;
173 else if (strcmp (event, "next_task") == 0)
174 *action = NEXT_TASK;
175 else if (strcmp (event, "prev_task") == 0)
176 *action = PREV_TASK;
177 }
178
179
180 int get_task_status(char* status)
181 {
182 if (strcmp(status, "active") == 0)
183 return TASK_ACTIVE;
184 if (strcmp(status, "iconified") == 0)
185 return TASK_ICONIFIED;
186 if (strcmp(status, "urgent") == 0)
187 return TASK_URGENT;
188 return TASK_NORMAL;
189 }
190
191
192 void add_entry (char *key, char *value)
193 {
194 char *value1=0, *value2=0, *value3=0;
195
196 /* Background and border */
197 if (strcmp (key, "rounded") == 0) {
198 // 'rounded' is the first parameter => alloc a new background
199 Background bg;
200 bg.border.rounded = atoi(value);
201 g_array_append_val(backgrounds, bg);
202 }
203 else if (strcmp (key, "border_width") == 0) {
204 g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
205 }
206 else if (strcmp (key, "background_color") == 0) {
207 Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
208 extract_values(value, &value1, &value2, &value3);
209 get_color (value1, bg->back.color);
210 if (value2) bg->back.alpha = (atoi (value2) / 100.0);
211 else bg->back.alpha = 0.5;
212 }
213 else if (strcmp (key, "border_color") == 0) {
214 Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
215 extract_values(value, &value1, &value2, &value3);
216 get_color (value1, bg->border.color);
217 if (value2) bg->border.alpha = (atoi (value2) / 100.0);
218 else bg->border.alpha = 0.5;
219 }
220
221 /* Panel */
222 else if (strcmp (key, "panel_monitor") == 0) {
223 if (strcmp (value, "all") == 0) panel_config.monitor = -1;
224 else {
225 panel_config.monitor = atoi (value);
226 if (panel_config.monitor > 0) panel_config.monitor -= 1;
227 }
228 }
229 else if (strcmp (key, "panel_size") == 0) {
230 extract_values(value, &value1, &value2, &value3);
231
232 char *b;
233 if ((b = strchr (value1, '%'))) {
234 b[0] = '\0';
235 panel_config.pourcentx = 1;
236 }
237 panel_config.area.width = atoi(value1);
238 if (panel_config.area.width == 0) {
239 // full width mode
240 panel_config.area.width = 100;
241 panel_config.pourcentx = 1;
242 }
243 if (value2) {
244 if ((b = strchr (value2, '%'))) {
245 b[0] = '\0';
246 panel_config.pourcenty = 1;
247 }
248 panel_config.area.height = atoi(value2);
249 }
250 }
251 else if (strcmp (key, "panel_margin") == 0) {
252 extract_values(value, &value1, &value2, &value3);
253 panel_config.marginx = atoi (value1);
254 if (value2) panel_config.marginy = atoi (value2);
255 }
256 else if (strcmp (key, "panel_padding") == 0) {
257 extract_values(value, &value1, &value2, &value3);
258 panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
259 if (value2) panel_config.area.paddingy = atoi (value2);
260 if (value3) panel_config.area.paddingx = atoi (value3);
261 }
262 else if (strcmp (key, "panel_position") == 0) {
263 extract_values(value, &value1, &value2, &value3);
264 if (strcmp (value1, "top") == 0) panel_position = TOP;
265 else {
266 if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
267 else panel_position = CENTER;
268 }
269
270 if (!value2) panel_position |= CENTER;
271 else {
272 if (strcmp (value2, "left") == 0) panel_position |= LEFT;
273 else {
274 if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
275 else panel_position |= CENTER;
276 }
277 }
278 if (!value3) panel_horizontal = 1;
279 else {
280 if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
281 else panel_horizontal = 1;
282 }
283 }
284 else if (strcmp (key, "font_shadow") == 0)
285 panel_config.g_task.font_shadow = atoi (value);
286 else if (strcmp (key, "panel_background_id") == 0) {
287 int id = atoi (value);
288 id = (id < backgrounds->len && id >= 0) ? id : 0;
289 panel_config.area.bg = &g_array_index(backgrounds, Background, id);
290 }
291 else if (strcmp (key, "wm_menu") == 0)
292 wm_menu = atoi (value);
293 else if (strcmp (key, "panel_dock") == 0)
294 panel_dock = atoi (value);
295 else if (strcmp (key, "urgent_nb_of_blink") == 0)
296 max_tick_urgent = (atoi (value) * 2) + 1;
297 else if (strcmp (key, "panel_layer") == 0) {
298 if (strcmp(value, "bottom") == 0)
299 panel_layer = BOTTOM_LAYER;
300 else if (strcmp(value, "normal") == 0)
301 panel_layer = NORMAL_LAYER;
302 else if (strcmp(value, "top") == 0)
303 panel_layer = TOP_LAYER;
304 }
305
306 /* Battery */
307 else if (strcmp (key, "battery") == 0) {
308 #ifdef ENABLE_BATTERY
309 if(atoi(value) == 1)
310 battery_enabled = 1;
311 #else
312 if(atoi(value) == 1)
313 fprintf(stderr, "tint2 is build without battery support\n");
314 #endif
315 }
316 else if (strcmp (key, "battery_low_status") == 0) {
317 #ifdef ENABLE_BATTERY
318 battery_low_status = atoi(value);
319 if(battery_low_status < 0 || battery_low_status > 100)
320 battery_low_status = 0;
321 #endif
322 }
323 else if (strcmp (key, "battery_low_cmd") == 0) {
324 #ifdef ENABLE_BATTERY
325 if (strlen(value) > 0)
326 battery_low_cmd = strdup (value);
327 #endif
328 }
329 else if (strcmp (key, "bat1_font") == 0) {
330 #ifdef ENABLE_BATTERY
331 bat1_font_desc = pango_font_description_from_string (value);
332 #endif
333 }
334 else if (strcmp (key, "bat2_font") == 0) {
335 #ifdef ENABLE_BATTERY
336 bat2_font_desc = pango_font_description_from_string (value);
337 #endif
338 }
339 else if (strcmp (key, "battery_font_color") == 0) {
340 #ifdef ENABLE_BATTERY
341 extract_values(value, &value1, &value2, &value3);
342 get_color (value1, panel_config.battery.font.color);
343 if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
344 else panel_config.battery.font.alpha = 0.5;
345 #endif
346 }
347 else if (strcmp (key, "battery_padding") == 0) {
348 #ifdef ENABLE_BATTERY
349 extract_values(value, &value1, &value2, &value3);
350 panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
351 if (value2) panel_config.battery.area.paddingy = atoi (value2);
352 if (value3) panel_config.battery.area.paddingx = atoi (value3);
353 #endif
354 }
355 else if (strcmp (key, "battery_background_id") == 0) {
356 #ifdef ENABLE_BATTERY
357 int id = atoi (value);
358 id = (id < backgrounds->len && id >= 0) ? id : 0;
359 panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id);
360 #endif
361 }
362 else if (strcmp (key, "battery_hide") == 0) {
363 #ifdef ENABLE_BATTERY
364 percentage_hide = atoi (value);
365 if (percentage_hide == 0)
366 percentage_hide = 101;
367 #endif
368 }
369
370 /* Clock */
371 else if (strcmp (key, "time1_format") == 0) {
372 if (strlen(value) > 0) {
373 time1_format = strdup (value);
374 clock_enabled = 1;
375 }
376 }
377 else if (strcmp (key, "time2_format") == 0) {
378 if (strlen(value) > 0)
379 time2_format = strdup (value);
380 }
381 else if (strcmp (key, "time1_font") == 0) {
382 time1_font_desc = pango_font_description_from_string (value);
383 }
384 else if (strcmp(key, "time1_timezone") == 0) {
385 if (strlen(value) > 0)
386 time1_timezone = strdup(value);
387 }
388 else if (strcmp(key, "time2_timezone") == 0) {
389 if (strlen(value) > 0)
390 time2_timezone = strdup(value);
391 }
392 else if (strcmp (key, "time2_font") == 0) {
393 time2_font_desc = pango_font_description_from_string (value);
394 }
395 else if (strcmp (key, "clock_font_color") == 0) {
396 extract_values(value, &value1, &value2, &value3);
397 get_color (value1, panel_config.clock.font.color);
398 if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
399 else panel_config.clock.font.alpha = 0.5;
400 }
401 else if (strcmp (key, "clock_padding") == 0) {
402 extract_values(value, &value1, &value2, &value3);
403 panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
404 if (value2) panel_config.clock.area.paddingy = atoi (value2);
405 if (value3) panel_config.clock.area.paddingx = atoi (value3);
406 }
407 else if (strcmp (key, "clock_background_id") == 0) {
408 int id = atoi (value);
409 id = (id < backgrounds->len && id >= 0) ? id : 0;
410 panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id);
411 }
412 else if (strcmp(key, "clock_tooltip") == 0) {
413 if (strlen(value) > 0)
414 time_tooltip_format = strdup (value);
415 }
416 else if (strcmp(key, "clock_tooltip_timezone") == 0) {
417 if (strlen(value) > 0)
418 time_tooltip_timezone = strdup(value);
419 }
420 else if (strcmp(key, "clock_lclick_command") == 0) {
421 if (strlen(value) > 0)
422 clock_lclick_command = strdup(value);
423 }
424 else if (strcmp(key, "clock_rclick_command") == 0) {
425 if (strlen(value) > 0)
426 clock_rclick_command = strdup(value);
427 }
428
429 /* Taskbar */
430 else if (strcmp (key, "taskbar_mode") == 0) {
431 if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
432 else panel_mode = SINGLE_DESKTOP;
433 }
434 else if (strcmp (key, "taskbar_padding") == 0) {
435 extract_values(value, &value1, &value2, &value3);
436 panel_config.g_taskbar.area.paddingxlr = panel_config.g_taskbar.area.paddingx = atoi (value1);
437 if (value2) panel_config.g_taskbar.area.paddingy = atoi (value2);
438 if (value3) panel_config.g_taskbar.area.paddingx = atoi (value3);
439 }
440 else if (strcmp (key, "taskbar_background_id") == 0) {
441 int id = atoi (value);
442 id = (id < backgrounds->len && id >= 0) ? id : 0;
443 panel_config.g_taskbar.bg = &g_array_index(backgrounds, Background, id);
444 panel_config.g_taskbar.area.bg = panel_config.g_taskbar.bg;
445 }
446 else if (strcmp (key, "taskbar_active_background_id") == 0) {
447 int id = atoi (value);
448 id = (id < backgrounds->len && id >= 0) ? id : 0;
449 panel_config.g_taskbar.bg_active = &g_array_index(backgrounds, Background, id);
450 panel_config.g_taskbar.use_active = 1;
451 }
452
453 /* Task */
454 else if (strcmp (key, "task_text") == 0)
455 panel_config.g_task.text = atoi (value);
456 else if (strcmp (key, "task_icon") == 0)
457 panel_config.g_task.icon = atoi (value);
458 else if (strcmp (key, "task_centered") == 0)
459 panel_config.g_task.centered = atoi (value);
460 else if (strcmp (key, "task_width") == 0) {
461 // old parameter : just for backward compatibility
462 panel_config.g_task.maximum_width = atoi (value);
463 panel_config.g_task.maximum_height = 30;
464 }
465 else if (strcmp (key, "task_maximum_size") == 0) {
466 extract_values(value, &value1, &value2, &value3);
467 panel_config.g_task.maximum_width = atoi (value1);
468 panel_config.g_task.maximum_height = 30;
469 if (value2)
470 panel_config.g_task.maximum_height = atoi (value2);
471 }
472 else if (strcmp (key, "task_padding") == 0) {
473 extract_values(value, &value1, &value2, &value3);
474 panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
475 if (value2) panel_config.g_task.area.paddingy = atoi (value2);
476 if (value3) panel_config.g_task.area.paddingx = atoi (value3);
477 }
478 else if (strcmp (key, "task_font") == 0) {
479 panel_config.g_task.font_desc = pango_font_description_from_string (value);
480 }
481 else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
482 gchar** split = g_regex_split_simple("_", key, 0, 0);
483 int status = get_task_status(split[1]);
484 g_strfreev(split);
485 extract_values(value, &value1, &value2, &value3);
486 float alpha = 1;
487 if (value2) alpha = (atoi (value2) / 100.0);
488 get_color (value1, panel_config.g_task.font[status].color);
489 panel_config.g_task.font[status].alpha = alpha;
490 panel_config.g_task.config_font_mask |= (1<<status);
491 }
492 else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
493 gchar** split = g_regex_split_simple("_", key, 0, 0);
494 int status = get_task_status(split[1]);
495 g_strfreev(split);
496 extract_values(value, &value1, &value2, &value3);
497 panel_config.g_task.alpha[status] = atoi(value1);
498 panel_config.g_task.saturation[status] = atoi(value2);
499 panel_config.g_task.brightness[status] = atoi(value3);
500 panel_config.g_task.config_asb_mask |= (1<<status);
501 }
502 else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
503 gchar** split = g_regex_split_simple("_", key, 0, 0);
504 int status = get_task_status(split[1]);
505 g_strfreev(split);
506 int id = atoi (value);
507 id = (id < backgrounds->len && id >= 0) ? id : 0;
508 panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
509 panel_config.g_task.config_background_mask |= (1<<status);
510 if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
511 }
512
513 /* Systray */
514 else if (strcmp (key, "systray") == 0) {
515 systray_enabled = atoi(value);
516 // systray is latest option added. files without 'systray' are old.
517 old_config_file = 0;
518 }
519 else if (strcmp (key, "systray_padding") == 0) {
520 if (old_config_file)
521 systray_enabled = 1;
522 extract_values(value, &value1, &value2, &value3);
523 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
524 if (value2) systray.area.paddingy = atoi (value2);
525 if (value3) systray.area.paddingx = atoi (value3);
526 }
527 else if (strcmp (key, "systray_background_id") == 0) {
528 int id = atoi (value);
529 id = (id < backgrounds->len && id >= 0) ? id : 0;
530 systray.area.bg = &g_array_index(backgrounds, Background, id);
531 }
532 else if (strcmp(key, "systray_sort") == 0) {
533 if (strcmp(value, "descending") == 0)
534 systray.sort = -1;
535 else if (strcmp(value, "ascending") == 0)
536 systray.sort = 1;
537 else if (strcmp(value, "left2right") == 0)
538 systray.sort = 2;
539 else if (strcmp(value, "right2left") == 0)
540 systray.sort = 3;
541 }
542 else if (strcmp(key, "systray_icon_size") == 0) {
543 systray_max_icon_size = atoi(value);
544 }
545 else if (strcmp(key, "systray_icon_asb") == 0) {
546 extract_values(value, &value1, &value2, &value3);
547 systray.alpha = atoi(value1);
548 systray.saturation = atoi(value2);
549 systray.brightness = atoi(value3);
550 }
551
552 /* Tooltip */
553 else if (strcmp (key, "tooltip") == 0)
554 g_tooltip.enabled = atoi(value);
555 else if (strcmp (key, "tooltip_show_timeout") == 0) {
556 int timeout_msec = 1000*atof(value);
557 g_tooltip.show_timeout_msec = timeout_msec;
558 }
559 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
560 int timeout_msec = 1000*atof(value);
561 g_tooltip.hide_timeout_msec = timeout_msec;
562 }
563 else if (strcmp (key, "tooltip_padding") == 0) {
564 extract_values(value, &value1, &value2, &value3);
565 if (value1) g_tooltip.paddingx = atoi(value1);
566 if (value2) g_tooltip.paddingy = atoi(value2);
567 }
568 else if (strcmp (key, "tooltip_background_id") == 0) {
569 int id = atoi (value);
570 id = (id < backgrounds->len && id >= 0) ? id : 0;
571 g_tooltip.bg = &g_array_index(backgrounds, Background, id);
572 }
573 else if (strcmp (key, "tooltip_font_color") == 0) {
574 extract_values(value, &value1, &value2, &value3);
575 get_color(value1, g_tooltip.font_color.color);
576 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
577 else g_tooltip.font_color.alpha = 0.1;
578 }
579 else if (strcmp (key, "tooltip_font") == 0) {
580 g_tooltip.font_desc = pango_font_description_from_string(value);
581 }
582
583 /* Mouse actions */
584 else if (strcmp (key, "mouse_middle") == 0)
585 get_action (value, &mouse_middle);
586 else if (strcmp (key, "mouse_right") == 0)
587 get_action (value, &mouse_right);
588 else if (strcmp (key, "mouse_scroll_up") == 0)
589 get_action (value, &mouse_scroll_up);
590 else if (strcmp (key, "mouse_scroll_down") == 0)
591 get_action (value, &mouse_scroll_down);
592
593 /* autohide options */
594 else if (strcmp(key, "autohide") == 0)
595 panel_autohide = atoi(value);
596 else if (strcmp(key, "autohide_show_timeout") == 0)
597 panel_autohide_show_timeout = 1000*atof(value);
598 else if (strcmp(key, "autohide_hide_timeout") == 0)
599 panel_autohide_hide_timeout = 1000*atof(value);
600 else if (strcmp(key, "strut_policy") == 0) {
601 if (strcmp(value, "follow_size") == 0)
602 panel_strut_policy = STRUT_FOLLOW_SIZE;
603 else
604 panel_strut_policy = STRUT_MINIMUM;
605 }
606 else if (strcmp(key, "autohide_height") == 0)
607 panel_autohide_height = atoi(value);
608
609 else
610 fprintf(stderr, "tint2 : invalid option \"%s\", correct your config file\n", key);
611
612 if (value1) free (value1);
613 if (value2) free (value2);
614 if (value3) free (value3);
615 }
616
617
618 int config_read ()
619 {
620 const gchar * const * system_dirs;
621 char *path1;
622 gint i;
623
624 // follow XDG specification
625 // check tint2rc in user directory
626 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
627 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
628 i = config_read_file (path1);
629 config_path = strdup(path1);
630 g_free(path1);
631 return i;
632 }
633 g_free(path1);
634
635 // copy tint2rc from system directory to user directory
636 char *path2 = 0;
637 system_dirs = g_get_system_config_dirs();
638 for (i = 0; system_dirs[i]; i++) {
639 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
640
641 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
642 g_free (path2);
643 path2 = 0;
644 }
645
646 if (path2) {
647 // copy file in user directory (path1)
648 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
649 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
650 g_free(dir);
651
652 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
653 copy_file(path2, path1);
654 g_free(path2);
655
656 i = config_read_file (path1);
657 config_path = strdup(path1);
658 g_free(path1);
659 return i;
660 }
661 return 0;
662 }
663
664
665 int config_read_file (const char *path)
666 {
667 FILE *fp;
668 char line[512];
669 char *key, *value;
670
671 if ((fp = fopen(path, "r")) == NULL) return 0;
672
673 while (fgets(line, sizeof(line), fp) != NULL) {
674 if (parse_line(line, &key, &value)) {
675 add_entry (key, value);
676 free (key);
677 free (value);
678 }
679 }
680 fclose (fp);
681
682 if (old_task_icon_size) {
683 panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
684 }
685 return 1;
686 }
687
688
689
This page took 0.07354 seconds and 5 git commands to generate.