]> Dogcows Code - chaz/tint2/blob - src/config.c
814bc5d2ff3fcba5f03d24d43a8f9da737edeee7
[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 /* autohide options */
611 else if (strcmp(key, "autohide") == 0)
612 panel_autohide = atoi(value);
613 else if (strcmp(key, "autohide_show_timeout") == 0)
614 panel_autohide_show_timeout = 1000*atof(value);
615 else if (strcmp(key, "autohide_hide_timeout") == 0)
616 panel_autohide_hide_timeout = 1000*atof(value);
617 else if (strcmp(key, "strut_policy") == 0) {
618 if (strcmp(value, "follow_size") == 0)
619 panel_strut_policy = STRUT_FOLLOW_SIZE;
620 else
621 panel_strut_policy = STRUT_MINIMUM;
622 }
623 else if (strcmp(key, "autohide_height") == 0)
624 panel_autohide_height = atoi(value);
625
626
627 /* Read tint-0.6 config for backward compatibility */
628 else if (strcmp (key, "panel_mode") == 0) {
629 if (strcmp (value, "single_desktop") == 0) panel_mode = SINGLE_DESKTOP;
630 else panel_mode = MULTI_DESKTOP;
631 }
632 else if (strcmp (key, "panel_rounded") == 0) {
633 Area *a = calloc(1, sizeof(Area));
634 a->pix.border.rounded = atoi (value);
635 list_back = g_slist_append(list_back, a);
636 }
637 else if (strcmp (key, "panel_border_width") == 0) {
638 Area *a = g_slist_last(list_back)->data;
639 a->pix.border.width = atoi (value);
640 }
641 else if (strcmp (key, "panel_background_color") == 0) {
642 Area *a = g_slist_last(list_back)->data;
643 extract_values(value, &value1, &value2, &value3);
644 get_color (value1, a->pix.back.color);
645 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
646 else a->pix.back.alpha = 0.5;
647 }
648 else if (strcmp (key, "panel_border_color") == 0) {
649 Area *a = g_slist_last(list_back)->data;
650 extract_values(value, &value1, &value2, &value3);
651 get_color (value1, a->pix.border.color);
652 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
653 else a->pix.border.alpha = 0.5;
654 }
655 else if (strcmp (key, "task_text_centered") == 0)
656 panel_config.g_task.centered = atoi (value);
657 else if (strcmp (key, "task_margin") == 0) {
658 panel_config.g_taskbar.paddingxlr = 0;
659 panel_config.g_taskbar.paddingx = atoi (value);
660 }
661 else if (strcmp (key, "task_icon_size") == 0)
662 old_task_icon_size = atoi (value);
663 else if (strcmp (key, "task_rounded") == 0) {
664 area_task = calloc(1, sizeof(Area));
665 area_task->pix.border.rounded = atoi (value);
666 list_back = g_slist_append(list_back, area_task);
667
668 area_task_active = calloc(1, sizeof(Area));
669 area_task_active->pix.border.rounded = atoi (value);
670 list_back = g_slist_append(list_back, area_task_active);
671 }
672 else if (strcmp (key, "task_background_color") == 0) {
673 extract_values(value, &value1, &value2, &value3);
674 get_color (value1, area_task->pix.back.color);
675 if (value2) area_task->pix.back.alpha = (atoi (value2) / 100.0);
676 else area_task->pix.back.alpha = 0.5;
677 }
678 else if (strcmp (key, "task_active_background_color") == 0) {
679 extract_values(value, &value1, &value2, &value3);
680 get_color (value1, area_task_active->pix.back.color);
681 if (value2) area_task_active->pix.back.alpha = (atoi (value2) / 100.0);
682 else area_task_active->pix.back.alpha = 0.5;
683 }
684 else if (strcmp (key, "task_border_width") == 0) {
685 area_task->pix.border.width = atoi (value);
686 area_task_active->pix.border.width = atoi (value);
687 }
688 else if (strcmp (key, "task_border_color") == 0) {
689 extract_values(value, &value1, &value2, &value3);
690 get_color (value1, area_task->pix.border.color);
691 if (value2) area_task->pix.border.alpha = (atoi (value2) / 100.0);
692 else area_task->pix.border.alpha = 0.5;
693 }
694 else if (strcmp (key, "task_active_border_color") == 0) {
695 extract_values(value, &value1, &value2, &value3);
696 get_color (value1, area_task_active->pix.border.color);
697 if (value2) area_task_active->pix.border.alpha = (atoi (value2) / 100.0);
698 else area_task_active->pix.border.alpha = 0.5;
699 }
700
701 else
702 fprintf(stderr, "tint2 : invalid option \"%s\", correct your config file\n", key);
703
704 if (value1) free (value1);
705 if (value2) free (value2);
706 if (value3) free (value3);
707 }
708
709
710 int config_read ()
711 {
712 const gchar * const * system_dirs;
713 char *path1;
714 gint i;
715
716 // follow XDG specification
717 // check tint2rc in user directory
718 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
719 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
720 i = config_read_file (path1);
721 config_path = strdup(path1);
722 g_free(path1);
723 return i;
724 }
725 g_free(path1);
726
727 // copy tint2rc from system directory to user directory
728 char *path2 = 0;
729 system_dirs = g_get_system_config_dirs();
730 for (i = 0; system_dirs[i]; i++) {
731 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
732
733 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
734 g_free (path2);
735 path2 = 0;
736 }
737
738 if (path2) {
739 // copy file in user directory (path1)
740 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
741 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
742 g_free(dir);
743
744 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
745 copy_file(path2, path1);
746 g_free(path2);
747
748 i = config_read_file (path1);
749 config_path = strdup(path1);
750 g_free(path1);
751 return i;
752 }
753 return 0;
754 }
755
756
757 int config_read_file (const char *path)
758 {
759 FILE *fp;
760 char line[512];
761 char *key, *value;
762
763 if ((fp = fopen(path, "r")) == NULL) return 0;
764
765 while (fgets(line, sizeof(line), fp) != NULL) {
766 if (parse_line(line, &key, &value)) {
767 add_entry (key, value);
768 free (key);
769 free (value);
770 }
771 }
772 fclose (fp);
773
774 if (old_task_icon_size) {
775 panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
776 }
777 return 1;
778 }
779
780
781
This page took 0.077675 seconds and 4 git commands to generate.