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