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