]> Dogcows Code - chaz/openbox/blob - openbox/config.c
remove the dialog options
[chaz/openbox] / openbox / config.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 config.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "config.h"
20 #include "keyboard.h"
21 #include "mouse.h"
22 #include "prop.h"
23 #include "translate.h"
24 #include "parser/parse.h"
25 #include "openbox.h"
26
27 gboolean config_focus_new;
28 gboolean config_focus_follow;
29 gboolean config_focus_last;
30 guint config_focus_delay;
31 guint config_focus_raise;
32
33 char *config_theme;
34
35 gchar *config_title_layout;
36
37 int config_desktops_num;
38 GSList *config_desktops_names;
39
40 gboolean config_redraw_resize;
41
42 ObStackingLayer config_dock_layer;
43 gboolean config_dock_floating;
44 ObDirection config_dock_pos;
45 gint config_dock_x;
46 gint config_dock_y;
47 ObOrientation config_dock_orient;
48 gboolean config_dock_hide;
49 guint config_dock_hide_delay;
50 guint config_dock_app_move_button;
51 guint config_dock_app_move_modifiers;
52
53 guint config_keyboard_reset_keycode;
54 guint config_keyboard_reset_state;
55
56 gint config_mouse_threshold;
57 gint config_mouse_dclicktime;
58
59 gboolean config_dialog_focus;
60 gboolean config_dialog_desktop;
61
62 GSList *config_menu_files;
63
64 gint config_resist_win;
65 gint config_resist_edge;
66
67 /*
68
69 <keybind key="C-x">
70 <action name="ChangeDesktop">
71 <desktop>3</desktop>
72 </action>
73 </keybind>
74
75 */
76
77 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
78 GList *keylist)
79 {
80 char *key;
81 ObAction *action;
82 xmlNodePtr n, nact;
83 GList *it;
84
85 if ((n = parse_find_node("chainQuitKey", node))) {
86 key = parse_string(doc, n);
87 translate_key(key, &config_keyboard_reset_state,
88 &config_keyboard_reset_keycode);
89 g_free(key);
90 }
91
92 n = parse_find_node("keybind", node);
93 while (n) {
94 if (parse_attr_string("key", n, &key)) {
95 keylist = g_list_append(keylist, key);
96
97 parse_key(i, doc, n->children, keylist);
98
99 it = g_list_last(keylist);
100 g_free(it->data);
101 keylist = g_list_delete_link(keylist, it);
102 }
103 n = parse_find_node("keybind", n->next);
104 }
105 if (keylist) {
106 nact = parse_find_node("action", node);
107 while (nact) {
108 if ((action = action_parse(i, doc, nact,
109 OB_USER_ACTION_KEYBOARD_KEY)))
110 keyboard_bind(keylist, action);
111 nact = parse_find_node("action", nact->next);
112 }
113 }
114 }
115
116 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
117 void *d)
118 {
119 keyboard_unbind_all();
120
121 parse_key(i, doc, node->children, NULL);
122 }
123
124 /*
125
126 <context name="Titlebar">
127 <mousebind button="Left" action="Press">
128 <action name="Raise"></action>
129 </mousebind>
130 </context>
131
132 */
133
134 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
135 void *d)
136 {
137 xmlNodePtr n, nbut, nact;
138 char *buttonstr;
139 char *contextstr;
140 ObUserAction uact;
141 ObMouseAction mact;
142 ObAction *action;
143
144 mouse_unbind_all();
145
146 node = node->children;
147
148 if ((n = parse_find_node("dragThreshold", node)))
149 config_mouse_threshold = parse_int(doc, n);
150 if ((n = parse_find_node("doubleClickTime", node)))
151 config_mouse_dclicktime = parse_int(doc, n);
152
153 n = parse_find_node("context", node);
154 while (n) {
155 if (!parse_attr_string("name", n, &contextstr))
156 goto next_n;
157 nbut = parse_find_node("mousebind", n->children);
158 while (nbut) {
159 if (!parse_attr_string("button", nbut, &buttonstr))
160 goto next_nbut;
161 if (parse_attr_contains("press", nbut, "action")) {
162 uact = OB_USER_ACTION_MOUSE_PRESS;
163 mact = OB_MOUSE_ACTION_PRESS;
164 } else if (parse_attr_contains("release", nbut, "action")) {
165 uact = OB_USER_ACTION_MOUSE_RELEASE;
166 mact = OB_MOUSE_ACTION_RELEASE;
167 } else if (parse_attr_contains("click", nbut, "action")) {
168 uact = OB_USER_ACTION_MOUSE_CLICK;
169 mact = OB_MOUSE_ACTION_CLICK;
170 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
171 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
172 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
173 } else if (parse_attr_contains("drag", nbut, "action")) {
174 uact = OB_USER_ACTION_MOUSE_MOTION;
175 mact = OB_MOUSE_ACTION_MOTION;
176 } else
177 goto next_nbut;
178 nact = parse_find_node("action", nbut->children);
179 while (nact) {
180 if ((action = action_parse(i, doc, nact, uact)))
181 mouse_bind(buttonstr, contextstr, mact, action);
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->children;
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("focusDelay", node)))
208 config_focus_delay = parse_int(doc, n) * 1000;
209 if ((n = parse_find_node("raiseOnFocus", node)))
210 config_focus_raise = parse_bool(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->children;
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 = parse_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->children;
240
241 if ((n = parse_find_node("number", node))) {
242 guint d = parse_int(doc, n);
243 if (d > 0)
244 config_desktops_num = d;
245 }
246 if ((n = parse_find_node("names", node))) {
247 GSList *it;
248 xmlNodePtr nname;
249
250 for (it = config_desktops_names; it; it = it->next)
251 g_free(it->data);
252 g_slist_free(config_desktops_names);
253 config_desktops_names = NULL;
254
255 nname = parse_find_node("name", n->children);
256 while (nname) {
257 config_desktops_names = g_slist_append(config_desktops_names,
258 parse_string(doc, nname));
259 nname = parse_find_node("name", nname->next);
260 }
261 }
262 }
263
264 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
265 void *d)
266 {
267 xmlNodePtr n;
268
269 node = node->children;
270
271 if ((n = parse_find_node("drawContents", node)))
272 config_redraw_resize = parse_bool(doc, n);
273 }
274
275 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
276 {
277 xmlNodePtr n;
278
279 node = node->children;
280
281 if ((n = parse_find_node("position", node))) {
282 if (parse_contains("TopLeft", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_NORTHWEST;
285 else if (parse_contains("Top", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_NORTH;
288 else if (parse_contains("TopRight", doc, n))
289 config_dock_floating = FALSE,
290 config_dock_pos = OB_DIRECTION_NORTHEAST;
291 else if (parse_contains("Right", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_EAST;
294 else if (parse_contains("BottomRight", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_SOUTHEAST;
297 else if (parse_contains("Bottom", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_SOUTH;
300 else if (parse_contains("BottomLeft", doc, n))
301 config_dock_floating = FALSE,
302 config_dock_pos = OB_DIRECTION_SOUTHWEST;
303 else if (parse_contains("Left", doc, n))
304 config_dock_floating = FALSE,
305 config_dock_pos = OB_DIRECTION_WEST;
306 else if (parse_contains("Floating", doc, n))
307 config_dock_floating = TRUE;
308 }
309 if (config_dock_floating) {
310 if ((n = parse_find_node("floatingX", node)))
311 config_dock_x = parse_int(doc, n);
312 if ((n = parse_find_node("floatingY", node)))
313 config_dock_y = parse_int(doc, n);
314 }
315 if ((n = parse_find_node("stacking", node))) {
316 if (parse_contains("top", doc, n))
317 config_dock_layer = OB_STACKING_LAYER_TOP;
318 else if (parse_contains("normal", doc, n))
319 config_dock_layer = OB_STACKING_LAYER_NORMAL;
320 else if (parse_contains("bottom", doc, n))
321 config_dock_layer = OB_STACKING_LAYER_BELOW;
322 }
323 if ((n = parse_find_node("direction", node))) {
324 if (parse_contains("horizontal", doc, n))
325 config_dock_orient = OB_ORIENTATION_HORZ;
326 else if (parse_contains("vertical", doc, n))
327 config_dock_orient = OB_ORIENTATION_VERT;
328 }
329 if ((n = parse_find_node("autoHide", node)))
330 config_dock_hide = parse_bool(doc, n);
331 if ((n = parse_find_node("hideDelay", node)))
332 config_dock_hide_delay = parse_int(doc, n) * 1000;
333 if ((n = parse_find_node("moveButton", node))) {
334 gchar *str = parse_string(doc, n);
335 guint b, s;
336 if (translate_button(str, &s, &b)) {
337 config_dock_app_move_button = b;
338 config_dock_app_move_modifiers = s;
339 } else {
340 g_warning("invalid button '%s'", str);
341 }
342 g_free(str);
343 }
344 }
345
346 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
347 {
348 for (node = node->children; node; node = node->next) {
349 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
350 gchar *c;
351
352 c = parse_string(doc, node);
353 config_menu_files = g_slist_append(config_menu_files,
354 parse_expand_tilde(c));
355 g_free(c);
356 }
357 }
358 }
359
360 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
361 void *d)
362 {
363 xmlNodePtr n;
364
365 node = node->children;
366 if ((n = parse_find_node("strength", node)))
367 config_resist_win = parse_int(doc, n);
368 if ((n = parse_find_node("screen_edge_strength", node)))
369 config_resist_edge = parse_int(doc, n);
370 }
371
372 typedef struct
373 {
374 const gchar *key;
375 const gchar *actname;
376 } ObDefKeyBind;
377
378 static void bind_default_keyboard()
379 {
380 ObDefKeyBind *it;
381 ObDefKeyBind binds[] = {
382 { "A-Tab", "NextWindow" },
383 { "S-A-Tab", "PreviousWindow" },
384 { "A-F4", "Close" },
385 { NULL, NULL }
386 };
387
388 for (it = binds; it->key; ++it) {
389 GList *l = g_list_append(NULL, g_strdup(it->key));
390 keyboard_bind(l, action_from_string(it->actname,
391 OB_USER_ACTION_KEYBOARD_KEY));
392 }
393 }
394
395 typedef struct
396 {
397 const gchar *button;
398 const gchar *context;
399 const ObMouseAction mact;
400 const gchar *actname;
401 } ObDefMouseBind;
402
403 static void bind_default_mouse()
404 {
405 ObDefMouseBind *it;
406 ObDefMouseBind binds[] = {
407 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
408 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
409 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
410 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
411 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
412 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
413 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
414 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
415 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
416 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
417 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
418 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
419 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
420 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
421 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
422 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
423 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
424 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
425 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
426 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
427 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
428 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
429 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
430 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
431 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
432 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
433 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
434 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
435 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
436 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
437 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
438 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
439 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
440 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
441 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
442 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
443 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
444 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
445 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
446 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
447 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
448 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
449 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
450 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
451 { NULL, NULL, 0, NULL }
452 };
453
454 for (it = binds; it->button; ++it) {
455 ObUserAction uact;
456 switch (it->mact) {
457 case OB_MOUSE_ACTION_PRESS:
458 uact = OB_USER_ACTION_MOUSE_PRESS; break;
459 case OB_MOUSE_ACTION_RELEASE:
460 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
461 case OB_MOUSE_ACTION_CLICK:
462 uact = OB_USER_ACTION_MOUSE_CLICK; break;
463 case OB_MOUSE_ACTION_DOUBLE_CLICK:
464 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
465 case OB_MOUSE_ACTION_MOTION:
466 uact = OB_USER_ACTION_MOUSE_MOTION; break;
467 case OB_NUM_MOUSE_ACTIONS:
468 g_assert_not_reached();
469 }
470 mouse_bind(it->button, it->context, it->mact,
471 action_from_string(it->actname, uact));
472 }
473 }
474
475 void config_startup(ObParseInst *i)
476 {
477 config_focus_new = TRUE;
478 config_focus_follow = FALSE;
479 config_focus_last = TRUE;
480 config_focus_delay = 0;
481 config_focus_raise = FALSE;
482
483 parse_register(i, "focus", parse_focus, NULL);
484
485 config_theme = NULL;
486
487 config_title_layout = g_strdup("NLIMC");
488
489 parse_register(i, "theme", parse_theme, NULL);
490
491 config_desktops_num = 4;
492 config_desktops_names = NULL;
493
494 parse_register(i, "desktops", parse_desktops, NULL);
495
496 config_redraw_resize = TRUE;
497
498 parse_register(i, "resize", parse_resize, NULL);
499
500 config_dock_layer = OB_STACKING_LAYER_TOP;
501 config_dock_pos = OB_DIRECTION_NORTHEAST;
502 config_dock_floating = FALSE;
503 config_dock_x = 0;
504 config_dock_y = 0;
505 config_dock_orient = OB_ORIENTATION_VERT;
506 config_dock_hide = FALSE;
507 config_dock_hide_delay = 300;
508 config_dock_app_move_button = 2; /* middle */
509 config_dock_app_move_modifiers = 0;
510
511 parse_register(i, "dock", parse_dock, NULL);
512
513 translate_key("C-g", &config_keyboard_reset_state,
514 &config_keyboard_reset_keycode);
515
516 bind_default_keyboard();
517
518 parse_register(i, "keyboard", parse_keyboard, NULL);
519
520 config_mouse_threshold = 3;
521 config_mouse_dclicktime = 200;
522
523 bind_default_mouse();
524
525 parse_register(i, "mouse", parse_mouse, NULL);
526
527 config_resist_win = 10;
528 config_resist_edge = 20;
529
530 parse_register(i, "resistance", parse_resistance, NULL);
531
532 config_menu_files = NULL;
533
534 parse_register(i, "menu", parse_menu, NULL);
535 }
536
537 void config_shutdown()
538 {
539 GSList *it;
540
541 g_free(config_theme);
542
543 g_free(config_title_layout);
544
545 for (it = config_desktops_names; it; it = g_slist_next(it))
546 g_free(it->data);
547 g_slist_free(config_desktops_names);
548
549 for (it = config_menu_files; it; it = g_slist_next(it))
550 g_free(it->data);
551 g_slist_free(config_menu_files);
552 }
This page took 0.064415 seconds and 4 git commands to generate.