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