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