]> Dogcows Code - chaz/openbox/blob - openbox/config.c
add a 'Switch to...' entry to empty desktops in the client-list-menu
[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 guint config_focus_delay;
30
31 char *config_theme;
32
33 gchar *config_title_layout;
34
35 int config_desktops_num;
36 GSList *config_desktops_names;
37
38 gboolean config_redraw_resize;
39
40 ObStackingLayer config_dock_layer;
41 gboolean config_dock_floating;
42 ObDirection config_dock_pos;
43 gint config_dock_x;
44 gint config_dock_y;
45 ObOrientation config_dock_orient;
46 gboolean config_dock_hide;
47 guint config_dock_hide_timeout;
48
49 guint config_keyboard_reset_keycode;
50 guint config_keyboard_reset_state;
51
52 gint config_mouse_threshold;
53 gint config_mouse_dclicktime;
54
55 GSList *config_menu_files;
56
57 gint config_resist_win;
58 gint config_resist_edge;
59
60 /*
61
62 <keybind key="C-x">
63 <action name="ChangeDesktop">
64 <desktop>3</desktop>
65 </action>
66 </keybind>
67
68 */
69
70 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
71 GList *keylist)
72 {
73 char *key;
74 ObAction *action;
75 xmlNodePtr n, nact;
76 GList *it;
77
78 if ((n = parse_find_node("chainQuitKey", node))) {
79 key = parse_string(doc, n);
80 translate_key(key, &config_keyboard_reset_state,
81 &config_keyboard_reset_keycode);
82 g_free(key);
83 }
84
85 n = parse_find_node("keybind", node);
86 while (n) {
87 if (parse_attr_string("key", n, &key)) {
88 keylist = g_list_append(keylist, key);
89
90 parse_key(i, doc, n->children, keylist);
91
92 it = g_list_last(keylist);
93 g_free(it->data);
94 keylist = g_list_delete_link(keylist, it);
95 }
96 n = parse_find_node("keybind", n->next);
97 }
98 if (keylist) {
99 nact = parse_find_node("action", node);
100 while (nact) {
101 if ((action = action_parse(i, doc, nact,
102 OB_USER_ACTION_KEYBOARD_KEY)))
103 keyboard_bind(keylist, action);
104 nact = parse_find_node("action", nact->next);
105 }
106 }
107 }
108
109 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
110 void *d)
111 {
112 keyboard_unbind_all();
113
114 parse_key(i, doc, node->children, NULL);
115 }
116
117 /*
118
119 <context name="Titlebar">
120 <mousebind button="Left" action="Press">
121 <action name="Raise"></action>
122 </mousebind>
123 </context>
124
125 */
126
127 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
128 void *d)
129 {
130 xmlNodePtr n, nbut, nact;
131 char *buttonstr;
132 char *contextstr;
133 ObUserAction uact;
134 ObMouseAction mact;
135 ObAction *action;
136
137 mouse_unbind_all();
138
139 node = node->children;
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->children);
151 while (nbut) {
152 if (!parse_attr_string("button", nbut, &buttonstr))
153 goto next_nbut;
154 if (parse_attr_contains("press", nbut, "action")) {
155 uact = OB_USER_ACTION_MOUSE_PRESS;
156 mact = OB_MOUSE_ACTION_PRESS;
157 } else if (parse_attr_contains("release", nbut, "action")) {
158 uact = OB_USER_ACTION_MOUSE_RELEASE;
159 mact = OB_MOUSE_ACTION_RELEASE;
160 } else if (parse_attr_contains("click", nbut, "action")) {
161 uact = OB_USER_ACTION_MOUSE_CLICK;
162 mact = OB_MOUSE_ACTION_CLICK;
163 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
164 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
165 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
166 } else if (parse_attr_contains("drag", nbut, "action")) {
167 uact = OB_USER_ACTION_MOUSE_MOTION;
168 mact = OB_MOUSE_ACTION_MOTION;
169 } else
170 goto next_nbut;
171 nact = parse_find_node("action", nbut->children);
172 while (nact) {
173 if ((action = action_parse(i, doc, nact, uact)))
174 mouse_bind(buttonstr, contextstr, mact, action);
175 nact = parse_find_node("action", nact->next);
176 }
177 g_free(buttonstr);
178 next_nbut:
179 nbut = parse_find_node("mousebind", nbut->next);
180 }
181 g_free(contextstr);
182 next_n:
183 n = parse_find_node("context", n->next);
184 }
185 }
186
187 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
188 void *d)
189 {
190 xmlNodePtr n;
191
192 node = node->children;
193
194 if ((n = parse_find_node("focusNew", node)))
195 config_focus_new = parse_bool(doc, n);
196 if ((n = parse_find_node("followMouse", node)))
197 config_focus_follow = parse_bool(doc, n);
198 if ((n = parse_find_node("focusDelay", node)))
199 config_focus_delay = parse_int(doc, n) * 1000;
200 }
201
202 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
203 void *d)
204 {
205 xmlNodePtr n;
206
207 node = node->children;
208
209 if ((n = parse_find_node("name", node))) {
210 gchar *c;
211
212 g_free(config_theme);
213 c = parse_string(doc, n);
214 config_theme = parse_expand_tilde(c);
215 g_free(c);
216 }
217 if ((n = parse_find_node("titleLayout", node))) {
218 g_free(config_title_layout);
219 config_title_layout = parse_string(doc, n);
220 }
221 }
222
223 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
224 void *d)
225 {
226 xmlNodePtr n;
227
228 node = node->children;
229
230 if ((n = parse_find_node("number", node)))
231 config_desktops_num = parse_int(doc, n);
232 if ((n = parse_find_node("names", node))) {
233 GSList *it;
234 xmlNodePtr nname;
235
236 for (it = config_desktops_names; it; it = it->next)
237 g_free(it->data);
238 g_slist_free(config_desktops_names);
239 config_desktops_names = NULL;
240
241 nname = parse_find_node("name", n->children);
242 while (nname) {
243 config_desktops_names = g_slist_append(config_desktops_names,
244 parse_string(doc, nname));
245 nname = parse_find_node("name", nname->next);
246 }
247 }
248 }
249
250 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
251 void *d)
252 {
253 xmlNodePtr n;
254
255 node = node->children;
256
257 if ((n = parse_find_node("drawContents", node)))
258 config_redraw_resize = parse_bool(doc, n);
259 }
260
261 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
262 {
263 xmlNodePtr n;
264
265 node = node->children;
266
267 if ((n = parse_find_node("position", node))) {
268 if (parse_contains("TopLeft", doc, n))
269 config_dock_floating = FALSE,
270 config_dock_pos = OB_DIRECTION_NORTHWEST;
271 else if (parse_contains("Top", doc, n))
272 config_dock_floating = FALSE,
273 config_dock_pos = OB_DIRECTION_NORTH;
274 else if (parse_contains("TopRight", doc, n))
275 config_dock_floating = FALSE,
276 config_dock_pos = OB_DIRECTION_NORTHEAST;
277 else if (parse_contains("Right", doc, n))
278 config_dock_floating = FALSE,
279 config_dock_pos = OB_DIRECTION_EAST;
280 else if (parse_contains("BottomRight", doc, n))
281 config_dock_floating = FALSE,
282 config_dock_pos = OB_DIRECTION_SOUTHEAST;
283 else if (parse_contains("Bottom", doc, n))
284 config_dock_floating = FALSE,
285 config_dock_pos = OB_DIRECTION_SOUTH;
286 else if (parse_contains("BottomLeft", doc, n))
287 config_dock_floating = FALSE,
288 config_dock_pos = OB_DIRECTION_SOUTHWEST;
289 else if (parse_contains("Left", doc, n))
290 config_dock_floating = FALSE,
291 config_dock_pos = OB_DIRECTION_WEST;
292 else if (parse_contains("Floating", doc, n))
293 config_dock_floating = TRUE;
294 }
295 if (config_dock_floating) {
296 if ((n = parse_find_node("floatingX", node)))
297 config_dock_x = parse_int(doc, n);
298 if ((n = parse_find_node("floatingY", node)))
299 config_dock_y = parse_int(doc, n);
300 }
301 if ((n = parse_find_node("stacking", node))) {
302 if (parse_contains("top", doc, n))
303 config_dock_layer = OB_STACKING_LAYER_TOP;
304 else if (parse_contains("normal", doc, n))
305 config_dock_layer = OB_STACKING_LAYER_NORMAL;
306 else if (parse_contains("bottom", doc, n))
307 config_dock_layer = OB_STACKING_LAYER_BELOW;
308 }
309 if ((n = parse_find_node("direction", node))) {
310 if (parse_contains("horizontal", doc, n))
311 config_dock_orient = OB_ORIENTATION_HORZ;
312 else if (parse_contains("vertical", doc, n))
313 config_dock_orient = OB_ORIENTATION_VERT;
314 }
315 if ((n = parse_find_node("autoHide", node)))
316 config_dock_hide = parse_bool(doc, n);
317 if ((n = parse_find_node("hideTimeout", node)))
318 config_dock_hide_timeout = parse_int(doc, n) * 1000;
319 }
320
321 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
322 {
323 for (node = node->children; node; node = node->next) {
324 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
325 gchar *c;
326
327 c = parse_string(doc, node);
328 config_menu_files = g_slist_append(config_menu_files,
329 parse_expand_tilde(c));
330 g_free(c);
331 }
332 }
333 }
334
335 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
336 void *d)
337 {
338 xmlNodePtr n;
339
340 node = node->children;
341 if ((n = parse_find_node("strength", node)))
342 config_resist_win = parse_int(doc, n);
343 if ((n = parse_find_node("screen_edge_strength", node)))
344 config_resist_edge = parse_int(doc, n);
345 }
346
347 typedef struct
348 {
349 const gchar *key;
350 const gchar *actname;
351 } ObDefKeyBind;
352
353 static void bind_default_keyboard()
354 {
355 ObDefKeyBind *it;
356 ObDefKeyBind binds[] = {
357 { "A-Tab", "NextWindow" },
358 { "S-A-Tab", "PreviousWindow" },
359 { "C-A-Right", "DesktopRight" },
360 { "C-A-Left", "DesktopLeft" },
361 { "C-A-Up", "DesktopUp" },
362 { "C-A-Down", "DesktopDown" },
363 { "S-A-Right", "SendToDesktopRight" },
364 { "S-A-Left", "SendToDesktopLeft" },
365 { "S-A-Up", "SendToDesktopUp" },
366 { "S-A-Down", "SendToDesktopDown" },
367 { "A-F10", "MaximizeFull" },
368 { "A-F5", "UnmaximizeFull" },
369 { "A-F12", "ToggleShade" },
370 { "A-F4", "Close" },
371 { "A-F7", "Move" },
372 { "A-F8", "Resize" },
373 { "A-F9", "Iconify" },
374 { NULL, NULL }
375 };
376
377 for (it = binds; it->key; ++it) {
378 GList *l = g_list_append(NULL, g_strdup(it->key));
379 keyboard_bind(l, action_from_string(it->actname,
380 OB_USER_ACTION_KEYBOARD_KEY));
381 }
382 }
383
384 typedef struct
385 {
386 const gchar *button;
387 const gchar *context;
388 ObMouseAction mact;
389 const gchar *actname;
390 } ObDefMouseBind;
391
392 static void bind_default_mouse()
393 {
394 ObDefMouseBind *it;
395 ObDefMouseBind binds[] = {
396 { "Up", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
397 { "Down", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
398 { "A-Up", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
399 { "A-Down", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
400 { "A-Up", "Frame", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
401 { "A-Down", "Frame", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
402 { "A-Up", "MoveResize", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
403 { "Down", "MoveResize", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
404 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
405 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
406 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
407 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
408 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
409 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
410 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
411 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
412 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
413 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
414 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
415 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
416 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
417 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
418 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
419 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
420 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
421 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
422 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
423 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
424 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
425 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
426 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
427 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
428 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
429 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
430 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
431 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
432 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
433 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
434 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
435 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
436 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
437 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
438 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
439 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
440 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
441 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
442 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
443 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
444 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
445 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
446 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
447 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
448 { NULL, NULL, 0, NULL }
449 };
450
451 for (it = binds; it->button; ++it) {
452 ObUserAction uact;
453 switch (it->mact) {
454 case OB_MOUSE_ACTION_PRESS:
455 uact = OB_USER_ACTION_MOUSE_PRESS; break;
456 case OB_MOUSE_ACTION_RELEASE:
457 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
458 case OB_MOUSE_ACTION_CLICK:
459 uact = OB_USER_ACTION_MOUSE_CLICK; break;
460 case OB_MOUSE_ACTION_DOUBLE_CLICK:
461 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
462 case OB_MOUSE_ACTION_MOTION:
463 uact = OB_USER_ACTION_MOUSE_MOTION; break;
464 case OB_NUM_MOUSE_ACTIONS:
465 g_assert_not_reached();
466 }
467 mouse_bind(it->button, it->context, it->mact,
468 action_from_string(it->actname, uact));
469 }
470 }
471
472 void config_startup(ObParseInst *i)
473 {
474 config_focus_new = TRUE;
475 config_focus_follow = FALSE;
476 config_focus_delay = 0;
477
478 parse_register(i, "focus", parse_focus, NULL);
479
480 config_theme = NULL;
481
482 config_title_layout = g_strdup("NLIMC");
483
484 parse_register(i, "theme", parse_theme, NULL);
485
486 config_desktops_num = 4;
487 config_desktops_names = NULL;
488
489 parse_register(i, "desktops", parse_desktops, NULL);
490
491 config_redraw_resize = TRUE;
492
493 parse_register(i, "resize", parse_resize, NULL);
494
495 config_dock_layer = OB_STACKING_LAYER_TOP;
496 config_dock_pos = OB_DIRECTION_NORTHEAST;
497 config_dock_floating = FALSE;
498 config_dock_x = 0;
499 config_dock_y = 0;
500 config_dock_orient = OB_ORIENTATION_VERT;
501 config_dock_hide = FALSE;
502 config_dock_hide_timeout = 300;
503
504 parse_register(i, "dock", parse_dock, NULL);
505
506 translate_key("C-g", &config_keyboard_reset_state,
507 &config_keyboard_reset_keycode);
508
509 bind_default_keyboard();
510
511 parse_register(i, "keyboard", parse_keyboard, NULL);
512
513 config_mouse_threshold = 3;
514 config_mouse_dclicktime = 200;
515
516 bind_default_mouse();
517
518 parse_register(i, "mouse", parse_mouse, NULL);
519
520 config_resist_win = 10;
521 config_resist_edge = 20;
522
523 parse_register(i, "resistance", parse_resistance, NULL);
524
525 config_menu_files = NULL;
526
527 parse_register(i, "menu", parse_menu, NULL);
528 }
529
530 void config_shutdown()
531 {
532 GSList *it;
533
534 g_free(config_theme);
535
536 g_free(config_title_layout);
537
538 for (it = config_desktops_names; it; it = g_slist_next(it))
539 g_free(it->data);
540 g_slist_free(config_desktops_names);
541
542 for (it = config_menu_files; it; it = g_slist_next(it))
543 g_free(it->data);
544 g_slist_free(config_menu_files);
545 }
This page took 0.057775 seconds and 4 git commands to generate.