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