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