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