]> icculus.org git repositories - dana/openbox.git/blob - openbox/config.c
move config option loading for the kernel into config.c/h
[dana/openbox.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
9 char *config_engine_name;
10 char *config_engine_theme;
11 char *config_engine_layout;
12 char *config_engine_font;
13 gboolean config_engine_shadow;
14 int config_engine_shadow_offset;
15 int config_engine_shadow_tint;
16
17 int config_desktops_num;
18 GSList *config_desktops_names;
19
20 static void parse_focus(char *name, ParseToken *value)
21 {
22     if (!g_ascii_strcasecmp(name, "focusnew")) {
23         if (value->type != TOKEN_BOOL)
24             yyerror("invalid value");
25         else {
26             config_focus_new = value->data.bool;
27         }
28     } else if (!g_ascii_strcasecmp(name, "followmouse")) {
29         if (value->type != TOKEN_BOOL)
30             yyerror("invalid value");
31         else {
32             config_focus_follow = value->data.bool;
33         }
34     } else if (!g_ascii_strcasecmp(name, "focuslast")) {
35         if (value->type != TOKEN_BOOL)
36             yyerror("invalid value");
37         else {
38             config_focus_last = value->data.bool;
39         }
40     } else if (!g_ascii_strcasecmp(name, "focuslastondesktop")) {
41         if (value->type != TOKEN_BOOL)
42             yyerror("invalid value");
43         else {
44             config_focus_last_on_desktop = value->data.bool;
45         }
46     } else
47         yyerror("invalid option");
48     parse_free_token(value);
49 }
50
51 static void parse_engine(char *name, ParseToken *value)
52 {
53     if (!g_ascii_strcasecmp(name, "engine")) {
54         if (value->type != TOKEN_STRING)
55             yyerror("invalid value");
56         else {
57             g_free(config_engine_name);
58             config_engine_name = g_strdup(value->data.string);
59         }
60     } else if (!g_ascii_strcasecmp(name, "theme")) {
61         if (value->type != TOKEN_STRING)
62             yyerror("invalid value");
63         else {
64             g_free(config_engine_theme);
65             config_engine_theme = g_strdup(value->data.string);
66         }
67     } else if (!g_ascii_strcasecmp(name, "titlebarlayout")) {
68         if (value->type != TOKEN_STRING)
69             yyerror("invalid value");
70         else {
71             g_free(config_engine_layout);
72             config_engine_layout = g_strdup(value->data.string);
73         }
74     } else if (!g_ascii_strcasecmp(name, "font.title")) {
75         if (value->type != TOKEN_STRING)
76             yyerror("invalid value");
77         else {
78             g_free(config_engine_font);
79             config_engine_font = g_strdup(value->data.string);
80         }
81     } else if (!g_ascii_strcasecmp(name, "font.title.shadow")) {
82         if (value->type != TOKEN_BOOL)
83             yyerror("invalid value");
84         else {
85             config_engine_shadow = value->data.bool;
86         }
87     } else if (!g_ascii_strcasecmp(name, "font.title.shadow.offset")) {
88         if (value->type != TOKEN_INTEGER)
89             yyerror("invalid value");
90         else {
91             config_engine_shadow_offset = value->data.integer;
92         }
93     } else if (!g_ascii_strcasecmp(name, "font.title.shadow.tint")) {
94         if (value->type != TOKEN_INTEGER)
95             yyerror("invalid value");
96         else {
97             config_engine_shadow_tint = value->data.integer;
98             if (config_engine_shadow_tint < -100)
99                 config_engine_shadow_tint = -100;
100             else if (config_engine_shadow_tint > 100)
101                 config_engine_shadow_tint = 100;
102         }
103     } else
104         yyerror("invalid option");
105     parse_free_token(value);
106 }
107
108 static void parse_desktops(char *name, ParseToken *value)
109 {
110     GList *it;
111
112     if (!g_ascii_strcasecmp(name, "number")) {
113         if (value->type != TOKEN_INTEGER)
114             yyerror("invalid value");
115         else {
116             config_desktops_num = value->data.integer;
117         }
118     } else if (!g_ascii_strcasecmp(name, "names")) {
119         if (value->type == TOKEN_LIST) {
120             for (it = value->data.list; it; it = it->next)
121                 if (((ParseToken*)it->data)->type != TOKEN_STRING) break;
122             if (it == NULL) {
123                 /* build a string list */
124                 g_free(config_desktops_names);
125                 for (it = value->data.list; it; it = it->next)
126                     config_desktops_names =
127                         g_slist_append(config_desktops_names,
128                                        g_strdup
129                                        (((ParseToken*)it->data)->data.string));
130             } else {
131                 yyerror("invalid string in names list");
132             }
133         } else {
134             yyerror("syntax error (expected list of strings)");
135         }
136     } else
137         yyerror("invalid option");
138     parse_free_token(value);
139 }
140
141 void config_startup()
142 {
143     config_focus_new = TRUE;
144     config_focus_follow = FALSE;
145     config_focus_last = TRUE;
146     config_focus_last_on_desktop = TRUE;
147
148     parse_reg_section("focus", NULL, parse_focus);
149
150     config_engine_name = g_strdup(DEFAULT_ENGINE);
151     config_engine_theme = NULL;
152     config_engine_layout = g_strdup("NLIMC");
153     config_engine_font = g_strdup("Sans-7");
154     config_engine_shadow = FALSE;
155     config_engine_shadow_offset = 1;
156     config_engine_shadow_tint = 25;
157
158     parse_reg_section("engine", NULL, parse_engine);
159
160     config_desktops_num = 4;
161     config_desktops_names = NULL;
162
163     parse_reg_section("desktops", NULL, parse_desktops);
164 }
165
166 void config_shutdown()
167 {
168     GSList *it;
169
170     g_free(config_engine_name);
171     g_free(config_engine_layout);
172     g_free(config_engine_font);
173
174     for (it = config_desktops_names; it; it = it->next)
175         g_free(it->data);
176     g_slist_free(config_desktops_names);
177 }