all my changes while i was offline.
[dana/openbox-history.git] / openbox / config.c
1 #include "config.h"
2 #include "parse.h"
3
4 gboolean config_focus_new;
5 gboolean config_focus_follow;
6 gboolean config_focus_last;
7 gboolean config_focus_last_on_desktop;
8 gboolean config_focus_popup;
9
10 char *config_theme;
11
12 int config_desktops_num;
13 GSList *config_desktops_names;
14
15 static void parse_focus(char *name, ParseToken *value)
16 {
17     if (!g_ascii_strcasecmp(name, "focusnew")) {
18         if (value->type != TOKEN_BOOL)
19             yyerror("invalid value");
20         else {
21             config_focus_new = value->data.bool;
22         }
23     } else if (!g_ascii_strcasecmp(name, "followmouse")) {
24         if (value->type != TOKEN_BOOL)
25             yyerror("invalid value");
26         else {
27             config_focus_follow = value->data.bool;
28         }
29     } else if (!g_ascii_strcasecmp(name, "focuslast")) {
30         if (value->type != TOKEN_BOOL)
31             yyerror("invalid value");
32         else {
33             config_focus_last = value->data.bool;
34         }
35     } else if (!g_ascii_strcasecmp(name, "focuslastondesktop")) {
36         if (value->type != TOKEN_BOOL)
37             yyerror("invalid value");
38         else {
39             config_focus_last_on_desktop = value->data.bool;
40         }
41     } else if (!g_ascii_strcasecmp(name, "cyclingdialog")) {
42         if (value->type != TOKEN_BOOL)
43             yyerror("invalid value");
44         else {
45             config_focus_popup = value->data.bool;
46         }
47     } else
48         yyerror("invalid option");
49     parse_free_token(value);
50 }
51
52 static void parse_theme(char *name, ParseToken *value)
53 {
54     if (!g_ascii_strcasecmp(name, "theme")) {
55         if (value->type != TOKEN_STRING)
56             yyerror("invalid value");
57         else {
58             g_free(config_theme);
59             config_theme = g_strdup(value->data.string);
60         }
61     } else
62         yyerror("invalid option");
63     parse_free_token(value);
64 }
65
66 static void parse_desktops(char *name, ParseToken *value)
67 {
68     GList *it;
69
70     if (!g_ascii_strcasecmp(name, "number")) {
71         if (value->type != TOKEN_INTEGER)
72             yyerror("invalid value");
73         else {
74             config_desktops_num = value->data.integer;
75         }
76     } else if (!g_ascii_strcasecmp(name, "names")) {
77         if (value->type == TOKEN_LIST) {
78             for (it = value->data.list; it; it = it->next)
79                 if (((ParseToken*)it->data)->type != TOKEN_STRING) break;
80             if (it == NULL) {
81                 /* build a string list */
82                 g_free(config_desktops_names);
83                 for (it = value->data.list; it; it = it->next)
84                     config_desktops_names =
85                         g_slist_append(config_desktops_names,
86                                        g_strdup
87                                        (((ParseToken*)it->data)->data.string));
88             } else {
89                 yyerror("invalid string in names list");
90             }
91         } else {
92             yyerror("syntax error (expected list of strings)");
93         }
94     } else
95         yyerror("invalid option");
96     parse_free_token(value);
97 }
98
99 void config_startup()
100 {
101     config_focus_new = TRUE;
102     config_focus_follow = FALSE;
103     config_focus_last = TRUE;
104     config_focus_last_on_desktop = TRUE;
105     config_focus_popup = TRUE;
106
107     parse_reg_section("focus", NULL, parse_focus);
108
109     config_theme = NULL;
110
111     parse_reg_section("theme", NULL, parse_theme);
112
113     config_desktops_num = 4;
114     config_desktops_names = NULL;
115
116     parse_reg_section("desktops", NULL, parse_desktops);
117 }
118
119 void config_shutdown()
120 {
121     GSList *it;
122
123     g_free(config_theme);
124
125     for (it = config_desktops_names; it; it = it->next)
126         g_free(it->data);
127     g_slist_free(config_desktops_names);
128 }