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