trunk: changeset 1925
[notion/jeffpc.git] / ioncore / bindmaps.c
blobd54e8e26d88f98122e758f20c475fe0f2c45f985
1 /*
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.
12 #include <libtu/rb.h>
13 #include "common.h"
14 #include "conf-bindings.h"
15 #include "binding.h"
16 #include <libextl/extl.h>
17 #include "framep.h"
18 #include "bindmaps.h"
21 /*
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},
38 END_STRINGINTMAP
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);
55 known_bindmaps=NULL;
59 #define DO_ALLOC(X, Y, Z) \
60 ioncore_ ## X ## _bindmap=ioncore_alloc_bindmap(Y, Z); \
61 if(ioncore_ ## X ## _bindmap==NULL) \
62 return FALSE;
64 bool ioncore_init_bindmaps()
66 known_bindmaps=make_rb();
68 if(known_bindmaps==NULL)
69 return FALSE;
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);
76 return TRUE;
81 void ioncore_refresh_bindmaps()
83 Rb_node node;
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();
97 if(bm==NULL)
98 return NULL;
100 bm->areamap=areas;
102 if(!rb_insert(known_bindmaps, name, bm)){
103 bindmap_destroy(bm);
104 return NULL;
107 return 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)
119 int found=0;
120 Rb_node node;
122 node=rb_find_key_n(known_bindmaps, name, &found);
123 assert(found!=0 && rb_val(node)==(void*)bm);
125 rb_delete_node(node);
126 bindmap_destroy(bm);
130 WBindmap *ioncore_lookup_bindmap(const char *name)
132 int found=0;
133 Rb_node node;
135 node=rb_find_key_n(known_bindmaps, name, &found);
137 if(found==0)
138 return NULL;
140 return (WBindmap*)rb_val(node);
144 EXTL_EXPORT
145 bool ioncore_do_defbindings(const char *name, ExtlTab tab)
147 WBindmap *bm=ioncore_lookup_bindmap(name);
148 if(bm==NULL){
149 warn("Unknown bindmap %s.", name);
150 return FALSE;
152 return bindmap_defbindings(bm, tab, FALSE);
156 EXTL_EXPORT
157 ExtlTab ioncore_do_getbindings()
159 Rb_node node;
160 ExtlTab tab;
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);
170 return tab;