]> Dogcows Code - chaz/openbox/blob - openbox/config.c
add the NONE cursor.
[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 #include "openbox.h"
8
9 gboolean config_focus_new;
10 gboolean config_focus_follow;
11 gboolean config_focus_last;
12 gboolean config_focus_last_on_desktop;
13 guint config_focus_delay;
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 GSList *config_menu_files;
40
41 gint config_resist_win;
42 gint config_resist_edge;
43
44 /*
45
46 <keybind key="C-x">
47 <action name="ChangeDesktop">
48 <desktop>3</desktop>
49 </action>
50 </keybind>
51
52 */
53
54 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
55 GList *keylist)
56 {
57 char *key;
58 ObAction *action;
59 xmlNodePtr n, nact;
60 GList *it;
61
62 if ((n = parse_find_node("chainQuitKey", node))) {
63 key = parse_string(doc, n);
64 translate_key(key, &config_keyboard_reset_state,
65 &config_keyboard_reset_keycode);
66 g_free(key);
67 }
68
69 n = parse_find_node("keybind", node);
70 while (n) {
71 if (parse_attr_string("key", n, &key)) {
72 keylist = g_list_append(keylist, key);
73
74 parse_key(i, doc, n->xmlChildrenNode, keylist);
75
76 it = g_list_last(keylist);
77 g_free(it->data);
78 keylist = g_list_delete_link(keylist, it);
79 }
80 n = parse_find_node("keybind", n->next);
81 }
82 if (keylist) {
83 nact = parse_find_node("action", node);
84 while (nact) {
85 if ((action = action_parse(i, doc, nact))) {
86 /* validate that its okay for a key binding */
87 if (action->func == action_moveresize &&
88 action->data.moveresize.corner !=
89 prop_atoms.net_wm_moveresize_move_keyboard &&
90 action->data.moveresize.corner !=
91 prop_atoms.net_wm_moveresize_size_keyboard) {
92 action_free(action);
93 action = NULL;
94 }
95
96 if (action)
97 keyboard_bind(keylist, action);
98 }
99 nact = parse_find_node("action", nact->next);
100 }
101 }
102 }
103
104 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
105 void *d)
106 {
107 parse_key(i, doc, node->xmlChildrenNode, NULL);
108 }
109
110 /*
111
112 <context name="Titlebar">
113 <mousebind button="Left" action="Press">
114 <action name="Raise"></action>
115 </mousebind>
116 </context>
117
118 */
119
120 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
121 void *d)
122 {
123 xmlNodePtr n, nbut, nact;
124 char *buttonstr;
125 char *contextstr;
126 ObMouseAction mact;
127 ObAction *action;
128
129 node = node->xmlChildrenNode;
130
131 if ((n = parse_find_node("dragThreshold", node)))
132 config_mouse_threshold = parse_int(doc, n);
133 if ((n = parse_find_node("doubleClickTime", node)))
134 config_mouse_dclicktime = parse_int(doc, n);
135
136 n = parse_find_node("context", node);
137 while (n) {
138 if (!parse_attr_string("name", n, &contextstr))
139 goto next_n;
140 nbut = parse_find_node("mousebind", n->xmlChildrenNode);
141 while (nbut) {
142 if (!parse_attr_string("button", nbut, &buttonstr))
143 goto next_nbut;
144 if (parse_attr_contains("press", nbut, "action"))
145 mact = OB_MOUSE_ACTION_PRESS;
146 else if (parse_attr_contains("release", nbut, "action"))
147 mact = OB_MOUSE_ACTION_RELEASE;
148 else if (parse_attr_contains("click", nbut, "action"))
149 mact = OB_MOUSE_ACTION_CLICK;
150 else if (parse_attr_contains("doubleclick", nbut,"action"))
151 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
152 else if (parse_attr_contains("drag", nbut, "action"))
153 mact = OB_MOUSE_ACTION_MOTION;
154 else
155 goto next_nbut;
156 nact = parse_find_node("action", nbut->xmlChildrenNode);
157 while (nact) {
158 if ((action = action_parse(i, doc, nact))) {
159 /* validate that its okay for a mouse binding*/
160 if (mact == OB_MOUSE_ACTION_MOTION) {
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 } else {
170 if (action->func == action_moveresize &&
171 action->data.moveresize.corner !=
172 prop_atoms.net_wm_moveresize_move_keyboard &&
173 action->data.moveresize.corner !=
174 prop_atoms.net_wm_moveresize_size_keyboard) {
175 action_free(action);
176 action = NULL;
177 }
178 }
179 if (action)
180 mouse_bind(buttonstr, contextstr, mact, action);
181 }
182 nact = parse_find_node("action", nact->next);
183 }
184 g_free(buttonstr);
185 next_nbut:
186 nbut = parse_find_node("mousebind", nbut->next);
187 }
188 g_free(contextstr);
189 next_n:
190 n = parse_find_node("context", n->next);
191 }
192 }
193
194 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
195 void *d)
196 {
197 xmlNodePtr n;
198
199 node = node->xmlChildrenNode;
200
201 if ((n = parse_find_node("focusNew", node)))
202 config_focus_new = parse_bool(doc, n);
203 if ((n = parse_find_node("followMouse", node)))
204 config_focus_follow = parse_bool(doc, n);
205 if ((n = parse_find_node("focusLast", node)))
206 config_focus_last = parse_bool(doc, n);
207 if ((n = parse_find_node("focusLastOnDesktop", node)))
208 config_focus_last_on_desktop = parse_bool(doc, n);
209 if ((n = parse_find_node("focusDelay", node)))
210 config_focus_delay = parse_int(doc, n);
211 }
212
213 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
214 void *d)
215 {
216 xmlNodePtr n;
217
218 node = node->xmlChildrenNode;
219
220 if ((n = parse_find_node("name", node))) {
221 gchar *c;
222
223 g_free(config_theme);
224 c = parse_string(doc, n);
225 config_theme = ob_expand_tilde(c);
226 g_free(c);
227 }
228 if ((n = parse_find_node("titleLayout", node))) {
229 g_free(config_title_layout);
230 config_title_layout = parse_string(doc, n);
231 }
232 }
233
234 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
235 void *d)
236 {
237 xmlNodePtr n;
238
239 node = node->xmlChildrenNode;
240
241 if ((n = parse_find_node("number", node)))
242 config_desktops_num = parse_int(doc, n);
243 if ((n = parse_find_node("names", node))) {
244 GSList *it;
245 xmlNodePtr nname;
246
247 for (it = config_desktops_names; it; it = it->next)
248 g_free(it->data);
249 g_slist_free(config_desktops_names);
250 config_desktops_names = NULL;
251
252 nname = parse_find_node("name", n->xmlChildrenNode);
253 while (nname) {
254 config_desktops_names = g_slist_append(config_desktops_names,
255 parse_string(doc, nname));
256 nname = parse_find_node("name", nname->next);
257 }
258 }
259 }
260
261 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
262 void *d)
263 {
264 xmlNodePtr n;
265
266 node = node->xmlChildrenNode;
267
268 if ((n = parse_find_node("drawContents", node)))
269 config_redraw_resize = parse_bool(doc, n);
270 }
271
272 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
273 {
274 xmlNodePtr n;
275
276 node = node->xmlChildrenNode;
277
278 if ((n = parse_find_node("position", node))) {
279 if (parse_contains("TopLeft", doc, n))
280 config_dock_floating = FALSE,
281 config_dock_pos = OB_DIRECTION_NORTHWEST;
282 else if (parse_contains("Top", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_NORTH;
285 else if (parse_contains("TopRight", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_NORTHEAST;
288 else if (parse_contains("Right", doc, n))
289 config_dock_floating = FALSE,
290 config_dock_pos = OB_DIRECTION_EAST;
291 else if (parse_contains("BottomRight", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_SOUTHEAST;
294 else if (parse_contains("Bottom", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_SOUTH;
297 else if (parse_contains("BottomLeft", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_SOUTHWEST;
300 else if (parse_contains("Left", doc, n))
301 config_dock_floating = FALSE,
302 config_dock_pos = OB_DIRECTION_WEST;
303 else if (parse_contains("Floating", doc, n))
304 config_dock_floating = TRUE;
305 }
306 if (config_dock_floating) {
307 if ((n = parse_find_node("floatingX", node)))
308 config_dock_x = parse_int(doc, n);
309 if ((n = parse_find_node("floatingY", node)))
310 config_dock_y = parse_int(doc, n);
311 }
312 if ((n = parse_find_node("stacking", node))) {
313 if (parse_contains("top", doc, n))
314 config_dock_layer = OB_STACKING_LAYER_TOP;
315 else if (parse_contains("normal", doc, n))
316 config_dock_layer = OB_STACKING_LAYER_NORMAL;
317 else if (parse_contains("bottom", doc, n))
318 config_dock_layer = OB_STACKING_LAYER_BELOW;
319 }
320 if ((n = parse_find_node("direction", node))) {
321 if (parse_contains("horizontal", doc, n))
322 config_dock_orient = OB_ORIENTATION_HORZ;
323 else if (parse_contains("vertical", doc, n))
324 config_dock_orient = OB_ORIENTATION_VERT;
325 }
326 if ((n = parse_find_node("autoHide", node)))
327 config_dock_hide = parse_bool(doc, n);
328 if ((n = parse_find_node("hideTimeout", node)))
329 config_dock_hide_timeout = parse_int(doc, n);
330 }
331
332 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
333 {
334 for (node = node->xmlChildrenNode; node; node = node->next) {
335 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
336 gchar *c;
337
338 c = parse_string(doc, node);
339 config_menu_files = g_slist_append(config_menu_files,
340 ob_expand_tilde(c));
341 g_free(c);
342 }
343 }
344 }
345
346 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
347 void *d)
348 {
349 xmlNodePtr n;
350
351 node = node->xmlChildrenNode;
352 if ((n = parse_find_node("strength", node)))
353 config_resist_win = parse_int(doc, n);
354 if ((n = parse_find_node("screen_edge_strength", node)))
355 config_resist_edge = parse_int(doc, n);
356 }
357
358 void config_startup(ObParseInst *i)
359 {
360 config_focus_new = TRUE;
361 config_focus_follow = FALSE;
362 config_focus_last = TRUE;
363 config_focus_last_on_desktop = TRUE;
364 config_focus_delay = 150000;
365
366 parse_register(i, "focus", parse_focus, NULL);
367
368 config_theme = NULL;
369
370 config_title_layout = g_strdup("NLIMC");
371
372 parse_register(i, "theme", parse_theme, NULL);
373
374 config_desktops_num = 4;
375 config_desktops_names = NULL;
376
377 parse_register(i, "desktops", parse_desktops, NULL);
378
379 config_redraw_resize = TRUE;
380
381 parse_register(i, "resize", parse_resize, NULL);
382
383 config_dock_layer = OB_STACKING_LAYER_TOP;
384 config_dock_pos = OB_DIRECTION_NORTHEAST;
385 config_dock_floating = FALSE;
386 config_dock_x = 0;
387 config_dock_y = 0;
388 config_dock_orient = OB_ORIENTATION_VERT;
389 config_dock_hide = FALSE;
390 config_dock_hide_timeout = 3000;
391
392 parse_register(i, "dock", parse_dock, NULL);
393
394 translate_key("C-g", &config_keyboard_reset_state,
395 &config_keyboard_reset_keycode);
396
397 parse_register(i, "keyboard", parse_keyboard, NULL);
398
399 config_mouse_threshold = 3;
400 config_mouse_dclicktime = 200;
401
402 parse_register(i, "mouse", parse_mouse, NULL);
403
404 config_resist_win = 10;
405 config_resist_edge = 20;
406
407 parse_register(i, "resistance", parse_resistance, NULL);
408
409 config_menu_files = NULL;
410
411 parse_register(i, "menu", parse_menu, NULL);
412 }
413
414 void config_shutdown()
415 {
416 GSList *it;
417
418 g_free(config_theme);
419
420 for (it = config_desktops_names; it; it = g_slist_next(it))
421 g_free(it->data);
422 g_slist_free(config_desktops_names);
423
424 for (it = config_menu_files; it; it = g_slist_next(it))
425 g_free(it->data);
426 g_slist_free(config_menu_files);
427 }
This page took 0.052759 seconds and 4 git commands to generate.