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