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