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