]> Dogcows Code - chaz/tint2/blob - src/config.c
memorized taskbar pixmap. So we don t redraw taskbar/task when switching desktop.
[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 "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 //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.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
466 }
467 else if (strcmp (key, "taskbar_name") == 0) {
468 taskbarname_enabled = atoi (value);
469 }
470 else if (strcmp (key, "taskbar_name_background_id") == 0) {
471 }
472 else if (strcmp (key, "taskbar_name_active_background_id") == 0) {
473 }
474 else if (strcmp (key, "taskbar_name_font") == 0) {
475 }
476 else if (strcmp (key, "taskbar_name_font_color") == 0) {
477 }
478 else if (strcmp (key, "taskbar_name_active_font_color") == 0) {
479 }
480
481 /* Task */
482 else if (strcmp (key, "task_text") == 0)
483 panel_config.g_task.text = atoi (value);
484 else if (strcmp (key, "task_icon") == 0)
485 panel_config.g_task.icon = atoi (value);
486 else if (strcmp (key, "task_centered") == 0)
487 panel_config.g_task.centered = atoi (value);
488 else if (strcmp (key, "task_width") == 0) {
489 // old parameter : just for backward compatibility
490 panel_config.g_task.maximum_width = atoi (value);
491 panel_config.g_task.maximum_height = 30;
492 }
493 else if (strcmp (key, "task_maximum_size") == 0) {
494 extract_values(value, &value1, &value2, &value3);
495 panel_config.g_task.maximum_width = atoi (value1);
496 panel_config.g_task.maximum_height = 30;
497 if (value2)
498 panel_config.g_task.maximum_height = atoi (value2);
499 }
500 else if (strcmp (key, "task_padding") == 0) {
501 extract_values(value, &value1, &value2, &value3);
502 panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
503 if (value2) panel_config.g_task.area.paddingy = atoi (value2);
504 if (value3) panel_config.g_task.area.paddingx = atoi (value3);
505 }
506 else if (strcmp (key, "task_font") == 0) {
507 panel_config.g_task.font_desc = pango_font_description_from_string (value);
508 }
509 else if (g_regex_match_simple("task.*_font_color", 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 float alpha = 1;
515 if (value2) alpha = (atoi (value2) / 100.0);
516 get_color (value1, panel_config.g_task.font[status].color);
517 panel_config.g_task.font[status].alpha = alpha;
518 panel_config.g_task.config_font_mask |= (1<<status);
519 }
520 else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
521 gchar** split = g_regex_split_simple("_", key, 0, 0);
522 int status = get_task_status(split[1]);
523 g_strfreev(split);
524 extract_values(value, &value1, &value2, &value3);
525 panel_config.g_task.alpha[status] = atoi(value1);
526 panel_config.g_task.saturation[status] = atoi(value2);
527 panel_config.g_task.brightness[status] = atoi(value3);
528 panel_config.g_task.config_asb_mask |= (1<<status);
529 }
530 else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
531 gchar** split = g_regex_split_simple("_", key, 0, 0);
532 int status = get_task_status(split[1]);
533 g_strfreev(split);
534 int id = atoi (value);
535 id = (id < backgrounds->len && id >= 0) ? id : 0;
536 panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
537 panel_config.g_task.config_background_mask |= (1<<status);
538 if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
539 }
540
541 /* Systray */
542 else if (strcmp (key, "systray_padding") == 0) {
543 extract_values(value, &value1, &value2, &value3);
544 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
545 if (value2) systray.area.paddingy = atoi (value2);
546 if (value3) systray.area.paddingx = atoi (value3);
547 }
548 else if (strcmp (key, "systray_background_id") == 0) {
549 int id = atoi (value);
550 id = (id < backgrounds->len && id >= 0) ? id : 0;
551 systray.area.bg = &g_array_index(backgrounds, Background, id);
552 }
553 else if (strcmp(key, "systray_sort") == 0) {
554 if (strcmp(value, "descending") == 0)
555 systray.sort = -1;
556 else if (strcmp(value, "ascending") == 0)
557 systray.sort = 1;
558 else if (strcmp(value, "left2right") == 0)
559 systray.sort = 2;
560 else if (strcmp(value, "right2left") == 0)
561 systray.sort = 3;
562 }
563 else if (strcmp(key, "systray_icon_size") == 0) {
564 systray_max_icon_size = atoi(value);
565 }
566 else if (strcmp(key, "systray_icon_asb") == 0) {
567 extract_values(value, &value1, &value2, &value3);
568 systray.alpha = atoi(value1);
569 systray.saturation = atoi(value2);
570 systray.brightness = atoi(value3);
571 }
572
573 /* Launcher */
574 else if (strcmp (key, "launcher_padding") == 0) {
575 extract_values(value, &value1, &value2, &value3);
576 panel_config.launcher.area.paddingxlr = panel_config.launcher.area.paddingx = atoi (value1);
577 if (value2) panel_config.launcher.area.paddingy = atoi (value2);
578 if (value3) panel_config.launcher.area.paddingx = atoi (value3);
579 }
580 else if (strcmp (key, "launcher_background_id") == 0) {
581 int id = atoi (value);
582 id = (id < backgrounds->len && id >= 0) ? id : 0;
583 panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id);
584 }
585 else if (strcmp(key, "launcher_icon_size") == 0) {
586 launcher_max_icon_size = atoi(value);
587 }
588 else if (strcmp(key, "launcher_item_app") == 0) {
589 char *app = strdup(value);
590 panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app);
591 }
592 else if (strcmp(key, "launcher_icon_theme") == 0) {
593 char *app = strdup(value);
594 panel_config.launcher.icon_theme_names = g_slist_append(panel_config.launcher.icon_theme_names, app);
595 }
596
597 /* Tooltip */
598 else if (strcmp (key, "tooltip") == 0)
599 g_tooltip.enabled = atoi(value);
600 else if (strcmp (key, "tooltip_show_timeout") == 0) {
601 int timeout_msec = 1000*atof(value);
602 g_tooltip.show_timeout_msec = timeout_msec;
603 }
604 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
605 int timeout_msec = 1000*atof(value);
606 g_tooltip.hide_timeout_msec = timeout_msec;
607 }
608 else if (strcmp (key, "tooltip_padding") == 0) {
609 extract_values(value, &value1, &value2, &value3);
610 if (value1) g_tooltip.paddingx = atoi(value1);
611 if (value2) g_tooltip.paddingy = atoi(value2);
612 }
613 else if (strcmp (key, "tooltip_background_id") == 0) {
614 int id = atoi (value);
615 id = (id < backgrounds->len && id >= 0) ? id : 0;
616 g_tooltip.bg = &g_array_index(backgrounds, Background, id);
617 }
618 else if (strcmp (key, "tooltip_font_color") == 0) {
619 extract_values(value, &value1, &value2, &value3);
620 get_color(value1, g_tooltip.font_color.color);
621 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
622 else g_tooltip.font_color.alpha = 0.1;
623 }
624 else if (strcmp (key, "tooltip_font") == 0) {
625 g_tooltip.font_desc = pango_font_description_from_string(value);
626 }
627
628 /* Mouse actions */
629 else if (strcmp (key, "mouse_middle") == 0)
630 get_action (value, &mouse_middle);
631 else if (strcmp (key, "mouse_right") == 0)
632 get_action (value, &mouse_right);
633 else if (strcmp (key, "mouse_scroll_up") == 0)
634 get_action (value, &mouse_scroll_up);
635 else if (strcmp (key, "mouse_scroll_down") == 0)
636 get_action (value, &mouse_scroll_down);
637
638 /* autohide options */
639 else if (strcmp(key, "autohide") == 0)
640 panel_autohide = atoi(value);
641 else if (strcmp(key, "autohide_show_timeout") == 0)
642 panel_autohide_show_timeout = 1000*atof(value);
643 else if (strcmp(key, "autohide_hide_timeout") == 0)
644 panel_autohide_hide_timeout = 1000*atof(value);
645 else if (strcmp(key, "strut_policy") == 0) {
646 if (strcmp(value, "follow_size") == 0)
647 panel_strut_policy = STRUT_FOLLOW_SIZE;
648 else if (strcmp(value, "none") == 0)
649 panel_strut_policy = STRUT_NONE;
650 else
651 panel_strut_policy = STRUT_MINIMUM;
652 }
653 else if (strcmp(key, "autohide_height") == 0) {
654 panel_autohide_height = atoi(value);
655 if (panel_autohide_height == 0) {
656 // autohide need height > 0
657 panel_autohide_height = 1;
658 }
659 }
660
661 // old config option
662 else if (strcmp(key, "systray") == 0) {
663 if (new_config_file == 0) {
664 systray_enabled = atoi(value);
665 if (systray_enabled) {
666 if (panel_items_order) {
667 char* tmp = g_strconcat(panel_items_order, "S", NULL);
668 g_free( panel_items_order );
669 panel_items_order = tmp;
670 }
671 else
672 panel_items_order = g_strdup("S");
673 }
674 }
675 }
676 else if (strcmp(key, "battery") == 0) {
677 if (new_config_file == 0) {
678 battery_enabled = atoi(value);
679 if (battery_enabled) {
680 if (panel_items_order) {
681 char* tmp = g_strconcat(panel_items_order, "B", NULL);
682 g_free( panel_items_order );
683 panel_items_order = tmp;
684 }
685 else
686 panel_items_order = g_strdup("B");
687 }
688 }
689 }
690 else
691 fprintf(stderr, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key);
692
693 if (value1) free (value1);
694 if (value2) free (value2);
695 if (value3) free (value3);
696 }
697
698
699 int config_read ()
700 {
701 const gchar * const * system_dirs;
702 char *path1;
703 gint i;
704
705 // follow XDG specification
706 // check tint2rc in user directory
707 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
708 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
709 i = config_read_file (path1);
710 config_path = strdup(path1);
711 g_free(path1);
712 return i;
713 }
714 g_free(path1);
715
716 // copy tint2rc from system directory to user directory
717 char *path2 = 0;
718 system_dirs = g_get_system_config_dirs();
719 for (i = 0; system_dirs[i]; i++) {
720 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
721
722 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
723 g_free (path2);
724 path2 = 0;
725 }
726
727 if (path2) {
728 // copy file in user directory (path1)
729 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
730 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
731 g_free(dir);
732
733 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
734 copy_file(path2, path1);
735 g_free(path2);
736
737 i = config_read_file (path1);
738 config_path = strdup(path1);
739 g_free(path1);
740 return i;
741 }
742 return 0;
743 }
744
745
746 int config_read_file (const char *path)
747 {
748 FILE *fp;
749 char line[512];
750 char *key, *value;
751
752 if ((fp = fopen(path, "r")) == NULL) return 0;
753
754 while (fgets(line, sizeof(line), fp) != NULL) {
755 if (parse_line(line, &key, &value)) {
756 add_entry (key, value);
757 free (key);
758 free (value);
759 }
760 }
761 fclose (fp);
762
763 // append Taskbar item
764 if (new_config_file == 0) {
765 taskbar_enabled = 1;
766 if (panel_items_order) {
767 char* tmp = g_strconcat( "T", panel_items_order, NULL );
768 g_free(panel_items_order);
769 panel_items_order = tmp;
770 }
771 else
772 panel_items_order = g_strdup("T");
773 }
774
775 return 1;
776 }
777
778
779
This page took 0.072309 seconds and 4 git commands to generate.