]> Dogcows Code - chaz/tint2/blob - src/config.c
80d02c0275b564bbaedc5347534ee8c150e01528
[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_font") == 0) {
488 panel_config.g_task.font_desc = pango_font_description_from_string (value);
489 }
490 else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
491 gchar** split = g_regex_split_simple("_", key, 0, 0);
492 int status = get_task_status(split[1]);
493 g_strfreev(split);
494 extract_values(value, &value1, &value2, &value3);
495 float alpha = 1;
496 if (value2) alpha = (atoi (value2) / 100.0);
497 get_color (value1, panel_config.g_task.font[status].color);
498 panel_config.g_task.font[status].alpha = alpha;
499 panel_config.g_task.config_font_mask |= (1<<status);
500 }
501 else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
502 gchar** split = g_regex_split_simple("_", key, 0, 0);
503 int status = get_task_status(split[1]);
504 g_strfreev(split);
505 extract_values(value, &value1, &value2, &value3);
506 panel_config.g_task.alpha[status] = atoi(value1);
507 panel_config.g_task.saturation[status] = atoi(value2);
508 panel_config.g_task.brightness[status] = atoi(value3);
509 panel_config.g_task.config_asb_mask |= (1<<status);
510 }
511 else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
512 gchar** split = g_regex_split_simple("_", key, 0, 0);
513 int status = get_task_status(split[1]);
514 g_strfreev(split);
515 int id = atoi (value);
516 id = (id < backgrounds->len && id >= 0) ? id : 0;
517 panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
518 panel_config.g_task.config_background_mask |= (1<<status);
519 if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
520 }
521 // "tooltip" is deprecated but here for backwards compatibility
522 else if (strcmp (key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0)
523 panel_config.g_task.tooltip_enabled = atoi(value);
524
525 /* Systray */
526 else if (strcmp (key, "systray_padding") == 0) {
527 if (new_config_file == 0 && systray_enabled == 0) {
528 systray_enabled = 1;
529 if (panel_items_order) {
530 char* tmp = g_strconcat(panel_items_order, "S", NULL);
531 g_free( panel_items_order );
532 panel_items_order = tmp;
533 }
534 else
535 panel_items_order = g_strdup("S");
536 }
537 extract_values(value, &value1, &value2, &value3);
538 systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
539 if (value2) systray.area.paddingy = atoi (value2);
540 if (value3) systray.area.paddingx = atoi (value3);
541 }
542 else if (strcmp (key, "systray_background_id") == 0) {
543 int id = atoi (value);
544 id = (id < backgrounds->len && id >= 0) ? id : 0;
545 systray.area.bg = &g_array_index(backgrounds, Background, id);
546 }
547 else if (strcmp(key, "systray_sort") == 0) {
548 if (strcmp(value, "descending") == 0)
549 systray.sort = -1;
550 else if (strcmp(value, "ascending") == 0)
551 systray.sort = 1;
552 else if (strcmp(value, "left2right") == 0)
553 systray.sort = 2;
554 else if (strcmp(value, "right2left") == 0)
555 systray.sort = 3;
556 }
557 else if (strcmp(key, "systray_icon_size") == 0) {
558 systray_max_icon_size = atoi(value);
559 }
560 else if (strcmp(key, "systray_icon_asb") == 0) {
561 extract_values(value, &value1, &value2, &value3);
562 systray.alpha = atoi(value1);
563 systray.saturation = atoi(value2);
564 systray.brightness = atoi(value3);
565 }
566
567 /* Launcher */
568 else if (strcmp (key, "launcher_padding") == 0) {
569 extract_values(value, &value1, &value2, &value3);
570 panel_config.launcher.area.paddingxlr = panel_config.launcher.area.paddingx = atoi (value1);
571 if (value2) panel_config.launcher.area.paddingy = atoi (value2);
572 if (value3) panel_config.launcher.area.paddingx = atoi (value3);
573 }
574 else if (strcmp (key, "launcher_background_id") == 0) {
575 int id = atoi (value);
576 id = (id < backgrounds->len && id >= 0) ? id : 0;
577 panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id);
578 }
579 else if (strcmp(key, "launcher_icon_size") == 0) {
580 launcher_max_icon_size = atoi(value);
581 }
582 else if (strcmp(key, "launcher_item_app") == 0) {
583 char *app = strdup(value);
584 panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app);
585 }
586 else if (strcmp(key, "launcher_icon_theme") == 0) {
587 // if XSETTINGS manager running, tint2 use it.
588 if (!icon_theme_name)
589 icon_theme_name = strdup(value);
590 }
591
592 /* Tooltip */
593 else if (strcmp (key, "tooltip_show_timeout") == 0) {
594 int timeout_msec = 1000*atof(value);
595 g_tooltip.show_timeout_msec = timeout_msec;
596 }
597 else if (strcmp (key, "tooltip_hide_timeout") == 0) {
598 int timeout_msec = 1000*atof(value);
599 g_tooltip.hide_timeout_msec = timeout_msec;
600 }
601 else if (strcmp (key, "tooltip_padding") == 0) {
602 extract_values(value, &value1, &value2, &value3);
603 if (value1) g_tooltip.paddingx = atoi(value1);
604 if (value2) g_tooltip.paddingy = atoi(value2);
605 }
606 else if (strcmp (key, "tooltip_background_id") == 0) {
607 int id = atoi (value);
608 id = (id < backgrounds->len && id >= 0) ? id : 0;
609 g_tooltip.bg = &g_array_index(backgrounds, Background, id);
610 }
611 else if (strcmp (key, "tooltip_font_color") == 0) {
612 extract_values(value, &value1, &value2, &value3);
613 get_color(value1, g_tooltip.font_color.color);
614 if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
615 else g_tooltip.font_color.alpha = 0.1;
616 }
617 else if (strcmp (key, "tooltip_font") == 0) {
618 g_tooltip.font_desc = pango_font_description_from_string(value);
619 }
620
621 /* Mouse actions */
622 else if (strcmp (key, "mouse_middle") == 0)
623 get_action (value, &mouse_middle);
624 else if (strcmp (key, "mouse_right") == 0)
625 get_action (value, &mouse_right);
626 else if (strcmp (key, "mouse_scroll_up") == 0)
627 get_action (value, &mouse_scroll_up);
628 else if (strcmp (key, "mouse_scroll_down") == 0)
629 get_action (value, &mouse_scroll_down);
630
631 /* autohide options */
632 else if (strcmp(key, "autohide") == 0)
633 panel_autohide = atoi(value);
634 else if (strcmp(key, "autohide_show_timeout") == 0)
635 panel_autohide_show_timeout = 1000*atof(value);
636 else if (strcmp(key, "autohide_hide_timeout") == 0)
637 panel_autohide_hide_timeout = 1000*atof(value);
638 else if (strcmp(key, "strut_policy") == 0) {
639 if (strcmp(value, "follow_size") == 0)
640 panel_strut_policy = STRUT_FOLLOW_SIZE;
641 else if (strcmp(value, "none") == 0)
642 panel_strut_policy = STRUT_NONE;
643 else
644 panel_strut_policy = STRUT_MINIMUM;
645 }
646 else if (strcmp(key, "autohide_height") == 0) {
647 panel_autohide_height = atoi(value);
648 if (panel_autohide_height == 0) {
649 // autohide need height > 0
650 panel_autohide_height = 1;
651 }
652 }
653
654 // old config option
655 else if (strcmp(key, "systray") == 0) {
656 if (new_config_file == 0) {
657 systray_enabled = atoi(value);
658 if (systray_enabled) {
659 if (panel_items_order) {
660 char* tmp = g_strconcat(panel_items_order, "S", NULL);
661 g_free( panel_items_order );
662 panel_items_order = tmp;
663 }
664 else
665 panel_items_order = g_strdup("S");
666 }
667 }
668 }
669 else if (strcmp(key, "battery") == 0) {
670 if (new_config_file == 0) {
671 battery_enabled = atoi(value);
672 if (battery_enabled) {
673 if (panel_items_order) {
674 char* tmp = g_strconcat(panel_items_order, "B", NULL);
675 g_free( panel_items_order );
676 panel_items_order = tmp;
677 }
678 else
679 panel_items_order = g_strdup("B");
680 }
681 }
682 }
683 else
684 fprintf(stderr, "tint2 : invalid option \"%s\",\n upgrade tint2 or correct your config file\n", key);
685
686 if (value1) free (value1);
687 if (value2) free (value2);
688 if (value3) free (value3);
689 }
690
691
692 int config_read ()
693 {
694 const gchar * const * system_dirs;
695 char *path1;
696 gint i;
697
698 // follow XDG specification
699 // check tint2rc in user directory
700 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
701 if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
702 i = config_read_file (path1);
703 config_path = strdup(path1);
704 g_free(path1);
705 return i;
706 }
707 g_free(path1);
708
709 // copy tint2rc from system directory to user directory
710 char *path2 = 0;
711 system_dirs = g_get_system_config_dirs();
712 for (i = 0; system_dirs[i]; i++) {
713 path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
714
715 if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
716 g_free (path2);
717 path2 = 0;
718 }
719
720 if (path2) {
721 // copy file in user directory (path1)
722 char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
723 if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
724 g_free(dir);
725
726 path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
727 copy_file(path2, path1);
728 g_free(path2);
729
730 i = config_read_file (path1);
731 config_path = strdup(path1);
732 g_free(path1);
733 return i;
734 }
735 return 0;
736 }
737
738
739 int config_read_file (const char *path)
740 {
741 FILE *fp;
742 char line[512];
743 char *key, *value;
744
745 if ((fp = fopen(path, "r")) == NULL) return 0;
746
747 while (fgets(line, sizeof(line), fp) != NULL) {
748 if (parse_line(line, &key, &value)) {
749 add_entry (key, value);
750 free (key);
751 free (value);
752 }
753 }
754 fclose (fp);
755
756 // append Taskbar item
757 if (new_config_file == 0) {
758 taskbar_enabled = 1;
759 if (panel_items_order) {
760 char* tmp = g_strconcat( "T", panel_items_order, NULL );
761 g_free(panel_items_order);
762 panel_items_order = tmp;
763 }
764 else
765 panel_items_order = g_strdup("T");
766 }
767
768 return 1;
769 }
770
771
772
This page took 0.064385 seconds and 3 git commands to generate.