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