2 * ion/ioncore/bindmaps.c
4 * Copyright (c) Tuomo Valkonen 1999-2005.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include "conf-bindings.h"
16 #include <libextl/extl.h>
22 * This file contains higher-level bindmap management code
26 WBindmap
*ioncore_rootwin_bindmap
=NULL
;
27 WBindmap
*ioncore_mplex_bindmap
=NULL
;
28 WBindmap
*ioncore_frame_bindmap
=NULL
;
29 WBindmap
*ioncore_moveres_bindmap
=NULL
;
31 static Rb_node known_bindmaps
=NULL
;
33 static StringIntMap frame_areas
[]={
34 {"border", FRAME_AREA_BORDER
},
35 {"tab", FRAME_AREA_TAB
},
36 {"empty_tab", FRAME_AREA_TAB
},
37 {"client", FRAME_AREA_CLIENT
},
42 #define DO_FREE(X, Y) \
43 if(ioncore_ ## X ## _bindmap!=NULL){ \
44 ioncore_free_bindmap(Y, ioncore_ ## X ## _bindmap); \
45 ioncore_ ## X ## _bindmap=NULL; \
48 void ioncore_deinit_bindmaps()
50 DO_FREE(rootwin
, "WScreen");
51 DO_FREE(mplex
, "WMPlex");
52 DO_FREE(frame
, "WFrame");
53 DO_FREE(moveres
, "WMoveresMode");
54 rb_free_tree(known_bindmaps
);
59 #define DO_ALLOC(X, Y, Z) \
60 ioncore_ ## X ## _bindmap=ioncore_alloc_bindmap(Y, Z); \
61 if(ioncore_ ## X ## _bindmap==NULL) \
64 bool ioncore_init_bindmaps()
66 known_bindmaps
=make_rb();
68 if(known_bindmaps
==NULL
)
71 DO_ALLOC(rootwin
, "WScreen", NULL
);
72 DO_ALLOC(mplex
, "WMPlex", NULL
);
73 DO_ALLOC(frame
, "WFrame", frame_areas
);
74 DO_ALLOC(moveres
, "WMoveresMode", NULL
);
81 void ioncore_refresh_bindmaps()
85 ioncore_update_modmap();
87 rb_traverse(node
,known_bindmaps
){
88 bindmap_refresh((WBindmap
*)rb_val(node
));
93 WBindmap
*ioncore_alloc_bindmap(const char *name
, const StringIntMap
*areas
)
95 WBindmap
*bm
=create_bindmap();
102 if(!rb_insert(known_bindmaps
, name
, bm
)){
111 WBindmap
*ioncore_alloc_bindmap_frame(const char *name
)
113 return ioncore_alloc_bindmap(name
, frame_areas
);
117 void ioncore_free_bindmap(const char *name
, WBindmap
*bm
)
122 node
=rb_find_key_n(known_bindmaps
, name
, &found
);
123 assert(found
!=0 && rb_val(node
)==(void*)bm
);
125 rb_delete_node(node
);
130 WBindmap
*ioncore_lookup_bindmap(const char *name
)
135 node
=rb_find_key_n(known_bindmaps
, name
, &found
);
140 return (WBindmap
*)rb_val(node
);
145 bool ioncore_do_defbindings(const char *name
, ExtlTab tab
)
147 WBindmap
*bm
=ioncore_lookup_bindmap(name
);
149 warn("Unknown bindmap %s.", name
);
152 return bindmap_defbindings(bm
, tab
, FALSE
);
157 ExtlTab
ioncore_do_getbindings()
162 tab
=extl_create_table();
164 rb_traverse(node
, known_bindmaps
){
165 ExtlTab bmtab
=bindmap_getbindings((WBindmap
*)rb_val(node
));
166 extl_table_sets_t(tab
, (const char*)node
->k
.key
, bmtab
);
167 extl_unref_table(bmtab
);