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