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