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