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