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