]> Dogcows Code - chaz/tint2/blob - src/config.c
fd1cfcc82a2dcccd420c922a00589e6ffdc2737f
[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 "task.h"
40 #include "taskbar.h"
41 #include "clock.h"
42 #include "panel.h"
43 #include "config.h"
44 #include "window.h"
45
46
47 void cleanup_taskbar()
48 {
49 GSList *l0;
50 Task *tsk;
51
52 int i, nb;
53 nb = panel.nb_desktop * panel.nb_monitor;
54 for (i=0 ; i < nb ; i++) {
55 l0 = panel.taskbar[i].area.list;
56 while (l0) {
57 tsk = l0->data;
58 l0 = l0->next;
59 // careful : remove_task change l0->next
60 remove_task (tsk);
61 }
62
63 free_area (&panel.taskbar[i].area);
64 }
65
66 free(panel.taskbar);
67 panel.taskbar = 0;
68
69 free_area(&panel.area);
70 }
71
72
73 void cleanup ()
74 {
75 if (panel.old_task_font) free(panel.old_task_font);
76 if (g_task.font_desc) pango_font_description_free(g_task.font_desc);
77 if (panel.clock.time1_font_desc) pango_font_description_free(panel.clock.time1_font_desc);
78 if (panel.clock.time2_font_desc) pango_font_description_free(panel.clock.time2_font_desc);
79 if (panel.taskbar) cleanup_taskbar();
80 if (panel.clock.time1_format) g_free(panel.clock.time1_format);
81 if (panel.clock.time2_format) g_free(panel.clock.time2_format);
82 if (server.monitor) free(server.monitor);
83 XCloseDisplay(server.dsp);
84 }
85
86
87 void copy_file(const char *pathSrc, const char *pathDest)
88 {
89 FILE *fileSrc, *fileDest;
90 char line[100];
91 int nb;
92
93 fileSrc = fopen(pathSrc, "rb");
94 if (fileSrc == NULL) return;
95
96 fileDest = fopen(pathDest, "wb");
97 if (fileDest == NULL) return;
98
99 while ((nb = fread(line, 1, 100, fileSrc)) > 0) fwrite(line, 1, nb, fileDest);
100
101 fclose (fileDest);
102 fclose (fileSrc);
103 }
104
105
106 void extract_values (const char *value, char **value1, char **value2, char **value3)
107 {
108 char *b=0, *c=0;
109
110 if (*value1) free (*value1);
111 if (*value2) free (*value2);
112 if (*value3) free (*value3);
113
114 if ((b = strchr (value, ' '))) {
115 b[0] = '\0';
116 b++;
117 }
118 else {
119 *value2 = 0;
120 *value3 = 0;
121 }
122 *value1 = strdup (value);
123 g_strstrip(*value1);
124
125 if (b) {
126 if ((c = strchr (b, ' '))) {
127 c[0] = '\0';
128 c++;
129 }
130 else {
131 c = 0;
132 *value3 = 0;
133 }
134 *value2 = strdup (b);
135 g_strstrip(*value2);
136 }
137
138 if (c) {
139 *value3 = strdup (c);
140 g_strstrip(*value3);
141 }
142 }
143
144
145 int hex_char_to_int (char c)
146 {
147 int r;
148
149 if (c >= '0' && c <= '9') r = c - '0';
150 else if (c >= 'a' && c <= 'f') r = c - 'a' + 10;
151 else if (c >= 'A' && c <= 'F') r = c - 'A' + 10;
152 else r = 0;
153
154 return r;
155 }
156
157
158 int hex_to_rgb (char *hex, int *r, int *g, int *b)
159 {
160 int len;
161
162 if (hex == NULL || hex[0] != '#') return (0);
163
164 len = strlen (hex);
165 if (len == 3 + 1) {
166 *r = hex_char_to_int (hex[1]);
167 *g = hex_char_to_int (hex[2]);
168 *b = hex_char_to_int (hex[3]);
169 }
170 else if (len == 6 + 1) {
171 *r = hex_char_to_int (hex[1]) * 16 + hex_char_to_int (hex[2]);
172 *g = hex_char_to_int (hex[3]) * 16 + hex_char_to_int (hex[4]);
173 *b = hex_char_to_int (hex[5]) * 16 + hex_char_to_int (hex[6]);
174 }
175 else if (len == 12 + 1) {
176 *r = hex_char_to_int (hex[1]) * 16 + hex_char_to_int (hex[2]);
177 *g = hex_char_to_int (hex[5]) * 16 + hex_char_to_int (hex[6]);
178 *b = hex_char_to_int (hex[9]) * 16 + hex_char_to_int (hex[10]);
179 }
180 else return 0;
181
182 return 1;
183 }
184
185
186 void get_color (char *hex, double *rgb)
187 {
188 int r, g, b;
189 hex_to_rgb (hex, &r, &g, &b);
190
191 rgb[0] = (r / 255.0);
192 rgb[1] = (g / 255.0);
193 rgb[2] = (b / 255.0);
194 }
195
196
197 void get_action (char *event, int *action)
198 {
199 if (strcmp (event, "none") == 0)
200 *action = NONE;
201 else if (strcmp (event, "close") == 0)
202 *action = CLOSE;
203 else if (strcmp (event, "toggle") == 0)
204 *action = TOGGLE;
205 else if (strcmp (event, "iconify") == 0)
206 *action = ICONIFY;
207 else if (strcmp (event, "shade") == 0)
208 *action = SHADE;
209 else if (strcmp (event, "toggle_iconify") == 0)
210 *action = TOGGLE_ICONIFY;
211 }
212
213
214 void add_entry (char *key, char *value)
215 {
216 char *value1=0, *value2=0, *value3=0;
217
218 /* Background and border */
219 if (strcmp (key, "rounded") == 0) {
220 // 'rounded' is the first parameter => alloc a new background
221 Area *a = calloc(1, sizeof(Area));
222 a->pix.border.rounded = atoi (value);
223 list_back = g_slist_append(list_back, a);
224 }
225 else if (strcmp (key, "border_width") == 0) {
226 Area *a = g_slist_last(list_back)->data;
227 a->pix.border.width = atoi (value);
228 }
229 else if (strcmp (key, "background_color") == 0) {
230 Area *a = g_slist_last(list_back)->data;
231 extract_values(value, &value1, &value2, &value3);
232 get_color (value1, a->pix.back.color);
233 if (value2) a->pix.back.alpha = (atoi (value2) / 100.0);
234 else a->pix.back.alpha = 0.5;
235 }
236 else if (strcmp (key, "border_color") == 0) {
237 Area *a = g_slist_last(list_back)->data;
238 extract_values(value, &value1, &value2, &value3);
239 get_color (value1, a->pix.border.color);
240 if (value2) a->pix.border.alpha = (atoi (value2) / 100.0);
241 else a->pix.border.alpha = 0.5;
242 }
243
244 /* Panel */
245 else if (strcmp (key, "panel_monitor") == 0) {
246 panel.monitor = atoi (value);
247 if (panel.monitor > 0) panel.monitor -= 1;
248 }
249 else if (strcmp (key, "panel_size") == 0) {
250 extract_values(value, &value1, &value2, &value3);
251 panel.area.width = atoi (value1);
252 if (value2) panel.area.height = atoi (value2);
253 }
254 else if (strcmp (key, "panel_margin") == 0) {
255 extract_values(value, &value1, &value2, &value3);
256 panel.marginleft = panel.marginright = atoi (value1);
257 if (value2) panel.marginy = atoi (value2);
258 if (value3) panel.marginright = atoi (value3);
259 }
260 else if (strcmp (key, "panel_padding") == 0) {
261 extract_values(value, &value1, &value2, &value3);
262 panel.area.paddingxlr = panel.area.paddingx = atoi (value1);
263 if (value2) panel.area.paddingy = atoi (value2);
264 if (value3) panel.area.paddingx = atoi (value3);
265 }
266 else if (strcmp (key, "panel_position") == 0) {
267 extract_values(value, &value1, &value2, &value3);
268 if (strcmp (value1, "top") == 0) panel.position = TOP;
269 else panel.position = BOTTOM;
270
271 if (!value2) panel.position = CENTER;
272 else {
273 if (strcmp (value2, "left") == 0) panel.position |= LEFT;
274 else {
275 if (strcmp (value2, "right") == 0) panel.position |= RIGHT;
276 else panel.position |= CENTER;
277 }
278 }
279 }
280 else if (strcmp (key, "font_shadow") == 0)
281 g_task.font_shadow = atoi (value);
282 else if (strcmp (key, "panel_background_id") == 0) {
283 int id = atoi (value);
284 Area *a = g_slist_nth_data(list_back, id);
285 memcpy(&panel.area.pix.back, &a->pix.back, sizeof(Color));
286 memcpy(&panel.area.pix.border, &a->pix.border, sizeof(Border));
287 }
288
289 /* Clock */
290 else if (strcmp (key, "time1_format") == 0) {
291 if (panel.clock.time1_format) g_free(panel.clock.time1_format);
292 if (strlen(value) > 0) panel.clock.time1_format = strdup (value);
293 else panel.clock.time1_format = 0;
294 }
295 else if (strcmp (key, "time2_format") == 0) {
296 if (panel.clock.time2_format) g_free(panel.clock.time2_format);
297 if (strlen(value) > 0) panel.clock.time2_format = strdup (value);
298 else panel.clock.time2_format = 0;
299 }
300 else if (strcmp (key, "time1_font") == 0) {
301 if (panel.clock.time1_font_desc) pango_font_description_free(panel.clock.time1_font_desc);
302 panel.clock.time1_font_desc = pango_font_description_from_string (value);
303 }
304 else if (strcmp (key, "time2_font") == 0) {
305 if (panel.clock.time2_font_desc) pango_font_description_free(panel.clock.time2_font_desc);
306 panel.clock.time2_font_desc = pango_font_description_from_string (value);
307 }
308 else if (strcmp (key, "clock_font_color") == 0) {
309 extract_values(value, &value1, &value2, &value3);
310 get_color (value1, panel.clock.font.color);
311 if (value2) panel.clock.font.alpha = (atoi (value2) / 100.0);
312 else panel.clock.font.alpha = 0.1;
313 }
314 else if (strcmp (key, "clock_padding") == 0) {
315 extract_values(value, &value1, &value2, &value3);
316 panel.clock.area.paddingxlr = panel.clock.area.paddingx = atoi (value1);
317 if (value2) panel.clock.area.paddingy = atoi (value2);
318 if (value3) panel.clock.area.paddingx = atoi (value3);
319 }
320 else if (strcmp (key, "clock_background_id") == 0) {
321 int id = atoi (value);
322 Area *a = g_slist_nth_data(list_back, id);
323 memcpy(&panel.clock.area.pix.back, &a->pix.back, sizeof(Color));
324 memcpy(&panel.clock.area.pix.border, &a->pix.border, sizeof(Border));
325 }
326
327 /* Taskbar */
328 else if (strcmp (key, "taskbar_mode") == 0) {
329 if (strcmp (value, "multi_desktop") == 0) panel.mode = MULTI_DESKTOP;
330 else if (strcmp (value, "multi_monitor") == 0) panel.mode = MULTI_MONITOR;
331 else panel.mode = SINGLE_DESKTOP;
332 }
333 else if (strcmp (key, "taskbar_padding") == 0) {
334 extract_values(value, &value1, &value2, &value3);
335 g_taskbar.paddingxlr = g_taskbar.paddingx = atoi (value1);
336 if (value2) g_taskbar.paddingy = atoi (value2);
337 if (value3) g_taskbar.paddingx = atoi (value3);
338 }
339 else if (strcmp (key, "taskbar_background_id") == 0) {
340 int id = atoi (value);
341 Area *a = g_slist_nth_data(list_back, id);
342 memcpy(&g_taskbar.pix.back, &a->pix.back, sizeof(Color));
343 memcpy(&g_taskbar.pix.border, &a->pix.border, sizeof(Border));
344 }
345
346 /* Task */
347 else if (strcmp (key, "task_text") == 0)
348 g_task.text = atoi (value);
349 else if (strcmp (key, "task_icon") == 0)
350 g_task.icon = atoi (value);
351 else if (strcmp (key, "task_centered") == 0)
352 g_task.centered = atoi (value);
353 else if (strcmp (key, "task_width") == 0)
354 g_task.maximum_width = atoi (value);
355 else if (strcmp (key, "task_padding") == 0) {
356 extract_values(value, &value1, &value2, &value3);
357 g_task.area.paddingxlr = g_task.area.paddingx = atoi (value1);
358 if (value2) g_task.area.paddingy = atoi (value2);
359 if (value3) g_task.area.paddingx = atoi (value3);
360 }
361 else if (strcmp (key, "task_font") == 0) {
362 if (g_task.font_desc) pango_font_description_free(g_task.font_desc);
363 g_task.font_desc = pango_font_description_from_string (value);
364 }
365 else if (strcmp (key, "task_font_color") == 0) {
366 extract_values(value, &value1, &value2, &value3);
367 get_color (value1, g_task.font.color);
368 if (value2) g_task.font.alpha = (atoi (value2) / 100.0);
369 else g_task.font.alpha = 0.1;
370 }
371 else if (strcmp (key, "task_active_font_color") == 0) {
372 extract_values(value, &value1, &value2, &value3);
373 get_color (value1, g_task.font_active.color);
374 if (value2) g_task.font_active.alpha = (atoi (value2) / 100.0);
375 else g_task.font_active.alpha = 0.1;
376 }
377 else if (strcmp (key, "task_background_id") == 0) {
378 int id = atoi (value);
379 Area *a = g_slist_nth_data(list_back, id);
380 memcpy(&g_task.area.pix.back, &a->pix.back, sizeof(Color));
381 memcpy(&g_task.area.pix.border, &a->pix.border, sizeof(Border));
382 }
383 else if (strcmp (key, "task_active_background_id") == 0) {
384 int id = atoi (value);
385 Area *a = g_slist_nth_data(list_back, id);
386 memcpy(&g_task.area.pix_active.back, &a->pix.back, sizeof(Color));
387 memcpy(&g_task.area.pix_active.border, &a->pix.border, sizeof(Border));
388 }
389
390 /* Mouse actions */
391 else if (strcmp (key, "mouse_middle") == 0)
392 get_action (value, &panel.mouse_middle);
393 else if (strcmp (key, "mouse_right") == 0)
394 get_action (value, &panel.mouse_right);
395 else if (strcmp (key, "mouse_scroll_up") == 0)
396 get_action (value, &panel.mouse_scroll_up);
397 else if (strcmp (key, "mouse_scroll_down") == 0)
398 get_action (value, &panel.mouse_scroll_down);
399
400
401 /* Read old config for backward compatibility */
402 else if (strcmp (key, "font") == 0) {
403 panel.old_config_file = 1;
404 if (g_task.font_desc) pango_font_description_free(g_task.font_desc);
405 g_task.font_desc = pango_font_description_from_string (value);
406 if (panel.old_task_font) free(panel.old_task_font);
407 panel.old_task_font = strdup (value);
408 }
409 else if (strcmp (key, "font_color") == 0)
410 get_color (value, g_task.font.color);
411 else if (strcmp (key, "font_alpha") == 0)
412 g_task.font.alpha = (atoi (value) / 100.0);
413 else if (strcmp (key, "font_active_color") == 0)
414 get_color (value, g_task.font_active.color);
415 else if (strcmp (key, "font_active_alpha") == 0)
416 g_task.font_active.alpha = (atoi (value) / 100.0);
417 else if (strcmp (key, "panel_show_all_desktop") == 0) {
418 if (atoi (value) == 0) panel.mode = SINGLE_DESKTOP;
419 else panel.mode = MULTI_DESKTOP;
420 }
421 else if (strcmp (key, "panel_width") == 0)
422 panel.area.width = atoi (value);
423 else if (strcmp (key, "panel_height") == 0)
424 panel.area.height = atoi (value);
425 else if (strcmp (key, "panel_background") == 0)
426 panel.old_panel_background = atoi (value);
427 else if (strcmp (key, "panel_background_alpha") == 0)
428 panel.area.pix.back.alpha = (atoi (value) / 100.0);
429 else if (strcmp (key, "panel_border_alpha") == 0)
430 panel.area.pix.border.alpha = (atoi (value) / 100.0);
431 else if (strcmp (key, "task_icon") == 0)
432 panel.old_task_icon = atoi (value);
433 else if (strcmp (key, "task_background") == 0)
434 panel.old_task_background = atoi (value);
435 else if (strcmp (key, "task_background_alpha") == 0)
436 g_task.area.pix.back.alpha = (atoi (value) / 100.0);
437 else if (strcmp (key, "task_active_background_alpha") == 0)
438 g_task.area.pix_active.back.alpha = (atoi (value) / 100.0);
439 else if (strcmp (key, "task_border_alpha") == 0)
440 g_task.area.pix.border.alpha = (atoi (value) / 100.0);
441 else if (strcmp (key, "task_active_border_alpha") == 0)
442 g_task.area.pix_active.border.alpha = (atoi (value) / 100.0);
443 // disabled parameters
444 else if (strcmp (key, "task_active_border_width") == 0) ;
445 else if (strcmp (key, "task_active_rounded") == 0) ;
446
447 else
448 fprintf(stderr, "Invalid option: \"%s\", correct your config file\n", key);
449
450 if (value1) free (value1);
451 if (value2) free (value2);
452 if (value3) free (value3);
453 }
454
455
456 int parse_line (const char *line)
457 {
458 char *a, *b, *key, *value;
459
460 /* Skip useless lines */
461 if ((line[0] == '#') || (line[0] == '\n')) return 0;
462 if (!(a = strchr (line, '='))) return 0;
463
464 /* overwrite '=' with '\0' */
465 a[0] = '\0';
466 key = strdup (line);
467 a++;
468
469 /* overwrite '\n' with '\0' if '\n' present */
470 if ((b = strchr (a, '\n'))) b[0] = '\0';
471
472 value = strdup (a);
473
474 g_strstrip(key);
475 g_strstrip(value);
476
477 add_entry (key, value);
478
479 free (key);
480 free (value);
481 return 1;
482 }
483
484
485 void config_taskbar()
486 {
487 int i, j;
488
489 if (g_task.area.pix.border.rounded > g_task.area.height/2) {
490 g_task.area.pix.border.rounded = g_task.area.height/2;
491 g_task.area.pix_active.border.rounded = g_task.area.pix.border.rounded;
492 }
493
494 for (i=0 ; i < 15 ; i++) {
495 server.nb_desktop = server_get_number_of_desktop ();
496 if (server.nb_desktop > 0) break;
497 sleep(1);
498 }
499 if (server.nb_desktop == 0) {
500 server.nb_desktop = 1;
501 fprintf(stderr, "tint2 warning : cannot found number of desktop.\n");
502 }
503
504 if (panel.taskbar) cleanup_taskbar();
505
506 panel.nb_desktop = server.nb_desktop;
507 if (panel.mode == MULTI_MONITOR) panel.nb_monitor = server.nb_monitor;
508 else panel.nb_monitor = 1;
509 panel.taskbar = calloc(panel.nb_desktop * panel.nb_monitor, sizeof(Taskbar));
510 g_slist_free(panel.area.list);
511 panel.area.list = 0;
512
513 Taskbar *tskbar;
514 for (i=0 ; i < panel.nb_desktop ; i++) {
515 for (j=0 ; j < panel.nb_monitor ; j++) {
516 tskbar = &panel.taskbar[index(i,j)];
517 memcpy(&tskbar->area, &g_taskbar, sizeof(Area));
518 tskbar->desktop = i;
519 tskbar->monitor = j;
520
521 // TODO: redefinir panel.area.list en fonction des objets visibles
522 panel.area.list = g_slist_append(panel.area.list, tskbar);
523 }
524 }
525 if (panel.clock.time1_format)
526 panel.area.list = g_slist_append(panel.area.list, &panel.clock);
527
528 //printf("taskbar (desktop x monitor) : (%d x %d)\n", panel.nb_desktop, panel.nb_monitor);
529 resize_taskbar();
530 task_refresh_tasklist ();
531 panel.refresh = 1;
532 }
533
534
535 void config_finish ()
536 {
537 int height_ink, height;
538
539 if (panel.old_config_file) save_config();
540
541 // get monitor's configuration
542 get_monitors();
543
544 if (panel.monitor > (server.nb_monitor-1)) {
545 panel.sleep_mode = 1;
546 fprintf(stderr, "tint2 sleep and wait monitor %d.\n", panel.monitor+1);
547 }
548 else {
549 panel.sleep_mode = 0;
550 //printf("tint2 wake up on monitor %d\n", panel.monitor+1);
551 if (!server.monitor[panel.monitor].width || !server.monitor[panel.monitor].height)
552 fprintf(stderr, "tint2 error : invalid monitor size.\n");
553 }
554
555 if (!panel.area.width) panel.area.width = server.monitor[panel.monitor].width - 1 - panel.marginleft - panel.marginright;
556
557 // taskbar
558 g_taskbar.posy = panel.area.pix.border.width + panel.area.paddingy;
559 g_taskbar.height = panel.area.height - (2 * g_taskbar.posy);
560 g_taskbar.redraw = 1;
561
562 // task
563 g_task.area.posy = g_taskbar.posy + g_taskbar.pix.border.width + g_taskbar.paddingy;
564 g_task.area.height = panel.area.height - (2 * g_task.area.posy);
565 g_task.area.use_active = 1;
566 g_task.area.redraw = 1;
567
568 if (!g_task.maximum_width)
569 g_task.maximum_width = server.monitor[panel.monitor].width;
570
571 if (panel.area.pix.border.rounded > panel.area.height/2)
572 panel.area.pix.border.rounded = panel.area.height/2;
573
574 // clock
575 init_clock(&panel.clock, panel.area.height);
576
577 // compute vertical position : text and icon
578 get_text_size(g_task.font_desc, &height_ink, &height, panel.area.height, "TAjpg", 5);
579 g_task.text_posy = (g_task.area.height - height) / 2.0;
580
581 // add task_icon_size
582 g_task.text_posx = g_task.area.paddingxlr + g_task.area.pix.border.width;
583 if (g_task.icon) {
584 g_task.icon_size1 = g_task.area.height - (2 * g_task.area.paddingy);
585 g_task.text_posx += g_task.icon_size1;
586 g_task.icon_posy = (g_task.area.height - g_task.icon_size1) / 2;
587 }
588
589 config_taskbar();
590 visible_object();
591
592 // cleanup background list
593 GSList *l0;
594 for (l0 = list_back; l0 ; l0 = l0->next) {
595 free(l0->data);
596 }
597 g_slist_free(list_back);
598 list_back = NULL;
599 }
600
601
602 int config_read ()
603 {
604 const gchar * const * system_dirs;
605 char *path1, *path2, *dir;
606 gint i;
607
608 // check tint2rc file according to XDG specification
609 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
610 if (!g_file_test (path1, G_FILE_TEST_EXISTS)) {
611
612 path2 = 0;
613 system_dirs = g_get_system_config_dirs();
614 for (i = 0; system_dirs[i]; i++) {
615 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
616
617 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
618 g_free (path2);
619 path2 = 0;
620 }
621
622 if (path2) {
623 // copy file in user directory (path1)
624 dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
625 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
626 g_free(dir);
627
628 copy_file(path2, path1);
629 g_free(path2);
630 }
631 }
632
633 i = config_read_file (path1);
634 g_free(path1);
635 return i;
636 }
637
638
639 int config_read_file (const char *path)
640 {
641 FILE *fp;
642 char line[80];
643
644 if ((fp = fopen(path, "r")) == NULL) return 0;
645
646 while (fgets(line, sizeof(line), fp) != NULL)
647 parse_line (line);
648
649 fclose (fp);
650 return 1;
651 }
652
653
654 void save_config ()
655 {
656 fprintf(stderr, "tint2 warning : convert user's config file\n");
657 panel.area.paddingx = panel.area.paddingy = panel.marginleft;
658 panel.marginleft = panel.marginright = panel.marginy = 0;
659
660 if (panel.old_task_icon == 0) g_task.icon_size1 = 0;
661 if (panel.old_panel_background == 0) panel.area.pix.back.alpha = 0;
662 if (panel.old_task_background == 0) {
663 g_task.area.pix.back.alpha = 0;
664 g_task.area.pix_active.back.alpha = 0;
665 }
666 g_task.area.pix.border.rounded = g_task.area.pix.border.rounded / 2;
667 g_task.area.pix_active.border.rounded = g_task.area.pix.border.rounded;
668 panel.area.pix.border.rounded = panel.area.pix.border.rounded / 2;
669
670 char *path;
671 FILE *fp;
672
673 path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
674 fp = fopen(path, "w");
675 g_free(path);
676 if (fp == NULL) return;
677
678 fputs("#---------------------------------------------\n", fp);
679 fputs("# TINT CONFIG FILE\n", fp);
680 fputs("#---------------------------------------------\n\n", fp);
681 fputs("#---------------------------------------------\n", fp);
682 fputs("# PANEL\n", fp);
683 fputs("#---------------------------------------------\n", fp);
684 if (panel.mode == SINGLE_DESKTOP) fputs("panel_mode = single_desktop\n", fp);
685 else fputs("panel_mode = multi_desktop\n", fp);
686 fputs("panel_monitor = 1\n", fp);
687 if (panel.position & BOTTOM) fputs("panel_position = bottom", fp);
688 else fputs("panel_position = top", fp);
689 if (panel.position & LEFT) fputs(" left\n", fp);
690 else if (panel.position & RIGHT) fputs(" right\n", fp);
691 else fputs(" center\n", fp);
692 fprintf(fp, "panel_size = %d %d\n", panel.area.width, panel.area.height);
693 fprintf(fp, "panel_margin = %d %d\n", panel.marginleft, panel.marginy);
694 fprintf(fp, "panel_padding = %d %d\n", panel.area.paddingx, panel.area.paddingy);
695 fprintf(fp, "font_shadow = %d\n", g_task.font_shadow);
696
697 fputs("\n#---------------------------------------------\n", fp);
698 fputs("# PANEL BACKGROUND AND BORDER\n", fp);
699 fputs("#---------------------------------------------\n", fp);
700 fprintf(fp, "panel_rounded = %d\n", panel.area.pix.border.rounded);
701 fprintf(fp, "panel_border_width = %d\n", panel.area.pix.border.width);
702 fprintf(fp, "panel_background_color = #%02x%02x%02x %d\n", (int)(panel.area.pix.back.color[0]*255), (int)(panel.area.pix.back.color[1]*255), (int)(panel.area.pix.back.color[2]*255), (int)(panel.area.pix.back.alpha*100));
703 fprintf(fp, "panel_border_color = #%02x%02x%02x %d\n", (int)(panel.area.pix.border.color[0]*255), (int)(panel.area.pix.border.color[1]*255), (int)(panel.area.pix.border.color[2]*255), (int)(panel.area.pix.border.alpha*100));
704
705 fputs("\n#---------------------------------------------\n", fp);
706 fputs("# TASKS\n", fp);
707 fputs("#---------------------------------------------\n", fp);
708 fprintf(fp, "task_centered = %d\n", g_task.centered);
709 fprintf(fp, "task_width = %d\n", g_task.maximum_width);
710 fprintf(fp, "task_padding = %d\n", g_task.area.paddingx);
711 fprintf(fp, "task_icon = %d\n", g_task.icon);
712 fprintf(fp, "task_font = %s\n", panel.old_task_font);
713 fprintf(fp, "task_font_color = #%02x%02x%02x %d\n", (int)(g_task.font.color[0]*255), (int)(g_task.font.color[1]*255), (int)(g_task.font.color[2]*255), (int)(g_task.font.alpha*100));
714 fprintf(fp, "task_active_font_color = #%02x%02x%02x %d\n", (int)(g_task.font_active.color[0]*255), (int)(g_task.font_active.color[1]*255), (int)(g_task.font_active.color[2]*255), (int)(g_task.font_active.alpha*100));
715
716 fputs("\n#---------------------------------------------\n", fp);
717 fputs("# TASK BACKGROUND AND BORDER\n", fp);
718 fputs("#---------------------------------------------\n", fp);
719 fprintf(fp, "task_rounded = %d\n", g_task.area.pix.border.rounded);
720 fprintf(fp, "task_background_color = #%02x%02x%02x %d\n", (int)(g_task.area.pix.back.color[0]*255), (int)(g_task.area.pix.back.color[1]*255), (int)(g_task.area.pix.back.color[2]*255), (int)(g_task.area.pix.back.alpha*100));
721 fprintf(fp, "task_active_background_color = #%02x%02x%02x %d\n", (int)(g_task.area.pix_active.back.color[0]*255), (int)(g_task.area.pix_active.back.color[1]*255), (int)(g_task.area.pix_active.back.color[2]*255), (int)(g_task.area.pix_active.back.alpha*100));
722 fprintf(fp, "task_border_width = %d\n", g_task.area.pix.border.width);
723 fprintf(fp, "task_border_color = #%02x%02x%02x %d\n", (int)(g_task.area.pix.border.color[0]*255), (int)(g_task.area.pix.border.color[1]*255), (int)(g_task.area.pix.border.color[2]*255), (int)(g_task.area.pix.border.alpha*100));
724 fprintf(fp, "task_active_border_color = #%02x%02x%02x %d\n", (int)(g_task.area.pix_active.border.color[0]*255), (int)(g_task.area.pix_active.border.color[1]*255), (int)(g_task.area.pix_active.border.color[2]*255), (int)(g_task.area.pix_active.border.alpha*100));
725
726 fputs("\n#---------------------------------------------\n", fp);
727 fputs("# CLOCK\n", fp);
728 fputs("#---------------------------------------------\n", fp);
729 fputs("#time1_format = %H:%M\n", fp);
730 fputs("time1_font = sans bold 8\n", fp);
731 fputs("#time2_format = %A %d %B\n", fp);
732 fputs("time2_font = sans 6\n", fp);
733 fputs("clock_font_color = #ffffff 75\n", fp);
734
735 fputs("\n#---------------------------------------------\n", fp);
736 fputs("# MOUSE ACTION ON TASK\n", fp);
737 fputs("#---------------------------------------------\n", fp);
738 if (panel.mouse_middle == NONE) fputs("mouse_middle = none\n", fp);
739 else if (panel.mouse_middle == CLOSE) fputs("mouse_middle = close\n", fp);
740 else if (panel.mouse_middle == TOGGLE) fputs("mouse_middle = toggle\n", fp);
741 else if (panel.mouse_middle == ICONIFY) fputs("mouse_middle = iconify\n", fp);
742 else if (panel.mouse_middle == SHADE) fputs("mouse_middle = shade\n", fp);
743 else fputs("mouse_middle = toggle_iconify\n", fp);
744
745 if (panel.mouse_right == NONE) fputs("mouse_right = none\n", fp);
746 else if (panel.mouse_right == CLOSE) fputs("mouse_right = close\n", fp);
747 else if (panel.mouse_right == TOGGLE) fputs("mouse_right = toggle\n", fp);
748 else if (panel.mouse_right == ICONIFY) fputs("mouse_right = iconify\n", fp);
749 else if (panel.mouse_right == SHADE) fputs("mouse_right = shade\n", fp);
750 else fputs("mouse_right = toggle_iconify\n", fp);
751
752 if (panel.mouse_scroll_up == NONE) fputs("mouse_scroll_up = none\n", fp);
753 else if (panel.mouse_scroll_up == CLOSE) fputs("mouse_scroll_up = close\n", fp);
754 else if (panel.mouse_scroll_up == TOGGLE) fputs("mouse_scroll_up = toggle\n", fp);
755 else if (panel.mouse_scroll_up == ICONIFY) fputs("mouse_scroll_up = iconify\n", fp);
756 else if (panel.mouse_scroll_up == SHADE) fputs("mouse_scroll_up = shade\n", fp);
757 else fputs("mouse_scroll_up = toggle_iconify\n", fp);
758
759 if (panel.mouse_scroll_down == NONE) fputs("mouse_scroll_down = none\n", fp);
760 else if (panel.mouse_scroll_down == CLOSE) fputs("mouse_scroll_down = close\n", fp);
761 else if (panel.mouse_scroll_down == TOGGLE) fputs("mouse_scroll_down = toggle\n", fp);
762 else if (panel.mouse_scroll_down == ICONIFY) fputs("mouse_scroll_down = iconify\n", fp);
763 else if (panel.mouse_scroll_down == SHADE) fputs("mouse_scroll_down = shade\n", fp);
764 else fputs("mouse_scroll_down = toggle_iconify\n", fp);
765
766 fputs("\n\n", fp);
767 fclose (fp);
768
769 panel.old_config_file = 0;
770 }
771
This page took 0.076968 seconds and 3 git commands to generate.