]> Dogcows Code - chaz/tint2/blob - src/config.c
02d0265d74fd9117f9c966f5d11b97e2c1a9b9fd
[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 <Imlib2.h>
36
37 #include "common.h"
38 #include "server.h"
39 #include "panel.h"
40 #include "task.h"
41 #include "taskbar.h"
42 #include "systraybar.h"
43 #include "clock.h"
44 #include "config.h"
45 #include "window.h"
46 #include "tooltip.h"
47
48 #ifdef ENABLE_BATTERY
49 #include "battery.h"
50 #endif
51
52 // global path
53 char *config_path = 0;
54 char *thumbnail_path = 0;
55
56 // --------------------------------------------------
57 // backward compatibility
58 static int save_file_config;
59 static int old_task_icon_size;
60 static char *old_task_font;
61 static char *old_time1_font;
62 static char *old_time2_font;
63 static Area *area_task, *area_task_active;
64
65 #ifdef ENABLE_BATTERY
66 static char *old_bat1_font;
67 static char *old_bat2_font;
68 #endif
69
70 // temporary list of background
71 static GSList *list_back;
72
73
74
75 void init_config()
76 {
77 // append full transparency background
78 list_back = g_slist_append(0, calloc(1, sizeof(Area)));
79
80 memset(&panel_config, 0, sizeof(Panel));
81 panel_config.g_task.alpha = 100;
82 panel_config.g_task.alpha_active = 100;
83 systray.sort = 3;
84
85 // window manager's menu default value == false
86 wm_menu = 0;
87 max_tick_urgent = 7;
88 }
89
90
91 void cleanup_config()
92 {
93 // cleanup background list
94 GSList *l0;
95 for (l0 = list_back; l0 ; l0 = l0->next) {
96 free(l0->data);
97 }
98 g_slist_free(list_back);
99 list_back = NULL;
100 }
101
102
103 void extract_values (const char *value, char **value1, char **value2, char **value3)
104 {
105 char *b=0, *c=0;
106
107 if (*value1) free (*value1);
108 if (*value2) free (*value2);
109 if (*value3) free (*value3);
110
111 if ((b = strchr (value, ' '))) {
112 b[0] = '\0';
113 b++;
114 }
115 else {
116 *value2 = 0;
117 *value3 = 0;
118 }
119 *value1 = strdup (value);
120 g_strstrip(*value1);
121
122 if (b) {
123 if ((c = strchr (b, ' '))) {
124 c[0] = '\0';
125 c++;
126 }
127 else {
128 c = 0;
129 *value3 = 0;
130 }
131 *value2 = strdup (b);
132 g_strstrip(*value2);
133 }
134
135 if (c) {
136 *value3 = strdup (c);
137 g_strstrip(*value3);
138 }
139 }
140
141
142 void get_action (char *event, int *action)
143 {
144 if (strcmp (event, "none") == 0)
145 *action = NONE;
146 else if (strcmp (event, "close") == 0)
147 *action = CLOSE;
148 else if (strcmp (event, "toggle") == 0)
149 *action = TOGGLE;
150 else if (strcmp (event, "iconify") == 0)
151 *action = ICONIFY;
152 else if (strcmp (event, "shade") == 0)
153 *action = SHADE;
154 else if (strcmp (event, "toggle_iconify") == 0)
155 *action = TOGGLE_ICONIFY;
156 else if (strcmp (event, "maximize_restore") == 0)
157 *action = MAXIMIZE_RESTORE;
158 else if (strcmp (event, "desktop_left") == 0)
159 *action = DESKTOP_LEFT;
160 else if (strcmp (event, "desktop_right") == 0)
161 *action = DESKTOP_RIGHT;
162 }
163
164
165 void add_entry (char *key, char *value)
166 {
167 char *value1=0, *value2=0, *value3=0;
168
169 /* Background and border */
170 if (strcmp (key, "rounded") == 0) {
171 // 'rounded' is the first parameter => alloc a new background
172 Area *a = calloc(1, sizeof(Area));
173 a->pix.border.rounded = atoi (value);
174 list_back = g_slist_append(list_back, a);
175 }
176 else if (strcmp (key, "border_width") == 0) {
177 Area *a = g_slist_last(list_back)->data;
178 a->pix.border.width = atoi (value);
179 }
180 else if (strcmp (key, "background_color") == 0) {
181 Area *a = g_slist_last(list_back)->data;
182 extract_values(value, &value1, &value2, &value3);
183 get_color (value1, a->pix.back.color);
184 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
185 else a->pix.back.alpha = 0.5;
186 }
187 else if (strcmp (key, "border_color") == 0) {
188 Area *a = g_slist_last(list_back)->data;
189 extract_values(value, &value1, &value2, &value3);
190 get_color (value1, a->pix.border.color);
191 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
192 else a->pix.border.alpha = 0.5;
193 }
194
195 /* Panel */
196 else if (strcmp (key, "panel_monitor") == 0) {
197 if (strcmp (value, "all") == 0) panel_config.monitor = -1;
198 else {
199 panel_config.monitor = atoi (value);
200 if (panel_config.monitor > 0) panel_config.monitor -= 1;
201 }
202 }
203 else if (strcmp (key, "panel_size") == 0) {
204 extract_values(value, &value1, &value2, &value3);
205
206 char *b;
207 if ((b = strchr (value1, '%'))) {
208 b[0] = '\0';
209 panel_config.pourcentx = 1;
210 }
211 panel_config.area.width = atoi(value1);
212 if (panel_config.area.width == 0) {
213 // full width mode
214 panel_config.area.width = 100;
215 panel_config.pourcentx = 1;
216 }
217 if (value2) {
218 if ((b = strchr (value2, '%'))) {
219 b[0] = '\0';
220 panel_config.pourcenty = 1;
221 }
222 panel_config.area.height = atoi(value2);
223 }
224 }
225 else if (strcmp (key, "panel_margin") == 0) {
226 extract_values(value, &value1, &value2, &value3);
227 panel_config.marginx = atoi (value1);
228 if (value2) panel_config.marginy = atoi (value2);
229 }
230 else if (strcmp (key, "panel_padding") == 0) {
231 extract_values(value, &value1, &value2, &value3);
232 panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
233 if (value2) panel_config.area.paddingy = atoi (value2);
234 if (value3) panel_config.area.paddingx = atoi (value3);
235 }
236 else if (strcmp (key, "panel_position") == 0) {
237 extract_values(value, &value1, &value2, &value3);
238 if (strcmp (value1, "top") == 0) panel_position = TOP;
239 else {
240 if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
241 else panel_position = CENTER;
242 }
243
244 if (!value2) panel_position |= CENTER;
245 else {
246 if (strcmp (value2, "left") == 0) panel_position |= LEFT;
247 else {
248 if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
249 else panel_position |= CENTER;
250 }
251 }
252 if (!value3) panel_horizontal = 1;
253 else {
254 if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
255 else panel_horizontal = 1;
256 }
257 }
258 else if (strcmp (key, "font_shadow") == 0)
259 panel_config.g_task.font_shadow = atoi (value);
260 else if (strcmp (key, "panel_background_id") == 0) {
261 int id = atoi (value);
262 Area *a = g_slist_nth_data(list_back, id);
263 memcpy(&panel_config.area.pix.back, &a->pix.back, sizeof(Color));
264 memcpy(&panel_config.area.pix.border, &a->pix.border, sizeof(Border));
265 }
266 else if (strcmp (key, "wm_menu") == 0)
267 wm_menu = atoi (value);
268 else if (strcmp (key, "panel_dock") == 0)
269 panel_dock = atoi (value);
270 else if (strcmp (key, "urgent_nb_of_blink") == 0)
271 max_tick_urgent = (atoi (value) * 2) + 1;
272
273 /* Battery */
274 else if (strcmp (key, "battery") == 0) {
275 #ifdef ENABLE_BATTERY
276 if(atoi(value) == 1)
277 battery_enabled = 1;
278 #else
279 if(atoi(value) == 1)
280 fprintf(stderr, "tint2 is build without battery support\n");
281 #endif
282 }
283 else if (strcmp (key, "battery_low_status") == 0) {
284 #ifdef ENABLE_BATTERY
285 battery_low_status = atoi(value);
286 if(battery_low_status < 0 || battery_low_status > 100)
287 battery_low_status = 0;
288 #endif
289 }
290 else if (strcmp (key, "battery_low_cmd") == 0) {
291 #ifdef ENABLE_BATTERY
292 if (battery_low_cmd) g_free(battery_low_cmd);
293 if (strlen(value) > 0) battery_low_cmd = strdup (value);
294 else battery_low_cmd = 0;
295 #endif
296 }
297 else if (strcmp (key, "bat1_font") == 0) {
298 #ifdef ENABLE_BATTERY
299 if (save_file_config) old_bat1_font = strdup (value);
300 if (bat1_font_desc) pango_font_description_free(bat1_font_desc);
301 bat1_font_desc = pango_font_description_from_string (value);
302 #endif
303 }
304 else if (strcmp (key, "bat2_font") == 0) {
305 #ifdef ENABLE_BATTERY
306 if (save_file_config) old_bat2_font = strdup (value);
307 if (bat2_font_desc) pango_font_description_free(bat2_font_desc);
308 bat2_font_desc = pango_font_description_from_string (value);
309 #endif
310 }
311 else if (strcmp (key, "battery_font_color") == 0) {
312 #ifdef ENABLE_BATTERY
313 extract_values(value, &value1, &value2, &value3);
314 get_color (value1, panel_config.battery.font.color);
315 if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
316 else panel_config.battery.font.alpha = 0.5;
317 #endif
318 }
319 else if (strcmp (key, "battery_padding") == 0) {
320 #ifdef ENABLE_BATTERY
321 extract_values(value, &value1, &value2, &value3);
322 panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
323 if (value2) panel_config.battery.area.paddingy = atoi (value2);
324 if (value3) panel_config.battery.area.paddingx = atoi (value3);
325 #endif
326 }
327 else if (strcmp (key, "battery_background_id") == 0) {
328 #ifdef ENABLE_BATTERY
329 int id = atoi (value);
330 Area *a = g_slist_nth_data(list_back, id);
331 memcpy(&panel_config.battery.area.pix.back, &a->pix.back, sizeof(Color));
332 memcpy(&panel_config.battery.area.pix.border, &a->pix.border, sizeof(Border));
333 #endif
334 }
335
336 /* Clock */
337 else if (strcmp (key, "time1_format") == 0) {
338 if (time1_format) g_free(time1_format);
339 if (strlen(value) > 0) {
340 time1_format = strdup (value);
341 panel_config.clock.area.on_screen = 1;
342 }
343 else {
344 time1_format = 0;
345 panel_config.clock.area.on_screen = 0;
346 }
347 }
348 else if (strcmp (key, "time2_format") == 0) {
349 if (time2_format) g_free(time2_format);
350 if (strlen(value) > 0) time2_format = strdup (value);
351 else time2_format = 0;
352 }
353 else if (strcmp (key, "time1_font") == 0) {
354 if (save_file_config) old_time1_font = strdup (value);
355 if (time1_font_desc) pango_font_description_free(time1_font_desc);
356 time1_font_desc = pango_font_description_from_string (value);
357 }
358 else if (strcmp (key, "time2_font") == 0) {
359 if (save_file_config) old_time2_font = strdup (value);
360 if (time2_font_desc) pango_font_description_free(time2_font_desc);
361 time2_font_desc = pango_font_description_from_string (value);
362 }
363 else if (strcmp (key, "clock_font_color") == 0) {
364 extract_values(value, &value1, &value2, &value3);
365 get_color (value1, panel_config.clock.font.color);
366 if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
367 else panel_config.clock.font.alpha = 0.5;
368 }
369 else if (strcmp (key, "clock_padding") == 0) {
370 extract_values(value, &value1, &value2, &value3);
371 panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
372 if (value2) panel_config.clock.area.paddingy = atoi (value2);
373 if (value3) panel_config.clock.area.paddingx = atoi (value3);
374 }
375 else if (strcmp (key, "clock_background_id") == 0) {
376 int id = atoi (value);
377 Area *a = g_slist_nth_data(list_back, id);
378 memcpy(&panel_config.clock.area.pix.back, &a->pix.back, sizeof(Color));
379 memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border));
380 }
381 else if (strcmp(key, "clock_lclick_command") == 0) {
382 if (clock_lclick_command) g_free(clock_lclick_command);
383 if (strlen(value) > 0) clock_lclick_command = strdup(value);
384 else clock_lclick_command = 0;
385 }
386 else if (strcmp(key, "clock_rclick_command") == 0) {
387 if (clock_rclick_command) g_free(clock_rclick_command);
388 if (strlen(value) > 0) clock_rclick_command = strdup(value);
389 else clock_rclick_command = 0;
390 }
391
392 /* Taskbar */
393 else if (strcmp (key, "taskbar_mode") == 0) {
394 if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
395 else panel_mode = SINGLE_DESKTOP;
396 }
397 else if (strcmp (key, "taskbar_padding") == 0) {
398 extract_values(value, &value1, &value2, &value3);
399 panel_config.g_taskbar.paddingxlr = panel_config.g_taskbar.paddingx = atoi (value1);
400 if (value2) panel_config.g_taskbar.paddingy = atoi (value2);
401 if (value3) panel_config.g_taskbar.paddingx = atoi (value3);
402 }
403 else if (strcmp (key, "taskbar_background_id") == 0) {
404 int id = atoi (value);
405 Area *a = g_slist_nth_data(list_back, id);
406 memcpy(&panel_config.g_taskbar.pix.back, &a->pix.back, sizeof(Color));
407 memcpy(&panel_config.g_taskbar.pix.border, &a->pix.border, sizeof(Border));
408 }
409 else if (strcmp (key, "taskbar_active_background_id") == 0) {
410 int id = atoi (value);
411 Area *a = g_slist_nth_data(list_back, id);
412 memcpy(&panel_config.g_taskbar.pix_active.back, &a->pix.back, sizeof(Color));
413 memcpy(&panel_config.g_taskbar.pix_active.border, &a->pix.border, sizeof(Border));
414 panel_config.g_taskbar.use_active = 1;
415 }
416
417 /* Task */
418 else if (strcmp (key, "task_text") == 0)
419 panel_config.g_task.text = atoi (value);
420 else if (strcmp (key, "task_icon") == 0)
421 panel_config.g_task.icon = atoi (value);
422 else if (strcmp (key, "task_centered") == 0)
423 panel_config.g_task.centered = atoi (value);
424 else if (strcmp (key, "task_width") == 0) {
425 // old parameter : just for backward compatibility
426 panel_config.g_task.maximum_width = atoi (value);
427 panel_config.g_task.maximum_height = 30;
428 }
429 else if (strcmp (key, "task_maximum_size") == 0) {
430 extract_values(value, &value1, &value2, &value3);
431 panel_config.g_task.maximum_width = atoi (value1);
432 panel_config.g_task.maximum_height = 30;
433 if (value2)
434 panel_config.g_task.maximum_height = atoi (value2);
435 }
436 else if (strcmp (key, "task_padding") == 0) {
437 extract_values(value, &value1, &value2, &value3);
438 panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
439 if (value2) panel_config.g_task.area.paddingy = atoi (value2);
440 if (value3) panel_config.g_task.area.paddingx = atoi (value3);
441 }
442 else if (strcmp (key, "task_font") == 0) {
443 if (save_file_config) old_task_font = strdup (value);
444 if (panel_config.g_task.font_desc) pango_font_description_free(panel_config.g_task.font_desc);
445 panel_config.g_task.font_desc = pango_font_description_from_string (value);
446 }
447 else if (strcmp (key, "task_font_color") == 0) {
448 extract_values(value, &value1, &value2, &value3);
449 get_color (value1, panel_config.g_task.font.color);
450 if (value2) panel_config.g_task.font.alpha = (atoi (value2) / 100.0);
451 else panel_config.g_task.font.alpha = 0.1;
452 }
453 else if (strcmp (key, "task_active_font_color") == 0) {
454 extract_values(value, &value1, &value2, &value3);
455 get_color (value1, panel_config.g_task.font_active.color);
456 if (value2) panel_config.g_task.font_active.alpha = (atoi (value2) / 100.0);
457 else panel_config.g_task.font_active.alpha = 0.1;
458 }
459 else if (strcmp (key, "task_icon_asb") == 0) {
460 extract_values(value, &value1, &value2, &value3);
461 panel_config.g_task.alpha = atoi(value1);
462 panel_config.g_task.saturation = atoi(value2);
463 panel_config.g_task.brightness = atoi(value3);
464 }
465 else if (strcmp (key, "task_active_icon_asb") == 0) {
466 extract_values(value, &value1, &value2, &value3);
467 panel_config.g_task.alpha_active = atoi(value1);
468 panel_config.g_task.saturation_active = atoi(value2);
469 panel_config.g_task.brightness_active = atoi(value3);
470 }
471 else if (strcmp (key, "task_background_id") == 0) {
472 int id = atoi (value);
473 Area *a = g_slist_nth_data(list_back, id);
474 memcpy(&panel_config.g_task.area.pix.back, &a->pix.back, sizeof(Color));
475 memcpy(&panel_config.g_task.area.pix.border, &a->pix.border, sizeof(Border));
476 }
477 else if (strcmp (key, "task_active_background_id") == 0) {
478 int id = atoi (value);
479 Area *a = g_slist_nth_data(list_back, id);
480 memcpy(&panel_config.g_task.area.pix_active.back, &a->pix.back, sizeof(Color));
481 memcpy(&panel_config.g_task.area.pix_active.border, &a->pix.border, sizeof(Border));
482 }
483
484 /* Systray */
485 else if (strcmp (key, "systray_padding") == 0) {
486 extract_values(value, &value1, &value2, &value3);
487 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
488 if (value2) systray.area.paddingy = atoi (value2);
489 if (value3) systray.area.paddingx = atoi (value3);
490 systray.area.on_screen = 1;
491 }
492 else if (strcmp (key, "systray_background_id") == 0) {
493 int id = atoi (value);
494 Area *a = g_slist_nth_data(list_back, id);
495 memcpy(&systray.area.pix.back, &a->pix.back, sizeof(Color));
496 memcpy(&systray.area.pix.border, &a->pix.border, sizeof(Border));
497 }
498 else if (strcmp(key, "systray_sort") == 0) {
499 if (strcmp(value, "descending") == 0)
500 systray.sort = -1;
501 else if (strcmp(value, "ascending") == 0)
502 systray.sort = 1;
503 else if (strcmp(value, "left2right") == 0)
504 systray.sort = 2;
505 else if (strcmp(value, "right2left") == 0)
506 systray.sort = 3;
507 }
508
509 /* Tooltip */
510 else if (strcmp (key, "tooltip") == 0)
511 g_tooltip.enabled = atoi(value);
512 else if (strcmp (key, "tooltip_show_timeout") == 0) {
513 double timeout = atof(value);
514 int sec = (int)timeout;
515 int usec = (timeout-sec)*1e6;
516 g_tooltip.show_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
517 }
518 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
519 double timeout = atof(value);
520 int sec = (int)timeout;
521 int usec = (timeout-sec)*1e6;
522 g_tooltip.hide_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
523 }
524 else if (strcmp (key, "tooltip_padding") == 0) {
525 extract_values(value, &value1, &value2, &value3);
526 if (value1) g_tooltip.paddingx = atoi(value1);
527 if (value2) g_tooltip.paddingy = atoi(value2);
528 }
529 else if (strcmp (key, "tooltip_background_id") == 0) {
530 int id = atoi (value);
531 Area *a = g_slist_nth_data(list_back, id);
532 memcpy(&g_tooltip.background_color, &a->pix.back, sizeof(Color));
533 memcpy(&g_tooltip.border, &a->pix.border, sizeof(Border));
534 }
535 else if (strcmp (key, "tooltip_font_color") == 0) {
536 extract_values(value, &value1, &value2, &value3);
537 get_color(value1, g_tooltip.font_color.color);
538 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
539 else g_tooltip.font_color.alpha = 0.1;
540 }
541 else if (strcmp (key, "tooltip_font") == 0) {
542 if (g_tooltip.font_desc) pango_font_description_free(g_tooltip.font_desc);
543 g_tooltip.font_desc = pango_font_description_from_string(value);
544 }
545
546 /* Mouse actions */
547 else if (strcmp (key, "mouse_middle") == 0)
548 get_action (value, &mouse_middle);
549 else if (strcmp (key, "mouse_right") == 0)
550 get_action (value, &mouse_right);
551 else if (strcmp (key, "mouse_scroll_up") == 0)
552 get_action (value, &mouse_scroll_up);
553 else if (strcmp (key, "mouse_scroll_down") == 0)
554 get_action (value, &mouse_scroll_down);
555
556
557 /* Read tint-0.6 config for backward compatibility */
558 else if (strcmp (key, "panel_mode") == 0) {
559 save_file_config = 1;
560 if (strcmp (value, "single_desktop") == 0) panel_mode = SINGLE_DESKTOP;
561 else panel_mode = MULTI_DESKTOP;
562 }
563 else if (strcmp (key, "panel_rounded") == 0) {
564 Area *a = calloc(1, sizeof(Area));
565 a->pix.border.rounded = atoi (value);
566 list_back = g_slist_append(list_back, a);
567 }
568 else if (strcmp (key, "panel_border_width") == 0) {
569 Area *a = g_slist_last(list_back)->data;
570 a->pix.border.width = atoi (value);
571 }
572 else if (strcmp (key, "panel_background_color") == 0) {
573 Area *a = g_slist_last(list_back)->data;
574 extract_values(value, &value1, &value2, &value3);
575 get_color (value1, a->pix.back.color);
576 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
577 else a->pix.back.alpha = 0.5;
578 }
579 else if (strcmp (key, "panel_border_color") == 0) {
580 Area *a = g_slist_last(list_back)->data;
581 extract_values(value, &value1, &value2, &value3);
582 get_color (value1, a->pix.border.color);
583 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
584 else a->pix.border.alpha = 0.5;
585 }
586 else if (strcmp (key, "task_text_centered") == 0)
587 panel_config.g_task.centered = atoi (value);
588 else if (strcmp (key, "task_margin") == 0) {
589 panel_config.g_taskbar.paddingxlr = 0;
590 panel_config.g_taskbar.paddingx = atoi (value);
591 }
592 else if (strcmp (key, "task_icon_size") == 0)
593 old_task_icon_size = atoi (value);
594 else if (strcmp (key, "task_rounded") == 0) {
595 area_task = calloc(1, sizeof(Area));
596 area_task->pix.border.rounded = atoi (value);
597 list_back = g_slist_append(list_back, area_task);
598
599 area_task_active = calloc(1, sizeof(Area));
600 area_task_active->pix.border.rounded = atoi (value);
601 list_back = g_slist_append(list_back, area_task_active);
602 }
603 else if (strcmp (key, "task_background_color") == 0) {
604 extract_values(value, &value1, &value2, &value3);
605 get_color (value1, area_task->pix.back.color);
606 if (value2) area_task->pix.back.alpha = (atoi (value2) / 100.0);
607 else area_task->pix.back.alpha = 0.5;
608 }
609 else if (strcmp (key, "task_active_background_color") == 0) {
610 extract_values(value, &value1, &value2, &value3);
611 get_color (value1, area_task_active->pix.back.color);
612 if (value2) area_task_active->pix.back.alpha = (atoi (value2) / 100.0);
613 else area_task_active->pix.back.alpha = 0.5;
614 }
615 else if (strcmp (key, "task_border_width") == 0) {
616 area_task->pix.border.width = atoi (value);
617 area_task_active->pix.border.width = atoi (value);
618 }
619 else if (strcmp (key, "task_border_color") == 0) {
620 extract_values(value, &value1, &value2, &value3);
621 get_color (value1, area_task->pix.border.color);
622 if (value2) area_task->pix.border.alpha = (atoi (value2) / 100.0);
623 else area_task->pix.border.alpha = 0.5;
624 }
625 else if (strcmp (key, "task_active_border_color") == 0) {
626 extract_values(value, &value1, &value2, &value3);
627 get_color (value1, area_task_active->pix.border.color);
628 if (value2) area_task_active->pix.border.alpha = (atoi (value2) / 100.0);
629 else area_task_active->pix.border.alpha = 0.5;
630 }
631
632 else
633 fprintf(stderr, "tint2 : invalid option \"%s\", correct your config file\n", key);
634
635 if (value1) free (value1);
636 if (value2) free (value2);
637 if (value3) free (value3);
638 }
639
640
641 void config_finish ()
642 {
643 if (panel_config.monitor > (server.nb_monitor-1)) {
644 // server.nb_monitor minimum value is 1 (see get_monitors())
645 // and panel_config->monitor is higher
646 fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n");
647 panel_config.monitor = 0;
648 }
649
650 // TODO: user can configure layout => ordered objects in panel.area.list
651 // clock and systray before taskbar because resize(clock) can resize others object ??
652 init_tooltip();
653 init_clock();
654 #ifdef ENABLE_BATTERY
655 init_battery();
656 #endif
657 init_systray();
658 init_panel();
659
660 cleanup_config();
661 }
662
663
664 int config_read ()
665 {
666 const gchar * const * system_dirs;
667 char *path1;
668 gint i;
669
670 save_file_config = 0;
671
672 // follow XDG specification
673 deb:
674 // check tint2rc in user directory
675 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
676 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
677 i = config_read_file (path1);
678 config_path = strdup(path1);
679 g_free(path1);
680 return i;
681 }
682
683 g_free(path1);
684 if (save_file_config) {
685 fprintf(stderr, "tint2 exit : enable to write $HOME/.config/tint2/tint2rc\n");
686 exit(0);
687 }
688
689 // check old tintrc config file
690 path1 = g_build_filename (g_get_user_config_dir(), "tint", "tintrc", NULL);
691 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
692 save_file_config = 1;
693 config_read_file (path1);
694 g_free(path1);
695 goto deb;
696 }
697
698 // copy tint2rc from system directory to user directory
699 g_free(path1);
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[80];
733 char *key, *value;
734
735 if ((fp = fopen(path, "r")) == NULL) return 0;
736 old_task_font = 0;
737 old_time1_font = 0;
738 old_time2_font = 0;
739
740 while (fgets(line, sizeof(line), fp) != NULL) {
741 if (parse_line(line, &key, &value)) {
742 add_entry (key, value);
743 free (key);
744 free (value);
745 }
746 }
747 fclose (fp);
748
749 if (save_file_config)
750 save_config();
751
752 if (old_task_font) {
753 g_free(old_task_font);
754 old_task_font = 0;
755 }
756 if (old_time1_font) {
757 g_free(old_time1_font);
758 old_time1_font = 0;
759 }
760 if (old_time2_font) {
761 g_free(old_time2_font);
762 old_time2_font = 0;
763 }
764 return 1;
765 }
766
767
768 void save_config ()
769 {
770 fprintf(stderr, "tint2 : convert user's config file\n");
771
772 char *path, *dir;
773 FILE *fp;
774
775 if (old_task_icon_size) {
776 panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
777 }
778
779 dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
780 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
781 g_free(dir);
782
783 path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
784 fp = fopen(path, "w");
785 g_free(path);
786 if (fp == NULL) return;
787
788 fputs("#---------------------------------------------\n", fp);
789 fputs("# TINT2 CONFIG FILE\n", fp);
790 fputs("#---------------------------------------------\n\n", fp);
791 fputs("#---------------------------------------------\n", fp);
792 fputs("# BACKGROUND AND BORDER\n", fp);
793 fputs("#---------------------------------------------\n", fp);
794 GSList *l0;
795 Area *a;
796 l0 = list_back->next;
797 while (l0) {
798 a = l0->data;
799 fprintf(fp, "rounded = %d\n", a->pix.border.rounded);
800 fprintf(fp, "border_width = %d\n", a->pix.border.width);
801 fprintf(fp, "background_color = #%02x%02x%02x %d\n", (int)(a->pix.back.color[0]*255), (int)(a->pix.back.color[1]*255), (int)(a->pix.back.color[2]*255), (int)(a->pix.back.alpha*100));
802 fprintf(fp, "border_color = #%02x%02x%02x %d\n\n", (int)(a->pix.border.color[0]*255), (int)(a->pix.border.color[1]*255), (int)(a->pix.border.color[2]*255), (int)(a->pix.border.alpha*100));
803
804 l0 = l0->next;
805 }
806
807 fputs("#---------------------------------------------\n", fp);
808 fputs("# PANEL\n", fp);
809 fputs("#---------------------------------------------\n", fp);
810 fputs("panel_monitor = all\n", fp);
811 if (panel_position & BOTTOM) fputs("panel_position = bottom", fp);
812 else fputs("panel_position = top", fp);
813 if (panel_position & LEFT) fputs(" left horizontal\n", fp);
814 else if (panel_position & RIGHT) fputs(" right horizontal\n", fp);
815 else fputs(" center horizontal\n", fp);
816 fprintf(fp, "panel_size = %d %d\n", panel_config.area.width, panel_config.area.height);
817 fprintf(fp, "panel_margin = %d %d\n", panel_config.marginx, panel_config.marginy);
818 fprintf(fp, "panel_padding = %d %d %d\n", panel_config.area.paddingxlr, panel_config.area.paddingy, panel_config.area.paddingx);
819 fprintf(fp, "font_shadow = %d\n", panel_config.g_task.font_shadow);
820 fputs("panel_background_id = 1\n", fp);
821 fputs("wm_menu = 0\n", fp);
822
823 fputs("\n#---------------------------------------------\n", fp);
824 fputs("# TASKBAR\n", fp);
825 fputs("#---------------------------------------------\n", fp);
826 if (panel_mode == MULTI_DESKTOP) fputs("taskbar_mode = multi_desktop\n", fp);
827 else fputs("taskbar_mode = single_desktop\n", fp);
828 fprintf(fp, "taskbar_padding = 0 0 %d\n", panel_config.g_taskbar.paddingx);
829 fputs("taskbar_background_id = 0\n", fp);
830
831 fputs("\n#---------------------------------------------\n", fp);
832 fputs("# TASK\n", fp);
833 fputs("#---------------------------------------------\n", fp);
834 if (old_task_icon_size) fputs("task_icon = 1\n", fp);
835 else fputs("task_icon = 0\n", fp);
836 fputs("task_text = 1\n", fp);
837 fprintf(fp, "task_maximum_size = %d %d\n", panel_config.g_task.maximum_width, panel_config.g_task.maximum_height);
838 fprintf(fp, "task_centered = %d\n", panel_config.g_task.centered);
839 fprintf(fp, "task_padding = %d %d\n", panel_config.g_task.area.paddingx, panel_config.g_task.area.paddingy);
840 fprintf(fp, "task_font = %s\n", old_task_font);
841 fprintf(fp, "task_font_color = #%02x%02x%02x %d\n", (int)(panel_config.g_task.font.color[0]*255), (int)(panel_config.g_task.font.color[1]*255), (int)(panel_config.g_task.font.color[2]*255), (int)(panel_config.g_task.font.alpha*100));
842 fprintf(fp, "task_active_font_color = #%02x%02x%02x %d\n", (int)(panel_config.g_task.font_active.color[0]*255), (int)(panel_config.g_task.font_active.color[1]*255), (int)(panel_config.g_task.font_active.color[2]*255), (int)(panel_config.g_task.font_active.alpha*100));
843 fputs("task_background_id = 2\n", fp);
844 fputs("task_active_background_id = 3\n", fp);
845
846 fputs("\n#---------------------------------------------\n", fp);
847 fputs("# SYSTRAYBAR\n", fp);
848 fputs("#---------------------------------------------\n", fp);
849 fputs("systray_padding = 4 3 4\n", fp);
850 fputs("systray_background_id = 0\n", fp);
851
852 fputs("\n#---------------------------------------------\n", fp);
853 fputs("# CLOCK\n", fp);
854 fputs("#---------------------------------------------\n", fp);
855 if (time1_format) fprintf(fp, "time1_format = %s\n", time1_format);
856 else fputs("#time1_format = %H:%M\n", fp);
857 fprintf(fp, "time1_font = %s\n", old_time1_font);
858 if (time2_format) fprintf(fp, "time2_format = %s\n", time2_format);
859 else fputs("#time2_format = %A %d %B\n", fp);
860 fprintf(fp, "time2_font = %s\n", old_time2_font);
861 fprintf(fp, "clock_font_color = #%02x%02x%02x %d\n", (int)(panel_config.clock.font.color[0]*255), (int)(panel_config.clock.font.color[1]*255), (int)(panel_config.clock.font.color[2]*255), (int)(panel_config.clock.font.alpha*100));
862 fputs("clock_padding = 2 2\n", fp);
863 fputs("clock_background_id = 0\n", fp);
864 fputs("#clock_lclick_command = xclock\n", fp);
865 fputs("clock_rclick_command = orage\n", fp);
866
867 #ifdef ENABLE_BATTERY
868 fputs("\n#---------------------------------------------\n", fp);
869 fputs("# BATTERY\n", fp);
870 fputs("#---------------------------------------------\n", fp);
871 fprintf(fp, "battery = %d\n", panel_config.battery.area.on_screen);
872 fprintf(fp, "battery_low_status = %d\n", battery_low_status);
873 fprintf(fp, "battery_low_cmd = %s\n", battery_low_cmd);
874 fprintf(fp, "bat1_font = %s\n", old_bat1_font);
875 fprintf(fp, "bat2_font = %s\n", old_bat2_font);
876 fprintf(fp, "battery_font_color = #%02x%02x%02x %d\n", (int)(panel_config.battery.font.color[0]*255), (int)(panel_config.battery.font.color[1]*255), (int)(panel_config.battery.font.color[2]*255), (int)(panel_config.battery.font.alpha*100));
877 fputs("battery_padding = 2 2\n", fp);
878 fputs("battery_background_id = 0\n", fp);
879 #endif
880
881 fputs("\n#---------------------------------------------\n", fp);
882 fputs("# MOUSE ACTION ON TASK\n", fp);
883 fputs("#---------------------------------------------\n", fp);
884 if (mouse_middle == NONE) fputs("mouse_middle = none\n", fp);
885 else if (mouse_middle == CLOSE) fputs("mouse_middle = close\n", fp);
886 else if (mouse_middle == TOGGLE) fputs("mouse_middle = toggle\n", fp);
887 else if (mouse_middle == ICONIFY) fputs("mouse_middle = iconify\n", fp);
888 else if (mouse_middle == SHADE) fputs("mouse_middle = shade\n", fp);
889 else fputs("mouse_middle = toggle_iconify\n", fp);
890
891 if (mouse_right == NONE) fputs("mouse_right = none\n", fp);
892 else if (mouse_right == CLOSE) fputs("mouse_right = close\n", fp);
893 else if (mouse_right == TOGGLE) fputs("mouse_right = toggle\n", fp);
894 else if (mouse_right == ICONIFY) fputs("mouse_right = iconify\n", fp);
895 else if (mouse_right == SHADE) fputs("mouse_right = shade\n", fp);
896 else fputs("mouse_right = toggle_iconify\n", fp);
897
898 if (mouse_scroll_up == NONE) fputs("mouse_scroll_up = none\n", fp);
899 else if (mouse_scroll_up == CLOSE) fputs("mouse_scroll_up = close\n", fp);
900 else if (mouse_scroll_up == TOGGLE) fputs("mouse_scroll_up = toggle\n", fp);
901 else if (mouse_scroll_up == ICONIFY) fputs("mouse_scroll_up = iconify\n", fp);
902 else if (mouse_scroll_up == SHADE) fputs("mouse_scroll_up = shade\n", fp);
903 else fputs("mouse_scroll_up = toggle_iconify\n", fp);
904
905 if (mouse_scroll_down == NONE) fputs("mouse_scroll_down = none\n", fp);
906 else if (mouse_scroll_down == CLOSE) fputs("mouse_scroll_down = close\n", fp);
907 else if (mouse_scroll_down == TOGGLE) fputs("mouse_scroll_down = toggle\n", fp);
908 else if (mouse_scroll_down == ICONIFY) fputs("mouse_scroll_down = iconify\n", fp);
909 else if (mouse_scroll_down == SHADE) fputs("mouse_scroll_down = shade\n", fp);
910 else fputs("mouse_scroll_down = toggle_iconify\n", fp);
911
912 fputs("\n\n", fp);
913 fclose (fp);
914 }
915
This page took 0.094174 seconds and 4 git commands to generate.