2 * ion/ioncore/bindmaps.c
4 * Copyright (c) Tuomo Valkonen 1999-2008.
6 * See the included file LICENSE for details.
10 #include <libextl/extl.h>
12 #include "conf-bindings.h"
21 * This file contains higher-level bindmap management code
25 WBindmap *ioncore_screen_bindmap=NULL;
26 WBindmap *ioncore_mplex_bindmap=NULL;
27 WBindmap *ioncore_mplex_toplevel_bindmap=NULL;
28 WBindmap *ioncore_frame_bindmap=NULL;
29 WBindmap *ioncore_frame_toplevel_bindmap=NULL;
30 WBindmap *ioncore_frame_floating_bindmap=NULL;
31 WBindmap *ioncore_frame_tiled_bindmap=NULL;
32 WBindmap *ioncore_frame_transient_bindmap=NULL;
33 WBindmap *ioncore_moveres_bindmap=NULL;
34 WBindmap *ioncore_group_bindmap=NULL;
35 WBindmap *ioncore_groupcw_bindmap=NULL;
36 WBindmap *ioncore_groupws_bindmap=NULL;
37 WBindmap *ioncore_clientwin_bindmap=NULL;
39 static Rb_node known_bindmaps=NULL;
41 static StringIntMap frame_areas[]={
42 {"border", FRAME_AREA_BORDER},
43 {"tab", FRAME_AREA_TAB},
44 {"empty_tab", FRAME_AREA_TAB},
45 {"client", FRAME_AREA_CLIENT},
50 #define DO_FREE(X, Y) \
51 if(ioncore_ ## X ## _bindmap!=NULL){ \
52 ioncore_free_bindmap(Y, ioncore_ ## X ## _bindmap); \
53 ioncore_ ## X ## _bindmap=NULL; \
56 void ioncore_deinit_bindmaps()
58 DO_FREE(screen, "WScreen");
59 DO_FREE(mplex, "WMPlex");
60 DO_FREE(mplex_toplevel, "WMPlex.toplevel");
61 DO_FREE(frame, "WFrame");
62 DO_FREE(frame_toplevel, "WFrame.toplevel");
63 DO_FREE(frame_floating, "WFrame.floating");
64 DO_FREE(frame_tiled, "WFrame.tiled");
65 DO_FREE(frame_transient, "WFrame.transient");
66 DO_FREE(moveres, "WMoveresMode");
67 DO_FREE(group, "WGroup");
68 DO_FREE(groupcw, "WGroupCW");
69 DO_FREE(groupws, "WGroupWS");
70 DO_FREE(clientwin, "WClientWin");
71 rb_free_tree(known_bindmaps);
76 #define DO_ALLOC(X, Y, Z) \
77 ioncore_ ## X ## _bindmap=ioncore_alloc_bindmap(Y, Z); \
78 if(ioncore_ ## X ## _bindmap==NULL) \
81 bool ioncore_init_bindmaps()
83 known_bindmaps=make_rb();
85 if(known_bindmaps==NULL)
88 DO_ALLOC(screen, "WScreen", NULL);
89 DO_ALLOC(mplex, "WMPlex", NULL);
90 DO_ALLOC(mplex_toplevel, "WMPlex.toplevel", NULL);
91 DO_ALLOC(frame, "WFrame", frame_areas);
92 DO_ALLOC(frame_toplevel, "WFrame.toplevel", frame_areas);
93 DO_ALLOC(frame_floating, "WFrame.floating", frame_areas);
94 DO_ALLOC(frame_tiled, "WFrame.tiled", frame_areas);
95 DO_ALLOC(frame_transient, "WFrame.transient", frame_areas);
96 DO_ALLOC(moveres, "WMoveresMode", NULL);
97 DO_ALLOC(group, "WGroup", NULL);
98 DO_ALLOC(groupcw, "WGroupCW", NULL);
99 DO_ALLOC(groupws, "WGroupWS", NULL);
100 DO_ALLOC(clientwin, "WClientWin", NULL);
107 void ioncore_refresh_bindmaps()
111 ioncore_update_modmap();
113 rb_traverse(node,known_bindmaps){
114 bindmap_refresh((WBindmap*)rb_val(node));
119 WBindmap *ioncore_alloc_bindmap(const char *name, const StringIntMap *areas)
121 WBindmap *bm=create_bindmap();
128 if(!rb_insert(known_bindmaps, name, bm)){
137 WBindmap *ioncore_alloc_bindmap_frame(const char *name)
139 return ioncore_alloc_bindmap(name, frame_areas);
143 void ioncore_free_bindmap(const char *name, WBindmap *bm)
148 node=rb_find_key_n(known_bindmaps, name, &found);
149 assert(found!=0 && rb_val(node)==(void*)bm);
151 rb_delete_node(node);
156 WBindmap *ioncore_lookup_bindmap(const char *name)
161 node=rb_find_key_n(known_bindmaps, name, &found);
166 return (WBindmap*)rb_val(node);
171 bool ioncore_do_defbindings(const char *name, ExtlTab tab)
173 WBindmap *bm=ioncore_lookup_bindmap(name);
175 warn("Unknown bindmap %s.", name);
178 return bindmap_defbindings(bm, tab, FALSE);
184 ExtlTab ioncore_do_getbindings()
189 tab=extl_create_table();
191 rb_traverse(node, known_bindmaps){
192 ExtlTab bmtab=bindmap_getbindings((WBindmap*)rb_val(node));
193 extl_table_sets_t(tab, (const char*)node->k.key, bmtab);
194 extl_unref_table(bmtab);
201 WBindmap *ioncore_create_cycle_bindmap(uint kcb, uint state,
202 ExtlFn cycle, ExtlFn bcycle)
204 WBindmap *bindmap=create_bindmap();
210 b.ksb=XKeycodeToKeysym(ioncore_g.dpy, kcb, 0);
213 b.act=BINDING_KEYPRESS;
217 b.func=extl_ref_fn(cycle);
219 if(!bindmap_add_binding(bindmap, &b)){
220 extl_unref_fn(b.func);
221 bindmap_destroy(bindmap);
225 if((b.state&ShiftMask)==0 && bcycle!=extl_fn_none()){
226 b.func=extl_ref_fn(bcycle);
228 bindmap_add_binding(bindmap, &b);
235 WBindmap *region_add_cycle_bindmap(WRegion *reg, uint kcb, uint state,
236 ExtlFn cycle, ExtlFn bcycle)
238 WBindmap *bindmap=ioncore_create_cycle_bindmap(kcb, state, cycle, bcycle);
241 if(!region_add_bindmap(reg, bindmap)){
242 bindmap_destroy(bindmap);