]> Dogcows Code - chaz/openbox/blob - openbox/config.c
b7241f5905c4787dde988d734456a0afc773e6e6
[chaz/openbox] / openbox / config.c
1 #include "config.h"
2 #include "keyboard.h"
3 #include "mouse.h"
4 #include "prop.h"
5 #include "translate.h"
6 #include "parser/parse.h"
7
8 gboolean config_focus_new;
9 gboolean config_focus_follow;
10 gboolean config_focus_last;
11 gboolean config_focus_last_on_desktop;
12 gboolean config_focus_popup;
13 gboolean config_desktop_popup;
14
15 char *config_theme;
16
17 gchar *config_title_layout;
18
19 int config_desktops_num;
20 GSList *config_desktops_names;
21
22 gboolean config_redraw_resize;
23
24 ObStackingLayer config_dock_layer;
25 gboolean config_dock_floating;
26 ObDirection config_dock_pos;
27 gint config_dock_x;
28 gint config_dock_y;
29 ObOrientation config_dock_orient;
30 gboolean config_dock_hide;
31 guint config_dock_hide_timeout;
32
33 guint config_keyboard_reset_keycode;
34 guint config_keyboard_reset_state;
35
36 gint config_mouse_threshold;
37 gint config_mouse_dclicktime;
38
39 /*
40
41 <keybind key="C-x">
42 <action name="ChangeDesktop">
43 <desktop>3</desktop>
44 </action>
45 </keybind>
46
47 */
48
49 static void parse_key(xmlDocPtr doc, xmlNodePtr node, GList *keylist)
50 {
51 char *key;
52 ObAction *action;
53 xmlNodePtr n, nact;
54 GList *it;
55
56 if ((n = parse_find_node("chainQuitKey", node))) {
57 key = parse_string(doc, n);
58 translate_key(key, &config_keyboard_reset_state,
59 &config_keyboard_reset_keycode);
60 }
61
62 n = parse_find_node("keybind", node);
63 while (n) {
64 if (parse_attr_string("key", n, &key)) {
65 keylist = g_list_append(keylist, key);
66
67 parse_key(doc, n->xmlChildrenNode, keylist);
68
69 it = g_list_last(keylist);
70 g_free(it->data);
71 keylist = g_list_delete_link(keylist, it);
72 }
73 n = parse_find_node("keybind", n->next);
74 }
75 if (keylist) {
76 nact = parse_find_node("action", node);
77 while (nact) {
78 if ((action = action_parse(doc, nact))) {
79 /* validate that its okay for a key binding */
80 if (action->func == action_moveresize &&
81 action->data.moveresize.corner !=
82 prop_atoms.net_wm_moveresize_move_keyboard &&
83 action->data.moveresize.corner !=
84 prop_atoms.net_wm_moveresize_size_keyboard) {
85 action_free(action);
86 action = NULL;
87 }
88
89 if (action)
90 keyboard_bind(keylist, action);
91 }
92 nact = parse_find_node("action", nact->next);
93 }
94 }
95 }
96
97 static void parse_keyboard(xmlDocPtr doc, xmlNodePtr node, void *d)
98 {
99 parse_key(doc, node->xmlChildrenNode, NULL);
100 }
101
102 /*
103
104 <context name="Titlebar">
105 <mousebind button="Left" action="Press">
106 <action name="Raise"></action>
107 </mousebind>
108 </context>
109
110 */
111
112 static void parse_mouse(xmlDocPtr doc, xmlNodePtr node, void *d)
113 {
114 xmlNodePtr n, nbut, nact;
115 char *buttonstr;
116 char *contextstr;
117 ObMouseAction mact;
118 ObAction *action;
119
120 node = node->xmlChildrenNode;
121
122 if ((n = parse_find_node("dragThreshold", node)))
123 config_mouse_threshold = parse_int(doc, n);
124 if ((n = parse_find_node("doubleClickTime", node)))
125 config_mouse_dclicktime = parse_int(doc, n);
126
127 n = parse_find_node("context", node);
128 while (n) {
129 if (!parse_attr_string("name", n, &contextstr))
130 goto next_n;
131 nbut = parse_find_node("mousebind", n->xmlChildrenNode);
132 while (nbut) {
133 if (!parse_attr_string("button", nbut, &buttonstr))
134 goto next_nbut;
135 if (parse_attr_contains("press", nbut, "action"))
136 mact = MouseAction_Press;
137 else if (parse_attr_contains("release", nbut, "action"))
138 mact = MouseAction_Release;
139 else if (parse_attr_contains("click", nbut, "action"))
140 mact = MouseAction_Click;
141 else if (parse_attr_contains("doubleclick", nbut,"action"))
142 mact = MouseAction_DClick;
143 else if (parse_attr_contains("drag", nbut, "action"))
144 mact = MouseAction_Motion;
145 else
146 goto next_nbut;
147 nact = parse_find_node("action", nbut->xmlChildrenNode);
148 while (nact) {
149 if ((action = action_parse(doc, nact))) {
150 /* validate that its okay for a mouse binding*/
151 if (mact == MouseAction_Motion) {
152 if (action->func != action_moveresize ||
153 action->data.moveresize.corner ==
154 prop_atoms.net_wm_moveresize_move_keyboard ||
155 action->data.moveresize.corner ==
156 prop_atoms.net_wm_moveresize_size_keyboard) {
157 action_free(action);
158 action = NULL;
159 }
160 } else {
161 if (action->func == action_moveresize &&
162 action->data.moveresize.corner !=
163 prop_atoms.net_wm_moveresize_move_keyboard &&
164 action->data.moveresize.corner !=
165 prop_atoms.net_wm_moveresize_size_keyboard) {
166 action_free(action);
167 action = NULL;
168 }
169 }
170 if (action)
171 mouse_bind(buttonstr, contextstr, mact, action);
172 }
173 nact = parse_find_node("action", nact->next);
174 }
175 g_free(buttonstr);
176 next_nbut:
177 nbut = parse_find_node("mousebind", nbut->next);
178 }
179 g_free(contextstr);
180 next_n:
181 n = parse_find_node("context", n->next);
182 }
183 }
184
185 static void parse_focus(xmlDocPtr doc, xmlNodePtr node, void *d)
186 {
187 xmlNodePtr n;
188
189 node = node->xmlChildrenNode;
190
191 if ((n = parse_find_node("focusNew", node)))
192 config_focus_new = parse_bool(doc, n);
193 if ((n = parse_find_node("followMouse", node)))
194 config_focus_follow = parse_bool(doc, n);
195 if ((n = parse_find_node("focusLast", node)))
196 config_focus_last = parse_bool(doc, n);
197 if ((n = parse_find_node("focusLastOnDesktop", node)))
198 config_focus_last_on_desktop = parse_bool(doc, n);
199 if ((n = parse_find_node("cyclingDialog", node)))
200 config_focus_popup = parse_bool(doc, n);
201 }
202
203 static void parse_theme(xmlDocPtr doc, xmlNodePtr node, void *d)
204 {
205 xmlNodePtr n;
206
207 node = node->xmlChildrenNode;
208
209 if ((n = parse_find_node("theme", node))) {
210 g_free(config_theme);
211 config_theme = parse_string(doc, n);
212 }
213 if ((n = parse_find_node("titlelayout", node))) {
214 g_free(config_title_layout);
215 config_title_layout = parse_string(doc, n);
216 }
217 }
218
219 static void parse_desktops(xmlDocPtr doc, xmlNodePtr node, void *d)
220 {
221 xmlNodePtr n;
222
223 node = node->xmlChildrenNode;
224
225 if ((n = parse_find_node("number", node)))
226 config_desktops_num = parse_int(doc, n);
227 if ((n = parse_find_node("names", node))) {
228 GSList *it;
229 xmlNodePtr nname;
230
231 for (it = config_desktops_names; it; it = it->next)
232 g_free(it->data);
233 g_slist_free(config_desktops_names);
234 config_desktops_names = NULL;
235
236 nname = parse_find_node("name", n->xmlChildrenNode);
237 while (nname) {
238 config_desktops_names = g_slist_append(config_desktops_names,
239 parse_string(doc, nname));
240 nname = parse_find_node("name", nname->next);
241 }
242 }
243 if ((n = parse_find_node("cyclingDialog", node)))
244 config_desktop_popup = parse_bool(doc, n);
245 }
246
247 static void parse_resize(xmlDocPtr doc, xmlNodePtr node, void *d)
248 {
249 xmlNodePtr n;
250
251 node = node->xmlChildrenNode;
252
253 if ((n = parse_find_node("drawContents", node)))
254 config_redraw_resize = parse_bool(doc, n);
255 }
256
257 static void parse_dock(xmlDocPtr doc, xmlNodePtr node, void *d)
258 {
259 xmlNodePtr n;
260
261 node = node->xmlChildrenNode;
262
263 if ((n = parse_find_node("position", node))) {
264 if (parse_contains("TopLeft", doc, n))
265 config_dock_floating = FALSE,
266 config_dock_pos = OB_DIRECTION_NORTHWEST;
267 else if (parse_contains("Top", doc, n))
268 config_dock_floating = FALSE,
269 config_dock_pos = OB_DIRECTION_NORTH;
270 else if (parse_contains("TopRight", doc, n))
271 config_dock_floating = FALSE,
272 config_dock_pos = OB_DIRECTION_NORTHEAST;
273 else if (parse_contains("Right", doc, n))
274 config_dock_floating = FALSE,
275 config_dock_pos = OB_DIRECTION_EAST;
276 else if (parse_contains("BottomRight", doc, n))
277 config_dock_floating = FALSE,
278 config_dock_pos = OB_DIRECTION_SOUTHEAST;
279 else if (parse_contains("Bottom", doc, n))
280 config_dock_floating = FALSE,
281 config_dock_pos = OB_DIRECTION_SOUTH;
282 else if (parse_contains("BottomLeft", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_SOUTHWEST;
285 else if (parse_contains("Left", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_WEST;
288 else if (parse_contains("Floating", doc, n))
289 config_dock_floating = TRUE;
290 }
291 if (config_dock_floating) {
292 if ((n = parse_find_node("floatingX", node)))
293 config_dock_x = parse_int(doc, n);
294 if ((n = parse_find_node("floatingY", node)))
295 config_dock_y = parse_int(doc, n);
296 }
297 if ((n = parse_find_node("stacking", node))) {
298 if (parse_contains("top", doc, n))
299 config_dock_layer = OB_STACKING_LAYER_TOP;
300 else if (parse_contains("normal", doc, n))
301 config_dock_layer = OB_STACKING_LAYER_NORMAL;
302 else if (parse_contains("bottom", doc, n))
303 config_dock_layer = OB_STACKING_LAYER_BELOW;
304 }
305 if ((n = parse_find_node("direction", node))) {
306 if (parse_contains("horizontal", doc, n))
307 config_dock_orient = OB_ORIENTATION_HORZ;
308 else if (parse_contains("vertical", doc, n))
309 config_dock_orient = OB_ORIENTATION_VERT;
310 }
311 if ((n = parse_find_node("autoHide", node)))
312 config_dock_hide = parse_bool(doc, n);
313 if ((n = parse_find_node("hideTimeout", node)))
314 config_dock_hide_timeout = parse_int(doc, n);
315 }
316
317 void config_startup()
318 {
319 config_focus_new = TRUE;
320 config_focus_follow = FALSE;
321 config_focus_last = TRUE;
322 config_focus_last_on_desktop = TRUE;
323 config_focus_popup = TRUE;
324
325 parse_register("focus", parse_focus, NULL);
326
327 config_theme = NULL;
328
329 config_title_layout = g_strdup("NLIMC");
330
331 parse_register("theme", parse_theme, NULL);
332
333 config_desktops_num = 4;
334 config_desktops_names = NULL;
335 config_desktop_popup = TRUE;
336
337 parse_register("desktops", parse_desktops, NULL);
338
339 config_redraw_resize = TRUE;
340
341 parse_register("resize", parse_resize, NULL);
342
343 config_dock_layer = OB_STACKING_LAYER_TOP;
344 config_dock_pos = OB_DIRECTION_NORTHEAST;
345 config_dock_floating = FALSE;
346 config_dock_x = 0;
347 config_dock_y = 0;
348 config_dock_orient = OB_ORIENTATION_VERT;
349 config_dock_hide = FALSE;
350 config_dock_hide_timeout = 3000;
351
352 parse_register("dock", parse_dock, NULL);
353
354 translate_key("C-g", &config_keyboard_reset_state,
355 &config_keyboard_reset_keycode);
356
357 parse_register("keyboard", parse_keyboard, NULL);
358
359 config_mouse_threshold = 3;
360 config_mouse_dclicktime = 200;
361
362 parse_register("mouse", parse_mouse, NULL);
363 }
364
365 void config_shutdown()
366 {
367 GSList *it;
368
369 g_free(config_theme);
370
371 for (it = config_desktops_names; it; it = it->next)
372 g_free(it->data);
373 g_slist_free(config_desktops_names);
374 }
This page took 0.052901 seconds and 3 git commands to generate.