]> Dogcows Code - chaz/tint2/blob - src/config.c
sample-task-align.patch, src-task-align.patch
[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) from Omega distribution
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 <pango/pangoxft.h>
36 #include <Imlib2.h>
37
38 #include "common.h"
39 #include "server.h"
40 #include "panel.h"
41 #include "task.h"
42 #include "taskbar.h"
43 #include "taskbarname.h"
44 #include "systraybar.h"
45 #include "launcher.h"
46 #include "clock.h"
47 #include "config.h"
48 #include "window.h"
49 #include "tooltip.h"
50 #include "timer.h"
51
52 #ifdef ENABLE_BATTERY
53 #include "battery.h"
54 #endif
55
56 // global path
57 char *config_path;
58 char *snapshot_path;
59
60 // --------------------------------------------------
61 // backward compatibility
62 // detect if it's an old config file (==1)
63 static int new_config_file;
64
65
66 void default_config()
67 {
68 config_path = 0;
69 snapshot_path = 0;
70 new_config_file = 0;
71 }
72
73 void cleanup_config()
74 {
75 if (config_path) g_free(config_path);
76 if (snapshot_path) g_free(snapshot_path);
77 }
78
79
80 void get_action (char *event, int *action)
81 {
82 if (strcmp (event, "none") == 0)
83 *action = NONE;
84 else if (strcmp (event, "close") == 0)
85 *action = CLOSE;
86 else if (strcmp (event, "toggle") == 0)
87 *action = TOGGLE;
88 else if (strcmp (event, "iconify") == 0)
89 *action = ICONIFY;
90 else if (strcmp (event, "shade") == 0)
91 *action = SHADE;
92 else if (strcmp (event, "toggle_iconify") == 0)
93 *action = TOGGLE_ICONIFY;
94 else if (strcmp (event, "maximize_restore") == 0)
95 *action = MAXIMIZE_RESTORE;
96 else if (strcmp (event, "desktop_left") == 0)
97 *action = DESKTOP_LEFT;
98 else if (strcmp (event, "desktop_right") == 0)
99 *action = DESKTOP_RIGHT;
100 else if (strcmp (event, "next_task") == 0)
101 *action = NEXT_TASK;
102 else if (strcmp (event, "prev_task") == 0)
103 *action = PREV_TASK;
104 }
105
106
107 int get_task_status(char* status)
108 {
109 if (strcmp(status, "active") == 0)
110 return TASK_ACTIVE;
111 if (strcmp(status, "iconified") == 0)
112 return TASK_ICONIFIED;
113 if (strcmp(status, "urgent") == 0)
114 return TASK_URGENT;
115 return TASK_NORMAL;
116 }
117
118
119 int config_get_monitor(char* monitor)
120 {
121 if (strcmp(monitor, "all") != 0) {
122 char* endptr;
123 int ret_int = strtol(monitor, &endptr, 10);
124 if (*endptr == 0)
125 return ret_int-1;
126 else {
127 // monitor specified by name, not by index
128 int i, j;
129 for (i=0; i<server.nb_monitor; ++i) {
130 if (server.monitor[i].names == 0)
131 // xrandr can't identify monitors
132 continue;
133 j = 0;
134 while (server.monitor[i].names[j] != 0) {
135 if (strcmp(monitor, server.monitor[i].names[j++]) == 0)
136 return i;
137 }
138 }
139 }
140 }
141 // monitor == "all" or monitor not found or xrandr can't identify monitors
142 return -1;
143 }
144
145 void add_entry (char *key, char *value)
146 {
147 char *value1=0, *value2=0, *value3=0;
148
149 /* Background and border */
150 if (strcmp (key, "rounded") == 0) {
151 // 'rounded' is the first parameter => alloc a new background
152 Background bg;
153 bg.border.rounded = atoi(value);
154 g_array_append_val(backgrounds, bg);
155 }
156 else if (strcmp (key, "border_width") == 0) {
157 g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
158 }
159 else if (strcmp (key, "background_color") == 0) {
160 Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
161 extract_values(value, &value1, &value2, &value3);
162 get_color (value1, bg->back.color);
163 if (value2) bg->back.alpha = (atoi (value2) / 100.0);
164 else bg->back.alpha = 0.5;
165 }
166 else if (strcmp (key, "border_color") == 0) {
167 Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
168 extract_values(value, &value1, &value2, &value3);
169 get_color (value1, bg->border.color);
170 if (value2) bg->border.alpha = (atoi (value2) / 100.0);
171 else bg->border.alpha = 0.5;
172 }
173
174 /* Panel */
175 else if (strcmp (key, "panel_monitor") == 0) {
176 panel_config.monitor = config_get_monitor(value);
177 }
178 else if (strcmp (key, "panel_size") == 0) {
179 extract_values(value, &value1, &value2, &value3);
180
181 char *b;
182 if ((b = strchr (value1, '%'))) {
183 b[0] = '\0';
184 panel_config.pourcentx = 1;
185 }
186 panel_config.area.width = atoi(value1);
187 if (panel_config.area.width == 0) {
188 // full width mode
189 panel_config.area.width = 100;
190 panel_config.pourcentx = 1;
191 }
192 if (value2) {
193 if ((b = strchr (value2, '%'))) {
194 b[0] = '\0';
195 panel_config.pourcenty = 1;
196 }
197 panel_config.area.height = atoi(value2);
198 }
199 }
200 else if (strcmp (key, "panel_items") == 0) {
201 new_config_file = 1;
202 panel_items_order = strdup(value);
203 int j;
204 for (j=0 ; j < strlen(panel_items_order) ; j++) {
205 if (panel_items_order[j] == 'L')
206 launcher_enabled = 1;
207 if (panel_items_order[j] == 'T')
208 taskbar_enabled = 1;
209 if (panel_items_order[j] == 'B') {
210 #ifdef ENABLE_BATTERY
211 battery_enabled = 1;
212 #else
213 fprintf(stderr, "tint2 is build without battery support\n");
214 #endif
215 }
216 if (panel_items_order[j] == 'S') {
217 // systray disabled in snapshot mode
218 if (snapshot_path == 0)
219 systray_enabled = 1;
220 }
221 if (panel_items_order[j] == 'C')
222 clock_enabled = 1;
223 }
224 }
225 else if (strcmp (key, "panel_margin") == 0) {
226 extract_values(value, &value1, &value2, &value3);
227 panel_config.marginx = atoi (value1);
228 if (value2) panel_config.marginy = atoi (value2);
229 }
230 else if (strcmp (key, "panel_padding") == 0) {
231 extract_values(value, &value1, &value2, &value3);
232 panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
233 if (value2) panel_config.area.paddingy = atoi (value2);
234 if (value3) panel_config.area.paddingx = atoi (value3);
235 }
236 else if (strcmp (key, "panel_position") == 0) {
237 extract_values(value, &value1, &value2, &value3);
238 if (strcmp (value1, "top") == 0) panel_position = TOP;
239 else {
240 if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
241 else panel_position = CENTER;
242 }
243
244 if (!value2) panel_position |= CENTER;
245 else {
246 if (strcmp (value2, "left") == 0) panel_position |= LEFT;
247 else {
248 if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
249 else panel_position |= CENTER;
250 }
251 }
252 if (!value3) panel_horizontal = 1;
253 else {
254 if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
255 else panel_horizontal = 1;
256 }
257 }
258 else if (strcmp (key, "font_shadow") == 0)
259 panel_config.g_task.font_shadow = atoi (value);
260 else if (strcmp (key, "panel_background_id") == 0) {
261 int id = atoi (value);
262 id = (id < backgrounds->len && id >= 0) ? id : 0;
263 panel_config.area.bg = &g_array_index(backgrounds, Background, id);
264 }
265 else if (strcmp (key, "wm_menu") == 0)
266 wm_menu = atoi (value);
267 else if (strcmp (key, "panel_dock") == 0)
268 panel_dock = atoi (value);
269 else if (strcmp (key, "urgent_nb_of_blink") == 0)
270 max_tick_urgent = atoi (value);
271 else if (strcmp (key, "panel_layer") == 0) {
272 if (strcmp(value, "bottom") == 0)
273 panel_layer = BOTTOM_LAYER;
274 else if (strcmp(value, "top") == 0)
275 panel_layer = TOP_LAYER;
276 else
277 panel_layer = NORMAL_LAYER;
278 }
279
280 /* Battery */
281 else if (strcmp (key, "battery_low_status") == 0) {
282 #ifdef ENABLE_BATTERY
283 battery_low_status = atoi(value);
284 if(battery_low_status < 0 || battery_low_status > 100)
285 battery_low_status = 0;
286 #endif
287 }
288 else if (strcmp (key, "battery_low_cmd") == 0) {
289 #ifdef ENABLE_BATTERY
290 if (strlen(value) > 0)
291 battery_low_cmd = strdup (value);
292 #endif
293 }
294 else if (strcmp (key, "bat1_font") == 0) {
295 #ifdef ENABLE_BATTERY
296 bat1_font_desc = pango_font_description_from_string (value);
297 #endif
298 }
299 else if (strcmp (key, "bat2_font") == 0) {
300 #ifdef ENABLE_BATTERY
301 bat2_font_desc = pango_font_description_from_string (value);
302 #endif
303 }
304 else if (strcmp (key, "battery_font_color") == 0) {
305 #ifdef ENABLE_BATTERY
306 extract_values(value, &value1, &value2, &value3);
307 get_color (value1, panel_config.battery.font.color);
308 if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
309 else panel_config.battery.font.alpha = 0.5;
310 #endif
311 }
312 else if (strcmp (key, "battery_padding") == 0) {
313 #ifdef ENABLE_BATTERY
314 extract_values(value, &value1, &value2, &value3);
315 panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
316 if (value2) panel_config.battery.area.paddingy = atoi (value2);
317 if (value3) panel_config.battery.area.paddingx = atoi (value3);
318 #endif
319 }
320 else if (strcmp (key, "battery_background_id") == 0) {
321 #ifdef ENABLE_BATTERY
322 int id = atoi (value);
323 id = (id < backgrounds->len && id >= 0) ? id : 0;
324 panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id);
325 #endif
326 }
327 else if (strcmp (key, "battery_hide") == 0) {
328 #ifdef ENABLE_BATTERY
329 percentage_hide = atoi (value);
330 if (percentage_hide == 0)
331 percentage_hide = 101;
332 #endif
333 }
334
335 /* Clock */
336 else if (strcmp (key, "time1_format") == 0) {
337 if (new_config_file == 0) {
338 clock_enabled = 1;
339 if (panel_items_order) {
340 char* tmp = g_strconcat(panel_items_order, "C", NULL);
341 g_free( panel_items_order );
342 panel_items_order = tmp;
343 }
344 else
345 panel_items_order = g_strdup("C");
346 }
347 if (strlen(value) > 0) {
348 time1_format = strdup (value);
349 clock_enabled = 1;
350 }
351 }
352 else if (strcmp (key, "time2_format") == 0) {
353 if (strlen(value) > 0)
354 time2_format = strdup (value);
355 }
356 else if (strcmp (key, "time1_font") == 0) {
357 time1_font_desc = pango_font_description_from_string (value);
358 }
359 else if (strcmp(key, "time1_timezone") == 0) {
360 if (strlen(value) > 0)
361 time1_timezone = strdup(value);
362 }
363 else if (strcmp(key, "time2_timezone") == 0) {
364 if (strlen(value) > 0)
365 time2_timezone = strdup(value);
366 }
367 else if (strcmp (key, "time2_font") == 0) {
368 time2_font_desc = pango_font_description_from_string (value);
369 }
370 else if (strcmp (key, "clock_font_color") == 0) {
371 extract_values(value, &value1, &value2, &value3);
372 get_color (value1, panel_config.clock.font.color);
373 if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
374 else panel_config.clock.font.alpha = 0.5;
375 }
376 else if (strcmp (key, "clock_padding") == 0) {
377 extract_values(value, &value1, &value2, &value3);
378 panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
379 if (value2) panel_config.clock.area.paddingy = atoi (value2);
380 if (value3) panel_config.clock.area.paddingx = atoi (value3);
381 }
382 else if (strcmp (key, "clock_background_id") == 0) {
383 int id = atoi (value);
384 id = (id < backgrounds->len && id >= 0) ? id : 0;
385 panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id);
386 }
387 else if (strcmp(key, "clock_tooltip") == 0) {
388 if (strlen(value) > 0)
389 time_tooltip_format = strdup (value);
390 }
391 else if (strcmp(key, "clock_tooltip_timezone") == 0) {
392 if (strlen(value) > 0)
393 time_tooltip_timezone = strdup(value);
394 }
395 else if (strcmp(key, "clock_lclick_command") == 0) {
396 if (strlen(value) > 0)
397 clock_lclick_command = strdup(value);
398 }
399 else if (strcmp(key, "clock_rclick_command") == 0) {
400 if (strlen(value) > 0)
401 clock_rclick_command = strdup(value);
402 }
403
404 /* Taskbar */
405 else if (strcmp (key, "taskbar_mode") == 0) {
406 if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
407 else panel_mode = SINGLE_DESKTOP;
408 }
409 else if (strcmp (key, "taskbar_padding") == 0) {
410 extract_values(value, &value1, &value2, &value3);
411 panel_config.g_taskbar.area.paddingxlr = panel_config.g_taskbar.area.paddingx = atoi (value1);
412 if (value2) panel_config.g_taskbar.area.paddingy = atoi (value2);
413 if (value3) panel_config.g_taskbar.area.paddingx = atoi (value3);
414 }
415 else if (strcmp (key, "taskbar_background_id") == 0) {
416 int id = atoi (value);
417 id = (id < backgrounds->len && id >= 0) ? id : 0;
418 panel_config.g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
419 if (panel_config.g_taskbar.background[TASKBAR_ACTIVE] == 0)
420 panel_config.g_taskbar.background[TASKBAR_ACTIVE] = panel_config.g_taskbar.background[TASKBAR_NORMAL];
421 }
422 else if (strcmp (key, "taskbar_active_background_id") == 0) {
423 int id = atoi (value);
424 id = (id < backgrounds->len && id >= 0) ? id : 0;
425 panel_config.g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
426 }
427 else if (strcmp (key, "taskbar_name") == 0) {
428 taskbarname_enabled = atoi (value);
429 }
430 else if (strcmp (key, "taskbar_name_padding") == 0) {
431 extract_values(value, &value1, &value2, &value3);
432 panel_config.g_taskbar.area_name.paddingxlr = panel_config.g_taskbar.area_name.paddingx = atoi (value1);
433 }
434 else if (strcmp (key, "taskbar_name_background_id") == 0) {
435 int id = atoi (value);
436 id = (id < backgrounds->len && id >= 0) ? id : 0;
437 panel_config.g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
438 if (panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] == 0)
439 panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = panel_config.g_taskbar.background_name[TASKBAR_NORMAL];
440 }
441 else if (strcmp (key, "taskbar_name_active_background_id") == 0) {
442 int id = atoi (value);
443 id = (id < backgrounds->len && id >= 0) ? id : 0;
444 panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
445 }
446 else if (strcmp (key, "taskbar_name_font") == 0) {
447 taskbarname_font_desc = pango_font_description_from_string (value);
448 }
449 else if (strcmp (key, "taskbar_name_font_color") == 0) {
450 extract_values(value, &value1, &value2, &value3);
451 get_color (value1, taskbarname_font.color);
452 if (value2) taskbarname_font.alpha = (atoi (value2) / 100.0);
453 else taskbarname_font.alpha = 0.5;
454 }
455 else if (strcmp (key, "taskbar_name_active_font_color") == 0) {
456 extract_values(value, &value1, &value2, &value3);
457 get_color (value1, taskbarname_active_font.color);
458 if (value2) taskbarname_active_font.alpha = (atoi (value2) / 100.0);
459 else taskbarname_active_font.alpha = 0.5;
460 }
461
462 /* Task */
463 else if (strcmp (key, "task_text") == 0)
464 panel_config.g_task.text = atoi (value);
465 else if (strcmp (key, "task_icon") == 0)
466 panel_config.g_task.icon = atoi (value);
467 else if (strcmp (key, "task_centered") == 0)
468 panel_config.g_task.centered = atoi (value);
469 else if (strcmp (key, "task_width") == 0) {
470 // old parameter : just for backward compatibility
471 panel_config.g_task.maximum_width = atoi (value);
472 panel_config.g_task.maximum_height = 30;
473 }
474 else if (strcmp (key, "task_maximum_size") == 0) {
475 extract_values(value, &value1, &value2, &value3);
476 panel_config.g_task.maximum_width = atoi (value1);
477 panel_config.g_task.maximum_height = 30;
478 if (value2)
479 panel_config.g_task.maximum_height = atoi (value2);
480 }
481 else if (strcmp (key, "task_padding") == 0) {
482 extract_values(value, &value1, &value2, &value3);
483 panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
484 if (value2) panel_config.g_task.area.paddingy = atoi (value2);
485 if (value3) panel_config.g_task.area.paddingx = atoi (value3);
486 }
487 else if (strcmp (key, "task_align") == 0) {
488 extract_values(value, &value1, &value2, &value3);
489 printf("task_align: %s\n", value1);
490 if (strcmp (value1, "left") == 0) panel_config.g_task.align = ALIGN_LEFT;
491 else if (strcmp (value1, "center") == 0) panel_config.g_task.align = ALIGN_CENTER;
492 else if (strcmp (value1, "right") == 0) panel_config.g_task.align = ALIGN_RIGHT;
493 else fprintf(stderr, "Unknown value for task_align: %s\n", value1);
494 }
495 else if (strcmp (key, "task_font") == 0) {
496 panel_config.g_task.font_desc = pango_font_description_from_string (value);
497 }
498 else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
499 gchar** split = g_regex_split_simple("_", key, 0, 0);
500 int status = get_task_status(split[1]);
501 g_strfreev(split);
502 extract_values(value, &value1, &value2, &value3);
503 float alpha = 1;
504 if (value2) alpha = (atoi (value2) / 100.0);
505 get_color (value1, panel_config.g_task.font[status].color);
506 panel_config.g_task.font[status].alpha = alpha;
507 panel_config.g_task.config_font_mask |= (1<<status);
508 }
509 else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
510 gchar** split = g_regex_split_simple("_", key, 0, 0);
511 int status = get_task_status(split[1]);
512 g_strfreev(split);
513 extract_values(value, &value1, &value2, &value3);
514 panel_config.g_task.alpha[status] = atoi(value1);
515 panel_config.g_task.saturation[status] = atoi(value2);
516 panel_config.g_task.brightness[status] = atoi(value3);
517 panel_config.g_task.config_asb_mask |= (1<<status);
518 }
519 else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
520 gchar** split = g_regex_split_simple("_", key, 0, 0);
521 int status = get_task_status(split[1]);
522 g_strfreev(split);
523 int id = atoi (value);
524 id = (id < backgrounds->len && id >= 0) ? id : 0;
525 panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
526 panel_config.g_task.config_background_mask |= (1<<status);
527 if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
528 }
529 // "tooltip" is deprecated but here for backwards compatibility
530 else if (strcmp (key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0)
531 panel_config.g_task.tooltip_enabled = atoi(value);
532
533 /* Systray */
534 else if (strcmp (key, "systray_padding") == 0) {
535 if (new_config_file == 0 && systray_enabled == 0) {
536 systray_enabled = 1;
537 if (panel_items_order) {
538 char* tmp = g_strconcat(panel_items_order, "S", NULL);
539 g_free( panel_items_order );
540 panel_items_order = tmp;
541 }
542 else
543 panel_items_order = g_strdup("S");
544 }
545 extract_values(value, &value1, &value2, &value3);
546 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
547 if (value2) systray.area.paddingy = atoi (value2);
548 if (value3) systray.area.paddingx = atoi (value3);
549 }
550 else if (strcmp (key, "systray_background_id") == 0) {
551 int id = atoi (value);
552 id = (id < backgrounds->len && id >= 0) ? id : 0;
553 systray.area.bg = &g_array_index(backgrounds, Background, id);
554 }
555 else if (strcmp(key, "systray_sort") == 0) {
556 if (strcmp(value, "descending") == 0)
557 systray.sort = -1;
558 else if (strcmp(value, "ascending") == 0)
559 systray.sort = 1;
560 else if (strcmp(value, "left2right") == 0)
561 systray.sort = 2;
562 else if (strcmp(value, "right2left") == 0)
563 systray.sort = 3;
564 }
565 else if (strcmp(key, "systray_icon_size") == 0) {
566 systray_max_icon_size = atoi(value);
567 }
568 else if (strcmp(key, "systray_icon_asb") == 0) {
569 extract_values(value, &value1, &value2, &value3);
570 systray.alpha = atoi(value1);
571 systray.saturation = atoi(value2);
572 systray.brightness = atoi(value3);
573 }
574
575 /* Launcher */
576 else if (strcmp (key, "launcher_padding") == 0) {
577 extract_values(value, &value1, &value2, &value3);
578 panel_config.launcher.area.paddingxlr = panel_config.launcher.area.paddingx = atoi (value1);
579 if (value2) panel_config.launcher.area.paddingy = atoi (value2);
580 if (value3) panel_config.launcher.area.paddingx = atoi (value3);
581 }
582 else if (strcmp (key, "launcher_background_id") == 0) {
583 int id = atoi (value);
584 id = (id < backgrounds->len && id >= 0) ? id : 0;
585 panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id);
586 }
587 else if (strcmp(key, "launcher_icon_size") == 0) {
588 launcher_max_icon_size = atoi(value);
589 }
590 else if (strcmp(key, "launcher_item_app") == 0) {
591 char *app = strdup(value);
592 panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app);
593 }
594 else if (strcmp(key, "launcher_icon_theme") == 0) {
595 // if XSETTINGS manager running, tint2 use it.
596 if (!icon_theme_name)
597 icon_theme_name = strdup(value);
598 }
599 else if (strcmp(key, "launcher_icon_asb") == 0) {
600 extract_values(value, &value1, &value2, &value3);
601 launcher_alpha = atoi(value1);
602 launcher_saturation = atoi(value2);
603 launcher_brightness = atoi(value3);
604 }
605 else if (strcmp(key, "launcher_tooltip") == 0) {
606 launcher_tooltip_enabled = atoi(value);
607 }
608
609 /* Tooltip */
610 else if (strcmp (key, "tooltip_show_timeout") == 0) {
611 int timeout_msec = 1000*atof(value);
612 g_tooltip.show_timeout_msec = timeout_msec;
613 }
614 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
615 int timeout_msec = 1000*atof(value);
616 g_tooltip.hide_timeout_msec = timeout_msec;
617 }
618 else if (strcmp (key, "tooltip_padding") == 0) {
619 extract_values(value, &value1, &value2, &value3);
620 if (value1) g_tooltip.paddingx = atoi(value1);
621 if (value2) g_tooltip.paddingy = atoi(value2);
622 }
623 else if (strcmp (key, "tooltip_background_id") == 0) {
624 int id = atoi (value);
625 id = (id < backgrounds->len && id >= 0) ? id : 0;
626 g_tooltip.bg = &g_array_index(backgrounds, Background, id);
627 }
628 else if (strcmp (key, "tooltip_font_color") == 0) {
629 extract_values(value, &value1, &value2, &value3);
630 get_color(value1, g_tooltip.font_color.color);
631 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
632 else g_tooltip.font_color.alpha = 0.1;
633 }
634 else if (strcmp (key, "tooltip_font") == 0) {
635 g_tooltip.font_desc = pango_font_description_from_string(value);
636 }
637
638 /* Mouse actions */
639 else if (strcmp (key, "mouse_middle") == 0)
640 get_action (value, &mouse_middle);
641 else if (strcmp (key, "mouse_right") == 0)
642 get_action (value, &mouse_right);
643 else if (strcmp (key, "mouse_scroll_up") == 0)
644 get_action (value, &mouse_scroll_up);
645 else if (strcmp (key, "mouse_scroll_down") == 0)
646 get_action (value, &mouse_scroll_down);
647
648 /* autohide options */
649 else if (strcmp(key, "autohide") == 0)
650 panel_autohide = atoi(value);
651 else if (strcmp(key, "autohide_show_timeout") == 0)
652 panel_autohide_show_timeout = 1000*atof(value);
653 else if (strcmp(key, "autohide_hide_timeout") == 0)
654 panel_autohide_hide_timeout = 1000*atof(value);
655 else if (strcmp(key, "strut_policy") == 0) {
656 if (strcmp(value, "follow_size") == 0)
657 panel_strut_policy = STRUT_FOLLOW_SIZE;
658 else if (strcmp(value, "none") == 0)
659 panel_strut_policy = STRUT_NONE;
660 else
661 panel_strut_policy = STRUT_MINIMUM;
662 }
663 else if (strcmp(key, "autohide_height") == 0) {
664 panel_autohide_height = atoi(value);
665 if (panel_autohide_height == 0) {
666 // autohide need height > 0
667 panel_autohide_height = 1;
668 }
669 }
670
671 // old config option
672 else if (strcmp(key, "systray") == 0) {
673 if (new_config_file == 0) {
674 systray_enabled = atoi(value);
675 if (systray_enabled) {
676 if (panel_items_order) {
677 char* tmp = g_strconcat(panel_items_order, "S", NULL);
678 g_free( panel_items_order );
679 panel_items_order = tmp;
680 }
681 else
682 panel_items_order = g_strdup("S");
683 }
684 }
685 }
686 else if (strcmp(key, "battery") == 0) {
687 if (new_config_file == 0) {
688 battery_enabled = atoi(value);
689 if (battery_enabled) {
690 if (panel_items_order) {
691 char* tmp = g_strconcat(panel_items_order, "B", NULL);
692 g_free( panel_items_order );
693 panel_items_order = tmp;
694 }
695 else
696 panel_items_order = g_strdup("B");
697 }
698 }
699 }
700 else
701 fprintf(stderr, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key);
702
703 if (value1) free (value1);
704 if (value2) free (value2);
705 if (value3) free (value3);
706 }
707
708
709 int config_read ()
710 {
711 const gchar * const * system_dirs;
712 char *path1;
713 gint i;
714
715 // follow XDG specification
716 // check tint2rc in user directory
717 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
718 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
719 i = config_read_file (path1);
720 config_path = strdup(path1);
721 g_free(path1);
722 return i;
723 }
724 g_free(path1);
725
726 // copy tint2rc from system directory to user directory
727 char *path2 = 0;
728 system_dirs = g_get_system_config_dirs();
729 for (i = 0; system_dirs[i]; i++) {
730 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
731
732 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
733 g_free (path2);
734 path2 = 0;
735 }
736
737 if (path2) {
738 // copy file in user directory (path1)
739 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
740 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
741 g_free(dir);
742
743 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
744 copy_file(path2, path1);
745 g_free(path2);
746
747 i = config_read_file (path1);
748 config_path = strdup(path1);
749 g_free(path1);
750 return i;
751 }
752 return 0;
753 }
754
755
756 int config_read_file (const char *path)
757 {
758 FILE *fp;
759 char line[512];
760 char *key, *value;
761
762 if ((fp = fopen(path, "r")) == NULL) return 0;
763
764 while (fgets(line, sizeof(line), fp) != NULL) {
765 if (parse_line(line, &key, &value)) {
766 add_entry (key, value);
767 free (key);
768 free (value);
769 }
770 }
771 fclose (fp);
772
773 // append Taskbar item
774 if (new_config_file == 0) {
775 taskbar_enabled = 1;
776 if (panel_items_order) {
777 char* tmp = g_strconcat( "T", panel_items_order, NULL );
778 g_free(panel_items_order);
779 panel_items_order = tmp;
780 }
781 else
782 panel_items_order = g_strdup("T");
783 }
784
785 return 1;
786 }
787
788
789
This page took 0.06836 seconds and 4 git commands to generate.