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