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