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